Many small pedagogical examples illustrate some functionalities of the viewer and are provided
for understanding and cut and paste. Click on the image to see the code of the example.
 |
3dsViewer
The LGPL lib3ds library is used to load and display a 3ds scene
You need to install the lib3ds library in order to compile this file.
See http://lib3ds.sourceforge.net/.
The current version (Dec 2002) is flawed and a patched version is available on the libQGLViewer rpm page.
Once this is done, edit 3dsViewer.pro and set INCLUDEPATH and LIBS to the
path where you installed lib3ds.
Simply press 'L' (load) to load a new 3DS scene.
|
|
animation
The animate() function used on a water particle simulation.
When animation is activated (the Return key toggles animation), the animate() and
then the draw() functions are called in an infinite loop.
You can tune the frequency of your animation (default is 25Hz) using
setAnimationInterval() . The frame rate will then be fixed, provided that your
animation loop function is fast enough.
|
 |
|
 |
callback
Using the QT callback signal-slot to connect a QGLViewer and your scene.
This very simple application uses the QT callback signal-slot mechanism to link the QGLViewer and
your Scene. The drawNeeded() QGLViewer signal is connected to the Scene
drawScene() slot.
|
|
constrainedCamera
Constraints applied on the Camera Frame to limit its translation and/or rotation.
Try the different possible constraints using the T (translate) and R (rotate) keys. G and D change
the constraint directions. Press Space to change the coordinate system (World or Camera) which
defines the constraint directions.
Note that in order to apply a constraint to a camera, you need to apply it to the camera.frame
(for the translation part), and to the camera.frame.referenceFrame() (for the rotationnal part).
This is due to the frame hierarchy which defines the camera position (see the Frame explanation
page). You can also choose to use two different constraints, one for camera.frame and one for
camera.frame.referenceFrame, but this is useless.
|
 |
|
 |
constrainedFrame
Constraints can limit the translation and/or rotation of a (Manipulated)Frame.
Try the different possible constraints using the T (translate) and R (rotate) keys. G and D change
the constraint directions. Press Space to change the coordinate system (World, Camera or Local)
which defines the constraint directions.
Press the Alt key while moving the mouse to move the camera.
|
|
draw3DText
An icosahedron is used to illustrate the draw3DText() function.
Use this function to draw text as if it was a normal object of your 3D scene.
|
 |
|
 |
drawLight
The drawLight() function is a light debugging tool.
drawLight() takes as an argument the GL index of the lamp : GL_LIGHT0, GL_LIGHT1... and displays a
symbolic representation of the light. This function is usefull for debugging your light setup.
|
|
fastDraw
The fastDraw() function keeps interactivity even with large scenes.
This example demonstrates the use of the fastDraw() function, which
is called when the camera moves. This function is usefull for displaying very
complex scene, while keeping an interactive camera motion.
|
 |
|
 |
frameTransform
Coordinate transformation between different Frames.
This example illustrates the camera and world coordinate systems
relationship. The position of the camera in the world coordinate
system is printed from Camera::position(). Symetrically, the
position of the world origin is given in the camera coordinate
system by camera.cameraCoordinatesOf(0,0,0).
Three sets of lines (red, green, blue) are drawned. They have different starting points, but
common end points, located on a circle in the XY plane.
All the red lines start from the camera position, and will hence always be aligned with the
viewing direction, making them invisible.
The green lines starting points' positions are determined from the camera coordinate system, using
camera.worldCoordinatesOf(). As a result, these points will seem to be fixed in the screen,
even when the camera is moved
Finally, the blue lines are classically defined in the world coordinate system, and will move with
the camera.
Beautiful Moire pattern can be obtained with a proper rotation.
|
|
interface
Adding a graphical user interface around a QGLViewer.
The same example as simpleViewer with an interface designed with designer. The interface.ui file
is the description of the interface resulting of designer. The interface.cw file is the
description of the signals and slots available. Here we use three slots and three signals to
connect to and from the interface and the viewer.
The designer cw files (custom widget), describing all the available
signals and slots of the libQGLViewer classes are available in the
|
 |
|
 |
