void display (void) {
   // this code executes whenever the window is redrawn (when opened,
   //   moved, resized, etc.
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   // set the viewing transform
   setUpView();
	
   // set up light source
   setUpLight();
   // start drawing objects
	drawt1Text();
   drawTank1();
	drawTank2();
   //drawCone();
	drawGround();
	drawSheet1();

	if (bulletflag1 == 1)
	{
		drawBullet1();
	}
	if (bulletflag2 == 1)
	{
		drawBullet2();
	}

   glutSwapBuffers();
}
Esempio n. 2
0
/*********************************************************
**********************************************************
**********************************************************

    PROC: display()
    DOES: this gets called by the event handler to draw
          the scene, so this is where you need to build
          your ROBOT --  
      
        MAKE YOUR CHANGES AND ADDITIONS HERE

    Add other procedures if you like.

**********************************************************
**********************************************************
**********************************************************/
void display(void)
{
    // Clear the screen with the background colour (set in myinit)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    model_view = mat4(1.0f);
    
    model_view *= Translate(0.0f, -5.0f, -15.0f);
    HMatrix r;
    Ball_Value(Arcball,r);

    mat4 mat_arcball_rot(
        r[0][0], r[0][1], r[0][2], r[0][3],
        r[1][0], r[1][1], r[1][2], r[1][3],
        r[2][0], r[2][1], r[2][2], r[2][3],
        r[3][0], r[3][1], r[3][2], r[3][3]);
    model_view *= mat_arcball_rot;
        
    glUniformMatrix4fv( uView, 1, GL_TRUE, model_view );


    // Previously glScalef(Zoom, Zoom, Zoom);
    model_view *= Scale(Zoom);

    //draw objects
    drawGround();
    drawBee();
    drawFlower();

    glutSwapBuffers();
    if(Recording == 1)
        FrSaver.DumpPPM(Width, Height);
}
Esempio n. 3
0
// ------------------------------------------------------ 
void ofxBox2d::draw() {
	/*
	 if(mouseJoint) {
	 b2Body* mbody = mouseJoint->GetBody2();
	 b2Vec2 p1 = mbody->GetWorldPoint(mouseJoint->m_localAnchor);
	 b2Vec2 p2 = mouseJoint->m_target;
	 
	 p1 *= OFX_BOX2D_SCALE;
	 p2 *= OFX_BOX2D_SCALE;
	 
	 //draw a line from touched shape
	 ofEnableAlphaBlending();
	 ofSetLineWidth(2.0);
	 ofSetColor(200, 200, 200, 200);
	 ofLine(p1.x, p1.y, p2.x, p2.y);
	 ofNoFill();
	 ofSetLineWidth(1.0);
	 ofCircle(p1.x, p1.y, 2);
	 ofCircle(p2.x, p2.y, 5);
	 ofDisableAlphaBlending();
	 }
	 
	 
	 */
	
	drawGround();
}
int OpenGLGame::drawGLScene( GLvoid )
{

	static GLfloat yRot = 0.0f;         // Rotation angle for animation
	yRot += 0.1f;

	// Clear the window with current clearing color
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Draw everything as wire frame
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

    glPushMatrix();

	// Draw the ground
	drawGround();

    // Draw everything as wire frame
    glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

	// Draw the randomly located spheres
    for( int i = 0; i < NUM_SPHERES; i++ )
	{
		glPushMatrix();
        glTranslatef( m_vSphereLocation[i].x, m_vSphereLocation[i].y, m_vSphereLocation[i].z );
		glutSolidSphere( 0.5f, 13, 26 );
		glPopMatrix();
	}

	glPopMatrix();

	return TRUE;								//  一切 OK
}
Esempio n. 5
0
void DirectionalLightScene::draw(void) {
	//ライト設定
	
	Vector3<GLfloat> direction = Vector3<GLfloat>(10, 10, 0);
	//減衰率
	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1);		//一定減衰率(距離が近い程明るく、遠くなる程暗くなる度合い※一定)
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0);			//線形減衰率(距離が近い程明るく、遠くなる程暗くなる度合い※線形)
	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);		//二次減衰率(距離が近い程明るく、遠くなる程暗くなる度合い※二次)
	glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction.v);	//スポットライトの向き

	//シェーダーの適用
	Shader *shader = Manager<Shader>::getInstance().get("directional");
	shader->apply();
	
	Surface *surface = Manager<Surface>::getInstance().create("ground");
	surface->bindTexture(shader->getProgramId());
	drawGround();
	//カメラの設定
	Camera *camera = Manager<Camera>::getInstance().get("MyCamera");
	camera->setViewport(getWindowWidth(),getWindowHeight());
	camera->setPerspective(60,1);
	camera->lookat(	camera_position,Vector3<float>(0,10,0),Vector3<float>(0,1,0));
	//FBXモデルの表示
	FbxAnimationMesh *mesh = Manager<FbxAnimationMesh>::getInstance().get("ゾンビ");
	FbxAnimationTimer *timer = Manager<FbxAnimationTimer>::getInstance().get("ゾンビタイマー");
	mesh->draw(timer);

	shader->disable();

}
Esempio n. 6
0
void drawMyHouse(GLuint texSet[])
{
	//plot dimension
	//x: -4:4
	//y: 0:12
	//z: -4:4

	glEnable(GL_TEXTURE_2D);

	
	
	drawGround(texSet);
	drawRoof(texSet);

	

	glDisable(GL_TEXTURE_2D);



	//bounding volume
	glPushMatrix();
	glTranslatef(0, 6, 0);
	glScalef(8, 12, 8);	
	glColor3f(1.0, 1.0, 1.0);
	glutWireCube(1);
	glPopMatrix();
	
	
}
Esempio n. 7
0
        void drawMap(){

            drawGround();

            drawWalls();
            drawGlass();

        }
