DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
majinbeem.cpp
1#pragma helper_mask_gpr 0x30
2
3#include "title/majinbeem.hpp"
4
5#include <cmath>
6
7#include "camera.hpp"
8#include "mathutil.hpp"
9#include "mglib.hpp"
10#include "rect.hpp"
11#include "snd.hpp"
12#include "texture.hpp"
13
14/* The tail, which is drawn where its elements already are: the head is the only element `Step`
15 moves and every other one is a place the head has been. */
17 sceVu0FVECTOR camera_position;
18 sceVu0FVECTOR position;
19 int top_left[4];
20 int bottom_right[4];
21 int top_right[4];
22 int bottom_left[4];
23 sceGsAlpha alpha;
24 sceGsZbuf zbuf;
25 int i;
26
27 camera->GetPos(camera_position);
28
29 alpha = mgAlpha;
30 alpha.bits.a = 0;
31 alpha.bits.b = 2;
32 alpha.bits.c = 0;
33 alpha.bits.d = 1;
34 MGSetGsALPHA(&alpha);
35
36 zbuf = mgZBuffer;
37 zbuf.bits.zmsk = 1;
38 MGSetGsZBUF(&zbuf);
39
40 for (i = 0; i < 59; i++) {
41 if (active != 1) {
42 continue;
43 }
44
45 if (counters[i] < 0) {
46 continue;
47 }
48
49 position[0] = positions[i][0];
50 position[1] = positions[i][1];
51 position[2] = positions[i][2];
52 position[3] = 1.0f;
53
54 if (MGRotTransPers3DSprite(top_left, bottom_right, position, sizes[i], sizes[i] / 2.0f, 0) != 1) {
55 continue;
56 }
57
58 top_right[0] = bottom_right[0];
59 top_right[1] = top_left[1];
60 top_right[2] = top_left[2];
61 top_right[3] = top_left[3];
62 bottom_left[0] = top_left[0];
63 bottom_left[1] = bottom_right[1];
64 bottom_left[2] = bottom_right[2];
65 bottom_left[3] = bottom_right[3];
66
67 {
68 CRect_i_ rect;
69
70 rect.x = 0;
71 rect.y = 0;
72 rect.width = 128;
73 rect.height = 128;
74 set3DSprite(Vif1Packet, TexManager.GetTexture("beem", -1), rect, top_left, top_right, bottom_left, bottom_right, (u_char) alphas[i]);
75 }
76 }
77
78 MGSetGsALPHA(0);
79 MGSetGsZBUF(0);
80}
81
82/* The head, which the caller places rather than the effect: whatever is carrying the beam hands
83 its own position in every tick.
84 The head is projected twice and only the depth of the second projection is kept. The second is
85 the same point moved fifteen units towards the camera, so all four corners take a depth the
86 thing that fired the beam cannot be in front of. */
87void CMajinBeem::Draw2(CCamera *camera, float *head, float *source) {
88 sceVu0FVECTOR direction;
89 sceVu0FVECTOR position;
90 int top_left[4];
91 int bottom_right[4];
92 int near_top_left[4];
93 int near_bottom_right[4];
94 int top_right[4];
95 int bottom_left[4];
96 sceGsAlpha alpha;
97 sceGsZbuf zbuf;
98
99 camera->GetPos(direction);
100 direction[0] -= source[0];
101 direction[1] -= source[1];
102 direction[2] -= source[2];
103 sceVu0Normalize(direction, direction);
104 direction[0] *= 15.0f;
105 direction[1] *= 15.0f;
106 direction[2] *= 15.0f;
107
108 alpha = mgAlpha;
109 alpha.bits.a = 0;
110 alpha.bits.b = 2;
111 alpha.bits.c = 0;
112 alpha.bits.d = 1;
113 MGSetGsALPHA(&alpha);
114
115 zbuf = mgZBuffer;
116 zbuf.bits.zmsk = 1;
117 MGSetGsZBUF(&zbuf);
118
119 if (alphas[59] > 0.0f) {
120 alphas[59] -= 1.0f;
121 sizes[59] -= 0.25f;
122 sceVu0CopyVector(positions[59], head);
123
124 position[0] = positions[59][0];
125 position[1] = positions[59][1];
126 position[2] = positions[59][2];
127 position[3] = 1.0f;
128
129 if (MGRotTransPers3DSprite(top_left, bottom_right, position, sizes[59], sizes[59] / 2.0f, 0) == 1) {
130 CRect_i_ rect;
131
132 top_right[0] = bottom_right[0];
133 top_right[1] = top_left[1];
134 top_right[2] = top_left[2];
135 top_right[3] = top_left[3];
136 bottom_left[0] = top_left[0];
137 bottom_left[1] = bottom_right[1];
138 bottom_left[2] = bottom_right[2];
139 bottom_left[3] = bottom_right[3];
140
141 position[0] += direction[0];
142 position[1] += direction[1];
143 position[2] += direction[2];
144
145 if (MGRotTransPers3DSprite(near_top_left, near_bottom_right, position, sizes[59], sizes[59] / 2.0f, 0) == 1) {
146 bottom_right[2] = near_top_left[2];
147 bottom_left[2] = near_top_left[2];
148 top_left[2] = near_top_left[2];
149 top_right[2] = near_top_left[2];
150 }
151
152 rect.x = 0;
153 rect.y = 0;
154 rect.width = 128;
155 rect.height = 128;
156 set3DSprite(Vif1Packet, TexManager.GetTexture("beem", -1), rect, top_left, top_right, bottom_left, bottom_right, (u_char) alphas[59]);
157 }
158 }
159
160 MGSetGsALPHA(0);
161 MGSetGsZBUF(0);
162}
163
164/* The whole path is fixed on the first tick: the two angles source the head's starting point to the
165 target are taken once and nothing steers afterwards, so the beam is straight. */
167 int substep;
168 int element;
169
170 switch (state) {
171 case MAJIN_BEEM_AIM:
172 pitch = atan2f(target[0] - positions[0][0], target[1] - positions[0][1]);
173 yaw = atan2f(target[0] - positions[0][0], target[2] - positions[0][2]);
174 state++;
175 break;
176
177 case MAJIN_BEEM_TRAVEL:
178 for (substep = 0; substep < 3; substep++) {
179 for (element = 0; element < 58; element++) {
180 sceVu0CopyVector(positions[58 - element], positions[57 - element]);
181 counters[element]++;
182 }
183
184 positions[0][1] += speed / 3.0f * cos(pitch);
185 positions[0][0] += speed / 3.0f * sin(yaw);
186 positions[0][2] += speed / 3.0f * cos(yaw);
187 }
188
189 if (counters[58] >= 200) {
190 active = false;
191 }
192
193 break;
194 }
195}
void GetPos(float *pos)
Definition camera.cpp:230
int counters[60]
Definition majinbeem.hpp:28
void Step()
sceVu0FVECTOR positions[60]
Definition majinbeem.hpp:25
float alphas[60]
Definition majinbeem.hpp:30
void Draw(CCamera *camera)
Definition majinbeem.cpp:16
float pitch
Definition majinbeem.hpp:32
void Draw2(CCamera *camera, float *head, float *source)
Definition majinbeem.cpp:87
sceVu0FVECTOR target
Definition majinbeem.hpp:26
float sizes[60]
Definition majinbeem.hpp:29
float speed
Definition majinbeem.hpp:34
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19