I'm in need of testing if an axis oriented bounding box collides with a triangle (set of triangles as a terrain), and if it does - in which point. I found few algorithms on the internet, but I can't determine the intersection point, which is essential for me here.

Is there an algorithm to achieve what I need? Or maybe is there some method that suits this task better?

Thanks. ]]>

<www.opengl.org/wiki/GLAPI/glViewport>

xw = (xnd + 1) (width / 2) + x;

yw = (ynd + 1) (height / 2) + y;

First test: Assume x=0 and width=800, then the window coordinates go from 0 to 799.

xnd = 1 should result in the rightmost pixel 799.

xw ( 1 ) = ( 1 + 1 ) * 800 / 2 + 0 = 800; And not 799.

I derivated the formula for normalized device to window coordinates and came to a slightly different result

to replace "width" by "(width - 1)":

xw = (xnd + 1) ((width - 1) / 2) + x;

yw = (ynd + 1) ((height - 1) / 2) + y;

Here my derivation for glViewport( x, y, width, height ):

So the rectangle is from (x) to (x + width - 1), and from (y) to (y + height - 1).

Example: glViewport( 400, 200, 800, 600 ) has a rectangle from x: 400 to 1199, and y: 200 to 799.

Formula for x:

xw - x = xnd * a + b; // Linear equation, resolve a and b.

1. xnd = -1, and xw = x:

x - x = -1 * a + b; -> a = b;

2. xnd = +1, and xw = x + width - 1:

x + width - 1 - x = 1 * a + b; -> width - 1 = 2 a; -> a = ( width - 1 ) / 2;

Insert in formula for x:

xw - x = xnd * (width - 1) / 2 + (width - 1) / 2;

xw = ( xnd + 1 ) * (( width - 1 ) / 2 ) + x;

Test:

1. xnd = -1: xw = ( -1 + 1 ) * (( width - 1 ) / 2 ) + x = x; -> ok, 400 by the example.

2. xnd = +1: xw = ( 1 + 1 ) * (( width - 1 ) / 2 ) + x = width - 1 + x; -> ok, 1199 by the example.

Analogical for y. ]]>

If I want to rotate a mesh around a point (x,y,z) and the axis of the rotation is oriented by the vertex (vx,vy,vz), how can I get the matrix of this rotation, please? I use GLM in cas there is a function that can perform that directly.

Thanks

Cathy L. ]]>

If I want (using GLM) to perform the rotation of alpha radians of a mesh around the point (x,y,z) and with an axis orientation (of the rotation) is given by a vector (vx,vy,vz), how do I get the matrix for that, please?

Thanks a lot

Cathy L. ]]>

Any good implementation?

Thanks. ]]>

I have been moving from intermediate mode to to full opengl 3+, it has gone well but I still have a couple of issues to solve. One of the biggest I have is the move to having 4x4 transformation matrix.

I understand where the translation bits go, the rotation bits and the scaling bits go but I am a little unsure as to how best to handle the multiplication. I have a single 4x4 matrix with the scaling, rotation and translation all applied, lets say I have a bone skeleton and i want to work out the initial positions (So I need to multiply in a recursive way). When I multiply this out to work out the bones final positions I "should" (in my mind) just be able to multiply the 4x4 transformations but I don't think this is right.

The scale components effect the rotation components so I am thinking should I actually keep the scale, rotation and translation components separate and multiply these like I did before and only combine to a 4x4 at the very end when I have the final transformation, or am I talking rubbish and the 4x4 matrix multiplication should all work and there is a bug else where in my code? (I can't get my objects to draw correctly as they were before so there is definitely a problem somewhere).

To give you are idea of what I did before, this is the pseudo code for the transformation code I had before (scale, rotation and translation kept as separate items)

newXXX = the result of the multiplication

currentXXX = the current transformation values

toMultiplyXXX = the transformation to multiplied with

(newXXX = currentXXX * toMultiplyXXX)

newPosition = (currentRotation * toMultiplyPosition) + currentPosition

newRotation = currentRotation * toMultiplyRotation

newScale = currentScale * toMultipleScale ]]>

The problem is that after I rotate, my subsequent translations are to longer matched to the motions of the pointer on the screen, the axes are different.

Everything I've tried gives me one of two behaviors. One is equivalent to:

Code :

Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, Xposition, Yposition, 0.0f);
Matrix.rotateM(mModelMatrix, 0, rotationAngle, 0.0f, 0.0f, 1.0f);

This allows me to translate as expected (up/down on the screen moves the model up and down, left/right moves model left and right), regardless of rotation. The problem is that the rotation is about the center of the object, and I need the rotation to be about the point that I am looking at, which is different than the center of the object.

The other behavior I can get is equivalent to:

Code :

Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, rotationAngle, 0.0f, 0.0f, 1.0f);
Matrix.translateM(mModelMatrix, 0, Xposition, Yposition, 0.0f);

This gives me the rotation that I want, always about the point I am looking at. The problem is that after a rotation, the translations are wrong. Left/right on the screen translates the object at a different angle, along the rotated axes.

I need some way to get both behaviors at the same time. It needs to rotate about the point I am looking at, and translate in the direction that the finger moves on the screen.

In summary:

I have an object that starts at (0, 0, 0) in world coordinates. My view is looking down the z-axis at the object, and I want to limit translation to the x/y plane. I also want to rotate the object about the z-axis only. The center of the rotation must always be the center of the screen.

I am controlling the translation with the touch screen so I need the object to the same way the finger moves, regardless of how it it rotated. ]]>