ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BoundaryMotionSimulator.cpp
Go to the documentation of this file.
2
3BoundaryMotionSimulator::BoundaryMotionSimulator(Object3D** objects, int objectCount, BoundaryCube* bC, float radius, float elasticity) {
4 this->bC = bC;
5 this->sphereCount = objectCount;
6 this->elasticity = elasticity;
7
8 bS = new BoundarySphere*[objectCount];
9 for (int i = 0; i < objectCount; i++) {
10 bS[i] = new BoundarySphere(objects[i], radius);
11 }
12}
13
15 for (int i = 0; i < sphereCount; i++) {
16 bS[i]->velocity.X = ((float)random(0, 999) / 1000.0f) * range - range / 2.0f;
17 bS[i]->velocity.Y = ((float)random(0, 999) / 1000.0f) * range - range / 2.0f;
18 bS[i]->velocity.Z = ((float)random(0, 999) / 1000.0f) * range - range / 2.0f;
19 }
20}
21
23 Vector3D vRand;
24 vRand.X = 1.0f + ((float)random(0, 999) / 1000.0f) * range;
25 vRand.Y = 1.0f + ((float)random(0, 999) / 1000.0f) * range;
26 vRand.Z = 1.0f + ((float)random(0, 999) / 1000.0f) * range;
27 return vRand;
28}
29
30void BoundaryMotionSimulator::Update(float dT, Vector3D acceleration, Quaternion rotation) {
31 for (int i = 0; i < sphereCount; i++) {
32 bS[i]->Update(dT, acceleration * RandomRatio(2.0f), rotation);
33
34 for (int j = i + 1; j < sphereCount; j++) {
35 bS[i]->Collide(elasticity, bS[j]);
36 }
37
39 bS[i]->velocity = bS[i]->velocity * RandomRatio(0.0005f);
41 bS[i]->GetObject3D()->GetTransform()->SetPosition(bS[i]->position);
42 }
43}
Defines the BoundaryMotionSimulator class for simulating motion and collisions of boundary objects.
Represents an axis-aligned bounding cube for collision detection and physics.
void CollideSphere(float elasticity, BoundarySphere *bO)
Handles collision with a BoundarySphere.
void Randomize(float range)
Randomizes the velocities of all boundary spheres within a specified range.
void Update(float dT, Vector3D acceleration, Quaternion rotation)
Updates the simulation by applying physics and resolving collisions.
int sphereCount
Number of boundary spheres.
BoundaryMotionSimulator(Object3D **objects, int objectCount, BoundaryCube *bC, float radius, float elasticity)
Constructs a BoundaryMotionSimulator.
float elasticity
Elasticity coefficient for collisions.
Vector3D RandomRatio(float range)
Generates a randomized vector with ratios for X, Y, and Z axes.
BoundarySphere ** bS
Array of pointers to the boundary spheres.
BoundaryCube * bC
Pointer to the boundary cube.
Represents a spherical boundary object for motion and collision simulations.
void Update(float dT, Vector3D acceleration, Quaternion rotation)
Updates the sphere's position and velocity based on acceleration and rotation.
Vector3D velocity
Velocity vector of the sphere.
void Collide(float elasticity, BoundarySphere *bO)
Resolves collision between this sphere and another BoundarySphere.
Object3D * GetObject3D()
Gets the associated Object3D of the sphere.
Represents a 3D object with geometry, material, and transformation data.
Definition Object3D.h:28
void ResetVertices()
Resets the object's vertices to their original positions.
Definition Object3D.cpp:54
Transform * GetTransform()
Retrieves the object's transformation data.
Definition Object3D.cpp:46
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
void SetPosition(const Vector3D &position)
Sets the position of the object.
Definition Transform.cpp:65
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
float Z
The Z-component of the 3D vector.
Definition Vector3D.h:30
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29