PDA

View Full Version : calling glVertex*() on local coordinate system



jkj2000
05-25-2006, 12:46 AM
I asked this question a couple of days ago, and I'm grateful for the reply, but I still can't get this to work. I'll try explaining my situation again, hopefully a little more clearly this time.

I have a scene with a first-person view. At a point in the room there is a particle flying in a certain direction. I know the particle's origin in world space, as well as the "axes" for the particle, also in world space. These axes are mutually perpendicular and correspond to a local x,y and z coordinate system for the particle. The particle is traveling along its z-axis, in the negative direction.

I want to draw some surrounding geometry around this particle, using the particle's axes and origin as the reference for the commands. So in other words, when I say glVertex3f(1.0f,0.0f,0.0f) I want to place a vertex one unit in the x-direction along the particle's x axis....not along the world space x-axis.

I've tried everything I can think of, which admittedly isn't much. Among other things I've used gluLookAt() with the particle's origin values as the first three parameters, an appropriate look at point for the second three parameters, and the particle's y axis as the final three params. Nothing doing. I'm open to any and all suggestions on what I can/should be doing. Thanks very much.

memfr0b
05-26-2006, 05:57 AM
Create a matrix from the particles x, y, and z axes and origin. Multiply this matrix on top of the current matrix stack, and you're good to go.

Each axis goes into one column, which, considering opengl's matrix layout, means the coefficients occupy adjacent places in an array.

Suppose you have three vectors X, Y, Z and O, representing the particles axes and origin. Each has three fields x, y and z:


float matrix[16] = {
X.x, X.y, X.z, 0,
Y.x, Y.y, Y.z, 0,
Z.x, Z.y, Z.z, 0,
O.x, O.y, O.z, 0
};

glMultMatrixf(matrix);

glBegin(GL_POINTS);
glVertex3f(1, 0, 0);
glEnd();

jkj2000
05-27-2006, 01:12 AM
Thanks very much-- just what I was looking for. The only thing is, did you want the last value in the matrix to be a 1 and not a zero?