View Full Version : Need help with x axis movement without using Model or Proj - using glLookAt

09-12-2014, 11:09 AM
Trying to understand the math with movements. Right now when I move straight left or right, the object curves off screen instead of going straight. I currently have virtical and horizontal rotation working, using cos and math.h and adjusting glLookAt.

This is at tinypic, if anyone wants to watch the video of my problem + what I have working
The start of this video shows the issue I am having. The end shows what I have working, I have not used glrotatef or gltranslatef.

gluPerspective(20.f,1.0f, 1.0f, 1000.0f);
while (!bQuit)
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
if (msg.message == WM_QUIT)
bQuit = TRUE;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable( GL_TEXTURE_2D );
gluLookAt(curx, cury, curz,
hingx, hingy, hingz,
pinx, piny, pinz);

//glBindTexture( GL_TEXTURE_2D, loadtextures( "textures//basicsolarpanel.raw", FALSE, 100, 100) );
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.2f, 0.2f, 0.0f);
glVertex3f(0.2f, -0.2f, 0.0f);
glVertex3f(-0.2f, -0.2f, 0.0f);
glVertex3f(-0.2f, 0.2f, 0.0f);

void leftright() {
curx -= 0.1*hordir; //hordir in this example can be thought of as +1 or -1 depending on direction
hingx -= 0.1*hordir;
pinx -= 0.1*hordir;

Once I get the above working on left and right movement, I would eventually like to change it to something like

if (horang!= 0.0){
temphold = 90.0 + horang;
temphold = cos((temphold*3.141592654)/180);
curx = curx - ((temphold*2.0)*hordir);
hingx = hingx - ((temphold*2.0)*hordir);
pinx = pinx - ((temphold*2.0)*hordir);
temphold = 180.0 - horang;
temphold = cos((temphold*3.141592654)/180);
curz = curz - ((temphold*2.0)*hordir);
hingz = hingz - ((temphold*2.0)*hordir);
pinz = pinz - ((temphold*2.0)*hordir);
hordir = 0;
else {
curx -= 0.1*hordir;
hingx -= 0.1*hordir;
pinx -= 0.1*hordir;


Any help would be nice, I'd like to avoid using glTranslatef and glrotatef.

carsten neumann
09-12-2014, 11:34 AM
The first 6 arguments to gluLookAt specify positions (eye and center respectively) and as such should be affected by translations, the last three arguments are the up direction and should not be affected by a translation. For your code that means if you want to perform a translation in (world) x direction only change curx, hingx.

09-12-2014, 11:42 AM
Wow, that was easy and I feel stupid.
Got it working, tyvm.