1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
Class SpatialView : public QGLWidget
{
Q_OBJECT
public:
SpatialView(QWidget* pParent = NULL);
~SpatialView();
private:
// OpenGL callbacks
void paintGL();
void resizeGL(int pWidth, int pHeight);
void initializeGL();
// Creation of the renderer
void createRenderer();
// Creation of the scene
void createScene();
// Camera
Wm4::CameraPtr mCamera;
// OpenGL Renderer
Renderer* mRenderer;
// The scene node
Wm4::NodePtr mScene;
// The culler
Wm4::Culler mCuller;
};
SpatialView::SpatialView(QWidget *pParent)
: QGLWidget(pParent),
mRenderer(NULL)
{
mCamera = WM4_NEW Camera();
setAutoBufferSwap(false);
}
SpatialView::~SpatialView()
{
if (mRenderer != NULL)
{
delete mRenderer;
}
}
void SpatialView::paintGL()
{
mRenderer->ClearBuffers();
if ( mRenderer->BeginScene() )
{
mRenderer->DrawScene( mCuller.GetVisibleSet() );
mRenderer->Draw(8,16,ColorRGBA::WHITE,"YOUPLA");
mRenderer->EndScene();
}
mRenderer->DisplayBackBuffer();
}
void SpatialView::resizeGL(int pWidth, int pHeight)
{
mRenderer->Resize(pWidth, pHeight);
//mCamera->SetFrustum( -10, 10, -10, 10, 0.001f, 1000.f);
mCamera->SetFrustum(60.f, 4.f/3.f, 0.1f, 1000.f);
mCamera->SetLocation( mCamera->GetLocation() );
mCuller.ComputeVisibleSet(mScene);
}
void SpatialView::initializeGL()
{
createRenderer();
createScene();
mCuller.SetCamera( mCamera );
mCuller.ComputeVisibleSet(mScene);
}
void SpatialView::createRenderer()
{
if (mRenderer != NULL)
{
delete mRenderer;
}
mRenderer = new As::Renderer(this);
mRenderer->SetClearColor(ColorRGBA(0.7f, 0.7f, 0.7f, 1.0f));
mRenderer->SetCamera(mCamera);
}
void SpatialView::createScene()
{
mScene = WM4_NEW Node();
Attributes lAttributes;
lAttributes.SetNormalChannels(3);
lAttributes.SetPositionChannels(3);
StandardMesh lMeshCreator(lAttributes);
TriMesh* lMesh = lMeshCreator.Sphere(20, 20, 1.f);
MaterialStatePtr lMaterial = WM4_NEW MaterialState();
lMaterial->Emissive = ColorRGB(0.0f,0.0f,0.0f);
lMaterial->Diffuse = ColorRGB( 1.f, 0.f, 0.f);
lMaterial->Ambient = lMaterial->Diffuse*0.1f;
lMaterial->Specular = ColorRGB(0.8f,0.8f,0.8f);
lMaterial->Shininess = 40.0f;
lMesh->AttachGlobalState(lMaterial);
lMesh->AttachEffect( WM4_NEW DefaultShaderEffect );
lMesh->Local.SetTranslate( Vector3f(0.f, 0.f, -10.f) );
mScene->AttachChild(lMesh);
mScene->UpdateGS();
mScene->UpdateRS();
} |
Partager