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_internal.h, battle_tables.c, battle_effect_constants.c, battle_effect_internal.h, battle_effect_table.c, field_engine_internal.h, field_internal.h, field_psynergy_internal.h, script_commands_internal.h, script_commands_scripts.c, script_commands_tables.c, world_map_lines.c, menu_internal.h, shop_internal.h, window_internal.h, battle.h, battle_action.h, battle_actor.h, battle_camera.h, battle_state.h, stubs.h, battle_effect.h, actor.h, actor_script.h, curve.h, effect_sprite.h, facing.h, field.h, field_coordinate.h, field_effect.h, field_engine_functions.h, field_functions.h, field_particle.h, field_psynergy_state.h, field_script.h, field_sprite.h, field_state.h, hanging_vine.h, lucky_dice.h, lucky_wheels.h, map.h, map_grid.h, metatile_target.h, particle.h, perspective.h, scene_tables.h, script.h, script_inline.h, sprite.h, stubs.h and 27 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.
#definePIXEL_PART (v) (((Sint16 *)&(v))[1])The whole-pixel half of a 16.16 coordinate, read in place as its high halfword.
#defineFIXEDtoINT_TWICE (value) ((value) >> 15)Twice a 16.16 value, as a whole number: FIXEDtoINT a shift short.
#defineFIXEDtoINT_FOUR_TIMES (value) ((value) >> 14)Four times a 16.16 value, as a whole number: FIXEDtoINT two shifts 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 and syCos take: DEGtoANG(90) is a quarter 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 btEffectPosAdvanceWithGravity2D(), btEffectPosAdvanceWithGravity3D(), btEffectRunAzul(), btEffectRunBallLightning(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunDaedalus(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunEclipse(), btEffectRunFallingSword(), btEffectRunFire(), btEffectRunFlora(), btEffectRunFroth(), btEffectRunGround(), btEffectRunHaures(), btEffectRunJudgment(), btEffectRunJuggle(), btEffectRunKirin(), btEffectRunLifeShear(), btEffectRunMegaera(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunNereidCopy(), btEffectRunStarSwarm(), btEffectRunStoneJustice(), btEffectRunThor(), btEffectRunVengeance(), btEffectRunVolcano(), btEffectRunZagan(), fdBlazeUpdateSpray(), fdLuckyDiceRun(), fdLuckyWheelsRun(), fdSummonTabletUpdateRunes(), fdSuperLuckyDiceRun() and scParticleUpdateFalling().

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(), btEffectRunAzul(), btEffectRunBackstab(), btEffectRunBallLightning(), btEffectRunBoreas(), btEffectRunBreaths(), btEffectRunBubbleColumn(), btEffectRunCanvasBurst(), btEffectRunCards(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCoatlicue(), btEffectRunCondemn(), btEffectRunCool(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunCybele(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDiamondBerg(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunEclipse(), btEffectRunElementCards(), btEffectRunFirePuppet(), btEffectRunFlora(), btEffectRunFormChange(), btEffectRunFrost(), btEffectRunFume(), btEffectRunGaia(), btEffectRunGaspFamily(), btEffectRunGeode(), btEffectRunGeyser(), btEffectRunHail(), btEffectRunHaures(), btEffectRunHeartbreak(), btEffectRunHeavyBlow(), btEffectRunHurricane(), btEffectRunIris(), btEffectRunJudgment(), btEffectRunJuggle(), btEffectRunKirin(), btEffectRunLeapingStrike(), btEffectRunLegend(), btEffectRunLifeShear() and 52 more.

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(), btEffectBuildShadeRamp(), btEffectBuildShadeRampWave(), btEffectBuildSteepShadeRampWave(), btEffectDrawShadedDisc(), btEffectDrawShadedDiscQuarter(), btEffectRunAzul(), btEffectRunBallLightning(), btEffectRunBind(), btEffectRunBladeRain(), btEffectRunBolt(), btEffectRunBoreas(), btEffectRunBreaths(), btEffectRunBurstShower(), btEffectRunCanvasBurst(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCoatlicue(), btEffectRunCondemn(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunCybele(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunDjinniSign(), btEffectRunDragonCloud(), btEffectRunEclipse(), btEffectRunElementBurst(), btEffectRunFallingSword(), btEffectRunFirePuppet(), btEffectRunFlare(), btEffectRunFlora(), btEffectRunFlurry(), btEffectRunFormChange(), btEffectRunFrost(), btEffectRunFume(), btEffectRunGaspFamily(), btEffectRunGatheringLights(), btEffectRunGeode(), btEffectRunGeyser(), btEffectRunGround(), btEffectRunHail(), btEffectRunHaures() and 190 more.

Definition at line 58 of file fixed_math.h.

PIXEL_PART

#define PIXEL_PART(v) (((Sint16 *)&(v))[1])

The whole-pixel half of a 16.16 coordinate, read in place as its high halfword.

Referenced by fdLuckyWheelsUpdate() and scPushTargetFindAhead().

Definition at line 61 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(), mnWindowDrawZoomBorder(), scAirsRockInsideDriftMote(), scEasternAlhafraFillWaveLines(), scIdejimaUpdateWaveLines(), scIsletsFillWaveLines() and scJupiterLighthouseUpdateSpark().

Definition at line 63 of file fixed_math.h.

FIXEDtoINT_FOUR_TIMES

#define FIXEDtoINT_FOUR_TIMES(value) ((value) >> 14)

Four times a 16.16 value, as a whole number: FIXEDtoINT two shifts short.

Referenced by mnWindowSpriteUpdateAll(), scAirsRockInsideDriftMote() and scJupiterLighthouseUpdateSpark().

Definition at line 65 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 ActorPlacements, ActorSpriteFullScale, AirsRockInsideWindStoneScript, AirsRockRubbleScript, AirsRockWindStoneScript, AnemosInnerSanctumDjinniRisesScript, AnemosInnerSanctumDjinniSinksScript, AnemosInnerSanctumDullahanLightGrowsScript, AnemosInnerSanctumDullahanLightShrinksScript, AnemosInnerSanctumDullahanShadowScript, AnemosInnerSanctumDustScript, AnemosInnerSanctumSparkScript, AnkohlRuinsSandStep, AnkohlRuinsWeedsScript, ApojiiIslandsCaveWeedsScript, ArrowWobbleFades, AtalantaUnitScale, AzulLateUnitScale, AzulUnitScale, BattleCameraCommandMatrix, BattleKnockbackAcceleration, BattleKnockbackSpeedLimit, BattleKnockbackVelocityY, BattleUnusedUnitMatrix, btAbilityApplyToTarget(), btActionRunBuild(), btBackgroundLoad(), btBackgroundSetPaletteLevel(), btCameraAdjustByShoulderKeys(), btCameraCreate(), btCameraSetCommandView(), btCameraSetRange(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate(), btChangeEnemyForm(), btEffectDarkenBackgroundStep(), btEffectDimBackgroundStep(), btEffectDrawShadedDisc(), btEffectDrawShadedDiscQuarter(), btEffectHopBackToSpot(), btEffectPlaceFormationSprites(), btEffectRunAnnihilation(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunAzul(), btEffectRunBackstab(), btEffectRunBallLightning(), btEffectRunBind() and 1466 more.

Definition at line 73 of file fixed_math.h.

POStoFIXED

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

Definition at line 75 of file fixed_math.h.

TRIG_TURN

#define TRIG_TURN (1 << 16)

A whole turn in the angles that sySin and syCos take: DEGtoANG(90) is a quarter turn.

Referenced by ArrowWobbleAngles, btCameraAdjustByShoulderKeys(), btCameraCreate(), btCameraSetCommandView(), btCameraSetDefaultView(), btEffectRunAzul(), btEffectRunBind(), btEffectRunBreaths(), btEffectRunBurstShower(), btEffectRunCanvasBurst(), btEffectRunCards(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCloudSwirl(), btEffectRunCoatlicue(), btEffectRunCondemn(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunDjinniSign(), btEffectRunDragonCloud(), btEffectRunEclipse(), btEffectRunElementCards(), btEffectRunElementPillar(), btEffectRunFire(), btEffectRunFirePuppet(), btEffectRunFlare(), btEffectRunFlora(), btEffectRunFlurry(), btEffectRunFormChange(), btEffectRunFrost(), btEffectRunFroth(), btEffectRunFume(), btEffectRunGaspFamily(), btEffectRunGatheringLights(), btEffectRunGeode(), btEffectRunGeyser(), btEffectRunGround(), btEffectRunHail(), btEffectRunHaunt(), btEffectRunHaures(), btEffectRunHealingMotes(), btEffectRunHeartbreak() and 253 more.

Definition at line 79 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(), btEffectDrawShadedDisc(), btEffectDrawShadedDiscQuarter(), btEffectRunAstralBlast(), btEffectRunAzul(), btEffectRunBackstab(), btEffectRunBind(), btEffectRunBolt(), btEffectRunBreaths(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCoatlicue(), btEffectRunDaedalus(), btEffectRunDeathPlunge(), btEffectRunDiamondBerg(), btEffectRunDjinniCharge(), btEffectRunDjinniSign(), btEffectRunDragonCloud(), btEffectRunEclipse(), btEffectRunElementCards(), btEffectRunFirePuppet(), btEffectRunFlare(), btEffectRunFume(), btEffectRunGaspFamily(), btEffectRunGeyser(), btEffectRunHail(), btEffectRunHaures(), btEffectRunHeavyBlow(), btEffectRunImpactBurst(), btEffectRunIris(), btEffectRunJudgment(), btEffectRunJuggle(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunLeapingStrike(), btEffectRunLegend(), btEffectRunLifeShear(), btEffectRunLightSurge(), btEffectRunLiquifier(), btEffectRunMegaera(), btEffectRunMegiddo(), btEffectRunMeteorBlow(), btEffectRunMoteFountain(), btEffectRunNeptune(), btEffectRunNirvana(), btEffectRunOdyssey(), btEffectRunPlasma(), btEffectRunPlumeEdge(), btEffectRunProcne() and 182 more.

Definition at line 81 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 btEffectRunAtalanta(), btEffectRunBreak(), btEffectRunBurstShower(), btEffectRunCanvasBurst(), btEffectRunCards(), btEffectRunCastingImpact(), btEffectRunCharon(), btEffectRunCool(), btEffectRunCriticalHit(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunEclipse(), btEffectRunElementBurst(), btEffectRunElementPillar(), btEffectRunFallingSword(), btEffectRunFlora(), btEffectRunFlurry(), btEffectRunFormChange(), btEffectRunFrost(), btEffectRunGaspFamily(), btEffectRunHealingMotes(), btEffectRunHelmSplitter(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunLeapingStrike(), btEffectRunLightSurge(), btEffectRunMars(), btEffectRunMercury(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunNereidCopy(), btEffectRunOceanFist(), btEffectRunProcne(), btEffectRunProjectileVolley(), btEffectRunRadiantFire(), btEffectRunRagnarok(), btEffectRunRamses(), btEffectRunSerac(), btEffectRunSparkGroups(), btEffectRunStarSwarm(), btEffectRunStatReduction(), btEffectRunTargetBursts(), btEffectRunTargetMotes(), btEffectRunTargetStrike(), btEffectRunThor(), btEffectRunTrident() and 10 more.

Definition at line 84 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 ActorSpriteFullScale, BattleCameraCommandMatrix, BattleKnockbackAcceleration, BattleKnockbackSpeedLimit, BattleKnockbackVelocityY, btCameraSetRange(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraSetViewAtPairMidpoint(), btEffectDrawShadedDiscQuarter(), btEffectPlaceFormationSprites(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunAzul(), btEffectRunBurstShower(), btEffectRunCards(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCloudSwirl(), btEffectRunCoatlicue(), btEffectRunCondemn(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunCybele(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDjinnHeal(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunDjinniSign(), btEffectRunEclipse(), btEffectRunElementCards(), btEffectRunFallingSword(), btEffectRunFire(), btEffectRunFlora(), btEffectRunFormChange(), btEffectRunFrost(), btEffectRunGaia(), btEffectRunGaspFamily(), btEffectRunGeode(), btEffectRunHaunt(), btEffectRunHaures(), btEffectRunHealingMotes(), btEffectRunHeavyBlow(), btEffectRunImpactBurst(), btEffectRunIris(), btEffectRunJudgment(), btEffectRunLegend() and 548 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(), syMatrixSetRotateY(), 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(), syMatrixSetTranslation(), 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, btEffectRunAtalanta(), btMatrixSetUnit(), CurrentMatrix, syGetMatrix(), syLoadMatrix(), syLookAt(), syMatrixBuildLookAt(), syMatrixRotate(), syMatrixRotateTranslate(), syMatrixRotateTranslateScale(), syMatrixScaleUniform(), syMatrixScaleVector(), syMatrixStoreUnit(), syMatrixTranslateVector(), syMultiMatrix(), syRotX(), syRotY(), syRotZ(), syScale(), syTranslate() 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.