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

OpenGL problem?

Started by Hydra13 Feb 27, 2003 at 12:27 AM 13 replies 2.4k views
Original Post
Hydra13
Hydra13
I am trying to make my triangle move on the X axis and the Y axis but it isnt working... it only moves on the X axis, could someone help me out. Code is: case WM_KEYDOWN: { keys[wParam] = TRUE; if (keys[VK_LEFT]) { glRotatef(rtri,1.0f,0.0f,0.0f); rtri-=3.0f; } else if(keys[VK_RIGHT]) { glRotatef(rtri,1.0f,0.0f,0.0f); rtri+=3.0f; } glRotatef(rtri,0.0f,1.0f,0.0f); glLoadIdentity(); if (keys[VK_UP]) { glRotatef(rtri,0.0f,1.0f,0.0f); rtri+=3.0f; } else if(keys[VK_DOWN]) { glRotatef(rtri,0.0f,1.0f,0.0f); rtri-=3.0f; }
Cat_B
Cat_B
glRotatef(rtri,0.0f,1.0f,0.0f);
glLoadIdentity();


well, I''m not sure of your program, but why do you do these commands in the middle? Try putting the loadidentity at the top and forgetting the other line. You also say you want to "move on the x axis" If you want to move in a straight line us glTranslate not glRotate. Anyway, just my 2 cents.
Hydra13
Hydra13
Oh... sorry i wasn''t clear enough.... i want to rotate it on the x axis!
Hydra13
Hydra13
I hope people are still reading here... but i want the triangle''s y axis to move like when they hit down it rotates downward...when they hit up rotate upwards, but when i hit up or down it still goes to the left or right!?
Cat_B
Cat_B
You mean rotate "around" the x axis (the x axis is the line going right-left and you want your triangle to swing around that line) Same advice as above- move loadIdentity to the top and delete the other line.
Hydra13
Hydra13
I did that but it still doesnt work
Cat_B
Cat_B
do you have a case WM_KEYUP where you set the key to false?
Hydra13
Hydra13
This is before that other statement:


case WM_KEYUP:
{
keys[wParam] = FALSE;
return 0;
}
RipTorn
RipTorn
sorry. I can''t help but think that the code you just posted is unsavable.
the fact you think it''s a bug in GL suggests to me you have A LOT to learn.

I know it''s harsh but it''s true.

consider getting a good C++ book and reading about matrices then move onto GL once you are confident there.

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |
RipTorn
RipTorn
yeah. I know. and I appologize. I''m not really in the mood for sugar coating my replies tonight

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |
lowlevel
lowlevel
Do you know what glLoadIdentity() does? It doesn''t seem like it or you wouldn''t put it right after a glRotatef(). Find out what it does.

You seem to have missunderstood rotations, and what rotation around an axis mean.

Imagine a drilling machine. Think of the drill as for example the x-axis. You have just drilled through a cube. If you start your drilling machine and let the cube rotate along with the drill, you have rotation around the x-axis.

Ofcourse this example applies the y-axis and z-axis too.
cowsarenotevil
cowsarenotevil
You actually can do a surprising amount without understanding matrices..... they''re good to know, but opengl''s functions generally don''t require you to understand them.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
cowsarenotevil
cowsarenotevil
You actually can do a surprising amount without understanding matrices..... they''re good to know, but opengl''s functions generally don''t require you to understand them.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-

Topic Locked

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

Sign in to reply to this topic.