Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<math.h>
- #include<windows.h>
- #include<GL/glut.h>
- #include<iostream>
- #include<vector>
- using namespace std;
- #define pb push_back
- #define PI 2*acos(0)
- #define pi 2*acos(0)
- double cameraHeight;
- double cameraAngle;
- int drawgrid;
- int drawaxes;
- double angle;
- ///prototypes
- void drawsphere(float radius,int slices,int stacks);
- void drawCircularStrip();
- void drawCylinder(float height, float radius, int stacks, int slices);
- void rods(void);
- ///
- struct point
- {
- double x,y,z;
- // point(double a , double b, double c)
- // {
- // x=a;
- // y=b;
- // z=c;
- // }
- };
- void drawBase(float scale)
- {
- float a=200;
- glBegin(GL_POLYGON);
- {glColor3f((float)248/255,(float)205/255,(float)156/255);
- glVertex3f(-scale*a/2,0,0);
- glVertex3f(-scale*a*1.5*cos(pi/6),scale*a*1.5*sin(pi/6),0);
- glVertex3f(-scale*a*1.5*cos(pi/6)+scale*a/2*cos(pi*55/180),
- scale*a*1.5*sin(pi/6)+scale*a/2*sin(pi*55/180),0);
- glVertex3f(-scale*a*1.5*cos(pi/6)+scale*a/2*cos(pi*55/180)+scale*a*cos(pi*70/180),
- scale*a*1.5*sin(pi/6)+scale*a/2*sin(pi*55/180)+scale*a*sin(pi*70/180),0);
- glVertex3f(-(-scale*a*1.5*cos(pi/6)+scale*a/2*cos(pi*55/180)+scale*a*cos(pi*70/180)),
- scale*a*1.5*sin(pi/6)+scale*a/2*sin(pi*55/180)+scale*a*sin(pi*70/180),0);
- glVertex3f(-(-scale*a*1.5*cos(pi/6)+scale*a/2*cos(pi*55/180)),
- scale*a*1.5*sin(pi/6)+scale*a/2*sin(pi*55/180),0);
- glVertex3f(scale*a*1.5*cos(pi/6),scale*a*1.5*sin(pi/6),0);
- glVertex3f(scale*a/2,0,0);
- }glEnd();
- }
- void drawAxes()
- {
- if(drawaxes==1)
- {
- glColor3f(1.0, 1.0, 1.0);
- glBegin(GL_LINES);{
- glVertex3f( 1000,0,0);
- glVertex3f(-1000,0,0);
- glVertex3f(0,-1000,0);
- glVertex3f(0, 1000,0);
- glVertex3f(0,0, 1000);
- glVertex3f(0,0,-1000);
- }glEnd();
- }
- }
- void drawCurvedCylinderBasic(float length, float angle, float radius)
- {
- float bigradius=length/sin(angle*pi/2/180);
- float ang=-angle/2;
- float height=length;
- float stacks=50;
- float slices=50;
- struct point points[100][100];
- int i,j;
- double h,r;
- for(i=0;i<=stacks;i++)
- {
- h=height*(double)i/(double)stacks;
- r=radius;
- for(j=0;j<=slices;j++)
- {
- points[i][j].x=r*cos(((double)j/(double)slices)*2*pi)
- +bigradius*cos(ang*pi/180)-bigradius;
- points[i][j].y=r*sin(((double)j/(double)slices)*2*pi);
- points[i][j].z=h; ///this creates the upper half
- }
- ang=ang+angle/stacks;
- }
- for(i=0;i<stacks;i++)
- {
- for(j=0;j<slices;j++)
- {
- glColor3f(200,200,200);
- glBegin(GL_QUADS);{
- glVertex3f(points[i][j].x,points[i][j].y,points[i][j].z);
- glVertex3f(points[i][j+1].x,points[i][j+1].y,points[i][j+1].z);
- glVertex3f(points[i+1][j+1].x,points[i+1][j+1].y,points[i+1][j+1].z);
- glVertex3f(points[i+1][j].x,points[i+1][j].y,points[i+1][j].z);
- }glEnd();
- }
- }
- }
- void drawCurvedCylinder(float length, float angle, float radius)
- {
- glPushMatrix();{
- glRotatef(-90,1,0,0);
- glRotatef(90,0,1,0);
- glTranslatef(0,0,-length/2);
- drawCurvedCylinderBasic(length,angle,radius);
- }glPopMatrix();
- }
- void drawGrid()
- {
- int i;
- if(drawgrid==1)
- {
- glColor3f(0.6, 0.6, 0.6); //grey
- glBegin(GL_LINES);{
- for(i=-8;i<=8;i++){
- if(i==0)
- continue; //SKIP the MAIN axes
- //lines parallel to Y-axis
- glVertex3f(i*10, -90, 0);
- glVertex3f(i*10, 90, 0);
- //lines parallel to X-axis
- glVertex3f(-90, i*10, 0);
- glVertex3f( 90, i*10, 0);
- }
- }glEnd();
- }
- }
- void drawSquare(float a)
- {
- glBegin(GL_QUADS);{
- glVertex3f( a, a,2);
- glVertex3f( a,-a,2);
- glVertex3f(-a,-a,2);
- glVertex3f(-a, a,2);
- }glEnd();
- }
- void drawBaseCircle(float angle, float radius, float thickness)
- {
- point a;
- vector<point> v1,v2;
- for(float i=-angle/2;i<=angle/2;i++)
- {
- a.x=radius*sin(i*pi/180);
- a.y=-radius*cos(i*pi/180);
- a.z=0;
- v1.push_back(a);
- }
- for(int i=0;i<v1.size()-1;i++)
- {
- glBegin(GL_QUADS);{
- glVertex3f(v1[i].x,v1[i].y,v1[i].z);
- glVertex3f(v1[i].x,v1[i].y,v1[i].z-thickness);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z-thickness);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(0,0,0);
- glVertex3f(v1[i].x,v1[i].y,v1[i].z);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z);
- glVertex3f(0,0,0);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(0,0,0);
- glVertex3f(v1[i].x,v1[i].y,v1[i].z-thickness);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z-thickness);
- glVertex3f(0,0,0);
- }glEnd();
- }
- glBegin(GL_QUADS);{
- glVertex3f(0,0,0);
- glVertex3f(radius*sin(angle/2*pi/180),-radius*cos(angle/2*pi/180),0);
- glVertex3f(radius*sin(angle/2*pi/180),-radius*cos(angle/2*pi/180),-thickness);
- glVertex3f(0,0,-thickness);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(0,0,0);
- glVertex3f(radius*sin(-angle/2*pi/180),-radius*cos(-angle/2*pi/180),0);
- glVertex3f(radius*sin(-angle/2*pi/180),-radius*cos(-angle/2*pi/180),-thickness);
- glVertex3f(0,0,-thickness);
- }glEnd();
- }
- void triangularBasic(float first, float third, float width )
- {
- glBegin(GL_QUADS);{
- glColor3f(200,200,200);
- glVertex3f(third/2,0,width);
- glVertex3f(0,sqrt(first*first-third*third/4),width);
- glVertex3f(0,sqrt(first*first-third*third/4),width);
- glVertex3f(-third/2,0,width);
- }glEnd();
- glBegin(GL_QUADS);{glColor3f(200,200,200);
- glVertex3f(third/2,0,width);
- glVertex3f(third/2,0,0);
- glVertex3f(0,sqrt(first*first-third*third/4),0);
- glVertex3f(0,sqrt(first*first-third*third/4),width);
- }glEnd();
- glBegin(GL_QUADS);{glColor3f(200,200,200);
- glVertex3f(-third/2,0,width);
- glVertex3f(-third/2,0,0);
- glVertex3f(0,sqrt(first*first-third*third/4),0);
- glVertex3f(0,sqrt(first*first-third*third/4),width);
- }glEnd();
- glBegin(GL_QUADS);{glColor3f(200,200,200);
- glVertex3f(third/2,0,0);
- glVertex3f(0,sqrt(first*first-third*third/4),0);
- glVertex3f(0,sqrt(first*first-third*third/4),0);
- glVertex3f(-third/2,0,0);
- }glEnd();
- glBegin(GL_QUADS);{glColor3f(200,200,200);
- glVertex3f(third/2, 0,width);
- glVertex3f(third/2, 0,0);
- glVertex3f(-third/2, 0,0);
- glVertex3f(-third/2, 0,width);
- }glEnd();
- }
- void triangular(float first, float third, float width, float clip )
- {
- glPushMatrix();{
- double equ[4];
- equ[0] = 0; //0.x
- equ[1] = -1; //0.y
- equ[2] = 0;//-1.z
- equ[3] = clip;//30
- glClipPlane(GL_CLIP_PLANE0,equ);
- glEnable(GL_CLIP_PLANE0);{
- triangularBasic(1000,70,10);
- }glDisable(GL_CLIP_PLANE0);
- }glPopMatrix();
- //triangularBasic( first, third, width );
- }
- void drawHexCap(float height, float side)
- {
- glColor3f(200,200,200);
- glBegin(GL_QUADS);{
- glVertex3f(side, 0,0);
- glVertex3f(side*cos(pi/3),side*cos(pi/6),0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();;
- glBegin(GL_QUADS);{
- glVertex3f(side*cos(pi/3),side*cos(pi/6),0);
- glVertex3f(-side*cos(pi/3),side*cos(pi/6),0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(-side*cos(pi/3),side*cos(pi/6),0);
- glVertex3f(-side,0,0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(-side,0,0);
- glVertex3f(-side*cos(pi/3),-side*cos(pi/6),0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(-side*cos(pi/3),-side*cos(pi/6),0);
- glVertex3f(side*cos(pi/3),-side*cos(pi/6),0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();
- glBegin(GL_QUADS);{
- glVertex3f(side*cos(pi/3),-side*cos(pi/6),0);
- glVertex3f(side,0,0);
- glVertex3f(0,0,height);
- glVertex3f(0,0,height);
- }glEnd();
- }
- void drawRectBarBasic(float length, float side)
- {
- glBegin(GL_QUADS);{
- glColor3f((float)240/256,(float)248/256,(float)255/256);
- glVertex3f(length/2,-side/2,side/2);
- glVertex3f(length/2,-side/2,-side/2);
- glVertex3f(-length/2,-side/2,-side/2);
- glVertex3f(-length/2,-side/2,side/2);
- }glEnd();
- }
- void drawRectBar(float length, float side)
- {
- drawRectBarBasic(length,side);
- glPushMatrix();
- {
- glTranslatef(0,side,0);
- drawRectBarBasic(length,side);
- }glPopMatrix();
- glPushMatrix();
- {
- glRotatef(90,1,0,0);
- glColor3f(1,0,0);
- drawRectBarBasic(length,side);
- }glPopMatrix();
- glPushMatrix();
- {
- glRotatef(-90,1,0,0);
- glColor3f(1,0,0);
- drawRectBarBasic(length,side);
- }glPopMatrix();
- }
- void HexColumnBasic(float length, float side)
- {
- glBegin(GL_QUADS);{
- glVertex3f(0,0,0);
- glVertex3f(side,0,0);
- glVertex3f(side,0,length);
- glVertex3f(0,0,length);
- }glEnd();;
- }
- void drawHexColumn(float length, float side)
- {
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated((float)side*cos(pi/3),-(float)side*cos(pi/6),0);
- //glTranslated(side,0,0);
- glRotated(60,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated(-side,0,0);
- glRotated(60,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated(-side/2,(float)side*cos(pi/6),0);
- //glRotated(60,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated(-side/2,-(float)side*cos(pi/6),0);
- //glRotated(60,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated(-side,0,0);
- //glTranslated(side,0,0);
- glRotated(300,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- glColor3f(200,200,200);
- glPushMatrix();{
- glTranslated(side/2,(float)side*cos(pi/6),0);
- //glTranslated(side,0,0);
- glRotated(300,0,0,1);
- HexColumnBasic(length,side);
- }glPopMatrix();
- }
- void drawCylinder(float height, float radius, int stacks, int slices)
- {
- struct point points[100][100];
- int i,j;
- double h,r;
- for(i=0;i<=stacks;i++)
- {
- h=height*(double)i/(double)stacks/2;
- r=radius;
- for(j=0;j<=slices;j++)
- {
- points[i][j].x=r*cos(((double)j/(double)slices)*2*pi);
- points[i][j].y=r*sin(((double)j/(double)slices)*2*pi);
- points[i][j].z=h; ///this creates the upper half
- }
- }
- for(i=0;i<stacks;i++)
- {
- for(j=0;j<slices;j++)
- {
- glColor3f(200,200,200);
- glBegin(GL_QUADS);{
- glVertex3f(points[i][j].x,points[i][j].y,points[i][j].z);
- glVertex3f(points[i][j+1].x,points[i][j+1].y,points[i][j+1].z);
- glVertex3f(points[i+1][j+1].x,points[i+1][j+1].y,points[i+1][j+1].z);
- glVertex3f(points[i+1][j].x,points[i+1][j].y,points[i+1][j].z);
- }glEnd();
- }
- }
- for(i=0;i<=stacks;i++)
- {
- h=height*(double)i/(double)stacks/2;
- r=radius;
- for(j=0;j<=slices;j++)
- {
- points[i][j].x=r*cos(((double)j/(double)slices)*2*pi);
- points[i][j].y=r*sin(((double)j/(double)slices)*2*pi);
- points[i][j].z=-h; ///this creates the lower half
- }
- }
- for(i=0;i<stacks;i++)
- {
- for(j=0;j<slices;j++)
- {
- glColor3f(200,200,200);
- glBegin(GL_QUADS);{
- glVertex3f(points[i][j].x,points[i][j].y,points[i][j].z);
- glVertex3f(points[i][j+1].x,points[i][j+1].y,points[i][j+1].z);
- glVertex3f(points[i+1][j+1].x,points[i+1][j+1].y,points[i+1][j+1].z);
- glVertex3f(points[i+1][j].x,points[i+1][j].y,points[i+1][j].z);
- }glEnd();
- }
- }
- }
- void twoColumn()
- {
- float length=1014.73;
- glPushMatrix();{
- glTranslated(-105,0,0);
- glRotated(6,0,1,0);
- drawHexColumn(length,33.13);
- }glPopMatrix();
- glPushMatrix();{
- glTranslated(105,0,0);
- glRotated(-6,0,1,0);
- drawHexColumn(length,33.13);
- }glPopMatrix();
- glPushMatrix(); ///strip
- {
- glTranslatef(0,0,100);
- glRotatef(4,1,0,0);
- float x,y,z,xa,ya,za;
- x=150;
- y=300;
- z=600;
- xa=90;
- za=30;
- glPushMatrix();{
- glTranslatef(-x,y,z);
- glRotatef(za,0,0,1);
- glRotatef(90,1,0,0);
- drawCircularStrip();
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(x,y,z);
- glRotatef(-za,0,0,1);
- glRotatef(90,1,0,0);
- drawCircularStrip();
- }glPopMatrix();
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,0,250);
- drawRectBar(200,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,0,400);
- drawRectBar(150,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,0,550);
- drawRectBar(100,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,0,650);
- drawRectBar(100,20);
- }glPopMatrix();
- rods();
- //drawCurvedCylinder(1000, 10, 10);
- glPushMatrix();///extension of strips
- {
- glTranslatef(-100,170,-20);///////////
- glRotatef(30,1.9,1,.47);
- glRotatef(120,0,0,1);
- glRotatef(90,1,0,0);
- triangular(1000,70,10,500);//////////////
- }glPopMatrix();
- //}glPopMatrix();
- glPushMatrix();
- {
- glScalef(-1, 1, 1);
- glPushMatrix();
- {
- glTranslatef(-100,170,-20);///////////
- glRotatef(30,1.9,1,.47);
- glRotatef(120,0,0,1);
- glRotatef(90,1,0,0);
- triangular(1000,70,10,500);//////////////
- }glPopMatrix();
- }glPopMatrix();
- //drawBase();
- }
- void drawCircularStrip()
- {
- vector<point> v1,v2,v3,v4;
- double radius1,radius2,width;
- radius1=200;
- radius2=190;
- width=10;
- for(int i=-45;i<52;i++)
- {
- float scale=.45;
- point a;
- a.x=-width/2;
- a.y=scale*6*radius1*sin(pi*i/180);
- a.z=scale*5*radius1*cos(pi*i/180);
- v1.push_back(a);
- a.x=width/2;
- a.y=scale*6*radius1*sin(pi*i/180);
- a.z=scale*5*radius1*cos(pi*i/180);
- v2.push_back(a);
- a.x=-width/2;
- a.y=scale*5.5*radius2*sin(pi*i/180);
- a.z=scale*5*radius2*cos(pi*i/180);
- v3.push_back(a);
- a.x=width/2;
- a.y=scale*5.5*radius2*sin(pi*i/180);
- a.z=scale*5*radius2*cos(pi*i/180);
- v4.push_back(a);
- }
- for(int i=0;i<v1.size()-1;i++)
- {
- glBegin(GL_QUADS);{
- glColor3d((float)200/256,(float)200/256,(float)200/256);
- glVertex3f(v1[i].x,v1[i].y,v1[i].z);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z);
- glVertex3f(v2[i+1].x,v2[i+1].y,v2[i+1].z);
- glVertex3f(v2[i].x,v2[i].y,v2[i].z);
- }glEnd();
- glBegin(GL_QUADS);{
- glColor3d((float)200/256,(float)200/256,(float)200/256);
- glVertex3f(v3[i].x,v3[i].y,v3[i].z);
- glVertex3f(v3[i+1].x,v3[i+1].y,v3[i+1].z);
- glVertex3f(v4[i+1].x,v4[i+1].y,v4[i+1].z);
- glVertex3f(v4[i].x,v4[i].y,v4[i].z);
- }glEnd();
- ///right side
- glBegin(GL_QUADS);{
- glColor3d((float)200/256,(float)200/256,(float)200/256);
- glVertex3f(v1[i].x,v1[i].y,v1[i].z);
- glVertex3f(v1[i+1].x,v1[i+1].y,v1[i+1].z);
- glVertex3f(v3[i+1].x,v3[i+1].y,v3[i+1].z);
- glVertex3f(v3[i].x,v3[i].y,v3[i].z);
- }glEnd();
- ///left side
- glBegin(GL_QUADS);{
- glColor3d((float)200/256,(float)200/256,(float)200/256);
- glVertex3f(v2[i+1].x,v2[i+1].y,v2[i+1].z);
- glVertex3f(v2[i].x,v2[i].y,v2[i].z);
- glVertex3f(v4[i].x,v4[i].y,v4[i].z);
- glVertex3f(v4[i+1].x,v4[i+1].y,v4[i+1].z);
- }glEnd();
- }
- }
- void rods()
- {///curved rods
- glPushMatrix();{
- glTranslatef(0,-47,400);
- drawCurvedCylinder(60,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-99,490);
- drawCurvedCylinder(89,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-135,550);
- drawCurvedCylinder(128,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-145,610);
- drawCurvedCylinder(145,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-145,660);
- drawCurvedCylinder(145,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-155,710);
- drawCurvedCylinder(140,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-155,760);
- drawCurvedCylinder(140,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-155,810);
- drawCurvedCylinder(140,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-140,860);
- drawCurvedCylinder(130,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-125,910);
- drawCurvedCylinder(110,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-110,950);
- drawCurvedCylinder(95,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-95,995);
- drawCurvedCylinder(70,50,5);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-75,1019);
- drawCurvedCylinder(50,50,5);
- }glPopMatrix();
- ///straight rods
- glPushMatrix();{
- glTranslatef(45,-30,490);
- glRotatef(90,1,0,0);
- drawCylinder(100,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-45,-30,490);
- glRotatef(90,1,0,0);
- drawCylinder(100,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(64,-30,550);
- glRotatef(90,1,0,0);
- drawCylinder(110,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-64,-30,550);
- glRotatef(90,1,0,0);
- drawCylinder(110,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(60,-50,610);
- glRotatef(10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(110,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-60,-50,610);
- glRotatef(-10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(110,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(60,-50,660);
- glRotatef(10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(120,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-60,-50,660);
- glRotatef(-10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(120,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(60,-50,710);
- glRotatef(10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-60,-50,710);
- glRotatef(-10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(60,-50,760);
- glRotatef(10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-60,-50,760);
- glRotatef(-10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(53,-50,810);
- glRotatef(10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-53,-50,810);
- glRotatef(-10,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(125,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(50,-50,860);
- glRotatef(12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(128,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-50,-50,860);
- glRotatef(-12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(128,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(40,-50,910);
- glRotatef(12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(120,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-40,-50,910);
- glRotatef(-12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(120,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(37,-50,950);
- glRotatef(12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(102,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-37,-50,950);
- glRotatef(-12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(102,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(30,-50,995);
- glRotatef(12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(70,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-30,-50,995);
- glRotatef(-12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(70,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(20,-50,1019);
- glRotatef(12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(50,5,20,20);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(-20,-50,1019);
- glRotatef(-12,0,0,1);
- glRotatef(90,1,0,0);
- drawCylinder(50,5,20,20);
- }glPopMatrix();
- }
- void drawCurveColumns(){
- double ang = 50;
- glPushMatrix();{
- glTranslated(0.5,0,0);
- glRotated(-ang,0,0,1);
- glPushMatrix();{
- glTranslated(0,-12,13.5);
- glRotated(-37,1,0,0);
- //drawRectBar(1.25,0.4,1.25,15,55);
- };glPopMatrix();
- glTranslated(0,2,82);
- glRotated(-18,1,0,0);
- glTranslated(0,-4.5,-37);
- // drawColumnStrip(1.25,22);
- }glPopMatrix();
- }
- void drawss()
- {
- glPushMatrix();{
- glTranslated(900,0,0);
- drawsphere(20,20,20);}glPopMatrix();
- twoColumn();
- glPushMatrix();{
- glTranslatef(0,0,1014);
- drawHexCap(300,33.13);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-150,0);
- drawBase(.75);
- }glPopMatrix();
- glPushMatrix();{
- glTranslatef(0,-150,-20);
- drawBase(.75);
- }glPopMatrix();
- glPushMatrix();{
- glRotatef(180,0,0,1);
- drawBaseCircle(58, 300, 20);
- }glPopMatrix();
- //drawCurvedCylinder(1000,50,2);
- }
- //draws half sphere
- void drawsphere(float radius,int slices,int stacks)
- {
- struct point points[100][100];
- int i,j;
- double h,r;
- for(i=0;i<=stacks;i++)
- {
- h=radius*sin(((double)i/(double)stacks)*(pi/2));
- r=sqrt(radius*radius-h*h);
- for(j=0;j<=slices;j++)
- {
- points[i][j].x=r*cos(((double)j/(double)slices)*2*pi);
- points[i][j].y=r*sin(((double)j/(double)slices)*2*pi);
- points[i][j].z=h; ///this creates the upper half
- }
- }
- for(i=0;i<stacks;i++)
- {
- for(j=0;j<slices;j++)
- {
- glColor3f((double)i/(double)stacks,(double)i/(double)stacks,(double)i/(double)stacks);
- glBegin(GL_QUADS);{
- glVertex3f(points[i][j].x,points[i][j].y,points[i][j].z);
- glVertex3f(points[i][j+1].x,points[i][j+1].y,points[i][j+1].z);
- glVertex3f(points[i+1][j+1].x,points[i+1][j+1].y,points[i+1][j+1].z);
- glVertex3f(points[i+1][j].x,points[i+1][j].y,points[i+1][j].z);
- }glEnd();
- }
- }
- for(i=0;i<=stacks;i++)
- {
- h=radius*sin(((double)i/(double)stacks)*(pi/2));
- r=sqrt(radius*radius-h*h);
- for(j=0;j<=slices;j++)
- {
- points[i][j].x=r*cos(((double)j/(double)slices)*2*pi);
- points[i][j].y=r*sin(((double)j/(double)slices)*2*pi);
- points[i][j].z=-h; ///this creates the lower half
- }
- }
- for(i=0;i<stacks;i++)
- {
- for(j=0;j<slices;j++)
- {
- glColor3f((double)i/(double)stacks,(double)i/(double)stacks,(double)i/(double)stacks);
- glBegin(GL_QUADS);{
- glVertex3f(points[i][j].x,points[i][j].y,points[i][j].z);
- glVertex3f(points[i][j+1].x,points[i][j+1].y,points[i][j+1].z);
- glVertex3f(points[i+1][j+1].x,points[i+1][j+1].y,points[i+1][j+1].z);
- glVertex3f(points[i+1][j].x,points[i+1][j].y,points[i+1][j].z);
- }glEnd();
- }
- }
- }
- void keyboardListener(unsigned char key, int x,int y){
- switch(key){
- case '1':
- drawgrid=1-drawgrid;
- break;
- default:
- break;
- }
- }
- void specialKeyListener(int key, int x,int y){
- switch(key){
- case GLUT_KEY_DOWN: //down arrow key
- cameraHeight -= 30.0;
- break;
- case GLUT_KEY_UP: // up arrow key
- cameraHeight += 30.0;
- break;
- case GLUT_KEY_RIGHT:
- cameraAngle += 0.03;
- break;
- case GLUT_KEY_LEFT:
- cameraAngle -= 0.03;
- break;
- case GLUT_KEY_PAGE_UP:
- break;
- case GLUT_KEY_PAGE_DOWN:
- break;
- case GLUT_KEY_INSERT:
- break;
- case GLUT_KEY_HOME:
- break;
- case GLUT_KEY_END:
- break;
- default:
- break;
- }
- }
- void mouseListener(int button, int state, int x, int y){ //x, y is the x-y of the screen (2D)
- switch(button){
- case GLUT_LEFT_BUTTON:
- if(state == GLUT_DOWN){ // 2 times?? in ONE click? -- solution is checking DOWN or UP
- drawaxes=1-drawaxes;
- }
- break;
- case GLUT_RIGHT_BUTTON:
- //........
- break;
- case GLUT_MIDDLE_BUTTON:
- //........
- break;
- default:
- break;
- }
- }
- void display(){
- //clear the display
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor(0,0,0,0); //color black
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- /********************
- / set-up camera here
- ********************/
- //load the correct matrix -- MODEL-VIEW matrix
- glMatrixMode(GL_MODELVIEW);
- //initialize the matrix
- glLoadIdentity();
- //now give three info
- //1. where is the camera (viewer)?
- //2. where is the camera looking?
- //3. Which direction is the camera's UP direction?
- //gluLookAt(100,100,100, 0,0,0, 0,0,1);
- gluLookAt(500*cos(cameraAngle), 500*sin(cameraAngle), cameraHeight, 0,0,0, 0,0,1);
- //gluLookAt(0,-1,150, 0,0,0, 0,0,1);
- //again select MODEL-VIEW
- glMatrixMode(GL_MODELVIEW);
- /****************************
- / Add your objects from here
- ****************************/
- //add objects
- drawAxes();
- drawGrid();
- drawss();
- //ADD this line in the end --- if you use double buffer (i.e. GL_DOUBLE)
- glutSwapBuffers();
- }
- void animate(){
- angle+=0.05;
- //codes for any changes in Models, Camera
- glutPostRedisplay();
- }
- void init(){
- //codes for initialization
- drawgrid=0;
- drawaxes=1;
- cameraHeight=1000.0;
- cameraAngle=1.0;
- angle=0;
- //clear the screen
- glClearColor(0,0,0,0);
- /************************
- / set-up projection here
- ************************/
- //load the PROJECTION matrix
- glMatrixMode(GL_PROJECTION);
- //initialize the matrix
- glLoadIdentity();
- //give PERSPECTIVE parameters
- gluPerspective(80, 1, 1, 10000.0);
- //field of view in the Y (vertically)
- //aspect ratio that determines the field of view in the X direction (horizontally)
- //near distance
- //far distance
- }
- int main(int argc, char **argv){
- glutInit(&argc,argv);
- glutInitWindowSize(500, 500);
- glutInitWindowPosition(0, 0);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB); //Depth, Double buffer, RGB color
- glutCreateWindow("Mega structure, 0905004");
- init();
- glEnable(GL_DEPTH_TEST); //enable Depth Testing
- glutDisplayFunc(display); //display callback function
- glutIdleFunc(animate); //what you want to do in the idle time (when no drawing is occuring)
- glutKeyboardFunc(keyboardListener);
- glutSpecialFunc(specialKeyListener);
- glutMouseFunc(mouseListener);
- glutMainLoop(); //The main loop of OpenGL
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement