🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Moving in a 3D scene

Started by
6 comments, last by ichor 24 years ago
Man... I hope I have something wrong in my theory or something, ''cause I can''t get this working no matter what I do. Here''s what I''m trying to do: I have created a 10x10 matrix to store objects in. All the objects (at the current time) are hardcoded into the program, but it works fine, and creates a "3D world." Now, I''m having a heck of a time MOVING in the world. I''m just trying to move FORWARD right now... Here''s what I have: if (keys[VK_UP]) { translateZ += 0.5f; glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(translateX, translateY, translateZ); drawObjects(); } That doesn''t work. When I press up, nothing happens. (I put a MessageBox in there to make sure the if was being executed, as it is.) Has anybody had similiar problems? I''ve been working at this for a LONG time, and can''t figure it out... I''m not really going for a real efficient way to make it work, just the easiest way, as I am new to OpenGL. Any suggestions? Thanks!
Advertisement
Is lighting on ?
Are you sure you''re moving in the right direction do see the objects ?

Have you set objects color porperties (material) ?

What is the matrix you''re using ?
(You need to use the modelview matrix, I think)

Hope it helps.

-* So many things to do, so few time to spend *-
-* So many things to do, so little time to spend. *-
Lighting is whatever default is if you don''t specify anything. I can see all my objects perfectly (in front of me), though.

As far as Matrix ... glMatrixMode(GL_MODELVIEW);
That''s what I use. I''m not experienced enough with OpenGL to know if that''s the one I should be using... To be honest, I''m not even sure what THAT does.

And, it should be moving in the correct direction, yes... but nothing at all changes when I press the key... really not sure what else could be wrong.

Any other ideas? =)
do you glLoadIdentity() in drawObjects() ??
and where do you swap the buffers ??

thats the only two posibile errors can guess on in the code you posted.
Ries
Are you sure you don''t reset the matrix before drawing ?
(you can find me on IRC : #opengl on undernet)
Sorry misunderstood your post I thought you''re having a black screen.

No more idea than those already posted, sorry.

-* So many things to do, so few time to spend *-
-* So many things to do, so little time to spend. *-
For glLoadIdentity() in drawObjects(). No, it wasn''t in there, so I added it (in case it was supposed to be), and it still didn''t work...so I took it back out.

drawObject() has variables for x,y,z for where to draw the objects, then a glTranslate(transX, transY, transZ) --separate x y and z than with drawing the objects. Then it just draws cubes from an array.

As for SwapBuffers()...it''s done in WinMain (that part of the code is taken from the NeHe tutorials).

And for reseting the matrix... I don''t think I do. The upArrow event is in the first post, and the drawObjects() looks like this (scaled down a bit):

void drawObjects()
{
float zAxis = -15.0f;
float xAxis = -7.0f;
float yAxis = 0.0f;

for (int i=0; i<10; i++)
{
world[0].setXYZ(xAxis, yAxis, zAxis);
world[0].drawCube();<br> xAxis += 1.5f;<br> }<br> <br> zAxis++; //next cube is 1 unit closer<br> xAxis = -7.0f; //all x''s start at -7<br><br> /* more for loops to fill in the 10x10 world */<br>}<br><br>The world array is basically a cube with a couple extra functions to make it a bit easier work with.<br><br>One REALLY weird thing… If I move the zAxis, xAxis, and yAxis from the drawObjects() function and use them as globals, the 3d scene is drawn, but seems to keep drawing itself until the entire scene is completely off the screen (because after every row of drawing, I increase zAxis by 1…) And that all happens BY ITSELF. I kind of see a flicker of something hapening, a split second later, everything is black… This happens before I even try pressing the UP arrow to see if it works…<br>Those values aren''t used ANYWHERE else in the program. Really strange…<br><br>I had thought that hardcoding the x, y, and z into each object may be a problem, but shouldn''t glTranslatef() adjust the view and compensate for that?<br><br><br><br>Hopefully you guys have more ideas, ''cause I don''t. =)<br><br> </i>

This topic is closed to new replies.

Advertisement