rotations... (center of rotation)
hi fella''s,
i loaded a CS(counter strike) type(gun with arms) weapon model and have it set to move with the camera on the x and z, now, my problem is, no matter how i try to rotate it, i cant keep it in the lower right corner... heres how i draw it to the screen...
glTranslatef(0.06f+xpos,-0.17f+ypos, -0.2f+zpos);
glRotatef(lookupdown,-2.0f,0,0);
glRotatef(sceneroty,0,-2.0f,0);
pModel->draw();
glLoadIdentity();
that rotates it perfect with the cam, but... it wont rotate arround me, it just stays in its old spot, so when i look right, it looks like i switch the gun to my left hand, if i turn 180degrees, i cant ven se the gun because its -.2 infront of me, im thinking the problem is in glTranslatef(*,*, -0.2f+zpos); because it keeps it -0.2 into z ahead of me, but i dont see how i could fix that, and still have the gun infront of the cam.... im really confuse, and going with no sleep here =/ and i probably wont have sleep till this is fixed hehe.
thanx in advance,
dirtypope
Theres no such thing as stupid people... only people with under clocked brains. -dirty
updateposition();
drawscene();
glPushMatrix();
glTranslatef(0.06f,-0.17f, -0.2f);
glRotatef(lookupdown,-2.0f,0,0);
glRotatef(sceneroty,0,-2.0f,0);
pModel->draw();
glPopMatrix();
Pushing the matirx wil protext the rest of the prgram from being affected by the translatef() call.

~prevail by daring to fail~
updateposition();
drawscene();
are undeclared identifiers, (probably somthing specific in your code)
and then the rest of it did exactly what it was doing before, except it dodnt move on x and z with me....
drawscene();
are undeclared identifiers, (probably somthing specific in your code)
and then the rest of it did exactly what it was doing before, except it dodnt move on x and z with me....
Theres no such thing as stupid people... only people with under clocked brains. -dirty
Lol there just pointer to u for program flow they artn funtions, also the gltranslated and rotat values are just samples and wont worj for ure engine
//update ure position
//draw the scene
glPushMatrix();
glTranslatef(0.06f,-0.17f, -0.2f);
glRotatef(lookupdown,-2.0f,0,0);
glRotatef(sceneroty,0,-2.0f,0);
pModel->draw();
glPopMatrix();

~prevail by daring to fail~
//update ure position
//draw the scene
glPushMatrix();
glTranslatef(0.06f,-0.17f, -0.2f);
glRotatef(lookupdown,-2.0f,0,0);
glRotatef(sceneroty,0,-2.0f,0);
pModel->draw();
glPopMatrix();

