DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
objectframe.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "objectframe.hpp"
5
6#include "framevu1.hpp"
7#include "mathutil.hpp"
8#include "mglib.hpp"
9
10void CObjectFrame::SetFrame(CFrameVu1 *frame, int level) {
11 if (level < 0) {
12 return;
13 }
14
15 if (level >= 4) {
16 return;
17 }
18
19 this->frame[level] = frame;
20}
21
22void CObjectFrame::FrameObjectOnOff(char *name, int on) {
23 int i;
24 CFrame *found;
25
26 if (name == NULL) {
27 return;
28 }
29
30 for (i = 0; i < 4; i++) {
31 if (this->frame[i] != NULL) {
32 found = this->frame[i]->SearchFrame(name);
33
34 if (found != NULL) {
35 found->attr.draw_on = on;
36 }
37 }
38 }
39}
40
41void CObjectFrame::Draw() {
42 if (this->draw_on == 0) {
43 return;
44 }
45
46 if (this->frame[0] == NULL) {
47 return;
48 }
49
50 this->frame[0]->SetPosition(this->pos);
51 this->frame[0]->SetRotation(this->rotation.x, this->rotation.y, this->rotation.z);
52 this->frame[0]->SetScale(this->scale[0], this->scale[1], this->scale[2]);
53 MGDraw(this->frame[0]);
54}
55
56void CObjectFrame::DrawLOD(float *distance, int lowest, int highest, int *out_level) {
57 float local_to_world[4][4];
58 float local_to_eye[4][4];
59 int lod;
60 int level;
61 float eye_distance;
62
63 if (this->draw_on == 0) {
64 return;
65 }
66
67 if (this->frame[0] == NULL) {
68 return;
69 }
70
71 // Keep the range of levels within the four the object holds.
72 if (lowest < 0) {
73 lowest = 0;
74 }
75
76 if (highest >= 4) {
77 highest = 3;
78 }
79
80 if (highest < lowest) {
81 highest = lowest;
82 }
83
84 if (lowest == highest) {
85 lod = lowest;
86
87 while (lod >= 0) {
88 if (this->frame[lod] != NULL) {
89 break;
90 }
91
92 lod--;
93 }
94 } else {
95 // The level comes from how far the object is from the eye. The frame
96 // carries the position and the angle so that its matrix gives the
97 // distance the eye sees, not the distance along the world axes.
98 this->frame[0]->SetPosition(this->pos);
99 this->frame[0]->SetRotation(this->rotation.x, this->rotation.y, this->rotation.z);
100 this->frame[0]->GetLWMatrix(local_to_world);
101 MulMatrix(local_to_eye, mgRenderInfo.view_scaled, local_to_world);
102 eye_distance = local_to_eye[3][0] * local_to_eye[3][0] + local_to_eye[3][1] * local_to_eye[3][1] + local_to_eye[3][2] * local_to_eye[3][2];
103
104 level = 0;
105
106 for (lod = 0; lod < 4; lod++) {
107 if (eye_distance < distance[lod] * distance[lod]) {
108 break;
109 }
110
111 level = lod;
112 }
113
114 if (level <= lowest) {
115 level = lowest;
116 }
117
118 if (level >= highest) {
119 level = highest;
120 }
121
122 lod = level;
123
124 while (lod >= 0) {
125 if (this->frame[lod] != NULL) {
126 break;
127 }
128
129 lod--;
130 }
131 }
132
133 if (this->frame[lod] != NULL) {
134 this->frame[lod]->SetPosition(this->pos);
135 this->frame[lod]->SetRotation(this->rotation.x, this->rotation.y, this->rotation.z);
136 this->frame[lod]->SetScale(this->scale[0], this->scale[1], this->scale[2]);
137 MGDraw(this->frame[lod]);
138 }
139
140 if (out_level != NULL) {
141 *out_level = lod;
142 }
143}
144
146 int i;
147
149 this->rotation_changed = false;
150 this->draw_on = 1;
151 this->frame[0] = frame;
152
153 for (i = 1; i < 4; i++) {
154 this->frame[i] = NULL;
155 }
156
157 this->scale[0] = 1.0f;
158 this->scale[1] = 1.0f;
159 this->scale[2] = 1.0f;
160}
short draw_on
Definition frame.hpp:27
CFrameAttr attr
Definition frame.hpp:65
void Initialize(CFrameVu1 *frame)
virtual void DrawLOD(float *distance, int lowest, int highest, int *out_level)
s32 rotation_changed
Definition op_b.cpp:77
CFrameVu1 * frame[4]
Definition op_b.cpp:76
s32 draw_on
Definition op_b.cpp:78
float scale[4]
Definition object.hpp:26
CVector3_f_ rotation
Definition object.hpp:23
void Initialize(float mass)
Definition object.cpp:184
float pos[4]
Definition object.hpp:18
sceVu0FMATRIX view_scaled