Esempio n. 1
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
    modelViewMatrix.Translate(0.0f, 0.8f, 0.0f);
    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.3f, 0.f, 0.0f);
        modelViewMatrix.Scale(0.40, 0.8, 0.40);
        modelViewMatrix.Rotate(50.0, 0.0, 10.0, 0.0);
        glSampleMaski(0, 0x02);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtYellow);
        glass1Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.4f, 0.0f, 0.0f);
        modelViewMatrix.Scale(0.5, 0.8, 1.0);
        modelViewMatrix.Rotate(-20.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x04);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtGreen);
        glass2Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(1.0f, 0.0f, -0.6f);
        modelViewMatrix.Scale(0.3, 0.9, 1.0);
        modelViewMatrix.Rotate(-40.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x08);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtMagenta);
        glass3Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.8f, 0.0f, -0.60f);
        modelViewMatrix.Scale(0.6, 0.9, 0.40);
        modelViewMatrix.Rotate(60.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x10);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtBlue);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.1f, 0.0f, 0.50f);
        modelViewMatrix.Scale(0.4, 0.9, 0.4);
        modelViewMatrix.Rotate(205.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x20);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtPink);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();
}
Esempio n. 2
0
void RenderDwudziestoscian(float xPos, float yPos, float zPos, float scale) {
	matrixStack.PushMatrix();

	matrixStack.Translate(xPos, yPos, zPos);
	matrixStack.Scale(scale, scale, scale);

	M3DMatrix44f MVMatrix;
	m3dCopyMatrix44(MVMatrix, matrixStack.GetMatrix());
	
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,MVMatrix);

	M3DMatrix44f normalMatrix;
	m3dInvertMatrix44(normalMatrix,MVMatrix);

	float tmp;
	// transponse
	for(int n = 0; n < 3; n++) {
		for(int m = n + 1; m <= 3; m++) {
			tmp = normalMatrix[4*n + m];
			normalMatrix[4*n + m] = normalMatrix[4*m + n];
			normalMatrix[4*m + n] = tmp;
		}
	}

	glUniformMatrix3fv(NormalMatrixLocation,1,GL_FALSE,normalMatrix);

	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);

	matrixStack.PopMatrix();
}
Esempio n. 3
0
void Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	
	static CStopWatch timer;
	GLfloat yRot = timer.GetElapsedSeconds()*20.0f;

	GLfloat vWhite[] = {1.0f,1.0f,1.0f,1.0f};
	GLfloat vLightPos[] = {0.0f,2.0f,2.0f};
	GLfloat vAmbient[] = {0.3f,0.3f,1.0f,1.0f};
	modelViewMatrix.PushMatrix();
		//move to camera view
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		modelViewMatrix.PushMatrix();
		modelViewMatrix.Rotate(yRot,1.0,1.0,1.0);
		glBindTexture(GL_TEXTURE_2D,fbxTexture);
		shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, 
                                     transformPipeLine.GetModelViewMatrix(),
                                     transformPipeLine.GetProjectionMatrix(), 
                                     vLightPos, vWhite, 0);
		//*/shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeLine.GetModelViewProjectionMatrix(),vWhite);
		modelViewMatrix.Scale(0.05,0.05,0.05);
		rTest.DrawReader();

		modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();

	glutSwapBuffers();
	glutPostRedisplay();
}
Esempio n. 4
0
void DrawBaeumchen() {

	// Boden
	modelViewMatrix.PushMatrix();
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, -25, 0);
	modelViewMatrix.Scale(20, -0.01, 20);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	modelViewMatrix.PopMatrix();
	DrawCube();

	// Baumstamm
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 0.0, 0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.3, 0.5, 0.3);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	modelViewMatrix.PopMatrix();
	DrawCylinder();

	//unterster Kegel
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 25.0, 0);
	modelViewMatrix.Scale(1.5, 1.5, 1.5);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();

	// mittlerer Kegel
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 40.0, 0);
	modelViewMatrix.Scale(0.75, 0.75, 0.75);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();	
	
	// Spitze
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 50.0, 0);
	modelViewMatrix.Scale(0.75, 0.75, 0.75);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();

	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
}
Esempio n. 5
0
void DrawMaennchen(float angle) {

	//float overallScaleFactor = 0.2 * cos(GL_PI / 200 * angle) + 1;
	float jumpFactor = abs(cos(GL_PI/10 * angle));

	/**
	* Rumpf zeichnen
	**/
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Rotate(angle, 0, -1, 0);
	// generelle Verschiebung aus dem Mittelpunkt heraus
	modelViewMatrix.Translate(200.0f, 0.0f, 0.0f);
	// Verschiebung fuer Huepfbahn
	modelViewMatrix.Translate(0.0f, 30 * jumpFactor, 0);
	//modelViewMatrix.Scale(overallScaleFactor, overallScaleFactor, overallScaleFactor);

	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.9, 1.0, 0.7);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Hals
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 55.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.25, 0.15, 0.25);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Kopf
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 40.0f, 0.0f);
	modelViewMatrix.Scale(0.72, 0.72, 0.72);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawSphere();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	
	// Giedmaßen zeichnen - abhaengig vom Rumpf!
	DrawLimbs(angle);

	modelViewMatrix.PopMatrix();
}
Esempio n. 6
0
void render_scene(void) {
    float angle = timer.GetElapsedSeconds() * 3.14f / 10.0f;
    location[0] = -8.0f * cos(angle / 2.0f);
    location[1] = -8.0f * sin(angle / 2.0f);
    location[2] = 5.0f;
    light_0.position[0] = 10.0f * cos(-angle);
    light_0.position[1] = 10.0f * sin(-angle);
    light_0.position[2] = 3.0f;
    look_at(camera_frame, location, target, up_dir);
    camera_frame.GetCameraMatrix(camera_matrix);
    p_stack.LoadMatrix(view_frustum.GetProjectionMatrix());
    mv_stack.LoadMatrix(camera_matrix);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    //--
    glUseProgram(shader_color);
    mv_stack.PushMatrix();
    mv_stack.Translate(light_0.position[0], light_0.position[1], light_0.position[2]);
    mv_stack.Scale(0.25f, 0.25f, 0.25f);
    glUniformMatrix4fv(mvp_matrix_location_shader_color, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
    draw_light();
    mv_stack.PopMatrix();
    //--
    glUseProgram(shader_light);
    glUniformMatrix3fv(normal_matrix_location, 1, GL_FALSE, geometry_pipeline.GetNormalMatrix());
    glUniformMatrix4fv(v_matrix_location, 1, GL_FALSE, camera_matrix);
    glUniform3fv(intensity_ambient_component_location, 1, intensity_ambient_component);
    glUniform3fv(light_0_position_location, 1, light_0.position);
    glUniform3fv(light_0_intensity_diffuse_location, 1, light_0.intensity_diffuse);
    glUniform3fv(light_0_intensity_specular_location, 1, light_0.intensity_specular);
    glUniform3fv(light_0_attenuation_location, 1, light_0.attenuation);
    glUniform1f(material_0_ka_location, material_0.ka);
    glUniform1f(material_0_kd_location, material_0.kd);
    glUniform1f(material_0_ks_location, material_0.ks);
    glUniform1f(material_0_alpha_location, material_0.alpha);
    //--
    for(int i = -10; i <= 10; i += 3)
        for(int j = -10; j <= 10; j += 3) {
            mv_stack.PushMatrix();
            mv_stack.Translate(i, j, 0.0f);
            glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
            glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix());
            glDrawElements(GL_TRIANGLES, faces.size(), GL_UNSIGNED_INT, 0);
            mv_stack.PopMatrix();
        }
    //--
    glUseProgram(0);
    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 7
0
void animate() {
	frameNo++;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	glUseProgram(shader);

	//cameraAngleX += randf() * 5.0;
	//cameraAngleY += randf() * 2.7;
	//cameraAngleZ += randf() * 50.0;
	cameraBothZ += randf() * 10.0;
	
	matrixStack.LoadIdentity();
	matrixStack.PushMatrix();
	matrixStack.Scale(0.1,0.1,0.1);
	//Perspektywa + krêcenie kamery
	matrixStack.Rotate(40, 1, 0, 0);
	matrixStack.Rotate(cameraBothZ, 0, 0, 1);
		
	glUniformMatrix4fv(PMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix());
	
	float ambient[] = {0.5,0.2,0.2}, diffuse[] = {0.5,0.2,1}, specular[] = {0.2,1,0.2};
	material.setMaterial(ambient, diffuse, specular, 1);

	float color[] = {1,1,1}, position[] = {0,0,-1};
	light.setLight(position, color, 180, 1, 1, 2);

	float ambientLight[] = {1,1,1};
	glUniform3fv(ambientLightLocation, 1, ambientLight);

	float small_color[] = {1,1,1}, small_position[] = {5 + 2*cos(frameNo/180.0*PI/2.0), 5 + 2*sin(frameNo/180.0*PI/2.0), -1};
	small_light.setLight(small_position, small_color, 180, 1, 1, 2);

	matrixStack.PopMatrix();

	//siatka
	pushSiatka();
	float ambient2[] = {0.2,0.2,0.2};
	material.setMaterial(ambient2, diffuse, specular, 1);

	RenderDwudziestoscian(5,5,-2,0.8);

	RenderDwudziestoscian(-5,-5,-2,0.5);
	
	RenderDwudziestoscian(small_position[0], small_position[1], small_position[2], 0.2);

	glutSwapBuffers();
}
Esempio n. 8
0
// Called to draw scene
void RenderScene(void)
{
    static CStopWatch	rotTimer;
    float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
    
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);
    
    // Draw the world upside down
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Scale(1.0f, -1.0f, 1.0f); // Flips the Y Axis
    modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit...
    glFrontFace(GL_CW);
    DrawSongAndDance(yRot);
    glFrontFace(GL_CCW);
    modelViewMatrix.PopMatrix();
    
    // Draw the solid ground
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f};
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vFloorColor,
                                 0);
    
    floorBatch.Draw();
    glDisable(GL_BLEND);
    
    
    DrawSongAndDance(yRot);
    
    modelViewMatrix.PopMatrix();
    
    
    // Do the buffer Swap
    glutSwapBuffers();
    
    // Do it again
    glutPostRedisplay();
}
Esempio n. 9
0
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
	{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	modelViewMatrix.PushMatrix();
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		// Reflection step... draw cube upside down, the floor
		// blended on top of it
		if(nStep == 5) {
			glDisable(GL_CULL_FACE);
			modelViewMatrix.PushMatrix();
			modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);
			modelViewMatrix.Translate(0.0f, 2.0f, 0.0f);
			modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
			RenderBlock();
			modelViewMatrix.PopMatrix();
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			RenderFloor();
			glDisable(GL_BLEND);			
			}


		modelViewMatrix.PushMatrix();

			// Draw normally
			modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
			RenderBlock();
		modelViewMatrix.PopMatrix();
		
		
	// If not the reflection pass, draw floor last
	if(nStep != 5)
		RenderFloor();

		
	modelViewMatrix.PopMatrix();


	// Flush drawing commands
	glutSwapBuffers();
	}
