//---------------------------------------------------------------------------- void OnIdle() { // the render loop Transformation transformation; Matrix3F rotate(Vector3F(0.2F, 0.7F, 0.1F), MathF::FMod( static_cast<Float>(System::GetTime()), MathF::TWO_PI)); transformation.SetRotate(rotate); gpRenderer->ClearBuffers(); gpRenderer->PreDraw(gspCamera); gpRenderer->Draw(gspCube, transformation); gpRenderer->PostDraw(); gpRenderer->DisplayBackBuffer(); }
//---------------------------------------------------------------------------- void Sample0::OnIdle() { // The render loop. Called by the main loop. // Rotate the cube and render it. Transformation transformation; Matrix3F rotate(Vector3F(0.2F, 0.7F, 0.1F), MathF::FMod(static_cast<Float>(System::GetTime()), MathF::TWO_PI)); transformation.SetRotate(rotate); GetRenderer()->ClearBuffers(); GetRenderer()->PreDraw(mspCamera); GetRenderer()->Draw(mspCube, transformation); GetRenderer()->PostDraw(); GetRenderer()->DisplayBackBuffer(); }
//---------------------------------------------------------------------------- Int main(Int argc, Char** argv) { Main::Initialize(); PdrRendererInput input; const Bool useVSync = true; // window width/height and windowed mode not supported on the Wii Renderer* pRenderer = WIRE_NEW Renderer(input, 0, 0, true, useVSync); // Renderer must be created before calling PADInit PADInit(); RenderObjectPtr spCube = StandardMesh::CreateCube8(/* RGB(A) channels */ 4); Vector3F cameraLocation(0.0F, 0.0F, 10.0F); Vector3F viewDirection(0.0F, 0.0F, -1.0F); Vector3F up(0.0F, 1.0F, 0.0F); CameraPtr spCamera = WIRE_NEW Camera(cameraLocation, viewDirection, up); do { Transformation transformation; Matrix34F rotate(Vector3F(0.2F, 0.7F, 0.1F), MathF::FMod( static_cast<Float>(System::GetTime()), MathF::TWO_PI)); transformation.SetRotate(rotate); pRenderer->ClearBuffers(); pRenderer->PreDraw(spCamera); pRenderer->Draw(spCube, transformation); pRenderer->PostDraw(); pRenderer->DisplayBackBuffer(); WPAD_ScanPads(); } while (!(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)); // dereference (i.e. destroy) before destroying the renderer spCamera = NULL; spCube = NULL; WIRE_DELETE pRenderer; Main::Terminate(); return 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(); }