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
player.php?v=orjk2t%3E&s=8
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);
glEnable(GL_DEPTH_TEST);
while (!bQuit)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable( GL_TEXTURE_2D );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(curx, cury, curz,
hingx, hingy, hingz,
pinx, piny, pinz);
//glBindTexture( GL_TEXTURE_2D, loadtextures( "textures//basicsolarpanel.raw", FALSE, 100, 100) );
glBegin(GL_QUADS);
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;
return;
}
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.