Esempio n. 10
0
void RenderScene(void) {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glUseProgram(shader);
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CW);

	CStopWatch timer;
	float angle = timer.GetElapsedSeconds()*3.14f;

	M3DVector3f mAt={0,0,0};
	M3DVector3f mUp={0,0,1};
	M3DVector3f mEye;

	mEye[0]=6.8f*cos(angle);
	mEye[1]=6.0f*sin(angle);
	mEye[2]=5.0f; 
	LookAt(mFrame,mEye,mAt,mUp);
	mFrame.GetCameraMatrix(mCameraMatrix);

	matrixStack.LoadMatrix(mFrustrum.GetProjectionMatrix());
	matrixStack.MultMatrix(mCameraMatrix);

	glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, matrixStack.GetMatrix());

	drawGrid();

	matrixStack.Translate(1.0f,7.0f,0.0f);
	matrixStack.Rotate(30.0f,0.0,0.0,1.0);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix());
	drawPyramid();

	matrixStack.PopMatrix();
	matrixStack.Translate(-7.0f,0.0f,0.0f);
	matrixStack.Scale(2.0f, 2.0f, 2.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix());
	drawPyramid();

	matrixStack.PopMatrix();

	// Perform the buffer swap to display back buffer
    glutSwapBuffers();
	glutPostRedisplay();
}
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld(GLfloat yRot)
{
	M3DMatrix44f mCamera;
	modelViewMatrix.GetMatrix(mCamera);
	
	// Need light position relative to the Camera
	M3DVector4f vLightTransformed;
	m3dTransformVector4(vLightTransformed, vLightPos, mCamera);

	// Draw the light source as a small white unshaded sphere
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translatev(vLightPos);

		if(bUseFBO)
			UseProcessProgram(vLightPos, vWhite, -1);
		else
			shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vWhite);

		sphereBatch.Draw();
	modelViewMatrix.PopMatrix();

	// Draw stuff relative to the camera
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(0.0f, 0.2f, -2.5f);

		modelViewMatrix.PushMatrix();
			modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
            modelViewMatrix.Translate(0.0, (GLfloat)-0.60, 0.0);
            modelViewMatrix.Scale((GLfloat)0.02, (GLfloat)0.006, (GLfloat)0.02);
            
            glBindTexture(GL_TEXTURE_2D, ninjaTex[0]);

			if(bUseFBO)
			{
				UseProcessProgram(vLightTransformed, vWhite, 0);
			}
			else
			{
                shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
			}
            ninja.Render(0,0);
        modelViewMatrix.PopMatrix();

	modelViewMatrix.PopMatrix();
}
Esempio n. 12
0
void Display()
{
	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		if (reflecting)
		{
			// Draw the "reflection" of the scene upside down
			modelViewMatrix.PushMatrix();

				// Flip the y-axis last.
				modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);

				// The scene is essentially in a pit, bo elevate it an equal distance from the
				// x-z plane to ensure that its reflection will appear to be below the ground.
				modelViewMatrix.Translate(0.0f, -2.0f * FLOOR_HEIGHT, 0.0f);

				// Reverse the orientation of all polygonsm in the scene so the orientation of
				// their reflections will produce the same lighting as the above-ground scene.
				glFrontFace(GL_CW);
				DrawScene();
				glFrontFace(GL_CCW);

			modelViewMatrix.PopMatrix();
		}

  DrawGround();
  DrawScene();

	modelViewMatrix.PopMatrix();

	// Do the buffer Swap
	glutSwapBuffers();

	// Tell GLUT to do it again
	glutPostRedisplay();
}
Esempio n. 13
0
void RenderScene(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glFrontFace(GL_CW);
    glUseProgram(shader);
    M3DVector3f at={0.0f, 0.0f, 0.0f};
    M3DVector3f up={0.0f, 0.0f, 1.0f};
    M3DVector3f eye;
    float angle = timer.GetElapsedSeconds()*3.14159f/8;
    eye[0]= 6.8f * cos(angle);
    eye[1]= 6.0f * sin(angle);
    eye[2]= 25.0f;
    LookAt(cameraFrame,eye,at,up);

    projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
    modelView.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);

    modelView.LoadMatrix(mCamera);
    modelView.PushMatrix();
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
		szachownica();
    modelView.Translate(0.0f, 0.0f, 0.0f);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
		rysujPiramidke();
    modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(5.0f, 0.0f, 0.0f);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
		rysujPiramidke();
    modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-5.0f, 0.0f, 0.0f);
    modelView.Scale(2.0f, 2.0f, 2.0f);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
		rysujPiramidke();
    modelView.PopMatrix();
    modelView.PopMatrix();

	glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 14
