Created
September 18, 2022 18:32
-
-
Save grebenkov/c8c9a04999161dfe983a12784d63fa3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "windows.h" | |
#include "gl\gl.h" | |
#include "gl\glaux.h" | |
#include "math.h" | |
GLUquadricObj *obj; | |
float camx=0,camy=400,camz=400; | |
float alpha=0; | |
void DrawClaw(void) | |
{ | |
glPushMatrix(); | |
glTranslatef(0.0f,0.3f,28.5f); | |
glRotatef(30.0f, 1.0, 0.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 5.0, 20, 3); | |
glTranslatef(0.0f,0.0f,5.0f); | |
gluCylinder(obj, 2.0, 0.0, 2.0, 20, 3); | |
glPopMatrix(); | |
} | |
void CALLBACK RenderScene(void) | |
{ | |
gluQuadricDrawStyle(obj, GLU_FILL); | |
gluQuadricOrientation(obj, GLU_OUTSIDE); | |
gluQuadricNormals(obj, GLU_FLAT); | |
glClearColor(0.7f,0.7f,1.0f,1.0f); | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluPerspective(45.0, 1, 10.0, 1000.0); | |
glEnable(GL_LIGHTING); | |
GLfloat ambientLight[] = {0.4f, 0.4f, 0.4f, 1.0f}; | |
GLfloat diffuseLight[] = {0.8f, 0.8f, 0.8f, 1.0f}; | |
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); | |
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); | |
GLfloat light0pos[] = { -200.0f, 200.0f, 200.0f, 1.0f }; | |
glLightfv(GL_LIGHT0,GL_POSITION,light0pos); | |
glEnable(GL_LIGHT0); | |
GLfloat wood[] = {0.39f,0.285f,0.192f,1.0f}; | |
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientLight); | |
glEnable(GL_COLOR_MATERIAL); | |
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); | |
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,wood); | |
glEnable(GL_DEPTH_TEST); | |
//glEnable(GL_TEXTURE_2D); | |
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) ; | |
//glMatrixMode(GL_MODELVIEW); | |
glColor3f(0.39f,0.285f,0.192f); | |
gluLookAt(camx,camy,camz,0,0,0,0,1,0); | |
//gluLookAt(300,300,0,0,0,0,0,1,0); | |
gluQuadricNormals(obj, GLU_FLAT); | |
glPushMatrix(); | |
glTranslatef(-60.0f,-50.0f,50.0f); | |
glRotatef(90.0f, 0.0, 1.0, 0.0); | |
//glRectf(-10.0f,-10.0f,10.0f,10.0f); | |
for(int i=0;i<=10;++i) | |
{ | |
glTranslatef(0.0f, 10.0f, 0.0f); | |
gluCylinder(obj, 5.0, 5.0, 120.0, 20, 30); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, 120.0f); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, -120.0f); | |
} | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(-50.0f,-45.0f,60.0f); | |
glRotatef(180.0f, 0.0, 1.0, 0.0); | |
//glRectf(-10.0f,-10.0f,10.0f,10.0f); | |
for(int i=0;i<10;++i) | |
{ | |
glTranslatef(0.0f, 10.0f, 0.0f); | |
gluCylinder(obj, 5.0, 5.0, 120.0, 20, 30); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, 120.0f); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, -120.0f); | |
} | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(-60.0f,-50.0f,-50.0f); | |
glRotatef(90.0f, 0.0, 1.0, 0.0); | |
//glRectf(-10.0f,-10.0f,10.0f,10.0f); | |
for(int i=0;i<=10;++i) | |
{ | |
glTranslatef(0.0f, 10.0f, 0.0f); | |
gluCylinder(obj, 5.0, 5.0, 120.0, 20, 30); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, 120.0f); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, -120.0f); | |
} | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(50.0f,-45.0f,60.0f); | |
glRotatef(180.0f, 0.0, 1.0, 0.0); | |
//glRectf(-10.0f,-10.0f,10.0f,10.0f); | |
for(int i=0;i<10;++i) | |
{ | |
glTranslatef(0.0f, 10.0f, 0.0f); | |
gluCylinder(obj, 5.0, 5.0, 120.0, 20, 30); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, 120.0f); | |
gluCylinder(obj, 5.0, 0.0, 0.0, 20, 2); | |
glTranslatef(0.0f, 0.0f, -120.0f); | |
} | |
glPopMatrix(); | |
glBegin(GL_TRIANGLES); | |
glVertex3f(-60.0f,65.0f,50.0f); | |
glVertex3f(60.0f,65.0f,50.0f); | |
glVertex3f(0.0f,125.0f,50.0f); | |
glEnd(); | |
glBegin(GL_TRIANGLES); | |
glVertex3f(-60.0f,65.0f,-50.0f); | |
glVertex3f(60.0f,65.0f,-50.0f); | |
glVertex3f(0.0f,125.0f,-50.0f); | |
glEnd(); | |
glBegin(GL_QUADS); | |
glVertex3f(60.0f,65.0f,-50.0f); | |
glVertex3f(0.0f,125.0f,-50.0f); | |
glVertex3f(0.0f,125.0f,50.0f); | |
glVertex3f(60.0f,65.0f,50.0f); | |
glEnd(); | |
glBegin(GL_QUADS); | |
glVertex3f(-60.0f,65.0f,50.0f); | |
glVertex3f(0.0f,125.0f,50.0f); | |
glVertex3f(0.0f,125.0f,-50.0f); | |
glVertex3f(-60.0f,65.0f,-50.0f); | |
glEnd(); | |
glBegin(GL_QUADS); | |
glVertex3f(50.0f,-40.0f,50.0f); | |
glVertex3f(50.0f,-40.0f,-50.0f); | |
glVertex3f(-50.0f,-40.0f,-50.0f); | |
glVertex3f(-50.0f,-40.0f,50.0f); | |
glEnd(); | |
glColor3f(0.79f,0.644f,0.45f); | |
glPushMatrix(); | |
glTranslatef(35.0f, 90.0f, 50.0f); | |
glRotatef(90.0f, 0.0, 1.0, 0.0); | |
glRotatef(135.0f, 1.0, 0.0, 0.0); | |
for(int i=0;i<10;++i) | |
{ | |
auxSolidBox(10,120,2); | |
glTranslatef(11.25f, 0.0f, 0.0f); | |
} | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(-35.0f, 90.0f, 50.0f); | |
glRotatef(90.0f, 0.0, 1.0, 0.0); | |
glRotatef(45.0f, 1.0, 0.0, 0.0); | |
for(int i=0;i<10;++i) | |
{ | |
auxSolidBox(10,120,2); | |
glTranslatef(11.25f, 0.0f, 0.0f); | |
} | |
glPopMatrix(); | |
// окно | |
glPushMatrix(); | |
glTranslatef(0.0f,90.0f,55.0f); | |
glRotatef(180.0f, 0.0, 1.0, 0.0); | |
gluCylinder(obj, 10.0, 10.0, 110.0, 20, 3); | |
gluCylinder(obj, 8.0, 8.0, 110.0, 20, 3); | |
gluDisk(obj,8.0,10.0,20,2); | |
glTranslatef(0.0f,0.0f,55.0f); | |
auxSolidBox(2,19.5,110); | |
auxSolidBox(19.5,2,110); | |
glTranslatef(0.0f,0.0f,55.0f); | |
gluDisk(obj,8.0,10.0,20,2); | |
glTranslatef(0.0f,0.0f,-108.0f); | |
glColor3f(0.242f,0.18f,0.09f); | |
gluDisk(obj,0.0,9.5,20,1); | |
glTranslatef(0.0f,0.0f,106.0f); | |
gluDisk(obj,0.0,9.5,20,1); | |
glPopMatrix(); | |
//лапы | |
glColor3f(0.79f,0.79f,0.0f); | |
glPushMatrix(); | |
glTranslatef(-25.0f,-40.0f,0.0f); | |
glRotatef(90.0f, 1.0, 0.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
glTranslatef(50.0f,0.0f,0.0f); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
glRotatef(-90.0f, 1.0, 0.0, 0.0); | |
glTranslatef(0.0f,-29.0f,0.0f); | |
// lapa 2 | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
gluSphere(obj,3,10,10); | |
DrawClaw(); | |
glPushMatrix(); | |
glRotatef(-30.0f, 0.0, 1.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
DrawClaw(); | |
glRotatef(60.0f, 0.0, 1.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
DrawClaw(); | |
glPopMatrix(); | |
//lapa1 | |
glTranslatef(-50.0f,0.0f,0.0f); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
gluSphere(obj,3,10,10); | |
DrawClaw(); | |
glPushMatrix(); | |
glRotatef(-30.0f, 0.0, 1.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
DrawClaw(); | |
glRotatef(60.0f, 0.0, 1.0, 0.0); | |
gluCylinder(obj, 2.0, 2.0, 30.0, 20, 10); | |
DrawClaw(); | |
glPopMatrix(); | |
glPopMatrix(); | |
glFlush(); | |
auxSwapBuffers(); | |
} | |
void CALLBACK IdleFunction(void) | |
{ | |
alpha+=0.01; | |
if (alpha>2*3.14159265) alpha=0; | |
camz = 400 * cosf(alpha); | |
camx = 400 * sinf(alpha); | |
camy = 200 * cosf(2*alpha) + 62.5; | |
//Sleep(100); | |
RenderScene(); | |
} | |
int WINAPI WinMain(HINSTANCE hInstance, | |
HINSTANCE hPrevInstance, | |
LPTSTR lpCmdLine, | |
int nCmdShow) | |
{ | |
obj = gluNewQuadric(); | |
auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA); | |
auxInitPosition(100,100,500,500); | |
auxInitWindow("OpenGL lab"); | |
auxIdleFunc(IdleFunction); | |
auxMainLoop(RenderScene); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment