Archived

This topic is now archived and is closed to further replies.

mckracken

Problems with particles...

Recommended Posts

mckracken    122
I''ve made an algorithm to show always the polygon faceing to the camera.... here is the algorithm: posx,posy and posz are the position of the polygon. difx=CAM[actual].posx-posx; dify=CAM[actual].posy-posy; difz=CAM[actual].posz-posz; if (difz==0) { if (difx>=0) yaw=-3.14/2; else yaw=-3*3.14/2; if (dify>=0) pitch=-3.14/2; else pitch=-3*3.14/2; } else { yaw=-atan(difx/difz); pitch=-atan(dify/difz); } if (difz<0) { rotx=pitch*180/3.14+180; roty=yaw*180/3.14+180; } else { rotx=pitch*180/3.14; roty=-yaw*180/3.14+180; } glLoadIdentity(); gluLookAt(CAM[actual].posx, CAM[actual].posy,CAM[actual].posz, CAM[actual].x,CAM[actual].y, CAM[actual].z,0,1,0); glTranslatef(posx,posy,posz); glRotatef(rotx,1.0f,0.0f,0.0f); glRotatef(roty,0.0f,1.0f,0.0f); well... here is the problem... When the -1

Share this post


Link to post
Share on other sites
mckracken    122
damn it... some characters doesn''t work so well...
well... here is the problem... When difz is between -1 and 1, the algorithm doesn''t work any more!!! WHY??????!

Well.. see ya

Share this post


Link to post
Share on other sites
Nate    122
Try doing this, it should be a lot easier to use.

Get your current model view matrix from OpenGL.
glGetFloatv(GL_MODELVIEW_MATRIX, mat)

Take the transpose of that matrix and store it.
tmat = mat.Transpose().

Create two vectors, x and y, and set them as follows using the transposed matrix.
x.Set(tmat[0], tmat[1], tmat[2]);
y.Set(tmat[4], tmat[5], tmat[6]);

x is a vector that points right and y is a vector that points up. With these two vectors you can easily construct triangles that will always face the camera.

Hope this helps.

Nate Miller
http://nate.scuzzy.net

Share this post


Link to post
Share on other sites
Strylinys    122
I would have said that the value passed to atan has to be between 1 and -1 and by making the denominator a fraction, then it''s obviously not going to be very probable... At least that''s what I think right now... I''m a little brain fried since I have answered to and read so many posts today... (yesterday my connection was down {whine whine complain complain} )

S.

Share this post


Link to post
Share on other sites
mckracken    122
hahaha.... well.. thanks anyway...

I couldn''t solved the problem... Someone help me!!!
I don''t know how to use the matrix from Nate....
I saw that I have to use a pointer... but a pointer to what?
A pointer to an array?? A pointer to a structure?
And something else... I''m programming in c, not c++...
I''m not using classes....

well... thanks all of you...
Phew!! The people here are fantastic!!

See ya!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Strylinys

I would have said that the value passed to atan has to be between 1 and -1


uh, no. -PI/2 to PI/2.

Share this post


Link to post
Share on other sites