ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
TriangleGroupDeformer.cpp
Go to the documentation of this file.
2
10
12 this->objects = objects;
13 this->objectCount = objectCount;
14}
15
16bool TriangleGroupDeformer::CheckClipAxis(Vector3D base, bool positive, Axis valueCheckAxis) {
17 if (valueCheckAxis == XAxis && positive && base.X > 0) {
18 return true;
19 } else if (valueCheckAxis == XAxis && !positive && base.X < 0) {
20 return true;
21 } else if (valueCheckAxis == YAxis && positive && base.Y > 0) {
22 return true;
23 } else if (valueCheckAxis == YAxis && !positive && base.Y < 0) {
24 return true;
25 } else if (valueCheckAxis == ZAxis && positive && base.Z > 0) {
26 return true;
27 } else if (valueCheckAxis == ZAxis && !positive && base.Z < 0) {
28 return true;
29 } else {
30 return false;
31 }
32}
33
34void TriangleGroupDeformer::SinusoidalDeform(float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis) {
35 for (int i = 0; i < objectCount; i++) {
36 for (int j = 0; j < objects[i]->GetVertexCount(); j++) {
37 Vector3D base = objects[i]->GetVertices()[j];
38
39 switch (axis) {
40 case XAxis:
41 objects[i]->GetVertices()[j].X = (sinf((base.Y) + timeRatio * frequencyModifier) * periodModifier + cosf((base.Z) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
42 break;
43 case YAxis:
44 objects[i]->GetVertices()[j].Y = (sinf((base.X) + timeRatio * frequencyModifier) * periodModifier + cosf((base.Z) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
45 break;
46 case ZAxis:
47 objects[i]->GetVertices()[j].Z = (sinf((base.X) + timeRatio * frequencyModifier) * periodModifier + cosf((base.Y) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
48 break;
49 default:
50 break;
51 }
52 }
53 }
54}
55
56void TriangleGroupDeformer::DropwaveDeform(float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis) {
57 for (int i = 0; i < objectCount; i++) {
58 for (int j = 0; j < objects[i]->GetVertexCount(); j++) {
59 Vector3D base = objects[i]->GetVertices()[j];
60
61 switch (axis) {
62 case XAxis:
63 objects[i]->GetVertices()[j].X = -(1.0f + cosf(12.0f * sqrt(base.Y * base.Y + base.Z + base.Z) + timeRatio * frequencyModifier) * periodModifier) / (0.5f * (base.Y * base.Y + base.Z + base.Z) + 2.0f) * magnitude;
64 break;
65 case YAxis:
66 objects[i]->GetVertices()[j].Y = -(1.0f + cosf(12.0f * sqrt(base.X * base.X + base.Z + base.Z) + timeRatio * frequencyModifier) * periodModifier) / (0.5f * (base.X * base.X + base.Z + base.Z) + 2.0f) * magnitude;
67 break;
68 case ZAxis:
69 objects[i]->GetVertices()[j].Z = -(1.0f + cosf(12.0f * sqrt(base.X * base.X + base.Y * base.Y) + timeRatio * frequencyModifier) * periodModifier) / (0.5f * (base.X * base.X + base.Y * base.Y) + 2.0f) * magnitude;
70 break;
71 default:
72 break;
73 }
74 }
75 }
76}
77
78void TriangleGroupDeformer::SineWaveSurfaceDeform(Vector3D offset, float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis) {
79 for (int i = 0; i < objectCount; i++) {
80 for (int j = 0; j < objects[i]->GetVertexCount(); j++) {
81 Vector3D base = objects[i]->GetVertices()[j] - offset;
82
83 switch (axis) {
84 case XAxis:
85 objects[i]->GetVertices()[j].X = objects[i]->GetVertices()[j].X + sinf((sqrtf(base.Y * base.Y + base.Z * base.Z) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
86 break;
87 case YAxis:
88 objects[i]->GetVertices()[j].Y = objects[i]->GetVertices()[j].Y + sinf((sqrtf(base.X * base.X + base.Z * base.Z) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
89 break;
90 case ZAxis:
91 objects[i]->GetVertices()[j].Z = objects[i]->GetVertices()[j].Z + sinf((sqrtf(base.X * base.X + base.Y * base.Y) + timeRatio * frequencyModifier) * periodModifier) * magnitude;
92 break;
93 default:
94 break;
95 }
96 }
97 }
98}
99
100void TriangleGroupDeformer::CosineInterpolationDeformer(float* pointMultiplier, int points, float scale, float minAxis, float maxAxis, Axis selectionAxis, Axis deformAxis) {
101 for (int i = 0; i < objectCount; i++) {
102 for (int j = 0; j < objects[i]->GetVertexCount(); j++) {
103 float value;
104
105 switch (selectionAxis) {
106 case XAxis:
107 value = objects[i]->GetVertices()[j].X;
108 break;
109 case YAxis:
110 value = objects[i]->GetVertices()[j].Y;
111 break;
112 case ZAxis:
113 value = objects[i]->GetVertices()[j].Z;
114 break;
115 default:
116 value = 0.0f;
117 break;
118 }
119
120 float stepWindow = (maxAxis - minAxis) / points; // window size for the step interval
121
122 float roundUpWindow = Mathematics::RoundUpWindow(value, stepWindow);
123 float roundDownWindow = roundUpWindow - stepWindow;
124 int roundUpIndex = (roundUpWindow - minAxis) / stepWindow;
125
126 float intervalMultiplier, windowRatio;
127
128 if (roundUpIndex < 1) { // below range
129 intervalMultiplier = 1.0f; // Mathematics::CosineInterpolation(1.0f, pointMultiplier[0], windowRatio)
130 } else if (roundUpIndex > points) { // above range
131 intervalMultiplier = 1.0f; // Mathematics::CosineInterpolation(pointMultiplier[points - 1], 1.0f, windowRatio)
132 } else {
133 windowRatio = (value - roundDownWindow) / stepWindow;
134 intervalMultiplier = Mathematics::CosineInterpolation(pointMultiplier[roundUpIndex], pointMultiplier[roundUpIndex - 1], 1.0f - windowRatio);
135 }
136
137 // calculate where the axis fits on the range
138
139 switch (deformAxis) {
140 case XAxis:
141 objects[i]->GetVertices()[j].X = objects[i]->GetVertices()[j].X + scale * intervalMultiplier;
142 break;
143 case YAxis:
144 objects[i]->GetVertices()[j].Y = objects[i]->GetVertices()[j].Y + scale * intervalMultiplier;
145 break;
146 case ZAxis:
147 objects[i]->GetVertices()[j].Z = objects[i]->GetVertices()[j].Z + scale * intervalMultiplier;
148 break;
149 default:
150 break;
151 }
152 }
153 }
154}
155
156void TriangleGroupDeformer::AxisZeroClipping(bool positive, Axis clipAxis, Axis valueCheckAxis) {
157 for (int i = 0; i < objectCount; i++) {
158 for (int j = 0; j < objects[i]->GetVertexCount(); j++) {
159 Vector3D base = objects[i]->GetVertices()[j];
160
161 switch (clipAxis) {
162 case XAxis:
163 if (CheckClipAxis(base, positive, valueCheckAxis)) base.X = 0;
164 break;
165 case YAxis:
166 if (CheckClipAxis(base, positive, valueCheckAxis)) base.Y = 0;
167 break;
168 case ZAxis:
169 if (CheckClipAxis(base, positive, valueCheckAxis)) base.Z = 0;
170 break;
171 default:
172 break;
173 }
174 }
175 }
176}
Provides functionality to deform groups of 3D triangles in various ways.
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.
static int RoundUpWindow(int value, int multiple)
Rounds value up to the nearest multiple of multiple.
static float CosineInterpolation(float beg, float fin, float ratio)
Applies a cosine-based interpolation between two values.
void DropwaveDeform(float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis)
Applies a dropwave deformation along a specified axis.
void SineWaveSurfaceDeform(Vector3D offset, float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis)
Applies a sine wave surface deformation along a specified axis.
TriangleGroupDeformer(ITriangleGroup *object)
Constructor for a single triangle group.
ITriangleGroup ** objects
Array of triangle group objects to deform.
void CosineInterpolationDeformer(float *pointMultiplier, int points, float scale, float minAxis, float maxAxis, Axis selectionAxis, Axis deformAxis)
Applies a cosine interpolation deformation along a specified axis.
void AxisZeroClipping(bool positive, Axis clipAxis, Axis valueCheckAxis)
Applies axis-aligned clipping to the triangles.
bool CheckClipAxis(Vector3D base, bool positive, Axis valueCheckAxis)
Checks if a given base position is clipped along a specific axis.
void SinusoidalDeform(float magnitude, float timeRatio, float periodModifier, float frequencyModifier, Axis axis)
Applies a sinusoidal deformation along a specified axis.
Axis
Defines the axes available for deformations and clipping.
int objectCount
Number of triangle group objects.
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