Coordinate transformation

Hi there !!

First, hello to all the OpenGL-Coders !
Next, my problem: I wrote a small particle animation using 2D Textures. So, when I set my Viewpoint in front of the particles, I see them clearly. As I set the Viewpoint on Top, I can’t see anything becouse these particles are only 2-dimensional. Has anybody an idea for rotating each particle to the coordinates of my eye-point like doing a coordinate transformation ? Please help me!!!

Hi!

Setting your viewpoint on top means you are rotatting your camera 90º. You should try to glRotate all the particles the opposite angle, -90º. Remember to put this rotation matrix at the end of your transformations.

  • nemesis -

Well, thanks.
But how is the Rotation of the PArticles done ? As I used glRotate, all the Scene was rotated, but not every single Particle. So, where is it to be done every single Particle is rotated ? For Info: I got a loop to draw the Particles by using Triangle Strips.

Ok,

you should do something like this:

for each particle
glPushMatrix();
glTranslate the particle
glRotate the particle 90º
draw the particle
glPopMatrix();
end for

I think it should work.

  • nemesis -

Wow, it works. Its a little slow, but it works.

Thanks a lot !!

hi, there is some calculation stuff for this problem in the internet too… here is it:

void buildRot(float theta, float x, float y, float z, float m[16]) {
float d = xx + yy + z*z;
float ct = cosf(theta * 3.141592654f / 180), st = sinf(theta * 3.141592654f / 180);

/* normalize */
if (d > 0)
{
d = 1/d;
x *= d;
y *= d;
z *= d;
}

m[ 0] = 1; m[ 1] = 0; m[ 2] = 0; m[ 3] = 0;
m[ 4] = 0; m[ 5] = 1; m[ 6] = 0; m[ 7] = 0;
m[ 8] = 0; m[ 9] = 0; m[10] = 1; m[11] = 0;
m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;

/* R = uu’ + cos(theta)*(I-uu’) + sin(theta)*S
*

  • S = 0 -z y u’ = (x, y, z)
  • z 0 -x
  • -y x 0
    */

m[0] = xx + ct(1-xx) + st0;
m[4] = xy + ct(0-xy) + st-z;
m[8] = xz + ct(0-xz) + sty;

m[1] = yx + ct(0-yx) + stz;
m[5] = yy + ct(1-yy) + st0;
m[9] = yz + ct(0-yz) + st-x;

m[2] = zx + ct(0-zx) + st-y;
m[6] = zy + ct(0-zy) + stx;
m[10]= zz + ct(1-zz) + st0;
}

/2d object dreht sich in immer in eine richtung/

static void CalcMatrix(void) {
float mat[16];

glGetFloatv(GL_MODELVIEW_MATRIX, mat);
buildRot(-180*atan2f(mat[8], mat[10])/3.141592654f, 0, 1, 0, mat);
glMultMatrixf(mat);
}

dont know if it’s faster… but i use it ggg

If you get the current modelview matrix by calling
glGetFloatv(GL_MODELVIEW_MATRIX, your_array_to_hold_matrix_info);

and then build right and up vectors from this matrix, then render your particles as triangle strips using the point they exist at and then adding/subtracting (depending on the vertex) the right and up vectors you will obtain a tri strip that faces the camera (under all circumstances).

I think Nate Miller’s programming page is where I found this technique, you could try looking there for more info.

-Mezz

Thanks Mezz for your Posting ,
but sorry Im a raw newbie on OpenGL. COuld you please explain me how to do this by posting Code or something like that ?

Hi again!

about how to speed up your program…
If you don’t usually move the camera, I mean, if you are not moving around all the time, it might be better to really rotate your particle geometry (I supose you only have one particle model, do you?) every time you move the camera before start rendering. This way, you can avoid the glRotate command in the loop.
I think you could use the code posted by Mofux, or something similar, to build your own rotation matrix.
I don’t know if it will be useful in your case.

  • nemesis -

[This message has been edited by nemesis (edited 11-29-2001).]

Thanks Mezz for your Posting ,
but sorry Im a raw newbie on OpenGL. COuld you please explain me how to do this by posting Code or something like that ?