0
void Display()
{
    static CStopWatch timer;
    GLfloat yRot = timer.GetElapsedSeconds() * 60.0;

    M3DVector3f vCameraPosition;
    M3DVector3f vCameraForward;
    M3DVector3f vMirrorPosition;
    M3DVector3f vMirrorForward;
    void movingCylinder();

    cameraFrame.GetOrigin(vCameraPosition);
    cameraFrame.GetForwardVector(vCameraForward);

    vMirrorPosition[0] = 0.0f;
    vMirrorPosition[1] = 0.1f;
    vMirrorPosition[2] = -20.0f;
    mirrorFrame.SetOrigin(vMirrorPosition);

    vMirrorForward[0] = vCameraPosition[0];
    vMirrorForward[1] = vCameraPosition[1];
    vMirrorForward[2] = (vCameraPosition[2] + 20);
    m3dNormalizeVector3(vMirrorForward);
    mirrorFrame.SetForwardVector(vMirrorForward);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fboName);
    glDrawBuffers(1,fboBuffers);
    glViewport(0,0,mirrorWidth,mirrorHeight);

    modelViewMatrix.PushMatrix();
    M3DMatrix44f mMirrorView;
    mirrorFrame.GetCameraMatrix(mMirrorView);
    modelViewMatrix.MultMatrix(mMirrorView);
    modelViewMatrix.Scale(-1.0f,1.0f,1.0f);
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vWhite,0);
    floorBatch.Draw();

    drawSun();
    drawTorus(yRot);
    modelViewMatrix.PopMatrix();

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
    glDrawBuffers(1,windowBuffer);
    glViewport(0,0,mirrorWidth,mirrorHeight);

    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);

    modelViewMatrix.PushMatrix();
    glBindTexture(GL_TEXTURE_2D,mirrorTexture);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE,
                                 transformPipeline.GetModelViewProjectionMatrix(),0);
    mirrorFrontBatch.Draw();
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PushMatrix();
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vWhite,0);
    floorBatch.Draw();

    drawSun();
    drawTorus(yRot);
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();


    //control to moving cylinder
    movingCylinder();

    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 15
0
void renderScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    modelViewM.PushMatrix();

    M3DMatrix44f cameraM;
    cameraFrame.GetCameraMatrix(cameraM);
    modelViewM.MultMatrix(cameraM);

    M3DVector4f lightPos = {0.0f, 10.0f, 5.0f, 1.0f};
    M3DVector4f lightEyePos;
    m3dTransformVector4(lightEyePos, lightPos, cameraM);
    GLfloat whiteLight[] = {1.0f, 1.0f, 1.0f, 1.0f};

    modelViewM.PushMatrix();

    modelViewM.Translate(0, 0, -3);

    M3DMatrix44f objectM;
    objectFrame.GetMatrix(objectM);
    modelViewM.MultMatrix(objectM);

    glBindTexture(GL_TEXTURE_2D, textureID[0]);
