Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
part2.inc.c
Go to the documentation of this file.
1#include "ld_addrs.h"
2
4
5#define PIRANHA_DMA_ENTRY(name) \
6 (s32) world_model_anim_kzn_##name##_ROM_START,\
7 (s32) world_model_anim_kzn_##name##_ROM_END,\
8 (s32) world_model_anim_kzn_##name##_VRAM
9
48};
49
53 s32 args[4];
54 s32 count;
55
56 // setup dummy call to LoadPath
57 args[0] = 3 * vine->boneCount; // generate three output samples per input
58 args[1] = (s32) &vine->bonePos; // points
59 args[2] = vine->boneCount; // num vectors
60 args[3] = EASING_LINEAR;
61 dummyEvtPtr->ptrReadPos = args;
63
64 count = 0;
65 do {
67 vine->points[count].x = evt_get_float_variable(dummyEvtPtr, LVar1);
68 vine->points[count].y = evt_get_float_variable(dummyEvtPtr, LVar2);
69 vine->points[count].z = evt_get_float_variable(dummyEvtPtr, LVar3);
70 count++;
71 } while (dummyEvtPtr->varTable[0] != 0);
72 vine->numPoints = count;
73}
74
75API_CALLABLE(N(SetVineBonePos)) {
76 Bytecode* args = script->ptrReadPos;
79 s32 x = evt_get_variable(script, *args++);
80 s32 y = evt_get_variable(script, *args++);
81 s32 z = evt_get_variable(script, *args++);
84
85 vine->bonePos[jointIdx].x = x;
86 vine->bonePos[jointIdx].y = y;
87 vine->bonePos[jointIdx].z = z;
88 return ApiStatus_DONE2;
89}
90
91API_CALLABLE(N(SetVineBoneRot)) {
92 Bytecode* args = script->ptrReadPos;
95 s32 rx = evt_get_variable(script, *args++);
96 s32 ry = evt_get_variable(script, *args++);
97 s32 rz = evt_get_variable(script, *args++);
100
102 return ApiStatus_DONE2;
103}
104
105API_CALLABLE(N(SetVineBoneScale)) {
106 Bytecode* args = script->ptrReadPos;
109 s32 sx = evt_get_variable(script, *args++);
110 s32 sy = evt_get_variable(script, *args++);
111 s32 sz = evt_get_variable(script, *args++);
113
114 // do nothing
115 return ApiStatus_DONE2;
116}
117
118void N(appendGfx_piranha_vines)(void* data) {
120 Vtx_t* vtx;
121
122 f32 boneLength;
123 s32 boneCount;
124
125 f32 angle;
129
132 s32 nearest;
133
134 s32 numPoints;
135 s32 i, j;
136
138 f32 posX, posY, posZ;
139
140 if (N(VineRenderState) == -1) {
141 return;
142 }
143
144 if (N(VineRenderState) == 0) {
145 for (i = 0; i < NUM_VINES; i++) {
148
149 switch (i) {
150 default:
151 return;
152 case 0:
153 boneCount = 9;
154 boneLength = 10.0f;
155 break;
156 case 1:
157 boneCount = 7;
158 boneLength = 8.0f;
159 break;
160 case 2:
161 boneCount = 7;
162 boneLength = 8.0f;
163 break;
164 case 3:
165 boneCount = 5;
166 boneLength = 8.0f;
167 break;
168 }
169
170 vine->boneCount = boneCount;
171 vine->boneLength = boneLength;
172
173 for (j = 0; j < boneCount; j++) {
174 if (j == (boneCount - 1)) {
175 vine->boneRot[j] += 90.0f;
176 } else {
177 curAngle1 = vine->boneRot[j];
178 nextAngle = vine->boneRot[j + 1];
179 if (nextAngle - curAngle1 > 180.0f) {
180 curAngle1 += 360.0f;
181 } else if (nextAngle - curAngle1 < -180.0f) {
182 nextAngle += 360.0f;
183 }
184 // average cur and next angles
185 vine->boneRot[j] = ((curAngle1 + nextAngle) / 2.0) + 90.0;
186 }
187 }
188
190 }
191
192 N(VineRenderState) = 1;
193 }
194
197
198 for (i = 0; i < NUM_VINES; i++) {
201
202 boneLength = vine->boneLength;
203 boneCount = vine->boneCount;
204 numPoints = vine->numPoints;
205
206 // we'll build the vertex data and place it in the display list, so jump forward
207 // here and leave space behind for the gSPBranchList command followed by two vertices
208 // for each point in numPoints
209
210 vtxBuffer = (Vtx_t*)(gMainGfxPos + 1);
211 gSPBranchList(gMainGfxPos, &gMainGfxPos[1 + 2 * (2 * numPoints)]);
212 vtx = (Vtx_t*) (++gMainGfxPos);
213 gMainGfxPos = &gMainGfxPos[2 * (2 * numPoints)];
214
215 for (j = 0; j < numPoints; j++) {
216 posX = vine->points[j].x;
217 posY = vine->points[j].y;
218 posZ = vine->points[j].z;
219
220 alphaCoord = ((f32) j * boneCount) / numPoints;
223
224 if (nearest + 1 >= boneCount) {
225 angle = vine->boneRot[boneCount - 1];
226 } else {
227 curAngle2 = vine->boneRot[nearest];
228 nextAngle = vine->boneRot[nearest + 1];
229 if (nextAngle - curAngle2 > 180.0f) {
230 nextAngle -= 360.0f;
231 }
232 if (nextAngle - curAngle2 < -180.0f) {
233 nextAngle += 360.0f;
234 }
235 angle = ((nextAngle - curAngle2) * alphaFrac) + curAngle2;
236 }
237
238 deltaX = sin_deg(angle) * boneLength;
239 deltaY = -cos_deg(angle) * boneLength;
240
241 vtx->ob[0] = posX + deltaX;
242 vtx->ob[1] = posY + deltaY;
243 vtx->ob[2] = posZ;
244 vtx->tc[0] = j * 0x140;
245 vtx->tc[1] = 0;
246 vtx->cn[0] = j * 50;
247 vtx->cn[1] = j * 120;
248 vtx->cn[2] = j * 30;
249 vtx++;
250
251 vtx->ob[0] = posX - deltaX;
252 vtx->ob[1] = posY - deltaY;
253 vtx->ob[2] = posZ;
254 vtx->tc[0] = j * 0x140;
255 vtx->tc[1] = 0x400;
256 vtx->cn[0] = j * 50;
257 vtx->cn[1] = j * 120;
258 vtx->cn[2] = j * 30;
259 vtx++;
260 }
261
262 for (j = 0; j < numPoints - 1; j++) {
263 gSPVertex(gMainGfxPos++, &vtxBuffer[2*j], 4, 0);
264 gSP2Triangles(gMainGfxPos++, 1, 0, 2, 0, 1, 2, 3, 0);
265 }
266 }
267
269}
270
281
282API_CALLABLE(N(MarkVineInterpolationDirty)) {
283 N(VineRenderState) = 0;
284 return ApiStatus_DONE2;
285}
286
287API_CALLABLE(N(CreateVineRenderer)) {
288 LavaPiranhaVine* data = heap_malloc(NUM_VINES * sizeof(*data));
290 N(VineRenderState) = -1;
292 return ApiStatus_DONE2;
293}
BSS s32 PopupMenu_SelectedIndex
#define queue_render_task
#define sin_deg
#define cos_deg
@ EASING_LINEAR
Definition enums.h:510
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3298
#define ApiStatus_DONE2
Definition evt.h:119
s32 Bytecode
Definition evt.h:7
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1730
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1887
s32 create_worker_scene(void(*updateFunc)(void), void(*renderFunc)(void))
Definition worker.c:32
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1970
void * heap_malloc(s32 size)
Definition heap.c:34
@ NUM_VINES
Definition part1.inc.c:6
#define PIRANHA_DMA_ENTRY(name)
Definition part2.inc.c:5
void N appendGfx_piranha_vines(void *data)
Definition part2.inc.c:118
void N make_vine_interpolation(LavaPiranhaVine *vine)
Definition part2.inc.c:50
void N worker_render_piranha_vines(void)
Definition part2.inc.c:271
ApiStatus LoadPath(Evt *script, b32 isInitialCall)
ApiStatus GetNextPathPos(Evt *script, b32 isInitialCall)
#define BSS
Definition macros.h:6
#define LVar2
Definition macros.h:151
#define LVar1
Definition macros.h:150
#define A(sym)
Definition macros.h:35
#define LVar3
Definition macros.h:152
void(* appendGfx)(void *)
Gfx * gMainGfxPos
Definition cam_main.c:14