Skip to Content
The Alchemy Project

include/fixed_math.h

16.16 fixed-point constants and pixels, sine and cosine, and the system library's division.

Included by battle_effect_internal.h, actor_update_arm.c, world_map_lines.c, menu_internal.h, sol_sanctum_elemental_star_light_tables.c, screens_internal.h, battle.h, battle_action.h, battle_camera.h, battle_state.h, battle_effect.h, actor.h, actor_script.h, actor_update_arm.h, facing.h, field.h, field_coordinate.h, field_effect.h, field_engine.h, field_engine_functions.h, field_functions.h, field_particle.h, field_psynergy_state.h, field_state.h, lucky_dice.h, lucky_wheels.h, map_grid.h, particle.h, perspective.h, scene_tables.h, script.h, script_commands.h, script_inline.h, sprite.h, weather.h, world_map_affine.h, main_routine_state.h, display_transition.h, render_placement.h, menu.h, colosso_gauge.h, colosso_setup.h, import.h, kolima.h, mercury_lighthouse_lights.h, orbit.h, sol_sanctum_elemental_star_lights.h, vault_item_icon.h, shop.h, definitions.h and 3 more.

Macros

NameDescription
#defineDAMPING_SCALE 64A damping is a fraction of a speed kept each tick, out of DAMPING_SCALE: speed * damping / DAMPING_SCALE.
#defineINTtoFIXED (value) ((value) << 16)Whole pixels as 16.16 by a shift, unsigned for an unsigned value: kept only where toFIXED's signed multiply compiles to other instructions.
#defineFIXEDtoINT (value) ((value) >> 16)The whole pixels of a 16.16 value, toFIXED() undone: an arithmetic shift, so a negative value rounds down.
#defineFIXEDtoINT_TWICE (value) ((value) >> 15)Twice a 16.16 value, as a whole number: FIXEDtoINT a shift short.
#definetoFIXED (value) ((Sint32)((value) * 65536))
#definePOStoFIXED (x, y, z) {toFIXED(x), toFIXED(y), toFIXED(z)}
#defineTRIG_TURN (1 << 16)A whole turn in the angles that sySin, syCos and the transform's turns take, 65,536 to the turn.
#defineDEGtoANG (degrees) ((degrees) * TRIG_TURN / 360)An angle given in degrees, as SGL writes it: DEGtoANG(90) is a quarter turn.
#defineTRIG_ANGLE_MASK (TRIG_TURN - 1)Keeps an angle within one turn: syRandom() & TRIG_ANGLE_MASK is a random angle.

Typedefs

NameDescription
typedef Sint32FIXED ;A signed 16.16 fixed-point number, as SGL types one: toFIXED(1) is 1.0.
typedef Sint32ANGLE ;An angle, 65,536 to the turn, carried in 32 bits: SGL's ANGLE is 16 bits wide, and the callers here pass and keep 32.
typedef FIXEDVECTOR [XYZ];A direction or a scale in three 16.16 coordinates, as SGL types one.
typedef FIXEDPOINT [XYZ];A position in three 16.16 coordinates, as SGL types one.
typedef FIXEDMATRIX [4 * XYZ];A transform of four rows of three 16.16 words, the rotation's three and then the translation, as SGL types one but flat: FIXED[12], not [4][3].

Enumerations

NameDescription
enumanonymous enum { X, Y, Z, XYZ }The coordinate indices and their count, as SGL types them.
enumanonymous enum { M00, M01, M02, M10, M11, M12, M20, M21, M22, M30, M31, M32 }Matrix cell indices, matching SGL's M00..M32 (constenm).

Description

16.16 fixed-point constants and pixels, sine and cosine, and the system library's division.

Macros in detail

DAMPING_SCALE

#define DAMPING_SCALE 64

A damping is a fraction of a speed kept each tick, out of DAMPING_SCALE: speed * damping / DAMPING_SCALE.

