rotating box in openframeworks

Posted by Nikolaus Gradwohl Mon, 29 Sep 2008 17:17:00 GMT

I tried to write something simmilar to my neonbox-demo in openframeworks. At first a have been a bit puzzled because there is no rotate command.

Then i remembered that openframeworks uses OpenGL for drawing so glRotatef and glTranslatef can be used for rotating the image

    ...
int ang = 0;

void testApp::setup(){
    ofSetVerticalSync( true );
    ofSetFrameRate( 25 );
}

void testApp::draw(){
    int width = ofGetWidth() / 2;
    int height = ofGetHeight() / 2;

    ofBackground( 0,0,0 );
    glPushMatrix();
    glTranslatef( width, height, 0 );
    glRotatef( ang , 0, 0, 1);

    ang++;
    if (ang == 360) {
        ang = 0;
    }

    ofFill();
    ofSetColor( 255 * ( 1 + sin( ang * 2 * PI / 360 )) / 2, 
        255 * ( 1 + sin( PI + ang * 2 * PI / 360 )) / 2, 0 );

    ofRect(  -300,  -50, 100, 100 );
    ofRect(  -100,  -100, 200, 200 );
    ofRect(  200,  -50, 100, 100 );


    glPopMatrix();
}
    ...

This time i also made a little screenshot for those who don't have openframeworks installed (yet :-) )

screenshot

Tags ,  | no comments

Tweet This! submit to reddit Digg!

Comments

(leave url/email »)

   Comment Markup Help Preview comment