#if 0
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, 
                                 pipelineTransform.GetModelViewMatrix(),
                                 pipelineTransform.GetProjectionMatrix(), 
                                 lightEyePos, whiteLight, 0);
#else
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, 
                                 pipelineTransform.GetModelViewProjectionMatrix(),
                                 0);
#endif
    cuboidBatch.Draw();

    modelViewM.PopMatrix();

    static CStopWatch timer;
    float angle = timer.GetElapsedSeconds() * 120;
    modelViewM.Translate(0.5f, 0.6f, -5);
    modelViewM.Rotate(angle, 1, 1, 1);
    modelViewM.Scale(0.5/cuboidLength, 0.3/cuboidHeigth, 0.4/cuboidWidth);
    glBindTexture(GL_TEXTURE_2D, textureID[1]);
#if 0
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, 
                                 pipelineTransform.GetModelViewMatrix(),
                                 pipelineTransform.GetProjectionMatrix(), 
                                 lightEyePos, whiteLight, 0);
#else
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, 
                                 pipelineTransform.GetModelViewProjectionMatrix(),
                                 0);
#endif

    cuboidBatch.Draw();

    modelViewM.PopMatrix();

    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 16
0
void Gripper::render(GLMatrixStack &modelViewStack, GLMatrixStack &projectionStack, float *phantomMat, GLShaderManager &shaderManager){
		modelViewStack.PushMatrix();
		//modelViewStack.Translate(position[0] + size[0]*0.5f, position[1] + size[1]*0.5f, position[2] + size[2]*0.5f);

		modelViewStack.MultMatrix(phantomMat);
		modelViewStack.Scale(scalar, scalar, scalar);

		shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), curColor);	
		sphereBatch.Draw();

		modelViewStack.PushMatrix();			
			modelViewStack.PushMatrix();
				modelViewStack.Rotate(90, 0, 1, 0);
				modelViewStack.Scale(0.5, 0.5, endEffector[RED].curPos);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), curColor);	
				cylBatch.Draw();
			modelViewStack.PopMatrix();

			modelViewStack.Translate(endEffector[RED].curPos, 0, 0.0);
			shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vRed);	
			sphereBatch.Draw();

			modelViewStack.Translate(0.0, 0, -8.0);
			modelViewStack.PushMatrix();
				modelViewStack.Scale(0.5, 0.5, 8.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), curColor);	
				cylBatch.Draw();
			modelViewStack.PopMatrix();
			shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vRed);	
			sphereBatch.Draw();
			modelViewStack.PushMatrix();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vRed);	
				sphereBatch.Draw();
				modelViewStack.Translate(0.0, -4.0, 0.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vRed);	
				sphereBatch.Draw();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vRed);	
				sphereBatch.Draw();
			modelViewStack.PopMatrix();
		modelViewStack.PopMatrix();

		modelViewStack.PushMatrix();	
			modelViewStack.PushMatrix();
				modelViewStack.Rotate(-90, 0, 1, 0);
				modelViewStack.Scale(0.5, 0.5, endEffector[GREEN].curPos);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), curColor);	
				cylBatch.Draw();
			modelViewStack.PopMatrix();

			modelViewStack.Translate(-endEffector[GREEN].curPos, 0, 0.0);
			shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vGreen);	
			sphereBatch.Draw();

			modelViewStack.Translate(0.0, 0, -8.0);
			modelViewStack.PushMatrix();
				modelViewStack.Scale(0.5, 0.5, 8.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), curColor);	
				cylBatch.Draw();
			modelViewStack.PopMatrix();
			
			shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vGreen);	
			sphereBatch.Draw();
			modelViewStack.PushMatrix();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vGreen);	
				sphereBatch.Draw();
				modelViewStack.Translate(0.0, -4.0, 0.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vGreen);	
				sphereBatch.Draw();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, modelViewStack.GetMatrix(), projectionStack.GetMatrix(), vGreen);	
				sphereBatch.Draw();
			modelViewStack.PopMatrix();
		modelViewStack.PopMatrix();


	modelViewStack.PopMatrix();
}
Esempio n. 17
0
void RenderScene(void)
{
	static CStopWatch	rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	modelViewMatrix.PushMatrix();

	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelViewMatrix.MultMatrix(mCamera);

	modelViewMatrix.PushMatrix();
	{
		//反向
		modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);
		//因为是反向,所以正数是向下
		modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit...
		
		//三维中其中一维反向之后,缠绕方向也会呈相反,所以重新定义缠绕正方向为顺时针方向;
		glFrontFace(GL_CW);
		DrawSongAndDance(yRot);
		glFrontFace(GL_CCW);
	}
	modelViewMatrix.PopMatrix();

	// Draw the solid ground
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f };
	shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
		transformPipeLine.GetModelViewProjectionMatrix(),
		vFloorColor,
		0);

	floorBatch.Draw();
	glDisable(GL_BLEND);


	DrawSongAndDance(yRot);

	modelViewMatrix.PopMatrix();
	

	// Render the overlay

	// Creating this matrix really doesn't need to be done every frame. I'll leave it here
	// so all the pertenant code is together
	M3DMatrix44f mScreenSpace;
	m3dMakeOrthographicMatrix(mScreenSpace, 0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f);

	// Turn blending on, and depth testing off
	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);

	glUseProgram(sphereWolrdShader);
	glUniform1i(locTexture, 0);
	glUniformMatrix4fv(locMVP, 1, GL_FALSE, mScreenSpace);
	glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]);
	logoBatch.Draw();

	// Restore no blending and depth test
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Do the buffer Swap
	glutSwapBuffers();

	// Do it again
	glutPostRedisplay();

}
Esempio n. 18
0
void RenderScene(void) {
  


    // Clear the window with current clearing color
      
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    // Obracanie widoku
 float angle =timer.GetElapsedSeconds()*PI/4;
	posVector[0] = -8.0f * cos(angle / 2.0f);
    posVector[1] = -8.0f * sin(angle / 2.0f);
    posVector[2] = 5.0f;
  

	 swiatlo0.position[0] = 8.0f * cos(-angle);
   swiatlo0.position[1] = 15.0f * sin(-angle);
   swiatlo0.position[2] = 5.0f;

 LookAt(viewFrame, posVector, atVector, upVector);
     
  
  
geometryPipeline.SetMatrixStacks(modelView,projection);

      
    projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
modelView.PushMatrix();
M3DMatrix44f mCamera;
viewFrame.GetCameraMatrix(mCamera);
modelView.LoadMatrix(mCamera);
modelView.PushMatrix();
//glUseProgram(shader);

modelView.Translate(swiatlo0.position[0], swiatlo0.position[1], swiatlo0.position[2]);
glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
modelView.PopMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glUseProgram(shader);
   modelView.PushMatrix();
  modelView.Translate(swiatlo0.position[0], swiatlo0.position[1], swiatlo0.position[2]);
   modelView.Scale(0.25f, 0.25f, 0.25f);
   glUniformMatrix4fv(MVPMatrixLocationshader, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
modelView.PopMatrix();
    glUseProgram(Pshader);//wywo³anie shadera

    //mno¿enie macierzy
    //modelView.MultMatrix(mCamera);
   // modelView.PushMatrix();
    //m3dMatrixMultiply44(mModelViewProjection, viewFrustum.GetProjectionMatrix(), mCamera);
  // wrzucanie do shadera
   
glUniformMatrix3fv(NMatrixLocation, 1, GL_FALSE, geometryPipeline.GetNormalMatrix());
   glUniformMatrix4fv(VMmatrixLocation, 1, GL_FALSE, mCamera);
   glUniform3fv(iambient_component_location, 1, iambient_component);
   glUniform3fv(swiatlo0_location, 1, swiatlo0.position);
   glUniform3fv(swiatlo0_idiffuse_location, 1, swiatlo0.idiffuse);
   glUniform3fv(swiatlo0_ispecular_location, 1, swiatlo0.ispecular);
   glUniform3fv(swiatlo0_attenuation_location, 1, swiatlo0.attenuation);
   glUniform1f(material0_ka_location, material0.ka);
   glUniform1f(material0_kd_location, material0.kd);
   glUniform1f(material0_ks_location, material0.ks);
   glUniform1f(material0_alpha_location, material0.alpha);
   //--
   glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix());


    DrawPramid(0.5,0.0,1.0);    
 // drawTriangles(20,ico_vertices,ico_faces);
// rysowanie siatki --------------------------------------------------------------------------
    glEnable(GL_CULL_FACE);
    glPolygonOffset(1.0f, 1.0f);
    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0, 1.0, 1.0);
    glEnable(GL_POLYGON_OFFSET_FILL);
