码迷,mamicode.com
首页 > 其他好文 > 详细

WildMagic 简单图元(一)

时间:2014-06-05 12:52:51      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
#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();
}
bubuko.com,布布扣

 

WildMagic 简单图元(一),布布扣,bubuko.com

WildMagic 简单图元(一)

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/nmgxbc/p/3766340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!