?
Solved

Opengl spin shape

Posted on 2011-03-18
2
Medium Priority
?
860 Views
Last Modified: 2012-05-11
I am trying to get a sphere to spin on user input in opengl.

I have a class for my sphere which is a weapon in my game like below.


void Weapon::DrawWeapon()
{
      glPushMatrix();
    // Draw the Handle
   glPushMatrix();
   glRotatef(90.0f,5.0f,10.0f,5.0f);
   glScalef (2.0, 0.4, 1.0);
   glTranslatef(0.5f,-1.0f,0.6f);
  //glRotatef ((GLfloat) weapon, 0.0, 0.0, 1.0);
   glutSolidCube(10.0);
   
   


   

      glPopMatrix();
}

I have a function for the spin of the sphere


void spinDisplay(void)
{
   spin = spin + 2.0;
   if (spin > 360.0)
      spin = spin - 360.0;
   glutPostRedisplay();
}

How do I use this spin function with the sphere can you use it with glrotatef
0
Comment
Question by:tango2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
ikework earned 2000 total points
ID: 35197506
Hi tango2009,

this sounds pretty much like a duplicate of http://www.experts-exchange.com/Programming/Game/Game_Graphics/OpenGL/Q__26899124.html

See my answer there, basically you must swap the glTranslate and glRotate calls in order to rotate the object inplace, meaning first translate then rotate.

Since this is discussed in the other q too, I would suggest we delete this question.


ike
0
 
LVL 3

Expert Comment

by:StormSeed
ID: 35391222
There is also the potential problem that your rotation vector is not a unit length.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question