Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

csThing Class Reference

A Thing is a set of polygons. More...

#include <thing.h>

Inheritance diagram for csThing:

csObject iObject iBase List of all members.

Public Methods

 csThing (iBase *parent)
 Create an empty thing.

virtual ~csThing ()
 Destructor.

int AddVertex (const csVector3 &v)
 Just add a new vertex to the thing.

int AddVertex (float x, float y, float z)
 Just add a new vertex to the thing.

int AddVertexSmart (const csVector3 &v)
 Add a vertex but first check if there is already a vertex close to the wanted position. More...

int AddVertexSmart (float x, float y, float z)
 Add a vertex but first check if there is already a vertex close to the wanted position. More...

void CompressVertices ()
 Compress the vertex table so that all nearly identical vertices are compressed. More...

void RemoveUnusedVertices ()
 Optimize the vertex table so that all unused vertices are deleted. More...

const csVector3Vobj (int idx) const
 Return the object space vector for the vertex.

const csVector3Vwor (int idx) const
 Return the world space vector for the vertex. More...

const csVector3Vcam (int idx) const
 Return the camera space vector for the vertex. More...

int GetVertexCount () const
 Return the number of vertices.

void SetVertex (int idx, const csVector3 &vt)
 Change a vertex.

void DeleteVertex (int idx)
 Delete a vertex.

void DeleteVertices (int from, int to)
 Delete a range of vertices.

void AddPolygon (csPolygonInt *spoly)
 Add a polygon to this thing.

csPolygon3DNewPolygon (csMaterialWrapper *material)
 Create a new polygon in this thing and add it.

int GetPolygonCount ()
 Get the number of polygons in this thing.

csPolygonIntGetPolygonInt (int idx)
 Get a csPolygonInt with the index.

csPolygon3DGetPolygon3D (int idx)
 Get the specified polygon from this set.

csPolygon3DGetPolygon3D (const char *name)
 Get the named polygon from this set.

csPolygonArrayGetPolygonArray ()
 Get the entire array of polygons.

unsigned long GetNewPolygonID ()
 Get a new polygon ID. More...

int FindPolygonIndex (iPolygon3D *polygon) const
 Find a polygon index.

void RemovePolygon (int idx)
 Remove a single polygon.

void RemovePolygons ()
 Remove all polygons.

void AddCurve (csCurve *curve)
 Add a curve to this thing.

int GetCurveCount () const
 Get the number of curves in this thing.

csCurveGetCurve (int idx) const
 Get the specified curve from this set.

iCurveCreateCurve (iCurveTemplate *tmpl)
 Create a curve from a template.

int FindCurveIndex (iCurve *curve) const
 Find a curve index.

void RemoveCurve (int idx)
 Delete a curve given an index.

void RemoveCurves ()
 Delete all curves.

csCurveGetCurve (char *name) const
 Get the named curve from this set.

int GetCurveVertexCount () const
 Get the number of curve vertices.

csVector3GetCurveVertex (int i) const
 Get the specified curve vertex.

csVector3GetCurveVertices () const
 Get the curve vertices.

csVector2GetCurveTexel (int i) const
 Get the specified curve texture coordinate (texel).

void SetCurveVertex (int idx, const csVector3 &vt)
 Get the specified curve coordinate.

void SetCurveTexel (int idx, const csVector2 &vt)
 Set the specified curve texture coordinate (texel).

void ClearCurveVertices ()
 Clear the curve vertices.

int AddCurveVertex (const csVector3 &v, const csVector2 &t)
 Add a curve vertex and return the index of the vertex.

float GetCurvesScale () const
 Get the curve scale.

void SetCurvesScale (float f)
 Set the curve scale.

const csVector3GetCurvesCenter () const
 Get the curves center.

void SetCurvesCenter (csVector3 &v)
 Set the curves center.

void Prepare ()
 Prepare all polygons for use. More...

void Merge (csThing *other)
 Merge the given Thing into this one. More...

void MergeTemplate (iThingState *tpl, iMaterialWrapper *default_material=NULL, csVector3 *shift=NULL, csMatrix3 *transform=NULL)
 Add polygons and vertices from the specified thing (seen as template).

void ReplaceMaterials (iMaterialList *matList, const char *prefix)
 Replace the materials in this thing with new materials that are prefixed by some name. More...

void SetTemplate (csThing *t)
 Set parent template.

csThing* GetTemplate () const
 Query parent template.

