📄 all.cpp
字号:
#include <glut.h>
#include <glu.h>
#include <gl.h>
#include <iostream.h>
static int shoulder=0, elbow=0;
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 1.0);
glEnable (GL_DEPTH_TEST);
glColor3f (0.0, 0.5, 1.0);
}
void bawah()
{
glPushMatrix ();
glRotatef (90, 1, 0, 0);
GLUquadricObj* mySphere;
mySphere = gluNewQuadric ();
gluQuadricDrawStyle (mySphere, GLU_SILHOUETTE);
gluQuadricTexture (mySphere, 0);
gluCylinder (mySphere, 0.25, 0.5, 0.8, 35, 5);
glPopMatrix ();
}
void tengah()
{
glPushMatrix ();
glTranslatef (0, 1.5, 0);
glRotatef (90, 1, 0, 0);
GLUquadricObj* mySphere2;
mySphere2 = gluNewQuadric ();
gluQuadricDrawStyle (mySphere2, GLU_SILHOUETTE);
gluCylinder (mySphere2, 0.15, 0.15, 1.5, 25, 10);
glPopMatrix ();
}
void atas()
{
glPushMatrix ();
glTranslatef (0, 2, 0);
glRotatef (90, 1, 0, 0);
GLUquadricObj* mySphere3;
mySphere3 = gluNewQuadric ();
gluQuadricDrawStyle (mySphere3, GLU_SILHOUETTE);
gluCylinder (mySphere3, 0.3, 0.3, 0.5, 25, 10);
glPopMatrix ();
}
void lengan()
{
glTranslatef (0.8, 1.8, 0.0);
glPushMatrix();
glScalef (1, 0.3, 0.4);
glutWireCube(1.0);
glPopMatrix();
glTranslatef (1.0, 0.0, 0.0);
glPushMatrix();
glScalef (1.0, 0.2, 0.2);
glutWireCube (1.0);
glPopMatrix();
}
void jari()
{
glTranslatef(2.5, 1.45, 1.9);
glPushMatrix();
glScalef(0.5, 0.1, 0.1);
glutWireCube(1.0);
glPopMatrix();
glTranslatef(0.0, 0.0, -0.28);
glPushMatrix();
glScalef(0.5, 0.1, 0.1);
glutWireCube(1.0);
glPopMatrix();
}
void kotak()
{
glPushMatrix();
glTranslatef(-5.0,-4.,0.0);
glRotatef(90,1,35,0);
glScalef (1.0, 1.0, 1.0);
glutWireCube (1.5);
glPopMatrix();
}
void rel()
{
glTranslatef (-1.5, -3.5, 0.0);
for(int i=0;i<20;i++)
{
glTranslatef(0.0,0.0,-0.2);
glPushMatrix();
glScalef (1.0, 0.2, 0.2);
glutWireCube (1.0);
glPopMatrix();
glPushMatrix ();
glTranslatef(0.5,0.1,0.05);
glRotatef (180, 180, 0, -180);
GLUquadricObj* mySphere;
mySphere = gluNewQuadric ();
gluQuadricDrawStyle (mySphere, GLU_SILHOUETTE);
gluQuadricTexture (mySphere, 0);
gluCylinder (mySphere, 0.1, 0.1, 1, 10, 1);
glPopMatrix ();
}
}
void botol()
{
glPushMatrix();
glTranslatef(0,-0.6,0);
glRotatef(90,1,0,0);
GLUquadricObj* mySphere;
mySphere = gluNewQuadric();
gluQuadricDrawStyle(mySphere,GLU_SILHOUETTE);
gluQuadricTexture(mySphere,0);
gluCylinder(mySphere,0.27,0.27,1,30,5);
glPopMatrix();
glPushMatrix();
glTranslatef(0,-0.3,0);
glRotatef(90,1,0,0);
GLUquadricObj* mySphere2;
mySphere2 = gluNewQuadric();
gluQuadricDrawStyle(mySphere2, GLU_SILHOUETTE);
gluCylinder(mySphere2,0.1,0.27,0.3,20,10);
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.1,0);
glRotatef(90,1,0,0);
GLUquadricObj* mySphere3;
mySphere3 = gluNewQuadric();
gluQuadricDrawStyle(mySphere3, GLU_SILHOUETTE);
gluCylinder(mySphere3,0.1,0.1,0.4,20,10);
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.2,0);
glRotatef(90,1,0,0);
GLUquadricObj* mySphere4;
mySphere4 = gluNewQuadric();
gluQuadricDrawStyle(mySphere3, GLU_SILHOUETTE);
gluCylinder(mySphere4,0.15,0.15,0.1,20,10);
glPopMatrix();
}
void display (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (1,0.8,1,0,0,0,0,1,0);
bawah();
tengah();
atas();
lengan();
jari();
botol();
kotak();
rel();
glutSwapBuffers ();
}
void reshape (int w, int h)
{
glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
}
void main (int argc, char ** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (700, 700);
glutInitWindowPosition (-100, -100);
glutCreateWindow ("Robot");
init ();
glutReshapeFunc (reshape);
glutDisplayFunc (display);
glutMainLoop ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -