Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
damage_stars.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_090004C0_343500[];
5extern Gfx D_090005E0_343620[];
6
7u8 D_E0030E90[] = {
8 254, 172, 172,
9 254, 172, 213,
10 254, 180, 154,
11 213, 180, 254,
12 180, 180, 254,
13 180, 221, 254,
14 180, 254, 254,
15 180, 254, 213,
16 180, 254, 180,
17 213, 254, 180,
18 254, 254, 180,
19 254, 213, 172
20};
21
22f32 D_E0030EB4 = 0.0f;
23
27void damage_stars_appendGfx(void* effect);
28
29void damage_stars_main(s32 type, f32 x, f32 y, f32 z, f32 rotAxisX, f32 rotAxisY, f32 rotAxisZ, s32 number) {
31 EffectBlueprint* bpPtr = &bp;
32 EffectInstance* effect;
34 f32 norm;
35 f32 var_f28;
36 f32 var_f30;
37 f32 rotateX;
38 f32 rotateZ;
39 f32 sp70;
40 Matrix4f mtxRot;
41 s32 i;
42
43 if (number == 0) {
44 return;
45 }
46
47 norm = SQ(rotAxisX) + SQ(rotAxisY) + SQ(rotAxisZ);
48 if (norm == 0.0f) {
49 return;
50 }
51 norm = -1.0f / sqrtf(norm);
52
53 rotAxisX *= norm;
54 rotAxisY *= norm;
55 rotAxisZ *= norm;
56
57 if (rotAxisX != 0.0f) {
58 sp70 = 1.0f;
59 var_f30 = -rotAxisY / rotAxisX;
60 var_f28 = 0.0f;
61 } else if (rotAxisY != 0.0f) {
62 sp70 = -rotAxisX / rotAxisY;
63 var_f30 = 1.0f;
64 var_f28 = 0.0f;
65 } else {
66 sp70 = 0.0f;
67 var_f30 = 1.0f;
68 var_f28 = -rotAxisX / rotAxisZ;
69 }
70
71 norm = SQ(var_f30) + SQ(sp70) + SQ(var_f28);
72 if (norm != 0) {
73 norm = 1.0f / sqrtf(norm);
74
75 var_f30 *= norm;
76 sp70 *= norm;
77 var_f28 *= norm;
78
79 var_f30 *= 8.0f;
80 sp70 *= 8.0f;
81 var_f28 *= 8.0f;
82 rotAxisX *= 8.0f;
83 rotAxisY *= 8.0f;
84 rotAxisZ *= 8.0f;
85
86 bpPtr->unk_00 = 0;
87 bpPtr->init = damage_stars_init;
90 bpPtr->renderUI = NULL;
91 bpPtr->effectID = EFFECT_DAMAGE_STARS;
92
93 effect = create_effect_instance(bpPtr);
94 effect->numParts = number;
95 part = effect->data.damageStars = general_heap_malloc(number * sizeof(*part));
96 ASSERT(effect->data.damageStars != NULL);
97
98 for (i = 0; i < number; i++, part++) {
99 part->type = type;
100 part->pos.x = x;
101 part->pos.y = y;
102 part->pos.z = z;
103
104 switch (type) {
108 guRotateF(mtxRot, (i * 360) / (number - 1), rotAxisX, rotAxisY, rotAxisZ);
109 part->vel.x = rotAxisX + mtxRot[0][0] * var_f30 + mtxRot[1][0] * sp70 + mtxRot[2][0] * var_f28;
110 part->vel.y = rotAxisY + mtxRot[0][1] * var_f30 + mtxRot[1][1] * sp70 + mtxRot[2][1] * var_f28;
111 part->vel.z = rotAxisZ + mtxRot[0][2] * var_f30 + mtxRot[1][2] * sp70 + mtxRot[2][2] * var_f28;
112 break;
114 rotateX = sin_deg(gCameras[gCurrentCameraID].curYaw);
115 rotateZ = -cos_deg(gCameras[gCurrentCameraID].curYaw);
116 guRotateF(mtxRot,
117 (number != 1) ? (i * 100) / (number - 1) - 50 : 0.0f,
118 rotateX, 0.0f, rotateZ);
119 part->vel.x = mtxRot[0][0] * rotAxisX + mtxRot[1][0] * rotAxisY + mtxRot[2][0] * rotAxisZ;
120 part->vel.y = mtxRot[0][1] * rotAxisX + mtxRot[1][1] * rotAxisY + mtxRot[2][1] * rotAxisZ;
121 part->vel.z = mtxRot[0][2] * rotAxisX + mtxRot[1][2] * rotAxisY + mtxRot[2][2] * rotAxisZ;
122 break;
124 rotateX = sin_deg(gCameras[gCurrentCameraID].curYaw);
125 rotateZ = -cos_deg(gCameras[gCurrentCameraID].curYaw);
126 guRotateF(mtxRot, (i * 360.0f) / (number - 1), rotateX, 0.0f, rotateZ);
127 part->vel.x = mtxRot[0][0] * rotAxisX + mtxRot[1][0] * rotAxisY + mtxRot[2][0] * rotAxisZ;
128 part->vel.y = mtxRot[0][1] * rotAxisX + mtxRot[1][1] * rotAxisY + mtxRot[2][1] * rotAxisZ;
129 part->vel.z = mtxRot[0][2] * rotAxisX + mtxRot[1][2] * rotAxisY + mtxRot[2][2] * rotAxisZ;
130 break;
131 }
132
133 switch (type) {
135 part->rollAngleVel = 0;
136 part->timeLeft = 24;
137 break;
139 part->rollAngleVel = 20.0f;
140 part->timeLeft = 24;
141 break;
143 part->rollAngleVel = 20.0f;
144 part->timeLeft = 40;
145 part->vel.x *= 0.5;
146 part->vel.y *= 0.5;
147 part->vel.z *= 0.5;
148 break;
151 part->rollAngleVel = 20.0f;
152 part->timeLeft = 24;
153 break;
154 }
155
156 part->rollAngle = 0;
157 part->lifetime = 0;
158 part->alpha = 255;
159 }
160
161 D_E0030EB4 += 15.0f;
162 if (D_E0030EB4 > 360.0f) {
163 D_E0030EB4 = 0.0f;
164 }
165 }
166}
167
170
172 DamageStarsFXData* part = effect->data.damageStars;
173 s32 time;
174 s32 unk_2C;
175 s32 i;
176
177 part->timeLeft--;
178 part->lifetime++;
179
180 if (part->timeLeft < 0) {
181 remove_effect(effect);
182 return;
183 }
184
185 time = part->timeLeft;
186 unk_2C = part->lifetime;
187
188 for (i = 0; i < effect->numParts; i++, part++) {
189 if (part->type == FX_DAMAGE_STARS_2) {
190 part->vel.y = cos_deg(unk_2C * 6) * 4.0f;
191 part->vel.x *= 0.94;
192 part->vel.z *= 0.94;
193 if (part->vel.y < 0.0f) {
194 part->rollAngleVel *= 0.8;
195 part->alpha *= 0.6;
196 }
197 } else {
198 if (time >= 6) {
199 part->vel.x *= 0.8;
200 part->vel.y *= 0.8;
201 part->vel.z *= 0.8;
202 }
203 if (time >= 6 && time <= 19) {
204 if (part->type == FX_DAMAGE_STARS_0) {
205 part->rollAngleVel += 1.0f;
206 }
207 } else if (time < 5) {
208 part->rollAngleVel *= 0.8;
209 part->alpha *= 0.6;
210 part->vel.x *= 0.7;
211 part->vel.y *= 0.7;
212 part->vel.z *= 0.7;
213 }
214 }
215
216 part->pos.x += part->vel.x;
217 part->pos.y += part->vel.y;
218 part->pos.z += part->vel.z;
219 part->rollAngle += part->rollAngleVel;
220 }
221}
222
224 RenderTask renderTask;
225 RenderTask* retTask;
226
228 renderTask.appendGfxArg = effect;
229 renderTask.dist = 0;
231
232 retTask = queue_render_task(&renderTask);
234}
235
236void damage_stars_appendGfx(void* effect) {
237 DamageStarsFXData* part = ((EffectInstance*)effect)->data.damageStars;
238 Matrix4f mtxTransform;
239 Matrix4f mtxTemp;
240 s32 baseIdx;
241 s32 i;
242
243 gDPPipeSync(gMainGfxPos++);
244 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
245 gSPDisplayList(gMainGfxPos++, D_090004C0_343500);
246
247 baseIdx = (part->lifetime - 1) * 3;
248 baseIdx %= 36;
249
250 for (i = 0; i < ((EffectInstance*)effect)->numParts; i++, part++) {
251 s32 rIdx = baseIdx + i * 3;
252 s32 gIdx = baseIdx + 1 + i * 3;
253 s32 bIdx = baseIdx + 2 + i * 3;
254
255 gDPSetPrimColor(gMainGfxPos++, 0, 0, D_E0030E90[rIdx % 36], D_E0030E90[gIdx % 36], D_E0030E90[bIdx % 36], part->alpha);
256 guTranslateF(mtxTransform, part->pos.x, part->pos.y, part->pos.z);
257 guRotateF(mtxTemp, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
258 guMtxCatF(mtxTemp, mtxTransform, mtxTransform);
260
261 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
262
263 guRotateF(mtxTransform, part->rollAngle, 0.0f, 0.0f, 1.0f);
265
266 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
267 gSPDisplayList(gMainGfxPos++, D_090005E0_343620);
268 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
269 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
270 }
271}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
void damage_stars_init(EffectInstance *effect)
f32 D_E0030EB4
void damage_stars_appendGfx(void *effect)
Gfx D_090004C0_343500[]
void damage_stars_update(EffectInstance *effect)
Gfx D_090005E0_343620[]
void damage_stars_render(EffectInstance *effect)
void damage_stars_main(s32 type, f32 x, f32 y, f32 z, f32 rotAxisX, f32 rotAxisY, f32 rotAxisZ, s32 number)
u8 D_E0030E90[]
Definition damage_stars.c:7
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define sqrtf
#define guMtxF2L
#define sin_deg
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define cos_deg
#define create_effect_instance
@ FX_DAMAGE_STARS_3
Definition effects.h:359
@ FX_DAMAGE_STARS_2
Definition effects.h:358
@ FX_DAMAGE_STARS_4
Definition effects.h:360
@ FX_DAMAGE_STARS_0
Definition effects.h:356
@ FX_DAMAGE_STARS_1
Definition effects.h:357
EffectData data
Definition effects.h:2605
struct DamageStarsFXData * damageStars
Definition effects.h:2488
#define ASSERT(condition)
@ RENDER_TASK_FLAG_REFLECT_FLOOR
Definition enums.h:3318
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
#define SQ(x)
Definition macros.h:166
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
void(* renderUI)(EffectInstance *effectInst)
Definition effects.h:2655
void(* init)(EffectInstance *effectInst)
Definition effects.h:2652
void(* update)(EffectInstance *effectInst)
Definition effects.h:2653
void(* renderWorld)(EffectInstance *effectInst)
Definition effects.h:2654
void * appendGfxArg
void(* appendGfx)(void *)
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16