Basic Shape Creation and Rendering
2.0
Tools to create and render common shapes like blocks, cylinders, cones, and spheres
|
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 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 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 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 BasicShape * | makeSphere (const cryph::AffPoint ¢er, 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 BasicShape * | makeTorus (const cryph::AffPoint ¢er, 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) |
enum BasicShape::Caps |
An enumerated type that allows specification of whether cylinders and cones should have planar caps at the top and/or at the bottom.
|
virtual |
The destructor
|
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.
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
i | the glDrawArrays data desired (0 <= i < getNumDrawArraysCalls()) |
mode | the OpenGL draw mode to be used |
thisStartsFace | an 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.) |
offset | the offset parameter to be passed to glDrawArrays |
canUseVertexTexCoords | true if and only if texture mapping is being used |
canUseNormalArray | true if and only if a normal vector VBO should be enabled; otherwise the normal will be set by passing fixedN to glVertexAttrib |
fixedN | the normal vectior to be used if canUseNormalArray is false |
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
i | the glDrawElements data desired (0 <= i < getNumIndexLists()) |
mode | the OpenGL draw mode to be used |
thisStartsFace | an 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.) |
nInList | the number of indices in the returned index list |
type | the type of the indices to be specified to glDrawElements |
canUseVertexTexCoords | true if and only if texture mapping is being used |
canUseNormalArray | true if and only if a normal vector VBO should be enabled; otherwise the normal will be set by passing fixedN to glVertexAttrib |
fixedN | the normal vectior to be used if canUseNormalArray is false |
void BasicShape::getMCBoundingBox | ( | double * | xyzLimits | ) | const |
Retrieve the MC bounding box for the BasicShape instance
xyzLimits | the {xmin, xmax, ymin, ymax, zmin, zmax} bounds will be returned in this parameter. It is assumed to be at least of length 6. |
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
inline |
An accessor method intended to be used only by class BasicShapeRenderer
|
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.
llCorner | the (x,y,z) coordinates of the corner of the block |
uEdge | a vector specifying the u direction of the block. If this is a zero vector, nullptr is returned. |
uLength | if 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. |
vEdge | a 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. |
vLength | if 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. |
wEdge | a 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. |
wLength | if 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. |
|
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.
Pbottom | the (x,y,z) coordinates for the bottom of the cone |
Ptop | the (x,y,z) coordinates for the top of the cone |
radiusAtBottom | the radius of the circular cross section at Pbottom |
radiusAtTop | the radius of the circular cross section at Ptop (if radiusAtBottom==radiusAtTop, the BasicShape will be equivalent to a cylinder) |
nPointsAroundSide | the 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. |
nPointsAlongAxis | the 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. |
capSpec | specifies 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. |
sMin | the 's' texture coordinate associated with the sZero vector direction described below |
sMax | the 's' texture coordinate associated with the final point generated on the circular cross section. |
tMin | the 't' texture coordinate associated with the bottom of the cone |
tMax | the 't' texture coordinate associated with the top of the cone |
sZero | the 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. |
|
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.
Pbottom | the (x,y,z) coordinates for the bottom of the cylinder |
Ptop | the (x,y,z) coordinates for the top of the cylinder |
radius | the radius of the cylinder |
nPointsAroundSide | the 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. |
nPointsAlongAxis | the 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. |
capSpec | specifies 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. |
sMin | the 's' texture coordinate associated with the sZero vector direction described below |
sMax | the 's' texture coordinate associated with the final point generated on the circular cross section. |
tMin | the 't' texture coordinate associated with the bottom of the cylinder |
tMax | the 't' texture coordinate associated with the top of the cylinder |
sZero | the 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. |
|
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.
center | the (x,y,z) coordinates of the center of the sphere |
radius | the radius of the sphere |
nPointsAroundSide | the 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. |
nPointsAlongAxis | the 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. |
sMin | the 's' texture coordinate associated with the sZero vector direction described below |
sMax | the 's' texture coordinate associated with the final point generated on the circular cross section |
tMin | the 't' texture coordinate associated with the bottom of the sphere as determined by the -upAxis vector |
tMax | the 't' texture coordinate associated with the top of the sphere as determined by the +upAxis vector |
upAxis | determines the top/bottom directions for the sphere, hence where the "north pole" and "south pole" are located. |
sZero | the 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. |
|
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.
center | the (x,y,z) coordinates for the center of the torus |
u | Local x axis |
v | Local y-axis |
rMajor | The radius from the center to the outer ring |
rMinor | The (typically smaller) radius of the cross-section with a plane containing center and w = u x v |
nPointsInThetaDirection | the number of points generated in the theta direction for each phi |
nPointsInPhiDirection | the number of points generated in the phi direction for each theta |
sMin | the 's' texture coordinate associated with the sZero vector direction described below |
sMax | the 's' texture coordinate associated with the final point generated on the circular cross section. |
tMin | the 't' texture coordinate associated with the bottom of the cylinder |
tMax | the 't' texture coordinate associated with the top of the cylinder |
|
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.