Solved

Opengl spin shape

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

912 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

22 Experts available now in Live!

Get 1:1 Help Now