Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shapeutils.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFXUTILS_SHAPEUTILS_H_
19 #define ION_GFXUTILS_SHAPEUTILS_H_
20 
23 
24 #include <functional>
25 #include <istream> // NOLINT
26 
27 #include "ion/base/allocator.h"
28 #include "ion/gfx/bufferobject.h"
29 #include "ion/gfx/indexbuffer.h"
30 #include "ion/gfx/shape.h"
31 #include "ion/math/angle.h"
32 #include "ion/math/matrix.h"
33 #include "ion/math/vector.h"
34 
35 namespace ion {
36 namespace gfxutils {
37 
40 struct ShapeSpec {
44  enum VertexType {
45  kPosition, // Position only.
46  kPositionTexCoords, // Position and texture coordinates.
47  kPositionNormal, // Position and normal.
48  kPositionTexCoordsNormal, // Position, texture coordinates, and normal.
49  };
50  ShapeSpec() : translation(math::Point3f::Zero()),
51  scale(1.f),
52  rotation(math::Matrix3f::Identity()),
54  usage_mode(gfx::BufferObject::kStaticDraw) {}
55  base::AllocatorPtr allocator; // Used for all allocations (NULL).
57  math::Point3f translation; // Translation (0, 0, 0).
58  float scale; // Scale factor (1).
59  math::Matrix3f rotation; // Rotation (Identity).
60  VertexType vertex_type; // Type of vertices (kPositionTexCoordsNormal).
64 };
65 
67 
72 
73 
82  const gfx::IndexBufferPtr& tri_index_buffer);
83 
85 
90 
91 
92 struct ExternalShapeSpec : public ShapeSpec {
95  enum Format {
96  k3ds, // Autodesk 3D Studio format.
97  kDae, // Collada Digital Asset Exchange 1.4/1.5 formats.
98  kLwo, // Lightwave Object format.
99  kObj, // Wavefront Object format.
100  kOff, // Geomview file format.
101  kUnknown, // Used as initial value in spec.
102  };
105  enum IndexSize {
106  k16Bit, // 16-bit indices (unsigned short integer).
107  k32Bit, // 32-bit indices (unsigned integer).
108  };
118 };
119 
125 ION_API const gfx::ShapePtr LoadExternalShape(const ExternalShapeSpec& spec,
126  std::istream& in); // NOLINT
127 
129 
134 
135 
139 struct PlanarShapeSpec : public ShapeSpec {
144  enum PlaneNormal {
145  kPositiveX, // In YZ-plane, facing +X, width in Z, +S with -Z, +T with +Y.
146  kNegativeX, // In YZ-plane, facing -X, width in Z, +S with +Z, +T with +Y.
147  kPositiveY, // In XZ-plane, facing +Y, width in X, +S with +X, +T with -Z.
148  kNegativeY, // In XZ-plane, facing -Y, width in X, +S with +X, +T with +Z.
149  kPositiveZ, // In XY-plane, facing +Z, width in X, +S with +X, +T with +Y.
150  kNegativeZ, // In XY-plane, facing -Z, width in X, +S with -X, +T with +Y.
151  };
153  PlaneNormal plane_normal; // Orientation of plane (kPositiveZ).
154 };
155 
157 
162 
163 
168  RectangleSpec() : size(1.f, 1.f) {}
169  math::Vector2f size; // Size of rectangle (1x1).
170 };
171 
174 ION_API const gfx::ShapePtr BuildRectangleShape(const RectangleSpec& spec);
175 
177 
182 
183 
190  int sides; // The number of sides in the polygon.
191 };
192 
195  const RegularPolygonSpec& spec);
196 
198 
203 
204 
207 struct BoxSpec : public ShapeSpec {
208  BoxSpec() : size(1.f, 1.f, 1.f) {}
209  math::Vector3f size; // Size of box (1x1x1).
210 };
211 
213 ION_API const gfx::ShapePtr BuildBoxShape(const BoxSpec& spec);
214 
216 
221 
222 
238 struct EllipsoidSpec : public ShapeSpec {
240  : longitude_start(math::Anglef::FromDegrees(0.f)),
241  longitude_end(math::Anglef::FromDegrees(360.f)),
242  latitude_start(math::Anglef::FromDegrees(-90.f)),
243  latitude_end(math::Anglef::FromDegrees(90.f)),
244  band_count(10U),
245  sector_count(10U),
246  size(1.f, 1.f, 1.f) {}
247 
248  math::Anglef longitude_start; // Start longitude angle (0 degrees)
249  math::Anglef longitude_end; // End longitude angle (360 degrees)
250  math::Anglef latitude_start; // Start latitude angle (-90 degrees)
251  math::Anglef latitude_end; // End latitude angle (90 degrees)
252  size_t band_count; // Number of latitudinal bands (10).
253  size_t sector_count; // Number of longitudinal sectors (10).
254  math::Vector3f size; // Size of ellipsoid (1x1x1).
255 };
256 
258 ION_API const gfx::ShapePtr BuildEllipsoidShape(const EllipsoidSpec& spec);
259 
261 
266 
267 
283 struct CylinderSpec : public ShapeSpec {
285  : has_top_cap(true),
286  has_bottom_cap(true),
287  shaft_band_count(1U),
288  cap_band_count(1U),
289  sector_count(10U),
290  top_radius(.5f),
291  bottom_radius(.5f),
292  height(1.f) {}
293  bool has_top_cap; // Whether the top cap is present (true).
294  bool has_bottom_cap; // Whether the bottom cap is present (true).
295  size_t shaft_band_count; // Number of bands in the shaft (1).
296  size_t cap_band_count; // Number of bands in each cap (1).
297  size_t sector_count; // Number of longitudinal sectors (10).
298  float top_radius; // Radius of top of cylinder (.5).
299  float bottom_radius; // Radius of bottom of cylinder (.5).
300  float height; // Height of cylinder (1).
301 };
302 
304 ION_API const gfx::ShapePtr BuildCylinderShape(const CylinderSpec& spec);
305 
306 } // namespace gfxutils
307 } // namespace ion
308 
309 #endif // ION_GFXUTILS_SHAPEUTILS_H_
This struct contains specifications common to all basic shapes.
Definition: shapeutils.h:40
IndexSize index_size
The size of the vertex index data type.
Definition: shapeutils.h:117
math::Matrix3f rotation
Definition: shapeutils.h:59
Angle< float > Anglef
Type-specific typedefs.
Definition: angle.h:156
Matrix< 3, float > Matrix3f
Definition: matrix.h:369
External geometry formats.
Definition: shapeutils.h:92
const gfx::ShapePtr BuildEllipsoidShape(const EllipsoidSpec &spec)
Builds and returns a Shape representing an axis-aligned ellipsoid.
Definition: shapeutils.cc:1320
gfx::BufferObject::UsageMode usage_mode
UsageMode for all created BufferObject instances.
Definition: shapeutils.h:63
const gfx::ShapePtr BuildCylinderShape(const CylinderSpec &spec)
Builds and returns a Shape representing an axis-aligned cylinder.
Definition: shapeutils.cc:1330
const gfx::IndexBufferPtr BuildWireframeIndexBuffer(const gfx::IndexBufferPtr &tri_index_buffer)
Public functions.
Definition: shapeutils.cc:1236
const gfx::ShapePtr LoadExternalShape(const ExternalShapeSpec &spec, std::istream &in)
Loads a Shape with the specified format from the passed stream.
Definition: shapeutils.cc:1272
VertexType
This enum is used to specify what per-vertex attributes should be included in a Shape.
Definition: shapeutils.h:44
const gfx::ShapePtr BuildRegularPolygonShape(const RegularPolygonSpec &spec)
Builds and returns a Shape representing a flat regular polygon.
Definition: shapeutils.cc:1300
Format
The set of external geometry file formats that can be read with LoadExternalShape().
Definition: shapeutils.h:95
const gfx::ShapePtr BuildBoxShape(const BoxSpec &spec)
Builds and returns a Shape representing an axis-aligned box.
Definition: shapeutils.cc:1310
IndexSize
The size of the vertex index data type.
Definition: shapeutils.h:105
PlaneNormal
This enum specifies the principal Cartesian plane containing the rectangle by its directed normal...
Definition: shapeutils.h:144
bool center_at_origin
Whether to center the loaded object at the origin (defaults to true).
Definition: shapeutils.h:115
math::Vector3f size
Definition: shapeutils.h:209
math::Point3f translation
The order of operations is: scale, then rotate, then translate.
Definition: shapeutils.h:57
base::AllocatorPtr allocator
Definition: shapeutils.h:55
const gfx::ShapePtr BuildRectangleShape(const RectangleSpec &spec)
Builds and returns a Shape representing a rectangle in one of the principal Cartesian planes...
Definition: shapeutils.cc:1290