DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
seireiking.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "title/seireiking.hpp"
5
6#include <cstdlib>
7
8#include "camera.hpp"
9#include "mglib.hpp"
10#include "rect.hpp"
11#include "snd.hpp"
12#include "texture.hpp"
13
14/* The jitter is taken in hundredths so that `spread` reads as a whole-unit radius: the caller in
15 the movie asks for 2 and gets an offset anywhere in [-2, 2] to a hundredth. */
16void CSeireiKing::Draw(float *origin, float size, int spread) {
17 sceVu0FVECTOR point;
18 int corner0[4];
19 int corner1[4];
20 int corner2[4];
21 int corner3[4];
22 sceGsAlpha blend;
23 sceGsZbuf zbuf;
24 int i;
25
26 blend = mgAlpha;
27 blend.bits.a = 0;
28 blend.bits.b = 2;
29 blend.bits.c = 0;
30 blend.bits.d = 1;
31 MGSetGsALPHA(&blend);
32
33 zbuf = mgZBuffer;
34 zbuf.bits.zmsk = 1;
35 MGSetGsZBUF(&zbuf);
36
37 sceVu0CopyVector(this->position[0], origin);
38 position[0][0] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
39 position[0][1] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
40 position[0][2] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
41
42 for (i = 0; i < 19; i++) {
43 if (count[i] < 0) {
44 continue;
45 }
46
47 point[0] = position[i][0];
48 point[1] = position[i][1];
49 point[2] = position[i][2];
50 point[3] = 1.0f;
51
52 if (MGRotTransPers3DSprite(corner0, corner1, point, size, size / 2.0f, 0) == 1) {
53 corner2[0] = corner1[0];
54 corner2[1] = corner0[1];
55 corner2[2] = corner0[2];
56 corner2[3] = corner0[3];
57 corner3[0] = corner0[0];
58 corner3[1] = corner1[1];
59 corner3[2] = corner1[2];
60 corner3[3] = corner1[3];
61
62 switch (rand() % 3) {
63 case 0: {
64 CRect_i_ rect;
65
66 rect.x = 0;
67 rect.y = 0;
68 rect.width = 64;
69 rect.height = 64;
70 set3DSprite(Vif1Packet, TexManager.GetTexture("eef01", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
71 break;
72 }
73
74 case 1: {
75 CRect_i_ rect;
76
77 rect.x = 0;
78 rect.y = 0;
79 rect.width = 64;
80 rect.height = 64;
81 set3DSprite(Vif1Packet, TexManager.GetTexture("eef02", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
82 break;
83 }
84
85 case 2: {
86 CRect_i_ rect;
87
88 rect.x = 0;
89 rect.y = 0;
90 rect.width = 64;
91 rect.height = 64;
92 set3DSprite(Vif1Packet, TexManager.GetTexture("eef04", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
93 break;
94 }
95 }
96 }
97
98 point[0] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
99 point[1] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
100 point[2] += (float) (spread * 100 - rand() % (spread * 200)) / 100.0f;
101
102 if (MGRotTransPers3DSprite(corner0, corner1, point, size, size / 2.0f, 0) == 1) {
103 corner2[0] = corner1[0];
104 corner2[1] = corner0[1];
105 corner2[2] = corner0[2];
106 corner2[3] = corner0[3];
107 corner3[0] = corner0[0];
108 corner3[1] = corner1[1];
109 corner3[2] = corner1[2];
110 corner3[3] = corner1[3];
111
112 switch (rand() % 4) {
113 case 0: {
114 CRect_i_ rect;
115
116 rect.x = 0;
117 rect.y = 0;
118 rect.width = 32;
119 rect.height = 32;
120 set3DSprite(Vif1Packet, TexManager.GetTexture("eef05", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
121 break;
122 }
123
124 case 1: {
125 CRect_i_ rect;
126
127 rect.x = 32;
128 rect.y = 0;
129 rect.width = 32;
130 rect.height = 32;
131 set3DSprite(Vif1Packet, TexManager.GetTexture("eef05", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
132 break;
133 }
134
135 case 2: {
136 CRect_i_ rect;
137
138 rect.x = 0;
139 rect.y = 32;
140 rect.width = 32;
141 rect.height = 32;
142 set3DSprite(Vif1Packet, TexManager.GetTexture("eef05", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
143 break;
144 }
145
146 case 3: {
147 CRect_i_ rect;
148
149 rect.x = 32;
150 rect.y = 32;
151 rect.width = 32;
152 rect.height = 32;
153 set3DSprite(Vif1Packet, TexManager.GetTexture("eef05", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[i]);
154 break;
155 }
156 }
157 }
158 }
159
160 MGSetGsALPHA(0);
161 MGSetGsZBUF(0);
162}
163
164/* The head, which the caller places rather than the effect. It is projected twice and only the
165 depth of the second projection is kept, the second being the same point moved twenty-five units
166 towards the camera, so the whole sprite takes a depth the thing carrying it cannot be in front
167 of. */
168void CSeireiKing::Draw2(CCamera *camera, float *head, float *source) {
169 sceVu0FVECTOR direction;
170 sceVu0FVECTOR point;
171 int corner0[4];
172 int corner1[4];
173 int near0[4];
174 int near1[4];
175 int corner2[4];
176 int corner3[4];
177 sceGsAlpha blend;
178 sceGsZbuf zbuf;
179
180 camera->GetPos(direction);
181 direction[0] -= source[0];
182 direction[1] -= source[1];
183 direction[2] -= source[2];
184 sceVu0Normalize(direction, direction);
185 direction[0] *= 25.0f;
186 direction[1] *= 25.0f;
187 direction[2] *= 25.0f;
188
189 blend = mgAlpha;
190 blend.bits.a = 0;
191 blend.bits.b = 2;
192 blend.bits.c = 0;
193 blend.bits.d = 1;
194 MGSetGsALPHA(&blend);
195
196 zbuf = mgZBuffer;
197 zbuf.bits.zmsk = 1;
198 MGSetGsZBUF(&zbuf);
199
200 if (alpha[19] > 0.0f) {
201 alpha[19] -= 1.0f;
202 sceVu0CopyVector(position[19], head);
203
204 point[0] = position[19][0];
205 point[1] = position[19][1];
206 point[2] = position[19][2];
207 point[3] = 1.0f;
208
209 if (MGRotTransPers3DSprite(corner0, corner1, point, 5.0f, 2.5f, 0) == 1) {
210 CRect_i_ rect;
211
212 corner2[0] = corner1[0];
213 corner2[1] = corner0[1];
214 corner2[2] = corner0[2];
215 corner2[3] = corner0[3];
216 corner3[0] = corner0[0];
217 corner3[1] = corner1[1];
218 corner3[2] = corner1[2];
219 corner3[3] = corner1[3];
220
221 point[0] += direction[0];
222 point[1] += direction[1];
223 point[2] += direction[2];
224
225 if (MGRotTransPers3DSprite(near0, near1, point, 5.0f, 2.5f, 0) == 1) {
226 corner1[2] = near0[2];
227 corner3[2] = near0[2];
228 corner0[2] = near0[2];
229 corner2[2] = near0[2];
230 }
231
232 rect.x = 0;
233 rect.y = 0;
234 rect.width = 64;
235 rect.height = 64;
236 set3DSprite(Vif1Packet, TexManager.GetTexture("eef01", -1), rect, corner0, corner2, corner3, corner1, (u8) alpha[19]);
237 }
238 }
239
240 MGSetGsALPHA(0);
241 MGSetGsZBUF(0);
242}
243
244/* The trail is shifted rather than advanced: every element takes the position of the one in front
245 of it and `Draw` writes the new head, so an element's own age is all that decides how it looks. */
247 int i;
248
249 for (i = 0; i < 18; i++) {
250 sceVu0CopyVector(position[18 - i], position[17 - i]);
251 count[i]++;
252 }
253}
void GetPos(float *pos)
Definition camera.cpp:230
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
float alpha[20]
int count[20]
void Draw(float *origin, float size, int spread)
void Draw2(CCamera *camera, float *head, float *source)
sceVu0FVECTOR position[20]