ezEngine  Milestone 7
ezGeometry Class Reference

Provides functions to generate standard geometric shapes, such as boxes, spheres, cylinders, etc. More...

#include <GeomUtils.h>

Classes

struct  Line
 A line only references two vertices. More...
 
struct  Polygon
 Each polygon has a face normal and a set of indices, which vertices it references. More...
 
struct  Vertex
 The data that is stored per vertex. More...
 

Public Member Functions

const ezDeque< Vertex > & GetVertices () const
 Returns the entire vertex data.
 
const ezDeque< Polygon > & GetPolygons () const
 Returns the entire polygon data.
 
const ezDeque< Line > & GetLines () const
 Returns the entire line data.
 
void Clear ()
 Clears all data.
 
ezUInt32 AddVertex (const ezVec3 &vPos, const ezVec3 &vNormal, const ezVec2 &vTexCoord, const ezColor &color, ezInt32 iCustomIndex=0)
 Adds a vertex, returns the index to the added vertex.
 
ezUInt32 AddVertex (const ezVec3 &vPos, const ezVec3 &vNormal, const ezVec2 &vTexCoord, const ezColor &color, ezInt32 iCustomIndex, const ezMat4 &mTransform)
 Adds a vertex, returns the index to the added vertex. Position and normal are transformed with the given matrix.
 
void AddPolygon (const ezArrayPtr< ezUInt32 > &Vertices)
 Adds a polygon that consists of all the referenced vertices. No face normal is computed at this point.
 
void AddLine (ezUInt32 uiStartVertex, ezUInt32 uiEndVertex)
 Adds a line.
 
void ComputeFaceNormals ()
 Computes normals for all polygons from the current vertex positions. Call this when you do not intend to make further modifications.
 
void ComputeSmoothVertexNormals ()
 Computes smooth (averaged) normals for each vertex. Requires that face normals are computed. More...
 
void SetAllVertexCustomIndex (ezInt32 iCustomIndex, ezUInt32 uiFirstVertex=0)
 Changes the custom index for all vertices (starting at vertex uiFirstVertex).
 
void SetAllVertexColor (const ezColor &color, ezUInt32 uiFirstVertex=0)
 Changes the color for all vertices (starting at vertex uiFirstVertex).
 
void Transform (const ezMat4 &mTransform, bool bTransformPolyNormals)
 Transforms all vertices by the given transform. More...
 
void Merge (const ezGeometry &other)
 Merges the given mesh into this one. Use this to composite multiple shapes into one.
 
void AddRectXY (const ezVec2 &size, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a rectangle shape in the XY plane, with the front in positive Z direction. It is centered at the origin, extending half size.x and half size.y into direction +X, -X, +Y and -Y.
 
void AddBox (const ezVec3 &size, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds an untextured box (8 vertices).
 
void AddTexturedBox (const ezVec3 &size, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a box that has UV coordinates set (24 vertices).
 
void AddPyramid (const ezVec3 &size, bool bCap, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a pyramid. This is different to a low-res cone in that the corners are placed differently (like on a box). More...
 
void AddGeodesicSphere (float fRadius, ezUInt8 uiSubDivisions, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a geodesic sphere with radius 1 at the origin. More...
 
void AddCylinder (float fRadiusTop, float fRadiusBottom, float fHeight, bool bCapTop, bool bCapBottom, ezUInt16 uiSegments, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0, ezAngle fraction=ezAngle::Degree(360.0f))
 Adds a cylinder. The origin is at the center. More...
 
void AddCone (float fRadius, float fHeight, bool bCap, ezUInt16 uiSegments, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a cylinder. The origin is at the center of the bottom. More...
 
void AddSphere (float fRadius, ezUInt16 uiSegments, ezUInt16 uiStacks, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a sphere. More...
 
void AddHalfSphere (float fRadius, ezUInt16 uiSegments, ezUInt16 uiStacks, bool bCap, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds half a sphere. More...
 
void AddCapsule (float fRadius, float fHeight, ezUInt16 uiSegments, ezUInt16 uiStacks, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a capsule. More...
 
void AddTorus (float fInnerRadius, float fOuterRadius, ezUInt16 uiSegments, ezUInt16 uiSegmentDetail, const ezColor &color, const ezMat4 &mTransform=ezMat4::IdentityMatrix(), ezInt32 iCustomIndex=0)
 Adds a full torus. More...
 

Private Member Functions

void TransformVertices (const ezMat4 &mTransform, ezUInt32 uiFirstVertex)
 

Private Attributes

ezDeque< Vertexm_Vertices
 
ezDeque< Polygonm_Polygons
 
ezDeque< Linem_Lines
 

Detailed Description

Provides functions to generate standard geometric shapes, such as boxes, spheres, cylinders, etc.

This class provides simple functions to create frequently used basic shapes. It allows to transform the shapes, merge them into a single mesh, compute normals, etc. It is meant for debug and editor geometry (gizmos, etc.). Vertices can have position, normal, color and 'shape index'. UV coordinates are currently not supported.


Class Documentation

struct ezGeometry::Polygon

Each polygon has a face normal and a set of indices, which vertices it references.

Class Members
ezHybridArray< ezUInt32, 4 > m_Vertices
ezVec3 m_vNormal

Member Function Documentation

void ezGeometry::AddCapsule ( float  fRadius,
float  fHeight,
ezUInt16  uiSegments,
ezUInt16  uiStacks,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a capsule.

The origin is at the center of the capsule. Radius and height are added to get the total height of the capsule. uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail of the rounded top and bottom, must be at least 1.

void ezGeometry::AddCone ( float  fRadius,
float  fHeight,
bool  bCap,
ezUInt16  uiSegments,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a cylinder. The origin is at the center of the bottom.

uiSegments is the detail around the up axis, must be at least 3.

void ezGeometry::AddCylinder ( float  fRadiusTop,
float  fRadiusBottom,
float  fHeight,
bool  bCapTop,
bool  bCapBottom,
ezUInt16  uiSegments,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0,
ezAngle  fraction = ezAngle::Degree(360.0f) 
)

Adds a cylinder. The origin is at the center.

uiSegments is the detail around the up axis, must be at least 3. The top or bottom caps can be removed using bCapTop and bCapBottom. When fraction is set to any value below 360 degree, a pie / pacman shaped cylinder is created.

void ezGeometry::AddGeodesicSphere ( float  fRadius,
ezUInt8  uiSubDivisions,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a geodesic sphere with radius 1 at the origin.

When uiSubDivisions is zero, the sphere will have 20 triangles.
For each subdivision step the number of triangles quadruples.
0 = 20 triangles, 12 vertices
1 = 80 triangles, 42 vertices
2 = 320 triangles, 162 vertices
3 = 1280 triangles, 642 vertices
4 = 5120 triangles, 2562 vertices
...

void ezGeometry::AddHalfSphere ( float  fRadius,
ezUInt16  uiSegments,
ezUInt16  uiStacks,
bool  bCap,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds half a sphere.

The origin is at the 'full sphere center', ie. at the center of the cap. uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail of the rounded top and bottom, must be at least 1.

void ezGeometry::AddPyramid ( const ezVec3 size,
bool  bCap,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a pyramid. This is different to a low-res cone in that the corners are placed differently (like on a box).

The origin is at the center of the base quad.size.z is the height of the pyramid.

void ezGeometry::AddSphere ( float  fRadius,
ezUInt16  uiSegments,
ezUInt16  uiStacks,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a sphere.

uiSegments is the detail around the up axis, must be at least 3. uiStacks is the detail of the rounded top and bottom, must be at least 2.

void ezGeometry::AddTorus ( float  fInnerRadius,
float  fOuterRadius,
ezUInt16  uiSegments,
ezUInt16  uiSegmentDetail,
const ezColor color,
const ezMat4 mTransform = ezMat4::IdentityMatrix(),
ezInt32  iCustomIndex = 0 
)

Adds a full torus.

The origin is at the center of the torus. fInnerRadius is the radius from the center to where the torus ring starts. fOuterRadius is the radius to where the torus ring stops. uiSegments is the detail around the up axis. uiSegmentDetail is the number of segments around the torus ring (ie. the cylinder detail)

void ezGeometry::ComputeSmoothVertexNormals ( )

Computes smooth (averaged) normals for each vertex. Requires that face normals are computed.

This only yields smooth normals for vertices that are shared among multiple polygons, otherwise a vertex will have the same normal as the one face that it is used in.

void ezGeometry::Transform ( const ezMat4 mTransform,
bool  bTransformPolyNormals 
)

Transforms all vertices by the given transform.

When bTransformPolyNormals is true, the polygon normals are transformed, as well. Set this to false when face normals are going to be computed later anyway.

void ezGeometry::TransformVertices ( const ezMat4 mTransform,
ezUInt32  uiFirstVertex 
)
private
Todo:
GeomUtils improvements:

The documentation for this class was generated from the following files: