예제 #1
0
파일: Game.cpp 프로젝트: alanhaugen/wire3d
//----------------------------------------------------------------------------
void Game::DrawWarning(Double time)
{
	GetRenderer()->DisableLighting();
	Float f = (MathF::Sin(MathF::FMod(static_cast<Float>(time*5),
		MathF::TWO_PI)) + 1) * 0.5F;
	ColorRGB color(1, f, f);
	mspWarningText->Clear(color);
	mspWarningText->Append("Aim at the screen!");
	mspWarningText->Update(GetRenderer());

	Vector3F center = mspWarningText->GetMesh()->GetModelBound()->GetCenter();
	center.Y() -= static_cast<Float>(mpRenderer->GetHeight()) * 0.5F;
	center.X() -= static_cast<Float>(mpRenderer->GetWidth()) * 0.5F;
	Transformation translate;
	translate.SetTranslate(-center);

	GetRenderer()->Draw(mspWarningText, translate);
}
예제 #2
0
//----------------------------------------------------------------------------
void Node::WarmUpRendering(Renderer* pRenderer)
{
#ifndef WIRE_WII // Wii does not need to warm up by submitting draw calls
	WIRE_ASSERT(pRenderer);
	UpdateGS(0, true, false);

	Vector3F cameraLocation = WorldBound->GetCenter();
	cameraLocation.Z() += WorldBound->GetRadius();
	Vector3F viewDirection = -Vector3F::UNIT_Z;
	Vector3F up = Vector3F::UNIT_Y;
	Vector3F right = viewDirection.Cross(up);
	CameraPtr spCamera = WIRE_NEW Camera;
	spCamera->SetFrame(cameraLocation, viewDirection, up, right);

	Float fieldOfView = 60.0F;
	Float aspectRatio = 2;
	Float nearPlane = 0.1F;
	Float farPlane = WorldBound->GetRadius() * 2.0F;
	spCamera->SetFrustum(fieldOfView, aspectRatio, nearPlane, farPlane);

	CullerSorting culler;
	culler.SetCamera(spCamera);
	culler.ComputeVisibleSet(this);

	pRenderer->PreDraw(spCamera);

	// draw scene to warm up batching buffers
	pRenderer->Draw(culler.GetVisibleSets());

	// collect and draw all materials separately so none will be missed
	// by CULL_ALWAYS or Switch/LOD nodes.
	THashSet<Material*> materials;
	TStack<Node*> scene(1000);
	scene.Push(this);
	while (!scene.IsEmpty())
	{
		Node* pNode = NULL;
		scene.Pop(pNode);
		RenderObject* pRenderObject = pNode->GetRenderObject();
		if (pRenderObject && pRenderObject->GetMaterial())
		{
			materials.Insert(pRenderObject->GetMaterial());
		}

		for (UInt i = 0; i < pNode->GetQuantity(); i++)
		{
			Node* pChild = DynamicCast<Node>(pNode->GetChild(i)); 
			if (pChild)
			{
				scene.Push(pChild);
			}
		}
	}

	RenderObjectPtr spCube = StandardMesh::CreateCube24(4, pRenderer->
		GetMaxTextureStages(), true);
	THashSet<Material*>::Iterator it(&materials);
	Transformation transformation;
	transformation.SetTranslate(cameraLocation - Vector3F(0, 0, 3));
	for (Material** pMaterial = it.GetFirst(); pMaterial; pMaterial = 
		it.GetNext())
	{
		spCube->SetMaterial(*pMaterial);
		pRenderer->Draw(spCube, transformation);
	}

	pRenderer->PostDraw();
#endif
}
예제 #3
0
//----------------------------------------------------------------------------
void Sample5::OnIdle()
{
	Double time = System::GetTime();
	Double elapsedTime = time - mLastTime;
	mLastTime = time;
	mAngle += static_cast<Float>(elapsedTime);
	mAngle = MathF::FMod(mAngle, MathF::TWO_PI * 2);

	// scene graph transformations
	//
	Node* pLitGroup = DynamicCast<Node>(mspRoot->GetChild(0));
	WIRE_ASSERT(pLitGroup);

	// rotate the 2 cubes
	Matrix3F rotate1(Vector3F(0.75F, 0.25F, 0.5F), -mAngle * 0.5F);
	Spatial* pCube1 = pLitGroup->GetChild(0);
	pCube1->Local.SetRotate(rotate1);

	Matrix3F rotate2(Vector3F(-0.75F, -0.25F, -0.5F), -mAngle * 0.5F);
	Spatial* pCube2 = pLitGroup->GetChild(1);
	pCube2->Local.SetRotate(rotate2);

	// move the green light up and down
	Float y = MathF::FMod(static_cast<Float>(time), MathF::TWO_PI);
	Vector3F lightPos1(0, MathF::Sin(y*2) * 1.5F, 2);
	Node* pLightNode1 = DynamicCast<Node>(mspRoot->GetChild(1));
	WIRE_ASSERT(pLightNode1);
	pLightNode1->Local.SetTranslate(lightPos1);

	// rotate the red light about the y axis
	Node* pLightNode2 = DynamicCast<Node>(mspRoot->GetChild(2));
	WIRE_ASSERT(pLightNode2);
	Matrix34F rotateLight2(Vector3F::UNIT_Y, -mAngle);
	Vector3F lightPos2 = rotateLight2 * Vector3F(5, 0, 0);
	pLightNode2->Local.SetTranslate(lightPos2);

	mspRoot->UpdateGS(time);
	mCuller.ComputeVisibleSet(mspRoot);

	// manual transformation from local to world space of 
	// the non-scene graph part
	Transformation transformation;
	Float angle = MathF::Sin(mAngle*2);
	angle = angle * MathF::HALF_PI*0.3F + MathF::PI;
	Matrix34F rotateLocalLight3(Vector3F(0, 1, 0), angle);
	Matrix34F rotateWorldLight3(Vector3F(1, 0, 0), -0.5F);
	transformation.SetTranslate(Vector3F(0.5F, -1.0F, 4+MathF::Sin(y*1.0F)*2));
	transformation.SetRotate(rotateWorldLight3 * rotateLocalLight3);
	transformation.SetUniformScale(0.15F);
	mspSpotLight->Position = transformation.GetTranslate();
	mspSpotLight->Direction = transformation.GetMatrix().GetColumn(2);

	GetRenderer()->ClearBuffers();
	GetRenderer()->PreDraw(mspCamera);

	// render the scene graph
	GetRenderer()->Draw(mCuller.GetVisibleSets());

	// before we start drawing objects in 'manual' mode, release all resources
	// cached by the Renderer to return the renderer to its default state.
	// This is necessary when identical resources (mspTexture in this case)
	// are used by the scene graph and other objects that are being draw
	// manually.
	GetRenderer()->ReleaseResources();

	// render the white cube representing the spot light
	GetRenderer()->Draw(mspWhiteCube, transformation);

	Matrix34F matrix(Vector3F(1.0F, 0, 0), -1.0F, Vector3F(0, -2.5F, 0));
	transformation.SetMatrix(matrix, false);
	transformation.SetUniformScale(1);

	// render the bottom plane which is being lit by the spot light
	GetRenderer()->SetLight(mspSpotLight);
	GetRenderer()->EnableLighting(mspSpotLight->Ambient);
	GetRenderer()->Draw(mspPlane, transformation);
	GetRenderer()->DisableLighting();

	GetRenderer()->PostDraw();
	GetRenderer()->DisplayBackBuffer();
}