Alchemy
Loading...
Searching...
No Matches

transform.c File Reference

The 3D transform, its stack, the look-at matrix and the projection. More...

Go to the source code of this file.

Macros

#define TRANSFORM_DMA   (DMA_COPY_WORDS(12))
 one matrix

Typedefs

typedef s32(*) Dot3Fn(s32 ax, s32 bx, s32 ay, s32 by, s32 az, s32 bz)

Functions

void Render_ResetTransformState (void)
 Allocates the one-level save area (heap slot HEAP_SLOT_TRANSFORM_STACK), clears gTransformStackDepth and resets gTransform to identity.
void Transform_Push (void)
 Saves gTransform into the save area (one level deep; a second save is ignored).
void Transform_Store (void *dst)
 Copies gTransform to dst. Called by BattleFx_RunAtalanta.
void Transform_Load (const void *src)
 Copies the matrix at src into gTransform. Called by BattleFx_RunAtalanta.
void Transform_Pop (void)
 Restores gTransform from the save area, if Transform_Push saved it.
void SceneTransform_ResetMatrix (void)
 Resets gTransform to identity. Reached through the far-call table.
void SceneTransform_ApplyRotation (s32 *angles)
 Rotates gTransform by angles[0], angles[1] and angles[2] about the X, Y and Z axes, in that order, with one combined matrix.
void SceneTransform_ApplyPitch (s32 angle)
 Rotates gTransform about the X axis by angle.
void SceneTransform_ApplyYaw (s32 angle)
 Rotates gTransform about the Y axis by angle.
void SceneTransform_ApplyRoll (s32 angle)
 Rotates gTransform about the Z axis by angle.
void SceneTransform_ApplyPosition (const s32 *position)
 Translates gTransform by position (x, y, z in 16.16).
void SceneTransform_ApplyScale (const s32 *scale)
 Scales gTransform by scale (x, y, z factors in 16.16).
void SceneTransform_ApplyRotationTranslation (s32 *angles, s32 *position)
 Rotates gTransform by angles and translates it by position in one matrix.
void SceneTransform_ApplyScaledRotation (s32 *angles, s32 *position, s32 *scale)
 Rotates by angles, scales each rotation row by scale and translates by position, in one matrix.
void Transform_BuildLookAt (s32 *eye, s32 *target, s32 *out)
 Builds in out the camera matrix of an eye at eye looking at target.
void Transform_SetLookAt (s32 *eye, s32 *target)
 Makes the camera at eye looking at target the whole of gTransform.
void Transform_ApplyLookAt (s32 *eye, s32 *target)
 Multiplies the camera at eye looking at target into gTransform.
void Projection_SetFieldOfView (u32 fieldOfView, s32 nearDepth, s32 farDepth)
 Sets gProjection from a vertical field of view: the focal length is 80 (half the screen height) over the tangent of half the angle.
void Projection_Set (u32 focal, u32 nearDepth, u32 farDepth)
 Sets gProjection's focal length and depth range directly.
s32 Render_ProjectPoint (const void *point, s32 *screen)
 Reads three word-aligned coordinates from point, transforms them by gTransform and projects them to the screen: screen[0] and screen[1] are its pixel position and screen[2] its whole-unit depth.

Detailed Description

The 3D transform, its stack, the look-at matrix and the projection.

Part of runtime.c, the runtime object, compiled only through it.

Definition in file transform.c.

Macro Definition Documentation

◆ TRANSFORM_DMA

#define TRANSFORM_DMA   (DMA_COPY_WORDS(12))

one matrix

Definition at line 11 of file transform.c.

Referenced by Transform_Load(), Transform_Pop(), Transform_Push(), and Transform_Store().

Typedef Documentation

◆ Dot3Fn

typedef s32(*) Dot3Fn(s32 ax, s32 bx, s32 ay, s32 by, s32 az, s32 bz)

Definition at line 13 of file transform.c.

Function Documentation

◆ Render_ResetTransformState()

◆ Transform_Push()

void Transform_Push ( void )

Saves gTransform into the save area (one level deep; a second save is ignored).

Called by the battle effects that draw a part with its own transform, with Transform_Pop after.

Definition at line 30 of file transform.c.

Referenced by BattleFx_RunAstralBlast(), BattleFx_RunDjinnHeal(), BattleFx_RunDjinniEntrance(), BattleFx_RunSwirlingStars(), memcpy(), and Transform_Push().

◆ Transform_Store()

void Transform_Store ( void * dst)

Copies gTransform to dst. Called by BattleFx_RunAtalanta.

Definition at line 39 of file transform.c.

Referenced by BattleFx_RunAtalanta(), memcpy(), and Transform_Store().

◆ Transform_Load()

void Transform_Load ( const void * src)

Copies the matrix at src into gTransform. Called by BattleFx_RunAtalanta.

Definition at line 44 of file transform.c.

Referenced by BattleFx_RunAtalanta(), memcpy(), and Transform_Load().

◆ Transform_Pop()

void Transform_Pop ( void )

