Frz::Scene Class Reference

Base class for animated 3D scenes. More...

#include <frz_scene.hpp>

Collaboration diagram for Frz::Scene:
Collaboration graph
[legend]

List of all members.

Classes

struct  Triangle
 Container class for 3D triangle or quad polygon data. More...
struct  vvertex
 A vertex to Object3d::Vertex wrapper class.

Public Member Functions

 Scene ()
 Constructor.
virtual ~Scene ()
 Destructor.

Protected Member Functions

void flash ()
 Triggers a flash effect.
void setBackgroundColor (uint32_t c)
 Sets the background color.
void setFade (uint32_t c, float s)
 Configures the fade effect.
int add_triangle (uint16_t _sh_type, uint16_t _rot_id, uint16_t _tex_id, uint32_t _color, const vertex &_a, const vertex &_b, const vertex &_c)
 Adds a triangle.
int add_quad (uint16_t _sh_type, uint16_t _rot_id, uint16_t _tex_id, uint32_t _color, const vertex &_a, const vertex &_b, const vertex &_c, const vertex &_d)
 Adds a quad.
int add_object (const Object3d &obj, uint16_t type=SH_SMOOTH, float zoom=1.0f, uint16_t tex_id=-1)
 Adds a 3D object.
int add_object_extrude (const Object3d &obj, uint16_t th, float zoom=1.0f)
 Adds a 3D object with polygon extrusion.
int add_object ()
 Allocates a rotation matrix identifier for a new object.
TrianglegetTriangles ()
 Returns a reference to the internal polygon array.
int getTriangleCount ()
 Returns the number of elements in the internal polygon array.
int getObjectCount ()
 Returns the number of objects (rotation matrices).
virtual void setupFrame (uint32_t time, trans t[])=0
 Sets up a scene frame.

Friends

class Script

Detailed Description

Base class for animated 3D scenes.

This is the base class for programming an animated 3D scene.

The Scene class basically embeds an array of 3D polygons (triangles or quads), organized to make up a complete scene. Each polygon is space-located according to its vertices, whose coordinates are modified by a rotation/translation matrix. One can consider all polygons sharing the same rotation/translation matrix to form a 3D object, since they are “tied” together.
Design your own scene
A Scene-derived class must populate the polygon array in its constructor. Then, the animation system will call the setupFrame method of your derived class before each time new frame is rendered. In this method, you have to set the proper values to generate the rotation/translation matrices, you can also change the screen background color, and play with the fade and flash effects.
The following example is taken from the cube.cpp example program file in the examples directory of the Freezer source archive.
// An example scene with a rotating cube
class ScnCube : public Frz::Scene {
public:
  ScnCube() {
    int16_t r = 100;
    Frz::Object3d obj;
    // The eight vertices for the cube
    obj.addVertex(-r, -r, -r);  // vertex 0
    obj.addVertex( r, -r, -r);  // vertex 1
    obj.addVertex(-r,  r, -r);  // vertex 2
    obj.addVertex( r,  r, -r);  // vertex 3
    obj.addVertex(-r, -r,  r);  // vertex 4
    obj.addVertex( r, -r,  r);  // vertex 5
    obj.addVertex(-r,  r,  r);  // vertex 6
    obj.addVertex( r,  r,  r);  // vertex 7
    // The six faces defined according to the vertices above
    obj.addPoly(6, 7, 5, 4, 0x00f0f0);
    obj.addPoly(0, 1, 3, 2, 0xf000f0);
    obj.addPoly(2, 6, 4, 0, 0xf0f000);
    obj.addPoly(1, 5, 7, 3, 0xf00000);
    obj.addPoly(2, 3, 7, 6, 0x00f000);
    obj.addPoly(0, 4, 5, 1, 0x0000f0);

    add_object(obj);  // Adds the cube object into the scene. Its
                      // rotating/translation matrix identifier is zero as it
                      // is the first object inserted.
  }

  // This method is called before rendering a new frame
  virtual void setupFrame(uint32_t time, Frz::trans transforms[]) {
    transforms[0].a = time * 0.001f;  // Rotation angle according to the x axis
    transforms[0].b = time * 0.001f;  // Rotation angle according to the y axis
    transforms[0].c = time * 0.001f;  // Rotation angle according to the z axis
    transforms[0].x = 0.0f;           // Translation according to the x axis
    transforms[0].y = 0.0f;           // Translation according to the y axis
    transforms[0].z = -400.0f;        // Translation according to the z axis
  }
};

