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

Go to the source code of this file.

Enumerations

enum  {
  LERP_VAR_0 = 0x0 , LERP_VAR_1 = 0x1 , LERP_VAR_B = 0xB , LERP_VAR_C = 0xC ,
  LERP_VAR_D = 0xD , LERP_VAR_E = 0xE , LERP_VAR_F = 0xF
}
 

Functions

void load_path_data (s32 num, f32 *normalizedLengths, Vec3f *pathPositions, Vec3f *outVectors)
 
void get_path_position (f32 alpha, Vec3f *outPos, s32 numVectors, f32 *normalizedLengths, Vec3f *pathPoints, Vec3f *vectors)
 

Enumeration Type Documentation

◆ anonymous enum

Enumerator
LERP_VAR_0 
LERP_VAR_1 
LERP_VAR_B 
LERP_VAR_C 
LERP_VAR_D 
LERP_VAR_E 
LERP_VAR_F 

Definition at line 5 of file f8f60_len_1560.c.

5 {
6 LERP_VAR_0 = 0x0, // (out float) cur
7 LERP_VAR_1 = 0x1, // (out bool) in-progress
8 LERP_VAR_B = 0xB, // mode
9 LERP_VAR_C = 0xC, // start
10 LERP_VAR_D = 0xD, // end
11 LERP_VAR_E = 0xE, // elapsed
12 LERP_VAR_F = 0xF, // duration
13};
@ LERP_VAR_0
@ LERP_VAR_C
@ LERP_VAR_B
@ LERP_VAR_D
@ LERP_VAR_F
@ LERP_VAR_E
@ LERP_VAR_1

Function Documentation

◆ load_path_data()

void load_path_data ( s32 num,
f32 * normalizedLengths,
Vec3f * pathPositions,
Vec3f * outVectors )

Definition at line 290 of file f8f60_len_1560.c.

290 {
291 f32* lenBuf = heap_malloc(num * sizeof(f32));
292 Vec3f* vecBuf = heap_malloc(num * sizeof(Vec3f));
293 s32 i;
294
295 // compute the distance of each vector along the path and map to the range [0,1]
296 normalizedLengths[0] = 0.0f;
297 for (i = 1; i < num; i++) {
298 f32 dx = pathPositions[i].x - pathPositions[i-1].x;
299 f32 dy = pathPositions[i].y - pathPositions[i-1].y;
300 f32 dz = pathPositions[i].z - pathPositions[i-1].z;
301 f32 length = sqrtf(SQ(dx) + SQ(dy) + SQ(dz));
302 normalizedLengths[i] = normalizedLengths[i-1] + length;
303 }
304 for (i = 1; i < num; i++) {
306 }
307
308 // end points
309 outVectors[0].x = 0.0f;
310 outVectors[0].y = 0.0f;
311 outVectors[0].z = 0.0f;
312 outVectors[num-1].x = 0.0f;
313 outVectors[num-1].y = 0.0f;
314 outVectors[num-1].z = 0.0f;
315
316 for (i = 0; i < num - 1; i++) {
318 vecBuf[i+1].x = (pathPositions[i+1].x - pathPositions[i].x) / lenBuf[i];
319 vecBuf[i+1].y = (pathPositions[i+1].y - pathPositions[i].y) / lenBuf[i];
320 vecBuf[i+1].z = (pathPositions[i+1].z - pathPositions[i].z) / lenBuf[i];
321 }
322
323 // n = 1
324 outVectors[1].x = vecBuf[2].x - vecBuf[1].x;
325 outVectors[1].y = vecBuf[2].y - vecBuf[1].y;
326 outVectors[1].z = vecBuf[2].z - vecBuf[1].z;
327 vecBuf[1].x = 2.0f * (normalizedLengths[2] - normalizedLengths[0]);
328 vecBuf[1].y = 2.0f * (normalizedLengths[2] - normalizedLengths[0]);
329 vecBuf[1].z = 2.0f * (normalizedLengths[2] - normalizedLengths[0]);
330
331 // 1 < n < N - 2
332 for (i = 1; i < num - 2; i++) {
333 f32 sx = lenBuf[i] / vecBuf[i].x;
334 f32 sy = lenBuf[i] / vecBuf[i].y;
335 f32 sz = lenBuf[i] / vecBuf[i].z;
336 outVectors[i+1].x = (vecBuf[i+2].x - vecBuf[i+1].x) - outVectors[i].x * sx;
337 outVectors[i+1].y = (vecBuf[i+2].y - vecBuf[i+1].y) - outVectors[i].y * sy;
338 outVectors[i+1].z = (vecBuf[i+2].z - vecBuf[i+1].z) - outVectors[i].z * sz;
339 vecBuf[i+1].x = 2.0f * (normalizedLengths[i+2] - normalizedLengths[i]) - lenBuf[i] * sx;
340 vecBuf[i+1].y = 2.0f * (normalizedLengths[i+2] - normalizedLengths[i]) - lenBuf[i] * sy;
341 vecBuf[i+1].z = 2.0f * (normalizedLengths[i+2] - normalizedLengths[i]) - lenBuf[i] * sz;
342 }
343
344 // n = N - 2
345 outVectors[num-2].x -= (lenBuf[num-2] * outVectors[num-1].x);
346 outVectors[num-2].y -= (lenBuf[num-2] * outVectors[num-1].y);
347 outVectors[num-2].z -= (lenBuf[num-2] * outVectors[num-1].z);
348
349 for (i = num - 2; i > 0; i--) {
350 outVectors[i].x = (outVectors[i].x - (lenBuf[i] * outVectors[i+1].x)) / vecBuf[i].x;
351 outVectors[i].y = (outVectors[i].y - (lenBuf[i] * outVectors[i+1].y)) / vecBuf[i].y;
352 outVectors[i].z = (outVectors[i].z - (lenBuf[i] * outVectors[i+1].z)) / vecBuf[i].z;
353 }
354
357}
BSS s32 PopupMenu_SelectedIndex
#define sqrtf
s32 heap_free(void *ptr)
Definition heap.c:42
void * heap_malloc(s32 size)
Definition heap.c:34
#define SQ(x)
Definition macros.h:177

◆ get_path_position()

void get_path_position ( f32 alpha,
Vec3f * outPos,
s32 numVectors,
f32 * normalizedLengths,
Vec3f * pathPoints,
Vec3f * vectors )

Definition at line 359 of file f8f60_len_1560.c.

359 {
360 s32 limit = numVectors - 1;
363 f32 ax, ay, az, bx, by, bz, dx, dy, dz;
364 s32 i;
365
366 for (i = 0; i < limit;) {
367 s32 temp_v1 = (i + limit) / 2;
368
369 if (normalizedLengths[temp_v1] < alpha) {
370 i = temp_v1 + 1;
371 } else {
372 limit = temp_v1;
373 }
374 }
375
376 if (i > 0) {
377 i--;
378 }
379
381 curProgress = alpha - normalizedLengths[i];
382
383 dx = (pathPoints[i+1].x - pathPoints[i].x) / curLength;
384 ax = (((vectors[i+1].x - vectors[i].x) * curProgress / curLength) + (3.0f * vectors[i].x)) * curProgress;
385 bx = dx - (((2.0f * vectors[i].x) + vectors[i+1].x) * curLength);
386 outPos->x = ((ax + bx) * curProgress) + pathPoints[i].x;
387
388 dy = (pathPoints[i+1].y - pathPoints[i].y) / curLength;
389 ay = (((vectors[i+1].y - vectors[i].y) * curProgress / curLength) + (3.0f * vectors[i].y)) * curProgress;
390 by = dy - (((2.0f * vectors[i].y) + vectors[i+1].y) * curLength);
391 outPos->y = ((ay + by) * curProgress) + pathPoints[i].y;
392
393 dz = (pathPoints[i+1].z - pathPoints[i].z) / curLength;
394 az = (((vectors[i+1].z - vectors[i].z) * curProgress / curLength) + (3.0f * vectors[i].z)) * curProgress;
395 bz = dz - (((2.0f * vectors[i].z) + vectors[i+1].z) * curLength);
396 outPos->z = ((az + bz) * curProgress) + pathPoints[i].z;
397}