#include <polygon.h>
Inheritance diagram for csPolygon3D:
Public Methods | |
csPolygon3D (csMaterialWrapper *mat) | |
Construct a new polygon with the given material. | |
csPolygon3D (csPolygon3D &poly) | |
Construct a new polygon and copy from the given polygon. More... | |
virtual | ~csPolygon3D () |
Delete everything related to this polygon. More... | |
unsigned long | GetPolygonID () |
Get the ID of this polygon relative to the parent (will be >0). | |
void | SetTextureType (int type) |
Set type of texturing to use for this polygon (one of the POLYTXT_??? flags). More... | |
int | GetTextureType () |
Get the polygon texture type (one of POLYTXT_XXX values). | |
void | CopyTextureType (iPolygon3D *other_polygon) |
Copy texture type settings from another polygon. More... | |
csPolyTexType* | GetTextureTypeInfo () |
Get the general texture type information structure. | |
csPolyTexLightMap* | GetLightMapInfo () |
This is a conveniance function to get the lightmap information structure. More... | |
csPolyTexGouraud* | GetGouraudInfo () |
This is a conveniance function to get the gouraud information structure. More... | |
csPolyTexFlat* | GetFlatInfo () |
This is a conveniance function to get the flat shaded information structure. More... | |
csPolyTexType* | GetNoTexInfo () |
This is a conveniance function to get the "type" texturing type information structure. More... | |
void | Reset () |
Clear the polygon (remove all vertices). | |
int | AddVertex (int v) |
Add a vertex from the container (polygonset) to the polygon. | |
int | AddVertex (const csVector3 &v) |
Add a vertex to the polygon (and containing thing). More... | |
int | AddVertex (float x, float y, float z) |
Add a vertex to the polygon (and containing thing). More... | |
void | ComputeNormal () |
Precompute the plane normal. More... | |
void | Finish () |
After the plane normal and the texture matrices have been set up this routine makes some needed pre-calculations for this polygon. More... | |
void | SetCSPortal (csSector *sector, bool null=false) |
If the polygon is a portal this will set the sector that this portal points to. More... | |
void | SetPortal (csPortal *prt) |
Set a pre-created portal on this polygon. | |
csPortal* | GetPortal () |
Get the portal structure (if there is one). | |
void | SetParent (csThing *thing) |
Set the thing that this polygon belongs to. | |
csThing* | GetParent () |
Get the polygonset (container) that this polygons belongs to. | |
csPolyPlane* | GetPlane () |
Return the plane of this polygon. More... | |
csPlane3* | GetPolyPlane () |
Return the world-space plane of this polygon. | |
csPolyIndexed& | GetVertices () |
Get the vertices. | |
virtual int | GetVertexCount () |
Get number of vertices (required for csPolygonInt). | |
virtual int* | GetVertexIndices () |
Get vertex index table (required for csPolygonInt). | |
void | SetWarp (const csTransform &t) |
Set the warping transformation for the portal. More... | |
void | SetWarp (const csMatrix3 &m_w, const csVector3 &v_w_before, const csVector3 &v_w_after) |
Set the warping transformation for the portal. More... | |
const csVector3& | Vwor (int idx) const |
'idx' is a local index into the vertices table of the polygon. More... | |
const csVector3& | Vobj (int idx) const |
'idx' is a local index into the vertices table of the polygon. More... | |
const csVector3& | Vcam (int idx) const |
'idx' is a local index into the vertices table of the polygon. More... | |
void | UpdateTransformation (const csTransform &c, long cam_cameranr) |
Before calling a series of Vcam() you should call UpdateTransformation() first to make sure that the camera vertex set is up-to-date. | |
void | WorUpdate () |
Before calling a series of Vwor() you should call WorUpdate() first to make sure that the world vertex set is up-to-date. | |
void | SetMaterial (csMaterialWrapper *material) |
Set the material for this polygon. More... | |
csMaterialWrapper* | GetMaterialWrapper () |
Get the material. | |
bool | IsTransparent () |
Return true if this polygon or the texture it uses is transparent. | |
float | GetArea () |
Calculates the area of the polygon in object space. | |
float | GetCosinusFactor () |
Get the cosinus factor. More... | |
void | SetCosinusFactor (float f) |
Set the cosinus factor. More... | |
void | SetTextureSpace (csPolygon3D *copy_from) |
One of the SetTextureSpace functions should be called after adding all vertices to the polygon (not before) and before doing any processing on the polygon (not after)! It makes sure that the plane normal is correctly computed and the texture and plane are correctly initialized. More... | |
void | SetTextureSpace (csPolyTxtPlane *txt_pl) |
This version takes the given plane. More... | |
void | SetTextureSpace (const csVector3 &p1, const csVector2 &uv1, const csVector3 &p2, const csVector2 &uv2, const csVector3 &p3, const csVector2 &uv3) |
Set the texture space transformation given three vertices and their uv coordinates. | |
void | SetTextureSpace (const csVector3 &v_orig, const csVector3 &v1, float len1) |
Calculate the matrix using two vertices (which are preferably on the plane of the polygon and are possibly (but not necessarily) two vertices of the polygon). More... | |
void | SetTextureSpace (float xo, float yo, float zo, float x1, float y1, float z1, float len1) |
Calculate the matrix using two vertices (which are preferably on the plane of the polygon and are possibly (but not necessarily) two vertices of the polygon). More... | |
void | SetTextureSpace (const csVector3 &v_orig, const csVector3 &v1, float len1, const csVector3 &v2, float len2) |
Calculate the matrix using 'v1' and 'len1' for the u-axis and 'v2' and 'len2' for the v-axis. | |
void | SetTextureSpace (float xo, float yo, float zo, float x1, float y1, float z1, float len1, float x2, float y2, float z2, float len2) |
The same but all in floats. | |
void | SetTextureSpace (csMatrix3 const &, csVector3 const &) |
The most general function. More... | |
csPolygonInt* | GetUnsplitPolygon () |
Return the pointer to the original polygon (before any BSP splits). | |
csPolygon3D* | GetBasePolygon () |
Return the pointer to the original polygon (before any BSP splits). More... | |
void | MakeDirtyDynamicLights () |
A dynamic light has changed (this can be either an intensity/color change of a pseudo-dynamic light or else a real dynamic light change). | |
bool | IsDirty () |
Return true if polygon is dirty for dynamic lights. | |
void | MakeCleanDynamicLights () |
Make clean again. | |
void | UnlinkLightpatch (csLightPatch *lp) |
Unlink a light patch from the light patch list. More... | |
void | AddLightpatch (csLightPatch *lp) |
Add a light patch to the light patch list. | |
csLightPatch* | GetLightpatches () |
Get the list of light patches for this polygon. | |
void | ClipPolyPlane (csVector3 *verts, int *num, bool mirror, csVector3 &v1, csVector3 &v2) |
Clip a polygon against a plane (in camera space). More... | |
void | InitializeDefault () |
Initialize the lightmaps for this polygon. More... | |
bool | ReadFromCache (int id) |
This function will try to read the lightmap from the cache in the level archive. More... | |
bool | WriteToCache (int id) |
Call after calling InitializeDefault() and CalculateLighting to cache the calculated lightmap to the level archive. More... | |
void | PrepareLighting () |
Prepare the lightmaps for use. More... | |
void | FillLightMapDynamic (csFrustumView &lview) |
Fill the lightmap of this polygon according to the given light and the frustum. More... | |
void | FillLightMapStatic (csFrustumView *lview, bool vis) |
Fill the lightmap of this polygon according to the given light and the frustum. More... | |
void | UpdateVertexLighting (iLight *light, const csColor &lcol, bool dynamic, bool reset) |
Update vertex lighting for this polygon. More... | |
bool | MarkRelevantShadowFrustums (csFrustumView &lview, csPlane3 &plane) |
Check all shadow frustums and mark all relevant ones. More... | |
bool | MarkRelevantShadowFrustums (csFrustumView &lview) |
Same as above but takes polygon plane as 'plane' argument. | |
void | CalculateLightingDynamic (csFrustumView *lview) |
Check visibility of this polygon with the given csFrustumView and update the light patches if needed. More... | |
void | CalculateLightingStatic (csFrustumView *lview, bool vis) |
Check visibility of this polygon with the given csFrustumView and fill the lightmap if needed (this function calls FillLightMap ()). More... | |
void | ObjectToWorld (const csReversibleTransform &t, const csVector3 &vwor) |
Transform the plane of this polygon from object space to world space. More... | |
void | HardTransform (const csReversibleTransform &t) |
Hard transform the plane of this polygon and also the portal and lightmap info. More... | |
bool | ClipToPlane (csPlane3 *portal_plane, const csVector3 &v_w2c, csVector3 *&pverts, int &num_verts, bool cw=true) |
Clip this camera space polygon to the given plane. More... | |
bool | DoPerspective (const csTransform &trans, csVector3 *source, int num_verts, csPolygon2D *dest, csVector2 *orig_triangle, bool mirror) |
This is the link between csPolygon3D and csPolygon2D (see below for more info about csPolygon2D). More... | |
virtual int | Classify (const csPlane3 &pl) |
Classify this polygon with regards to a plane (in object space). More... | |
virtual int | ClassifyX (float x) |
Same as Classify() but for X plane only. | |
virtual int | ClassifyY (float y) |
Same as Classify() but for Y plane only. | |
virtual int | ClassifyZ (float z) |
Same as Classify() but for Z plane only. | |
virtual void | SplitWithPlane (csPolygonInt **front, csPolygonInt **back, const csPlane3 &plane) |
Split this polygon with the given plane (A,B,C,D) and return the two resulting new polygons in 'front' and 'back'. More... | |
virtual bool | Overlaps (csPolygonInt *overlapped) |
Check if this polygon (partially) overlaps the other polygon from some viewpoint in space. More... | |
virtual int | GetType () |
Return 1 to indicate to the BSP tree routines that this is a csPolygon3D. | |
bool | IntersectSegment (const csVector3 &start, const csVector3 &end, csVector3 &isect, float *pr=NULL) |
Intersect object-space segment with this polygon. More... | |
bool | IntersectRay (const csVector3 &start, const csVector3 &end) |
Intersect object-space ray with this polygon. More... | |
bool | IntersectRayNoBackFace (const csVector3 &start, const csVector3 &end) |
Intersect object-space ray with this polygon. More... | |
bool | IntersectRayPlane (const csVector3 &start, const csVector3 &end, csVector3 &isect) |
Intersect object space ray with the plane of this polygon and returns the intersection point. More... | |
bool | PointOnPolygon (const csVector3 &v) |
This is a given point is on (or very nearly on) this polygon. More... | |
virtual int | GetAlpha () |
Get the alpha transparency value for this polygon. | |
virtual void | SetAlpha (int iAlpha) |
Set the alpha transparency value for this polygon (only if it is a portal). More... | |
virtual iMaterialHandle* | GetMaterialHandle () |
Get the material handle for the texture manager. | |
virtual iPolygonTexture* | GetTexture () |
Get the handle to the polygon texture object. | |
csPolygon3D* | GetNextShare () |
Get next polygon in texture share list. | |
void | SetNextShare (csPolygon3D *next) |
Set next polygon in texture share list. | |
SCF_DECLARE_IBASE_EXT (csObject) | |
Public Attributes | |
csFlags | flags |
Set of flags. | |
csPolygon3D::eiPolygon3D | scfiPolygon3D |
Friends | |
class | csPolyTexture |
class | eiPolygon3D |
Polygons are used to construct the outer hull of sectors and the faces of 3D things. Polygons can be transformed in 3D (usually they are transformed so that the camera position is at (0,0,0) and the Z-axis is forward). Polygons cannot be transformed in 2D. That's what csPolygon2D is for. It is possible to convert a csPolygon3D to a csPolygon2D though, at which point processing continues with the csPolygon2D object.
Polygons have a texture and lie on a plane. The plane does not define the orientation of the polygon but is derived from it. The plane does define how the texture is scaled and translated accross the surface of the polygon (in case we are talking about lightmapped polygons, gouraud shaded polygons have u,v coordinates at every vertex). Several planes can be shared for different polygons. As a result of this their textures will be correctly aligned.
If a polygon is part of a sector it can be a portal to another sector. A portal-polygon is a see-through polygon that defines a view to another sector. Normally the texture for a portal-polygon is not drawn unless the texture is filtered in which case it is drawn on top of the other sector.
|
Construct a new polygon and copy from the given polygon. Note! Several fields will reflect that a copy was made! New polytextures will be allocated. This is mainly used when a BSP tree splits a polygon. |
|
Delete everything related to this polygon. Less is deleted if this polygon is a copy of another one (because some stuff is shared). |
|
Add a vertex to the polygon (and containing thing). Note that it will not check if the vertex is already there. After adding all vertices/polygons you should call CompressVertices() to safe space and gain efficiency. |
|
Add a vertex to the polygon (and containing thing). Note that it will not check if the vertex is already there. After adding all vertices/polygons you should call CompressVertices() to safe space and gain efficiency. |
|
Check visibility of this polygon with the given csFrustumView and update the light patches if needed. This function will also traverse through a portal if so needed. This version is for dynamic lighting. |
|
Check visibility of this polygon with the given csFrustumView and fill the lightmap if needed (this function calls FillLightMap ()). This function will also traverse through a portal if so needed. If 'vis' == false this means that the lighting system already discovered that the polygon is totally shadowed. This version is for static lighting. |
|
Classify this polygon with regards to a plane (in object space). If this poly is on same plane it returns POL_SAME_PLANE. If this poly is completely in front of the given plane it returnes POL_FRONT. If this poly is completely back of the given plane it returnes POL_BACK. Otherwise it returns POL_SPLIT_NEEDED. Reimplemented from csPolygonInt. |
|
Clip a polygon against a plane (in camera space). The plane is defined as going through v1, v2, and (0,0,0). The 'verts' array is modified and 'num' is also modified if needed. |
|
Clip this camera space polygon to the given plane. 'plane' can be NULL in which case no clipping happens.
If this function returns false then the polygon is not visible (backface culling, no visible vertices, ...) and 'verts' will be NULL. Otherwise this function will return true and 'verts' will point to the new clipped polygon (this is a pointer to a static table of vertices. WARNING! Because of this you cannot do new ClipToPlane calls until you have processed the 'verts' array!).
If 'cw' is true the polygon has to be oriented clockwise in order to be visible. Otherwise it is the other way around. |
|
Precompute the plane normal. Normally this is done automatically by set_texture_space but if needed you can call this function again when something has changed. |
|
Copy texture type settings from another polygon. (this will not copy the actual material that is used, just the information on how to apply that material to the polygon). |
|
This is the link between csPolygon3D and csPolygon2D (see below for more info about csPolygon2D). It should be used after the parent container has been transformed from world to camera space. It will fill the given csPolygon2D with a perspective corrected polygon that is also clipped to the view plane (Z=SMALL_Z). If all vertices are behind the view plane the polygon will not be visible and it will return false. 'do_perspective' will also do back-face culling and returns false if the polygon is not visible because of this. If the polygon is deemed to be visible it will return true. |
|
Fill the lightmap of this polygon according to the given light and the frustum. The light is given in world space coordinates. The view frustum is given in camera space (with (0,0,0) the origin of the frustum). The camera space used is just world space translated so that the center of the light is at (0,0,0). If the lightmaps were cached in the level archive this function will do nothing. The "frustum" parameter defines the original light frustum (not the one bounded by this polygon as given by "lview"). |
|
Fill the lightmap of this polygon according to the given light and the frustum. The light is given in world space coordinates. The view frustum is given in camera space (with (0,0,0) the origin of the frustum). The camera space used is just world space translated so that the center of the light is at (0,0,0). If the lightmaps were cached in the level archive this function will do nothing.
The "frustum" parameter defines the original light frustum (not the one bounded by this polygon as given by "lview").
If 'vis' == false this means that the lighting system already discovered that the polygon is totally shadowed. |
|
After the plane normal and the texture matrices have been set up this routine makes some needed pre-calculations for this polygon. It will create a texture space bounding box that is going to be used for lighting and the texture cache. Then it will allocate the light map tables for this polygons. You also need to call this function if you make a copy of a polygon (using the copy constructor) or if you change the vertices in a polygon. |
|
Return the pointer to the original polygon (before any BSP splits). If polygon was not split this will return current poly. |
|
Get the cosinus factor. This factor is used for lighting. |
|
This is a conveniance function to get the flat shaded information structure. If this polygon is not POLYTXT_FLAT or POLYTXT_GOURAUD it will return NULL, GOURAUD is derived from the FLAT structure. |
|
This is a conveniance function to get the gouraud information structure. If this polygon is not POLYTXT_GOURAUD it will return NULL. |
|
This is a conveniance function to get the lightmap information structure. If this polygon is not POLYTXT_LIGHTMAP it will return NULL. |
|
This is a conveniance function to get the "type" texturing type information structure. It returns NULL only if the polygon texture type is lightmapped, because all other texturing types are subclassed from NONE. |
|
Return the plane of this polygon. This function returns a 3D engine type csPolyPlane which encapsulates object, world, and camera space planes as well as the texture transformation. |
|
Hard transform the plane of this polygon and also the portal and lightmap info. This is similar to ObjectToWorld but it does a hard transform of the object space planes instead of keeping a transformation. |
|
Initialize the lightmaps for this polygon. Should be called before calling CalculateLighting() and before calling WriteToCache(). |
|
Intersect object-space ray with this polygon. This function is similar to IntersectSegment except that it doesn't keep the lenght of the ray in account. It just tests if the ray intersects with the interior of the polygon. Note that this function also does back-face culling. |
|
Intersect object-space ray with this polygon. This function is similar to IntersectSegment except that it doesn't keep the lenght of the ray in account. It just tests if the ray intersects with the interior of the polygon. Note that this function doesn't do back-face culling. |
|
Intersect object space ray with the plane of this polygon and returns the intersection point. This function does not test if the intersection is inside the polygon. It just returns the intersection with the plane (in or out). This function returns false if the ray is parallel with the plane (i.e. there is no intersection). |
|
Intersect object-space segment with this polygon. Return true if it intersects and the intersection point in world coordinates. |
|
Check all shadow frustums and mark all relevant ones.
A shadow frustum is relevant if it is (partially) inside the light frustum and if it is not obscured by other shadow frustums. In addition to the checking above this routine will return false if it can find a shadow frustum which totally obscures the light frustum. In this case it makes no sense to continue lighting the polygon. |
|
Transform the plane of this polygon from object space to world space. 'vt' is a vertex of this polygon in world space. |
|
Check if this polygon (partially) overlaps the other polygon from some viewpoint in space. This function works in object space. Reimplemented from csPolygonInt. |
|
This is a given point is on (or very nearly on) this polygon. Test happens in object space. |
|
Prepare the lightmaps for use. This function also converts the lightmaps to the correct format required by the 3D driver. This function does NOT create the first lightmap. This is done by the precalculated lighting process (using CalculateLighting()). |
|
This function will try to read the lightmap from the cache in the level archive. If do_cache == false this function will not try to read the lightmap from the cache. |
|
Set the alpha transparency value for this polygon (only if it is a portal). Not all renderers support all possible values. 0, 25, 50, 75, and 100 will always work but other values may give only the closest possible to one of the above. |
|
If the polygon is a portal this will set the sector that this portal points to. If this polygon has no portal one will be created. If 'null' is true and sector == 'NULL' then a NULL portal is created. |
|
Set the cosinus factor. This factor is used for lighting. |
|
Set the material for this polygon. This material handle will only be used as soon as 'Finish()' is called. So you can safely wait preparing the materials until finally csEngine::Prepare() is called (which in the end calls Finish() for every polygon). |
|
The most general function. With these you provide the matrix directly. |
|
Calculate the matrix using two vertices (which are preferably on the plane of the polygon and are possibly (but not necessarily) two vertices of the polygon). The first vertex is seen as the origin and the second as the u-axis of the texture space coordinate system. The v-axis is calculated on the plane of the polygon and orthogonal to the given u-axis. The length of the u-axis and the v-axis is given as the 'len1' parameter. |
|
Calculate the matrix using two vertices (which are preferably on the plane of the polygon and are possibly (but not necessarily) two vertices of the polygon). The first vertex is seen as the origin and the second as the u-axis of the texture space coordinate system. The v-axis is calculated on the plane of the polygon and orthogonal to the given u-axis. The length of the u-axis and the v-axis is given as the 'len1' parameter. For example, if 'len1' is equal to 2 this means that texture will be tiled exactly two times between vertex 'v_orig' and 'v1'. I hope this explanation is clear since I can't seem to make it any clearer :-) |
|
This version takes the given plane. Using this function you can use the same plane for several polygons. This polygon is not responsible for cleaning this plane. |
|
One of the SetTextureSpace functions should be called after adding all vertices to the polygon (not before) and before doing any processing on the polygon (not after)! It makes sure that the plane normal is correctly computed and the texture and plane are correctly initialized.
Internally the transformation from 3D to texture space is represented by a matrix and a vector. You can supply this matrix directly or let it be calculated from other parameters. If you supply another Polygon or a csPolyPlane to this function it will automatically share the plane. This version copies the plane from the other polygon. The plane is shared with that other plane and this allows the engine to do some optimizations. This polygon is not responsible for cleaning this plane. |
|
Set type of texturing to use for this polygon (one of the POLYTXT_??? flags). POLYTXT_LIGHTMAP is default. This function is guaranteed not to do anything if the type is already correct. |
|
Set the warping transformation for the portal. If there is no portal this function does nothing. |
|
Set the warping transformation for the portal. If there is no portal this function does nothing. |
|
Split this polygon with the given plane (A,B,C,D) and return the two resulting new polygons in 'front' and 'back'. The new polygons will mimic the behaviour of the parent polygon as good as possible. This function is mainly used by the BSP splitter. Note that splitting happens in object space. Reimplemented from csPolygonInt. |
|
Unlink a light patch from the light patch list. Warning! This function does not test if the light patch is really on the list! |
|
Update vertex lighting for this polygon.
Only works if the polygon uses gouraud shading or is flat-shaded. 'dynamic' is true for a dynamic light. 'reset' is true if the light values need to be reset to 0. 'lcol' is the color of the light. It is given seperately because the color of the light may be modified by portals and other effects. |
|
'idx' is a local index into the vertices table of the polygon. This index is translated to the index in the parent container and a reference to the vertex in camera-space is returned. |
|
'idx' is a local index into the vertices table of the polygon. This index is translated to the index in the parent container and a reference to the vertex in object-space is returned. |
|
'idx' is a local index into the vertices table of the polygon. This index is translated to the index in the parent container and a reference to the vertex in world-space is returned. |
|
Call after calling InitializeDefault() and CalculateLighting to cache the calculated lightmap to the level archive. This function does nothing if the cached lightmap was already up-to-date. |