Referenced by btEffectRunCastingImpact(), btEffectRunDjinniEntrance(), btEffectRunFire(), btEffectRunFroth(), btEffectRunGround(), btEffectRunJudgment(), btEffectRunKirin(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunPlanetDiver(), btEffectRunThor(), btEffectRunTitanBlade(), btEffectRunVolcano(), btParticleAdvanceWithGravity2D(), btParticleAdvanceWithGravity3D(), fdLuckyDiceRun() and fdLuckyWheelsRun().

Definition at line 51 of file fixed_math.h.

INTtoFIXED

#define INTtoFIXED(value) ((value) << 16)

Whole pixels as 16.16 by a shift, unsigned for an unsigned value: kept only where toFIXED's signed multiply compiles to other instructions.

Referenced by btEffectRunAtalanta(), btEffectRunBoreas(), btEffectRunCondemn(), btEffectRunCybele(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunDragonFire(), btEffectRunFrost(), btEffectRunGaia(), btEffectRunHail(), btEffectRunJudgment(), btEffectRunKirin(), btEffectRunMars(), btEffectRunPlanetDiver(), btEffectRunPrism(), btEffectRunProcne(), btEffectRunRamses(), btEffectRunRay(), btEffectRunShatteringOpening(), btEffectRunSleep(), btEffectRunSparkGroups(), btEffectRunStarfieldFall(), btEffectRunThor(), btEffectRunVenus(), btEffectRunVolcano(), fdLuckyWheelsSetUpBetting(), scSanctumSpawnActorSpark(), scSolSanctumUpdateFloatingLights(), scVaultSpawnDriftingEffect() and syMulFXArm().

Definition at line 55 of file fixed_math.h.

FIXEDtoINT

#define FIXEDtoINT(value) ((value) >> 16)

The whole pixels of a 16.16 value, toFIXED() undone: an arithmetic shift, so a negative value rounds down.

Referenced by btCameraSetRange(), btCameraSetView(), btCameraSetViewAtDepth(), btEffectRunAtalanta(), btEffectRunBind(), btEffectRunBladeRain(), btEffectRunBolt(), btEffectRunBoreas(), btEffectRunBreak(), btEffectRunBurstShower(), btEffectRunCastingImpact(), btEffectRunCondemn(), btEffectRunCybele(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunElementBurst(), btEffectRunFlare(), btEffectRunFrost(), btEffectRunGaia(), btEffectRunGround(), btEffectRunHail(), btEffectRunHealingMotes(), btEffectRunHelmSplitter(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunMars(), btEffectRunMercury(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunOrbitingSkulls(), btEffectRunPlanetDiver(), btEffectRunPlasma(), btEffectRunPrism(), btEffectRunProcne(), btEffectRunProjectileVolley(), btEffectRunQuake(), btEffectRunRagnarok(), btEffectRunRamses(), btEffectRunRay(), btEffectRunShatteringOpening(), btEffectRunShiningStar(), btEffectRunSleep(), btEffectRunSparkGroups(), btEffectRunSpire() and 73 more.

Definition at line 58 of file fixed_math.h.

FIXEDtoINT_TWICE

#define FIXEDtoINT_TWICE(value) ((value) >> 15)

Twice a 16.16 value, as a whole number: FIXEDtoINT a shift short.

Referenced by btEffectRunVolcano(), btEffectUpdatePhasePalette() and mnWindowDrawZoomBorder().

Definition at line 60 of file fixed_math.h.

toFIXED

#define toFIXED(value) ((Sint32)((value) * 65536))

A whole or decimal number as 16.16, as SGL writes one: toFIXED(1) is 1.0 and
toFIXED(0.8) is
52428. SGL multiplies by 65536.0; here the factor is the integer 65536, so a
       whole number stays
integer arithmetic, and a multiply rather than a shift keeps toFIXED(-64)
defined C.

Referenced by ActorTrembleScript, AltinPeakCartSpeeds, AltinPeakPuddleGrowScript, AltinPeakStatueSinkScript, AltmillerCavePulseScales, AtalantaUnitScale, BabiLighthouseTrembleScript, BabiPalaceIndigestionScript, BalancePlatformHeights, BattleCameraCommandMatrix, BattleKnockbackAcceleration, BattleKnockbackSpeedLimit, BattleKnockbackVelocityY, BattleUnusedUnitMatrix, BeaconSparkScript, btAbilityApplyToTarget(), btActionRunBuild(), btBackgroundLoad(), btBackgroundSetPaletteLevel(), btCameraSetCommandView(), btCameraSetRange(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btEffectDarkenBackgroundStep(), btEffectHopBackToSpot(), btEffectPlaceFormationSprites(), btEffectRunAnnihilation(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunBind(), btEffectRunBladeRain(), btEffectRunBolt(), btEffectRunBoreas(), btEffectRunBreak(), btEffectRunBurstShower(), btEffectRunCastingImpact(), btEffectRunCondemn(), btEffectRunCriticalHit(), btEffectRunCybele(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunDrain(), btEffectRunElementBurst() and 936 more.

Definition at line 68 of file fixed_math.h.

POStoFIXED

#define POStoFIXED(x, y, z) {toFIXED(x), toFIXED(y), toFIXED(z)}

Definition at line 70 of file fixed_math.h.

TRIG_TURN

#define TRIG_TURN (1 << 16)

A whole turn in the angles that sySin, syCos and the transform's turns take, 65,536 to the turn.

Referenced by AltinPeakLeaderFleePath, btCameraSetCommandView(), btCameraSetDefaultView(), btEffectRunBind(), btEffectRunCastingImpact(), btEffectRunCondemn(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunDragonCloud(), btEffectRunElementPillar(), btEffectRunFire(), btEffectRunFlare(), btEffectRunFrost(), btEffectRunFroth(), btEffectRunGatheringLights(), btEffectRunGround(), btEffectRunHail(), btEffectRunHaunt(), btEffectRunHealingMotes(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunMars(), btEffectRunMercury(), btEffectRunMoteFountain(), btEffectRunOrbitingSkulls(), btEffectRunPlanetDiver(), btEffectRunPlasma(), btEffectRunProcne(), btEffectRunProjectileVolley(), btEffectRunQuake(), btEffectRunRamses(), btEffectRunShiningStar(), btEffectRunSparkGroups(), btEffectRunStarfieldFall(), btEffectRunStatBoost(), btEffectRunStreakVolley(), btEffectRunTargetMotes(), btEffectRunThor(), btEffectRunTorch(), btEffectRunUnusedOrbitingSpirals(), btEffectRunUnusedTriangleStrike(), btEffectRunVenus(), btEffectRunWhirlwind(), btEffectUpdatePhasePalette(), btPaletteUpdatePulseBrightness(), btRun(), btStagingRunAttack() and 79 more.

Definition at line 74 of file fixed_math.h.

DEGtoANG

#define DEGtoANG(degrees) ((degrees) * TRIG_TURN / 360)

An angle given in degrees, as SGL writes it: DEGtoANG(90) is a quarter turn.

Referenced by btCameraSetCommandView(), btEffectRunAstralBlast(), btEffectRunBind(), btEffectRunBolt(), btEffectRunDragonCloud(), btEffectRunFlare(), btEffectRunHail(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunNeptune(), btEffectRunOrbitingSkulls(), btEffectRunPlasma(), btEffectRunProcne(), btEffectRunRay(), btEffectRunShiningStar(), btEffectRunStarfieldFall(), btEffectRunThor(), btEffectRunUnusedTriangleStrike(), btEffectRunVenus(), btEffectRunVolcano(), btEffectRunWhirlwind(), btElementGlowInitStarField(), btMotionReturnToSpot(), btObjectMake(), btStagingRunAttack(), btStagingRunPlainAttack(), CottageRoomsAFatherPacingScript, fdActorMoveOnWorldMap(), fdActorSystemProjectSprites(), fdActorTurnPairToFaceEachOther(), fdActorUpdatePlayerControl(), fdDjinnRunBattleStartHop(), fdEffectAdvanceSpinAngle(), fdEffectBurstHand(), fdEffectSpawnCarryHand(), fdEffectSpawnLiftHand(), fdEffectUpdateRetreatCaster(), fdFindCue(), fdFindNearbyPsynergyTarget(), fdLuckyWheelsSetUpBetting(), fdLuckyWheelsUpdate(), fdPsynergySteerPushedTarget(), fdSpriteViewerLayOutRing(), fdSpriteViewerPlaceRing(), KalayTolbiDocksBodyguardSpinScript, mnDjinnMenuRunPreview(), scAltinPeakForceLogOver(), scAltinPeakRestoreFallingRocksRoom() and 33 more.

Definition at line 76 of file fixed_math.h.

TRIG_ANGLE_MASK

#define TRIG_ANGLE_MASK (TRIG_TURN - 1)

Keeps an angle within one turn: syRandom() & TRIG_ANGLE_MASK is a random angle.

Referenced by btEffectDrawStreaks(), btEffectRunAtalanta(), btEffectRunBreak(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunElementBurst(), btEffectRunElementPillar(), btEffectRunFrost(), btEffectRunHealingMotes(), btEffectRunHelmSplitter(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunMars(), btEffectRunMercury(), btEffectRunMoteFountain(), btEffectRunNeptune(), btEffectRunPlanetDiver(), btEffectRunProcne(), btEffectRunRagnarok(), btEffectRunRamses(), btEffectRunSparkGroups(), btEffectRunStatReduction(), btEffectRunTargetBursts(), btEffectRunTargetMotes(), btEffectRunTargetStrike(), btEffectRunThor(), btEffectRunTitanBlade(), btEffectRunUndeadSword(), fdLuckyDiceRun(), fdLuckyWheelsRun(), mnFileListUpdateGlow(), scTolbiShipDeckRockDeck() and scTolbiShipMastRockView().

Definition at line 79 of file fixed_math.h.

Typedefs in detail

FIXED

typedef Sint32 FIXED;

A signed 16.16 fixed-point number, as SGL types one: toFIXED(1) is 1.0.

Referenced by AltinPeakCartSpeeds, BattleCameraCommandMatrix, BattleKnockbackAcceleration, BattleKnockbackSpeedLimit, BattleKnockbackVelocityY, btCameraSetRange(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraSetViewAtPairMidpoint(), btEffectPlaceFormationSprites(), btEffectRunAtalanta(), btEffectRunCastingImpact(), btEffectRunCondemn(), btEffectRunCybele(), btEffectRunDeathPlunge(), btEffectRunDjinnHeal(), btEffectRunFire(), btEffectRunFroth(), btEffectRunHelmSplitter(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunLobbedShells(), btEffectRunNeptune(), btEffectRunPlanetDiver(), btEffectRunShatteringOpening(), btEffectRunSparkGroups(), btEffectRunStarfieldFall(), btEffectRunStreakVolley(), btEffectRunThor(), btEffectRunTitanBlade(), btEffectRunVolcano(), btEffectRunWhirlwind(), btEffectSetApproachMotion(), btElementGlowUpdateStarField(), btGraphicsScaleRGB555Clamped(), btMatrixSetUnit(), btMotionApplyPairMidpoint(), btMotionApproachTarget(), btMotionLeapToward(), btMotionProjectCursorPoint(), btMotionProjectScaledPos(), btObjectMake(), btStagingRunAttack(), btStagingRunItem(), btStagingRunPlainAttack(), btUnitProjectToScreen(), CameraFixedViewMatrix, ColossoWarriorStartX, ColossoWarriorStartZ, fdActorApproachWatchedActor() and 338 more.

Definition at line 10 of file fixed_math.h.

ANGLE

typedef Sint32 ANGLE;

An angle, 65,536 to the turn, carried in 32 bits: SGL's ANGLE is 16 bits wide, and the callers here pass and keep 32.

Referenced by syAtan(), syRotX(), syRotY(), syRotZ() and syVectorAddPolarOffset().

Definition at line 13 of file fixed_math.h.

VECTOR

typedef FIXED VECTOR[XYZ];

A direction or a scale in three 16.16 coordinates, as SGL types one.

Referenced by syMatrixRotateTranslateScale() and syMatrixScaleVector().

Definition at line 42 of file fixed_math.h.

POINT

typedef FIXED POINT[XYZ];

A position in three 16.16 coordinates, as SGL types one.

Referenced by btCameraSetCommandView(), btCameraSetDefaultView(), fdWorldMapInitPerspective(), fdWorldMapUpdateView(), syCalcPoint(), syConvert3Dto2D(), syLookAt(), syLookAtLoad(), syMatrixBuildLookAt(), syMatrixRotateTranslate(), syMatrixRotateTranslateScale(), syMatrixTranslateVector() and syVectorAddPolarOffset().

Definition at line 44 of file fixed_math.h.

MATRIX

typedef FIXED MATRIX[4 * XYZ];

A transform of four rows of three 16.16 words, the rotation's three and then the translation, as SGL types one but flat: FIXED[12], not [4][3].

Referenced by BattleUnusedUnitMatrix, btMatrixSetUnit(), CurrentMatrix, syGetMatrix(), syLoadMatrix(), syLookAt(), syMatrixBuildLookAt(), syMatrixRotate(), syMatrixRotateTranslate(), syMatrixRotateTranslateScale(), syMatrixScaleVector(), syMatrixTranslateVector(), syMultiMatrix(), syRotX(), syRotY(), syRotZ() and syUnitMatrix().

Definition at line 47 of file fixed_math.h.

Enumerations in detail

anonymous enum

enum { X, Y, Z, XYZ }

The coordinate indices and their count, as SGL types them.

EnumeratorValueDescription
X
Y
Z
XYZ

Definition at line 16 of file fixed_math.h.

anonymous enum

enum { M00, M01, M02, M10, … }

Matrix cell indices, matching SGL's M00..M32 (constenm).

EnumeratorValueDescription
M00
M01
M02
M10
M11
M12
M20
M21
M22
M30
M31
M32

Definition at line 25 of file fixed_math.h.