首页 > 代码库 > WildMagic 简单图元(一)
WildMagic 简单图元(一)
#include <Wm5WindowApplication3.h> #include <Wm5VisualEffectInstance.h> using namespace Wm5; class MyFrame : public WindowApplication3 { WM5_DECLARE_INITIALIZE; WM5_DECLARE_TERMINATE; public: MyFrame(); virtual bool OnInitialize(); virtual void OnTerminate(); virtual void OnIdle(); private: NodePtr mScene; Culler mCuller; }; WM5_REGISTER_INITIALIZE(MyFrame); WM5_REGISTER_TERMINATE(MyFrame); WM5_WINDOW_APPLICATION(MyFrame) MyFrame::MyFrame() :WindowApplication3("Ocean", 0, 0, 1024, 800, Float4(0.0, 0.0, 1.0, 1.0)) { } bool MyFrame::OnInitialize() { if (!WindowApplication3::OnInitialize()) { return false; } mCamera->SetFrustum(60.0f, GetAspectRatio(), 0.1f, 1000.0f); APoint camPosition(16.0f, 0.0f, 0.0f); AVector camDVector(-1.0f, 0.0f, 0.0f); AVector camUVector(0.0f, 0.0f, 1.0f); AVector camRVector = camDVector.Cross(camUVector); mCamera->SetFrame(camPosition, camDVector, camUVector, camRVector); mScene = new0 Node; VertexFormat * vFormat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); TriMesh * mesh = StandardMesh(vFormat).Rectangle(32, 32, 16.0f, 16.0f); VisualEffectInstance * instance = VertexColor3Effect::CreateUniqueInstance(); mesh->SetEffectInstance(instance); mScene->AttachChild(mesh); mScene->Update(); mCuller.SetCamera(mCamera); mCuller.ComputeVisibleSet(mScene); InitializeCameraMotion(0.01f, 0.001f); InitializeObjectMotion(mScene); return true; } void MyFrame::OnTerminate() { WindowApplication3::OnTerminate(); } void MyFrame::OnIdle() { MeasureTime(); if (MoveCamera()) { mCuller.ComputeVisibleSet(mScene); } if (MoveObject()) { mScene->Update(); mCuller.ComputeVisibleSet(mScene); } if (mRenderer->PreDraw()) { mRenderer->ClearBuffers(); mRenderer->Draw(mCuller.GetVisibleSet()); DrawFrameRate(8, GetHeight() - 8, Float4(0.0, 1.0, 0.0, 1.0)); mRenderer->PostDraw(); mRenderer->DisplayColorBuffer(); } UpdateFrameCount(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。