This page was last modified 12:50, 3 November 2007.
Get the bounding box of a jsr 184 mesh
From Forum Nokia Wiki
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() {} }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| M3G (JSR 184) Detail about External Reference in m3g file | amitian | Mobile Java Media (Graphics & Sounds) | 1 | 2004-12-28 14:50 |
| FPS | stenlik | General Symbian C++ | 18 | 2007-11-20 16:10 |
| 欢迎加入I4Game精品游戏开发团队 | I4Game_Chanking | Other Programming Discussion 关于其他编程技术的讨论 | 0 | 2006-09-05 16:31 |
| 6280 and jsr-75 | per.lundberg | Mobile Java Networking & Messaging & Security | 16 | 2006-04-18 09:49 |
| implementation of JSR 253 | bd.garg | Mobile Java Tools & SDKs | 4 | 2007-10-05 23:50 |
