Пример #1
0
Camera::Camera() 
 : _far(CLIPPING_DEPTH_MAX),
   _near(CLIPPING_DEPTH_MIN),
   _fov(90),
   _focalPoint(0)
{
  setPerspectiveMatrix(_near,_far,_fov);
}
Пример #2
0
void setupCamera(ShaderProgram * sp, const Camera * camera)
{
    /* Pointers */
    GLint viewProjP, viewPosP;

    /* Matrices */
    mat4 viewTrMatrix, viewRotMatrix, viewMatrix;
    mat4 projMatrix, viewProjMatrix;

    setPerspectiveMatrix(projMatrix,
        camera->viewAngleY,
        camera->aspect,
        camera->znear,
        camera->zfar);

    setMatrixFromQuaternion(viewRotMatrix, camera->q);

    setTranslationMatrix(viewTrMatrix,
        -camera->pos[0],
        -camera->pos[1],
        -camera->pos[2]);

    setMulMatrix(viewMatrix, viewRotMatrix, viewTrMatrix);

    setMulMatrix(viewProjMatrix, projMatrix, viewMatrix);

    glUseProgram(sp->p);

    viewProjP = glGetUniformLocation(sp->p, "transform.viewProjection");
    /* TODO: if (viewProjP == -1) {} */
    glUniformMatrix4fv(viewProjP, 1, GL_TRUE, viewProjMatrix);

    viewPosP = glGetUniformLocation(sp->p, "transform.viewPosition");
    /* TODO: if (viewPosP == -1) {} */
    glUniform3fv(viewPosP, 1, camera->pos);

#ifdef DEBUG
    validateShaderProgram(sp->p);
#endif
    CHECK_OPENGL_ERRORS(__FILE__, __LINE__);
}
	static void render()
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the draw buffer

		glEnable( GL_BLEND );

		currentCamera->setAspectRatio(resolution.x/resolution.y);
		setCameraTransMatrix(currentCamera->getCameraTransformationMatrix());
		setPerspectiveMatrix(currentCamera->getPerspectiveMatrix());
		setCameraPosition(currentCamera->getTranslate());
		setLights(wLights,LIGHT_COUNT);
		setAmbientLightColor(vec3(.1,.05,.075));
		setAmbientLightColor(vec3(.1,.1,.2));

		//
		//Draw non-transparent models, pushing transparent ones onto a max-heap
		TransparencyQueue transparencyQueue;
		drawOpaqueEntities(wEntities, transparencyQueue); //Draw Every GameEntity
		drawOpaqueEntities(wWalls, transparencyQueue); //Draw Every Wall
		drawOpaqueEntities(wSoftEntities, transparencyQueue);

		//Draw transparent models, furthest from camera first
		//Disable updating the z-buffer, but still conduct the
		//test so that nearer opaque objects completely occlude
		//farther transparent objects.

		glEnable( GL_BLEND );
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDepthMask(GL_FALSE);
		while(!transparencyQueue.empty()) {
			transparencyQueue.top()->draw();
			transparencyQueue.pop();
		}
		glDepthMask(GL_TRUE);

		glDisable(GL_BLEND);
	}
Пример #4
0
 /**
  * @brief Changes the fovy and computes new perspective projection matrix.
  * @param new_fovy New value for field of view.
  */
 void changeFovy (float new_fovy)
 {
     fovy = new_fovy;
     setPerspectiveMatrix(fovy, aspect_ratio, near_plane, far_plane);
 }
	void callbackDisplay() {
		//Render all the TVCameras.
		CameraEntity* const originalCamera = currentCamera;
		for(TVCameraList::iterator i = wTVCameras.begin(); i != wTVCameras.end(); ++i) {
			currentCamera = &(*i)->cameraEntity;
			(*i)->framebuffer.render(&render, 160, 160);
		}
		currentCamera = originalCamera;

		//Render to the screen.
		render();

		//UI hack
		glEnable(GL_BLEND);

		setAmbientLightColor(vec3(1,1,1));
		setCameraTransMatrix(mat4());
		setPerspectiveMatrix(currentCamera->getOrthographicMatrix());
		setCameraPosition(vec3(0,0,.5));

		Wall w=Wall();
		w.translate(-(.4)*(resolution.x/resolution.y),.48,-10);
		w.scale((Globals::getPlayer()->getHealth()/Player::MAX_HEALTH)*.5,.025,.1);

		DrawableEntity d=DrawableEntity(NULL,"Resources/cube.obj");
		d.translate(.5,0,0);
		d.setAlpha(.75);

		w.setModel(d);
		w.draw();

		w.translate(0,-.02,0);
		w.setScale((Globals::getPlayer()->getShieldCharge()/Player::MAX_SHIELD)*.5,.01,.1);
		w.draw();

		glDisable(GL_BLEND);

		//Draw UI Text
		if(useText) {
			Globals::setModelTransMatrix(mat4());
			Text2D n; 
			n.draw_stuff("HEALTH",vec4(1,1,1,1), -0.495*(resolution.x/resolution.y), .4725 );
			n.draw_stuff("SHIELD",vec4(1,1,1,1), -0.495*(resolution.x/resolution.y), .449 );

			char* weaponText="";
			switch(getPlayer()->getWeapon()){
			case 2:
				weaponText="CURVY BULLET";
				break;
			case 0:
				weaponText="MACHINE GUN";
				break;
			case 1:
				weaponText="MORTAR";
				break;

			}
			n.draw_stuff(weaponText,vec4(1,1,1,1), -0.495*(resolution.x/resolution.y), .449-(.4725-.449) );

			if(wScenes[currentLevel]->_beaten){
				n.draw_stuff("You Won!!",vec4(1,1,1,1),-.025,.05);
				n.draw_stuff("Press 'esc' to quit",vec4(1,1,1,1),-.1,0);
			}
		}

		glutSwapBuffers();
	}