Joined: Sat Feb 24, 2007 11:17 pm Posts: 2704 Location: The Aussie Land
Here's my axis-aligned bounding-box code (lots of trial and error ). I was wondering if there was a less cpu intensive way of doing it, or atleast do it in less code? or if there are any unnecessary statements?
What it does is peek at the matrix on the matrix stack and pulls it into an array. In OpenGL each number in the matrix (16 in total) has a different role in getting the object to render the right way, but the important ones are the rotation ones [0],[1],[4] and [5]. So i make a temporary Rectangle (my own class called "Quad" is the same as a Rect but uses 4 points rather than 2).
These values are like sin,cos and tan on the unit circle. They only go from 0 to 1, and stretch/shrink in relation to the rotation. Each one of my calculations calculates the x value of each point on the rectangle, then each y values of the same points, by multiplying it with the width or height respectively.
Then it iterates through all the combinations and gets the min/max x/y values.
I'm bad at geometry/specialist maths so this was the only way i could think of. I especially don't like the part where you have to loop through all the combinations. I was wondering if there was an algorithm of some sort.
Any advice would be appreciated Thanks!!!
Code:
Code:
public void calculate(Quad aabb, GL gl) { float[] matrix = new float[16]; gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0);
Although this is the fastest version of collision detection, im still looking for how to do rotated rectangle collision and pixel-perfect collision. For when higher-precision is required.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum