Jump to content
  • Advertisement

Archived

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

vrybak

rotating objects once they are already drawn

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

I am trying to draw 2 triangles. I want to be able to rotate one of the triangles upon a button click. But I cant figure out why both of them are always rotating. Is there any way to tag a drawn object and then refer to it when I want to do a rotation or scaling operation?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
here is what you are probably doing:

rotate( someDegrees )
drawTriangleOne();
drawTriangleTwo();

when you should actually be doing this:

drawTriangleOne();
rotate( someDegrees )
drawTriangleTwo();

there is no such thing as rotating an object when its already drawn... the rotating & translating takes place before drawing.... BUT... you can always redraw (& if you redraw enough with some movement between each time, you get animation)

I hope that was simple enough for you.

Share this post


Link to post
Share on other sites
ok, but what if I want to draw some objects first, and then when the user requests I want to rotate one of them. Kind of like in a paint program. They let me draw a square first and then i can select the move button and move it around the screen. Is it possible to do something like that in openGL?

Share this post


Link to post
Share on other sites
See it like this:

Main Program
Main Loop (while the user doesn't want to exit)
Check for input and handle it
Draw the 'scene'
Swap Buffers (double buffering)
End Main Loop
End Program


[edited by - Tree Penguin on March 5, 2004 12:33:03 PM]

Share this post


Link to post
Share on other sites
What you are trying to do is not an OpenGL issue, but rather one of general programming technique. It can certainly be done. Off the top of my head I would think you could have a CheckKeyPress() routine called in your DrawScene or main loop. It detects a particular key press or mouse click and sets a global flag. In your draw routine you would have an if statement checking for the flag being true and if it is perform a rotate command.

pseudo code might look like this:

DrawScene()
{
CheckKeyPress()
DrawTriangleOne()
if rotateFlag is true
then rotate(someDegrees)
endif
DrawTriangleTwo()

increment someDegrees
if someDegrees greater than 359
then someDegrees = 0
}

In your CheckKeyPress routine you should probably check for which triangle was clicked and the modify the if statements to rotate the appropriate one in your DrawScene() routine. Dectecting which triangle was clicked is more tricky, but all the info you need is in the NeHe tutorials.

Hope that helps.

Share this post


Link to post
Share on other sites
i would advise u create a class for the tris
class TRIANGLE
{
float x,y,z;
float rx,ry,rz;
bool mouseintri(int x,int y);
}

//youi get the idea thus using a class or a struct u can(basiclly using an array) create alot of tris and rotate them individualy(i think that is spealt correct)

Share this post


Link to post
Share on other sites
perhaps a better way if you are doing something like this especially when you are rotating a single triangle and there''s other triangles drawn afterwards is to use glPushMatrix and glPopMatrix:


CheckKeyPress();
DrawTriangleOne();

if(rotateFlag)
{
glPushMatrix();
rotate(someDegrees);
glPopMatrix();
}

DrawTriangleTwo();
someDegrees += increment;
if (someDegrees >= 360)
someDegrees = 0


(I unbasiced the example in question! )

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!