Esempio n. 8
0
void draw2D(){

	glPushMatrix();  // TRANSLATE & SCALE: (0,0) to center, screen width to 1.0
		glTranslatef(WIDTH*0.5, HEIGHT*0.75, 0.0f);
		glScalef(WIDTH, WIDTH, WIDTH);
		// NOW: dimensions are 1.0 = width of screen

		drawGround();
		glScalef(INTERVAL*INTERVAL, INTERVAL*INTERVAL, INTERVAL*INTERVAL);

		glPushMatrix();  // SCALE: zoom cycle
			glScalef(zoomCycleScale, zoomCycleScale, zoomCycleScale);

			for(int i = LVL_LOW; i < LVL_HIGH; i++){
				glPushMatrix();
				// with each zoom level we also calculate the fmodf of the translation

					float lvlWidth = 1.0/powf(INTERVAL, i);
					int lvlTransWhole = -transExp / lvlWidth;
					float lvlTransPart = modf(-(transExp)/lvlWidth, &unused);

					// int lvlTransWhole_OFF = -transExp / lvlWidth - 0.5;
					// float lvlTransPart_OFF = modf(-(transExp)/lvlWidth - 0.5, &unused);
					// glTranslatef(-transExp - lvlTransWhole_OFF * lvlWidth, 0, 0);

					int lvlTransWhole_OFF = -transExp / lvlWidth - 0.5*(INTERVAL_IS_ODD);
					float lvlTransPart_OFF = modf(-(transExp)/lvlWidth - 0.5*(INTERVAL_IS_ODD), &unused);
					glTranslatef(-transExp - (lvlTransWhole_OFF - 0.5*(!INTERVAL_IS_ODD)) * lvlWidth, 0, 0);

					float scale = powf(INTERVAL, i);
					float color = (i-zoom) / (LVL_HIGH-LVL_LOW);
					glScalef(1.0/scale, 1.0/scale, 1.0/scale);

					sprintf(zoomReports[i], "%f : (%d) %f : [(%d) %f]", lvlWidth, lvlTransWhole, lvlTransPart, lvlTransWhole_OFF, lvlTransPart_OFF);

					unsigned char highlight = 0;
					for(int i = 1; i <= INTERVAL; i++){
						float seg = (float)i / INTERVAL;
						if(fabs(lvlTransPart_OFF) < seg){
							highlight = i;
							break;
						}
					}

					repeating2DScene(color, highlight);
				glPopMatrix();
			}
		glPopMatrix();  // SCALE: zoom cycle
	glPopMatrix();  // TRANSLATE & SCALE: (0,0) to center, screen width to 1.0

	if(showHUD)
		drawHUD();
}
Esempio n. 9
0
void display(void)
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity ();             /* clear the matrix */
           /* viewing transformation  */
   gluLookAt (0.0, 0.0, 0.0, 0.0, theta-2.2, -5.0, 0.0, 1.0, 0.0);
   drawGround();
   drawCar();
   draw_remote_car();
   glFlush ();
   glutSwapBuffers();
}
void GlobalScene::draw()
{

    drawSkybox();
    drawGround();
    drawWalls();
    drawPillarsAndTorches();
    glRotatef(90, 1, 0, 0);
    glTranslatef(15, 5, -15);
    dragon->draw();

}
Esempio n. 11
0
void ShadowScene::renderScene()
{
	//----------------------------------------------------------------
	//カリング設定:表面のみを表示する又は両面表示する。
	//----------------------------------------------------------------
	glDisable(GL_CULL_FACE);
	//glCullFace(GL_BACK);
	glActiveTexture(GL_TEXTURE0);
	// 光源設定
	GLfloat light_pos[4];
	for(int i = 0; i < 3; ++i) light_pos[i] = (GLfloat)light_position[i];
	light_pos[3] = 1.0;
	glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
	
	Surface *surface = Manager<Surface>::getInstance().get("earth");
	Shader *shadowShader = Manager<Shader>::getInstance().get("ShadowingShader");
	Shader *phongShader = Manager<Shader>::getInstance().get("Shader");
	surface->bindTexture(shadowShader->getProgramId());
	
	int interval = 360/64;		//ここの値を変えてみよう
	for (int i = 0; i < 360; i+=interval) {
		//drawPlaneRect(i, interval);
	}
	//drawObjects();

	glPushMatrix();
	glScaled(0.1,0.1,0.1);
	FbxAnimationMesh *mesh = Manager<FbxAnimationMesh>::getInstance().get("キャラ");
	FbxAnimationTimer *timer = Manager<FbxAnimationTimer>::getInstance().get("キャラタイマー");
	mesh->draw(timer);
	glPopMatrix();

	////エフェクト
	//glPushMatrix();
	//glScaled(0.01,1.1,11.1);
	//glTranslated(0.0,0.2,0.0);
	//mesh = Manager<FbxAnimationMesh>::getInstance().get("魔方陣");
	//timer = Manager<FbxAnimationTimer>::getInstance().get("魔方陣タイマー");
	//mesh->draw(timer);
	//glPopMatrix();

	surface = Manager<Surface>::getInstance().get("ground");
	surface->bindTexture(shadowShader->getProgramId());
	//surface->bindTexture(phongShader->getProgramId());
	//glBindTexture(GL_TEXTURE_2D, 0);
	drawGround();

	
	//Manager<Surface>::getInstance().get("circle")->bindTexture(phongShader->getProgramId());
	//drawMagicCircle();

}
Esempio n. 12
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	if(begin)
	{
	glClearColor(a[0][0],a[0][1],a[0][2],a[0][3]);
	drawGround(0.6,30,60,0,500);
	drawCircle(bw[1],false,250,250,240);
	drawPitch(0.5,0.7,0.0,200,300,300,200,400,400,100,100,bail);
	drawCircle(rgb[0],true,kb.x,kb.y,4);
	if(inlin)
		Sprint(80.0,250.0,"PITCHED IN LINE");
	if(outline)
		Sprint(80.0,250.0,"PITCHED OUTSIDE");
	
	}
	else if(start)
	{
		glClearColor(a[1][0],a[1][1],a[1][2],a[1][3]);
		glColor3fv(rgb[0]);
		Sprint(170.0,450.0,"INSTRUCTIONS");
		glColor3f(0.5,0.1,0.8);
		Sprin(80.0,350.0,"PRESS O TO BOWL OVER THE WICKET");
		Sprin(80.0,300.0,"PRESS A TO BOWL AROUND THE WICKET");
		Sprin(80.0,250.0,"CLICK THE LEFT MOUSE BUTTON TO START THE BALL MOVEMENT");
		Sprin(80.0,200.0,"CLICK THE RIGHT BUTTON OF THE MOUSE TO PITCH THE BALL");
		Sprin(80.0,150.0,"PRESS R TO REBOWL");
		Sprin(80.0,100.0,"PRESS ESC TO EXIT FROM THE PROGRAM");
	}
	
	else
	{
		glClearColor(a[2][0],a[2][1],a[2][2],a[2][3]);
		glColor3fv(rgb[2]);
		Sprint(145.0,450,"SIMULATION OF A HAWK EYE");
		glColor3f(0.0,0.5,0.5);
		Sprin(160.0,400,"PROJECT TEAM MEMBERS");
		glColor3f(0.6,0.5,0.0);
		Sprint(120.0,350,"Aditya Chandrashekhar--USN:1DS08CS144");
		Sprint(120.0,300,"Ramdas.R--USN:1DS08CS080");
		Sprint(120.0,250,"Ranganath K Ingalagi--USN:1DS08CS082");
		Sprint(120.0,200,"Vivek Padmanabhan--USN:1DS09CS417");
	}
	


	glFlush();
	glutSwapBuffers();
}
Esempio n. 13
0
void GameMain::draw()
{
	drawBackGround();//背景(昼)描画

	drawMarioLove();//水道描画

	drawGround();//背景(地面)描画
	
	drawPlayer();//プレイヤー描画
	
	drawUI();//UI描画

	//DrawFormatString(0, 0, RGB(0, 0, 0), "playtime : %d", m_playtime);
	//DrawFormatString(0, 0, RGB(0, 0, 0), "P : %d", m_playerPoint);
}
Esempio n. 14
0
void Screen::paintEvent(QPaintEvent* evt)
{
    Q_UNUSED(evt);

    QPainter painter(this);
    painter.setBrush(Qt::black);
    painter.drawRect(rect());

    assert(World::CurrentCityHolder::isInitialized());
    auto& city = World::CurrentCityHolder::get();
    auto screenInfos = computeScreenInfos(city);
    double ratio = screenInfos.ratio;

    painter.translate(screenInfos.xMargin, screenInfos.yMargin);

    painter.scale(ratio, ratio);
    drawGround(city, painter);
    drawCurrentStateArea(city, painter);
}
Esempio n. 15
0
void onDisplay()
{
    // draw here
    glClearColor(0.4f, 0.7f, 0.9f, 0.5f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    drawGround();
    
    if (_gameMode == selection) {
        // show
        drawSelection();
        
        glutSwapBuffers();
        return;
    }
    
    for (int i = 0; i < NUM_BLOCKS; i++) {
        float px = 0.9;
        float py = _player->yOffset;
        if (_blocks[i]->hasCollided(px - PLAYER_SIZE, py + PLAYER_SIZE, px + PLAYER_SIZE, py - PLAYER_SIZE)) {
            if (_alive) {
                _alive = false;
                _deathTime = glutGet(GLUT_ELAPSED_TIME) * 0.001;
            }
        } else {
            _blocks[i]->draw();
        }
        
    }
    if (_alive) {
        _player->draw(_weightedMousePos);
    } else {
        float t_death = glutGet(GLUT_ELAPSED_TIME) * 0.001 - _deathTime;
        _player->drawDeath(_weightedMousePos, t_death);
    }
    
    drawScore();
    
    glutSwapBuffers();
}
Esempio n. 16
0
File: main.cpp Progetto: Pinkii-/IDI
void refresh(void) {
    glClearColor(r,g,b,a);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    if (sferaVisible) {
    glPushMatrix();
        glColor3f(0,0,0);
        glTranslated(s.centro.x,s.centro.y,s.centro.z);
        glutWireSphere(s.radio,30,30);
    glPopMatrix(); }
    glPushMatrix();
        glColor3f(0.1,0.9,0.9);
        drawGround(Vector3f(0,0,0), Vector3f(1,0,1), 10);
    glPopMatrix();
    ejes();
    if (wallVisible) {drawWall(Vector3f(0,0,-4.9),Vector3f(10,1.5,0.2));
                      drawWall(Vector3f(1.5,0,2.5),Vector3f(0.2,1.5,4));}
    drawMonigotes();
    glPushMatrix(); //patricio serialKiller
        glTranslated(patricio1.posFinal.x,patricio1.posFinal.y,patricio1.posFinal.z);
        glRotated(direccionPatricio,0,1,0);
        daModelIsReal(patricio1);
    glPopMatrix();
    glPushMatrix(); //patricio 2
        glTranslated(patricio2.posFinal.x,patricio2.posFinal.y,patricio2.posFinal.z);
        daModelIsReal(patricio2);
    glPopMatrix();
    for (uint i = 0; i < balas.size();++i) {
        glPushMatrix();
        glTranslated(balas[i].pos.x,balas[i].pos.y,balas[i].pos.z);
        glRotated(balas[i].dir,0,1,0);
        glTranslated(0.25,0.2,0.32);
        balas[i].draw();
        glPopMatrix();
    }
    glPushMatrix();
        writeOnWindow();
    glPopMatrix();
    glutPostRedisplay();
    glutSwapBuffers();
}
Esempio n. 17
0
void GL_run(GLFWwindow *window){
	float ratio;
	int width, height;

	GL_initialize(window);

	while (!glfwWindowShouldClose(window)){
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glLoadIdentity();



		glfwGetFramebufferSize(window, &width, &height);
		ratio = width / (float) height;
		glViewport(0, 0, width, height);

		// 透視投影。
		gluPerspective(30.0, ratio, 0.1, 500.0);
		// 視点設定前の行列をすべて平行移動(視界に収める)。
		glTranslated(0.0, 0.0, 0.0);
		// 視点の設定。
		gluLookAt(3.0*4, 4.0*4, 5.0*4, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);

		drawGround();

		// 光源の位置設定 (*重要 視点の位置を設定した後に行う) 
		glLightfv(GL_LIGHT0, GL_POSITION, aLight0pos);
		glLightfv(GL_LIGHT1, GL_POSITION, aLight1pos);

		/* 描画 */
		
		drawCube();


		glfwSwapBuffers(window);
		glfwPollEvents();
	}
}
Esempio n. 18
0
void Map::Draw()
{
	glEnable(GL_BLEND);
	drawGround();
	Point first, second;

	for(std::set<long>::iterator waysIt = waysToDraw.begin(); waysIt != waysToDraw.end(); ++waysIt)
		ways[*waysIt]->Draw();
	for(std::set<Building*>::iterator buildingIt = buildingsToDraw.begin(); buildingIt != buildingsToDraw.end(); ++buildingIt)
	{
		(*buildingIt)->Draw();
	}
	
	Point *checkPoint = miniMap->GetChekcpoint();
	if (checkPoint)
	{
		

		glEnable(GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1, 1, 0, 0.5);
		
		glPushMatrix();
		glTranslated(checkPoint->x, checkPoint->y, checkPoint->z);
		glRotatef(-90, 1,0,0);

		GLUquadricObj* quadric = gluNewQuadric();
		gluQuadricNormals(quadric, GLU_SMOOTH);
		gluQuadricTexture(quadric, GL_TRUE); 
		gluQuadricDrawStyle(quadric, GLU_FILL);
		gluCylinder(quadric, NODE_DIAMETER, NODE_DIAMETER, 100, 20, 1);

		glPopMatrix();
		glDisable(GL_BLEND);
	}

}
Esempio n. 19
0
File: anim.cpp Progetto: 4solo/cs174
/*********************************************************
**********************************************************
**********************************************************
 
    PROC: display()
    DOES: this gets called by the event handler to draw
          the scene, so this is where you need to build
          your ROBOT --  
      
        MAKE YOUR CHANGES AND ADDITIONS HERE
 
    Add other procedures if you like.
 
**********************************************************
**********************************************************
**********************************************************/
void display(void)
{
	// Clear the screen with the background colour (set in myinit)
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mat4 model_trans(1.0f);
	mat4 view_trans(1.0f);

	view_trans *= Translate(0.0f, 0.0f, -15.0f);
	HMatrix r;
	Ball_Value(Arcball, r);

	mat4 mat_arcball_rot(
		r[0][0], r[0][1], r[0][2], r[0][3],
		r[1][0], r[1][1], r[1][2], r[1][3],
		r[2][0], r[2][1], r[2][2], r[2][3],
		r[3][0], r[3][1], r[3][2], r[3][3]);
	view_trans *= mat_arcball_rot;
	view_trans *= Scale(Zoom);

	glUniformMatrix4fv(uView, 1, GL_TRUE, model_view);

	model_view = view_trans;

	mvstack.push(model_view);
	drawGround(view_trans);
	model_view = mvstack.top();
	mvstack.pop();

	model_view *= Translate(0, -10, 0);

	drawFlower();
	drawBee();
	glutSwapBuffers();
	if (Recording == 1)
		FrSaver.DumpPPM(Width, Height);
}
Esempio n. 20
0
void GateDemo::drawScene()
{
	// Clear the backbuffer and depth buffer.
	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0));

	HR(gd3dDevice->BeginScene());

	// Setup the rendering FX
	HR(mFX->SetTechnique(mhTech));
	HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3)));
	HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR)));
	HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR)));

	drawGround();
	drawGate();

	mGfxStats->display();

	HR(gd3dDevice->EndScene());

	// Present the backbuffer.
	HR(gd3dDevice->Present(0, 0, 0, 0));
}
Esempio n. 21
0
/* Initialize anything necessary to set up the scene for the roller coaster simulation. */
void init(void){
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    
    // Read in the control points from a file, first lets test without that feature.
    leftRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    rightRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    centerRail = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    columnTopRight = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    columnTopLeft = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    qValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    dqValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    ddqValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    uValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    vValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    nValues = (double **)malloc(COASTER_POINTS*NUMBER_SEGMENTS * sizeof(double *));
    calculateVectors();
    
    // Generate a display list that will hold the scene.
    scene = glGenLists(1);
    glNewList(scene, GL_COMPILE);
        // Draw the ground and colour it green.
        drawGround();
    
        // Draw the sky and colour it blue.
        drawSkybox();
        // Draw the coaster.
        drawCurve();
    
        // Draw the connection pieces for the rails.
        drawConnectors();
    
        // Draw the columnst that support the rails.
        drawColumns();
    glEndList();
}
static void
snowglobePaintInside (CompScreen *s,
                      const ScreenPaintAttrib *sAttrib,
                      const CompTransform     *transform,
                      CompOutput              *output,
                      int                     size)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    int i;

    as->waterHeight = 50000;

    if (as->hsize!=s->hsize) updateSnowglobe (s);


    static const float mat_shininess[] = { 60.0 };
    static const float mat_specular[] = { 0.8, 0.8, 0.8, 1.0 };
    static const float mat_diffuse[] = { 0.46, 0.66, 0.795, 1.0 };
    static const float mat_ambient[] = { 0.1, 0.1, 0.3, 1.0 };
    static const float lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
    static const float lmodel_localviewer[] = { 0.0 };

    ScreenPaintAttrib sA = *sAttrib;
    CompTransform mT = *transform;

    if (snowglobeGetShowWater(s))
        updateHeight(as->water);

    sA.yRotate += cs->invert * (360.0f / size) *
                  (cs->xRotations - (s->x* cs->nOutput));

    (*s->applyScreenTransform)(s, &sA, output, &mT);

    glPushMatrix();

    glLoadMatrixf(mT.m);

    glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f);

    glScalef(cs->outputXScale, cs->outputYScale, 1.0f);

    Bool enabledCull = FALSE;

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);

    glEnable(GL_BLEND);

    if (glIsEnabled(GL_CULL_FACE))
    {
        enabledCull = TRUE;
    }

    int cull;

    glGetIntegerv(GL_CULL_FACE_MODE, &cull);
    glEnable(GL_CULL_FACE);

    glCullFace(~cull & (GL_FRONT | GL_BACK));

    if (snowglobeGetShowWater(s))
    {
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, TRUE, FALSE);
    }
    glCullFace(cull);

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawGround(NULL, as->ground);

    }

    glPushMatrix();

    glColor4usv(defaultColor);

    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);

    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT0);

    glEnable(GL_COLOR_MATERIAL);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    for (i = 0; i < as->numSnowflakes; i++)
    {
        glPushMatrix();
        SnowflakeTransform(&(as->snow[i]));

        float scale = 0.01*as->snow[i].size;
        glScalef(scale, scale, scale);

        initDrawSnowflake();
        glCallList(as->snowflakeDisplayList);
        finDrawSnowflake();
        glPopMatrix();
    }

    if (snowglobeGetShowSnowman(s))
    {
        glPushMatrix();

        float bottom = -0.5;
        if (snowglobeGetShowGround(s))
            bottom = getHeight(as->ground, 0, 0);
        glTranslatef(0, bottom, 0);

        float scale = 0.4*snowglobeGetSnowmanSize(s)*(0.5-bottom);
        glScalef(scale, scale, scale);

        glColor4f(1.0, 1.0, 1.0, 1.0);

        DrawSnowman(0);
        glPopMatrix();
    }

    glPopMatrix();

    if (snowglobeGetShowWater(s))
    {
        glEnable(GL_CULL_FACE);
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, snowglobeGetShowWater(s), 0);
    }

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawBottomGround(s->hsize * cs->nOutput, cs->distance, -0.4999);
    }

    glDisable(GL_LIGHT1);
    glDisable(GL_NORMALIZE);

    if (!s->lighting)
        glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);

    if (enabledCull)
        glDisable(GL_CULL_FACE);

    glPopMatrix();

    glPopAttrib();

    as->damage = TRUE;

    UNWRAP (as, cs, paintInside);
    (*cs->paintInside)(s, sAttrib, transform, output, size);
    WRAP (as, cs, paintInside, snowglobePaintInside);
}
////////////////////////////////////////////////////////////////////////////////
// SoftShadowsRenderer::render()
////////////////////////////////////////////////////////////////////////////////
void SoftShadowsRenderer::render(float deltaTime)
{
    // Frame counter
    m_frameNumber++;
    
    // Bind all our textures and samplers
    for (GLuint unit = 0; unit < NumTextureUnits; ++unit)
    {
        glActiveTexture(GL_TEXTURE0 + unit);
        glBindTexture(GL_TEXTURE_2D, m_textures[unit]);
        glBindSampler(unit, m_samplers[unit]);
    }
    
    //
    // STEP 1: render shadow map from the light's point of view
    //
    if (m_shadowTechnique != None || m_visualizeDepthTexture)
    {
        GLuint prevFBO = 0;
        // Enum has MANY names based on extension/version
        // but they all map to 0x8CA6
        glGetIntegerv(0x8CA6, (GLint*)&prevFBO);

        glBindFramebuffer(GL_FRAMEBUFFER, m_shadowMapFramebuffer);

        glViewport(0, 0, LIGHT_RES, LIGHT_RES);
        glClear(GL_DEPTH_BUFFER_BIT);

        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(4.0f, 32.0f);

        m_shadowMapShader->enable();
        drawMeshes(*m_shadowMapShader);
        m_shadowMapShader->disable();

        glDisable(GL_POLYGON_OFFSET_FILL);
        glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
        glViewport(0, 0, m_screenWidth, m_screenHeight);
    }

    //
    // STEP 2: render scene from the eye's point of view
    //	
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if (m_visualizeDepthTexture)
    {
        m_visTexShader->enable();

        glDisable(GL_DEPTH_TEST);
        glDisable(GL_CULL_FACE);

        NvDrawQuadGL(
            m_visTexShader->getPositionAttrHandle(),
            m_visTexShader->getTexCoordAttrHandle());

        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);

        m_visTexShader->disable();
    }
    else
    {
        // To reduce overdraw, do a depth prepass to layout z
        m_depthPrepassShader->enable();

        drawMeshes(*m_depthPrepassShader);
        drawGround(*m_depthPrepassShader);

        m_depthPrepassShader->disable();
        
        // Do the shading pass
        EyeShader *shader = 0;
        switch (m_shadowTechnique)
        {            
        case None:        
            shader = m_pcssShader;
            m_pcssShader->enable();
            m_pcssShader->setShadowTechnique(static_cast<GLint>(m_shadowTechnique));
            break;

        case PCSS:
            shader = m_pcssShader;
            m_pcssShader->enable();
            m_pcssShader->setShadowTechnique(static_cast<GLint>(m_shadowTechnique));
            m_pcssShader->setSamplePattern(static_cast<GLint>(m_pcssSamplePattern));
            break;

        case PCF:
            shader = m_pcssShader;
            m_pcssShader->enable();
            m_pcssShader->setShadowTechnique(static_cast<GLint>(m_shadowTechnique));
            m_pcssShader->setSamplePattern(static_cast<GLint>(m_pcfSamplePattern));
            break;
        }
        if (shader != 0)
        {
            glDepthFunc(GL_EQUAL);

            drawMeshes(*shader);
            drawGround(*shader);

            shader->disable();
            glDepthFunc(GL_LEQUAL);
        }
        CHECK_GL_ERROR();
    }

    for (GLuint unit = 0; unit < NumTextureUnits; ++unit)
    {
        glBindSampler(unit, 0);
    }
}
Esempio n. 24
0
void display(void)
{
  //時間計測
  static double time1, time2, drawTime, frame;
  if(ang <= 0.001) time1 = timeGetTime();

  //ステップ1:デプスマップの作成
  glClear(GL_DEPTH_BUFFER_BIT);// デプスバッファをクリアする
  
  // ビューポートをテクスチャのサイズに設定する
  glViewport(0, 0, SHD_WIDTH, SHD_HEIGHT);
  
  // 透視変換行列を単位行列に設定する 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  
  //光源位置を視点とするモデルビュー変換行列を設定
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluPerspective(fov, (float)SHD_WIDTH / (float)SHD_HEIGHT, 1.0, farZ);
  gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);

  //設定したモデルビュー行列を保存しておく(setTextureMatrixで使用する) 
  glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

  //デプスバッファの内容だけを取得するので
  //フレームバッファには書き込まない
  glColorMask(0, 0, 0, 0);
  //デプスバッファには背面の奥行きを記録する
  glCullFace(GL_FRONT);
  //デプスマップ作成のためにシーンを描画
  draw0();
	draw1();
  drawGround();
  // デプスバッファの内容をテクスチャメモリに転送 
  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, SHD_WIDTH, SHD_HEIGHT, 0);

	//ステップ2
  //通常の描画設定に戻す 
  resize(width, height);

  glColorMask(1, 1, 1, 1); //フレームバッファへ書き込み許可
  glCullFace(GL_BACK);//背面は描画しない
	//カラーバッファのクリア
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();//視点を変えるときはこの位置に必要
  if(cos(view.theta*M_PI/180.0) >= 0.0)// <= 90.0)//カメラ仰角90度でビューアップベクトル切替
	  gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, 1.0, 0.0);
  else
	  gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, -1.0, 0.0);

	//光源設定//'l'を押した後光源位置可変
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, texName[0]);
  glActiveTexture(GL_TEXTURE2);
  glBindTexture(GL_TEXTURE_2D, texName[1]);
  glActiveTexture(GL_TEXTURE3);
  glBindTexture(GL_TEXTURE_2D, texName[2]);
  glActiveTexture(GL_TEXTURE4);
  glBindTexture(GL_TEXTURE_2D, texName[3]);
  glActiveTexture(GL_TEXTURE5);
  glBindTexture(GL_TEXTURE_2D, texName[4]);
  glActiveTexture(GL_TEXTURE6);
  glBindTexture(GL_TEXTURE_2D, texName[5]);

 //描画
  glUseProgram(shaderProg);
  // シェーダプログラムの適用 
  glActiveTexture(GL_TEXTURE0);
  GLint texLoc = glGetUniformLocation(shaderProg, "shadowMap");
  glUniform1i(texLoc, 0);//GL_TEXTURE0を適用
  GLint texColorLoc = glGetUniformLocation(shaderProg, "colorMap");
  GLint texNormalLoc = glGetUniformLocation(shaderProg, "normalMap");

  glUniform1i(texColorLoc, 1);//GL_TEXTURE1を適用
  glUniform1i(texNormalLoc, 4);//GL_TEXTURE4を適用
	draw0(); 
  glUniform1i(texColorLoc, 2);//GL_TEXTURE2を適用
  glUniform1i(texNormalLoc, 5);//GL_TEXTURE5を適用
	draw1();
  glUniform1i(texColorLoc, 3);//GL_TEXTURE3を適用
  glUniform1i(texNormalLoc, 6);//GL_TEXTURE6を適用
  drawGround();

  // シェーダプログラムの適用を解除	
  glUseProgram(0);

	drawLight();//光源の描画

  //回転角度更新
  ang += dang;
  if(ang >= 360.0)
  {
		time2 = timeGetTime();
		drawTime = (time2 - time1) * 0.001;
		frame = (360.0 / dang) / drawTime;
		printf("フレーム数 = %4.2f[fps] \n", frame);
		//フレームあたりの描画時間
		drawTime = 1.0 / frame;
		printf("描画時間 = %4.5f[spf] \n", drawTime);		
		ang = 0.0;
  }

	if(flagHelp)
  {
		printf("矢印キーによるアフィン変換/光源移動 \n");
		printf(" →,←:x軸 \n");
		printf(" ↑,↓:y軸 \n");
		printf(" [Shift]+↑,↓:z軸 \n");
		printf(" 'r'を押した後:回転 \n");
		printf(" 't'を押した後:平行移動 \n");
		printf(" 's'を押した後:スケーリング \n");
		printf(" 'l'を押した後、光源位置の移動可 \n");
		printf(" マウス操作で視点変更可 \n");
		printf("  dolly:中央付近を左ボタンクリックで近づき,右ボタンクリックで遠ざかる \n");
		printf("  pan:左横および右横を右ボタンクリックで注視点が左右に変化する \n");
		printf("  tilt:真上および真下を右ボタンクリックで注視点が上下に変化する \n");
		printf("  tumble:左右にドラッグすると視点が左右に変化する \n");
		printf("  crane:上下にドラッグすると視点が上下に変化する \n");
		printf("  zoom:左下を右ボタンクリックでズームイン \n");
		printf("        右下を右ボタンクリックでズームアウト \n");
		printf("[Shift]+'r'でリセット \n");
		printf("[F1]キー:凹凸反転 \n");
		printf("[F2]キー:勾配強調 \n");
		printf("[F3]キー:シャドウマッピングの視野角調整 \n");
		printf("[F4]キー:シャドウマッピングの後方クリップ面調整 \n");
		printf("[Page Up]キー:回転角度+0.1 \n");
		printf("[Page Dn]キー:回転角度-0.1 \n");
		flagHelp = false;
  }
  //終了
  glutSwapBuffers();
}
Esempio n. 25
0
void display () {

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	enter3D();

	gluLookAt(camera.x, camera.y, camera.z,
			  cameraLookAt.x, cameraLookAt.y, cameraLookAt.z,
			  cameraUp.x, cameraUp.y, cameraUp.z);

	glPushMatrix();
	glScaled(1.0, -1.0, 1.0);

	if (showSky) {
		drawSky();
	}

	// Draw coordinate axis
	// glCallList(axisList);

	for (int i = 0; i < 9; i ++) {
		gravitationalForce[i].draw();
	}

	if (showGround) {
		drawGround();
	}

	if (showPipe) {
		glPushMatrix();
			drawSprinkler(emitterSpacing * emitterCount, sprinkerHeight, 100, 5.0, 40.0);
		glPopMatrix();
	}

	if (showMountains) {
		drawMoutains(3000, 0, 0);
		drawMoutains(4000, 180, -200);
		drawMoutains(5600, 45, -500);
	}

	if (showTrees) {
		drawTrees();
	}

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::set("shine");
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	}

	particleSystem.draw();

	if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) {
		Texture::done();
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}

	/*glPushMatrix();
	glColor3f(1.0, 1.0, 1.0);
	glTranslatef(0.0, -100.0, 0.0);
	glScalef(100.0, -100.0, 100.0);
	drawModel();
	glPopMatrix();*/

	if (wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	glDisable(GL_DEPTH_TEST);
	enter2D();

	glColor4d(0.0, 0.0, 0.0, 1.0);
	sprintf(fpsText, "FPS:%4.2f", fps);
	drawText(GLUT_BITMAP_HELVETICA_18, windowWidth - 100, 20, fpsText);

	if (showHUD) {

		drawText(GLUT_BITMAP_HELVETICA_18, 10, 20, "Water sprinkler");

		sprintf(cameraText, "%4.2f %4.2f %4.2f", camera.x, camera.y, camera.z);
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 60, cameraText);

		sprintf(particleText, "Particles: %llu", particleSystem.getParticleCount());
		drawText(GLUT_BITMAP_HELVETICA_12, 10, 100, particleText);

		if (menu) {

			// Current option
			glColor4d(0.2, 0.2, 0.2, 0.8);
			glRectd(10, windowHeight - 40, 120, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, options[currentOption]);

			// Current option value
			glColor4d(0.4, 0.4, 0.4, 0.8);
			glRectd(120, windowHeight - 40, 240, windowHeight - 10);
			glColor4d(1.0, 1.0, 1.0, 1.0);

			switch (currentOption) {
			case 0: sprintf(optionValue, "%4.2f", Particle::initialVelocity); break;
			case 1: sprintf(optionValue, "%d", initialColour); break;
			case 2: sprintf(optionValue, "%d", gravityIntensity); break;
			case 3: sprintf(optionValue, "%d", Particle::startLifeSpan); break;
			case 4: sprintf(optionValue, "%s", renderModes[renderMode]); break;
			case 5: sprintf(optionValue, "%d", emitterCount); break;
			case 6: sprintf(optionValue, "%d", emitterSpacing); break;
			case 7: sprintf(optionValue, "%s", cameras[currentCamera]); break;
			case 8: sprintf(optionValue, "%4.2f", Particle::airResistance); break;
			case 9: sprintf(optionValue, "%s", cycleColours ? "On" : "Off"); break;
			case 10: sprintf(optionValue, "%d", emitFrequency); break;
			case 11: sprintf(optionValue, "%4.2f", ParticleEmitter::emitSpread); break;
			case 12: sprintf(optionValue, "%d", ParticleSystem::perEmit); break;
			case 13: sprintf(optionValue, "%s", ParticleEmitter::show ? "Yes" : "No"); break;
			case 14: sprintf(optionValue, "%s", wireframe ? "Yes" : "No"); break;
			case 15: sprintf(optionValue, "%s", showMountains ? "On" : "Off"); break;
			case 16: sprintf(optionValue, "%s", showTrees ? "On" : "Off"); break;
			case 17: sprintf(optionValue, "%s", showSky ? "On" : "Off"); break;
			case 18: sprintf(optionValue, "%s", showGround ? "On" : "Off"); break;
			case 19: sprintf(optionValue, "%s", demos[demo]->name.c_str()); break;
			case 20: sprintf(optionValue, "%1.1f", Particle::bounce); break;
			case 21: sprintf(optionValue, "%s", skyTexture ? "On" : "Off"); break;
			case 22: sprintf(optionValue, "%s", grassTexture ? "On" : "Off"); break;
			case 23: sprintf(optionValue, "%s", showPipe ? "On" : "Off"); break;
			case 24: sprintf(optionValue, "%s", ParticleEmitter::randomness ? "On" : "Off"); break;
			case 25: sprintf(optionValue, "%s", Tree::drawLeaves ? "On" : "Off"); break;
			default: sprintf(optionValue, "%s", ""); break;
			}

			drawText(GLUT_BITMAP_HELVETICA_12, 130, windowHeight - 20, optionValue);

		}
		else {
			glColor4d(1.0, 1.0, 1.0, 1.0);
			drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, "Press m to toggle menu");
		}

		for (int i = 1; i < 10; i++) {
			if (selectedGravitationalForce == i - 1) {
				glColor4d(1.0, 0.4, 0.4, 0.8);
			}
			else {
				glColor4d(0.4, 0.4, 1.0, 0.2);
			}
			glRectd(200 + ((i - 1) * 50), 10, 230 + ((i - 1) * 50), 40);
			glColor4d(0.0, 0.0, 0.0, 1.0);
			sprintf(n, "%d", i);
			drawText(GLUT_BITMAP_HELVETICA_18, 210 + ((i - 1) * 50), 30, n);
		}

	}

	if (currentCamera == 3) {
		glBegin(GL_LINES);
			glColor3d(0.8, 0.8, 0.8);
			glVertex2d((windowWidth / 2) - 30, windowHeight / 2);
			glVertex2d((windowWidth / 2) + 30, windowHeight / 2);
			glVertex2d(windowWidth / 2, (windowHeight / 2) - 30);
			glVertex2d(windowWidth / 2, (windowHeight / 2) + 30);
		glEnd();
	}

	glPopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}
