Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/game/level_geo.c
7858 views
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
#if 0
38
Mtx *mtx = alloc_display_list(sizeof(*mtx));
39
40
gfx = alloc_display_list(2 * sizeof(*gfx));
41
mtxf_to_mtx(mtx, mtxf);
42
gSPMatrix(&gfx[0], VIRTUAL_TO_PHYSICAL(mtx), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
43
gSPBranchList(&gfx[1], VIRTUAL_TO_PHYSICAL(particleList));
44
#else
45
gfx = particleList;
46
#endif
47
execNode->fnNode.node.flags = (execNode->fnNode.node.flags & 0xFF) | 0x400;
48
}
49
SET_HIGH_U16_OF_32(*params, gAreaUpdateCounter);
50
}
51
} else if (callContext == GEO_CONTEXT_AREA_INIT) {
52
// Give these arguments some dummy values. Not used in ENVFX_MODE_NONE
53
vec3s_copy(camTo, gVec3sZero);
54
vec3s_copy(camFrom, gVec3sZero);
55
vec3s_copy(marioPos, gVec3sZero);
56
envfx_update_particles(ENVFX_MODE_NONE, marioPos, camTo, camFrom);
57
}
58
59
return gfx;
60
}
61
62
/**
63
* Geo function that generates a displaylist for the skybox. Can be assigned
64
* as the function of a GraphNodeBackground.
65
*/
66
Gfx *geo_skybox_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) {
67
Gfx *gfx = NULL;
68
struct GraphNodeBackground *backgroundNode = (struct GraphNodeBackground *) node;
69
70
if (callContext == GEO_CONTEXT_AREA_LOAD) {
71
backgroundNode->unused = 0;
72
} else if (callContext == GEO_CONTEXT_RENDER) {
73
struct GraphNodeCamera *camNode = (struct GraphNodeCamera *) gCurGraphNodeRoot->views[0];
74
struct GraphNodePerspective *camFrustum =
75
(struct GraphNodePerspective *) camNode->fnNode.node.parent;
76
77
gfx = create_skybox_facing_camera(0, backgroundNode->background, camFrustum->fov, gLakituState.pos[0],
78
gLakituState.pos[1], gLakituState.pos[2], gLakituState.focus[0],
79
gLakituState.focus[1], gLakituState.focus[2]);
80
}
81
82
return gfx;
83
}
84
85