Isle
Loading...
Searching...
No Matches
orientableroi.cpp
Go to the documentation of this file.
1#include "orientableroi.h"
2
3#include "decomp.h"
4
5#include <vec.h>
6
8
9// FUNCTION: LEGO1 0x100a4420
11{
12 FILLVEC3(m_world_bounding_box.Min(), 888888.8);
13 FILLVEC3(m_world_bounding_box.Max(), -888888.8);
14 ZEROVEC3(m_world_bounding_sphere.Center());
15 m_world_bounding_sphere.Radius() = 0.0;
16 ZEROVEC3(m_world_velocity);
17 IDENTMAT4(m_local2world);
18
19 m_parentROI = NULL;
20 ToggleUnknown0xd8(TRUE);
21}
22
23// Maybe an overload based on MxMatrix type
24// FUNCTION: LEGO1 0x100a46a0
25// FUNCTION: BETA10 0x10165268
27{
28 SetLocalTransform(p_transform);
29}
30
31// FUNCTION: LEGO1 0x100a46b0
33{
34 MxMatrix mat;
35
36 double local2world[4][4];
37 double local2parent[4][4];
38 int i, j;
39
40 for (i = 0; i < 4; i++) {
41 for (j = 0; j < 4; j++) {
42 local2world[i][j] = p_transform[i][j];
43 local2parent[i][j] = m_local2world[i][j];
44 }
45 }
46
47 double local_inverse[4][4];
48 INVERTMAT4d(local_inverse, local2parent);
49
50 double parent2world[4][4];
51 MXM4(parent2world, local_inverse, local2world);
52
53 unsigned int k, l;
54 for (k = 0; k < 4; k++) {
55 for (l = 0; l < 4; l++) {
56 mat[k][l] = parent2world[k][l];
57 }
58 }
59
60 UpdateWorldData(mat);
61}
62
63// Maybe an overload based on MxMatrix type
64// FUNCTION: LEGO1 0x100a5090
66{
67 VTable0x24(p_transform);
68}
69
70// FUNCTION: LEGO1 0x100a50a0
71// FUNCTION: BETA10 0x1016601f
73{
74 MxMatrix mat;
75
76 if (m_parentROI != NULL) {
77 double local2parent[4][4];
78 unsigned int i, j;
79
80 for (i = 0; i < 4; i++) {
81 for (j = 0; j < 4; j++) {
82 local2parent[i][j] = m_parentROI->GetLocal2World()[i][j];
83 }
84 }
85
86 double local_inverse[4][4];
87 INVERTMAT4d(local_inverse, local2parent);
88
89 for (i = 0; i < 4; i++) {
90 for (j = 0; j < 4; j++) {
91 mat[i][j] = local_inverse[i][j];
92 }
93 }
94
95 MXM4(p_transform, m_local2world, mat);
96 }
97 else {
98 p_transform = m_local2world;
99 }
100}
101
102// FUNCTION: LEGO1 0x100a58f0
103// FUNCTION: BETA10 0x10167b77
104void OrientableROI::FUN_100a58f0(const Matrix4& p_transform)
105{
106 m_local2world = p_transform;
108}
109
110// FUNCTION: LEGO1 0x100a5910
112{
115}
116
117// FUNCTION: LEGO1 0x100a5930
119{
120 m_local2world = p_transform;
123}
124
125// FUNCTION: LEGO1 0x100a5960
126void OrientableROI::VTable0x24(const Matrix4& p_transform)
127{
128 MxMatrix l_matrix(m_local2world);
129 m_local2world.Product(p_transform, l_matrix);
132}
133
134// FUNCTION: LEGO1 0x100a59b0
136{
137 MxMatrix l_matrix(m_local2world);
138 m_local2world.Product(l_matrix, p_transform);
141
142 // iterate over comps
143 if (comp) {
144 for (CompoundObject::iterator iter = comp->begin(); !(iter == comp->end()); iter++) {
145 ROI* child = *iter;
146 static_cast<OrientableROI*>(child)->UpdateWorldData(p_transform);
147 }
148 }
149}
150
151// FUNCTION: LEGO1 0x100a5a30
152void OrientableROI::FUN_100a5a30(const Vector3& p_world_velocity)
153{
154 m_world_velocity = p_world_velocity;
155}
156
157// FUNCTION: LEGO1 0x100a5a50
159{
160}
161
162// FUNCTION: LEGO1 0x100a5a60
164 const BoundingSphere& modelling_sphere,
165 const Matrix4& local2world,
166 BoundingBox& world_bounding_box,
167 BoundingSphere& world_bounding_sphere
168)
169{
170 // calculate world bounding volumes given a bounding sphere in modelling
171 // space and local2world transform
172
173 // ??? we need to transform the radius too... if scaling...
174
175 V3XM4(world_bounding_sphere.Center(), modelling_sphere.Center(), local2world);
176
177 world_bounding_sphere.Radius() = modelling_sphere.Radius();
178
179 // update world_bounding_box
180 world_bounding_box.Min()[0] = world_bounding_sphere.Center()[0] - world_bounding_sphere.Radius();
181 world_bounding_box.Min()[1] = world_bounding_sphere.Center()[1] - world_bounding_sphere.Radius();
182 world_bounding_box.Min()[2] = world_bounding_sphere.Center()[2] - world_bounding_sphere.Radius();
183 world_bounding_box.Max()[0] = world_bounding_sphere.Center()[0] + world_bounding_sphere.Radius();
184 world_bounding_box.Max()[1] = world_bounding_sphere.Center()[1] + world_bounding_sphere.Radius();
185 world_bounding_box.Max()[2] = world_bounding_sphere.Center()[2] + world_bounding_sphere.Radius();
186}
187
188// FUNCTION: LEGO1 0x100a5d80
190{
191 return m_world_velocity.GetData();
192}
193
194// FUNCTION: LEGO1 0x100a5d90
196{
198}
199
200// FUNCTION: LEGO1 0x100a5da0
202{
204}
[AI] Represents an axis-aligned bounding box in 3D space, using minimum and maximum points.
Definition: roi.h:20
const Vector3 & Min() const
[AI] Const accessor for the minimum corner of the bounding box.
Definition: roi.h:26
const Vector3 & Max() const
[AI] Const accessor for the maximum corner of the bounding box.
Definition: roi.h:36
[AI] Represents a bounding sphere in 3D space with center and radius.
Definition: roi.h:56
const float & Radius() const
[AI] Const accessor for the sphere radius.
Definition: roi.h:72
const Vector3 & Center() const
[AI] Const accessor for the center of the sphere.
Definition: roi.h:62
4x4 Matrix class with virtual interface for manipulation and transformation.
Definition: matrix.h:24
virtual void Product(float(*p_a)[4], float(*p_b)[4])
Multiplies two 4x4 float matrices, storing result in this.
[AI] Represents a 4x4 transformation matrix, specialized for the LEGO Island engine and derived from ...
Definition: mxmatrix.h:16
[AI] Represents an ROI (Real-time Object Instance) that can be oriented in world space,...
Definition: orientableroi.h:29
const BoundingSphere & GetWorldBoundingSphere() const override
Returns the object's bounding sphere in world coordinates.
BoundingBox m_world_bounding_box
The object's axis-aligned bounding box in world space, recalculated as needed.
virtual void SetLocalTransform(const Matrix4 &p_transform)
Sets the local-to-world transformation matrix directly.
const Matrix4 & GetLocal2World() const
Accessor for the current local-to-world transformation matrix.
virtual void UpdateWorldVelocity()
Updates the world velocity (must be implemented by subclasses if custom velocity logic is needed).
void WrappedSetLocalTransform(const Matrix4 &p_transform)
Wraps SetLocalTransform, for possible override or interface uniformity.
virtual void VTable0x1c()
[AI] Concrete subclass implementation should implement this to perform post-bounding-volume-change lo...
Mx3DPointFloat m_world_velocity
The object's velocity vector in world coordinates.
void FUN_100a5a30(const Vector3 &p_world_velocity)
Sets the world velocity to the provided vector.
const float * GetWorldVelocity() const override
Returns a pointer to the object's velocity vector in world space.
MxMatrix m_local2world
The transform from local to world space; 4x4 transformation matrix.
void GetLocalTransform(Matrix4 &p_transform)
Retrieves the local-to-world transformation, or if there is a parent, computes the transform relative...
virtual void VTable0x24(const Matrix4 &p_transform)
Post-multiplies the current local-to-world matrix by p_transform.
void WrappedVTable0x24(const Matrix4 &p_transform)
Wraps VTable0x24, possibly for decoupling or uniform invocation.
void FUN_100a58f0(const Matrix4 &p_transform)
Assigns the given matrix as the local-to-world transformation and enables some internal flags.
OrientableROI * m_parentROI
If non-null, points to the parent OrientableROI for local/world transformation hierarchy.
virtual void UpdateWorldBoundingVolumes()=0
Recalculates all world bounding volumes from the current local-to-world transform.
void UpdateTransformationRelativeToParent(const Matrix4 &p_transform)
Calculates and updates the world transform relative to this object's parent, then calls UpdateWorldDa...
const BoundingBox & GetWorldBoundingBox() const override
Returns the object's bounding box in world coordinates.
BoundingSphere m_world_bounding_sphere
The object's bounding sphere in world space, recalculated from m_local2world.
void ToggleUnknown0xd8(BOOL p_enable)
Enables or disables some bitfields in the internal unknown status variable m_unk0xd8.
virtual void UpdateWorldData(const Matrix4 &p_transform)
Applies p_transform in (presumably) parent coordinates and updates world data for self and children.
[AI] Abstract base class for Real-time Object Instances (ROI) in the world.
Definition: roi.h:162
CompoundObject * comp
[AI] List of sub-ROIs composing this ROI (compound object), or NULL. [AI]
Definition: roi.h:241
virtual float * GetData()
[AI] Retrieves the mutable in-memory data pointer for this vector.
[AI] 3D vector class, providing vector and cross-product operations in 3D space.
Definition: vector.h:249
#define TRUE
Definition: d3drmdef.h:28
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
void CalcWorldBoundingVolumes(const BoundingSphere &modelling_sphere, const Matrix4 &local2world, BoundingBox &world_bounding_box, BoundingSphere &world_bounding_sphere)
[AI] Computes the world-space bounding box and bounding sphere for an ROI using a modeling sphere and...
#define MXM4(to, m1, m2)
Definition: vec.h:677
#define V3XM4(to3, v3, m4)
Definition: vec.h:518
#define ZEROVEC3(v)
Definition: vec.h:334
#define INVERTMAT4d(to, from)
Definition: vec.h:1081
#define FILLVEC3(v, s)
Definition: vec.h:326
#define IDENTMAT4(m)
Definition: vec.h:597