~prevail by daring to fail~
mmkay heres what i have...
glRotatef(lookupdown,-1,0,0);
glRotatef(sceneroty,0,-1.0f,0);
glTranslatef(0.06f+xpos,0.18f, -0.23f+zpos);
glPushMatrix();
pModel->draw();
glLoadIdentity();
glPopMatrix();
this will rotate it exactly how i want it horizontally, as long as im on x0 and z0 when im off those, it rotates arround them, just at my distance from x0 z0, is there a way i can update the center of rotation to be my x and z... and the vertical rotation works the same way as the horiz, but theres another problem, if im not facing -z it will rotate the gun all whacked out =(
man this is annoying me...
*punches monitor*
glRotatef(lookupdown,-1,0,0);
glRotatef(sceneroty,0,-1.0f,0);
glTranslatef(0.06f+xpos,0.18f, -0.23f+zpos);
glPushMatrix();
pModel->draw();
glLoadIdentity();
glPopMatrix();
this will rotate it exactly how i want it horizontally, as long as im on x0 and z0 when im off those, it rotates arround them, just at my distance from x0 z0, is there a way i can update the center of rotation to be my x and z... and the vertical rotation works the same way as the horiz, but theres another problem, if im not facing -z it will rotate the gun all whacked out =(
man this is annoying me...
*punches monitor*
Theres no such thing as stupid people... only people with under clocked brains. -dirty
I think you saw my posts on the other thread but I repeat here with a little explanation since your post here is newer:
azim: azimuthal. meaning the angle lying in XY plane. from the x-axis to y-axis.
elev: elevation. meaning the angle between XY plane and the direction of look vector. from XY plane to DOL vector.
Here is the code with line numbers:
[1] glPushMatrix();
[2] glTranslated(Player.Phys.eyex, Player.Phys.eyey, Player.Phys.eyez);
[3] glRotated(Player.Phys.azim*180.0/3.141592, 0.0, 0.0, 1.0);
[4] glRotated(-Player.Phys.elev*180.0/3.141592, 0.0, 1.0, 0.0);
[5] //DrawGunModel()
[6] glPopMatrix();
[1]: Push the current modelview matrix
[2]: Translate to where eye is
[3]: Rotate around the z-axis first. The amount is azimuthal angle
[4]: After rotating around the z-axis, now rotate around the y axis. amount is elevation angle
[5]: Draw the gun. There should be no problem here since most games have same definition of gun model coordinates.
[6]: Restore modelview matrix.
>>>NOTE THAT YOU HAVE TO ROTATE AROUND Z AXIS FIRST !!!. The order of rotations is important. If I rotate around Y axis and then rotate around Z axis results will be different(i.e. AxB != BxA for any A, B matrices)
>>>DO NOT TRANSLATE ANYWHERE DIFFERENT THEN YOUR EYE COORDINATE. If the gun should be biased, do this when you are loading the gun model.
>>>LAST NOTE: WHY LOAD IDENTITY IF YOU ARE GOING TO POP MATRIX???
It is useless and is just extra work without effect
Also I have to say that I use Z axis as the "UP" axis.
If you have problems with azim and elev here is how I use them to determine direction of look.(Actually I am not sure about the definitions I presented above, so below ones are better if you want to understand since they are directly from code)
Player.Phys.dirx = cos(Player.Phys.azim)*cos(Player.Phys.elev);
Player.Phys.diry = sin(Player.Phys.azim)*cos(Player.Phys.elev);
Player.Phys.dirz = sin(Player.Phys.elev);
Be good to your monitor, calm down, get a drink, see your girlfriend, blah, blah ...
azim: azimuthal. meaning the angle lying in XY plane. from the x-axis to y-axis.
elev: elevation. meaning the angle between XY plane and the direction of look vector. from XY plane to DOL vector.
Here is the code with line numbers:
[1] glPushMatrix();
[2] glTranslated(Player.Phys.eyex, Player.Phys.eyey, Player.Phys.eyez);
[3] glRotated(Player.Phys.azim*180.0/3.141592, 0.0, 0.0, 1.0);
[4] glRotated(-Player.Phys.elev*180.0/3.141592, 0.0, 1.0, 0.0);
[5] //DrawGunModel()
[6] glPopMatrix();
[1]: Push the current modelview matrix
[2]: Translate to where eye is
[3]: Rotate around the z-axis first. The amount is azimuthal angle
[4]: After rotating around the z-axis, now rotate around the y axis. amount is elevation angle
[5]: Draw the gun. There should be no problem here since most games have same definition of gun model coordinates.
[6]: Restore modelview matrix.
>>>NOTE THAT YOU HAVE TO ROTATE AROUND Z AXIS FIRST !!!. The order of rotations is important. If I rotate around Y axis and then rotate around Z axis results will be different(i.e. AxB != BxA for any A, B matrices)
>>>DO NOT TRANSLATE ANYWHERE DIFFERENT THEN YOUR EYE COORDINATE. If the gun should be biased, do this when you are loading the gun model.
>>>LAST NOTE: WHY LOAD IDENTITY IF YOU ARE GOING TO POP MATRIX???
It is useless and is just extra work without effect

Also I have to say that I use Z axis as the "UP" axis.
If you have problems with azim and elev here is how I use them to determine direction of look.(Actually I am not sure about the definitions I presented above, so below ones are better if you want to understand since they are directly from code)
Player.Phys.dirx = cos(Player.Phys.azim)*cos(Player.Phys.elev);
Player.Phys.diry = sin(Player.Phys.azim)*cos(Player.Phys.elev);
Player.Phys.dirz = sin(Player.Phys.elev);
Be good to your monitor, calm down, get a drink, see your girlfriend, blah, blah ...

Step one: Move the player. (Note: Player != Gun!) This is to set up the position on where your character is.
glTranslate(xpos, 0, zpos);
Step two: Rotate the scene/camera. After all, we want the gun to appear in front of you, so we must rotate first to see what direction you''ll be in...
glRotatef(sceneroty, 0, -1.0f, 0);
Step three: Rotate the eyes. A.k.a., look down or up. We want to draw the gun after we do the appropriate translation so the gun is always in front of our eyes.
glRotatef(lookupdown,-1,0,0);
THIS IS A WAYPOINT, because this sets up perfectly the player''s viewpoint in the game so push the matrix...
glPushMatrix();
Step four: Translate to account for the gun.
glTranslatef(0.06f, 0.18f, -0.23f);
Step five: Now we''re read to draw the gun, so draw it...
pModel->draw();
Step six: Jump back to the player''s view
glPopMatrix();
Done.
Dragonus
Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
glTranslate(xpos, 0, zpos);
Step two: Rotate the scene/camera. After all, we want the gun to appear in front of you, so we must rotate first to see what direction you''ll be in...
glRotatef(sceneroty, 0, -1.0f, 0);
Step three: Rotate the eyes. A.k.a., look down or up. We want to draw the gun after we do the appropriate translation so the gun is always in front of our eyes.
glRotatef(lookupdown,-1,0,0);
THIS IS A WAYPOINT, because this sets up perfectly the player''s viewpoint in the game so push the matrix...
glPushMatrix();
Step four: Translate to account for the gun.
glTranslatef(0.06f, 0.18f, -0.23f);
Step five: Now we''re read to draw the gun, so draw it...
pModel->draw();
Step six: Jump back to the player''s view
glPopMatrix();
Done.
Dragonus

Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
dragonus, your method works great for horizontal rotation, but the verticle only works good if im staring into -z, is there a way i can like, rotate the rotation? to keep it rotating as if i were constantly looking into -z...
thank you everyone for all of your help...
dirtypope
thank you everyone for all of your help...
dirtypope
Theres no such thing as stupid people... only people with under clocked brains. -dirty
Theoetically, we are rotating the -z axis so that it''s in front of you regardless where you look...
Would you mind giving me a little more detail as to what is going on in the vertical direction? (I assume by vertical you''re talking about looking up/down at the point, as in above and below the plane xz-plane.)
Dragonus
Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
Would you mind giving me a little more detail as to what is going on in the vertical direction? (I assume by vertical you''re talking about looking up/down at the point, as in above and below the plane xz-plane.)
Dragonus

Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
ok, heres what goes on, when i start im facing the -z, and vertical (up/down) rotations work great, then say i turn exactly 180 degrees, up becomes down and vice versa, so if i look up, the gun looks down, and if im at 90 degrees the gun rotates side ways, so im assuming i have to some how rotate the actual z to make -z infront at all times, im just hoping this doesnt have any side effects to anything else i need to do, like gravity or coldet,
Edited by - dirtypope on August 20, 2001 9:20:42 PM
Edited by - dirtypope on August 20, 2001 9:20:42 PM
Theres no such thing as stupid people... only people with under clocked brains. -dirty
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement