class Ast3DFract: public Ast

This class represent a asteroid with a 3D random fractal shape

Inheritance:


Public Fields

[more]Mesh M
The mesh representing the asteroid shape
[more]GLuint SharedTexture
Used to share an unique texture among all the asteroids

Public Methods

[more] Ast3DFract(char *filename="data/tetra.raw", float _size=5, int recur=1, int seed=-1)
Default constructor
[more] Ast3DFract(Mesh &mm, float _size=5, int recur=1, int seed=-1)
New constructor to avoid multiple loading of the same mesh
[more]int Draw()
Draw the asteroid shape
[more]void Split(int seed, float strenght=1)
This function split each triangle of the mesh into four smaller triangles
[more]Point3f MidPoint( Point3f &p0, Point3f &p1, Point3f const &BC, int seed, float strengh)
This function calculates a point on an edge that is slightly perturbed form its original midpoint position
[more]void Explode(list<Ast *> &AL, list<GameObj *> &OL)
Make the asteroid explode
[more]void GenerateSub(Mesh &AstM)
Generate in a preprocessing step all the sub asteroids
[more]int Points()
Points
[more]void SetSharedTexture(char *filename)
Load for a png file the shared texture

Inherited from Ast:

Public Fields

ofloat size
oint strenght
o Sub

Public

LargeSize=12, MediumSize=6, SmallSize=3


Inherited from GameObj:

Public Fields

oPoint3f p
oPoint3f axis
ofloat angle
oPoint3f v
ofloat av
obool active
oSphere3f B

Public Methods

ovoid Update(int t)
oPoint3f VDir()
obool Collide(GameObj *o)
ovoid DrawBound()
obool operator < ( GameObj const & o ) const
obool operator == ( GameObj const & o ) const

Documentation

This class represent a asteroid with a 3D random fractal shape. The fractal shape is stored in a mesh and it is generated, starting from a loaded base mesh (i.e. ast.raw or tetra.raw) and by recursively subdividing each face into four smaller faces. Version History
  • 0.4s Added the Explode and GenerateSub
  • 0.5s Added texture mapping. It involved the creation of a static variable SharedTexture and a static function SetSharedTexture to use a common texture among all the asteroids. For a similar reason we have added a constructor that starts from a given mesh instead of a file. Modified also the GenerateSub() in order to start the fractal generation from a previously loaded mesh.

oMesh M
The mesh representing the asteroid shape.

o Ast3DFract(char *filename="data/tetra.raw", float _size=5, int recur=1, int seed=-1)
Default constructor. It load a mesh from a file (default is tetra.raw, a simple tetrahedron), resize it into a unitary box and Split each face three times (e.g. the resulting mesh has 64x faces). At the end it calculates smooth per-vertex normal Version History
  • 0.4 Number of split depend on ast size.
  • 0.4s Added configurable recursion level and seed.

o Ast3DFract(Mesh &mm, float _size=5, int recur=1, int seed=-1)
New constructor to avoid multiple loading of the same mesh.

oint Draw()
Draw the asteroid shape. Simply draw the stored mesh. Version History
  • 0.4 Now it uses display lists.

ovoid Split(int seed, float strenght=1)
This function split each triangle of the mesh into four smaller triangles. When splitting a triangle we geneate three new vertices (one for each edge) whose coordinates are calculated by MidPoint depending on the coordinates of the two vertices of the triangle edge where the new midpoint lies. The two params are passed directly to the MidPoint function and influence how the new point is calculated.

oPoint3f MidPoint( Point3f &p0, Point3f &p1, Point3f const &BC, int seed, float strengh)
This function calculates a point on an edge that is slightly perturbed form its original midpoint position. It is important that the pertubation is not really random but it depends on the coords of the two edge vertexes. In this way we generate twice the same midpoint when splitting the same edge on two adjacent triangles.
Parameters:
p0_p1 - the two points of the edge. We use an hash function to get a random seed for each vertex.
BC - the BariCenter of the Asteroids; the perturbation is along the line from bc to the middlepoint
seed - a random seed to avoid to calculate always the same asteroid when starting from the same triangles...
stenght - the {strenght} of the perturbation when strenght == 0 the shape tends to a sphere, good values are in the [.2,2] range.

ovoid Explode(list<Ast *> &AL, list<GameObj *> &OL)
Make the asteroid explode. The two list passed are filled with the sub asteroids, the explosions and the fragments. The sub asteroids are the one generate in preproc. by the GenerateSub() function.

ovoid GenerateSub(Mesh &AstM)
Generate in a preprocessing step all the sub asteroids. It is called by the GameSessions::Init(). Modified in version 0.5s to include a mesh as parameter

oint Points()
Points. Small 50pt, medium 25 large 10pt.

oGLuint SharedTexture
Used to share an unique texture among all the asteroids. It is set by SetSharedTexture once, and used by calling Mesh::SetTexture(SharedTexture) instead of a filename.

ovoid SetSharedTexture(char *filename)
Load for a png file the shared texture.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.