Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ShatteringBlock_common.c File Reference

Go to the source code of this file.

Functions

void entity_shattering_setupGfx (s32 entityIndex)
 
void entity_BrickBlock_idle (Entity *entity)
 
void entity_shattering_init_pieces (Entity *entity, Gfx **dlists, Mtx *matrices)
 
void entity_shattering_idle (Entity *entity)
 

Variables

EntityScript Entity_ShatteringBlock_Script
 

Function Documentation

◆ entity_shattering_setupGfx()

void entity_shattering_setupGfx ( s32 entityIndex)

Definition at line 154 of file ShatteringBlock_common.c.

154 {
155 s32 i;
156 Matrix4f mtxTransInv;
157 Matrix4f mtx;
158 Matrix4f mtxRotX;
159 Matrix4f mtxRotY;
160 f32 x_inv;
161 f32 y_inv;
162 f32 z_inv;
163 Gfx* gfxPos = gMainGfxPos;
164 Entity* entity = get_entity_by_index(entityIndex);
166 Gfx* fragmentDlist;
167 Gfx** gfx = data->fragmentDisplayLists;
168
169 x_inv = -entity->pos.x;
170 y_inv = -entity->pos.y;
171 z_inv = -entity->pos.z;
172
173 for (i = 0; i < 24; i++) {
174 if (data->alpha == 255) {
175 gDPSetRenderMode(gfxPos++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
176 gDPSetCombineMode(gfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
177 } else {
178 gDPSetCombineMode(gfxPos++, PM_CC_11, PM_CC_12);
179 gDPSetPrimColor(gfxPos++, 0, 0, 0, 0, 0, data->alpha);
180 }
181
182 guTranslateF(mtxTransInv, x_inv, y_inv, z_inv);
183 guRotateF(mtxRotX, data->fragmentRotX[i] * 360.0f / 256, 1.0f, 0.0f, 0.0f);
184 guRotateF(mtxRotY, data->fragmentRotY[i] * 360.0f / 256, 0.0f, 1.0f, 0.0f);
185 guMtxCatF(mtxRotX, mtxRotY, mtxRotY);
186 guMtxCatF(mtxRotY, mtxTransInv, mtxTransInv);
187 guTranslateF(mtx, data->fragmentPosX[i], data->fragmentPosY[i], data->fragmentPosZ[i]);
188 guMtxCatF(mtxTransInv, mtx, mtx);
190
191 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
192 fragmentDlist = ENTITY_ADDR(entity, Gfx*, *gfx++);
193 gSPDisplayList(gfxPos++, fragmentDlist);
194 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
195 }
196
197 gMainGfxPos = gfxPos;
198}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
struct ShatteringBlockData * shatteringBlock
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
f32 fragmentPosY[25]
Definition entity.h:104
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
Gfx ** fragmentDisplayLists
Definition entity.h:94
u8 fragmentRotY[25]
Definition entity.h:102
f32 fragmentPosX[25]
Definition entity.h:103
f32 fragmentPosZ[25]
Definition entity.h:105
u8 fragmentRotX[25]
Definition entity.h:101
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
#define PM_CC_11
Definition macros.h:294
#define PM_CC_12
Definition macros.h:295
EntityData dataBuf
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16

Referenced by entity_shattering_init_pieces().

◆ entity_BrickBlock_idle()

void entity_BrickBlock_idle ( Entity * entity)

Definition at line 6 of file ShatteringBlock_common.c.

6 {
8}
s32 entity_base_block_idle(Entity *entity)
Definition Block.c:195

◆ entity_shattering_init_pieces()

void entity_shattering_init_pieces ( Entity * entity,
Gfx ** dlists,
Mtx * matrices )

Definition at line 10 of file ShatteringBlock_common.c.

10 {
12 s32 s7;
13 s32 i;
14 Matrix4f mtxFragment;
15 Matrix4f mtxTrans;
16 s32 rotSpeed;
17 f32 fallSpeed;
18
19 data->fragmentDisplayLists = ENTITY_ADDR(entity, Gfx**, dlists);
21 entity->alpha = 255;
22 entity->pos.y = data->originalPosY;
23 guTranslateF(mtxTrans, entity->pos.x, entity->pos.y, entity->pos.z);
24
25 s7 = 2;
26 if (!is_block_on_ground(entity)) {
27 s7 = 1;
28 }
29
30 data->fadeOutCounter = 0;
31 data->alpha = 255;
32
33 for (i = 0; i < 24; i++) {
34 guMtxL2F(mtxFragment, ENTITY_ADDR(entity, Mtx*, matrices++));
35 guMtxCatF(mtxTrans, mtxFragment, mtxFragment);
36 data->fragmentPosX[i] = mtxFragment[3][0];
37 data->fragmentPosY[i] = mtxFragment[3][1];
38 data->fragmentPosZ[i] = mtxFragment[3][2];
39 data->fragmentMoveAngle[i] = -rand_int(255);
40
41 if (s7 == 1) {
42 rotSpeed = 20;
43 fallSpeed = 6.4f;
44 data->fragmentFlags[i] |= 1;
45 } else {
46 rotSpeed = 40;
47 fallSpeed = 8.6f;
48 data->fragmentFlags[i] |= 2;
49 }
50 rotSpeed += rand_int(10);
51 data->fragmentRotSpeed[i] = rotSpeed;
52 if ((i % 2) == 0) {
53 data->fragmentRotSpeed[i] = -rotSpeed;
54 }
55
56 data->fragmentFallSpeed[i] = fallSpeed + (f32)(rand_float() * 2.7);
57 data->fragmentRebounds[i] = 0;
58 data->fragmentRotX[i] = 0;
59 data->fragmentRotY[i] = 0;
60 }
61}
void entity_shattering_setupGfx(s32 entityIndex)
#define rand_int
u16 fragmentFlags[25]
Definition entity.h:93
s8 fragmentRebounds[25]
Definition entity.h:98
u8 fragmentMoveAngle[25]
Definition entity.h:100
f32 fragmentFallSpeed[25]
Definition entity.h:106
s8 fragmentRotSpeed[25]
Definition entity.h:99
f32 rand_float(void)
Definition 43F0.c:504
s32 is_block_on_ground(Entity *block)
Definition entity.c:1736
void(* renderSetupFunc)(s32)

Referenced by entity_shattering_block_init().

◆ entity_shattering_idle()

void entity_shattering_idle ( Entity * entity)

Definition at line 63 of file ShatteringBlock_common.c.

63 {
65 f32 rotSpeed = 0.0f;
66 f32 reboundSpeed = 0.0f;
67 f32 lateralSpeed = 0.0f;
68 f32 angle;
69 s32 i;
70 f32 sinTheta;
71 f32 cosTheta;
72 f32 hitX, hitY, hitZ, hitDepth;
73
74 for (i = 0; i < 24; i++) {
75 switch (data->fragmentRebounds[i]) {
76 case 0:
77 if (data->fragmentFlags[i] & 1) {
78 lateralSpeed = 1.5f;
79 } else {
80 lateralSpeed = 2.4f;
81 }
82 reboundSpeed = 6.0f;
83 rotSpeed = data->fragmentRotSpeed[i];
84 break;
85 case 1:
86 lateralSpeed = 1.2f;
87 reboundSpeed = 3.0f;
88 rotSpeed = data->fragmentRotSpeed[i] >> 2;
89 break;
90 case 2:
91 lateralSpeed = 1.0f;
92 reboundSpeed = 2.0f;
93 rotSpeed = data->fragmentRotSpeed[i] >> 2;
94 if (data->alpha == 0) {
95 data->fragmentRebounds[i]++;
96 }
97 break;
98 case 3:
99 data->fragmentPosY[i] -= 0.3;
100 continue;
101 }
102
103 data->fragmentFallSpeed[i] -= 1.2;
104 if (data->fragmentFallSpeed[i] < -12.2) {
105 data->fragmentFallSpeed[i] = -12.2f;
106 }
107 data->fragmentPosY[i] += data->fragmentFallSpeed[i];
108
109 angle = data->fragmentMoveAngle[i] * 360.0 / 256;
110 sin_cos_rad(DEG_TO_RAD(angle), &sinTheta, &cosTheta);
111 data->fragmentPosX[i] += lateralSpeed * sinTheta;
112 data->fragmentPosZ[i] += lateralSpeed * cosTheta;
113
114 hitX = data->fragmentPosX[i];
115 hitY = data->fragmentPosY[i];
116 hitZ = data->fragmentPosZ[i];
117 if (npc_test_move_taller_with_slipping(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, lateralSpeed, angle, 8.0f, 8.0f)) {
118 data->fragmentPosX[i] = hitX;
119 data->fragmentPosY[i] = hitY;
120 data->fragmentPosZ[i] = hitZ;
121 data->fragmentMoveAngle[i] += 0x80; // inverse yaw
122
123 sin_cos_rad(DEG_TO_RAD(data->fragmentMoveAngle[i] * 360.0 / 256), &sinTheta, &cosTheta);
124 lateralSpeed = 8.0f;
125 data->fragmentPosX[i] += lateralSpeed * sinTheta;
126 data->fragmentPosZ[i] += lateralSpeed * cosTheta;
127 }
128
129 hitX = data->fragmentPosX[i];
130 hitY = data->fragmentPosY[i];
131 hitZ = data->fragmentPosZ[i];
132 hitDepth = fabsf(data->fragmentFallSpeed[i]);
133 if (npc_raycast_down_sides(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, &hitDepth) || hitY < data->originalPosY - 200.0f) {
134 data->fragmentRebounds[i]++;
135 data->fragmentPosY[i] = hitY + fabsf(data->fragmentFallSpeed[i]) * 1.2f;
136 data->fragmentFallSpeed[i] = reboundSpeed;
137 }
138
139 data->fragmentRotX[i] += rotSpeed;
140 data->fragmentRotY[i] -= rotSpeed;
141 }
142
143 data->fadeOutCounter++;
144 if (data->fadeOutCounter >= 10) {
145 data->fadeOutCounter = 10;
146 data->alpha -= 8;
147 if (data->alpha <= 0) {
148 data->alpha = 0;
150 }
151 }
152}
#define npc_raycast_down_sides
@ COLLISION_IGNORE_ENTITIES
Definition enums.h:4698
f32 fabsf(f32 f)
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
#define DEG_TO_RAD(deg)
Definition macros.h:134

Variable Documentation

◆ Entity_ShatteringBlock_Script

EntityScript Entity_ShatteringBlock_Script
Initial value:
= {
}
void entity_shattering_idle(Entity *entity)
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
#define es_End
Definition entity.h:35
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618

Definition at line 200 of file ShatteringBlock_common.c.