CMSC23740 Common Code Library
Support code for CS23740 programming projects
Loading...
Searching...
No Matches
gobjects.hpp
Go to the documentation of this file.
1
12/*
13 * COPYRIGHT (c) 2024 John Reppy (https://cs.uchicago.edu/~jhr)
14 * All rights reserved.
15 */
16
17#ifndef _CS237_GOBJECTS_HPP_
18#define _CS237_GOBJECTS_HPP_
19
20#ifndef _CS237_HPP_
21#error "cs237/gobjects.hpp should not be included directly"
22#endif
23
24namespace OBJ {
25 struct Group;
26}
27
28namespace cs237 {
29namespace gobj {
30
32constexpr uint32_t kVAttrPosBit = (1 << 0);
33constexpr uint32_t kVAttrNormBit = (1 << 1);
34constexpr uint32_t kVAttrTCBit = (1 << 2);
35constexpr uint32_t kVAttrTanBit = (1 << 3);
36
37
39//
46
48inline bool hasNormals (VertexAttrs attrs)
49{
50 return ((static_cast<uint32_t>(attrs) & kVAttrNormBit) != 0);
51}
52
54inline bool hasTextureCoords (VertexAttrs attrs)
55{
56 return ((static_cast<uint32_t>(attrs) & kVAttrTCBit) != 0);
57}
58
60struct Obj {
61 std::string name;
62 uint32_t nVerts;
63 uint32_t nIndices;
64 glm::vec3 *verts;
65 glm::vec3 *norms;
66 glm::vec2 *txtCoords;
67 uint32_t *indices;
69
70 Obj ()
71 : nVerts(0), nIndices(0),
72 verts(nullptr), norms(nullptr), txtCoords(nullptr),
73 indices(nullptr)
74 { }
75
76 Obj (Obj &) = delete;
77 Obj (Obj const &) = delete;
78 Obj (Obj &&) = delete;
79
80 Obj (std::string_view s)
81 : name(std::string(s)), nVerts(0), nIndices(0),
82 verts(nullptr), norms(nullptr), txtCoords(nullptr),
83 indices(nullptr)
84 { }
85
86 Obj (std::string_view s, uint32_t nv, uint32_t ni)
87 : name(std::string(s)), nVerts(nv), nIndices(ni),
88 verts(new glm::vec3[nv]), norms(nullptr), txtCoords(nullptr),
89 indices(new uint32_t[ni])
90 { }
91
93 {
94 if (this->verts != nullptr) { delete [] this->verts; }
95 if (this->norms != nullptr) { delete [] this->norms; }
96 if (this->txtCoords != nullptr) { delete [] this->txtCoords; }
97 if (this->indices != nullptr) { delete [] this->indices; }
98 }
99};
100
107Obj *cube (VertexAttrs attrs, glm::vec3 center, float width);
108
122 VertexAttrs attrs,
123 glm::vec3 center,
124 float radius,
125 uint32_t slices,
126 uint32_t stacks);
127
144 VertexAttrs attrs,
145 glm::vec3 pos,
146 glm::vec3 dir,
147 float radius,
148 float height,
149 uint32_t slices,
150 uint32_t stacks);
151
152} // namespace gobj
153} // namespace cs237
154
155#endif // !_CS237_GOBJECTS_HPP_
Definition obj.hpp:19
bool hasNormals(VertexAttrs attrs)
Does a vertex attribute specification include normals?
Definition gobjects.hpp:48
constexpr uint32_t kVAttrNormBit
normal vector attribute
Definition gobjects.hpp:33
VertexAttrs
specifying the attributes of the generated object
Definition gobjects.hpp:40
@ ePosNormTex
all attributes
@ ePosTex
position+texture coord
@ ePosNorm
position+normal
constexpr uint32_t kVAttrPosBit
bit mask for the various vertex attributes
Definition gobjects.hpp:32
Obj * cube(VertexAttrs attrs, glm::vec3 center, float width)
Obj * sphere(VertexAttrs attrs, glm::vec3 center, float radius, uint32_t slices, uint32_t stacks)
Obj * cone(VertexAttrs attrs, glm::vec3 pos, glm::vec3 dir, float radius, float height, uint32_t slices, uint32_t stacks)
bool hasTextureCoords(VertexAttrs attrs)
Does a vertex attribute specification include texture coordinates?
Definition gobjects.hpp:54
constexpr uint32_t kVAttrTCBit
texture coordinate attribute
Definition gobjects.hpp:34
constexpr uint32_t kVAttrTanBit
tangent vector attribute
Definition gobjects.hpp:35
Definition aabb.hpp:22
a geometric object
Definition gobjects.hpp:60
glm::vec3 * verts
array of nVerts vertex coordinates
Definition gobjects.hpp:64
Obj()
Definition gobjects.hpp:70
glm::vec3 * norms
array of nVerts normal vectors (or nullptr)
Definition gobjects.hpp:65
Obj(Obj const &)=delete
Obj(std::string_view s, uint32_t nv, uint32_t ni)
Definition gobjects.hpp:86
Obj(Obj &&)=delete
uint32_t nIndices
the number of indices (3 * number of triangles)
Definition gobjects.hpp:63
glm::vec2 * txtCoords
array of nVerts texture coordinates (or nullptr)
Definition gobjects.hpp:66
uint32_t * indices
Definition gobjects.hpp:67
std::string name
object name ("cube", etc.)
Definition gobjects.hpp:61
Obj(Obj &)=delete
~Obj()
Definition gobjects.hpp:92
Obj(std::string_view s)
Definition gobjects.hpp:80
uint32_t nVerts
the number of vertices in this group.
Definition gobjects.hpp:62