glBegin(GL_QUADS);
glVertex3f(10,    -10.0f,   0.0f);
  
  
glVertex3f(-10,    -10.0f,  0.0f);
glVertex3f(-10,    10.0f,   0.0f);
glVertex3f(10,    10.0f,   0.0f);
  
  
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
   glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0, 1.0, 1.0);
    for(int i=-10;i<=10;i++){
    glBegin(GL_LINES);
            glVertex3f((float)i,    -10.0f,  0.0f);
            glVertex3f((float)i,    10.0f,   0.0f);
            glEnd();
    }
for(int i=-10;i<=10;i++){
    glBegin(GL_LINES);
            glVertex3f(-10.0f,  (float)i,    0.0f);
            glVertex3f(10.0f,   (float)i,    0.0f);
    glEnd();
    }
     glDisable(GL_CULL_FACE); 
	 //sphereBatch.Draw();

	 glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix());
modelView.PopMatrix();
    // rysowanie siatki - koniec -------------------------------------------------------------------
//matrixStack.Translate(10.0f,1.0f,0.0f);
 
// macierz translacji i macierz rotacji
//M3DMatrix44f mT,mR;
 // m3dTranslationMatrix44(mT,0.0f,3.0f,0.0f);
  //m3dRotationMatrix44(mR, angle, 0.0f, 0.0f, 1.0f);
  
  //mno¿enie  macierzy translacji i macierzy rotacji
//m3dMatrixMultiply44(mM,mT,mR);
  
//mno¿enie macierzy przekszta³ceñ i macierzy projekcji modelwidok
// m3dMatrixMultiply44(mModelViewProjection,mModelViewProjection, mM);
  
 //wysy³anie macierzy projekcji modelwidok do shadera
 //glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, mModelViewProjection);
  //TriangleFace(position,color,atVector);
 //DrawPramid(0.5,0.0,1.0);
   
     //drawTriangles(20, ico_vertices, ico_faces);
//matrixStack.PopMatrix();
//matrixStack.Rotate(45.0,0,0,1);
//matrixStack.Translate(0.0,0.0,1.0);
//glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
//DrawPramid(0.5,0.0,1.0);



	glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix());
modelView.PopMatrix();

 
   
      glUseProgram(0);
    // Perform the buffer swap to display back buffer
    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 19