Member Function Documentation

int Frz::Scene::add_object (  )  [protected]

Allocates a rotation matrix identifier for a new object.

This method is useful when adding polygons directly into the scene, using add_triangle and add_quad, which require a valid rotation matrix identifier.

Returns:
the rotation matrix identifier
int Frz::Scene::add_object ( const Object3d obj,
uint16_t  type = SH_SMOOTH,
float  zoom = 1.0f,
uint16_t  tex_id = -1 
) [protected]

Adds a 3D object.

The method inserts all the polygons of the Object3d object into the scene.

To each added object is assigned a new rotation matrix identifier, which is the identifier of the previously allocated matrix identifier plus one. The first identifier is zero.

The normal vectors of each of the object's polygons are computed according to the shading type.

Parameters:
obj the 3D object to be added
type shading type (cf. frz_defs.h)
zoom zoom value
tex_id texture identifier (unused yet)
Returns:
the rotation matrix identifier
int Frz::Scene::add_object_extrude ( const Object3d obj,
uint16_t  th,
float  zoom = 1.0f 
) [protected]

Adds a 3D object with polygon extrusion.

Same operation as add_object, except every polygon in the object is extruded (see Triangle::setThickness).

The shading type is flat, and the normal vectors are computed automatically.

Parameters:
obj the 3D object to be added
th thickness value
zoom zoom value
Returns:
the rotation matrix identifier
int Frz::Scene::add_quad ( uint16_t  _sh_type,
uint16_t  _rot_id,
uint16_t  _tex_id,
uint32_t  _color,
const vertex _a,
const vertex _b,
const vertex _c,
const vertex _d 
) [protected]

Adds a quad.

Parameters:
_sh_type shading type (cf. frz_defs.h)
_rot_id rotation matrix number
_tex_id texture number (unused yet)
_color color (ARGB binary format)
_a first vertex
_b second vertex
_c third vertex
_d fourth vertex
Returns:
polygon index in internal array
int Frz::Scene::add_triangle ( uint16_t  _sh_type,
uint16_t  _rot_id,
uint16_t  _tex_id,
uint32_t  _color,
const vertex _a,
const vertex _b,
const vertex _c 
) [protected]

Adds a triangle.

Parameters:
_sh_type shading type (cf. frz_defs.h)
_rot_id rotation matrix number
_tex_id texture number (unused yet)
_color color (ARGB binary format)
_a first vertex
_b second vertex
_c third vertex
Returns:
polygon index in internal array
void Frz::Scene::flash (  )  [inline, protected]

Triggers a flash effect.

The flash effect renders the next frame to uniform white, then the subsequent frames quickly fade back to normal.

int Frz::Scene::getObjectCount (  )  [inline, protected]

Returns the number of objects (rotation matrices).

Returns:
the number of objects (rotation matrices)
int Frz::Scene::getTriangleCount (  )  [inline, protected]

Returns the number of elements in the internal polygon array.

Returns:
the number of elements in the internal polygon array.
Triangle* Frz::Scene::getTriangles (  )  [inline, protected]

Returns a reference to the internal polygon array.

Returns:
a reference to the internal polygon array
void Frz::Scene::setBackgroundColor ( uint32_t  c  )  [inline, protected]

Sets the background color.

Parameters:
c the new background color (in ARGB binary format)
void Frz::Scene::setFade ( uint32_t  c,
float  s 
) [inline, protected]

Configures the fade effect.

The fade effect consists, for each pixel in the generated picture, in a linear interpolation of the fade color and the pixel. If the fade strength is 0, the pixels are not modified. If it is 1, the full picture is filled by the fade color.

Parameters:
c the fade color (in ARGB binary format)
s the fade strength, between 0 (inactive) and 1 (full)
virtual void Frz::Scene::setupFrame ( uint32_t  time,
trans  t[] 
) [protected, pure virtual]

Sets up a scene frame.

This method is called by the animation system before drawing a new frame. It is responsible for setting the correct animation values (rotation and translation of every object in the scene, plus other effects), according to the current animation time.

Parameters:
time the animation time in milliseconds
t a set of rotation/translation structures to be populated

The documentation for this class was generated from the following file:
 All Classes Functions Variables Friends
Generated on Thu Jun 10 17:37:47 2010 for freezer-0.1.0 by  doxygen 1.6.3