Isle
Loading...
Searching...
No Matches
legoroi.cpp
Go to the documentation of this file.
1#include "legoroi.h"
2
3#include "anim/legoanim.h"
4#include "legolod.h"
6#include "misc/legostorage.h"
8#include "realtime/realtime.h"
9#include "shape/legobox.h"
10#include "shape/legosphere.h"
11
12#include <string.h>
13#include <vec.h>
14
17
18// SIZE 0x14
19typedef struct {
20 const char* m_name;
21 int m_red;
23 int m_blue;
26
27// GLOBAL: LEGO1 0x101011b0
29 {"lego black", 0x21, 0x21, 0x21, 0}, {"lego black f", 0x21, 0x21, 0x21, 0},
30 {"lego black flat", 0x21, 0x21, 0x21, 0}, {"lego blue", 0x00, 0x54, 0x8c, 0},
31 {"lego blue flat", 0x00, 0x54, 0x8c, 0}, {"lego brown", 0x4a, 0x23, 0x1a, 0},
32 {"lego brown flt", 0x4a, 0x23, 0x1a, 0}, {"lego brown flat", 0x4a, 0x23, 0x1a, 0},
33 {"lego drk grey", 0x40, 0x40, 0x40, 0}, {"lego drk grey flt", 0x40, 0x40, 0x40, 0},
34 {"lego dk grey flt", 0x40, 0x40, 0x40, 0}, {"lego green", 0x00, 0x78, 0x2d, 0},
35 {"lego green flat", 0x00, 0x78, 0x2d, 0}, {"lego lt grey", 0x82, 0x82, 0x82, 0},
36 {"lego lt grey flt", 0x82, 0x82, 0x82, 0}, {"lego lt grey fla", 0x82, 0x82, 0x82, 0},
37 {"lego red", 0xcb, 0x12, 0x20, 0}, {"lego red flat", 0xcb, 0x12, 0x20, 0},
38 {"lego white", 0xfa, 0xfa, 0xfa, 0}, {"lego white flat", 0xfa, 0xfa, 0xfa, 0},
39 {"lego yellow", 0xff, 0xb9, 0x00, 0}, {"lego yellow flat", 0xff, 0xb9, 0x00, 0},
40};
41
42// GLOBAL: LEGO1 0x10101368
43int g_roiConfig = 100;
44
45// GLOBAL: LEGO1 0x10101370
46const char* g_unk0x10101370[] = {"bike", "moto", NULL};
47
48// GLOBAL: LEGO1 0x10101380
49const char* g_unk0x10101380[] = {"bike", "moto", "haus", NULL};
50
51// GLOBAL: LEGO1 0x10101390
52const char* g_unk0x10101390[] = {"rcuser", "jsuser", "dunebugy", "chtrblad", "chtrbody", "chtrshld", NULL};
53
54// GLOBAL: LEGO1 0x101013ac
56
57// GLOBAL: LEGO1 0x101013b0
59
60// FUNCTION: LEGO1 0x100a81b0
61void LegoROI::FUN_100a81b0(const LegoChar* p_error, const LegoChar* p_name)
62{
63}
64
65// FUNCTION: LEGO1 0x100a81c0
66void LegoROI::configureLegoROI(int p_roiConfig)
67{
68 g_roiConfig = p_roiConfig;
69}
70
71// FUNCTION: LEGO1 0x100a81d0
72LegoROI::LegoROI(Tgl::Renderer* p_renderer) : ViewROI(p_renderer, NULL)
73{
75 m_name = NULL;
76 m_entity = NULL;
77}
78
79// FUNCTION: LEGO1 0x100a82d0
80LegoROI::LegoROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList) : ViewROI(p_renderer, p_lodList)
81{
83 m_name = NULL;
84 m_entity = NULL;
85}
86
87// FUNCTION: LEGO1 0x100a83c0
89{
90 if (comp) {
91 CompoundObject::iterator iterator;
92
93 for (iterator = comp->begin(); !(iterator == comp->end()); ++iterator) {
94 ROI* child = *iterator;
95
96 delete child;
97 }
98
99 delete comp;
100 comp = 0;
101 }
102 if (m_name) {
103 delete[] m_name;
104 }
105}
106
107// FUNCTION: LEGO1 0x100a84a0
109 OrientableROI* p_unk0xd4,
110 Tgl::Renderer* p_renderer,
111 ViewLODListManager* p_viewLODListManager,
112 LegoTextureContainer* p_textureContainer,
113 LegoStorage* p_storage
114)
115{
116 LegoResult result = FAILURE;
117 LegoU32 i, j;
118 LegoU32 numLODs, surplusLODs;
119 LegoROI* roi;
120 LegoLOD* lod;
121 LegoU32 length, roiLength;
122 LegoChar *roiName, *textureName;
123 LegoTextureInfo* textureInfo;
124 ViewLODList* lodList;
125 LegoU32 numROIs;
126 LegoSphere sphere;
127 LegoBox box;
128
129 m_parentROI = p_unk0xd4;
130
131 if (p_storage->Read(&length, sizeof(length)) != SUCCESS) {
132 goto done;
133 }
134 m_name = new LegoChar[length + 1];
135 if (p_storage->Read(m_name, length) != SUCCESS) {
136 goto done;
137 }
138 m_name[length] = '\0';
139 strlwr(m_name);
140
141 if (sphere.Read(p_storage) != SUCCESS) {
142 goto done;
143 }
144
145 SET3(m_sphere.Center(), sphere.GetCenter());
146 m_sphere.Radius() = sphere.GetRadius();
148
149 if (box.Read(p_storage) != SUCCESS) {
150 goto done;
151 }
152
153 SET3(m_unk0x80.Min(), box.GetMin());
154 SET3(m_unk0x80.Max(), box.GetMax());
155
156 if (p_storage->Read(&length, sizeof(length)) != SUCCESS) {
157 goto done;
158 }
159
160 if (length != 0) {
161 textureName = new LegoChar[length + 1];
162 if (p_storage->Read(textureName, length) != SUCCESS) {
163 goto done;
164 }
165 textureName[length] = '\0';
166 strlwr(textureName);
167 }
168 else {
169 textureName = NULL;
170 }
171
172 if (p_storage->Read(&m_unk0x100, sizeof(m_unk0x100)) != SUCCESS) {
173 goto done;
174 }
175
176 if (m_unk0x100) {
177 for (roiLength = strlen(m_name); roiLength; roiLength--) {
178 if (m_name[roiLength - 1] < '0' || m_name[roiLength - 1] > '9') {
179 break;
180 }
181 }
182
183 roiName = new LegoChar[roiLength + 1];
184 memcpy(roiName, m_name, roiLength);
185 roiName[roiLength] = '\0';
186
187 lodList = p_viewLODListManager->Lookup(roiName);
188 delete[] roiName;
189
190 if (lodList == NULL) {
191 goto done;
192 }
193 }
194 else {
195 if (p_storage->Read(&numLODs, sizeof(numLODs)) != SUCCESS) {
196 goto done;
197 }
198
199 if (!numLODs) {
200 lodList = NULL;
201 }
202 else {
203 const LegoChar* roiName = m_name;
204 LegoU32 offset;
205
206 if (p_storage->Read(&offset, sizeof(offset)) != SUCCESS) {
207 goto done;
208 }
209
210 if (numLODs > g_roiConfig) {
211 surplusLODs = numLODs - g_roiConfig;
212 numLODs = g_roiConfig;
213 }
214 else {
215 surplusLODs = 0;
216 }
217
218 if (g_roiConfig <= 2) {
219 for (i = 0; g_unk0x10101380[i] != NULL; i++) {
220 if (!strnicmp(m_name, g_unk0x10101380[i], 4)) {
221 roiName = g_unk0x10101380[i];
222 break;
223 }
224 }
225 }
226 else {
227 for (i = 0; g_unk0x10101370[i] != NULL; i++) {
228 if (!strnicmp(m_name, g_unk0x10101370[i], 4)) {
229 roiName = g_unk0x10101370[i];
230 break;
231 }
232 }
233 }
234
235 if ((lodList = p_viewLODListManager->Lookup(roiName))) {
236 for (j = 0; g_unk0x10101390[j] != NULL; j++) {
237 if (!strcmpi(g_unk0x10101390[j], roiName)) {
238 break;
239 }
240 }
241
242 if (g_unk0x10101390[j] != NULL) {
243 while (lodList->Size()) {
244 delete const_cast<ViewLOD*>(lodList->PopBack());
245 }
246
247 for (j = 0; j < numLODs; j++) {
248 lod = new LegoLOD(p_renderer);
249 if (lod->Read(p_renderer, p_textureContainer, p_storage) != SUCCESS) {
250 goto done;
251 }
252
253 if (j == 0) {
254 if (surplusLODs != 0 && lod->GetUnknown0x08Test8()) {
255 numLODs++;
256 }
257 }
258
259 lodList->PushBack(lod);
260 }
261 }
262 }
263 else {
264 for (i = 0; i < numLODs; i++) {
265 lod = new LegoLOD(p_renderer);
266 if (lod->Read(p_renderer, p_textureContainer, p_storage) != SUCCESS) {
267 goto done;
268 }
269
270 if (i == 0) {
271 if (surplusLODs != 0 && lod->GetUnknown0x08Test8()) {
272 numLODs++;
273 }
274 }
275
276 if (i == 0 && (lodList = p_viewLODListManager->Create(roiName, numLODs)) == NULL) {
277 goto done;
278 }
279
280 lodList->PushBack(lod);
281 }
282 }
283
284 p_storage->SetPosition(offset);
285 }
286 }
287
288 SetLODList(lodList);
289
290 if (lodList != NULL) {
291 lodList->Release();
292 }
293
294 if (textureName != NULL) {
295 if (!strnicmp(textureName, "t_", 2)) {
296 textureInfo = p_textureContainer->Get(textureName + 2);
297
298 if (textureInfo == NULL) {
299 goto done;
300 }
301
302 SetTextureInfo(textureInfo);
303 SetLodColor(1.0F, 1.0F, 1.0F, 0.0F);
304 }
305 else {
306 LegoFloat red = 1.0F;
307 LegoFloat green = 0.0F;
308 LegoFloat blue = 1.0F;
309 LegoFloat alpha = 0.0F;
310 GetRGBAColor(textureName, red, green, blue, alpha);
311 SetLodColor(red, green, blue, alpha);
312 }
313 }
314
315 if (p_storage->Read(&numROIs, sizeof(numROIs)) != SUCCESS) {
316 goto done;
317 }
318
319 if (numROIs > 0) {
320 comp = new CompoundObject;
321 }
322
323 for (i = 0; i < numROIs; i++) {
324 // Create and initialize a sub-component
325 roi = new LegoROI(p_renderer);
326 if (roi->Read(this, p_renderer, p_viewLODListManager, p_textureContainer, p_storage) != SUCCESS) {
327 goto done;
328 }
329 // Add the new sub-component to this ROI's protected list
330 comp->push_back(roi);
331 }
332
333 result = SUCCESS;
334
335done:
336 return result;
337}
338
339// FUNCTION: LEGO1 0x100a8cb0
341{
342 p_matrix.SetIdentity();
343 p_data->CreateLocalTransform(p_time, p_matrix);
344 return SUCCESS;
345}
346
347// FUNCTION: LEGO1 0x100a8ce0
348// FUNCTION: BETA10 0x1018a815
350{
351 CompoundObject::iterator it;
352 const LegoChar* name = p_roi->GetName();
353
354 if (name != NULL && *name != '\0' && !strcmpi(name, p_name)) {
355 return p_roi;
356 }
357
358 CompoundObject* comp = p_roi->comp;
359 if (comp != NULL) {
360 for (it = comp->begin(); it != comp->end(); it++) {
361 LegoROI* roi = (LegoROI*) *it;
362 name = roi->GetName();
363
364 if (name != NULL && *name != '\0' && !strcmpi(name, p_name)) {
365 return roi;
366 }
367 }
368
369 for (it = comp->begin(); it != comp->end(); it++) {
370 LegoROI* roi = FindChildROI(p_name, (LegoROI*) *it);
371
372 if (roi != NULL) {
373 return roi;
374 }
375 }
376 }
377
378 return NULL;
379}
380
381// FUNCTION: LEGO1 0x100a8da0
382LegoResult LegoROI::FUN_100a8da0(LegoTreeNode* p_node, const Matrix4& p_matrix, LegoTime p_time, LegoROI* p_roi)
383{
384 MxMatrix mat;
385 LegoAnimNodeData* data = (LegoAnimNodeData*) p_node->GetData();
386 const LegoChar* name = data->GetName();
387 LegoROI* roi = FindChildROI(name, p_roi);
388
389 if (roi == NULL) {
390 roi = FindChildROI(name, this);
391 }
392
393 if (roi != NULL) {
394 FUN_100a8cb0(data, p_time, mat);
395 roi->m_local2world.Product(mat, p_matrix);
396 roi->VTable0x1c();
397
398 LegoBool und = data->FUN_100a0990(p_time);
399 roi->SetVisibility(und);
400
401 for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
402 FUN_100a8da0(p_node->GetChild(i), roi->m_local2world, p_time, roi);
403 }
404 }
405 else {
406 FUN_100a81b0("%s ROI Not found\n", name);
407 }
408
409 return SUCCESS;
410}
411
412// FUNCTION: LEGO1 0x100a8e80
413// FUNCTION: BETA10 0x1018ab3a
414void LegoROI::FUN_100a8e80(LegoTreeNode* p_node, Matrix4& p_matrix, LegoTime p_time, LegoROI** p_roiMap)
415{
416 MxMatrix mat;
417
418 LegoAnimNodeData* data = (LegoAnimNodeData*) p_node->GetData();
419 FUN_100a8cb0(data, p_time, mat);
420
421 LegoROI* roi = p_roiMap[data->GetUnknown0x20()];
422 if (roi != NULL) {
423 roi->m_local2world.Product(mat, p_matrix);
424 roi->VTable0x1c();
425
426 LegoBool und = data->FUN_100a0990(p_time);
427 roi->SetVisibility(und);
428
429 for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
430 FUN_100a8e80(p_node->GetChild(i), roi->m_local2world, p_time, p_roiMap);
431 }
432 }
433 else {
434 MxMatrix local2world;
435 local2world.Product(mat, p_matrix);
436
437 for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
438 FUN_100a8e80(p_node->GetChild(i), local2world, p_time, p_roiMap);
439 }
440 }
441}
442
443// FUNCTION: LEGO1 0x100a8fd0
444// FUNCTION: BETA10 0x1018ac81
445void LegoROI::FUN_100a8fd0(LegoTreeNode* p_node, Matrix4& p_matrix, LegoTime p_time, LegoROI** p_roiMap)
446{
447 MxMatrix mat;
448
449 LegoAnimNodeData* data = (LegoAnimNodeData*) p_node->GetData();
450 FUN_100a8cb0(data, p_time, mat);
451
452 LegoROI* roi = p_roiMap[data->GetUnknown0x20()];
453 if (roi != NULL) {
454 roi->m_local2world.Product(mat, p_matrix);
455
456 for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
457 FUN_100a8fd0(p_node->GetChild(i), roi->m_local2world, p_time, p_roiMap);
458 }
459 }
460 else {
461 MxMatrix local2world;
462 local2world.Product(mat, p_matrix);
463
464 for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) {
465 FUN_100a8fd0(p_node->GetChild(i), local2world, p_time, p_roiMap);
466 }
467 }
468}
469
470// FUNCTION: LEGO1 0x100a90f0
472{
473 LegoTreeNode* root = p_anim->GetRoot();
474 MxMatrix mat;
475
476 mat = m_local2world;
477 mat.SetIdentity();
478
479 return FUN_100a8da0(root, mat, p_time, this);
480}
481
482// FUNCTION: LEGO1 0x100a9170
483// FUNCTION: BETA10 0x1018ae09
485{
486 LegoResult result = SUCCESS;
487 CompoundObject::iterator it;
488
489 int lodCount = GetLODCount();
490 for (LegoU32 i = 0; i < lodCount; i++) {
491 LegoLOD* lod = (LegoLOD*) GetLOD(i);
492
493 if (lod->SetColor(p_red, p_green, p_blue, p_alpha) != SUCCESS) {
494 result = FAILURE;
495 }
496 }
497
498 if (comp != NULL) {
499 for (it = comp->begin(); it != comp->end(); it++) {
500 if (((LegoROI*) *it)->SetLodColor(p_red, p_green, p_blue, p_alpha) != SUCCESS) {
501 result = FAILURE;
502 }
503 }
504 }
505
506 return result;
507}
508
509// FUNCTION: LEGO1 0x100a9210
511{
512 LegoResult result = SUCCESS;
513 CompoundObject::iterator it;
514
515 int lodCount = GetLODCount();
516 for (LegoU32 i = 0; i < lodCount; i++) {
517 LegoLOD* lod = (LegoLOD*) GetLOD(i);
518
519 if (lod->SetTextureInfo(p_textureInfo) != SUCCESS) {
520 result = FAILURE;
521 }
522 }
523
524 if (comp != NULL) {
525 for (it = comp->begin(); it != comp->end(); it++) {
526 if (((LegoROI*) *it)->SetTextureInfo(p_textureInfo) != SUCCESS) {
527 result = FAILURE;
528 }
529 }
530 }
531
532 return result;
533}
534
535// FUNCTION: LEGO1 0x100a92a0
536// FUNCTION: BETA10 0x1018b12d
538{
539 CompoundObject::iterator it;
540
541 int lodCount = GetLODCount();
542 for (LegoU32 i = 0; i < lodCount; i++) {
543 LegoLOD* lod = (LegoLOD*) GetLOD(i);
544
545 if (lod->GetTextureInfo(p_textureInfo) == SUCCESS) {
546 return SUCCESS;
547 }
548 }
549
550 if (comp != NULL) {
551 for (it = comp->begin(); it != comp->end(); it++) {
552 if (((LegoROI*) *it)->GetTextureInfo(p_textureInfo) == SUCCESS) {
553 return SUCCESS;
554 }
555 }
556 }
557
558 return FAILURE;
559}
560
561// FUNCTION: LEGO1 0x100a9330
562// FUNCTION: BETA10 0x1018b22c
564{
565 return SetLodColor(p_red, p_green, p_blue, p_alpha);
566}
567
568// FUNCTION: LEGO1 0x100a9350
569// FUNCTION: BETA10 0x1018b25c
571{
572 MxFloat red, green, blue, alpha;
573 if (ColorAliasLookup(p_name, red, green, blue, alpha)) {
574 return SetLodColor(red, green, blue, alpha);
575 }
576
577 return SUCCESS;
578}
579
580// FUNCTION: LEGO1 0x100a93b0
581// FUNCTION: BETA10 0x1018b2c0
583{
584 MxFloat red, green, blue, alpha;
585 if (ColorAliasLookup(p_name, red, green, blue, alpha)) {
586 return FUN_100a9330(red, green, blue, alpha);
587 }
588
589 return 0;
590}
591
592// FUNCTION: LEGO1 0x100a9410
593// FUNCTION: BETA10 0x1018b324
595 Vector3& p_v1,
596 Vector3& p_v2,
597 float p_f1,
598 float p_f2,
599 Vector3& p_v3,
600 LegoBool p_collideBox
601)
602{
603 if (p_collideBox) {
604 Mx3DPointFloat v2(p_v2);
605 v2 *= p_f1;
606 v2 += p_v1;
607
608 Mx4DPointFloat localc0;
609 Mx4DPointFloat local9c;
610 Mx4DPointFloat local168;
611 Mx4DPointFloat local70;
612 Mx4DPointFloat local150[6];
613
614 Vector3 local58(&localc0[0]);
615 Vector3 locala8(&local9c[0]);
616 Vector3 local38(&local168[0]);
617
618 Mx3DPointFloat local4c(p_v1);
619
620 local58 = m_unk0x80.Min();
621 locala8 = m_unk0x80.Max();
622
623 localc0[3] = local9c[3] = local168[3] = 1.0f;
624
625 local38 = local58;
626 local38 += locala8;
627 local38 *= 0.5f;
628
629 local70 = localc0;
630 localc0.SetMatrixProduct(local70, (float*) m_local2world.GetData());
631
632 local70 = local9c;
633 local9c.SetMatrixProduct(local70, (float*) m_local2world.GetData());
634
635 local70 = local168;
636 local168.SetMatrixProduct(local70, (float*) m_local2world.GetData());
637
638 p_v3 = m_local2world[3];
639
640 LegoS32 i;
641 for (i = 0; i < 6; i++) {
642 local150[i] = m_local2world[i % 3];
643
644 if (i > 2) {
645 local150[i][3] = -local58.Dot(local58, local150[i]);
646 }
647 else {
648 local150[i][3] = -locala8.Dot(locala8, local150[i]);
649 }
650
651 if (local150[i][3] + local38.Dot(local38, local150[i]) < 0.0f) {
652 local150[i] *= -1.0f;
653 }
654 }
655
656 for (i = 0; i < 6; i++) {
657 float local50 = p_v2.Dot(p_v2, local150[i]);
658
659 if (local50 >= 0.01 || local50 < -0.01) {
660 local50 = -((local150[i][3] + local4c.Dot(local4c, local150[i])) / local50);
661
662 if (local50 >= 0.0f && local50 <= p_f1) {
663 Mx3DPointFloat local17c(p_v2);
664 local17c *= local50;
665 local17c += local4c;
666
667 LegoS32 j;
668 for (j = 0; j < 6; j++) {
669 if (i != j && i - j != 3 && j - i != 3) {
670 if (local150[j][3] + local17c.Dot(local17c, local150[j]) < 0.0f) {
671 break;
672 }
673 }
674 }
675
676 if (j == 6) {
677 return 1;
678 }
679 }
680 }
681 }
682 }
683 else {
684 Mx3DPointFloat v1(p_v1);
686
687 float local10 = GetWorldBoundingSphere().Radius();
688 float local8 = p_v2.Dot(p_v2, p_v2);
689 float localc = p_v2.Dot(p_v2, v1) * 2.0f;
690 float local14 = v1.Dot(v1, v1) - (local10 * local10);
691
692 if (local8 >= 0.001 || local8 <= -0.001) {
693 float local1c = -1.0f;
694 float local18 = (localc * localc) - (local14 * local8 * 4.0f);
695
696 if (local18 >= -0.001) {
697 local8 *= 2.0f;
698 localc = -localc;
699
700 if (local18 > 0.0f) {
701 local18 = sqrt(local18);
702 float local184 = (localc + local18) / local8;
703 float local188 = (localc - local18) / local8;
704
705 if (local184 > 0.0f && local188 > local184) {
706 local1c = local184;
707 }
708 else if (local188 > 0.0f) {
709 local1c = local188;
710 }
711 else {
712 return 0;
713 }
714 }
715 else {
716 local1c = localc / local8;
717 }
718
719 if (local1c >= 0.0f && p_f1 >= local1c) {
720 p_v3 = p_v2;
721 p_v3 *= local1c;
722 p_v3 += p_v1;
723 return 1;
724 }
725 }
726 }
727 }
728
729 return 0;
730}
731
732// FUNCTION: LEGO1 0x100a9a50
733TimeROI::TimeROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList, LegoTime p_time) : LegoROI(p_renderer, p_lodList)
734{
735 m_time = p_time;
736}
737
738// FUNCTION: LEGO1 0x100a9b40
739// FUNCTION: BETA10 0x1018bbf0
741{
742 LegoTime time = p_time - m_time;
743
744 if (time) {
745 m_time = p_time;
746
747 Mx3DPointFloat targetPosition(p_matrix[3]);
748 Vector3 vec(m_local2world[3]);
749
750 targetPosition -= vec;
751 targetPosition /= time / 1000.0;
752
753 FUN_100a5a30(targetPosition);
754 }
755}
756
757// FUNCTION: LEGO1 0x100a9bf0
758LegoBool LegoROI::GetRGBAColor(const LegoChar* p_name, float& p_red, float& p_green, float& p_blue, float& p_alpha)
759{
760 if (p_name == NULL) {
761 return FALSE;
762 }
763
764 char p_updatedName[32];
765 if (g_colorOverride) {
766 if (g_colorOverride(p_name, p_updatedName, sizeof(p_updatedName))) {
767 p_name = p_updatedName;
768 }
769 }
770
771 return ColorAliasLookup(p_name, p_red, p_green, p_blue, p_alpha);
772}
773
774// FUNCTION: LEGO1 0x100a9c50
775// FUNCTION: BETA10 0x1018bdd9
776LegoBool LegoROI::ColorAliasLookup(const LegoChar* p_param, float& p_red, float& p_green, float& p_blue, float& p_alpha)
777{
778 for (LegoU32 i = 0; i < sizeOfArray(g_roiColorAliases); i++) {
779 if (strcmpi(g_roiColorAliases[i].m_name, p_param) == 0) {
780 p_red = g_roiColorAliases[i].m_red / 255.0;
781 p_green = g_roiColorAliases[i].m_green / 255.0;
782 p_blue = g_roiColorAliases[i].m_blue / 255.0;
783 p_alpha = g_roiColorAliases[i].m_alpha / 255.0;
784 return TRUE;
785 }
786 }
787
788 return FALSE;
789}
790
791// FUNCTION: LEGO1 0x100a9cf0
792LegoBool LegoROI::GetPaletteEntries(const LegoChar* p_name, unsigned char* paletteEntries, LegoU32 p_numEntries)
793{
794 if (p_name == NULL) {
795 return FALSE;
796 }
797
798 // Note: g_textureHandler is never set in the code base
799 if (g_textureHandler != NULL) {
800 return g_textureHandler(p_name, paletteEntries, p_numEntries);
801 }
802
803 paletteEntries[0] = '\0';
804 return FALSE;
805}
806
807// FUNCTION: LEGO1 0x100a9d30
809{
810 g_colorOverride = p_colorOverride;
811}
812
813// FUNCTION: LEGO1 0x100a9d40
814void LegoROI::SetName(const LegoChar* p_name)
815{
816 if (m_name != NULL) {
817 delete[] m_name;
818 }
819
820 if (p_name != NULL) {
821 m_name = new LegoChar[strlen(p_name) + 1];
822 strcpy(m_name, p_name);
823 strlwr(m_name);
824 }
825 else {
826 m_name = NULL;
827 }
828}
829
830// FUNCTION: LEGO1 0x100a9dd0
831// FUNCTION: BETA10 0x1018bfdb
833{
834 int lodCount = GetLODCount();
835 for (LegoS32 i = 0; i < lodCount; i++) {
836 LegoLOD* lod = (LegoLOD*) GetLOD(i);
837 lod->ClearMeshOffset();
838 }
839}
840
841// FUNCTION: LEGO1 0x100a9e10
842void LegoROI::SetDisplayBB(int p_displayBB)
843{
844 // Intentionally empty function
845}
846
847// FUNCTION: LEGO1 0x100aa340
849{
850 return .5;
851}
852
853// FUNCTION: LEGO1 0x100aa350
855{
857}
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
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
size_t Size() const
[AI] Returns the current number of LODObject pointers contained.
Definition: lodlist.h:165
const T * PushBack(const T *)
[AI] Typed append.
Definition: lodlist.h:243
const T * PopBack()
[AI] Typed remove.
Definition: lodlist.h:249
[AI] Holds per-node animation data for a model's animation tree.
Definition: legoanim.h:144
LegoResult CreateLocalTransform(LegoFloat p_time, Matrix4 &p_matrix)
[AI] Computes the interpolated local transformation matrix for this node at the given animation time.
Definition: legoanim.cpp:728
LegoBool FUN_100a0990(LegoFloat p_time)
[AI] Evaluates morph keys at the given animation time and returns result (typically affects mesh shap...
Definition: legoanim.cpp:923
LegoU16 GetUnknown0x20()
[AI] Unknown, used in scene/camera calculations (purpose unclear).
Definition: legoanim.h:180
LegoChar * GetName()
[AI] Name of this animation node (used for lookup/mapping to scene graph).
Definition: legoanim.h:163
[AI] Root class for all node-based animation blending/structure.
Definition: legoanim.h:356
[AI] Represents an axis-aligned 3D bounding box, defined by minimum and maximum corners.
Definition: legobox.h:11
LegoResult Read(LegoStorage *p_storage)
[AI] Reads the bounding box data from a LegoStorage stream.
Definition: legobox.cpp:10
LegoVertex & GetMax()
[AI] Returns a reference to the maximum vertex of the box.
Definition: legobox.h:29
LegoVertex & GetMin()
[AI] Returns a reference to the minimum vertex of the box.
Definition: legobox.h:17
T * Get(const char *p_name)
Retrieve the element mapped to the given name, or nullptr if missing.
Definition: legocontainer.h:92
[AI] Level-Of-Detail (LOD) object used for rendering and managing polygonal mesh data with LOD switch...
Definition: legolod.h:27
void ClearMeshOffset()
[AI] Reset mesh offset index to start at 0, affecting which meshes are updated by future color/textur...
Definition: legolod.cpp:393
LegoResult SetTextureInfo(LegoTextureInfo *p_textureInfo)
[AI] Assigns the same texture group to all textured meshes in this LOD.
Definition: legolod.cpp:340
LegoResult SetColor(LegoFloat p_red, LegoFloat p_green, LegoFloat p_blue, LegoFloat p_alpha)
[AI] Overrides the color of all non-textured mesh parts for this LOD.
Definition: legolod.cpp:328
LegoResult GetTextureInfo(LegoTextureInfo *&p_textureInfo)
[AI] Retrieves the texture info/group of the first mesh with group texture in this LOD.
Definition: legolod.cpp:366
LegoResult Read(Tgl::Renderer *p_renderer, LegoTextureContainer *p_textureContainer, LegoStorage *p_storage)
[AI] Load LOD geometry and material info from storage, building Tgl::Mesh group(s).
Definition: legolod.cpp:56
[AI] Represents a Real-time Object Instance enriched with LEGO-specific functionality.
Definition: legoroi.h:43
LegoResult FUN_100a8da0(LegoTreeNode *p_node, const Matrix4 &p_matrix, LegoTime p_time, LegoROI *p_roi)
[AI] [Unknown function.
Definition: legoroi.cpp:382
LegoU32 FUN_100a9410(Vector3 &p_v1, Vector3 &p_v2, float p_f1, float p_f2, Vector3 &p_v3, LegoBool p_collideBox)
[AI] Tests for collision along or within sphere/box, and computes intersection point as needed.
Definition: legoroi.cpp:594
LegoResult FUN_100a93b0(const LegoChar *p_name)
[AI] Like SetLodColor, but uses a different implementation or legacy style.
Definition: legoroi.cpp:582
static void FUN_100a8e80(LegoTreeNode *p_node, Matrix4 &p_matrix, LegoTime p_time, LegoROI **p_roiMap)
[AI] [Static] Recursively evaluates animation nodes, updating the transformation matrices and visibil...
Definition: legoroi.cpp:414
~LegoROI() override
[AI] Destroys the LegoROI, cleaning up children and name resources.
Definition: legoroi.cpp:88
static void configureLegoROI(int p_roi)
[AI] [Static] Configures the global ROI loading limit, controlling max LODs at load time.
Definition: legoroi.cpp:66
LegoResult GetTextureInfo(LegoTextureInfo *&p_textureInfo)
[AI] Attempts to retrieve a texture info pointer used by any LOD in this ROI or its children.
Definition: legoroi.cpp:537
LegoROI(Tgl::Renderer *p_renderer)
[AI] Constructs a new LegoROI for a given renderer.
Definition: legoroi.cpp:72
LegoResult SetTextureInfo(LegoTextureInfo *p_textureInfo)
[AI] Associates every LOD in this ROI (and sub-ROIs) with a given texture (palette/material informati...
Definition: legoroi.cpp:510
static void SetColorOverride(ColorOverride p_colorOverride)
[AI] [Static] Sets the global color override callback function to allow palette remapping or customiz...
Definition: legoroi.cpp:808
LegoROI * FindChildROI(const LegoChar *p_name, LegoROI *p_roi)
[AI] Recursively searches for a child ROI by name, starting at the given ROI.
Definition: legoroi.cpp:349
void ClearMeshOffset()
[AI] Resets mesh offset for all LODs in this ROI.
Definition: legoroi.cpp:832
static LegoResult FUN_100a8cb0(LegoAnimNodeData *p_data, LegoTime p_time, Matrix4 &p_matrix)
[AI] [Static] Sets the transform matrix for a given animation node at a specific time.
Definition: legoroi.cpp:340
LegoResult FUN_100a9330(LegoFloat p_red, LegoFloat p_green, LegoFloat p_blue, LegoFloat p_alpha)
[AI] Alias to SetLodColor; applies color to all LODs and children.
Definition: legoroi.cpp:563
LegoResult SetFrame(LegoAnim *p_anim, LegoTime p_time)
[AI] Sets the current animation frame for this ROI based on a parsed animation structure.
Definition: legoroi.cpp:471
static LegoBool ColorAliasLookup(const LegoChar *p_param, float &p_red, float &p_green, float &p_blue, float &p_alpha)
[AI] [Static] Looks up a color alias in the static alias table and sets p_red/p_green/p_blue/p_alpha ...
Definition: legoroi.cpp:776
void UpdateWorldBoundingVolumes() override
[AI] Updates this ROI's world-space bounding volumes based on its local-to-world transform.
Definition: legoroi.cpp:854
LegoResult SetLodColor(LegoFloat p_red, LegoFloat p_green, LegoFloat p_blue, LegoFloat p_alpha)
[AI] Sets the RGBA color for all LODs and recursively for all children.
Definition: legoroi.cpp:484
static void FUN_100a8fd0(LegoTreeNode *p_node, Matrix4 &p_matrix, LegoTime p_time, LegoROI **p_roiMap)
[AI] [Static] Similar to FUN_100a8e80, but only updates transformation matrices, not visibility or in...
Definition: legoroi.cpp:445
static void FUN_100a81b0(const LegoChar *p_error, const LegoChar *p_name)
[AI] [Static] Prints or logs an error message about missing ROI for animation (no-op in release).
Definition: legoroi.cpp:61
static LegoBool GetPaletteEntries(const LegoChar *p_name, unsigned char *paletteEntries, LegoU32 p_numEntries)
[AI] [Static] Fetches palette entries for a named texture using current texture handler.
Definition: legoroi.cpp:792
float IntrinsicImportance() const override
[AI] Returns the importance rating for LOD/visibility management (fixed value).
Definition: legoroi.cpp:848
LegoResult Read(OrientableROI *p_unk0xd4, Tgl::Renderer *p_renderer, ViewLODListManager *p_viewLODListManager, LegoTextureContainer *p_textureContainer, LegoStorage *p_storage)
[AI] Reads and initializes this ROI from a LEGO project resource stream, populating geometry,...
Definition: legoroi.cpp:108
void SetDisplayBB(int p_displayBB)
[AI] Sets whether to display or hide the bounding box.
Definition: legoroi.cpp:842
const LegoChar * GetName() const
[AI] Gets this ROI's name.
Definition: legoroi.h:287
void SetName(const LegoChar *p_name)
[AI] Sets this ROI's name, replacing the previous (converted to lower-case).
Definition: legoroi.cpp:814
static LegoBool GetRGBAColor(const LegoChar *p_name, float &p_red, float &p_green, float &p_blue, float &p_alpha)
[AI] [Static] Resolves a logical color alias into RGBA floats.
Definition: legoroi.cpp:758
[AI] Represents a sphere in 3D space, used for bounding volume calculations and spatial queries.
Definition: legosphere.h:13
LegoFloat GetRadius()
[AI] Retrieves the current radius of the sphere.
Definition: legosphere.h:37
LegoVertex & GetCenter()
[AI] Returns a reference to the center vertex of the sphere.
Definition: legosphere.h:25
LegoResult Read(LegoStorage *p_storage)
[AI] Reads the center and radius of the sphere from a binary storage source.
Definition: legosphere.cpp:9
Abstract base class providing an interface for file-like storage with binary and text read/write oper...
Definition: legostorage.h:16
virtual LegoResult SetPosition(LegoU32 p_position)=0
Set current read/write position in stream.
virtual LegoResult Read(void *p_buffer, LegoU32 p_size)=0
Read bytes from storage into buffer.
Specialized LegoContainer handling LegoTextureInfo objects and their DirectDraw/Direct3D caching.
[AI] Contains DirectDraw and Direct3DRM handles and metadata for a texture used in the LEGO Island re...
[AI] Represents a node within a general, N-ary tree structure.
Definition: legotree.h:44
LegoTreeNodeData * GetData()
[AI] Returns the data payload stored at this node (may be nullptr). [AI]
Definition: legotree.h:54
LegoU32 GetNumChildren()
[AI] Returns the number of direct children of this node. [AI]
Definition: legotree.h:63
LegoTreeNode * GetChild(LegoU32 p_i)
[AI] Gets the child node at the specified index (no bounds checking).
Definition: legotree.h:72
LegoTreeNode * GetRoot()
[AI] Returns a pointer to the root node of the tree. [AI]
Definition: legotree.h:112
4x4 Matrix class with virtual interface for manipulation and transformation.
Definition: matrix.h:24
virtual float(* GetData())[4]
Gets modifiable access to the 4x4 float matrix.
virtual void Product(float(*p_a)[4], float(*p_b)[4])
Multiplies two 4x4 float matrices, storing result in this.
virtual void SetIdentity()
Sets this matrix to identity (diagonal 1, others 0).
[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
[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.
BoundingBox m_unk0x80
An unknown bounding box; usage unclear, could be related to extended collision or volume testing.
void FUN_100a5a30(const Vector3 &p_world_velocity)
Sets the world velocity to the provided vector.
MxMatrix m_local2world
The transform from local to world space; 4x4 transformation matrix.
OrientableROI * m_parentROI
If non-null, points to the parent OrientableROI for local/world transformation hierarchy.
BoundingSphere m_world_bounding_sphere
The object's bounding sphere in world space, recalculated from m_local2world.
[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
void SetVisibility(unsigned char p_visible)
[AI] Sets the visibility flag to the provided value.
Definition: roi.h:235
int GetLODCount() const
[AI] Returns the number of available LODs for this ROI.
Definition: roi.h:216
const LODObject * GetLOD(int i) const
[AI] Returns the LODObject at the specified index.
Definition: roi.h:208
[AI] Main interface/factory for rendering resources and scene graphs.
Definition: tgl.h:188
[AI] An extension of LegoROI that adds support for keeping and applying a base time reference (used f...
Definition: legoroi.h:342
void FUN_100a9b40(Matrix4 &p_matrix, LegoTime p_time)
[AI] Updates animated position/offset by integrating movement since last update (applying time delta)...
Definition: legoroi.cpp:740
TimeROI(Tgl::Renderer *p_renderer, ViewLODList *p_lodList, LegoTime p_time)
[AI] Creates a TimeROI with reference time and LOD geometry.
Definition: legoroi.cpp:733
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.
[AI] 3D vector class, providing vector and cross-product operations in 3D space.
Definition: vector.h:249
virtual void SetMatrixProduct(const float *p_vec, const float *p_mat)
[AI] Set this vector to the result of a matrix-vector product: result = p_mat * p_vec.
[AI] Manages the lifecycle, lookup, and sharing of ViewLODList instances for different ROI names.
Definition: viewlodlist.h:111
ViewLODList * Create(const ROIName &rROIName, int lodCount)
[AI] Creates and registers a new ViewLODList for a named ROI, with space for the specified number of ...
Definition: viewlodlist.cpp:67
ViewLODList * Lookup(const ROIName &) const
[AI] Looks up an existing ViewLODList by ROI name, incrementing its reference count.
[AI] Reference-counted list of Level-of-Detail (LOD) objects associated with a single ROI (Realtime O...
Definition: viewlodlist.h:30
int Release()
[AI] Decrements the reference count.
[AI] Represents a Level of Detail (LOD) object for rendering, implemented with a mesh builder and sup...
Definition: viewlod.h:20
unsigned char GetUnknown0x08Test8()
[AI] Performs a bitwise AND (mask) with value 0xffffff08 on the internal flag, returning result as an...
Definition: viewlod.h:81
[AI] ViewROI objects represent viewable and placeable objects in the scene, each holding their own tr...
Definition: viewroi.h:13
void VTable0x1c() override
[AI] Updates internal state, potentially related to animation or LOD switching (exact purpose unclear...
Definition: viewroi.cpp:69
void SetLODList(ViewLODList *lodList)
[AI] Sets the ViewLODList for this ROI, managing reference counting.
Definition: viewroi.h:44
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define sizeOfArray(arr)
Definition: decomp.h:23
const char * g_unk0x10101370[]
Definition: legoroi.cpp:46
ColorOverride g_colorOverride
Definition: legoroi.cpp:55
ROIColorAlias g_roiColorAliases[22]
Definition: legoroi.cpp:28
const char * g_unk0x10101390[]
Definition: legoroi.cpp:52
const char * g_unk0x10101380[]
Definition: legoroi.cpp:49
int g_roiConfig
Definition: legoroi.cpp:43
TextureHandler g_textureHandler
Definition: legoroi.cpp:58
unsigned char(* ColorOverride)(const char *, char *, unsigned int)
[AI] Function pointer type for overriding color.
Definition: legoroi.h:15
unsigned char(* TextureHandler)(const char *, unsigned char *, unsigned int)
[AI] Function pointer type for custom palette lookup or texture palette fetching.
Definition: legoroi.h:25
#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
LegoS32 LegoTime
[AI] Time value, typically used for tick counts, durations, or timing; defined as a signed 32-bit int...
Definition: legotypes.h:95
char LegoChar
[AI] Alias for char, for use in character/byte data and string handling.
Definition: legotypes.h:83
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
LegoS32 LegoResult
[AI] Function result type (return code): typically SUCCESS (0) or FAILURE (-1).
Definition: legotypes.h:101
long LegoS32
[AI] Signed 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:65
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
float LegoFloat
[AI] Floating point type used throughout LEGO Island.
Definition: legotypes.h:77
LegoU8 LegoBool
[AI] Boolean value used throughout the codebase.
Definition: legotypes.h:89
float MxFloat
[AI]
Definition: mxtypes.h:68
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...
list< ROI * > CompoundObject
Definition: roi.h:135
const char * m_name
Definition: legoroi.cpp:20
#define SET3(to, from)
Definition: vec.h:310