Namespaces
Variants
Actions

Get the bounding box of a jsr 184 mesh

Jump to: navigation, search
SignpostIcon Palette 52.png
Article Metadata

Article
Created: ed_welch (03 Nov 2007)
Last edited: hamishwillee (18 Jul 2012)

Something I wrote a long time ago, but comes in quite handy. This function returns the bounding box on any mesh

// Gets the bounder box of any mesh
// returns an array for the min and max of each axis
// extreme[0].min = x axis min value,
// extreme[1].min = y axis min value, etc...
public MinMax[] GetExtremes(Mesh mesh)
{
MinMax[] extreme = new MinMax[3];
VertexBuffer vertexBuffer = mesh.getVertexBuffer();
float[] scaleBias = new float[4];
VertexArray postionArray = vertexBuffer.getPositions(scaleBias);
 
float[] out = new float[vertexBuffer.getVertexCount() * 4];
Transform trans = new Transform();
 
trans.postTranslate(scaleBias[1], scaleBias[2], scaleBias[3]);
trans.postScale(scaleBias[0], scaleBias[0], scaleBias[0]);
trans.transform(postionArray, out, true);
int n;
int axis;
for (axis = 0; axis < 3; axis++)
{
extreme[axis] = new MinMax();
extreme[axis].max = out[axis];
extreme[axis].min = out[axis];
}
for (n = 4; n < out.length / 4; n++)
{
for (axis = 0; axis < 3; axis++)
{
if (extreme[axis].max < out[n * 4 + axis])
{
extreme[axis].max = out[n * 4 + axis];
}
if (extreme[axis].min > out[n * 4 + axis])
{
extreme[axis].min = out[n * 4 + axis];
}
}
}
mesh.getScale(scaleBias); // reuse scaleBias
for (axis = 0; axis < 3; axis++)
{
extreme[axis].max *= scaleBias[axis];
extreme[axis].min *= scaleBias[axis];
}
return extreme;
}
 
 
public class MinMax
{
float min = 0f, max = 0f;
MinMax() {}
}
This page was last modified on 18 July 2012, at 12:10.
75 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved