Skip to main content
GameDev.net gamedev.net
🔒 Locked

Object rotation

Started by Lode Aug 4, 2002 at 1:32 PM 3 replies 400+ views
Original Post
Lode
Lode
I can rotate the camera already (oh yeah! ) but rotating and object is confusing me. Say I know the direction a spaceship should have (given as a vector) and it''s position, and then I want to draw it''s triangles, how do I calculate the position of each vertex? PS I''m working in OpenGL (and c++)
PouyaCat
PouyaCat
Well, rotating the camera implies doing:

translatef()
rotatef()
rotatef()
rotatef()

Thus, you are at a point, and looking in a certain direction.

Now, if you want to place your object, you simply do:
translatef() // move to location of object
rotatef() // rotates all verti
rotatef()
rotatef()

Baiscly, you tell the vertex to orientate itself at the translatef() point, and *then* rotate ^_^

So, your vertex at (1, 0, 0) relative to the ship location, is first translated away because of the camera stuff. Then, the ships location (x, y, z) is filled into the translatef() as well to move the cursor to where the ship would be... And then you rotate
thewayout_is_through
thewayout_is_through
Short semi-proper answer:

Your models' vertices are local cords, they govern only that object space. You can place and rotate the object (a reference for the local cord system's orientation in word space, not the vertices!) and then when the local cords for the vertices are placed into world space they will reflect the rotation.


The in other words answer:

If you rotate the vectors representing the local cords in world space, then recreate the vertices along the rotated local cords you get all of them rotated properly with repect to one another in world space.


(I just hate typing co-ord as an abbv. )

[edited by - thewayout_is_through on August 4, 2002 10:49:33 PM]
"Who are you, and how did you get in here?""I''m the locksmith, and I''m the locksmith."
Lode
Lode
Hmm now I'm even more confused

First I rotate the camera with:

gluLookAt(0,0,0,cam.dir.x,cam.dir.y,cam.dir.z,cam.v.x,cam.v.y,cam.v.z);

(it's position is always 0,0,0 and I translate the world instead to avoid zbuffer problems if my spaceship is far away from the origin)

Then drawing planets isn't difficult, because I don't need to rotate them, only the camera can rotate, and that all works perfectly.

But now I want to draw enemy ships and they're able to rotate, but I only know their rotation in the form of a vector (this vector is the direction they're looking at and is similar to the camera direction vector, I may have to add a v vector for enemy ships to allow them to roll). Using glRotatef doesn't work because that one wants eucledian coordinates (I think) while I only know a direction the ship is looking at.

And using a gluLookAt gives me some "WTF???" results and would also screw up my original camera direction if I want to draw other things that aren't rotated.

What's the proper way to do this?

Oh and another thing that seems to be happening is that the objects I try to rotate are flickering all the time, what could be causing that?

[edited by - Lode on August 5, 2002 8:56:51 AM]
silvero
silvero
read ogl geometry commands from the bottom to the top (in contrast to DirectX). If you have something like

glLoadIdentity
//start geometry commands
glRotate
glTranslate
//end geometry commands
glVertex

the vertex starts at (0,0,0), translated from the origin and then rotated around the origin

if your code is like
glLoadIdentity
glTranslate
glRotate
glVertex

the vertex is rotated around its own axis and then translated only.

Don''t use Glulookat if you dont really have to, the standard setting viewing in (0,0,-1) direction. Therefore the first call should be something like glTranslate(0,0,-20), then you will be able to see anything you drew before.

Topic Locked

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

Sign in to reply to this topic.