Archived

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

Cobra

How do I keep things separate????? (see inside)

Recommended Posts

Cobra    122
Hey ppl, I am really really hoping that some of you know how to do this. Basically, I want to know how to keep all of my functions separate, but let them all run at the same time.. for example. If I make it so that the sky texture rotates in a certain direction, I want it so that even if the camera turns upside down, or the world destroys itself, or whatever, I still want the sky to rotate in the same way as it was. Another example would be gravity... I want to make it so that no matter which direction you are looking at e.t.c, gravity always applies downwards.... Can anyone help me with this.. it''s really bugging me ''cause I used to know how to do it! Thanx in advance for any help. ~Cobra~

Share this post


Link to post
Share on other sites
ragonastick    134
Ummm... If I understand your question (doubtful), then the answer is to use a game loop:

(VB, since my C++ really stinks... I can''t even remember how to write a Do loop )


Do While bRunning
GetInput

MovePlayer
DoGravity
SpinSky

DrawEverything
FlipBackBuffer
Loop


Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
Cobra    122
Actually, I think I''ll just have to start using gluLookAt from now on.. this actually works like a camera, so it won''t affect anything in the rest of the level.

But thanx anyway.

~Cobra~

Share this post


Link to post
Share on other sites
rileyriley    235
I think that the reason that gluLookAt doesn''t mess up all the other junk is that it modifies the projection matrix, while normal transformations modify the model view matrix. So if you wanted to do it _without_ gluLookAt for some reason then you could glMatrixMode(GL_PROJECTION); mess with your camera, and go back to glMatrixMode(GL_MODEL_VIEW); (there''s about a 90% chance that I have every single one of those names wrong).

I just started with ogl about a month ago, so my understanding of how it works is still pretty shaky, but I think this is right. Someone please correct me if it isn''t.

/riley

Share this post


Link to post
Share on other sites
davepermen    1047
Do While bRunning
GetInput
MovePlayer
DoGravity
SpinSky
DrawEverything
FlipBackBuffer
Loop

  
do
{
GetInput();
MovePlayer();
DoGravity();
SpinSky();
DrawEverything();
}while(bRunning);


we wanna play, not watch the pictures

Share this post


Link to post
Share on other sites
zedzeek    528
DONT mess with the projection matrix AT ALL

gluLookat works in modelview space (have a look at the mesa source for a sample code of what it does )

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
what about glPushMatrix(), glPopMatrix()?? Maybe you''re rotating the sky, which then rotates the camera (since the camera is rotated after), which inturn rotates nething after... crappy explaination but I think u get it...
to stop this:

glPushMatrix()
// rotate 1 thing
glPopMatrix() <- resets the transformation matrix or whatever so you''re back where u started before glPushMatrix()
glPushMatrix() (again)
// rotate/move something else
glPopMatrix...

This way you can separate all your calls to rotate/move... You could draw a car for example like:

pushmatrix()
// move to car pos and draw car body
pushmatrix()
// move to front left wheel pos (relative to car pos) and draw it
popmatrix()
pushmatrix()
// move to front right wheel pos (relative to car pos) and draw it
popmatrix()
... do other wheels
popmatrix()
and this pop matrix gets you back to the state u were at before you moved to draw the car body

if this didnt help very much, look up glPushMatrix in the redbook, has a pretty good explaination, or NeHe

Share this post


Link to post
Share on other sites
Cobra    122
THATS IT!!!!!!!!

Thanx mr anonymous poster!..

I think that''s it.. I''ll go test it out now.. but I''m pretty sure that''s it.

~Cobra~

Share this post


Link to post
Share on other sites
Cobra    122
Wow, I never knew just how useful glPushMatrix and glPopMatrix were! I never used them before! Now I''ll ALWAYS use them! hehehe.

I''ve managed to totally move all of my functions out of DrawGLScene, and just make calls to it using function calls now, so my DrawGLScene looks a lot like the loop you guys were showing earlier.

There''s just one thing that I don''t get now.

What is this FlipBackBuffer that you guys were mentioning?

Thanx in advance for any help.

~Cobra~

Share this post


Link to post
Share on other sites
ARID    122
OpenGL dosen''t use a back buffer call it does it automaticly (I think) all a buffer is is a place to draw to then you swap the buffers front buffer is your current view back buffer is your next view. It eliminates flicker and increases framerates. You can impliment one in OGL i''m not shure how but i know you can DirectX requires you use one. Just another point at why OGL is a generaly better API.

A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.

Share this post


Link to post
Share on other sites