Solved

Opengl spin shape

Posted on 2011-03-18
2
780 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
2 Comments
 
LVL 20

Accepted Solution

by:
ikework earned 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now