Sign in to follow this  

animating primitives

This topic is 2133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to move 2 primitives each with keyboard input.here is the code I am working with.
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]DrawShip()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glPushMatrix();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glColor3f(0.0f,1.0f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glBegin(GL_LINE_LOOP);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.25f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.5f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.0f,0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.5f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.25f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glEnd();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glPopMatrix();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]DrawAlien()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glPushMatrix();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glLoadIdentity();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glTranslatef(2.0f,0.0f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glColor3f(1.0f,0.0f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glBegin(GL_LINE_LOOP);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.25f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.5f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(-0.0f,0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.5f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.25f,-0.5f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,-0.25f,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glEnd();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glPopMatrix();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]RenderScene()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]DrawShip();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]DrawAlien();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glutSwapBuffers();[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]ShipLeft()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glRotatef(m,0.0f,0.0f,1.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]m+=0.1f;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]ShipRight()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]ShipUp()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]ShipDown()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]ShipBullet()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]AlienUp()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glTranslatef(0.0f,i,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]i+=0.1f;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]AlienDown()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glTranslatef(0.0f,j,0.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]j-=0.1f;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]AlienLeft()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glRotatef(k,0.0f,0.0f,1.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]k+=0.1f;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font]


[font="Consolas"][size="2"][font="Consolas"][size="2"]AlienRight()[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]glRotatef(l,0.0f,0.0f,1.0f);[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]l-=0.1f;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]?[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
For plain and simple keyboard input, you can check GetASyncKeyState. Otherwise you can google for "C++ keyboard input" or something similar for something more appropriate. (there has even been enough answered on this forum if you bothered to search)

Share this post


Link to post
Share on other sites
Sign in to follow this