Академический Документы
Профессиональный Документы
Культура Документы
#include
#include
#include
<GL/glut.h>
<math.h>
<stdio.h>
<string.h>
#define X 1
#define Y 2
#define Z 3
float iden[4][4]={0};
int xinc=3, yinc=3,x=0,y=0;
typedef struct point // will store the lowest
{
float x, y, z,h; //x , y,z coordinates
}point;
glTranslatef(p1.x,p1.y,p1.z);
glRotatef(theta, vx,vy,vz);
glTranslatef(-p1.x,-p1.y,-p1.z);
}
void drawCube1(cube c)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
And Depth Buffer
glBegin(GL_QUADS);
// Draw A Quad
glColor3f(0.0f,1.0f,0.0f);
Set The Color To Green
glVertex3f( 50.0f, 50.0f,-50.0f);
Top Right Of The Quad (Top)
glVertex3f(-50.0f, 50.0f,-50.0f);
Top Left Of The Quad (Top)
glVertex3f(-50.0f, 50.0f, 50.0f);
Bottom Left Of The Quad (Top)
glVertex3f( 50.0f, 50.0f, 50.0f);
Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f);
Set The Color To Orange
glVertex3f( 50.0f,-50.0f, 50.0f);
Top Right Of The Quad (Bottom)
glVertex3f(-50.0f,-50.0f, 50.0f);
Top Left Of The Quad (Bottom)
glVertex3f(-50.0f,-50.0f,-50.0f);
Bottom Left Of The Quad (Bottom)
glVertex3f( 50.0f,-50.0f,-50.0f);
Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f);
Set The Color To Red
glVertex3f( 50.0f, 50.0f, 50.0f);
Top Right Of The Quad (Front)
glVertex3f(-50.0f, 50.0f, 50.0f);
Top Left Of The Quad (Front)
glVertex3f(-50.0f,-50.0f, 50.0f);
Bottom Left Of The Quad (Front)
glVertex3f( 50.0f,-50.0f, 50.0f);
Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f);
Set The Color To Yellow
glVertex3f( 50.0f,-50.0f,-50.0f);
Top Right Of The Quad (Back)
glVertex3f(-50.0f,-50.0f,-50.0f);
Top Left Of The Quad (Back)
glVertex3f(-50.0f, 50.0f,-50.0f);
Bottom Left Of The Quad (Back)
glVertex3f( 50.0f, 50.0f,-50.0f);
Bottom Right Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f);
Set The Color To Blue
glVertex3f(-50.0f, 50.0f, 50.0f);
Top Right Of The Quad (Left)
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
glVertex3f(-50.0f, 50.0f,-50.0f);
Top Left Of The Quad (Left)
glVertex3f(-50.0f,-50.0f,-50.0f);
Bottom Left Of The Quad (Left)
glVertex3f(-50.0f,-50.0f, 50.0f);
Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f);
Set The Color To Violet
glVertex3f( 50.0f, 50.0f,-50.0f);
Top Right Of The Quad (Right)
glVertex3f( 50.0f, 50.0f, 50.0f);
Top Left Of The Quad (Right)
glVertex3f( 50.0f,-50.0f, 50.0f);
Bottom Left Of The Quad (Right)
glVertex3f( 50.0f,-50.0f,-50.0f);
Bottom Right Of The Quad (Right)
glEnd();
// Done Drawing The Quad
}
void drawCube(cube c)
{
//back surface of sube
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glBegin(GL_LINE_LOOP);
glVertex3f(c.x[0].x,c.x[0].y,c.x[0].z);
glVertex3f(c.x[1].x,c.x[1].y,c.x[1].z);
glVertex3f(c.x[2].x,c.x[2].y,c.x[2].z);
glVertex3f(c.x[3].x,c.x[3].y,c.x[3].z);
glEnd();
// front surface
glBegin(GL_LINE_LOOP);
glVertex3f(c.x[4].x,c.x[4].y,c.x[4].z);
glVertex3f(c.x[5].x,c.x[5].y,c.x[5].z);
glVertex3f(c.x[6].x,c.x[6].y,c.x[6].z);
glVertex3f(c.x[7].x,c.x[7].y,c.x[7].z);
glEnd();
// Connect two surfaces with lines to form side surfaces
glBegin(GL_LINES);
glVertex3f(c.x[0].x,c.x[0].y,c.x[0].z);
glVertex3f(c.x[4].x,c.x[4].y,c.x[4].z);
glVertex3f(c.x[1].x,c.x[1].y,c.x[1].z);
glVertex3f(c.x[5].x,c.x[5].y,c.x[5].z);
glVertex3f(c.x[2].x,c.x[2].y,c.x[2].z);
glVertex3f(c.x[6].x,c.x[6].y,c.x[6].z);
glVertex3f(c.x[3].x,c.x[3].y,c.x[3].z);
glVertex3f(c.x[7].x,c.x[7].y,c.x[7].z);
glEnd();
glFinish();
glViewport(0,0,w,h);
}
void drawSphere(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere (50, 30, 20);
//
//
//
//
//
//
//
//
glFlush ();
}
void drawRect(rect r)
{
Set
Set
Set
Set
glBegin(GL_QUADS);
// Draw A Quad
glColor3f(0.0f,1.0f,0.0f);
The Color To Blue
glVertex3f( r.x[0].x, r.x[0].y,r.x[0].z);
// Top Right Of The Quad (Top)
glColor3f(1.0f,0.0f,0.0f);
The Color To Blue
glVertex3f(r.x[1].x, r.x[0].y,r.x[0].z);
// Top Left Of The Quad (Top)
glColor3f(0.0f,0.0f,1.0f);
The Color To Blue
glVertex3f(r.x[1].x, r.x[1].y,r.x[0].z);
// Bottom Left Of The Quad (Top)
glColor3f(1.0f,1.0f,0.0f);
The Color To Blue
glVertex3f( r.x[0].x, r.x[1].y,r.x[0].z);
// Bottom Right Of The Quad (Top)
glEnd();
//
//
//
//
}
void display(void)
{
cube c;
rect r;
int i,l=50;
point p1={25,0,0}, p2={25,10,0};
float mat[4][4]={0},mat1[4][4],mat2[4][4];
r.x[0].x=r.x[0].y=r.x[0].z=-l/2;
r.x[1].x=l=r.x[1].y=r.x[1].z=l/2;
r.x[0].z=r.x[1].z=0;
c.x[0].x=c.x[0].y=c.x[0].z=0;
c.x[1].x=l;c.x[1].y=c.x[1].z=0;
c.x[2].x=c.x[2].y=l;c.x[2].z=0;
c.x[3].x=0;c.x[3].y=l;c.x[3].z=0;
c.x[4].x=c.x[4].y=0;c.x[4].z=l;
c.x[5].x=l;c.x[5].y=0,c.x[5].z=l;
c.x[6].x=c.x[6].y=c.x[6].z=l;
c.x[7].x=0;c.x[7].y=c.x[7].z=l;
c.x[0].h=c.x[1].h=c.x[2].h=c.x[4].h=c.x[5].h=c.x[6].h=c.x[7].h=c.x[
3].h=1; // CHANGE
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen
And Depth Buffer
glColor3f(0.0,0.0,0.0) ;
// draw axes
glBegin(GL_LINES);
glVertex3i(-400,0,0);
glVertex3i(400,0,0);
glVertex3i(0,-400,0);
glVertex3i(0,400,0);
glVertex3i(0,0,-400);
glVertex3i(0,0,400);
glEnd();
glColor3f(0.0,1.0,0.0) ;
glBegin(GL_LINES);
glVertex3i(0,0,0);
glVertex3i(50,50,50);
glEnd();
glutSwapBuffers();
}