void CreateBoundingBox ()
 Create an oriented bounding box (currently not oriented yet@@) for this polygon set. More...

csThingBBoxGetBoundingBox ()
 Get the oriented bounding box created by CreateBoundingBox().

void GetTransformedBoundingBox (const csReversibleTransform &trans, csBox3 &cbox)
 Get bounding box given some transformation.

float GetScreenBoundingBox (float fov, float sx, float sy, const csReversibleTransform &trans, csBox2 &sbox, csBox3 &cbox)
 Get bounding box in screen space.

void GetBoundingBox (csBox3 &box)
 Get the bounding box in object space for this polygon set. More...

void GetBoundingBox (iMovable *movable, csBox3 &box)
 Get the bounding box for this object given some transformation (movable).

void GetRadius (csVector3 &rad, csVector3 &cent)
 Get the radius in object space for this polygon set.

void AddPortalPolygon (csPolygon3D *poly)
 Add a polygon to the list of polygons having a portal. More...

void RemovePortalPolygon (csPolygon3D *poly)
 Remove a polygon from the list of polygons having a portal.

csPolygonTreeGetStaticTree ()
 Get the static polygon tree.

void BuildStaticTree (const char *name, int mode=BSP_MINIMIZE_SPLITS)
 Call this function to generate a polygon tree for this csThing. More...

void RegisterVisObject (iVisibilityObject *visobj)
 Register a visibility object with this culler.

void UnregisterVisObject (iVisibilityObject *visobj)
 Unregister a visibility object with this culler.

bool VisTest (iRenderView *irview)
 Do the visibility test from a given viewpoint. More...

void RegisterShadowReceiver (iShadowReceiver *receiver)
 Register a shadow receiver.

void UnregisterShadowReceiver (iShadowReceiver *receiver)
 Unregister a shadow receiver.

void CastShadows (iFrustumView *fview)
 Start casting shadows from a given point in space.

bool DrawTest (iRenderView *rview, iMovable *movable)
 Test if this thing is visible or not.

bool Draw (iRenderView *rview, iMovable *movable, csZBufMode zMode)
 Draw this thing given a view and transformation.

bool DrawCurves (iRenderView *rview, iMovable *movable, csZBufMode zMode)
 Draw all curves in this thing given a view and transformation.

bool DrawFoggy (iRenderView *rview, iMovable *movable)
 Draw this thing as a fog volume (only when fog is enabled for this thing).

void InitializeDefault ()
 Init the lightmaps for all polygons in this thing.

bool ReadFromCache (iCacheManager *cache_mgr, int id)
 Read the lightmaps from the cache.

bool WriteToCache (iCacheManager *cache_mgr, int id)
 Cache the lightmaps for all polygons in this thing.

void PrepareLighting ()
 Prepare the lightmaps for all polys so that they are suitable for the 3D rasterizer.

void SetCacheName (const char *n)
 Set the cache name for this thing.

const char* GetCacheName ()
 Get the cache name.

csPolygon3DIntersectSphere (csVector3 &center, float radius, float *pr=NULL)
 Intersects object-space sphere with polygons of this set. More...

csPolygon3DIntersectSegment (const csVector3 &start, const csVector3 &end, csVector3 &isect, float *pr=NULL, bool only_portals=false)
 Intersect object-space segment with polygons of this set. More...

csPolygon3DIntersectSegmentFull (const csVector3 &start, const csVector3 &end, csVector3 &isect, float *pr=NULL, csMeshWrapper **p_mesh=NULL)
 Intersect object-space segment with polygons of this set. More...

void RealCheckFrustum (iFrustumView *lview, iMovable *movable)
 Check frustum visibility on this thing.

void CheckFrustum (iFrustumView *lview, iMovable *movable)
 Check frustum visibility on this thing. More...

void AppendShadows (iMovable *movable, iShadowBlockList *shadows, csVector3 &origin)
 Return a list of shadow frustums which extend from this thing. More...

void UpdateTransformation (const csTransform &c, long cam_cameranr)
 Transform to the given camera if needed. More...

void WorUpdate ()
 Make sure the world vertices are up-to-date.

void HardTransform (const csReversibleTransform &t)
 Do a hard transform of the object vertices. More...

csVector3GetCameraVertices (const csTransform &c, long cam_cameranr)
 Get the array of camera vertices.

void SetMovingOption (int opt)
 Control how this thing will be moved.

