Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ichor

Moving in a 3D scene

This topic is 6744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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 *-

Share this post


Link to post
Share on other sites
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? =)

Share this post


Link to post
Share on other sites
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 *-

Share this post


Link to post
Share on other sites
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[i][0].drawCube();
xAxis += 1.5f;
}

zAxis++; //next cube is 1 unit closer
xAxis = -7.0f; //all x''s start at -7

/* more for loops to fill in the 10x10 world */
}

The world array is basically a cube with a couple extra functions to make it a bit easier work with.

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...
Those values aren''t used ANYWHERE else in the program. Really strange...

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?



Hopefully you guys have more ideas, ''cause I don''t. =)

Share this post


Link to post
Share on other sites
I am new to this to but it looks like you have a glTranslate in your draw objects() and in your if(keys stament which is getting canceled out.If that is it take your translate code out of draw objects() and set translateX,Y,Z to what you had that at.I would put translateZ+=5.0f; at bottom after you draw hope that helps.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!