NNSG3dRS Structure and Access

# NNSG3dRS Structure and Accessor

## Description

The `NNSG3dRS` structure holds data corresponding to the state (machine state) during rendering. `NNSG3dRS` is referenced and changed when calculating the rendering and animation. This structure is normally allocated to the stack region (DTCM) inside the `NNS_G3dDraw` function. When executing things such as SBC commands or callback functions, a pointer is passed to `NNSG3dRS` as the command/function/etc.'s first argument. While the `NNS_G3dDraw` function is being executed, a pointer is also stored in the `NNSG3dRS` of the global variable. Normally, lack of knowledge about this structure will not cause any problems, but if you want to customize the drawing operations in detail using a callback, the data kept in this structure will need to be referenced and changed. The table below contains descriptions of the accessor to the data members in the `NNS_G3dRS` structure.

## Accessor Functions

`#include void NNS_G3dRSSetCallBack(NNSG3dRS* rs, NNSG3dSbcCallBackFunc func, u8 cmd, NNSG3dSbcCallBackTiming timing);`
Sets the callback to the SBC instruction command. For an argument, reference the `NNS_G3dRenderObjSetCallBack` function. The callback is enabled for one command. If the execution is performed on the same command, the setting will be overwritten. To set multiple callbacks, use this function rather than calling the `NNS_G3dRenderObjSetCallBack` function multiple times.

`#include void NNS_G3dRSResetCallBack(NNSG3dRS* rs, u8 cmd);`
Disables the callback that is set to the SBC instruction command.

`#include NNSG3dRenderObj* NNS_G3dRSGetRenderObj(NNSG3dRS* rs);`
Obtains a pointer to the `NNSG3dRenderObj` structure.

`#include NNSG3dMatAnmResult* NNS_G3dRSGetMatAnmResult(NNSG3dRS* rs);`
Obtains a pointer to the `NNSG3dMatAnmResult` structure. It can be referenced or changed with the timing A and timing B callbacks of the `NNS_G3D_SBC_MAT` command. For other cases, it is NULL.

`#include NNSG3dJntAnmResult* NNS_G3dRSGetJntAnmResult(NNSG3dRS* rs);`
Obtains a pointer to the `NNSG3dJntAnmResult` structure. It can be referenced or changed with the timing A and timing B callbacks of the `NNS_G3D_SBC_NODEDESC` command. For other cases, it is NULL.

`#include NNSG3dVisAnmResult* NNS_G3dRSGetVisAnmResult(NNSG3dRS* rs);`
Obtains a pointer to the `NNSG3dVisAnmResult` structure. It can be referenced or changed with the timing A and timing B callbacks of the `NNS_G3D_SBC_NODE` command. For other cases, it is NULL.

`#include u8* NNS_G3dRSGetSbcPtr(NNSG3dRS* rs);`
Obtains a pointer to the SBC instruction that is being executed.

`#include u8* NNS_G3dRSSetFlag(NNSG3dRS* rs, NNSG3dRSFlag flag);`
Specifies the `NNSG3dRSFlag` type flag that is defined in `sbc.h` to be turned ON.

`#include u8* NNS_G3dRSResetFlag(NNSG3dRS* rs, NNSG3dRSFlag flag);`
Specifies the `NNSG3dRSFlag` type flag that is defined in `sbc.h` to be turned OFF.

`#include int NNS_G3dRSGetCurrentMatID(const NNSG3dRS* rs);`
Returns the ID of the material set by the currently calculating `NNS_G3D_SBC_MAT` command, or that was set by the previously executed `NNS_G3D_SBC_MAT` command. The material ID is set by the SSBC `NNS_G3D_SBC_MAT` command. It will be maintained until the next `NNS_G3D_SBC_MAT` command overwrites it, or it is modified by a callback function. This function will return -1 if no `NNS_G3D_SBC_MAT` command has been run, or if the previous `NNS_G3D_SBC_MAT` command's results are nullified.

`#include int NNS_G3dRSGetCurrentNodeID(const NNSG3dRS* rs);`
Returns the ID of the node set by the currently calculating `NNS_G3D_SBC_NODE` command, or that was set by the previously executed `NNS_G3D_SBC_NODE` command. The node ID is set by the SBC `NNS_G3D_SBC_NODE` command. It will be maintained until the next `NNS_G3D_SBC_NODE` command overwrites it, or it is modified by a callback function. This function will return -1 if no `NNS_G3D_SBC_NODE` command has been run, or if the previous `NNS_G3D_SBC_NODE` command's results are nullified.

`#include int NNS_G3dRSGetCurrentNodeDescID(const NNSG3dRS* rs);`
Returns the ID of the node set by the currently calculating `NNS_G3D_SBC_NODEDESC` command, or that was set by the previously executed `NNS_G3D_SBC_NODEDESC` command. The node ID is set by the SBC `NNS_G3D_SBC_NODEDESC` command. It will be maintained until the next `NNS_G3D_SBC_NODEDESC` command overwrites it, or it is modified by a callback function. This function will return -1 if no `NNS_G3D_SBC_NODEDESC` command has been run, or if the previous `NNS_G3D_SBC_NODEDESC` command's results are nullified.

`#include fx32 NNS_G3dRSGetPosScale(const NNSG3dRS* rs);`
Acquires a scale value for vertex coordinates that are cached in the `NNSG3dRS` structure.

`#include fx32 NNS_G3dRSGetInvPosScale(const NNSG3dRS* rs);`
Acquires the inverse of a scale value for vertex coordinates that are cached in the `NNSG3dRS` structure.

Below is a description of the `NNSG3dRSFlag` type flags.

    NNS_G3D_RSFLAG_NODE_VISIBLE

This flag is set when the polygon belonging to the node is visible on the `NNS_G3D_SBC_NODE` command.

    NNS_G3D_RSFLAG_MAT_TRANSPARENT

This flag is set when the material is transparent on the `NNS_G3D_SBC_MAT` command.

    NNS_G3D_RSFLAG_CURRENT_NODE_VALID

This flag is set when a valid value is in `currentNode`.

    NNS_G3D_RSFLAG_CURRENT_MAT_VALID

This flag is set when a valid value is in `currentMat`.

    NNS_G3D_RSFLAG_RETURN

If this flag is set, execution of the `NNS_G3dDraw` function will finish after the end of the current SBC command.

    NNS_G3D_RSFLAG_SKIP

If this flag is set, then the processing will be skipped until the next callback point or the current command ends.

## See Also

## Revision History

10/11/2004 Revised version.

08/02/2004 Initial version.