Ejemplo n.º 1
0
void MainLoop(CPlatform * const  pPlatform)
{
	static float degrees[] = {0,0};
	CMatrix44 rot;	
	Transform transform(10);	

	//update the main application
	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT); //not really needed 
	transform.Push();
		program.SetMtx44(mt,transform.GetCurrentMatrix().data);
		WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);

		transform.Translate(0.2f,0.0,0.0);
		program.SetMtx44(mt,transform.GetCurrentMatrix().data);
		WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);
			

		transform.Push();				
			transform.Translate(-0.4f,0.0,0.0);
			rot.Identity();
			rot.Rotate(degrees[0],0,0,1);
			transform.ApplyTransform(rot);
			program.SetMtx44(mt,transform.GetCurrentMatrix().data);
			WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);

			transform.Push();
				transform.Translate(0.0,0.3f,0);
				program.SetMtx44(mt,transform.GetCurrentMatrix().data);
				WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);
			transform.Pop();
		transform.Pop();

		transform.Push();
			rot.Identity();
			rot.Rotate(degrees[1],0,0,1);
			transform.ApplyTransform(rot);
			transform.Translate(0.0,-0.3f,0.0);
			transform.ApplyTransform(rot);
			program.SetMtx44(mt,transform.GetCurrentMatrix().data);
			WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);
		transform.Pop();
	transform.Pop();
	//swap buffers
	pPlatform->UpdateBuffers();

	degrees[0] -= 360.0f*pPlatform->GetDT();
	degrees[1] += 180.0f*pPlatform->GetDT();
	if(degrees[0] < 0.0f)
		degrees[0] += 360.0f;
	if(degrees[1] > 360.0f)
		degrees[1] -= 360.0f;
}
Ejemplo n.º 2
0
void MainLoop(CPlatform * const  pPlatform)
{
	float tranD[3] = {0.0f, -1.0f, 0};				
	//update the main application
	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::EnableDepthTest(true);		
	program.Start();

	//Draw from light perspective
	//glPolygonOffset( 2.5f, 25.0f );
	//glEnable( GL_POLYGON_OFFSET_FILL);
	transform.Push();			
	{
		WRender::SetupViewport(0, 0, TEX_DIMENSIONS, TEX_DIMENSIONS);	//adjust viewport
		WRender::BindFrameBuffer(WRender::FrameBuffer::DRAW, fbo);		//set fbo 
		WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);				//clear draw buffers (must be called after we set the fbo)

		rotLat.Identity();	rotLat.Rotate(lightLatitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(lightLongitude, 0, 1, 0);

		transform.Translate(cameraPosition);			
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);

		//setup shadow mvp
			
		shadow_transform.Identity();
		shadow_transform.Translate(0.5f, 0.5f, 0.5f);
		shadow_transform.Scale(0.5f,0.5f,0.5f);
		shadow_transform.ApplyTransform(transforms.proj);
		shadow_transform.ApplyTransform(transform.GetCurrentMatrix());
		DrawGeometry(true);

		WRender::UnbindFrameBuffer(WRender::FrameBuffer::DRAW); //reset draw buffer
		WRender::SetupViewport(0, 0, 640, 640);	//reset viewport			
	}
	//glDisable( GL_POLYGON_OFFSET_FILL);
	transform.Pop();		

	//draw scene
	transform.Push();			
	{
		rotLat.Identity();	rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);
		DrawGeometry(false);			
	}
	transform.Pop();		

	//render depth texture to screen
	textureShader.Start();
	WRender::BindVertexArrayObject(sqVao);					
	textureShader.SetVec3("translate",tranD);		
	WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(sqIndices)/sizeof(unsigned char), 0);		
		
	//update Keyboard
	pPlatform->UpdateBuffers();
	if(!pPlatform->GetKeyboard().keys[KB_LEFTSHIFT].IsPressed())
	{	pLat = &latitude; pLong = &longitude;}
	else
	{	pLat = &lightLatitude; pLong = &lightLongitude;}

	if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
		*pLat += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
		*pLat -= 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())//l
		*pLong += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())//r
		*pLong -= 90.0f * pPlatform->GetDT();		

}