#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glu.h>
#define SWING 1
#define BAR 2
void CALLBACK draw();
void CALLBACK reshape(int width,int height);
float angle;
int direction;
void CALLBACK reshape(int width,int height)
{
glViewport(0,0,(GLint)width,(GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50,50.0,-50,50,-150,150);
glMatrixMode(GL_MODELVIEW);
}
void CALLBACK draw()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(60,0.0,1.0,0.0);
glCallList(BAR);
glLoadIdentity();
glColor3f(0.0,0.0,1.0);
//glTranslatef(0.0,30.0,0.0);
glRotatef(angle++,0.0,1.0,0.0);
glTranslatef(0.0,1.0,0.0);
glColor3f(0.0,0.0,1.0);
glCallList(SWING);
glFlush();
//auxSwapBuffers();
//if(direction==1)
//angle+=1;
/*else
angle--;
if(angle==-40.0)
{
direction=1;
}
if(angle==40.0)
{
direction=0;
}*/
}
void make_bar(){
/* glNewList(BAR,GL_COMPILE);
glColor3f(1.0,1.0,0.0);
glBegin(GL_QUADS);
glNormal3f(0.0,0.0,-1.0);
glVertex3d(-50,30,-1);
glVertex3d(50,30,-1);
glVertex3d(50,30,1);
glVertex3d(-50,30,1);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-50,33,-1);
glVertex3d(50,33,-1);
glVertex3d(50,33,1);
glVertex3d(-50,33,1);
glColor3f(1.0,0.65,0.0);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-50,33,1);
glVertex3d(-50,30,1);
glVertex3d(50,30,1);
glVertex3d(50,33,1);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(50,33,-1);
glVertex3d(50,30,-1);
glVertex3d(-50,30,-1);
glVertex3d(-50,33,-1);
glNormal3f(-1.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glVertex3d(-50,33,-1);
glVertex3d(-50,30,-1);
glVertex3d(-50,30,1);
glVertex3d(-50,33,1);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(50,33,1);
glVertex3d(50,30,1);
glVertex3d(50,30,-1);
glVertex3d(50,33,-1);
glEnd();
glEndList(); */
}
void make_swing(){
glNewList(SWING,GL_COMPILE);
glPushMatrix();
auxSolidBox(20,10,5);
glPopMatrix();
/* GLint slices,stacks;
GLUquadricObj *quadObj;
quadObj=gluNewQuadric();
slices=8;
stacks=6;
glNewList(SWING,GL_COMPILE);
glColor3f(1.0,0.0,1.0);
gluSphere(quadObj,40.0,slices,stacks);
glColor3f(1.0,0.0,1.0);
glLineWidth(5.0);
glBegin(GL_LINES);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-20,30,0);
glVertex3d(-20,-30,0);
glVertex3d(20,30,0);
glVertex3d(20,-30,0);
glEnd();
glColor3f(0.0,1.0,0.0);
glBegin(GL_QUAD_STRIP);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(20,-30,-10);
glVertex3d(20,-33,-10);
glVertex3d(-20,-30,-10);
glVertex3d(-20,-33,-10);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-20,-30,10);
glVertex3d(-20,-33,10);
glVertex3d(20,-30,10);
glVertex3d(20,-33,10);
glVertex3d(20,-30,-10);
glVertex3d(20,-33,-10);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_QUADS);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-20,-33,-10);
glVertex3d(20,-33,-10);
glVertex3d(20,-33,10);
glVertex3d(-20,-33,10);
glNormal3f(-1.0,0.0,0.0);
glVertex3d(-20,-30,-10);
glVertex3d(20,-30,-10);
glVertex3d(20,-30,10);
glVertex3d(-20,-30,10);
glEnd(); */
glEndList();
}
void main(int argc,char * *argv)
{
/* float position[]={3.0,0.0,3.0,0.0};
float local_view[]={10.0};
float ambient[]={0.17450,0.1175,0.01175};
float diffuse[]={0.61424,0.04136,0.4136};
float specular[]={0.727811,0.626959,0.626959};
glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER,local_view);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
glMaterialf(GL_FRONT,GL_SHININESS,0.6*128.0);
float specular[]={1.0,1.0,1.0,1.0};
float shininess[]={100.0};
float position[]={0.0,0.0,10.0,0.0};
auxInitPosition(0,0,500,500);
auxInitWindow("SWING");
auxInitDisplayMode(AUX_SINGLE|AUX_RGB|AUX_DEPTH);
glClearColor(0.0,1.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shininess);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);*/
auxInitPosition(0,0,500,500);
auxInitWindow("SWING");
auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH);
glClearColor(0.0,1.0,0.0,0.0);
glShadeModel(GL_FLAT);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable(GL_DEPTH_TEST);
make_bar();
make_swing();
angle=-39.0;
direction=0;
auxReshapeFunc(reshape);
auxIdleFunc(draw);
auxMainLoop(draw);
}