PDA

View Full Version : Coordinate transformation

Infamous
11-27-2001, 10:27 PM
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!!!

nemesis
11-27-2001, 11:29 PM
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 -

Infamous
11-28-2001, 12:23 AM
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.

nemesis
11-28-2001, 12:40 AM
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 -

Infamous
11-28-2001, 12:52 AM
Wow, it works. Its a little slow, but it works.

Thanks a lot !!

MofuX
11-28-2001, 03:58 AM
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 = x*x + y*y + 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] = x*x + ct*(1-x*x) + st*0;
m[4] = x*y + ct*(0-x*y) + st*-z;
m[8] = x*z + ct*(0-x*z) + st*y;

m[1] = y*x + ct*(0-y*x) + st*z;
m[5] = y*y + ct*(1-y*y) + st*0;
m[9] = y*z + ct*(0-y*z) + st*-x;

m[2] = z*x + ct*(0-z*x) + st*-y;
m[6] = z*y + ct*(0-z*y) + st*x;
m[10]= z*z + ct*(1-z*z) + st*0;
}

/*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*

Mezz
11-28-2001, 01:39 PM
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

Infamous
11-28-2001, 10:17 PM
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 ?

nemesis
11-28-2001, 11:51 PM
Hi again!