PDA

View Full Version : Basic Scene Movement Problem



CoolBeanJ
04-20-2011, 04:20 PM
Hi i'm currently having a problem moving my scene up and down and i was wondering if you could tell me whats wrong with my code.

BTW this works at first but after rotating the scene around and zooming in etc it doesn't.



if (panUp)
{
float xrotrad;
xrotrad = (xrot / 180 * 3.141592654f);
ypos -= (float)((Math.Cos(xrotrad)) * cameraSpeed * 2);
zpos -= (float)((Math.Sin(xrotrad)) * cameraSpeed * 2);

}
if (panDown)
{
float xrotrad;
xrotrad = (xrot / 180 * 3.141592654f);
ypos += (float)((Math.Cos(xrotrad)) * cameraSpeed * 2);
zpos += (float)((Math.Sin(xrotrad)) * cameraSpeed * 2);
}

thanks

mobeen
04-20-2011, 09:37 PM
You should use the camera up and right vectors. When moving up/down, move in the direction of the camera up vector and vice versa for right/left.

CoolBeanJ
04-20-2011, 10:01 PM
I was following the tutorial located here:

http://www.swiftless.com/tutorials/opengl/camera2.html

which explains left and right movement and it works prefectly, but it doesn't explain up and down so i was hoping it would be as simple as swaping them.

I don't actually have a camera, i'm just moving the scene with glRotatef and gltranslated. Sorry for not explaining that clearly.

candela
04-21-2011, 12:02 AM
Alternativelly, rather than applying rotation/translations to whole sceen objects, I also would like know how is that movement (preferably SpinBall or ArcBall rotation) implemented with gluLookAt function?

Cause I've function like that but the scene objects instantly goes away from focus. I'm aware that I'm relying on the screen coordinates instead of world coordinates to minimize them I multiply them with arbitrary small number (0.001 is in case), anyway that doesn't produced the movement effect that I want ?


void motion_func(int x, int y) {
glLoadIdentity();
gluLookAt(0.001*(x-mousex),0.001*( y-mousey), 0.2
, 0, 0, 0
, 0, 1, 0);

mousex = x; mousey = y;
glutPostRedisplay();
}

CoolBeanJ
04-21-2011, 01:03 AM
OH! I think i worked it out!

I was rotating the scene and then moving.

Now that i'm moving then rotating it seems to work. Would that be possible?