OpenGL ile robot kolu hareketi kodunu aşağıdaki örnekte bulabilirsiniz. R harfi ile CW , küçük r harfi ilede CCW yönünde hareketi inceleyebilirsiniz;
Video;
Kod;
#include "stdlib.h"
#include "glut.h"
#include "time.h"
#include "math.h"
#include "stdio.h"
GLvoid drawScene(GLvoid);
GLvoid keyboard(unsigned char c,int x,int y);
int MyRotate=0;
void main(int argc, char** argv)
{
int width,height;
double range;
glutInit(&argc,argv);
width=glutGet(GLUT_SCREEN_WIDTH);
height=glutGet(GLUT_SCREEN_HEIGHT);
glutInitWindowPosition(height*0.25,height*0.25);
glutInitWindowSize(width*.5,height*.5);
glutInitDisplayMode( GLUT_RGB );
glutCreateWindow("");
range=2;
glMatrixMode(GL_PROJECTION);
gluPerspective(45,(double)width/height,1,17);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0,0,-5);
glLineWidth(2.0);
glutKeyboardFunc(keyboard);
glutDisplayFunc( drawScene );
glutMainLoop();
}
GLvoid keyboard(unsigned char c,int x,int y)
{
switch (c)
{
case 'r':
MyRotate+=10;
break;
case 'R':
MyRotate-=10;
break;
}
glutPostRedisplay();
}
GLvoid wireBox(GLfloat width,GLfloat height, GLfloat depth)
{
float x,y,z;
x=width/2;
y=height/2;
z=depth/2;
glColor3f(0,0,1);
glBegin(GL_LINE_STRIP);
glVertex3f(-x,y,-z);
glVertex3f(x,y,-z);
glVertex3f(x,-y,-z);
glVertex3f(-x,-y,-z);
glVertex3f(-x,y,-z);
glVertex3f(-x,y,z);
glVertex3f(x,y,z);
glVertex3f(x,y,-z);
glVertex3f(x,y,z);
glVertex3f(x,-y,z);
glVertex3f(x,-y,-z);
glVertex3f(x,-y,z);
glVertex3f(-x,-y,z);
glVertex3f(-x,-y,-z);
glVertex3f(-x,-y,z);
glVertex3f(-x,y,z);
glEnd();
}
GLvoid drawScene()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(-1,0,0);
glPushMatrix();
wireBox(2.0,1.0,1.0);
glPopMatrix();
glTranslatef(1.0,0.0,0);
glRotatef(MyRotate,0,0,1);
glTranslatef(1.0,0.0,0);
wireBox(2.0,1.0,1.0);
glPopMatrix();
glFlush();
}
follow: