Basic Shape Creation and Rendering  2.0
Tools to create and render common shapes like blocks, cylinders, cones, and spheres
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
BasicShape Class Reference

Public Types

enum  Caps { CAP_AT_NEITHER, CAP_AT_BOTTOM, CAP_AT_TOP, CAP_AT_BOTH }
 

Public Member Functions

virtual ~BasicShape ()
 
void getMCBoundingBox (double *xyzLimits) const
 
int getNumPoints () const
 
const float * getPointCoords () const
 
const float * getNormals () const
 
const float * getTextureCoords () const
 
int getNumDrawArraysCalls () const
 
int getDrawArraysData (int i, GLenum &mode, int &thisStartsFace, int &offset, bool &canUsePerVertexTexCoords, bool &canUseNormalArray, cryph::AffVector &fixedN) const
 
int getNumIndexLists () const
 
const void * getIndexList (int i, GLenum &mode, int &thisStartsFace, int &nInList, GLenum &type, bool &canUsePerVertexTexCoords, bool &canUsePerVertexNormals, cryph::AffVector &fixedNormal) const
 

Static Public Member Functions

static BasicShapemakeBlock (const cryph::AffPoint &llCorner, const cryph::AffVector &uEdge, double uLength, const cryph::AffVector &vEdge, double vLength, const cryph::AffVector &wEdge, double wLength)
 
static BasicShapemakeBoundedCone (const cryph::AffPoint &Pbottom, const cryph::AffPoint &Ptop, double radiusAtBottom, double radiusAtTop, int nPointsAroundSide=10, int nPointsAlongAxis=2, Caps capSpec=CAP_AT_BOTH, double sMin=0, double sMax=0, double tMin=0, double tMax=0, const cryph::AffVector &sZero=cryph::AffVector::xu)
 
static BasicShapemakeBoundedCylinder (const cryph::AffPoint &Pbottom, const cryph::AffPoint &Ptop, double radius, int nPointsAroundSide=10, int nPointsAlongAxis=2, Caps capSpec=CAP_AT_BOTH, double sMin=0, double sMax=0, double tMin=0, double tMax=0, const cryph::AffVector &sZero=cryph::AffVector::xu)
 
static BasicShapemakeSphere (const cryph::AffPoint &center, double radius, int nPointsAroundSide=15, int nPointsAlongAxis=15, double sMin=0, double sMax=0, double tMin=0, double tMax=0, const cryph::AffVector &upAxis=cryph::AffVector::yu, const cryph::AffVector &sZero=cryph::AffVector::xu)
 
static BasicShapemakeTorus (const cryph::AffPoint &center, const cryph::AffVector &u, const cryph::AffVector &v, double rMajor, double rMinor, double thetaMinDegrees=0.0, double thetaMaxDegrees=360.0, double phiMinDegrees=0, double phiMaxDegrees=360.0, int nPointsInThetaDirection=60, int nPointsInPhiDirection=40, double sMin=0, double sMax=0, double tMin=0, double tMax=0)
 
static bool getAlwaysGeneratePerVertexNormals ()
 
static void setAlwaysGeneratePerVertexNormals (bool b)
 

Member Enumeration Documentation

◆ Caps

An enumerated type that allows specification of whether cylinders and cones should have planar caps at the top and/or at the bottom.

Constructor & Destructor Documentation

◆ ~BasicShape()

BasicShape::~BasicShape ( )
virtual

The destructor

Member Function Documentation

◆ getAlwaysGeneratePerVertexNormals()

static bool BasicShape::getAlwaysGeneratePerVertexNormals ( )
inlinestatic

An accessor method that returns whether the implementation is currently forcing all normal vectors to be stored in VBOs. This is largely for experimental purposes. Use of this method is highly discouraged.

◆ getDrawArraysData()

int BasicShape::getDrawArraysData ( int  i,
GLenum &  mode,
int &  thisStartsFace,
int &  offset,
bool &  canUsePerVertexTexCoords,
bool &  canUseNormalArray,
cryph::AffVector &  fixedN 
) const

An accessor method intended to be used only by class BasicShapeRenderer

Parameters
ithe glDrawArrays data desired (0 <= i < getNumDrawArraysCalls())
modethe OpenGL draw mode to be used
thisStartsFacean indication of whether this glDrawArrays call is the first on a face of the BasicShape. BasicShape instances created as cylinders, cones, and spheres will only report starting face 0; BasicShape instances created by makeBlock will report faces 0-5 as defined in BasicShape::makeBlock. If the current glDrawArrays call does not start a face, thisStartsFace will be returned as -1. The intended use for this output is to allow a client to "prepare for a face" by, for example, establishng texture mapping information. (See the BasicShapeRenderer::renderShape method.)
offsetthe offset parameter to be passed to glDrawArrays
canUseVertexTexCoordstrue if and only if texture mapping is being used
canUseNormalArraytrue if and only if a normal vector VBO should be enabled; otherwise the normal will be set by passing fixedN to glVertexAttrib
fixedNthe normal vectior to be used if canUseNormalArray is false
Returns
the number of points to be passed to the glDrawArrays call
See also
BasicShapeRenderer

◆ getIndexList()

const void * BasicShape::getIndexList ( int  i,
GLenum &  mode,
int &  thisStartsFace,
int &  nInList,
GLenum &  type,
bool &  canUsePerVertexTexCoords,
bool &  canUsePerVertexNormals,
cryph::AffVector &  fixedNormal 
) const

An accessor method intended to be used only by class BasicShapeRenderer

Parameters
ithe glDrawElements data desired (0 <= i < getNumIndexLists())
modethe OpenGL draw mode to be used
thisStartsFacean indication of whether this glDrawElements call is the first on a face of the BasicShape. BasicShape instances created as cylinders, cones, and spheres will only report starting face 0; BasicShape instances created by makeBlock will report faces 0-5 as defined in BasicShape::makeBlock. If the current glDrawArrays call does not start a face, thisStartsFace will be returned as -1. The intended use for this output is to allow a client to "prepare for a face" by, for example, establishng texture mapping information. (See the BasicShapeRenderer::renderShape method.)
nInListthe number of indices in the returned index list
typethe type of the indices to be specified to glDrawElements
canUseVertexTexCoordstrue if and only if texture mapping is being used
canUseNormalArraytrue if and only if a normal vector VBO should be enabled; otherwise the normal will be set by passing fixedN to glVertexAttrib
fixedNthe normal vectior to be used if canUseNormalArray is false
Returns
the index list. At the discretion of the client (e.g., BasicShapeRenderer), this will either be passed directly to glDrawElements, or stored in an EBO.
See also
BasicShapeRenderer

◆ getMCBoundingBox()

void BasicShape::getMCBoundingBox ( double *  xyzLimits) const

Retrieve the MC bounding box for the BasicShape instance

Parameters
xyzLimitsthe {xmin, xmax, ymin, ymax, zmin, zmax} bounds will be returned in this parameter. It is assumed to be at least of length 6.

◆ getNormals()

const float* BasicShape::getNormals ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the actual array of 3D normal vectors that must be stored in the normal vector VBO. nullptr is returned if there are no vectors to be stored there.)

◆ getNumDrawArraysCalls()

int BasicShape::getNumDrawArraysCalls ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the number of glDrawArrays calls that are needed to render this BasicShape

◆ getNumIndexLists()

int BasicShape::getNumIndexLists ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the number of glDrawElements calls that are needed to render this BasicShape

◆ getNumPoints()

int BasicShape::getNumPoints ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the number of points (equivalently, the number of normals, if applicable and the number of texture coordinates, if applicable) that must be sent to the GPU in VBOs.

◆ getPointCoords()

const float* BasicShape::getPointCoords ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the actual array of 3D point coordinates that must be stored in the point coordinate VBO.

◆ getTextureCoords()

const float* BasicShape::getTextureCoords ( ) const
inline

An accessor method intended to be used only by class BasicShapeRenderer

Returns
the actual array of 2D texture coordinates that must be stored in the texture coordinate VBO. nullptr is returned if there are no texture coordinates.)

◆ makeBlock()

BasicShape * BasicShape::makeBlock ( const cryph::AffPoint &  llCorner,
const cryph::AffVector &  uEdge,
double  uLength,
const cryph::AffVector &  vEdge,
double  vLength,
const cryph::AffVector &  wEdge,
double  wLength 
)
static

A factory method to create a block (actually a 3D parallelepiped). The uEdge, vEdge, and wEdge vectors determine the u, v, and w edge directions of the parallelepiped. There is no requirement that they be perpendicular to one another. They need only be linearly independent.

Texture coordinates are not generated for block shapes. However it will be of use to clients to know that the 8 vertices are stored in the VBO in the order: (uMin, vMin, wMin), (uMin, vMin, wMax), (uMax, vMin, wMin), (uMax, vMin, wMax), (uMax, vMax, wMin), (uMax, vMax, wMax), (uMin, vMax, wMin), (uMin, vMax, wMax). Furthermore, the faces are numbered and rendered as: [0: the vMin face], [1: the uMax face], [2: the vMax face], [3: uMin face], [4: wMin face], and [5: wMax face]. Faces 0-2 are drawn using glDrawArrays calls with a count of 4 and "first" index = 0, 2, and 4, respectively; faces 3-5 are drawn using glDrawElements with the following indices: [face 3: 6, 7, 0, 1], [face 4: 0, 2, 6, 4], and [face 5: 1, 3, 7, 5]. Using this information, clients of BasicShapeRenderer can apply texture to any and all block faces when the corresponding "prepareForFace" callback passed to BasicShapeRenderer::renderShape is invoked during display callbacks. The easiest way to do this is to use the utility BasicShapeRenderer::setTexCoordsForBlock, passing that method the current face index.

If either the uEdge vector or the vEdge vector is the zero vector, OR if they are parallel to one another, nullptr is returned. These are the only error conditions. A block will be created as specified below in all other cases.

Parameters
llCornerthe (x,y,z) coordinates of the corner of the block
uEdgea vector specifying the u direction of the block. If this is a zero vector, nullptr is returned.
uLengthif uLength > 0, this will be used as the length of the block in the u direction. If uLength <= 0, the length of the uEdge vector will be used.
vEdgea vector specifying the v direction of the block. If this is a zero vector or a scalar multiple of the uEdge vector, nullptr is returned.
vLengthif vLength > 0, this will be used as the length of the block in the v direction. If vLength <= 0, the length of the vEdge vector will be used.
wEdgea vector specifying the w direction of the block. If this is a zero vector or in the plane spanned by (uEdge, vEdge), then a w direction of uEdge x vEdge will be used for the w direction.
wLengthif wLength > 0, this will be used as the length of the block in the w direction. If wLength <= 0, the length of the wEdge vector will be used. If BOTH wLength<0 and the w direction was computed from a cross product as described above, then the wLength will be set to 1.0.
Returns
the BasicShape pointer, or nullptr if invalid data was provided

◆ makeBoundedCone()

BasicShape * BasicShape::makeBoundedCone ( const cryph::AffPoint &  Pbottom,
const cryph::AffPoint &  Ptop,
double  radiusAtBottom,
double  radiusAtTop,
int  nPointsAroundSide = 10,
int  nPointsAlongAxis = 2,
Caps  capSpec = CAP_AT_BOTH,
double  sMin = 0,
double  sMax = 0,
double  tMin = 0,
double  tMax = 0,
const cryph::AffVector &  sZero = cryph::AffVector::xu 
)
static

A factory method to create a piecewise linear approximation to a bounded cone. Texture coordinates are generated only if (sMax>sMin) AND (tMax>tMin). If texture coordinates are generated, the 's' texture direction is around the circumference of the cone; the 't' texture direction is along a cone ruling. If invalid input is given (negative radii, coincident points, or any other invalid specification), nullptr is returned.

Parameters
Pbottomthe (x,y,z) coordinates for the bottom of the cone
Ptopthe (x,y,z) coordinates for the top of the cone
radiusAtBottomthe radius of the circular cross section at Pbottom
radiusAtTopthe radius of the circular cross section at Ptop (if radiusAtBottom==radiusAtTop, the BasicShape will be equivalent to a cylinder)
nPointsAroundSidethe number of points in the piecewise linear approximation to the cone that will be generated around a circular cross section. Must be at least 3.
nPointsAlongAxisthe number of points in the piecewise linear approximation to the cone that will be generated along a cone ruling. This must be at least 2. Moreover, 2 is generally perfectly adequate.
capSpecspecifies whether circular disks will be generated at the top and/or bottom of the generated cone shape. Any created disks are created as a GL_TRIANGLE_FAN, reusing the points on the top and/or bottom piecewise linear cross section.
sMinthe 's' texture coordinate associated with the sZero vector direction described below
sMaxthe 's' texture coordinate associated with the final point generated on the circular cross section.
tMinthe 't' texture coordinate associated with the bottom of the cone
tMaxthe 't' texture coordinate associated with the top of the cone
sZerothe component of the optional vector "sZero" that is perpendicular to the axis of the cone (axis = Ptop - Pbottom) will define the direction for texture s coordinate=0. It serves no other externally significant purpose. If the component of "sZero" perpendicular to the axis is the zero vector, an arbitrary vector perpendicular to the axis is used.
Returns
the BasicShape pointer, or nullptr if invalid data was provided

◆ makeBoundedCylinder()

BasicShape * BasicShape::makeBoundedCylinder ( const cryph::AffPoint &  Pbottom,
const cryph::AffPoint &  Ptop,
double  radius,
int  nPointsAroundSide = 10,
int  nPointsAlongAxis = 2,
Caps  capSpec = CAP_AT_BOTH,
double  sMin = 0,
double  sMax = 0,
double  tMin = 0,
double  tMax = 0,
const cryph::AffVector &  sZero = cryph::AffVector::xu 
)
static

A factory method to create a piecewise linear approximation to a bounded cylinder. Texture coordinates are generated only if (sMax>sMin) AND (tMax>tMin). If texture coordinates are generated, the 's' texture direction is around the circumference of the cylinder; the 't' texture direction is along a cylinder ruling. If invalid input is given (negative radius, coincident points, or any other invalid specification), nullptr is returned.

Parameters
Pbottomthe (x,y,z) coordinates for the bottom of the cylinder
Ptopthe (x,y,z) coordinates for the top of the cylinder
radiusthe radius of the cylinder
nPointsAroundSidethe number of points in the piecewise linear approximation to the cylinder that will be generated around a circular cross section. Must be at least 3.
nPointsAlongAxisthe number of points in the piecewise linear approximation to the cylinder that will be generated along a cylinder ruling. This must be at least 2. Moreover, 2 is generally perfectly adequate.
capSpecspecifies whether circular disks will be generated at the top and/or bottom of the generated cylinder shape. Any created disks are created as a GL_TRIANGLE_FAN, reusing the points on the top and/or bottom piecewise linear cross section.
sMinthe 's' texture coordinate associated with the sZero vector direction described below
sMaxthe 's' texture coordinate associated with the final point generated on the circular cross section.
tMinthe 't' texture coordinate associated with the bottom of the cylinder
tMaxthe 't' texture coordinate associated with the top of the cylinder
sZerothe component of the optional vector "sZero" that is perpendicular to the axis of the cylinder (axis = Ptop - Pbottom) will define the direction for texture s coordinate=0. It serves no other externally significant purpose. If the component of "sZero" perpendicular to the axis is the zero vector, an arbitrary vector perpendicular to the axis is used.
Returns
the BasicShape pointer, or nullptr if invalid data was provided

◆ makeSphere()

BasicShape * BasicShape::makeSphere ( const cryph::AffPoint &  center,
double  radius,
int  nPointsAroundSide = 15,
int  nPointsAlongAxis = 15,
double  sMin = 0,
double  sMax = 0,
double  tMin = 0,
double  tMax = 0,
const cryph::AffVector &  upAxis = cryph::AffVector::yu,
const cryph::AffVector &  sZero = cryph::AffVector::xu 
)
static

A factory method to create a piecewise linear approximation to a sphere. Texture coordinates are generated only if (sMax>sMin) AND (tMax>tMin). If texture coordinates are generated, the 's' texture direction is determined by the sZero vector described below, and the 't' texture direction is determined by the upAxis vector described below. If invalid input is given (negative radius or any other invalid specification), nullptr is returned.

Parameters
centerthe (x,y,z) coordinates of the center of the sphere
radiusthe radius of the sphere
nPointsAroundSidethe number of points in the piecewise linear approximation to the sphere that will be generated around a circular cross section perpendicular to the upAxis described below. Must be at least 3.
nPointsAlongAxisthe number of points in the piecewise linear approximation to the sphere that will be generated along circular cross sections in the upAxis direction. Must be at least 3. In general, an odd number will work best because that forces points along the equator to be generated.
sMinthe 's' texture coordinate associated with the sZero vector direction described below
sMaxthe 's' texture coordinate associated with the final point generated on the circular cross section
tMinthe 't' texture coordinate associated with the bottom of the sphere as determined by the -upAxis vector
tMaxthe 't' texture coordinate associated with the top of the sphere as determined by the +upAxis vector
upAxisdetermines the top/bottom directions for the sphere, hence where the "north pole" and "south pole" are located.
sZerothe component of the optional vector "sZero" that is perpendicular to upAxis will define the direction for texture s coordinate=0. It serves no other externally significant purpose. If the component of "sZero" perpendicular to upAxis is the zero vector, an arbitrary vector perpendicular to upAxis is used.
Returns
the BasicShape pointer, or nullptr if invalid data was provided

◆ makeTorus()

BasicShape * BasicShape::makeTorus ( const cryph::AffPoint &  center,
const cryph::AffVector &  u,
const cryph::AffVector &  v,
double  rMajor,
double  rMinor,
double  thetaMinDegrees = 0.0,
double  thetaMaxDegrees = 360.0,
double  phiMinDegrees = 0,
double  phiMaxDegrees = 360.0,
int  nPointsInThetaDirection = 60,
int  nPointsInPhiDirection = 40,
double  sMin = 0,
double  sMax = 0,
double  tMin = 0,
double  tMax = 0 
)
static

A factory method to create a piecewise linear approximation to a torus. A point on the torus at (theta, phi) is computed as:

         toOuter = cos(theta)*u + sin(theta)*v
         normal = cos(phi)*toOuter + sin(phi)*w
         pntOnTorus = center + rMajor*toOuter + rMinor*normal
     where
         w = u x v

Texture coordinates are generated only if (sMax>sMin) AND (tMax>tMin). If texture coordinates are generated, the 's' texture direction is in the theta direction; the 't' texture direction is in the phi direction. (s=0 ==> u; t=0 ==> toOuter) If invalid input is given (negative radius, coincident points, or any other invalid specification), nullptr is returned.

Parameters
centerthe (x,y,z) coordinates for the center of the torus
uLocal x axis
vLocal y-axis
rMajorThe radius from the center to the outer ring
rMinorThe (typically smaller) radius of the cross-section with a plane containing center and w = u x v
nPointsInThetaDirectionthe number of points generated in the theta direction for each phi
nPointsInPhiDirectionthe number of points generated in the phi direction for each theta
sMinthe 's' texture coordinate associated with the sZero vector direction described below
sMaxthe 's' texture coordinate associated with the final point generated on the circular cross section.
tMinthe 't' texture coordinate associated with the bottom of the cylinder
tMaxthe 't' texture coordinate associated with the top of the cylinder
Returns
the BasicShape pointer, or nullptr if invalid data was provided

◆ setAlwaysGeneratePerVertexNormals()

void BasicShape::setAlwaysGeneratePerVertexNormals ( bool  b)
static

A method that can be used to force BasicShape instances to always generate per-vertex normals, regardless of whether they are actually needed. This is largely for experimental purposes. Use of this method is highly discouraged. Among other things, it can negatively impact the ability to use the "thisStartsFace" functionality described in getDrawArraysData and getIndexList.


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