Camera Roation

Started by
25 comments, last by Wavesonics 19 years, 8 months ago
Ok I'm having some trouble w\ my camera rotation. I know there are camera classes out there but I want to learn this. This cam will have no lateral roation or movement, just side to side rotation and forward and back translation. So this is what I got: For Input: if (keys[VK_UP]) // Is The Up Arrow Being Pressed? { ztranslate += sin((float)yangle) * .005; xtranslate += cos((float)yangle) * .005; } if (keys[VK_DOWN]) // Is The Down Arrow Being Pressed? { ztranslate -= sin((float)yangle) * .005; xtranslate -= cos((float)yangle) * .005; } if (keys[VK_RIGHT]) // Is The Right Arrow Being Pressed? { yangle += .01; } if (keys[VK_Left]) // Is The Left Arrow Being Pressed? { yangle -= .01; } This is what I have for the actual movement and rotation: // Move Camera glRotatef(yangle, 0.0f, 1.0f, 0.0f); glTranslatef(xtranslate, 0.0f, ztranslate); As you can see I leave the Y alone. Now the rotation is working great. The translation is the problem. The idea I have is I know the angle (yangle) of a right triangle. So I can use sin to get the Opp side which should b my Z cord and I can use Cos to get my Adj side which should b my X cord. then I multiplay by .005 so that I control the "speed" or distance of the translation. This just give me the point I want to move to right? So then I just plug that point into my glTranslate function and it just go, but it doesnt... Here take a look at the unpreditable responses: http://www.talentopoly.com/adam/UPLOADS/cpp/WinMain.exe it's not a virus, i'm not competent enough to program a virus, so dont worry.
==============================
A Developers Blog | Dark Rock Studios - My Site
Advertisement
Yeah but, where's your "look at" function...?
"Creativity requires you to murder your children." - Chris Crawford
I'm not using gluLookAt(); I'm doing the rotations and translations manual.
==============================
A Developers Blog | Dark Rock Studios - My Site
no ideas any one? Is my math wrong, is the application of the answer to the translation wrong? Plz I'm been working on this for hours and hours!
==============================
A Developers Blog | Dark Rock Studios - My Site
But... but... see, what ARE you rotating and translating? Do you see the problem?
"Creativity requires you to murder your children." - Chris Crawford
Well... the world. Everything, those come before i draw anything.
Take a look @ that sample prog I linked to, it almost works. It's just the direction of the translation is screwed up some times.
==============================
A Developers Blog | Dark Rock Studios - My Site
Okay, maybe the camera idea is a little vague. As far as I know there is no actual camera in OpenGL. It's a concept, nothing more.

Basically, according to your code, you aren't switching your matrix mode to projection. Therefore just calling rotate and translate out in the middle of nowhere will simply rotate and translate the last thing in the matrix stack, which could be anything at all, and not even the projection matrix.

Then again your code sample looks cut-n-pasted, so I can't tell if you're doing that or not.

What have you got against gluLookAt, anyway? ;)
"Creativity requires you to murder your children." - Chris Crawford
Hey there,

Try this
if (keys[VK_UP]) // Is The Up Arrow Being Pressed?{ztranslate -= sin((float)yangle) * .005;xtranslate += cos((float)yangle) * .005;}if (keys[VK_DOWN]) // Is The Down Arrow Being Pressed?{ztranslate += sin((float)yangle) * .005;xtranslate -= cos((float)yangle) * .005;}


The do your

glRotatef(yangle, 0.0f, 1.0f, 0.0f);glTranslatef(xtranslate, 0.0f, ztranslate);


If you walk the wrong way, then switch all of your += and -= around.

If you check out the law of sines, you'll see what you're doing wrong. Let me know if this helps!

PS: This is a great math tutorial to get this stuff sorted out.
Clicky
hehe i dont have anything against gluLookAt what I can't figure out is how to set the direction to look in correctly every time.

Ur right I didnt post the full code here, i coppied in snippets, but it's all my code if thats what u mean.

I'm not rotating the Projection Matrix. I'm rotating the modle view matrix as far as I know... I guess thats a problem huh...
==============================
A Developers Blog | Dark Rock Studios - My Site
Quote:Original post by Wavesonics
hehe i dont have anything against gluLookAt what I can't figure out is how to set the direction to look in correctly every time.

Ur right I didnt post the full code here, i coppied in snippets, but it's all my code if thats what u mean.

I'm not rotating the Projection Matrix. I'm rotating the modle view matrix as far as I know... I guess thats a problem huh...


No, you're going to want to use the ModelView matrix.

This topic is closed to new replies.

Advertisement