Skip to main content
gamedev.net
🔒 Locked

rotation question

Started by nitzan Nov 19, 2003 at 2:14 PM 0 replies 300+ views
Original Post
nitzan
nitzan
I have a spiral of particles that I want to place in my game. I also want each particle to always face the player regardless of its position or rotation relative to the spiral. Pseudo code: camera->view translate particle spiral rotate particle spiral for each particle { pushMatrix() rotate by particle''s angle translate particle rotate by particle''s -angle camera->unview (rotation only) popMatrix } The problem I am having is that the particles look great as long as the spiral rotation is 0,0,0. If I try to rotate the spiral, the particles no longer consistently face the player. I realize that I have to "undo" the spiral''s rotation, but I cant seem to figure out where to place "UNrotate particle spiral". I thought it would go with "rotate by particle''s -angle" and "camera->unview", but that doesnt seem to work. Can anyone offer any help ? Thanks, Nitzan
RipTorn
RipTorn
can I suggest you render you particles in a slightly different way?
I realise this might be annoying but it will liky help you solve this problem and also more in the future and also likly be a lot faster...

you currently use pushMatrix..popMatrix for each particle, and I guess, also use glTranslate, glRotate, etc, for each as well.. Honestly, this is quite slow and difficult to debug when things go wrong.

I guess you already have your particle positions stored? then, what you can do is work out where 4 vertices should be to create a front facing particle for the entire particle emitter (or even entire scene) and then go through each particle, draw 4 vertices with each being the particle position plus each of those 4 positions.
There is a nice easy way you can get there values too, through the modelview matrix:




//these are the two vertex offsets that can make a front facing particle (negative makes the other 2 verts) - they should be stored someplace.. computed when settings the camera

float vec1[3], vec2[3];



float mvMat[16];

glGetFloatv(GL_MODELVIEW_MATRIX,mvMat);


vec1[0] = mat[0] + mat[4];
vec1[1] = mat[1] + mat[5];
vec1[2] = mat[2] + mat[6];

vec2[0] = -mat[0] + mat[4];
vec2[1] = -mat[1] + mat[5];
vec2[2] = -mat[2] + mat[6];




ok, then when you render a particle (as quads), it would just be:




float x= ,y= ,z=; // particle position - I assume they are set...


glVertex(x + vec1[0] , y + vec1[1] , z + vec1[2]);
glVertex(x + vec2[0] , y + vec2[1] , z + vec2[2]);
glVertex(x - vec2[0] , y - vec2[1] , z - vec2[2]);
glVertex(x - vec1[0] , y - vec1[1] , z - vec1[2]);



vec1 and vec two should be scaled to the size of the particle of course.

The reason it works is because in the modelview matrix mat[0],mat[1] and mat[2] are effectivly a vector pointing ''left'' and mat[4], mat[5], and mat[6], effectivly point ''up''.. so you combine them you get up-left and down-left.. negate them and you then get down-right and up-right.. all relitive to the direction you are looking (hence useful in rendering sprites).

I can''t guarentee that code worked btw, I wrote it as is just then so I can''t say it will work.




| - Project-X - On hold (kindof ).. - | - adDeath - | - my windows XP theme
- | - email me - |

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.