level_geo.c (3232B)
1 #include <ultra64.h> 2 3 #include "sm64.h" 4 #include "rendering_graph_node.h" 5 #include "mario_misc.h" 6 #include "skybox.h" 7 #include "engine/math_util.h" 8 #include "camera.h" 9 #include "envfx_snow.h" 10 #include "level_geo.h" 11 12 /** 13 * Geo function that generates a displaylist for environment effects such as 14 * snow or jet stream bubbles. 15 */ 16 Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf) { 17 Vec3s marioPos; 18 Vec3s camFrom; 19 Vec3s camTo; 20 void *particleList; 21 Gfx *gfx = NULL; 22 23 if (callContext == GEO_CONTEXT_RENDER && gCurGraphNodeCamera != NULL) { 24 struct GraphNodeGenerated *execNode = (struct GraphNodeGenerated *) node; 25 u32 *params = &execNode->parameter; // accessed a s32 as 2 u16s by pointing to the variable and 26 // casting to a local struct as necessary. 27 28 if (GET_HIGH_U16_OF_32(*params) != gAreaUpdateCounter) { 29 UNUSED struct Camera *sp2C = gCurGraphNodeCamera->config.camera; 30 s32 snowMode = GET_LOW_U16_OF_32(*params); 31 32 vec3f_to_vec3s(camTo, gCurGraphNodeCamera->focus); 33 vec3f_to_vec3s(camFrom, gCurGraphNodeCamera->pos); 34 vec3f_to_vec3s(marioPos, gPlayerCameraState->pos); 35 particleList = envfx_update_particles(snowMode, marioPos, camTo, camFrom); 36 if (particleList != NULL) { 37 Mtx *mtx = alloc_display_list(sizeof(*mtx)); 38 39 gfx = alloc_display_list(2 * sizeof(*gfx)); 40 mtxf_to_mtx(mtx, mtxf); 41 gSPMatrix(&gfx[0], VIRTUAL_TO_PHYSICAL(mtx), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); 42 gSPBranchList(&gfx[1], VIRTUAL_TO_PHYSICAL(particleList)); 43 execNode->fnNode.node.flags = (execNode->fnNode.node.flags & 0xFF) | 0x400; 44 } 45 SET_HIGH_U16_OF_32(*params, gAreaUpdateCounter); 46 } 47 } else if (callContext == GEO_CONTEXT_AREA_INIT) { 48 // Give these arguments some dummy values. Not used in ENVFX_MODE_NONE 49 vec3s_copy(camTo, gVec3sZero); 50 vec3s_copy(camFrom, gVec3sZero); 51 vec3s_copy(marioPos, gVec3sZero); 52 envfx_update_particles(ENVFX_MODE_NONE, marioPos, camTo, camFrom); 53 } 54 55 return gfx; 56 } 57 58 /** 59 * Geo function that generates a displaylist for the skybox. Can be assigned 60 * as the function of a GraphNodeBackground. 61 */ 62 Gfx *geo_skybox_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) { 63 Gfx *gfx = NULL; 64 struct GraphNodeBackground *backgroundNode = (struct GraphNodeBackground *) node; 65 66 if (callContext == GEO_CONTEXT_AREA_LOAD) { 67 backgroundNode->unused = 0; 68 } else if (callContext == GEO_CONTEXT_RENDER) { 69 struct GraphNodeCamera *camNode = (struct GraphNodeCamera *) gCurGraphNodeRoot->views[0]; 70 struct GraphNodePerspective *camFrustum = 71 (struct GraphNodePerspective *) camNode->fnNode.node.parent; 72 73 gfx = create_skybox_facing_camera(0, backgroundNode->background, camFrustum->fov, gLakituState.pos[0], 74 gLakituState.pos[1], gLakituState.pos[2], gLakituState.focus[0], 75 gLakituState.focus[1], gLakituState.focus[2]); 76 } 77 78 return gfx; 79 }