![]() |
Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
|
#include <ultra64.h>
#include "sm64.h"
#include "main.h"
#include "display.h"
#include "print.h"
#include "engine/math_util.h"
#include "area.h"
#include "shadow.h"
#include "memory.h"
#include "game.h"
#include "rendering_graph_node.h"
Data Structures | |
struct | GeoAnimState |
Animation nodes have state in global variables, so this struct captures the animation state so a 'context switch' can be made when rendering the held object. More... | |
struct | RenderModeContainer |
Variables | |
s16 | gMatStackIndex |
This file contains the code that processes the scene graph for rendering. More... | |
Mat4 | gMatStack [32] |
Mtx * | gMatStackFixed [32] |
struct GeoAnimState | gGeoTempState |
u8 | gCurAnimType |
u8 | gCurAnimEnabled |
s16 | gCurrAnimFrame |
f32 | gCurAnimTranslationMultiplier |
u16 * | gCurrAnimAttribute |
s16 * | gCurAnimData |
struct AllocOnlyPool * | gDisplayListHeap |
struct RenderModeContainer | renderModeTable_1Cycle [2] |
struct RenderModeContainer | renderModeTable_2Cycle [2] |
struct GraphNodeRoot * | gCurGraphNodeRoot = NULL |
struct GraphNodeMasterList * | gCurGraphNodeMasterList = NULL |
struct GraphNodePerspective * | gCurGraphNodeCamFrustum = NULL |
struct GraphNodeCamera * | gCurGraphNodeCamera = NULL |
struct GraphNodeObject * | gCurGraphNodeObject = NULL |
struct GraphNodeHeldObject * | gCurGraphNodeHeldObject = NULL |
u16 | gAreaUpdateCounter = 0 |
Appends the display list to one of the master lists based on the layer parameter.
Look at the RenderModeContainer struct to see the corresponding render modes of layers.
|
static |
Render an animated part.
The current animation state is not part of the node but set in global variables. If an animated part is skipped, everything afterwards desyncs.
|
static |
Process a background node.
Tries to retrieve a background display list from the function of the node. If that function is null or returns null, a black rectangle is drawn instead.
|
static |
Process a billboard node.
A transformation matrix is created that makes its children face the camera, and it is pushed on the floating point and fixed point matrix stacks. For the rest it acts as a normal display list node.
|
static |
Process a camera node.
|
static |
Process a display list node.
It draws a display list without first pushing a transformation on the stack, so all transformations are inherited from the parent node. It processes its children if it has them.
|
static |
Process a generated list.
Instead of storing a pointer to a display list, the list is generated on the fly by a function.
void geo_process_held_object | ( | struct GraphNodeHeldObject * | node | ) |
Process a held object node.
|
static |
Process a level of detail node.
From the current transformation matrix, the perpendicular distance to the camera is extracted and the children of this node are only processed if that distance is within the render range of this node.
|
static |
Process the master list node.
|
static |
Process a generic geo node and its siblings.
The first argument is the start node, and all its siblings will be iterated over.
|
static |
Process an object parent node.
Temporarily assigns itself as the parent of the subtree rooted at 'sharedChild' and processes the subtree, after which the actual children are be processed. (in practice they are null though)
|
static |
Process an orthographic projection node.
|
static |
Process a perspective projection node.
Process a root node.
This is the entry point for processing the scene graph. The root node itself sets up the viewport, then all its children are processed to set up the projection and draw display lists.
|
static |
Process a rotation node.
A transformation matrix based on the node's rotation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.
|
static |
Process a scaling node.
A transformation matrix based on the node's scale is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.
|
static |
Process a shadow node.
Renders a shadow under an object offset by the translation of the first animated component and rotated according to the floor below it.
|
static |
Process a switch case node.
The node's selection function is called if it is 0, and among the node's children, only the selected child is processed next.
|
static |
Process a translation node.
A transformation matrix based on the node's translation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.
|
static |
Process a translation / rotation node.
A transformation matrix based on the node's translation and rotation is created and pushed on both the float and fixed point matrix stacks. For the rest it acts as a normal display list node.
void geo_set_animation_globals | ( | struct GraphNodeObject_sub * | node, |
s32 | hasAnimation | ||
) |
Initialize the animation-related global variables for the currently drawn object's animation.
Processes the children of the given GraphNode if it has any.
|
static |
Check whether an object is in view to determine whether it should be drawn.
This is known as frustrum culling. It checks whether the object is far away, very close / behind the camera, or horizontally out of view. It does not check whether it is vertically out of view. It assumes a sphere of 300 units around the object's position unless the object has a culling radius node that specifies otherwise.
The matrix parameter should be the top of the matrix stack, which is the object's transformation matrix times the camera 'look-at' matrix. The math is counter-intuitive, but it checks column 3 (translation vector) of this matrix to determine where the origin (0,0,0) in object space will be once transformed to camera space (x+ = right, y+ = up, z = 'coming out the screen'). In 3D graphics, you typically model the world as being moved in front of a static camera instead of a moving camera through a static world, which in this case simplifies calculations. Note that the perspective matrix is not on the matrix stack, so there are still calculations with the fov to compute the slope of the lines of the frustrum.
z-
\ | / \ | / \ | / \ | / \ | / |/ C x+
Since (0,0,0) is unaffected by rotation, columns 0, 1 and 2 are ignored.
Why is there a f32 cast?
This makes the HOLP not update when the camera is far away, and it
u16 gAreaUpdateCounter = 0 |
s16* gCurAnimData |
u8 gCurAnimEnabled |
f32 gCurAnimTranslationMultiplier |
u8 gCurAnimType |
struct GraphNodeCamera* gCurGraphNodeCamera = NULL |
struct GraphNodePerspective* gCurGraphNodeCamFrustum = NULL |
struct GraphNodeHeldObject* gCurGraphNodeHeldObject = NULL |
struct GraphNodeMasterList* gCurGraphNodeMasterList = NULL |
struct GraphNodeObject* gCurGraphNodeObject = NULL |
struct GraphNodeRoot* gCurGraphNodeRoot = NULL |
u16* gCurrAnimAttribute |
s16 gCurrAnimFrame |
struct AllocOnlyPool* gDisplayListHeap |
struct GeoAnimState gGeoTempState |
Mat4 gMatStack[32] |
Mtx* gMatStackFixed[32] |
s16 gMatStackIndex |
This file contains the code that processes the scene graph for rendering.
The scene graph is responsible for drawing everything except the HUD / text boxes. First the root of the scene graph is processed when geo_process_root is called from level_script.c. The rest of the tree is traversed recursively using the function geo_process_node_and_siblings, which switches over all geo node types and calls a specialized function accordingly. The types are defined in engine/graph_node.h
The scene graph typically looks like:
struct RenderModeContainer renderModeTable_1Cycle[2] |
struct RenderModeContainer renderModeTable_2Cycle[2] |