コード例 #1
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void drawRoad(int i)
{
	glPushMatrix();
		glTranslatef(0, -1.0f, stepObj[i].z);
		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
		if(stepObj[i].type == 0){
			road.draw();
			drawCar(10.0f, 0, 0.09f, i);
		}else if(stepObj[i].type == 1){
			grass.draw();
		}
	glPopMatrix();
		

}
コード例 #2
0
ファイル: main.cpp プロジェクト: streibeb/cs409
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// clear the screen - any drawing before here will not display

	glLoadIdentity();
	// set up the camera here
    camera.setCamera();

	// camera is set up - any drawing before here will display incorrectly
    
    // Draw Skybox
    glPushMatrix();
        glTranslatef(camera.getPosition().x,
                     camera.getPosition().y,
                     camera.getPosition().z);
        glDepthMask(GL_FALSE);
        skybox.draw();
        glDepthMask(GL_TRUE);
    glPopMatrix();

    // Draw Saturn
    glPushMatrix();
        glTranslatef(saturnInfo.x, 0.f, saturnInfo.z);
        glScalef(saturnInfo.radius, saturnInfo.radius, saturnInfo.radius);
        saturn.draw();
    glPopMatrix();
    
    // Draw Moons
    for (int i = 0; i < 10; i++)
    {
        glPushMatrix();
            glTranslatef(moonInfo[i].x, 0.f, moonInfo[i].z);
            glScalef(moonInfo[i].radius, moonInfo[i].radius, moonInfo[i].radius);
            moons[i].draw();
        glPopMatrix();
    }
    
    // Draw rings
    glPushMatrix();
        glTranslatef(ringInfo.x, 0.f, ringInfo.z);
        glScalef(ringInfo.radius, ringInfo.radius, ringInfo.radius);
        ring.draw();
    glPopMatrix();
    
	// send the current image to the screen - any drawing after here will not display
	glutSwapBuffers();
}
コード例 #3
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void drawCar(float  y, float z, float scale, int i)
{
	glPushMatrix();
		glTranslatef(0, 1, count_steps[i]);
		glScalef(scale,scale,scale);
		//glRotatef(90.0f, 0.0f, 1.0f, 0.0f);        
		car1.draw();
	glPopMatrix();
}
コード例 #4
0
ファイル: crossy.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void player()
{
	glPushMatrix();
        glTranslatef(playerX, playerY, playerZ);
		glRotatef(playerAngle, 0.0f, 1.0f, 0.0f);
        glScalef(playerSX, playerSY, playerSZ);
        player1.draw();
    glPopMatrix();
}
コード例 #5
0
ファイル: main.cpp プロジェクト: AbdulazizAlaa/OpenRoad
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	gluLookAt(2.0, 3.0, 4.0,
	          0.0, 0.0, 0.0,
	          0.0, 1.0, 0.0);

	// display positive X, Y, and Z axes near origin
	glBegin(GL_LINES);
		glColor3d(1.0, 0.0, 0.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(2.0, 0.0, 0.0);
		glColor3d(0.0, 1.0, 0.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(0.0, 2.0, 0.0);
		glColor3d(0.0, 0.0, 1.0);
		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(0.0, 0.0, 2.0);
	glEnd();

	// draw a purple wireframe cube
	glColor3d(1.0, 0.0, 1.0);
	glPushMatrix();
		glTranslated(0.0, 0.0, 0.0);
		glRotated(45, 0.0, 1.0, 0.0);
		glScaled(1.0, 1.0, 1.0);
		glutWireCube(1.0);
	glPopMatrix();

	glPushMatrix();
		glTranslated(0.0, 0.0, 0.0);
//		glRotated(45, 0.0, 1.0, 0.0);
		glScaled(0.005, 0.005, 0.005);		
		bucket.draw();
	glPopMatrix();

	glutSwapBuffers();
}
コード例 #6
0
void whale_model()
{
	
	//glMatrixMode(GL_MODELVIEW);
	GLUquadricObj* Sphere;
	Sphere=gluNewQuadric();
	float theta=0;
	


if(v_whale_z<0)
		{
			theta = 3.14 + atan(v_whale_x/v_whale_z);
		}


		else if (v_whale_z>0 )
		{
			theta = atan(v_whale_x/v_whale_z);
		}


		else
		{
			if(v_whale_x>0)
			{
				theta= 3.14/2;
			}
			else if(v_whale_x<0)
			{
				theta = (3 * 3.14) / 2;
			}

	   }
		theta = (theta * 180) / 3.14;
		float r;
		r = sqrt(powf(v_whale_x,2)+powf(v_whale_z,2));

		float pi;
		if(v_whale_y!=0 && r>0)
		{
			pi=atan(v_whale_y/r);
		}


		else if(r==0)
		{
			if(p_whale_y>0)
			{
				pi=3.14/2;
			}

			else if(p_whale_y<0)
			{
				pi = (3.14 * 3)/2;
			}
		}

		pi = (pi * 180) / 3.14;
		
		
		submarine1 sub2;
        GLUquadricObj *Spher;
		Spher = gluNewQuadric();
		glPushMatrix();
		
		glTranslatef(p_whale_x, p_whale_y, p_whale_z);	// unneeded since default position is (0, 0, 0)
		/*glBegin(GL_LINES);
              glVertex3d(0, 0, 0);
              glVertex3d(vx[i], vy[i], vz[i]);
         glEnd();*/
		glRotatef(theta, 0.0, 1.0, 0.0);	// unneeded since default rotation is 0 degrees
		glRotatef(pi, -1.0, 0.0, 0.0);
		 glScalef(7.0, 7.0, 7.0);		// unneeded since default scaling is 1 in X, Y, and Z
		glRotatef(90, 0.0, 1.0, 0.0);
	    whale_body.draw();
		if(sphere==true)
		{
		glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
		glColor4f(sub2.red, sub2.green, sub2.blue, 0.2f);
		gluSphere(Spher,1, 10, 10);
 
		glDisable(GL_BLEND);
		}
		
		
	   glPopMatrix();
		
		}
コード例 #7
0
void draw()
{
	glClearColor(1, 1, 1, 1);

	glLoadIdentity();
	float x1, y1, z1, x2=-65.147f, y2=80.219f, z2=12.301f;
	static int index = 0;

	TheoraVideoFrame* f=clip->getNextFrame();
	if (f)
	{
		index = (int)f->getFrameNumber();
		glBindTexture(GL_TEXTURE_2D,tex_id);
		unsigned char* buffer = f->getBuffer();
		int x, len = f->getWidth() * f->getHeight() * 3;
		for (int i = 0; i < len; i++)
		{
			x = (*buffer) * 0.8f + 255 * 0.2f;
			if (x > 255) *buffer = 255;
			else *buffer = x;
			buffer++;
		}
		
		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,f->getWidth(),f->getHeight(),GL_RGB,GL_UNSIGNED_BYTE,f->getBuffer());
		clip->popFrame();
	}
	x1 = camera_pos[index].x; y1 = camera_pos[index].y; z1 = camera_pos[index].z;
	gluLookAt(x1, z1, -y1, x2, z2, -y2,  0,1,0);
	//gluLookAt(x1, y1, z1, x2, z2, -y2,  0,1,0);

	glBlendFunc(GL_ONE,GL_ZERO);
	glEnable(GL_CULL_FACE);
	if (diffuse_enabled) glEnable(GL_TEXTURE_2D);
	else glDisable(GL_TEXTURE_2D);
	room.draw();
	glDisable(GL_CULL_FACE);

	if (lighting_enabled)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,tex_id);

		glPushMatrix();
		glLoadIdentity();
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		glDisable(GL_DEPTH_TEST);

		glBlendFunc(GL_DST_COLOR, GL_ZERO);
		
		glBegin(GL_QUADS);

		glTexCoord2f(            0,   4 / 1024.0f); glVertex3f(-1, 1, 0);
		glTexCoord2f(800 / 1024.0f,   4 / 1024.0f); glVertex3f( 1, 1, 0);
		glTexCoord2f(800 / 1024.0f, 604 / 1024.0f); glVertex3f( 1,-1, 0);
		glTexCoord2f(            0, 604 / 1024.0f); glVertex3f(-1,-1, 0);

		glEnd();

		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
		glEnable(GL_DEPTH_TEST);
	}
}
コード例 #8
0
ファイル: pac_1_cpp.cpp プロジェクト: aravindsagar/pac-minion
void draw()
{
	/**
	* Draws the 3D scene within the view volume
	*/
	int i,j;
	nfood=0;
	
	prevFrameTime = curFrameTime;
	curFrameTime = glutGet(GLUT_ELAPSED_TIME);								//Determines the time gap between two continuous frame to enable frame independent animation
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW); 											//Switch to the drawing perspective
	
	glLoadIdentity(); 														//Reset the drawing perspective
	glPushMatrix();
	camera();
	//glTranslatef(0.0f,0.0f,-100.0f);
	GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	//Set material for pac and draw the pac
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = {50.0};
	
	glTranslatef(-gridWidthby2, -gridHeightby2,-100.0f);
	
	glPushMatrix();
	glTranslatef(-gridCellSide/2,-gridCellSide/2,-gridCellSide/2);
	glColor4f(0.3,0.34,0.32,1.0);
	glBegin(GL_QUADS);
		glVertex3f(-gridCellSide,-gridCellSide,0);
		glVertex3f(-gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,0-gridCellSide,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	
	/*
	In the following lines of code, we translate the PAC, and rotate it according to the direction of the PAC
	*/
	glTranslatef(pacx,pacy,0);

	if(!minionEnabled){
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
		glColor4f(0.75f,0.75f,0.0f,1.0f);
		glutSolidSphere(PACSIZE,50,50);
	}
	else{
		glDisable(GL_COLOR_MATERIAL);
		glRotatef(90.0f,1.0,0.0,0.0);
		if(pacCurDir == GLUT_KEY_LEFT) {
			if(pacAngle <= 270 - angleChange || pacAngle >= 270 + angleChange){
				if(pacAngle<=90 || pacAngle>270){
					pacAngle-=angleChange;
					if(pacAngle<0)
						pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_RIGHT){
			if(pacAngle <= 90 - angleChange || pacAngle >= 90 + angleChange){
				if(pacAngle<90 || pacAngle>=270){
					pacAngle = (pacAngle+angleChange)%360;
				}
				else
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_UP){
			if(pacAngle <= 180 - angleChange || pacAngle >= 180 + angleChange){
				if(pacAngle<=359 && pacAngle>180){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_DOWN){
			if(pacAngle <= 0 - angleChange || pacAngle >= 0 + angleChange){
				if(pacAngle<=180 && pacAngle>0){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		minion.draw();	//Draws the minion
		glEnable(GL_COLOR_MATERIAL);
	}								
	glPopMatrix();
	
	//Drawing ghosts
	if(!paused)
		blinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(blinky.color);
	glTranslatef(blinky.getX(),blinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-blinky.getX(),-blinky.getY(),0.0f);
	
	if(!paused)
		inky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(inky.color);
	glTranslatef(inky.getX(),inky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-inky.getX(),-inky.getY(),0.0f);

	if(!paused)
		pinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(pinky.color);
	glTranslatef(pinky.getX(),pinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-pinky.getX(),-pinky.getY(),0.0f);

	if(!paused)
		clyde.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(clyde.color);
	glTranslatef(clyde.getX(),clyde.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-clyde.getX(),-clyde.getY(),0.0f);

	GLfloat mat_specular2[] = {0.2,0.2,0.2,0.7};
	mat_shininess[0] = 100.0;
	GLfloat mat_diffuse[] = {0.2,0.17,0.73,1.0};
	GLfloat mat_ambient[] = {0.1,0.07,0.63,1.0};
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular2);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	//Drawing the maze
	GLfloat mazeColor[] = {0.05f,0.07f,0.53f,1.0f};
	for(i=0;i<31;i++){
        
        for(j=0;j<28;j++){
            if(maze[i][j]==1){
                glColor4fv(mazeColor);
                glutSolidCube(gridCellSide);
            }
            else if(maze[i][j]==2){
                glColor4f(1.0f,0.8f,0.85f,0.9f);
                glutSolidSphere(0.5,10,10);
                nfood++;
            }
            else if(maze[i][j]==3){
                glColor4f(0.6f,1.0f,0.7f,0.75f);
                glutSolidSphere(1.2,20,20);
                nfood++;
            }
            glTranslatef(gridCellSide,0.0f,0.0f);
        }
        glTranslatef(-28*gridCellSide,gridCellSide,0.0f);
    }
    glPopMatrix();
    //staticElementsDraw();
    text();
	glutSwapBuffers(); //Send scene to the screen to be shown
}