int GetMovingOption () const
 Get the moving option.

void SetConvex (bool c)
 Set convexity flag of this thing. More...

int GetCenter ()
 If this thing is convex you can use getCenter to get the index of the vertex holding the center of this thing. More...

bool HasFog ()
 Return true if this has fog.

csFogGetFog ()
 Return fog structure.

void SetFog (float density, const csColor &color)
 Conveniance function to set fog to some setting.

void DisableFog ()
 Disable fog.

 SCF_DECLARE_IBASE_EXT (csObject)

Public Attributes

csFlags flags
 Set of flags.

int draw_busy
 How many times are we busy drawing this thing (recursive). More...

csThing::ThingState  scfiThingState
csThing::LightingInfo  scfiLightingInfo
csThing::PolyMesh  scfiPolygonMesh
csThing::VisCull  scfiVisibilityCuller
csThing::MeshObject  scfiMeshObject
csThing::MeshObjectFactory  scfiMeshObjectFactory

Static Public Attributes

long current_light_frame_number
 Current light frame number. More...


Friends

class  ThingState
class  LightingInfo
class  PolyMesh
class  VisCull
class  MeshObject
class  MeshObjectFactory

Detailed Description

A Thing is a set of polygons.

A thing can be used for the outside of a sector or else to augment the sector with features that are difficult to describe with convex sectors alone.

Every polygon in the set has a visible and an invisible face; if the vertices of the polygon are ordered clockwise then the polygon is visible. Using this feature it is possible to define two kinds of things: in one kind the polygons are oriented such that they are visible from within the hull. In other words, the polygons form a sort of container or room where the camera can be located. This kind of thing can be used for the outside walls of a sector. In another kind the polygons are oriented such that they are visible from the outside.

Things can also be used for volumetric fog. In that case the Thing must be convex.

If you add a static tree (octree/BSP trees) to a thing it can be used as a visibility culler (i.e. it implements iVisibilityCuller).


Member Function Documentation

void csThing::AddPortalPolygon ( csPolygon3D * poly )
 

Add a polygon to the list of polygons having a portal.

This function is called by a csPolygon3D in this thing whenever it gets a portal.

int csThing::AddVertexSmart ( float x,
float y,
float z )
 

Add a vertex but first check if there is already a vertex close to the wanted position.

In that case don't add a new vertex but return the index of the old one. Note that this function is not very efficient. If you plan to add a lot of vertices you should just use AddVertex() and call CompressVertices() later.

int csThing::AddVertexSmart ( const csVector3 & v ) [inline]
 

Add a vertex but first check if there is already a vertex close to the wanted position.

In that case don't add a new vertex but return the index of the old one. Note that this function is not very efficient. If you plan to add a lot of vertices you should just use AddVertex() and call CompressVertices() later.

void csThing::AppendShadows ( iMovable * movable,
iShadowBlockList * shadows,
csVector3 & origin )
 

Return a list of shadow frustums which extend from this thing.

The origin is the position of the light. Note that this function uses camera space coordinates and thus assumes that this thing is transformed to the origin of the light.

void csThing::BuildStaticTree ( const char * name,
int mode = BSP_MINIMIZE_SPLITS )
 

Call this function to generate a polygon tree for this csThing.

This might make drawing more efficient because this thing can then be drawn using Z-fill instead of Z-buffer. Also the c-buffer requires a tree of this kind.

void csThing::CheckFrustum ( iFrustumView * lview,
iMovable * movable )
 

Check frustum visibility on this thing.

First initialize the 2D culler cube.

void csThing::CompressVertices ( )
 

Compress the vertex table so that all nearly identical vertices are compressed.

The polygons in the set are automatically adapted. This function can be called at any time in the creation of the object and it can be called multiple time but it normally only makes sense to call this function after you have finished adding all polygons and all vertices.

Note that calling this function will make the camera vertex array invalid.

void csThing::CreateBoundingBox ( )
 

Create an oriented bounding box (currently not oriented yet@@) for this polygon set.

This function will add the vertices for the bounding box to the set itself so that they will get translated together with the other vertices. The indices of the vertices are added to the csThingBBox structure which is returned here. Note that this creation is done in object space. The newly added vertices will not have been translated to world/camera space yet.

void csThing::GetBoundingBox ( csBox3 & box )
 

Get the bounding box in object space for this polygon set.

This is calculated based on the oriented bounding box.