0
void RenderScene(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);


	glUniform3fv(shaderMaterialAmbientLocation, 1, ambientColor);
	glUniform3fv(shaderMaterialDiffuseLocation, 1, diffuseColor);
	glUniform3fv(shaderMaterialSpecularLocation, 1, specularColor);
	glUniform1f(shaderMaterialSpecularExponentLocation, specularExponent);
	
	
	glUniform3fv(shaderPositionLocation, 1, position);
	glUniform3fv(shaderColorLocation, 1, color);
	glUniform1f(shaderAngleLocation, angle);
	glUniform1f(shaderAttenuation0Location, attenuation0);
	glUniform1f(shaderAttenuation1Location, attenuation1);
	glUniform1f(shaderAttenuation2Location, attenuation2);


	GLMatrixStack modelView;
	GLMatrixStack projection;
	GLGeometryTransform geometryPipeline;
	geometryPipeline.SetMatrixStacks(modelView,projection);

	projection.LoadMatrix(frustum.GetProjectionMatrix());
	modelView.PushMatrix();
	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelView.LoadMatrix(mCamera);
	modelView.PushMatrix();

	
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	rysujSiatke();

	modelView.PushMatrix();
	modelView.Translate(0.0f,0.0f,-1.f);
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	rysujTrojkat();
	modelView.PopMatrix();


	modelView.PushMatrix();
	modelView.Translate(0.0f,4.0f,0.f);
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	rysujTrojkat();
	modelView.PopMatrix();


	modelView.PushMatrix();
	modelView.Translate(3.0f,-3.0f,0.f);
	modelView.Scale(2.0f,2.0f,2.f);
	modelView.Rotate(45,0,0,1);
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	rysujTrojkat();
	modelView.PopMatrix();


	modelView.PushMatrix();
	modelView.Translate(3.0f,3.0f,0.f);
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	drawTriangles(20, ico_vertices,ico_faces);
	modelView.PopMatrix();

	modelView.PushMatrix();
	modelView.Translate(0.0f,0.0f,7.f);
	modelView.Rotate(90+rotAngle,1,1,1);
	modelView.Scale(2.0f,2.5f,2.5f);
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	drawTriangles(20, ico_vertices,ico_faces);
	modelView.PopMatrix();




	modelView.PushMatrix();
	modelView.Translate(-4.0f,0.0f,4.f);
	modelView.Scale(2.0f,2.0f,2.0f);

	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);

	modelView.PopMatrix();


    // Perform the buffer swap to display back buffer
    glutSwapBuffers();
	rotAngle+=5.f;
	if(!stopRotate){
	M3DVector3f at={0,0,0};
	M3DVector3f up={0,0,1};
	M3DVector3f eye;
	float angle = timer.GetElapsedSeconds()*3.14159f /3.f;
	eye[0]=16.f*cos(angle);
	eye[1]=40.0f*sin(angle);
	eye[2]=20.0f; 
	LookAt(cameraFrame,eye,at,up);
	}