Restores gTransform from the save area, if Transform_Push saved it.

Definition at line 49 of file transform.c.

Referenced by BattleFx_RunAstralBlast(), BattleFx_RunDjinnHeal(), BattleFx_RunDjinniEntrance(), BattleFx_RunSwirlingStars(), memcpy(), and Transform_Pop().

◆ SceneTransform_ResetMatrix()

void SceneTransform_ResetMatrix ( void )

Resets gTransform to identity. Reached through the far-call table.

Definition at line 58 of file transform.c.

Referenced by memcpy(), and SceneTransform_ResetMatrix().

◆ SceneTransform_ApplyRotation()

void SceneTransform_ApplyRotation ( s32 * angles)

Rotates gTransform by angles[0], angles[1] and angles[2] about the X, Y and Z axes, in that order, with one combined matrix.

Reached through the far-call table.

Definition at line 66 of file transform.c.

Referenced by memcpy(), and SceneTransform_ApplyRotation().

◆ SceneTransform_ApplyPitch()

◆ SceneTransform_ApplyYaw()

◆ SceneTransform_ApplyRoll()

◆ SceneTransform_ApplyPosition()

◆ SceneTransform_ApplyScale()

void SceneTransform_ApplyScale ( const s32 * scale)

Scales gTransform by scale (x, y, z factors in 16.16).

Called by a few battle effects (Bind, Astral Blast, Thor).

Definition at line 158 of file transform.c.

Referenced by BattleFx_RunAstralBlast(), BattleFx_RunBind(), BattleFx_RunThor(), BattleFx_RunTriangleStrike(), memcpy(), and SceneTransform_ApplyScale().

◆ SceneTransform_ApplyRotationTranslation()

void SceneTransform_ApplyRotationTranslation ( s32 * angles,
s32 * position )

Rotates gTransform by angles and translates it by position in one matrix.

Reached through the far-call table.

Definition at line 171 of file transform.c.

Referenced by memcpy(), and SceneTransform_ApplyRotationTranslation().

◆ SceneTransform_ApplyScaledRotation()

void SceneTransform_ApplyScaledRotation ( s32 * angles,
s32 * position,
s32 * scale )

Rotates by angles, scales each rotation row by scale and translates by position, in one matrix.

Definition at line 202 of file transform.c.

Referenced by memcpy(), and SceneTransform_ApplyScaledRotation().

◆ Transform_BuildLookAt()

void Transform_BuildLookAt ( s32 * eye,
s32 * target,
s32 * out )

Builds in out the camera matrix of an eye at eye looking at target.

The camera's sideways axis is kept level (no Y component). Called by Transform_SetLookAt and Transform_ApplyLookAt.

Definition at line 243 of file transform.c.

Referenced by memcpy(), Transform_ApplyLookAt(), Transform_BuildLookAt(), and Transform_SetLookAt().

◆ Transform_SetLookAt()

void Transform_SetLookAt ( s32 * eye,
s32 * target )

◆ Transform_ApplyLookAt()

void Transform_ApplyLookAt ( s32 * eye,
s32 * target )

Multiplies the camera at eye looking at target into gTransform.

Called by the battle and field object cameras.

Definition at line 324 of file transform.c.

Referenced by Camera_ApplyTransformByFlag(), memcpy(), ObjectSystem_UpdateCameraFixed(), and Transform_ApplyLookAt().

◆ Projection_SetFieldOfView()

void Projection_SetFieldOfView ( u32 fieldOfView,
s32 nearDepth,
s32 farDepth )

Sets gProjection from a vertical field of view: the focal length is 80 (half the screen height) over the tangent of half the angle.

Points nearer than nearDepth or farther than farDepth are not drawn. Reached through the far-call table.

Definition at line 335 of file transform.c.

Referenced by memcpy(), and Projection_SetFieldOfView().

◆ Projection_Set()

void Projection_Set ( u32 focal,
u32 nearDepth,
u32 farDepth )

◆ Render_ProjectPoint()

s32 Render_ProjectPoint ( const void * point,
s32 * screen )

Reads three word-aligned coordinates from point, transforms them by gTransform and projects them to the screen: screen[0] and screen[1] are its pixel position and screen[2] its whole-unit depth.

Returns the projection scale (16.16), or 0 when the point is outside the depth range, when only the transformed point is written. Called by the battle and field code that places sprites in 3D.

Definition at line 364 of file transform.c.

Referenced by BattleFx_RunBeamSequence(), BattleMotion_ProjectConditionalPosition(), BattleMotion_ProjectPosition(), BattleMotion_ProjectScaledPosition(), BattlePres_SetupTransitionScene(), BattlePres_SetupTransitionSceneAtDepth(), BattleUnit_ProjectToScreen(), Camera_WorldToScreen(), EffectPosition_ProjectPoint(), Event_ShowSpeakerMessage(), LuckyDice_Run(), memcpy(), Render_PlaceProjectedSprite(), Render_ProjectPoint(), and UiText_OpenMessageAtObject().