Solved

Opengl spin shape

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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