Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
effect_3D.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Gfx D_09000240_37D3C0[];
5extern Gfx D_090002E8_37D468[];
6
10void effect_3D_appendGfx(void* effect);
11
12void effect_3D_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, s32 arg7, EffectInstance** outEffect) {
14 EffectBlueprint* bpPtr = &bp;
15 EffectInstance* effect;
16 Effect3DFXData* part;
17 f32 temp_f12;
18 f32 temp_f28;
19 f32 temp_f30;
20 f32 sp70;
21 Matrix4f sp30;
22 s32 i;
23
24 if (arg7 != 0) {
25 arg7++;
26
27 temp_f12 = SQ(arg4) + SQ(arg5) + SQ(arg6);
28 if (temp_f12 != 0.0f) {
29 temp_f12 = -1.0f / sqrtf(temp_f12);
30
31 arg4 *= temp_f12;
32 arg5 *= temp_f12;
33 arg6 *= temp_f12;
34
35 if (arg4 != 0.0f) {
36 sp70 = 1.0f;
37 temp_f30 = -arg5 / arg4;
38 temp_f28 = 0.0f;
39 } else if (arg5 != 0.0f) {
40 sp70 = -arg4 / arg5;
41 temp_f30 = 1.0f;
42 temp_f28 = 0.0f;
43 } else {
44 sp70 = 0.0f;
45 temp_f30 = 1.0f;
46 temp_f28 = -arg4 / arg6;
47 }
48
49 temp_f12 = SQ(temp_f30) + SQ(sp70) + SQ(temp_f28);
50 if (temp_f12 != 0.0f) {
51 temp_f12 = 1.0f / sqrtf(temp_f12);
52
53 temp_f30 *= temp_f12;
54 sp70 *= temp_f12;
55 temp_f28 *= temp_f12;
56
57 temp_f30 *= 8.0f;
58 sp70 *= 8.0f;
59 temp_f28 *= 8.0f;
60 arg4 *= 8.0f;
61 arg5 *= 8.0f;
62 arg6 *= 8.0f;
63
64 bpPtr->unk_00 = 0;
65 bpPtr->init = effect_3D_init;
66 bpPtr->update = effect_3D_update;
68 bpPtr->renderUI = NULL;
69 bpPtr->effectID = EFFECT_3D;
70
71 effect = create_effect_instance(bpPtr);
72 effect->numParts = arg7;
73 part = effect->data.unk_3D = general_heap_malloc(arg7 * sizeof(*part));
74 ASSERT(effect->data.unk_3D != NULL);
75
76 part->unk_04 = 0;
77 part->unk_00 = arg0;
78 part->pos.x = arg1;
79 part->pos.y = arg2;
80 part->pos.z = arg3;
81 part->unk_5C = 10;
82 part->unk_60 = 0;
83
84 part++;
85 for (i = 1; i < arg7; i++, part++) {
86 part->pos.x = 0;
87 part->pos.y = 0;
88 part->pos.z = 0;
89 guRotateF(sp30, i * 72, arg4, arg5, arg6);
90 part->unk_14 = part->unk_20 = 2.0f * arg4;
91 part->unk_18 = part->unk_24 = 2.0f * arg5;
92 part->unk_1C = part->unk_28 = 2.0f * arg6;
93 part->unk_38 = -arg4 * 0.05 * 4.0;
94 part->unk_3C = -arg5 * 0.05 * 4.0;
95 part->unk_40 = -arg6 * 0.05 * 4.0;
96 part->unk_2C = (sp30[0][0] * temp_f30 + sp30[1][0] * sp70 + sp30[2][0] * temp_f28) * 0.1 * 4.0;
97 part->unk_30 = (sp30[0][1] * temp_f30 + sp30[1][1] * sp70 + sp30[2][1] * temp_f28) * 0.1 * 4.0;
98 part->unk_34 = (sp30[0][2] * temp_f30 + sp30[1][2] * sp70 + sp30[2][2] * temp_f28) * 0.1 * 4.0;
99 part->unk_44 = 0.5f;
100 part->unk_48 = 4.0f;
101 part->unk_50 = 20.0f;
102 part->unk_4C = part->unk_54 = effect_rand_int(360);
103 part->unk_58 = 255;
104 part->unk_64 = ((i - 1) / 5) * 2;
105 part->unk_5C = 10;
106 }
107
108 *outEffect = effect;
109 }
110 }
111 }
112}
113
115}
116
118 Effect3DFXData* part = effect->data.unk_3D;
119 s32 unk_04 = part->unk_04;
120 s32 unk_5C;
121 s32 saved_5C;
122 s32 i;
123
124 part->unk_5C--;
125 part->unk_60++;
126 if (part->unk_5C < 0 && unk_04 == 2) {
127 remove_effect(effect);
128 return;
129 }
130
131 saved_5C = part->unk_5C;
132
133 part++;
134 for (i = 1; i < effect->numParts; i++, part++) {
135 if (part->unk_64 <= 0 || --part->unk_64 <= 0) {
136 unk_5C = --part->unk_5C;
137 if (unk_5C < 0) {
138 if (unk_04 == 0) {
139 part->unk_58 = 255;
140 part->pos.x = 0.0f;
141 part->pos.y = 0.0f;
142 part->pos.z = 0.0f;
143 part->unk_14 = part->unk_20;
144 part->unk_18 = part->unk_24;
145 part->unk_1C = part->unk_28;
146 part->unk_44 = 0.5f;
147 part->unk_48 = 4.0f;
148 part->unk_50 = 20.0f;
149 part->unk_4C = part->unk_54;
150 part->unk_5C = 9;
151 unk_5C = 9;
152 } else {
153 part->pos.x = 0.0f;
154 part->pos.y = 0.0f;
155 part->pos.z = 0.0f;
156 part->unk_14 = 0.0f;
157 part->unk_18 = 0.0f;
158 part->unk_1C = 0.0f;
159 part->unk_58 = 0;
160 part->unk_5C = 0;
161 }
162 }
163
164 if (unk_5C >= 4 && unk_5C <= 6) {
165 part->unk_14 += part->unk_2C;
166 part->unk_18 += part->unk_30;
167 part->unk_1C += part->unk_34;
168 }
169
170 if (unk_5C < 8) {
171 part->unk_44 += (3.0 - part->unk_44) * 0.03 * 8.0;
172 part->unk_48 += (0.5 - part->unk_48) * 0.03 * 6.0;
173 }
174
175 part->unk_14 += part->unk_38;
176 part->unk_18 += part->unk_3C;
177 part->unk_1C += part->unk_40;
178
179 if (part->unk_18 < 0.0f) {
180 part->unk_50 *= 0.2;
181 part->unk_14 *= 0.225;
182 part->unk_18 *= 0.45;
183 part->unk_1C *= 0.225;
184 part->unk_58 *= 0.8;
185 }
186
187 part->pos.x += part->unk_14;
188 part->pos.y += part->unk_18;
189 part->pos.z += part->unk_1C;
190 part->unk_4C += part->unk_50;
191 }
192 }
193
194 if (saved_5C < 0) {
195 part = effect->data.unk_3D;
196 part->unk_5C = 10;
197 part->unk_60 = 0;
198 }
199}
200
202 RenderTask renderTask;
203 RenderTask* retTask;
204
205 renderTask.appendGfx = effect_3D_appendGfx;
206 renderTask.appendGfxArg = effect;
207 renderTask.dist = 0;
209
210 retTask = queue_render_task(&renderTask);
212}
213
214void func_E007A884(void) {
215}
216
217void effect_3D_appendGfx(void* effect) {
218 Effect3DFXData* part = ((EffectInstance*)effect)->data.unk_3D;
219 Matrix4f sp18;
220 Matrix4f sp58;
221 s32 i;
222
223 gDPPipeSync(gMainGfxPos++);
224 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
225 gSPDisplayList(gMainGfxPos++, D_09000240_37D3C0);
226
227 guTranslateF(sp18, part->pos.x, part->pos.y, part->pos.z);
229
230 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
231
232 part++;
233 for (i = 1; i < ((EffectInstance*)effect)->numParts; i++, part++) {
234 gDPSetPrimColor(gMainGfxPos++, 0, 0, 200, 255, 255, part->unk_58);
235
236 guTranslateF(sp18, part->pos.x, part->pos.y, part->pos.z);
237 guRotateF(sp58, -gCameras[gCurrentCameraID].curYaw, 0.0f, 1.0f, 0.0f);
238 guMtxCatF(sp58, sp18, sp18);
239 guScaleF(sp58, part->unk_44, part->unk_48, part->unk_44);
240 guMtxCatF(sp58, sp18, sp18);
241 guRotateF(sp58, part->unk_4C, 0.0f, 0.0f, 1.0f);
242 guMtxCatF(sp58, sp18, sp18);
244
245 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
246 gSPDisplayList(gMainGfxPos++, D_090002E8_37D468);
247 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
248 }
249
250 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
251 gDPPipeSync(gMainGfxPos++);
252}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
Gfx D_090002E8_37D468[]
Gfx D_09000240_37D3C0[]
void effect_3D_update(EffectInstance *effect)
Definition effect_3D.c:117
void effect_3D_main(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, s32 arg7, EffectInstance **outEffect)
Definition effect_3D.c:12
void func_E007A884(void)
Definition effect_3D.c:214
void effect_3D_init(EffectInstance *effect)
Definition effect_3D.c:114
void effect_3D_appendGfx(void *effect)
Definition effect_3D.c:217
void effect_3D_render(EffectInstance *effect)
Definition effect_3D.c:201
#define general_heap_malloc
#define guRotateF
#define queue_render_task
#define sqrtf
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define remove_effect
#define create_effect_instance
#define guScaleF
struct Effect3DFXData * unk_3D
Definition effects.h:2525
EffectData data
Definition effects.h:2605
#define ASSERT(condition)
s32 effect_rand_int(s32)
@ 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