ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Object3D.cpp
Go to the documentation of this file.
1#include "Object3D.h"
2
3Object3D::Object3D(IStaticTriangleGroup* originalTriangles, ITriangleGroup* modifiedTriangles, Material* material) : originalTriangles(originalTriangles), modifiedTriangles(modifiedTriangles) {
4 this->material = material;
5}
6
8
10 enabled = true;
11}
12
14 enabled = false;
15}
16
18 return enabled;
19}
20
22 Vector3D center;
23
24 for (int i = 0; i < modifiedTriangles->GetVertexCount(); i++) {
25 center = center + modifiedTriangles->GetVertices()[i];
26 }
27
28 return center.Divide(modifiedTriangles->GetVertexCount());
29}
30
32 for (int i = 0; i < modifiedTriangles->GetVertexCount(); i++) {
33 minimum = Vector3D::Min(minimum, modifiedTriangles->GetVertices()[i]);
34 maximum = Vector3D::Max(maximum, modifiedTriangles->GetVertices()[i]);
35 }
36}
37
39 Vector3D min, max;
40
41 GetMinMaxDimensions(min, max);
42
43 return max - min;
44}
45
49
53
55 for (int i = 0; i < modifiedTriangles->GetVertexCount(); i++) {
57 }
58}
59
61 for (int i = 0; i < modifiedTriangles->GetVertexCount(); i++) {
62 Vector3D modifiedVector = modifiedTriangles->GetVertices()[i];
63
64 modifiedVector = (modifiedVector - transform.GetScaleOffset()) * transform.GetScale() + transform.GetScaleOffset();
66 modifiedVector = modifiedVector + transform.GetPosition();
67
68 modifiedTriangles->GetVertices()[i] = modifiedVector;
69 }
70}
71
75
79
81 this->material = material;
82}
Defines the Object3D class, representing a 3D object with geometry, material, and transformation data...
Interface for managing a static group of 3D triangles and associated data.
virtual const Vector3D * GetVertices()=0
Retrieves the array of vertices in the triangle group.
Interface for managing a dynamic group of 3D triangles and associated data.
virtual Vector3D * GetVertices()=0
Retrieves the array of mutable vertices in the triangle group.
virtual int GetVertexCount()=0
Retrieves the total number of vertices in the group.
Abstract base class for rendering materials.
Definition Material.h:27
void Disable()
Disables the object, making it invisible and inactive.
Definition Object3D.cpp:13
bool IsEnabled()
Checks if the object is enabled.
Definition Object3D.cpp:17
ITriangleGroup * modifiedTriangles
Pointer to the modifiable representation of the object's geometry.
Definition Object3D.h:32
IStaticTriangleGroup * originalTriangles
Pointer to the static representation of the object's geometry.
Definition Object3D.h:31
Transform transform
Transform object representing the object's position, rotation, and scale.
Definition Object3D.h:30
void ResetVertices()
Resets the object's vertices to their original positions.
Definition Object3D.cpp:54
void SetTransform(Transform &t)
Sets the object's transformation data.
Definition Object3D.cpp:50
Object3D(IStaticTriangleGroup *originalTriangles, ITriangleGroup *modifiedTriangles, Material *material)
Constructs an Object3D instance.
Definition Object3D.cpp:3
Material * GetMaterial()
Retrieves the material assigned to the object.
Definition Object3D.cpp:76
Vector3D GetSize()
Retrieves the size of the object.
Definition Object3D.cpp:38
bool enabled
Indicates whether the object is currently enabled.
Definition Object3D.h:34
~Object3D()
Destructor for Object3D.
Definition Object3D.cpp:7
Vector3D GetCenterOffset()
Retrieves the object's center offset.
Definition Object3D.cpp:21
void Enable()
Enables the object, making it visible and active.
Definition Object3D.cpp:9
void UpdateTransform()
Updates the object's geometry based on its transformation data.
Definition Object3D.cpp:60
void SetMaterial(Material *material)
Sets the material for the object.
Definition Object3D.cpp:80
ITriangleGroup * GetTriangleGroup()
Retrieves the modifiable geometry of the object.
Definition Object3D.cpp:72
void GetMinMaxDimensions(Vector3D &minimum, Vector3D &maximum)
Retrieves the minimum and maximum dimensions of the object.
Definition Object3D.cpp:31
Material * material
Pointer to the material assigned to the object.
Definition Object3D.h:33
Transform * GetTransform()
Retrieves the object's transformation data.
Definition Object3D.cpp:46
Vector2D RotateVector(const Vector2D &v) const
Rotates a 2D vector by this quaternion, projecting it in 2D.
Represents a 3D transformation including position, rotation, and scale.
Definition Transform.h:22
Vector3D GetRotationOffset()
Gets the rotation offset of the object.
Definition Transform.cpp:93
Quaternion GetRotation()
Gets the current rotation of the object.
Definition Transform.cpp:61
Vector3D GetPosition()
Gets the position of the object.
Definition Transform.cpp:69
Vector3D GetScaleOffset()
Gets the scale offset of the object.
Vector3D GetScale()
Gets the scale of the object.
Definition Transform.cpp:77
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
float Max() const
Returns the maximum component value among X, Y, Z.
Definition Vector3D.cpp:176
float Min() const
Returns the minimum component value among X, Y, Z.
Definition Vector3D.cpp:180
Vector3D Divide(const Vector3D &vector) const
Divides this vector by another Vector3D component-wise.
Definition Vector3D.cpp:74