StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
Primitive.hpp
1#pragma once
2#ifdef StevEngine_RENDERER_GL
3#include "renderer/RenderComponent.hpp"
4#include "utilities/Vertex.hpp"
5#include "visuals/renderer/Object.hpp"
6#include "visuals/Material.hpp"
7
8#define CUBE_PRIMITIVE_TYPE "CubePrimitive"
9#define UVSPHERE_PRIMITIVE_TYPE "UVSpherePrimitive"
10#define ICOSPHERE_PRIMITIVE_TYPE "IcoSpherePrimitive"
11#define CYLINDER_PRIMITIVE_TYPE "CylinderPrimitive"
12#define CAPSULE_PRIMITIVE_TYPE "CapsulePrimitive"
13
14#define RADIUS 0.5
15
16const double phi = (1 + sqrt(5)) / 2;
17
18namespace StevEngine {
19 namespace Visuals {
23 enum TextureType {
24 REPEAT,
25 COVER
26 };
27
31 const std::vector<Utilities::Vertex> CubeVertices(TextureType textureType);
32
40 public:
54 const Material& material = Material(),
55 TextureType textureType = REPEAT,
56 Renderer::RenderType renderType = Renderer::SOLID
57 );
58
64
69 std::string GetType() const { return CUBE_PRIMITIVE_TYPE; }
70
76 Utilities::Stream Export(Utilities::StreamType type) const;
77
78 const Visuals::TextureType textureType;
79 };
80
84 const std::vector<Utilities::Vertex> UVSphereVertices(TextureType textureType, bool smooth, int detail = 30, float height = RADIUS);
85
93 public:
108 Material material = Material(),
109 bool smooth = true,
110 TextureType textureType = COVER,
111 Renderer::RenderType renderType = Renderer::SOLID
112 );
113
119
124 std::string GetType() const { return UVSPHERE_PRIMITIVE_TYPE; }
125
131 Utilities::Stream Export(Utilities::StreamType type) const;
132
133 const Visuals::TextureType textureType;
134 const bool smooth;
135 };
136
140 const std::vector<Utilities::Vertex> IcosphereVertices(TextureType textureType, bool smooth, int detail = 3);
141
149 public:
164 Material material = Material(),
165 bool smooth = true,
166 TextureType textureType = COVER,
167 Renderer::RenderType renderType = Renderer::SOLID
168 );
169
175
180 std::string GetType() const { return ICOSPHERE_PRIMITIVE_TYPE; }
181
187 Utilities::Stream Export(Utilities::StreamType type) const;
188
189 const Visuals::TextureType textureType;
190 const bool smooth;
191 };
192
196 const std::vector<Utilities::Vertex> CylinderVertices(TextureType textureType, bool smooth, int detail = 30, double height = RADIUS);
197
205 public:
220 Material material = Material(),
221 bool smooth = true,
222 TextureType textureType = COVER,
223 Renderer::RenderType renderType = Renderer::SOLID
224 );
225
231
236 std::string GetType() const { return CYLINDER_PRIMITIVE_TYPE; }
237
243 Utilities::Stream Export(Utilities::StreamType type) const;
244
245 const Visuals::TextureType textureType;
246 const bool smooth;
247 };
248
252 const std::vector<Utilities::Vertex> CapsuleVertices(TextureType textureType, bool smooth, int detail = 30);
253
261 public:
276 Material material = Material(),
277 bool smooth = true,
278 TextureType textureType = COVER,
279 Renderer::RenderType renderType = Renderer::SOLID
280 );
281
287
292 std::string GetType() const { return CAPSULE_PRIMITIVE_TYPE; }
293
299 Utilities::Stream Export(Utilities::StreamType type) const;
300
301 const Visuals::TextureType textureType;
302 const bool smooth;
303 };
304
306 inline bool cube = CreateComponents::RegisterComponentType<CubePrimitive>(CUBE_PRIMITIVE_TYPE);
307 inline bool sphere = CreateComponents::RegisterComponentType<UVSpherePrimitive>(UVSPHERE_PRIMITIVE_TYPE);
308 inline bool icosphere = CreateComponents::RegisterComponentType<IcospherePrimitive>(ICOSPHERE_PRIMITIVE_TYPE);
309 inline bool cylinder = CreateComponents::RegisterComponentType<CylinderPrimitive>(CYLINDER_PRIMITIVE_TYPE);
310 inline bool capsule = CreateComponents::RegisterComponentType<CapsulePrimitive>(CAPSULE_PRIMITIVE_TYPE);
311 }
312}
313#endif
static bool RegisterComponentType(std::string type)
Register a component type for creation.
Definition Component.hpp:133
Base component for renderable objects.
Definition RenderComponent.hpp:19
Utilities::Quaternion rotation
Local position offset.
Definition RenderComponent.hpp:51
Utilities::Vector3 scale
Local rotation offset.
Definition RenderComponent.hpp:52
Quaternion for 3D rotations.
Definition Quaternion.hpp:17
Stream for serialization of data.
Definition Stream.hpp:22
3D vector class
Definition Vector3.hpp:17
std::string GetType() const
Get component type.
Definition Primitive.hpp:292
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Primitive.cpp:653
const bool smooth
Whether to use smooth shading.
Definition Primitive.hpp:302
CapsulePrimitive(Utilities::Vector3 position=Utilities::Vector3(), Utilities::Quaternion rotation=Utilities::Quaternion(), Utilities::Vector3 scale=Utilities::Vector3(1), Material material=Material(), bool smooth=true, TextureType textureType=COVER, Renderer::RenderType renderType=Renderer::SOLID)
Create capsule primitive.
Definition Primitive.cpp:646
const Visuals::TextureType textureType
Texture mapping mode.
Definition Primitive.hpp:301
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Primitive.cpp:118
const Visuals::TextureType textureType
Texture mapping mode.
Definition Primitive.hpp:78
std::string GetType() const
Get component type.
Definition Primitive.hpp:69
CubePrimitive(Utilities::Vector3 position=Utilities::Vector3(), Utilities::Quaternion rotation=Utilities::Quaternion(), Utilities::Vector3 scale=Utilities::Vector3(1), const Material &material=Material(), TextureType textureType=REPEAT, Renderer::RenderType renderType=Renderer::SOLID)
Create cube primitive.
Definition Primitive.cpp:109
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Primitive.cpp:584
std::string GetType() const
Get component type.
Definition Primitive.hpp:236
const bool smooth
Whether to use smooth shading.
Definition Primitive.hpp:246
CylinderPrimitive(Utilities::Vector3 position=Utilities::Vector3(), Utilities::Quaternion rotation=Utilities::Quaternion(), Utilities::Vector3 scale=Utilities::Vector3(1), Material material=Material(), bool smooth=true, TextureType textureType=COVER, Renderer::RenderType renderType=Renderer::SOLID)
Create cylinder primitive.
Definition Primitive.cpp:576
const Visuals::TextureType textureType
Texture mapping mode.
Definition Primitive.hpp:245
IcospherePrimitive(Utilities::Vector3 position=Utilities::Vector3(), Utilities::Quaternion rotation=Utilities::Quaternion(), Utilities::Vector3 scale=Utilities::Vector3(1), Material material=Material(), bool smooth=true, TextureType textureType=COVER, Renderer::RenderType renderType=Renderer::SOLID)
Create icosphere primitive.
Definition Primitive.cpp:444
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Primitive.cpp:453
const Visuals::TextureType textureType
Texture mapping mode.
Definition Primitive.hpp:189
const bool smooth
Whether to use smooth shading.
Definition Primitive.hpp:190
std::string GetType() const
Get component type.
Definition Primitive.hpp:180
Material properties for rendering.
Definition Material.hpp:14
UVSpherePrimitive(Utilities::Vector3 position=Utilities::Vector3(), Utilities::Quaternion rotation=Utilities::Quaternion(), Utilities::Vector3 scale=Utilities::Vector3(1), Material material=Material(), bool smooth=true, TextureType textureType=COVER, Renderer::RenderType renderType=Renderer::SOLID)
Create UV sphere primitive.
Definition Primitive.cpp:252
std::string GetType() const
Get component type.
Definition Primitive.hpp:124
Utilities::Stream Export(Utilities::StreamType type) const
Serialize component to a stream.
Definition Primitive.cpp:261
const bool smooth
Whether to use smooth shading.
Definition Primitive.hpp:134
const Visuals::TextureType textureType
Texture mapping mode.
Definition Primitive.hpp:133