Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
star.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects_internal.h"
3
4extern Vtx_t D_09001400_333AA0[];
5extern Gfx D_09001530_333BD0[];
6extern Gfx D_09001650_333CF0[];
7extern Gfx D_09001780_333E20[];
8extern Gfx D_090017D0_333E70[];
9
10void star_init(EffectInstance* effect);
11void star_update(EffectInstance* effect);
12void star_render(EffectInstance* effect);
13void star_appendGfx(void* effect);
14
15EffectInstance* star_main(s32 type, f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ, f32 speed) {
17 StarFXData* part;
18 EffectInstance* effect;
19 s32 numParts = 1;
20 s32 i;
21
22 f32 projVel;
23 f32 dz;
24 f32 currentYaw;
25 f32 sinYaw;
26 f32 cosYaw;
27 f32 dy;
28 f32 dx;
29 f32 norm;
30 f32 projVz;
31 f32 projVx;
32 s32 temp_s0;
33 f32 length;
34
35 bp.unk_00 = 0;
36 bp.init = star_init;
39 bp.renderUI = NULL;
40 bp.effectID = EFFECT_STAR;
41
42 effect = create_effect_instance(&bp);
43 effect->numParts = 1;
44 part = effect->data.star = general_heap_malloc(numParts * sizeof(*part));
45
46 ASSERT(effect->data.star != NULL);
47 part->canBounce = TRUE;
48 part->pos.x = startX;
49 part->pos.y = startY;
50 part->pos.z = startZ;
51 part->bounceTime = 0.0f;
52 part->starAngle = 0.0f;
53 part->unk_28 = 0.0f;
54 part->type = type;
55
56 if (type == FX_STAR_SMALL_BOUNCING) {
57 part->scale = 0.2f;
58 part->primR = rand_int(255);
59 part->primG = rand_int(255 - part->primR);
60 temp_s0 = 255 - part->primG;
61 part->primB = temp_s0 - part->primR;
62 } else {
63 part->primR = 210;
64 part->primG = 186;
65 part->primB = 90;
66 part->scale = 0.5f;
67 }
68
69 dx = endX - startX;
70 dy = endY - startY;
71 dz = endZ - startZ;
72
73 norm = SQ(dx) + SQ(dy) + SQ(dz);
74 length = norm;
75 if (norm != 0.0f) {
76 length = sqrtf(norm);
77 norm = speed / length;
78 }
79
80 part->vel.x = dx * norm;
81 part->vel.y = dy * norm;
82 part->vel.z = dz * norm;
83
84 currentYaw = gCameras[gCurrentCameraID].curYaw;
85 cosYaw = -cos_deg(currentYaw);
86 sinYaw = -sin_deg(currentYaw);
87
88 projVx = cosYaw * part->vel.x;
89 projVz = sinYaw * part->vel.z;
90 projVel = SQ(projVx) + SQ(projVz);
91
92 if (projVel != 0.0f) {
93 projVel = sqrtf(projVel);
94 }
95
96 if ((cosYaw * part->vel.x) + (sinYaw * part->vel.z) < 0.0f) {
97 projVel = -projVel;
98 part->starAngleVel = -20.0f;
99 } else {
100 part->starAngleVel = 20.0f;
101 }
102
103 part->trailAngle = part->starAngle = atan2(0.0f, 0.0f, -part->vel.y, -projVel);
104 part->timeLeft = length / speed;
105 part->projVel = -projVel;
106 guTranslate(&part->trailMatrices[0], part->pos.x, part->pos.y, part->pos.z);
107
108 for (i = 1; i < ARRAY_COUNT(part->trailMatrices); i++) {
109 part->trailMatrices[i] = part->trailMatrices[0];
110 }
111
112 part->trailMatrixPos = -1;
113 return effect;
114}
115
117}
118
120
122 PlayerStatus* playerStatus = &gPlayerStatus;
123 StarFXData* data = effect->data.star;
124 f32 traceStartX, traceStartY, traceStartZ, length;
125 f32 dx, dy, dz;
126
127 if (data->type >= FX_STAR_LARGE_BOUNCING) {
128 length = SQ(data->vel.x) + SQ(data->vel.y) + SQ(data->vel.z);
129 if (length > 0.01f) {
130 length = 1.0f / sqrtf(length);
131 }
132
133 dx = data->vel.x * length * 32.0f;
134 dy = data->vel.y * length * 32.0f;
135 dz = data->vel.z * length * 32.0f;
136 traceStartX = data->pos.x - dx;
137 traceStartY = data->pos.y - dy;
138 traceStartZ = data->pos.z - dz;
139 length = 64.0f;
140
141 if (data->canBounce
142 && data->vel.y < 0.0f
143 && npc_raycast_down_sides(0, &traceStartX, &traceStartY, &traceStartZ, &length) != 0
144 && length < 42.0f
145 ) {
146 data->bounceTime += 1.0f;
147 data->vel.y = -data->vel.y * 0.6;
148 data->vel.x = data->vel.x * 0.7;
149 data->projVel *= 0.7;
150 data->starAngleVel *= 0.7;
151 load_effect(EFFECT_LANDING_DUST);
152 landing_dust_main(0, data->pos.x, data->pos.y - 5.0f, data->pos.z, 0.0f);
153
156 }
157
158 data->canBounce = FALSE;
159 if (data->bounceTime >= 10.0f) {
160 data->timeLeft = -1;
161 }
162 }
163
164 if (data->bounceTime != 0.0f) {
165 data->vel.y += -0.5;
166 data->starAngle += data->starAngleVel;
167 data->trailAngle = atan2(0.0f, 0.0f, -data->vel.y, data->projVel);
168 }
169 }
170
171 if (playerStatus->pos.y - data->pos.y > 300.0f) {
172 data->timeLeft = -1;
173 }
174
175 data->pos.x += data->vel.x;
176 data->pos.y += data->vel.y;
177 data->pos.z += data->vel.z;
178
179 if (data->timeLeft < 0) {
180 remove_effect(effect);
181 }
182}
183
185 StarFXData* data = effect->data.star;
186 RenderTask renderTask;
187 RenderTask* renderTaskPtr = &renderTask;
188 RenderTask* retTask;
189 s32 renderModeTemp;
190
191 renderTask.appendGfxArg = effect;
192 renderTask.appendGfx = star_appendGfx;
193 renderTask.dist = 0;
194 if (data->type != FX_STAR_BACKGROUND) {
195 renderModeTemp = RENDER_MODE_CLOUD_NO_ZCMP;
196 } else {
198 }
199 renderTaskPtr->renderMode = renderModeTemp;
200
201 retTask = queue_render_task(&renderTask);
202}
203
204void star_appendGfx(void* effect) {
205 StarFXData* data = ((EffectInstance*)effect)->data.star;
206 f32 scale = data->scale;
207 s32 type = data->type;
208 s32 primR = data->primR;
209 s32 primG = data->primG;
210 s32 primB = data->primB;
211 s32 idx;
212 Matrix4f sp20;
213 Matrix4f sp60;
214 s32 i;
215
216 gDPPipeSync(gMainGfxPos++);
217 gSPSegment(gMainGfxPos++, 0x09, VIRTUAL_TO_PHYSICAL(((EffectInstance*)effect)->graphics->data));
218
219 guPositionF(sp20, 0.0f, -gCameras[gCurrentCameraID].curYaw, 0.0f, scale, data->pos.x, data->pos.y, data->pos.z);
220 guRotateF(sp60, data->starAngle, 0.0f, 0.0f, 1.0f);
221 guMtxCatF(sp60, sp20, sp20);
223
224 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
225 gDPSetPrimColor(gMainGfxPos++, 0, 80, primR, primG, primB, 255);
226 gDPSetEnvColor(gMainGfxPos++, 127, 127, 127, 127);
227
229 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
230 gDPPipeSync(gMainGfxPos++);
231
232 if (type == FX_STAR_SMALL_BOUNCING) {
233 gSPDisplayList(gMainGfxPos++, D_090017D0_333E70);
234 } else {
235 gSPDisplayList(gMainGfxPos++, D_09001780_333E20);
236 }
237
238 data->trailMatrixPos++;
239 if (data->trailMatrixPos >= ARRAY_COUNT(data->trailMatrices)) {
240 data->trailMatrixPos = 0;
241 }
242
243 // draw trail
244 if (data->bounceTime <= 1.0f) {
245 s32 baseIdx = (data->trailMatrixPos + 5) % ARRAY_COUNT(data->trailMatrices);
246 guPositionF(sp20, 0.0f, -gCameras[gCurrentCameraID].curYaw, 0.0f, scale, data->pos.x, data->pos.y, data->pos.z);
247 guRotateF(sp60, data->trailAngle, 0.0f, 0.0f, 1.0f);
248 guMtxCatF(sp60, sp20, sp20);
249 guMtxF2L(sp20, &data->trailMatrices[data->trailMatrixPos]);
250
251 for (i = 0; i < 5; i++) {
252 idx = (baseIdx - i + ARRAY_COUNT(data->trailMatrices)) % ARRAY_COUNT(data->trailMatrices);
254
255 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
256 gSPVertex(gMainGfxPos++, &D_09001400_333AA0[i * 2], 2, i * 2);
257 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
258 }
259
260 for (i = 0; i < 4; i++) {
261 s32 i2 = i * 2;
262 gSP2Triangles(gMainGfxPos++,
263 i2 , i2 + 1, i2 + 2, i2,
264 i2 + 1, i2 + 3, i2 + 2, i2 + 1);
265 }
266
267 gDPPipeSync(gMainGfxPos++);
268 }
269}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define general_heap_malloc
#define guRotateF
#define sfx_play_sound_at_position
#define queue_render_task
#define sqrtf
#define npc_raycast_down_sides
#define guMtxF2L
#define sin_deg
#define guMtxCatF
#define remove_effect
#define rand_int
#define guPositionF
#define load_effect
#define cos_deg
#define atan2
#define create_effect_instance
#define guTranslate
f32 starAngle
Definition effects.h:185
Vec3f pos
Definition effects.h:181
f32 starAngleVel
Definition effects.h:187
@ FX_STAR_BACKGROUND
Definition effects.h:173
@ FX_STAR_LARGE_BOUNCING
Definition effects.h:175
@ FX_STAR_SMALL_BOUNCING
Definition effects.h:176
f32 bounceTime
Definition effects.h:183
f32 trailAngle
Definition effects.h:184
s32 primG
Definition effects.h:195
Mtx trailMatrices[8]
Definition effects.h:192
s32 primB
Definition effects.h:196
f32 scale
Definition effects.h:193
s32 primR
Definition effects.h:194
f32 unk_28
Definition effects.h:186
s32 trailMatrixPos
Definition effects.h:191
f32 projVel
Definition effects.h:189
struct StarFXData * star
Definition effects.h:2479
EffectData data
Definition effects.h:2605
Vec3f vel
Definition effects.h:182
s32 timeLeft
Definition effects.h:188
b32 canBounce
Definition effects.h:180
#define ASSERT(condition)
@ CONTEXT_WORLD
Definition enums.h:3529
@ SOUND_SEQ_SHOOTING_STAR_BOUNCE
Definition enums.h:1721
@ RENDER_MODE_SURF_SOLID_AA_ZB_LAYER0
Definition enums.h:3263
@ RENDER_MODE_CLOUD_NO_ZCMP
Definition enums.h:3311
@ SOUND_SPACE_DEFAULT
Definition enums.h:1737
void landing_dust_main(s32 type, f32 x, f32 y, f32 z, f32 angle)
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define SQ(x)
Definition macros.h:166
#define VIRTUAL_TO_PHYSICAL(addr)
Definition macros.h:47
EFFECT_DEF_LANDING_DUST(landing_dust_main)
void star_init(EffectInstance *effect)
Definition star.c:116
Gfx D_09001530_333BD0[]
void star_update(EffectInstance *effect)
Definition star.c:121
Gfx D_09001780_333E20[]
Vtx_t D_09001400_333AA0[]
Gfx D_090017D0_333E70[]
void star_appendGfx(void *effect)
Definition star.c:204
EffectInstance * star_main(s32 type, f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ, f32 speed)
Definition star.c:15
Gfx D_09001650_333CF0[]
void star_render(EffectInstance *effect)
Definition star.c:184
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 *)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 gCurrentCameraID
Definition cam_math.c:4
DisplayContext * gDisplayContext
Definition cam_main.c:16