Solved

Opengl spin shape

Posted on 2011-03-18
2
805 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

786 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