Esempio n. 26
0
void renderScene(void) {
    
    //Set up Viewport 1 scene
    
    // Use the Projection Matrix
    glMatrixMode(GL_PROJECTION);
    
    // Reset Matrix
    glLoadIdentity();
    
    
    glScissor(0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9);
    glEnable(GL_SCISSOR_TEST);
    glClearDepth(1.0);
    
    glClearColor(0.49f, 0.75f, 0.93f, 1.0f);
    
    // Set the viewport to be the entire window
    glViewport (0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9);
    
    // Set the correct perspective.
    
    if (viewMode == PERSPECTIVE)
        gluPerspective(45.0f*zoom, ratio, 1.0f, 1000.0f);
    else if (viewMode == ORTHOGRAPHIC)
        glOrtho((-windowWidth/50)*zoom, (windowWidth/50)*zoom, (-windowHeight/50)*zoom, (windowHeight/50)*zoom, 1.0f, 1000);
    
    // Get Back to the Modelview
    glMatrixMode(GL_MODELVIEW);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    //Decide if wire frame or shaded
    if (polygonMode == WIREFRAME)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else if (polygonMode == SHADED)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
    glLoadIdentity();

    moveCamera();
    
    lx = (sin(heliRot+PI));
    lz = (cos(heliRot+PI));
    
    float camX = curX + lx * 10.0f;
    float camZ = curZ + lz * 10.0f;
    
    //Set camera
    if (viewPerson == THIRD) {
        gluLookAt(eyeX+curX, eyeY, eyeZ+curZ,
                  curX, 0.0f, curZ,
                  upX, upY, upZ);
    }

    else if (viewPerson == FIRST) {
        
        gluLookAt(camX, 1.5f, camZ,
                  camX+lx, 1.5f, camZ+lz,
                  0.0f, 1.0f, 0.0f);
        
    }
    
    glEnable(GL_DEPTH_TEST);
    
    glShadeModel(GL_SMOOTH); // smooth out lighting
    glEnable(GL_NORMALIZE);  // normalize lighting
    
    GLfloat mat_specular[] = {0.3, 0.3, 0.3, 1.0};
    GLfloat mat_shininess[] = { 10.0 };
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    
    if (lightingEnabled) {
        
        glEnable(GL_LIGHTING);
    
        if (sunlight) {

            setSunlight();
    
        }
    
        else {
            glDisable(GL_LIGHT0);
        }
        
        
        if (thirdPersonLight) {
            setThirdPersonLight();
        }
        
        else {
            glDisable(GL_LIGHT3);
        }
        
        
    }
    
    else {
        glDisable(GL_LIGHTING);
    }

    glPushMatrix();
    glTranslatef(0.0f, -10, 0.0f);
    drawGround(250, 100);
    glPopMatrix();
    
    glPushMatrix();
    glTranslatef(0.0f, -9.9, 0.0f);
    drawTrack(100.0, 100.0);
    glPopMatrix();
    
    glPushMatrix();
    moveHelicopter();
    glRotatef(heliRot/PI*180, 0.0f, 1.0f, 0.0f);
    drawHelicopter();
    
    
    if (lightingEnabled) {
    
        if (circleLight) {
    moveLight();
    setCircularLight();
        }
        
        else {
            glDisable(GL_LIGHT2);
        }
    
    }
    
    glPopMatrix();
    
    //Set up Viewport 2 scene
    
    // Use the Projection Matrix
    glMatrixMode(GL_PROJECTION);
    
    // Reset Matrix
    glLoadIdentity();
    
    glScissor(0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1);
    glEnable(GL_SCISSOR_TEST);
    glClearDepth(1.0);
    glClearColor(1, 1, 1, 1);

    
    // Set the viewport to be the entire window
    glViewport (0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1);
    
    // Set the correct perspective.
    
    // Get Back to the Modelview
    glMatrixMode(GL_MODELVIEW);
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glEnable(GL_DEPTH_TEST);
    
    frame++;
    time=glutGet(GLUT_ELAPSED_TIME);
    if (time - timebase > 1000) {
        sprintf(s,"FPS:%4.2f",
                frame*1000.0/(time-timebase));
        timebase = time;
        frame = 0;
    }
    
    glColor3f(0.0f,0.0f,0.0f);
    
    glPushMatrix();
    glLoadIdentity();
    setOrthographicProjection();
    glTranslatef(100.0f, 150, 0.0f);
    renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_18,s);
    glPopMatrix();
    restorePerspectiveProjection();
    
    glutSwapBuffers();
    
}
Esempio n. 27
0
void ProxyViz::draw( M3dView & view, const MDagPath & path, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{
	if(!m_enableCompute) return;
	MObject thisNode = thisMObject();
	updateWorldSpace(thisNode);
	
	MPlug mutxplug( thisNode, axmultiplier);
	MPlug mutyplug( thisNode, aymultiplier);
	MPlug mutzplug( thisNode, azmultiplier);
	setScaleMuliplier(mutxplug.asFloat(), 
						mutyplug.asFloat(),
						mutzplug.asFloat() );	
                        
    MPlug svtPlug(thisNode, adisplayVox);
    setShowVoxLodThresold(svtPlug.asFloat() );
	
	MDagPath cameraPath;
	view.getCamera(cameraPath);
	if(hasView() ) updateViewFrustum(thisNode);
	else updateViewFrustum(cameraPath);
	
	setViewportAspect(view.portWidth(), view.portHeight() );
	
	MPlug actp(thisNode, aactivated);
	if(actp.asBool()) setWireColor(.125f, .1925f, .1725f);
    else setWireColor(.0675f, .0675f, .0675f);

	_viewport = view;
	fHasView = 1;
	
	view.beginGL();
	
	double mm[16];
	matrix_as_array(_worldInverseSpace, mm);
	
	glPushMatrix();
	glMultMatrixd(mm);	
	
	ExampVox * defBox = plantExample(0);
	updateGeomBox(defBox, thisNode);
	drawWireBox(defBox->geomCenterV(), defBox->geomScale() );
	Matrix44F mat;
	mat.setFrontOrientation(Vector3F::YAxis);
	mat.scaleBy(defBox->geomSize() );
    mat.glMatrix(m_transBuf);
	
	drawCircle(m_transBuf);
	
	drawGridBounding();
	// drawGrid();

	if ( style == M3dView::kFlatShaded || 
		    style == M3dView::kGouraudShaded ) {		
		drawPlants();
	}
	else 
		drawWiredPlants();
	
    if(hasView() ) drawViewFrustum();
    
	drawBrush(view);
	drawActivePlants();
	drawGround();
	glPopMatrix();
	view.endGL();
	std::cout<<" viz node draw end";
}
Esempio n. 28
0
void Renderer::draw(const double time) {
	beginFrame();
	pushPopped([this] { drawGround(); });
	pushPopped([this] { drawMan(); });
	pushPopped([this] { drawManBodyCenter(); });
}
Esempio n. 29
0
void GLWidget::paintGL()
{
    int i;
    QList<Point3D> points;
    QImage image;
    //Set backgroung
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    rotateCamera();
    drawGround( 10.0f, 1.0f, 0);

    //Using stack of matrix
    glPushMatrix();

        //Draw all objects

        glEnable(GL_TEXTURE_2D);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        //colors of glObject are replaced by texture. other - GL_REPLACE - combination
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


        float refl;
        int shine;

        //need to draw pictures then objects


        //Drawing images
        for( i = 0; i < Scene::Instance().stub_objects().size(); i++)
        {
            //checking type of object - lense or picture
            LensObjectStub* n = dynamic_cast<LensObjectStub*>(Scene::Instance().stub_objects()[i]);
            if (!(n))
            {
                shine = 10;
                refl = 0.5;
                //textures
                PictureObjectStub* picobj = (PictureObjectStub*)Scene::Instance().stub_objects()[i];
                image = convertToGLFormat(picobj->image());
                glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0,
                                 GL_RGBA, GL_UNSIGNED_BYTE, image.bits());

                if (Scene::Instance().stub_objects()[i]->selected())
                {
                    glColor4f( 0.1, 0.1, 1.0, 1.0);
                } else {
                    glColor4f( 1.0, 1.0, 1.0, 1.0);
                }

                float specref[] = { refl, refl, refl};
                glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specref);
                glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shine); //0..128 - reflection

                points = Scene::Instance().stub_objects()[i]->getPoints();
                //qDebug() << points;
                //Drawing pictures
                  glBegin( GL_QUADS);
                        //Draw normals for lighting TODO
                        //glNormal3f( x, y ,z);
                        glTexCoord2f(0, 1);
                        glVertex3f( points[0].x, points[0].y, points[0].z);
                        glTexCoord2f(1, 1);
                        glVertex3f( points[1].x, points[1].y, points[1].z);
                        glTexCoord2f(1, 0);
                        glVertex3f( points[2].x, points[2].y, points[2].z);
                        glTexCoord2f(0, 0);
                        glVertex3f( points[3].x, points[3].y, points[3].z);
                  glEnd();
            }

        }

        //Drawing lenses
        for( i = 0; i < Scene::Instance().stub_objects().size(); i++)
        {

            //checking type of object - lense or picture
            LensObjectStub* n = dynamic_cast<LensObjectStub*>(Scene::Instance().stub_objects()[i]);
            if (n)
            {

                shine = 128;
                refl = 1.0;
                glEnable(GL_CULL_FACE);
                glCullFace(GL_FRONT);

                image = convertToGLFormat(n->heightMap1());
                glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0,
                                 GL_RGBA, GL_UNSIGNED_BYTE, image.bits());

                if (Scene::Instance().stub_objects()[i]->selected())
                {
                    glColor4f( 0.1, 0.1, 1.0, 0.5);
                } else {
                    glColor4f( 1.0, 1.0, 1.0, 0.5);
                }

                float specref[] = { refl, refl, refl};
                glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specref);
                glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, shine); //0..128 - reflection

                points = Scene::Instance().stub_objects()[i]->getPoints();
                //qDebug() << points;
                //Drawing pictures
                  glBegin( GL_QUADS);
                        //Draw normals for lighting TODO
                        //glNormal3f( x, y ,z);
                        glTexCoord2f(0, 1);
                        glVertex3f( points[0].x, points[0].y, points[0].z);
                        glTexCoord2f(1, 1);
                        glVertex3f( points[1].x, points[1].y, points[1].z);
                        glTexCoord2f(1, 0);
                        glVertex3f( points[2].x, points[2].y, points[2].z);
                        glTexCoord2f(0, 0);
                        glVertex3f( points[3].x, points[3].y, points[3].z);
                  glEnd();

                  //draw back with diff texture
                  glCullFace(GL_BACK);

                  image = convertToGLFormat(n->heightMap2());
                  glTexImage2D(GL_TEXTURE_2D, 0, 3, (GLsizei)image.width(), (GLsizei)image.height(), 0,
                                   GL_RGBA, GL_UNSIGNED_BYTE, image.bits());

                  glBegin( GL_QUADS);
                        //Draw again wi other texture
                        glTexCoord2f(0, 1);
                        glVertex3f( points[0].x, points[0].y, points[0].z);
                        glTexCoord2f(1, 1);
                        glVertex3f( points[1].x, points[1].y, points[1].z);
                        glTexCoord2f(1, 0);
                        glVertex3f( points[2].x, points[2].y, points[2].z);
                        glTexCoord2f(0, 0);
                        glVertex3f( points[3].x, points[3].y, points[3].z);
                  glEnd();
                  glCullFace(GL_FRONT_AND_BACK);
                  glDisable(GL_CULL_FACE);

            }

         }

        /*glPushMatrix();
            glBegin(GL_LINES);
            glVertex3f(8, -9, 5);
            glVertex3f(0, 0, 0);
            glEnd();
            glPopMatrix();*/
    glPopMatrix();

    drawCamera();
    //clear drawing command stack
    swapBuffers();
}
Esempio n. 30
0
void Quiddiards::paintGL(){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	/* set camera */
	QMatrix4x4 mat;				// identity matrix
	mat.rotate(phi, 0, 0, 1);	// rotate phi around z axis
	mat.rotate(theta, 1, 0, 0);	// rotate around x axis
	mat.rotate(theta, 0, 1, 0);	// rotate around y axis
	eye = mat * QVector3D(0, 0, radius);
	QVector3D up = QVector3D::crossProduct(eye, { -eye.y(), eye.x(), 0.0f });	// note: coord system is left-handwise
	switch (camera){
	case FOLLOW:
		center = cueball.getCenter();
		break;
	case OVER:
		center = { 0, 0, table.getDamHgt() };
		break;
	case FREE:
		break;
	default:
		break;
	}

	gluLookAt(eye.x() + center.x(), eye.y() + center.y(), eye.z() + center.z(), center.x(), center.y(), center.z(), up.x(), up.y(), up.z());

	/* enable or disable lights based on setting */
	if (ambLight){
		static GLfloat modAmb[] = { 0.4f, 0.4f, 0.4f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modAmb);
	}
	else{
		static GLfloat modAmb[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modAmb);
	}
	if (sunLight){
		static GLfloat sunPos[] = { 1.0f, 1.0f, 1.0f, 0.0f };
		glLightfv(GL_LIGHT0, GL_POSITION, sunPos);
		glEnable(GL_LIGHT0);
	}
	else{
		glDisable(GL_LIGHT0);
	}
	if (spotLight){
		spotPos = { cueball.getX(), cueball.getY(), cueball.getZ() + 5.0f, 1.0f };
		QVector3D dir = cueball.getCenter() - spotPos.toVector3D();
		glLightfv(GL_LIGHT1, GL_POSITION, (float*)&spotPos);
		glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, (float*)&dir);
		glEnable(GL_LIGHT1);
	}
	else{
		glDisable(GL_LIGHT1);
	}

	/* start drawing */
	glEnable(GL_TEXTURE_2D);
	/* draw scene */
	drawSkybox();
	drawGround();
	//drawTable();
	/* draw quaffles */
	for (unsigned i = 0; i < QUAFNUM; i++){
		drawBall(quaffles[i]);
	}
	/* draw bludgers */
	for (unsigned i = 0; i < BLUGNUM; i++){
		drawBall(bludgers[i]);
	}
	/* draw snitch */
	drawBall(snitch);
	/* draw cueball */
	drawBall(cueball);
	//if (operable){
	//	drawCueBroom();
	//}
	for (int i = 0; i < FLAGNUM; i++){
		drawFlag(flags[i]);
	}
	glDisable(GL_TEXTURE_2D);
	if (ps->isActive()){
		renderPS();
	}
}