QSDK 1.1 Documentation
Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

ptut02.cpp File Reference

Go to the source code of this file.

Compounds

struct  Listener

Functions

int main (int argc, char *argv[])


Detailed Description

Definition in file ptut02.cpp.


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 255 of file ptut02.cpp.

References Mesh::addBox(), Layer::addListener(), Application::app(), Scope::create(), CameraLayer::create(), Mesh::create(), Instance::create(), Light::create(), Camera::create(), Group::create(), Zone::create(), Screen::create(), Shader::defaultShader(), Zone::root(), Screen::setKeyboardFocus(), Group::setOrientation(), Group::setPosition(), and Vec3f.

00256 {
00257     // initialise the application
00258     Q::Application::app().init(argc, argv);
00259 
00260     // Create the 3D screen. This will create its own containing window.
00261     bool fullScreen = false;
00262     Maths::Vec2f extent(640, 480);
00263     Q::Screen screen = Q::Screen::create("ptut02", 0, 0, extent, extent,
00264                                          16, fullScreen);
00265 
00266     /*
00267      * Create the scene to be rendered. This consists of:
00268      * (a) a Zone to hold the geometry
00269      * (b) a Camera to view the scene
00270      * (c) a Light on the Camera to illuminate the scene
00271      * (d) a cube-shaped mesh in front of the camera and rotated around its
00272      *     vertical axis.
00273      */
00274 
00275     // (a) create the Zone
00276     Q::Zone z = Q::Zone::create(0);
00277     
00278     // (b) create the Camera. The Group gives it position and orientation
00279     Q::Group cameraGrp = Q::Group::create(0, z.root());
00280     Q::Camera camera = Q::Camera::create(0, cameraGrp);
00281 
00282     // (c) create an Instance of a Light. It is attached to the Camera.
00283     Q::Light light = Q::Light::create(0);
00284     Q::Instance::create(0, light, cameraGrp);
00285     
00286     // (d) create a Mesh asset with a cube-shape.
00287     Q::Mesh cube = Q::Mesh::create(0);
00288     cube.addBox(Maths::Box3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f),
00289                 Q::Shader::defaultShader());
00290     Q::Group cubeGrp = Q::Group::create(0, z.root());
00291     Q::Instance::create(0, cube, cubeGrp);
00292 
00293     // move the cube 5 metres in front of the camera.
00294     cubeGrp.setPosition(z.root(), Maths::Vec3f(0, 0, 5.0f));
00295 
00296     // rotate the cube by 45 degrees about its vertical axis.
00297     cubeGrp.setOrientation(z.root(), 
00298                            Maths::Quat4f(Maths::Vec3f(0, 1, 0), 
00299                                          Maths::PI/180.0f*45.0f));
00300     
00301     /*
00302      * Add a Layer to the Screen to display the scene as viewed through
00303      * the Camera.
00304      */
00305     Q::CameraLayer camLayer = Q::CameraLayer::create(screen,
00306                                                      camera,
00307                                                      Maths::Vec2f(0, 0),
00308                                                      extent,
00309                                                      Maths::Vec2f(0, 0));
00310     
00311     /*
00312      * Add a scope to the camera to indicate that Q should load the data
00313      * in scope.
00314      */
00315     Q::Scope scope = Q::Scope::create(cameraGrp);
00316 
00317     // Listen for keyboard and application events.
00318     Listener listener(cubeGrp, light);
00319     Q::Application::app().addListener(listener);
00320     camLayer.addListener((Q::KeyboardListener&)listener);
00321     screen.setKeyboardFocus(camLayer);
00322 
00323     // Start the message loop processing
00324     Q::Application::app().start();
00325 
00326     return 0;
00327 }

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004