src/system/system_matrix.c
The 3D transform, its stack, the look-at matrix and the projection. More…
Included by system.c.
Macros
| Name | Description | |
|---|---|---|
#define | MATRIX_DMA (DMA_COPY_WORDS(MATRIX_WORDS)) | one matrix |
#define | RECIPROCAL_SHIFT 15 | syMatrixBuildLookAt's reciprocals divide toFIXED(1) << RECIPROCAL_SHIFT, 2^31, the most a Uint32 holds: the quotient shifted right by RECIPROCAL_SHIFT is toFIXED(1) over a whole-number divisor, and doubled it is the 16.16 reciprocal of a 16.16 divisor. |
#define | PROJECTION_DEPTH_SHIFT 11 | syConvert3Dto2D's depth drops its low PROJECTION_DEPTH_SHIFT bits, and the focal length gains the rest of toFIXED(1)'s, so that the focal length over the depth comes out in 16.16 within 32 bits. |
Typedefs
| Name | Description | |
|---|---|---|
typedef Sint32 (* | DOT3_FN )( Sint32 ax, Sint32 bx, Sint32 ay, Sint32 by, Sint32 az, Sint32 bz); |
Functions
| Name | Description | |
|---|---|---|
void | syInitMatrix (void) | Allocates the one-level save area (heap slot HEAP_SLOT_MATRIX_STACK), clears MatrixStackDepth and resets CurrentMatrix to the unit matrix. |
void | syPushMatrix (void) | Saves CurrentMatrix into the save area (one level deep; a second save is ignored). |
void | syGetMatrix (MATRIX dest) | Copies CurrentMatrix to dest. |
void | syLoadMatrix (const MATRIX src) | Copies the matrix at src into CurrentMatrix. |
void | syPopMatrix (void) | Restores CurrentMatrix from the save area, if syPushMatrix saved it. |
void | syUnitMatrixCurrent (void) | Resets CurrentMatrix to the unit matrix. |
void | syMatrixRotate (Sint32 *angles) | Rotates CurrentMatrix by angles[0], angles[1] and angles[2] about the X, Y and Z axes, in that order, with one combined matrix. |
void | syRotX (ANGLE angle) | Rotates CurrentMatrix about the X axis by angle. |
void | syRotY (ANGLE angle) | Rotates CurrentMatrix about the Y axis by angle. |
void | syRotZ (ANGLE angle) | Rotates CurrentMatrix about the Z axis by angle. |
void | syMatrixTranslateVector (const POINT pos) | Translates CurrentMatrix by pos (x, y, z in 16.16). |
void | syMatrixScaleVector (const VECTOR scale) | Scales CurrentMatrix by scale (x, y, z factors in 16.16). |
void | syMatrixRotateTranslate (Sint32 *angles, POINT pos) | Rotates CurrentMatrix by angles and translates it by pos in one matrix. |
void | syMatrixRotateTranslateScale (Sint32 *angles, POINT pos, VECTOR scale) | Rotates by angles, scales each rotation row by scale and translates by pos, in one matrix. |
void | syMatrixBuildLookAt (POINT eye, POINT target, MATRIX out) | Builds in out the camera matrix of an eye at eye looking at target. |
void | syLookAtLoad (POINT eye, POINT target) | Makes the camera at eye looking at target the whole of CurrentMatrix. |
void | syLookAt (POINT eye, POINT target) | Multiplies the camera at eye looking at target into CurrentMatrix. |
void | syPerspective (Uint32 fieldOfView, FIXED nearDepth, FIXED farDepth) | Sets ProjectionWork from a vertical field of view (1/65536 turns): the focal length, in 16.16 pixels, is 80 (half the screen height) over the tangent of half the angle. |
void | sySetScreenDist (Uint32 focal, Uint32 nearDepth, Uint32 farDepth) | Sets ProjectionWork's focal length and depth range directly. |
Sint32 | syConvert3Dto2D (const POINT point, Sint32 *screen) | Reads three word-aligned coordinates from point, transforms them by CurrentMatrix and projects them to the screen: screen[0] and screen[1] are its pixel position and screen[2] its whole-unit depth. |
Description
The 3D transform, its stack, the look-at matrix and the projection. Part of
system.c.
Macros in detail
MATRIX_DMA
#define MATRIX_DMA (DMA_COPY_WORDS(MATRIX_WORDS))
one matrix
Referenced by syGetMatrix(), syLoadMatrix(), syPopMatrix() and syPushMatrix().
Definition at line 7 of file system_matrix.c.
RECIPROCAL_SHIFT
#define RECIPROCAL_SHIFT 15
syMatrixBuildLookAt's reciprocals divide toFIXED(1) << RECIPROCAL_SHIFT,
2^31, the most a Uint32 holds: the quotient shifted right by RECIPROCAL_SHIFT
is toFIXED(1) over a whole-number divisor, and doubled it is the 16.16
reciprocal of a 16.16 divisor.
Referenced by syMatrixBuildLookAt().
Definition at line 13 of file system_matrix.c.
PROJECTION_DEPTH_SHIFT
#define PROJECTION_DEPTH_SHIFT 11
syConvert3Dto2D's depth drops its low PROJECTION_DEPTH_SHIFT bits, and the
focal length gains the rest of toFIXED(1)'s, so that the focal length over
the depth comes out in 16.16 within 32 bits.
Referenced by syConvert3Dto2D().
Definition at line 18 of file system_matrix.c.
Typedefs in detail
DOT3_FN
typedef Sint32 (*DOT3_FN)( Sint32 ax, Sint32 bx, Sint32 ay, Sint32 by, Sint32 az, Sint32 bz);
Referenced by syMatrixBuildLookAt().
Definition at line 20 of file system_matrix.c.
Functions in detail
syInitMatrix
void syInitMatrix(void)
Allocates the one-level save area (heap slot HEAP_SLOT_MATRIX_STACK), clears
MatrixStackDepth and resets CurrentMatrix to the unit matrix.
References CurrentMatrix, MatrixStackDepth, MatrixStackTop, syHeapSlotAllocateEWRAM() and syUnitMatrixCurrentInline().
Referenced by btCameraApplyTransform(), btCameraSetCommandView(), btCameraSetDefaultView(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btEffectDrawStreaks(), btEffectRunAtalanta(), btEffectRunBind(), btEffectRunBoreas(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunFrost(), btEffectRunJudgment(), btEffectRunProcne(), btEffectRunStarfieldFall(), btEffectRunThor(), btEffectRunUnusedTriangleStrike(), btRun(), btStagingDispatchAction(), fdActorSystemProjectSprites(), fdCameraResetViewDefaults(), fdLuckyDiceRun(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 25 of file system_matrix.c.
syPushMatrix
void syPushMatrix(void)
Saves CurrentMatrix into the save area (one level deep; a second save is
ignored).
References CurrentMatrix, MatrixStackDepth, MatrixStackTop and syDMAXCopy().
Referenced by btEffectRunAstralBlast(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance() and btEffectRunSwirlingStars().
Definition at line 35 of file system_matrix.c.
syGetMatrix
void syGetMatrix(MATRIX dest)
Copies CurrentMatrix to dest.
References CurrentMatrix and syDMAXCopy().
Referenced by btEffectRunAtalanta().
Definition at line 46 of file system_matrix.c.
syLoadMatrix
void syLoadMatrix(const MATRIX src)
Copies the matrix at src into CurrentMatrix.
References CurrentMatrix and syDMAXCopy().
Referenced by btEffectRunAtalanta().
Definition at line 52 of file system_matrix.c.
syPopMatrix
void syPopMatrix(void)
Restores CurrentMatrix from the save area, if syPushMatrix saved it.
References CurrentMatrix, MatrixStackDepth, MatrixStackTop and syDMAXCopy().
Referenced by btEffectRunAstralBlast(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance() and btEffectRunSwirlingStars().
Definition at line 58 of file system_matrix.c.
syUnitMatrixCurrent
void syUnitMatrixCurrent(void)
Resets CurrentMatrix to the unit matrix. Reached through the stub call table.
References syUnitMatrixCurrentInline().
Definition at line 69 of file system_matrix.c.
syMatrixRotate
void syMatrixRotate(Sint32 *angles)
Rotates CurrentMatrix by angles[0], angles[1] and angles[2] about the X, Y
and Z axes, in that order, with one combined matrix.
References Sint32, syCos(), syMulFX(), syMultiMatrix() and sySin().
Definition at line 76 of file system_matrix.c.
syRotX
void syRotX(ANGLE angle)
Rotates CurrentMatrix about the X axis by angle.
References syCos(), syMultiMatrix(), sySin() and syUnitMatrix().
Referenced by btCameraSetCommandView(), btCameraSetDefaultView(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btEffectDrawStreaks(), btEffectRunAtalanta(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunHaunt(), btEffectRunHealingMotes(), btEffectRunJudgment(), btEffectRunStatBoost(), btEffectRunSwirlingStars(), btEffectRunTargetMotes(), btEffectRunThor(), fdCameraResetViewDefaults(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 103 of file system_matrix.c.
syRotY
void syRotY(ANGLE angle)
Rotates CurrentMatrix about the Y axis by angle.
References syCos(), syMultiMatrix(), sySin() and syUnitMatrix().
Referenced by btCameraSetCommandView(), btCameraSetDefaultView(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btEffectDrawStreaks(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunBind(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunHealingMotes(), btEffectRunJudgment(), btEffectRunProcne(), btEffectRunStarfieldFall(), btEffectRunStatBoost(), btEffectRunSwirlingStars(), btEffectRunTargetMotes(), btEffectRunThor(), btEffectRunUnusedTriangleStrike(), fdCameraResetViewDefaults(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 118 of file system_matrix.c.
syRotZ
void syRotZ(ANGLE angle)
Rotates CurrentMatrix about the Z axis by angle.
References syCos(), syMultiMatrix(), sySin() and syUnitMatrix().
Referenced by btEffectDrawStreaks(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunBind(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunHealingMotes(), btEffectRunJudgment(), btEffectRunProcne(), btEffectRunStarfieldFall(), btEffectRunStatBoost(), btEffectRunSwirlingStars(), btEffectRunThor() and btEffectRunUnusedTriangleStrike().
Definition at line 133 of file system_matrix.c.
syMatrixTranslateVector
void syMatrixTranslateVector(const POINT pos)
Translates CurrentMatrix by pos (x, y, z in 16.16).
References syMultiMatrix() and syUnitMatrix().
Referenced by btCameraSetCommandView(), btCameraSetDefaultView(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btEffectRunAstralBlast(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunFrost(), btEffectRunHaunt(), btEffectRunHealingMotes(), btEffectRunProcne(), btEffectRunSleep(), btEffectRunStarfieldFall(), btEffectRunStatBoost(), btEffectRunStatReduction(), btEffectRunSwirlingStars(), btEffectRunTargetBursts(), btEffectRunTargetMotes(), btEffectRunThor(), fdCameraResetViewDefaults(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 148 of file system_matrix.c.
syMatrixScaleVector
void syMatrixScaleVector(const VECTOR scale)
Scales CurrentMatrix by scale (x, y, z factors in 16.16).
References syMultiMatrix() and syUnitMatrix().
Referenced by btEffectRunAstralBlast(), btEffectRunBind(), btEffectRunThor() and btEffectRunUnusedTriangleStrike().
Definition at line 160 of file system_matrix.c.
syMatrixRotateTranslate
void syMatrixRotateTranslate(Sint32 *angles, POINT pos)
Rotates CurrentMatrix by angles and translates it by pos in one matrix.
Reached through the stub table.
References Sint32, syCos(), syMulFX(), syMultiMatrix() and sySin().
Definition at line 173 of file system_matrix.c.
syMatrixRotateTranslateScale
void syMatrixRotateTranslateScale(Sint32 *angles, POINT pos, VECTOR scale)
Rotates by angles, scales each rotation row by scale and translates by
pos, in one matrix.
References Sint32, syCos(), syMulFX(), syMultiMatrix() and sySin().
Definition at line 201 of file system_matrix.c.
syMatrixBuildLookAt
void syMatrixBuildLookAt(POINT eye, POINT target, MATRIX 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).
References RelocatedInnerProduct, Sint32, syDMAXCopy(), syIntegerDivideUnsigned(), syMulFX(), sySquartFX() and sySquartIWRAM().
Referenced by syLookAt() and syLookAtLoad().
Definition at line 237 of file system_matrix.c.
syLookAtLoad
void syLookAtLoad(POINT eye, POINT target)
Makes the camera at eye looking at target the whole of CurrentMatrix.
References CurrentMatrix and syMatrixBuildLookAt().
Referenced by btCameraApplyTransform(), btCameraSetView(), btCameraSetViewAtDepth(), btStagingDispatchAction(), fdActorSystemProjectSprites(), fdLuckyDiceRun(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 314 of file system_matrix.c.
syLookAt
void syLookAt(POINT eye, POINT target)
Multiplies the camera at eye looking at target into CurrentMatrix.
References syMatrixBuildLookAt() and syMultiMatrix().
Referenced by btCameraApplyTransform() and fdActorSystemProjectSprites().
Definition at line 320 of file system_matrix.c.
syPerspective
void syPerspective(Uint32 fieldOfView, FIXED nearDepth, FIXED farDepth)
Sets ProjectionWork from a vertical field of view (1/65536 turns): the focal
length, in 16.16 pixels, is 80 (half the screen height) over the tangent of
half the angle.
References ProjectionWork, Sint32, syCos(), syDivFX() and sySin().
Definition at line 331 of file system_matrix.c.
sySetScreenDist
void sySetScreenDist(Uint32 focal, Uint32 nearDepth, Uint32 farDepth)
Sets ProjectionWork's focal length and depth range directly.
References ProjectionWork.
Referenced by btCameraSetCommandView(), btCameraSetView(), btCameraSetViewAtDepth(), btEffectRunThor(), btStagingDispatchAction(), fdCameraResetViewDefaults(), fdWorldMapInitPerspective() and fdWorldMapUpdateView().
Definition at line 348 of file system_matrix.c.
syConvert3Dto2D
Sint32 syConvert3Dto2D(const POINT point, Sint32 *screen)
Reads three word-aligned coordinates from point, transforms them by
CurrentMatrix and projects them to the screen: screen[0] and screen[1] are
its pixel position and screen[2] its whole-unit depth. Returns the scale the
point is drawn at, in 16.16, or 0 when it lies outside the projection's depth
range and the screen position is not written.
References ProjectionWork, Sint32, syCalcPoint(), syIntegerDivideUnsigned() and syMulFX().
Referenced by btCameraSetView(), btCameraSetViewAtDepth(), btEffectRunAttackSlash(), btMotionProjectCursorPoint(), btMotionProjectPos(), btMotionProjectScaledPos(), btProjectionPoint(), btUnitProjectToScreen(), fdCameraWorldToScreen(), fdLuckyDiceRun(), fdMessageShowAtActor(), fdRenderPlaceProjectedSprite() and fdScriptShowSpeakerMessage().
Definition at line 362 of file system_matrix.c.