keyFrames
The KeyFrameInterpolator test example.
KeyFrameInterpolator smoothly interpolate their attached Frame over time on a path defined by Frames.
The interpolation can be started/stopped/reset, played in loop, played at a different speed,
etc...
In this examples, the path is defined by four ManipulatedFrame which all can be
moved with the mouse. The interpolating path is updated accordingly.
The path and the interpolating axis are drawn using KeyFrameInterpoar::drawPath()
By default, the QGLViewer Camera holds 12 KeyFrameInterpolator, binded to the F1-12 keys. Use
Alt-Fx to define a new keyFrame for path x, and simply press Fx to play/pause the path x. See the
shortcuts page for details.
|
|
luxo
A more complex exemple that combines manipulatedFrames, selection and constraints.
This exemple illustrates different functions of the viewer. It displays a famous luxoŽ lamp
(ŠPixar) that can be interactively manipulated with the mouse. It illustrates the use of several
ManipulatedFrames in the same scene.
Shift click on any part of the lamp to select it, and then move it with the mouse. To move the
camera select the background or press the Alt key (default modifier keys are switched).
A simpler object selection example is given in select .
A simpler frame displacement example is given in manipulatedFrame .
A simpler constrained frame example is given in constrainedFrame .
|
 |
|
 |
manipulatedFrame
A ManipulatedFrame can be moved with the mouse in the scene.
This example illustrates the mouse driven displacement of a frame in
the scene. The frame is moved by pressing the Alt key while using the
mouse (the key can be changed through the constant FRAME_MOUSE_MOVE_STATE_KEY).
The frame is drawned at its position using a glMultMatrix of the frame associated
matrix. This matrix will be changed when the mouse moves, thus changing the position
of the frame.
We use a glPushMatrix and glPopMatrix to save and restore the model view
matrix. It is not needed here as nothing is drawn after the frame, but it
is a good habbit for the general cases.
|
|
screenCoordSystem
A saucers control viewer that illustrates the screen coordinate system feature.
Use startScreenCoordinatesSystem() and stopScreenCoordinatesSystem() to
set this mode. Once this mode has been activated in draw() , the X,Y coordinates
correspond to the pixel units (origin in the lower left corner). Combined with the
camera.projectedCoordinatesOf() , this feature enable the mix of 2D and 3D drawing. The
arrows that designate the saucers then seem to be attached to the object.
|
 |
|
 |
select
Selection of objects of the scene using select() and an OpenGL GL_SELECT render mode.
Use the select() callback function to implement your object selection function. This
examples is based on a generic GL_SELECT implementation that can easily be cut and pasted in your
applications.
Analytic intersection computations are also possible once the screen coordinates have be converted
to a half line using convertClickToLine(). Make a selection and then move the camera to see a
representation of the intersection line.
|
|
simpleViewer
The simplest application example: 20 lines of code and yet all the power !
A Viewer class is derived from QGLViewer and its draw() function is overloaded to
specify the user defined OpenGL orders that describe the scene.
This is the first example you should try, as it explains some of the default keyboard shortcuts
and the mouse behavior of the viewer.
This example can be cut and pasted to start the development of a new application.
|
 |
|
 |
spinningFrame
Frame spinning capabilities using a QTimer
Note : this example is deprecated. Use the spinningFrame class (to come) instead. You should be
able to set the frame rotation axis and speed over time with this class.
|
|
stereoViewer
Simply press S to toggle stereo display (architecture dependent)
This is a simple stereo application inspired from simpleviewer. The constructor is called with a
QFormat stereo option to enable stereo. Press 'S' to toggle stereo display.
|
 |
|
 |
textureViewer
Loads image files and textures map polygons with it.
Pedagogical example that shows how to apply a texture on a 3D object.
Inpired from the QT texture example.
The Qt QImage class and its convertToGLFormat() function are used
to load any image format. The image is resized so that its dimensions are powers
of two if needed. Feel free to cut and paste.
|
|
triSetConstraint
A TriangleSetConstraint constrains the camera displacement.
The camera is constrained to stay above a given 'road' defined
by triangles. Camera is in FLY mode.
The example is a little bit complex : the computations needed
to get the intersection of the Z-direction and the triangle are
cut and pasted from the triangleSetConstraint class, in order to
draw interesting debugging informations.
|
 |
|