int csThing::GetCenter ( ) [inline]
 

If this thing is convex you can use getCenter to get the index of the vertex holding the center of this thing.

This center is calculated by 'setConvex(true)'.

unsigned long csThing::GetNewPolygonID ( ) [inline]
 

Get a new polygon ID.

This is used by the polygon constructor.

void csThing::HardTransform ( const csReversibleTransform & t )
 

Do a hard transform of the object vertices.

This transformation and the original coordinates are not remembered but the object space coordinates are directly computed (world space coordinates are set to the object space coordinates by this routine).

csPolygon3D * csThing::IntersectSegment ( const csVector3 & start,
const csVector3 & end,
csVector3 & isect,
float * pr = NULL,
bool only_portals = false )
 

Intersect object-space segment with polygons of this set.

Return polygon it intersects with (or NULL) and the intersection point in object coordinates.

If 'pr' != NULL it will also return a value between 0 and 1 indicating where on the 'start'-'end' vector the intersection happened.

If only_portals == true then only portals are checked.

csPolygon3D * csThing::IntersectSegmentFull ( const csVector3 & start,
const csVector3 & end,
csVector3 & isect,
float * pr = NULL,
csMeshWrapper ** p_mesh = NULL )
 

Intersect object-space segment with polygons of this set.

Return polygon it intersects with (or NULL) and the intersection point in object coordinates.

If 'pr' != NULL it will also return a value between 0 and 1 indicating where on the 'start'-'end' vector the intersection happened.

This version is similar to IntersectSegment() but it will also test polygons of all objects which are registered to the visibility culler of this thing (if there is any). It also returns the mesh wrapper that was hit. If this is NULL then this mesh was hit.

csPolygon3D * csThing::IntersectSphere ( csVector3 & center,
float radius,
float * pr = NULL )
 

Intersects object-space sphere with polygons of this set.

Return polygon it hits with (or NULL) and the intersection point in object coordinates. It will also return the polygon with the closest hit (the most nearby polygon). If 'pr' != NULL it will also return the distance where the intersection happened.

void csThing::Merge ( csThing * other )
 

Merge the given Thing into this one.

The other polygons and curves are removed from the other thing so that it is ready to be removed. Warning! All Things are merged in world space coordinates and not in object space as one could expect!

void csThing::Prepare ( )
 

Prepare all polygons for use.

This function MUST be called AFTER the texture manager has been prepared. This function is normally called by csEngine::Prepare() so you only need to worry about this function when you add sectors or things later.

void csThing::RemoveUnusedVertices ( )
 

Optimize the vertex table so that all unused vertices are deleted.

Note that calling this function will make the camera vertex array invalid.

void csThing::ReplaceMaterials ( iMaterialList * matList,
const char * prefix )
 

Replace the materials in this thing with new materials that are prefixed by some name.

For example, if a polygon in this thing uses a material 'blabla' and the prefix is 'pref' then the new material that will be used is called 'pref_blabla'. If that material cannot be found then the original material will be used.

void csThing::SetConvex ( bool c )
 

Set convexity flag of this thing.

You should call this instead of SetFlags (CS_ENTITY_CONVEX, CS_ENTITY_CONVEX) because this function does some extra calculations.

void csThing::UpdateTransformation ( const csTransform & c,
long cam_cameranr )
 

Transform to the given camera if needed.

This function will use the camera number to avoid unneeded transformation.

const csVector3 & csThing::Vcam ( int idx ) const [inline]
 

Return the camera space vector for the vertex.

Make sure you recently called UpdateTransformation(). Otherwise it is possible that this coordinate will not be valid.

bool csThing::VisTest ( iRenderView * irview )
 

Do the visibility test from a given viewpoint.

This will first clear the visible flag on all registered objects and then it will mark all visible objects.

const csVector3 & csThing::Vwor ( int idx ) const [inline]
 

Return the world space vector for the vertex.

Make sure you recently called WorUpdate(). Otherwise it is possible that this coordinate will not be valid.


Member Data Documentation

long csThing::current_light_frame_number [static]
 

Current light frame number.

This is used for seeing if gouraud shading should be recalculated for this thing. If there is a mismatch between the frame number of this set and the global number then the gouraud shading is not up-to-date.

int csThing::draw_busy
 

How many times are we busy drawing this thing (recursive).

This is an important variable as it indicates to 'new_transformation' which set of camera vertices it should use.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000