示例#1
0
gint redrawGL2PS()
{
	GLdouble m[4][4];
	GtkWidget *widget = GLArea;
	if(!GTK_IS_WIDGET(widget)) return TRUE;
	if(!GTK_WIDGET_REALIZED(widget)) return TRUE;

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	addFog();
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	set_background_color();

	mYPerspective(45,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,1,100);
    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(optcol==-1) drawChecker();

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	if(perspective)
		mYPerspective(Zoom,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,zNear,zFar);
	else
	{
	  	gdouble fw = (GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height;
	  	gdouble fh = 1.0;
		glOrtho(-fw,fw,-fh,fh,-1,1);
	}

    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(perspective)
		glTranslatef(Trans[0],Trans[1],Trans[2]);
	else
	{
		 glTranslatef(Trans[0]/10,Trans[1]/10,0);
		 glScalef(1/Zoom*2,1/Zoom*2,1/Zoom*2);
	}
	SetLight();

	build_rotmatrix(m,Quat);
	glMultMatrixd(&m[0][0]);

	redrawGeometry();
	redrawSurfaces();
	redrawCell();
	redrawContours();
	redrawPlanesMapped();
	if(get_show_symbols() || get_show_numbers() || get_show_charges()) showLabelSymbolsNumbersCharges();
	if(get_show_dipole()) showLabelDipole();
	if(get_show_distances()) showLabelDistances();
	if(get_show_axes()) showLabelAxes();
	if(get_show_axes()) showLabelPrincipalAxes();
	showLabelTitle(GLArea->allocation.width,GLArea->allocation.height);

	/* Swap backbuffer to front */
	glFlush();

	return TRUE;
}
示例#2
0
static gint redraw(GtkWidget *widget, gpointer data)
{
	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
	GLdouble m[4][4];
	if(!GTK_IS_WIDGET(widget)) return TRUE;
	if(!GTK_WIDGET_REALIZED(widget)) return TRUE;

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) return FALSE;

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	addFog();
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	set_background_color();

	mYPerspective(45,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,1,100);
    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(optcol==-1) drawChecker();

    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
	if(perspective)
		mYPerspective(Zoom,(GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height,zNear,zFar);
	else
	{
	  	gdouble fw = (GLdouble)widget->allocation.width/(GLdouble)widget->allocation.height;
	  	gdouble fh = 1.0;
		glOrtho(-fw,fw,-fh,fh,-1,1);
	}

    	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(perspective)
		glTranslatef(Trans[0],Trans[1],Trans[2]);
	else
	{
		 glTranslatef(Trans[0]/10,Trans[1]/10,0);
		 glScalef(1/Zoom*2,1/Zoom*2,1/Zoom*2);
	}
	SetLight();

	build_rotmatrix(m,Quat);
	glMultMatrixd(&m[0][0]);

	redrawGeometry();
	redrawSurfaces();
	redrawCell();
	redrawContours();
	redrawPlanesMapped();
	if(get_show_symbols() || get_show_numbers() || get_show_charges()) showLabelSymbolsNumbersCharges();
	if(get_show_dipole()) showLabelDipole();
	if(get_show_distances()) showLabelDistances();
	if(get_show_axes()) showLabelAxes();
	if(get_show_axes()) showLabelPrincipalAxes();
	showLabelTitle(GLArea->allocation.width,GLArea->allocation.height);

	/*
	glEnable(GL_DEPTH_TEST);	
	glDepthMask(GL_TRUE);
	glDepthRange(0.0f,1.0f);
	*/

	if (gdk_gl_drawable_is_double_buffered (gldrawable))
		gdk_gl_drawable_swap_buffers (gldrawable);
	else glFlush ();
	gdk_gl_drawable_gl_end (gldrawable);
	
        while( gtk_events_pending() ) gtk_main_iteration();

	createImagesFiles();
	/* gtk_widget_queue_draw(PrincipalWindow);*/

	return TRUE;
}
示例#3
0
void GameEnvironment::draw()
{
	if (blinkCounter++ < blinkDelay)
		;
	else
	{
		blinkDelay = (30 * rand()) / (RAND_MAX + 1.0);
		lightOn = rand() % 2 == 1;
		blinkCounter = 0;

		if (blinkDelay > 15 && !lightOn)
			lightOn = true;
	}

	if (!gameOver && !gameWon)
	{
		if (lightOn || pause)
		{
			// add ambient and directed light
			addLight();

			//add fog
			addFog();

			// flashlight
			glPushMatrix();
			//move with camera
			glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
			//rotate with camera
			glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
			glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
			glScalef(0.25, 0.25, 0.25);
			glTranslatef(1.0, -0.4, +0.7);
			glRotated(60, 0.7, -3.0, 0.5);
			flashlight->draw();
			glPopMatrix();
			
			// level
			glPushMatrix();
			level->draw();
			glPopMatrix();

			//table
			glPushMatrix();
			table->draw();
			glPopMatrix();

			if (!accesscardIsFound)
			{
				//accesscard
				glPushMatrix();
				glTranslatef(-38.0, -1.3, -58.0);
				accesscard->draw();
				glPopMatrix();
			}

			// terminal
			glPushMatrix();
			glScalef(1.0, 0.9, 1.0);
			glTranslatef(-34.5, -1.3, -59);
			terminal->draw();
			glPopMatrix();

			// monster
			glPushMatrix();
				monsterLastPositionZ = (monsterLastPositionZ + monsterSpeed);
				enemyMonster->jbTranslate(monsterLastPositionX, monsterLastPositionY, monsterLastPositionZ);
				glRotated(180, 0, -1.0, 0);

				enemyMonster->setFrameNumber(frame);
				enemyMonster->drawWithAni(monsterAnimationId);
				++frame;
				if (monsterIsRunning)
				{
					monsterSpeed += 0.02;
				}
				else
				{
					monsterSpeed = 0.0;
				}

				if (frame == (enemyMonster->frame_count[monsterAnimationId] - 1))
				{
					frame = 0;
				}
			glPopMatrix();

			glDisable(GL_TEXTURE_2D);
		}

		setCameraBoundingBox();		

		//countDistanceToMonster();
		jbCountDistanceToMonster();

		detectCollision(enemyMonster);
		detectCollision(table);
		//collision with walls
		checkLevelCollisionX();
		checkLevelCollisionZ();

		playRadarSound();
		playPlayerFootstepSound();
		playEnemyMonsterRandomSound();

		isEnemyMonsterSeePlayer();
		isEnemyMonsterCatchPlayer();
		isEnemyMonsterRunAway();
		checkEndGame();

		glFlush();
	}
	else if (gameWon)
	{
		// Add ambient light
		GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
		glPushMatrix();
		//move with camera
		glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
		//rotate with camera
		glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
		glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
		glScalef(0.5, 0.5, 0.5);
		glTranslatef(12.0, -5.0, 0.0);
		glRotated(90, 0.0, 1.0, 0.0);
		gameOverSuccess->draw();
		glPopMatrix();
	}
	else if (gameOver)
	{
		// Add ambient light
		GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
		glPushMatrix();
		//move with camera
		glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ());
		//rotate with camera
		glRotatef(-cameraYaw * 180 / PI, 0, 1, 0);
		glRotatef(-cameraPitch * 180 / PI, 0, 0, 1);
		glScalef(0.5, 0.5, 0.5);
		glTranslatef(12.0, -5.0, 0.0);
		glRotated(90, 0.0, 1.0, 0.0);
		gameOverFail->draw();
		glPopMatrix();
	}
}