glutPostRedisplay();
}
Esempio n. 20
0
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
    static CStopWatch animationTimer;
    float yRot = animationTimer.GetElapsedSeconds() * 60.0f;
    
    M3DVector3f vCameraPos;
    M3DVector3f vCameraForward;
    M3DVector3f vMirrorPos;
    M3DVector3f vMirrorForward;
    cameraFrame.GetOrigin(vCameraPos);
    cameraFrame.GetForwardVector(vCameraForward);
    
    // Set position of mirror frame (camera)
    vMirrorPos[0] = 0.0;
    vMirrorPos[1] = 0.1f;
    vMirrorPos[2] = -6.0f; // view pos is actually behind mirror
    mirrorFrame.SetOrigin(vMirrorPos);
    
    // Calculate direction of mirror frame (camera)
    // Because the position of the mirror is known relative to the origin
    // find the direction vector by adding the mirror offset to the vector
    // of the viewer-origin
    vMirrorForward[0] = vCameraPos[0];
    vMirrorForward[1] = vCameraPos[1];
    vMirrorForward[2] = (vCameraPos[2] + 5);
    m3dNormalizeVector3(vMirrorForward);
    mirrorFrame.SetForwardVector(vMirrorForward);
    
    // first render from the mirrors perspective
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
    glDrawBuffers(1, fboBuffs);
    glViewport(0, 0, mirrorTexWidth, mirrorTexHeight);
    
    // Draw scene from the perspective of the mirror camera
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mMirrorView;
    mirrorFrame.GetCameraMatrix(mMirrorView);
    modelViewMatrix.MultMatrix(mMirrorView);
    
    // Flip the mirror camera horizontally for the reflection
    modelViewMatrix.Scale(-1.0f, 1.0f, 1.0f);
    
    glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0);
    floorBatch.Draw();
    DrawWorld(yRot);
    
    // Now draw a cylinder representing the viewer
    M3DVector4f vLightTransformed;
    modelViewMatrix.GetMatrix(mMirrorView);
    m3dTransformVector4(vLightTransformed, vLightPos, mMirrorView);
    modelViewMatrix.Translate(vCameraPos[0],vCameraPos[1]-0.8f,vCameraPos[2]-1.0f);
    modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f);
    
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                                 modelViewMatrix.GetMatrix(),
                                 transformPipeline.GetProjectionMatrix(),
                                 vLightTransformed, vBlue, 0);
    cylinderBatch.Draw();
    modelViewMatrix.PopMatrix();
    
    // Reset FBO. Draw world again from the real cameras perspective
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glDrawBuffers(1, windowBuff);
    glViewport(0, 0, screenWidth, screenHeight);
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);
    
    glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0);
    
    floorBatch.Draw();
    DrawWorld(yRot);
    
    // Now draw the mirror surfaces
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translate(0.0f, -0.4f, -5.0f);
    if(vCameraPos[2] > -5.0)
    {
        glBindTexture(GL_TEXTURE_2D, mirrorTexture); // Reflection
        shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
    }
    else
    {
        // If the camera is behind the mirror, just draw black
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack);
    }
    mirrorBatch.Draw();
    shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey);
    mirrorBorderBatch.Draw();
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();
    
    // Do the buffer Swap
    glutSwapBuffers();
    
    // Do it again
    glutPostRedisplay();
}
// main rendering loop
void RenderScene(void){
    static CStopWatch rotTimer;
    float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
    GLfloat vBarColor[] = {1.0f, 0.0f, 0.0f, 1.0f};

    currentFrame = getLatestBufferIndex();

    if(mapper.getSimpleArg('c')){
        vBarColor[0] = .7;
        vBarColor[1] = .2 + sharedBuffer[currentFrame].averageAmp * 60;
        vBarColor[2] = 1.0;

        b = sharedBuffer[currentFrame].averageAmp;
        g = 0;
        r = 0;
        glClearColor(r, g, b, 1.0f);
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    modelViewMatrix.PushMatrix();

    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.PushMatrix(mCamera);
    if(mapper.getCompoundArg('r') == "auto"){
        cameraFrame.RotateWorld(.01, 0.0, 0.0, 1.0);
        cameraFrame.MoveForward(-.1 * sin(yRot * .05));
    }

    // set up light source
    M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
    M3DVector4f vLightEyePos;
    m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

    for(int m = 0; m < NUM_MACROS; m++){
        if(mapper.getSimpleArg('m')){
            modelViewMatrix.PushMatrix();
            macros[m].refFrame.RotateLocalY(.01 * macros[m].multiplier);
            macros[m].refFrame.RotateLocalX(.5 * sharedBuffer[currentFrame].averageAmp);
            modelViewMatrix.MultMatrix(macros[m].refFrame);
        }
        for(int i = 0; i < PACKET_SIZE; i++){
            modelViewMatrix.PushMatrix();
            GLfloat y = 5 * fabs(sharedBuffer[currentFrame].frames[i][0]);
            modelViewMatrix.MultMatrix(bars[i]);
            modelViewMatrix.Scale(barWidth, y, sharedBuffer[currentFrame].averageAmp * 4);
            if(mapper.getSimpleArg('t')){
                modelViewMatrix.Translate(0.0, sharedBuffer[currentFrame].averageAmp, 0.0);
            }
            shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                    transformPipeline.GetModelViewMatrix(),
                    transformPipeline.GetProjectionMatrix(),
                    vLightEyePos, vBarColor);
            cubeBatch.Draw();
            modelViewMatrix.PopMatrix();
        }
        if(mapper.getSimpleArg('m')){
            modelViewMatrix.PopMatrix();
        }
    }

    // draw prisms for amplitudes
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();

    glutSwapBuffers();
    glutPostRedisplay();

    if(currentFrame != -1){
        sharedBuffer[currentFrame].free = true;
    }
}
Esempio n. 22
0
void DrawUpperLimb(float angle) {

	float movement = sin(GL_PI/8 * angle);

	// rechten Arm
	modelViewMatrix.PushMatrix();

	//Schwingbewegung realisieren
	modelViewMatrix.Translate(10.0, 55.0, 0);
	modelViewMatrix.Rotate(movement * 35.0, 1.0, 0.0, 0.0);
	modelViewMatrix.Translate(-10.0, -55.0, 0);

	modelViewMatrix.Translate(60.0f, 10.0f, 0.0f);
	modelViewMatrix.Rotate(30.0, 0.0, 0.0, 1.0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.2, 0.75, 0.2);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// rechte Hand
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, -40.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.2, 0.2, 0.2);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawSphere();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();

	/**
	* linkes Bein
	**/
	modelViewMatrix.PushMatrix();

	// Schwingbewegung
	modelViewMatrix.Translate(0.0, -50.0, 0);
	modelViewMatrix.Rotate(movement * 35.0, 1.0, 0.0, 0.0);
	modelViewMatrix.Translate(0.0, 50.0, 0);

	modelViewMatrix.Translate(-20.0f, -80.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.3, 0.8, 0.3);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// linker Fuss
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, -47.0f, 10.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.5, 0.3, 0.9);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCube();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();

	/**
	* linker Arm
	**/
	modelViewMatrix.PushMatrix();

	// Schwingbewegung
	modelViewMatrix.Translate(10.0, 55.0, 0);
	modelViewMatrix.Rotate(-movement * 35.0, 1.0, 0.0, 0.0);
	modelViewMatrix.Translate(-10.0, -55.0, 0);

	modelViewMatrix.Translate(-60.0f, 10.0f, 0.0f);
	modelViewMatrix.Rotate(-30.0, 0.0, 0.0, 1.0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.2, 0.75, 0.2);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// linke Hand
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, -40.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.2, 0.2, 0.2);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawSphere();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();

	/** rechtes Bein
	*/
	modelViewMatrix.PushMatrix();

	// Schwingbewegung
	modelViewMatrix.Translate(0.0, -50.0, 0);
	modelViewMatrix.Rotate(-movement * 35.0, 1.0, 0.0, 0.0);
	modelViewMatrix.Translate(0.0, 50.0, 0);

	modelViewMatrix.Translate(20.0f, -80.0f, 0.0f);
	modelViewMatrix.Rotate(8.0, 1.0, 0.0, 0.0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.3, 0.8, 0.3);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// rechter Fuss
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, -47.0f, 10.0f);
	modelViewMatrix.Rotate(0.0, 1.0, 0.0, 0.0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.5, 0.3, 0.9);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCube();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	

}
void RenderScene(void) {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glUseProgram(shader);

	M3DVector3f at={0,0,0};
	M3DVector3f up={0,0,1};
	M3DVector3f eye;
	float angle = timer.GetElapsedSeconds()*M_PI/3;

	eye[0]=6.8f*cos(angle);
	eye[1]=6.0f*sin(angle);
	eye[2]=5.0f; 
	LookAt(cameraFrame,eye,at,up);

	geometryPipeline.SetMatrixStacks(modelView,projection);

	projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
	modelView.PushMatrix();

	cameraFrame.GetCameraMatrix(mCamera);
	modelView.LoadMatrix(mCamera);
	modelView.PushMatrix();

	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());

		drawLines();

		drawPyramid();
		
	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(1.0f,6.0f,2.0f);
	modelView.Rotate(180.0f,0.0f,0.0f,1.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());

		drawPyramid();

	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(6.0f,-4.0f,1.0f);
	modelView.Rotate(60.0f,1.0f,1.0f,1.5f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    
		drawPyramid();

	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(-2.0f,0.0f,1.0f);
	modelView.Rotate(80.0f,1.0f,0.0f,1.0f);
	modelView.Scale(0.8f,0.4f,1.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    
		drawPyramid();

	modelView.PopMatrix();
	modelView.PopMatrix();

    // Perform the buffer swap to display back buffer
    glutSwapBuffers();
	glutPostRedisplay();
}
Esempio n. 24
0
void RenderScene(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glFrontFace(GL_CW);
    glUseProgram(shader);
    M3DVector3f at={1.5f, 0.0f, 0.0f};
    M3DVector3f up={-1.0f, 0.0f, 1.0f};
    M3DVector3f eye;
    float angle = timer.GetElapsedSeconds()*3.14159f/8;
    eye[0]= 6.8f * cos(angle);
    eye[1]= 6.0f * sin(angle);
    eye[2]= 30.0f;
    LookAt(cameraFrame,eye,at,up);

    M3DVector3f ambientLight = {1.0f, 1.0f, 1.0f};
    M3DVector3f position = {10.0f, 10.0f, 5.0f};
    M3DVector3f color = {1.0f, 1.0f, 1.0f};
    float l_angle = 90.0f;
    float attenuation0 = 0.01f;
    float attenuation1 = 0.01f;
    float attenuation2 = 0.01f;
    M3DVector3f ambientColor = {0.0f, 1.0, 0.0};
    M3DVector3f diffuseColor = {0.0f, 1.0f, 1.0f};
    M3DVector3f specularColor = {1.0f, 1.0f, 1.0f};
    float specularExponent = 8;

    projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
    modelView.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelView.LoadMatrix(mCamera);
    modelView.PushMatrix();

glUniform3fv(shaderPositionLocation, 1, position);
glUniform3fv(shaderColorLocation, 1, color);
glUniform1f(shaderAngleLocation, angle);
glUniform1f(shaderAttenuation0Location, attenuation0);
glUniform1f(shaderAttenuation1Location, attenuation1);
glUniform1f(shaderAttenuation2Location, attenuation2);

    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);

    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);

    glPolygonOffset(1.0f, 1.0f);
	grid();
    glEnable(GL_POLYGON_OFFSET_FILL);
	grid();
    glDisable(GL_POLYGON_OFFSET_FILL);
   

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-7.75f, -7.75f, 0.0f);
	modelView.Scale(0.25f, 0.25f, 0.25f);
    glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	piramida();

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-6.0f, -6.0f, 0.0f);
	modelView.Scale(0.5f, 0.5f, 0.5f);
	modelView.Rotate(angle*512, 0.0f, 0.0f, 2.0f);
    glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-4.0f, -4.0f, 0.0f);
	modelView.Scale(0.75f, 0.75f, 0.75f);
	modelView.Rotate(angle*512, 0.0f, 2.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
    
	piramida();

	modelView.PopMatrix();`
    modelView.PushMatrix();
    modelView.Translate(2.0f, 2.0f, 0.0f);
    modelView.Scale(1.5f, 1.5f, 1.5f);
	modelView.Rotate(angle*512, 2.0f, 2.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
    
	piramida();

	modelView.PopMatrix();
    modelView.PushMatrix();
	modelView.Translate(-1.5f, -1.5f, 0.0f);
	modelView.Rotate(angle*512, 2.0f, 0.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);

	DrawTriangles(20, vertices_tab, faces_tab);
	
	modelView.PopMatrix();
	modelView.PushMatrix();
    modelView.Translate(6.5f, 6.5f, 0.0f);
    modelView.Scale(2.5f, 2.5f, 2.5f);
	modelView.Rotate(angle*512, 2.0f, 2.0f, 2.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	DrawSmoothTriangles(20, vertices_tab, faces_tab);

	modelView.PopMatrix();
    modelView.PopMatrix();
    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 25
0
void Gripper::environmentCalc(GLMatrixStack &modelViewStack, float phantomMat[16]){
	phidgets.sampleAll();

	for(int i = 0; i < 2; ++i){
		if(phidgets.getRaw(i) > 500)
			return;
		if(phidgets.getRaw(i) < 0)
			return;
	}

	endEffector[RED].currentRaw = phidgets.getRaw(0);
	endEffector[GREEN].currentRaw = phidgets.getRaw(1);
	for(int i = 0; i < 2; ++i){
		END_EFFECTOR *ee = &(endEffector[i]);
		ee->maxRaw = max(ee->maxRaw, ee->currentRaw);
		ee->minRaw = min(ee->minRaw, ee->currentRaw);
		double range = ee->maxRaw - ee->minRaw;
		double raw = ee->currentRaw - ee->minRaw;

		ee->gripperForce = max((1.0 - (raw/range)), 0);
		ee->curPos = ee->curPos - (ee->gripperForce - ee->restoreForce - ee->contactForce) * ee->scalar;

		ee->curPos = min(ee->maxRange, ee->curPos);
		ee->curPos = max(ee->minRange, ee->curPos);
		//Dprint::add("[%d] range = %.2f, raw = %.2f, maxRaw = %d, minRaw = %d, curPos = %.2f", i, range, raw, ee->maxRaw, ee->minRaw, ee->curPos);
	}

	modelViewStack.PushMatrix();
		modelViewStack.LoadIdentity();
		modelViewStack.MultMatrix(phantomMat);
		modelViewStack.Scale(scalar, scalar, scalar);
		modelViewStack.GetMatrix(matrix);
		setPosFromMatrix(positions[YELLOW]);

		modelViewStack.PushMatrix();			
			modelViewStack.Translate(endEffector[RED].curPos, 0, 0.0);
			modelViewStack.Translate(0.0, 0, -8.0);
			modelViewStack.GetMatrix(matrix);
			setPosFromMatrix(positions[RED]);
			modelViewStack.PushMatrix();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[RED2]);
				modelViewStack.Translate(0.0, -4.0, 0.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[RED3]);
				modelViewStack.Translate(0.0, 2.0, -2.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[RED4]);
			modelViewStack.PopMatrix();
		modelViewStack.PopMatrix();

		modelViewStack.PushMatrix();	
			modelViewStack.Translate(-endEffector[GREEN].curPos, 0, 0.0);
			modelViewStack.Translate(0.0, 0, -8.0);
			modelViewStack.GetMatrix(matrix);
			setPosFromMatrix(positions[GREEN]);
			modelViewStack.PushMatrix();
				modelViewStack.Translate(0.0, 2.0, -2.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[GREEN2]);
				modelViewStack.Translate(0.0, -4.0, 0.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[GREEN3]);
				modelViewStack.Translate(0.0, 2.0, -2.0);
				modelViewStack.GetMatrix(matrix);
				setPosFromMatrix(positions[GREEN4]);
			modelViewStack.PopMatrix();
		modelViewStack.PopMatrix();

	modelViewStack.PopMatrix();

	for(int i = 0; i < NUM_END_EFFECTORS; ++i){
		offsets[i][0] = positions[i][0] - positions[YELLOW][0];
		offsets[i][1] = positions[i][1] - positions[YELLOW][1];
		offsets[i][2] = positions[i][2] - positions[YELLOW][2];
	}
}