Isle
Loading...
Searching...
No Matches
legowegedge.cpp
Go to the documentation of this file.
1#include "legowegedge.h"
2
4
5#include <assert.h>
6
9
10// FUNCTION: LEGO1 0x1009a730
11// FUNCTION: BETA10 0x101830ec
13{
14 m_unk0x0d = 0;
15 m_name = NULL;
16 m_unk0x14.Clear();
17 m_edgeNormals = NULL;
18 m_flags = 0;
19 m_numTriggers = 0;
20 m_pathTrigger = NULL;
21 m_unk0x50 = NULL;
22}
23
24// FUNCTION: LEGO1 0x1009a800
26{
27 if (m_edges) {
28 delete[] m_edges;
29 m_edges = NULL;
30 }
31 if (m_name) {
32 delete[] m_name;
33 }
34 if (m_edgeNormals) {
35 delete[] m_edgeNormals;
36 }
37 if (m_pathTrigger) {
38 delete m_pathTrigger;
39 }
40 if (m_unk0x50) {
41 delete m_unk0x50;
42 }
43}
44
45// FUNCTION: LEGO1 0x1009a8c0
46// FUNCTION: BETA10 0x101832f7
48{
49 LegoS32 result = 0;
52
53 assert(m_numEdges > 1);
54
55 Vector3* local20;
56 if (IsEqual(m_edges[0]->m_faceA)) {
57 local20 = m_edges[0]->m_pointB;
58 }
59 else {
60 assert(IsEqual(m_edges[0]->m_faceB));
61 local20 = m_edges[0]->m_pointA;
62 }
63
64 Vector3 *local1c, *local14;
65 if (IsEqual(m_edges[1]->m_faceA)) {
66 local1c = m_edges[1]->m_pointB;
67 local14 = m_edges[1]->m_pointA;
68 }
69 else {
70 assert(IsEqual(m_edges[1]->m_faceB));
71 local1c = m_edges[1]->m_pointA;
72 local14 = m_edges[1]->m_pointB;
73 }
74
75 result = FUN_1009aea0();
76 if (result != 0) {
77 result = -2;
78 }
79
80 assert(m_edgeNormals == NULL);
82 assert(m_edgeNormals);
83
85 LegoS32 i;
86
87 for (i = 0; i < m_numEdges; i++) {
88 edge = m_edges[i];
89 m_unk0x30 += *edge->m_pointA;
90 m_unk0x30 += *edge->m_pointB;
91 }
92
93 m_unk0x30 /= m_numEdges * 2;
94 m_unk0x44 = 0.0f;
95
96 for (i = 0; i < m_numEdges; i++) {
97 Mx3DPointFloat local44;
98 edge = m_edges[i];
99
100 local44 = *edge->m_pointA;
101 local44 -= m_unk0x30;
102 float length = local44.LenSquared();
103
104 if (m_unk0x44 < length) {
105 m_unk0x44 = length;
106 }
107
108 local44 = *edge->m_pointB;
109 local44 -= m_unk0x30;
110 length = local44.LenSquared();
111
112 if (m_unk0x44 < length) {
113 m_unk0x44 = length;
114 }
115 }
116
117 m_unk0x44 = sqrt((double) m_unk0x44);
118
119 for (i = 0; i < m_numEdges; i++) {
120 edge = m_edges[i];
121 Vector3& local5c = edge->m_unk0x28;
122
123 if (edge->m_unk0x3c == 0) {
124 local5c = *m_edges[i]->m_pointB;
125 local5c -= *m_edges[i]->m_pointA;
126 edge->m_unk0x3c = local5c.LenSquared();
127
128 if (edge->m_unk0x3c <= 0.0f) {
129 assert(0);
130 if (result == 0) {
131 result = -1;
132 }
133 }
134
135 edge->m_unk0x3c = sqrt((double) edge->m_unk0x3c);
136 local5c /= edge->m_unk0x3c;
137 }
138
139 Mx3DPointFloat local58;
140 Vector3 local64(&m_edgeNormals[i][0]);
141 edge->FUN_1002ddc0(*this, local58);
142 local64.EqualsCross(local58, m_unk0x14);
143
144 m_edgeNormals[i][3] = -local64.Dot(*m_edges[i]->m_pointA, local64);
145 if (m_edgeNormals[i][3] + m_unk0x30.Dot(m_unk0x30, local64) < 0.0f) {
146 m_edgeNormals[i] *= -1.0f;
147 }
148
149 if (edge->GetFaceA() != NULL && edge->GetFaceB() != NULL) {
151 }
152 }
153
154 if (m_numTriggers > 0) {
155 Vector3* vTrig1 = m_edges[0]->CCWVertex(*this);
156 Vector3* vTrig2 = m_edges[1]->CCWVertex(*this);
157 assert(vTrig1 && vTrig2);
158
160 *m_unk0x50 = *vTrig2;
161 *m_unk0x50 -= *vTrig1;
162
163 if (m_unk0x50->Unitize() < 0) {
164 assert(0);
165 delete m_unk0x50;
166 m_unk0x50 = NULL;
167 }
168
169 if (GetNumEdges() == 4) {
170 float local98 = 0.0f;
171 Mx3DPointFloat localb8(*m_edges[0]->CWVertex(*this));
172 Mx3DPointFloat local80(*m_edges[2]->CCWVertex(*this));
173 Mx3DPointFloat local94(*vTrig2);
174
175 local94 -= *vTrig1;
176 float local9c = sqrt(local94.LenSquared());
177
178 localb8 -= *vTrig1;
179 local80 -= *vTrig1;
180
181 float locala4 = localb8.Dot(*m_unk0x50, localb8);
182 if (local98 < locala4) {
183 local98 = locala4;
184 }
185
186 locala4 = local80.Dot(*m_unk0x50, local80);
187 if (locala4 < local9c) {
188 local9c = locala4;
189 }
190
191 if (local9c < local98) {
192 result = -3;
193 }
194 if (local9c - local98 < 0.0025) {
195 result = -4;
196 }
197
198 local98 += 0.001;
199 local9c -= 0.001;
200
201 for (LegoS32 j = 0; j < m_numTriggers; j++) {
202 if (m_pathTrigger[j].m_unk0x08 < local98) {
203 m_pathTrigger[j].m_unk0x08 = local98;
204 }
205
206 if (m_pathTrigger[j].m_unk0x08 > local9c) {
207 m_pathTrigger[j].m_unk0x08 = local9c;
208 }
209 }
210 }
211 else {
212 result = -5;
213 }
214 }
215
216 return result;
217}
218
219// FUNCTION: LEGO1 0x1009aea0
220// FUNCTION: BETA10 0x10183e2a
222{
223 LegoU32 localc = FALSE;
224 Mx3DPointFloat local24;
225
226 if (m_numEdges < 3) {
227 return -1;
228 }
229
230 Vector3** local8 = new Vector3*[m_numEdges];
231 LegoS32 i;
232
233 for (i = 0; i < m_numEdges; i++) {
234 local8[i] = m_edges[i]->CWVertex(*this);
235 }
236
237 for (i = 2; i < m_numEdges; i++) {
238 Mx3DPointFloat local3c;
239 Mx3DPointFloat local50;
240 float local28 = 0.0f;
241
242 local3c = *local8[i];
243 local3c -= *local8[i - 1];
244 local50 = *local8[i - 2];
245 local50 -= *local8[i - 1];
246
247 local24.EqualsCross(local50, local3c);
248 local28 = local24.LenSquared();
249
250 if (local28 < 0.00001f) {
251 continue;
252 }
253
254 float local58 = sqrt((double) local28);
255 local24 /= local58;
256
257 if (localc) {
258 float local54 = local24.Dot(m_unk0x14, local24);
259 if (local54 < 0.98) {
260 delete[] local8;
261 return -2;
262 }
263 }
264 else {
265 m_unk0x14[0] = local24[0];
266 m_unk0x14[1] = local24[1];
267 m_unk0x14[2] = local24[2];
268 m_unk0x14[3] = -local8[i]->Dot(*local8[i], local24);
269 localc = TRUE;
270 }
271 }
272
273 if (local8 != NULL) {
274 delete[] local8;
275 }
276
277 if (!localc) {
278 return -1;
279 }
280
281 return 0;
282}
virtual LegoS32 VTable0x04()
[AI] Connects and links the associated edge objects to set up adjacency across the face.
Definition: legoweedge.cpp:23
LegoU8 m_numEdges
[AI] Number of edge elements in m_edges; number of sides of the polygon. [AI]
Definition: legoweedge.h:74
LegoU8 GetNumEdges()
[AI] Returns the number of edge elements assigned to this face.
Definition: legoweedge.h:43
LegoU32 IsEqual(LegoWEEdge *p_other)
[AI] Checks if this face object is the same as another.
Definition: legoweedge.h:56
LegoUnknown100db7f4 ** m_edges
[AI] Array of pointers to edge objects (LegoUnknown100db7f4) comprising this face....
Definition: legoweedge.h:75
[AI] Represents a "geometry edge" in the LEGO Island world polygon/path system.
Definition: legowegedge.h:31
Mx4DPointFloat m_unk0x14
[AI] 4D plane equation or normal used for polygon/edge side tests. [AI]
Definition: legowegedge.h:112
float m_unk0x44
[AI] Maximum squared distance from center—polygon bounding radius or similar. [AI]
Definition: legowegedge.h:115
LegoS32 VTable0x04() override
[AI] Performs geometry calculations for the edge, sets up normals, center point, and trigger vectors.
Definition: legowegedge.cpp:47
LegoU8 m_numTriggers
[AI] Number of trigger (path/segment) structures attached to this edge. [AI]
Definition: legowegedge.h:116
Mx3DPointFloat * m_unk0x50
[AI] Transition direction/unit vector—used for edge trigger geometry. [AI]
Definition: legowegedge.h:118
Mx4DPointFloat * m_edgeNormals
[AI] Per-edge normals for each polygon segment, allocated dynamically. [AI]
Definition: legowegedge.h:113
LegoS32 FUN_1009aea0()
[AI] Internal routine called by VTable0x04 for validity checking of polygon vertices and normal consi...
LegoChar * m_name
[AI] Edge's name string, dynamically allocated for debug/lookup. [AI]
Definition: legowegedge.h:111
PathWithTrigger * m_pathTrigger
[AI] Array of triggers influencing entity motion or event logic on this edge. [AI]
Definition: legowegedge.h:117
~LegoWEGEdge() override
[AI] Destroys this edge instance and properly deallocates memory for associated dynamic members.
Definition: legowegedge.cpp:25
Mx3DPointFloat m_unk0x30
[AI] Cached center for the edge polygon, used in geometric calculations. [AI]
Definition: legowegedge.h:114
[AI] Represents a 3D point with floating-point precision, inheriting from Vector3.
Definition: mxgeometry3d.h:14
[AI] 4D point class for floating point values.
Definition: mxgeometry4d.h:18
virtual float Dot(const float *p_a, const float *p_b) const
[AI] Compute the dot product of the two float arrays interpreted as vectors of 2 elements.
virtual int Unitize()
[AI] Scales the vector so its norm is 1 (unit vector).
[AI] 3D vector class, providing vector and cross-product operations in 3D space.
Definition: vector.h:249
void Clear() override
[AI] Sets every coordinate (x, y, z) to zero.
float LenSquared() const override
[AI] Computes the squared magnitude (x^2 + y^2 + z^2) of this vector.
virtual void EqualsCross(const Vector3 &p_a, const Vector3 &p_b)
[AI] Sets this vector to be the cross product of p_a and p_b.
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
unsigned long LegoU32
[AI] Unsigned 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:71
long LegoS32
[AI] Signed 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:65
Vector3 * CWVertex(LegoWEEdge &p_face)
[AI] Returns the "clockwise" endpoint of this edge with respect to a given face.
Definition: legoedge.cpp:56
Vector3 * m_pointB
[AI] The second endpoint of the edge.
Definition: legoedge.h:133
LegoWEEdge * GetFaceB()
[AI] Gets the second face (B) using this edge.
Definition: legoedge.h:76
LegoWEEdge * GetFaceA()
[AI] Gets the first face (A) using this edge.
Definition: legoedge.h:70
Vector3 * m_pointA
[AI] The first endpoint of the edge.
Definition: legoedge.h:128
Vector3 * CCWVertex(LegoWEEdge &p_face)
[AI] Returns the "counterclockwise" endpoint of this edge with respect to a given face.
Definition: legoedge.cpp:69
[AI] Represents an advanced edge in the LEGO Island geometry system, with direction,...
@ c_bit2
[AI] Bit flag 2 for face A connection/properties
@ c_bit1
[AI] Bit flag 1 for face B connection/properties
float m_unk0x3c
[AI] Unknown float; likely represents additional metric (possibly precomputed distance/weight).
Mx3DPointFloat m_unk0x28
[AI] Represents the edge's direction/normal vector or outward face normal.
LegoResult FUN_1002ddc0(LegoWEEdge &p_f, Vector3 &p_point) const
[AI] Calculates the edge normal for use from the given face, negating it if called from faceA.
void SetFlags(LegoU16 p_flags)
[AI] Directly sets the internal flags value.
[AI] Represents a path segment with an associated trigger in LEGO Island pathing logic.
Definition: legowegedge.h:8
float m_unk0x08
[AI] Distance along the path or trigger threshold (exact semantics unclear). [AI]
Definition: legowegedge.h:20