Spin!

Member
Posts: 102
Joined: 2005.01
Post: #1
why wont this quad rotate?

Code:
#include <stdlib.h>

#include <GLUT/glut.h>

float Gwidth, Gheight;

float lastFrameTime = 0.0f;

int RA = 0;

void display(void)
{
    //handle scaling
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    float aspect_ratio = Gwidth/Gheight;
    if(aspect_ratio > 1.0)
        glOrtho(-aspect_ratio, aspect_ratio, -1, 1, -1, 1);
    else
    {
        aspect_ratio = 1.0 / aspect_ratio;
        glOrtho(-1, 1, -aspect_ratio, aspect_ratio, -1, 1);
    }    
    glMatrixMode(GL_MODELVIEW);
    //handle spinning
    if (lastFrameTime == 0)    {            
        lastFrameTime = glutGet(GLUT_ELAPSED_TIME);
    }
            
    int now = glutGet(GLUT_ELAPSED_TIME);
    int elapsedMilliseconds = now - lastFrameTime;
    float elapsedTime = elapsedMilliseconds / 1000.0f;
    lastFrameTime = now;
    RA +=  5 * elapsedTime;
        
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLoadIdentity();
    
    //glPushMatrix();
    
        glRotatef(RA ,0.0 , 0.0, 1.0);
    
        glBegin(GL_QUADS);
            glColor3f(1.0f,0.5f,0.0f);
            glVertex2f(-0.75f, 0.75f);
            
            glColor3f(0.0f,1.0f,0.5f);
            glVertex2f(0.75f, 0.75f);
        
            glColor3f(0.5f,0.0f,1.0f);
            glVertex2f(0.75f,-0.75f);
        
            glColor3f(0.8f,0.5f,0.0f);
            glVertex2f(-0.75, -0.75);
        glEnd();
    //glPopMatrix();
    glutSwapBuffers();
}

void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
    Gwidth = width;
    Gheight = height;
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    
    glutCreateWindow("Large Square");
    
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);
    
    glutMainLoop();
    return EXIT_SUCCESS;
}
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #2
You're adding a tiny value to an int.
(int)(0 + tinyvalue) = 0;
Make RA a float instead.
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #3
swore i did that... o well thanks Rolleyes
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  spin a tire imaumac 2 1,968 Oct 19, 2008 07:29 PM
Last Post: imaumac