Public Member Functions | |
CBaseModel (const QString &name, int primitiveType, const vec3_t &mins, const vec3_t &maxs, float boundingRadius, IVertexStream *vertices) | |
Constructs a model object. | |
virtual | ~CBaseModel (void) |
Destructor. | |
QString | getName (void) |
Returns the name of this model. | |
int | getPrimitiveType (void) |
Returns the primitive type of this model. | |
QString | getPrimitiveTypeName (void) |
Returns the primitive type if this model in a human readable format. | |
float | getBoundingRadius (void) |
Returns the bounding radius of this model. | |
void | getBoundingBox (vec3_t &mins, vec3_t &maxs) |
Returns the bounding box of this model. | |
void | render (const VertexAttribLocations *attribs, const vec4_t *overrideColor) |
Sends the stored geometry to OpenGL via vertex arrays. | |
void | renderNormals (void) |
Draws the vertex normals stored in this model. | |
void | renderTangents (void) |
Draw vertex tangent space basis stored in this model. | |
Static Public Member Functions | |
static void | buildPlane (vec3_t *v, vec3_t *n, vec2_t *t, vec4_t *c, const vec3_t *mainVertices, const vec3_t &normal, const vec2_t *mainTexCoords, const vec4_t *mainColors, int level) |
Builds a tesseleted plane. | |
static int | vertexCountForPlaneLevel (int level) |
Helper method for buildPlane. |
There are some additinal functions for geometry construction available in this class.
CBaseModel::CBaseModel | ( | const QString & | name, | |
int | primitiveType, | |||
const vec3_t & | mins, | |||
const vec3_t & | maxs, | |||
float | boundingRadius, | |||
IVertexStream * | vertices | |||
) |
Constructs a model object.
It takes a vertex stream and its metadata and stores it. The vertex stream is deleted when this object is destroyed.
name | Model name. | |
primitiveType | OpenGL primitive type of this model. | |
mins | Bounding box mins. | |
maxs | Bounding box maxs. | |
boundingRadius | Bounding sphere radius. | |
vertices | IVertexStream object that stores the model's geometry. |
QString CBaseModel::getName | ( | void | ) | [inline, virtual] |
int CBaseModel::getPrimitiveType | ( | void | ) | [inline, virtual] |
Returns the primitive type of this model.
It assumes that the model is constructed of only one primitive type.
Implements IModel.
QString CBaseModel::getPrimitiveTypeName | ( | void | ) | [virtual] |
Returns the primitive type if this model in a human readable format.
It assumes that the model is constructeed of only one primitive type.
Implements IModel.
float CBaseModel::getBoundingRadius | ( | void | ) | [inline, virtual] |
Returns the bounding radius of this model.
Implements IModel.
Returns the bounding box of this model.
The bounding box is defined by minimum and maximum coordinates.
mins | Buffer to store the minimum coordiantes of the bounding box. | |
maxs | Buffer to store the maximum coordiantes of the bounding box. |
Implements IModel.
void CBaseModel::render | ( | const VertexAttribLocations * | attribs, | |
const vec4_t * | overrideColor | |||
) | [virtual] |
Sends the stored geometry to OpenGL via vertex arrays.
It enables OpenGL client state, binds vertex arrays, draws them and disables the client state.
attribs | Custom vertex attribute locations. If this model has these attributes available, they will be bound to the indexed custom vertex attributes. If one of these attributes is -1, it will not be used. If this parameters is set to NULL, no custom attributes will be used. | |
overrideColor | If this parameters if != NULL, then this color will be used as vertex color instead of the values stored in this model. |
Implements IModel.
void CBaseModel::renderNormals | ( | void | ) | [virtual] |
Draws the vertex normals stored in this model.
If no normal are available, this call has no effect. It loops through all vertices and draws a colored line starting at the vertex position and pointing into the normal's direction. The colors are chosen from the largest component: x == red, Y == green, Z == blue.
Implements IModel.
void CBaseModel::renderTangents | ( | void | ) | [virtual] |
Draw vertex tangent space basis stored in this model.
If no tangent space vectors are available, this call has no effect. Otherwise it draws a line from the vertex position in the direction of each tangent space vector. Tangent == red, Bitangent == green, Normal == blue.
Implements IModel.
void CBaseModel::buildPlane | ( | vec3_t * | v, | |
vec3_t * | n, | |||
vec2_t * | t, | |||
vec4_t * | c, | |||
const vec3_t * | mainVertices, | |||
const vec3_t & | normal, | |||
const vec2_t * | mainTexCoords, | |||
const vec4_t * | mainColors, | |||
int | level | |||
) | [static] |
Builds a tesseleted plane.
This function recursively builds a plane of triangle pairs. In fact, the plane is a quad. Each recursion level splits the quad into four sub-qurads, the upper-left, upper-right, lower-left and lower-right quads. These quads are created by calling the buildPlane functions with level-1. The base level is 1.
The parameters v,n,t and c point to arrays of n elements, where n = 6 * 4^level. This means every quad is created by two triangles, which require 6 vertices. Because the quads are split each level, the number of quads increases by factor 4 at each level. This results in 4^level. The caller of this function must make sure that enough space is allocated to hold the triangles for the requested recursion level.
The parameters holds the vetex normal that is assigned to every vertex this function produces.
The parameters mainVertices, mainTexCoords and mainColors point to arrays with four element wich hold the vertex attributes for the lower-left, lower-right, uppler-left, upper-right corner of the quad, in that order. Thses values are linear interpolated when goint into recursion.
v | Vertex position array. | |
n | Normal array. | |
t | TexCoord array. | |
c | Color array. | |
mainVertices | Input position. | |
normal | Surface normal. | |
mainTexCoords | Input texture coordinates. | |
mainColors | Input colors. | |
level | Recursion level, must be >= 1. |
int CBaseModel::vertexCountForPlaneLevel | ( | int | level | ) | [static] |
Helper method for buildPlane.
It calculates the amount of vertices in a plane for a recusion level.
level | Recusion level. |