Jump to content
  • Advertisement

Archived

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

Cronus

Brutal issue i've encountered

This topic is 5761 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

Alright. I''m trying to make a 2d war strategy game, and all is fairly well so far. Except! Alright, I have boats on the screen and they move around all fine, I can select them and click on the map to move them around and they move where i tell them. I can select multiple boats and it all works fine. But in my process of having the ships face where they should, I find I need the glLoadIdentity function to reset the Matrix so that i can rotate the boats on themselves and not the previously drawn boat. No problems. Ahh, my Selection no longer works. My Selection works by reseting the screen and rendering only a small window around the mouse click and cycling through the objects rendered, selecting the one closest to the camera. The problem is, when my selection function renders, it calls the DrawGLScene function which has the rotation code in it. But that resets the screen each boat, and it can''t do that because the window is a little tiny thing. And i can''t rotate unless i reset the screen. Which means with my current situation, i can not select the boats or i can not rotate the boats. Perhaps there is another way to rotate? or another way to select objects? Does anyone know, or have a simular problem? Any support or assistance would be greatly appreiated.

Share this post


Link to post
Share on other sites
Advertisement
Had the same problem with my particle engine - you had to draw each particle and had to compensate for the camera and what not but rendering each particle screws up the matrix. Heres the basic idea: Insted of loading identity and starting from scratch, which means more rotation calculations , you make a copy of the transformed modelview matrix and then load it whenever you need it. If you want a full demo download my mini-demo entry source (its the Pescao Loco Demo). I hope that helps...im not an expert on picking...but you should consult the picking tutorial (on nehe). Or you could apt for a simpler solution - have the boats central position stored in its structure and compare the mouse position using the unproject function with the mouse (i read about that function somewhere in the red book).

Heres the jist of the matrix loading code:

    
//global variable:

float * ModelViewMatrix = new float [16];

//in the draw routine

glTranslatef(0.0f,CAMERA_HEIGHT,zTranslate);
glRotatef(yRotate,0.0f,1.0f,0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, ModelViewMatrix);

Bubbley.RenderEmitter(-1 * yRotate, ModelViewMatrix, RenderBubble);

//in the render emitter routine

for (int loop=0;loop<NumParticles;loop++) // Loop Through All The Particles

{

//i sort of just realized that i left this in my code but you dont need it - the load identity

//glLoadIdentity();

//Set up scene

glLoadMatrixf(CameraMatrix);

glTranslatef(Particles[loop].x, Particles[loop].y, Particles[loop].z);
//This has to be changed if correct billboarding is to be done

glRotatef(theta,0.0f, 1.0f, 0.0f);

Render(loop);
}


[edited by - llvllatrix on February 6, 2003 11:45:49 PM]

Share this post


Link to post
Share on other sites
You could do that, or do it this way:


  
//global variable:


glTranslatef(0.0f,CAMERA_HEIGHT,zTranslate);
glRotatef(yRotate,0.0f,1.0f,0.0f);


Bubbley.RenderEmitter(-1 * yRotate, RenderBubble);

//in the render emitter routine

for (int loop=0;loop<NumParticles;loop++)
{
//i sort of just realized that i left this in my code but you dont need it - the load identity

//glLoadIdentity(); //Set up scene

glPushMatrix();
glTranslatef(Particles[loop].x, Particles[loop].y, Particles[loop].z); //This has to be changed if correct billboarding is to be done

glRotatef(theta,0.0f, 1.0f, 0.0f);
Render(loop);
glPopMatrix();
}

Share this post


Link to post
Share on other sites
yes, JuNC is onto it, but thats a bit extreme for a particle engine...
I''d avoid using glGetFloatv(GL_MODELVIEW_MATRIX, ModelViewMatrix), and such, like the plague.
Use your own ''local'' matrices within each object. Rotate them yourself with the cpu.

http://www.j3d.org/matrix_faq

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |

Share this post


Link to post
Share on other sites
You guys sure? The reason i loaded the modelview is because when you push the matrix you get an identity matrix and not the camera matrix (the matrix you generated with the camera''s values) you want.

Share this post


Link to post
Share on other sites
quote:

push the matrix you get an identity matrix



You misunderstand what PushMatrix does. It does *not* affect the current matrix at all.

Share this post


Link to post
Share on other sites
glPushMatrix() just puts a copy of the current matrix on the stack. It''s like you''re saving a copy of the position and rotation of the screen. When you call glPopMatrix(), you restore it to exactly the way it was before the glPushMatrix() command.

some pseudo-code:

start at world identity
for each object
glPushMatrix(); // Save the current Matrix
translate object xyz
rotate object xyz
draw object
glPopMatrix(); // Restore to previous matrix
// in this case, the world identity
next object // loop around again, next object''s pos and rot arent affected by any other object



If any man says he hates war more than I do, he better have a knife, that''s all I have to say.
- Jack Handy

Share this post


Link to post
Share on other sites
Wow, i didnt know that! I thought it just pushed the old matrix onto the stack and gave you an identity matrix. This makes things so much easier

Share this post


Link to post
Share on other sites
Heh, thanks for the relies, didn''t expect so much assistance :D

what is Bubbley.RenderEmitter(-1 * yRotate, ModelViewMatrix, RenderBubble); ?

Share this post


Link to post
Share on other sites
Its one of my functions, just ignore it. Lets see if i can get it right now:

-Set up your scene (build a matrix with you''re camera values.
for NumTanks
{
-Push the matrix onto the stack and you''re left with a copy of the camera matrix
-Rotate you''re tank
-Pop the matrix
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!