Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D.util
Class FXUtil

java.lang.Object
  extended by at.emini.physics2D.util.FXUtil

public class FXUtil
extends java.lang.Object

Utilities for fixpoint math.

The float values postfixed with FX represent decimal numbers: The first 20 bit are before the dot, the least 12 (DECIMAL )bit represent everything after the decimal point. So we have a precision of 2^-12 = 1/4096
Some small values also have "double precision". They are postfixed with 2FX and have 24 lower bits.

Methods with FX in the name (e.g: setValueFX(...), getValueFX(...)) make use of the FX number representation. That applies to both, input parameters and output parameters.

To perform fixpoint arithmetic the following has to be considered: Results from multiplication or division have to be shifted back into the correct place. Here is sample usage of adding, subtracting, multiplying and dividing values: float rFX = aFX + bFX; float rFX = aFX - bFX; float rFX = (((aFX) * ( bFX)) ); float rFX = FXUtil.divideFX(aFX, bFX);

Author:
Alexander Adensamer

Field Summary
static int ADD_MATRIX_DECIMAL
          Additional matrix shift factor.
static int DECIMAL
          Shift Factor for single shifted numbers.
static int DECIMAL2
          Shift Factor for double shifted numbers.
static short[] M_sinMatFX
          Lookup table for sinus calculation.
static float PI_2FX
          Fixpoint Math representation of Pi (2FX).
static float TWO_PI_2FX
          Fixpoint Math representation of 2*Pi (2FX).
 
Constructor Summary
FXUtil()
           
 
Method Summary
static float angleDiffFX(float angle1_2FX, float angle2_2FX)
          Returns the difference of two angles [-PI..PI].
static float angleInDegrees2FX(float angle2FX)
          Returns the angle in degrees
static float divideFX(float aFX, float bFX)
          Division of two fixpoint values.
static float fromFX(float valueFX)
          Converts a fixpoint value to integer
static float multFX(float aFX, float bFX)
          Multiplication of two fixpoint values.
static float toFX(int value)
          Converts a value to fixpoint value (shifting).
static float wrapAngleFX(float angle2FX)
          Wraps an angle into the area [0..2*PI].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_sinMatFX

public static final short[] M_sinMatFX
Lookup table for sinus calculation.
Sample lookup code: int sinFX = FXUtil.sinMatFX[rotation2FX >> 16];


DECIMAL

public static final int DECIMAL
Shift Factor for single shifted numbers.

See Also:
Constant Field Values

DECIMAL2

public static final int DECIMAL2
Shift Factor for double shifted numbers.

See Also:
Constant Field Values

ADD_MATRIX_DECIMAL

public static final int ADD_MATRIX_DECIMAL
Additional matrix shift factor.

See Also:
Constant Field Values

PI_2FX

public static final float PI_2FX
Fixpoint Math representation of Pi (2FX).
The value computes to ~ 3.141592.

See Also:
Constant Field Values

TWO_PI_2FX

public static final float TWO_PI_2FX
Fixpoint Math representation of 2*Pi (2FX).

See Also:
Constant Field Values
Constructor Detail

FXUtil

public FXUtil()
Method Detail

wrapAngleFX

public static float wrapAngleFX(float angle2FX)
Wraps an angle into the area [0..2*PI].

Parameters:
angle2FX - the original angle(2FX).
Returns:
the wrapped angle (2FX).

angleDiffFX

public static float angleDiffFX(float angle1_2FX,
                                float angle2_2FX)
Returns the difference of two angles [-PI..PI].

Parameters:
angle1_2FX - first angle (2FX).
angle2_2FX - second angle (2FX).
Returns:
the angle between them (2FX).

angleInDegrees2FX

public static float angleInDegrees2FX(float angle2FX)
Returns the angle in degrees

Parameters:
angle2FX - angle to convert (2FX).
Returns:
the angle converted to degrees.

multFX

public static float multFX(float aFX,
                           float bFX)
Multiplication of two fixpoint values.

Parameters:
aFX - value a to multiply (FX).
bFX - value b to multiply (FX).
Returns:
the product (FX).

divideFX

public static float divideFX(float aFX,
                             float bFX)
Division of two fixpoint values.

Parameters:
aFX - value a to multiply (FX).
bFX - value b to multiply (FX).
Returns:
the result of the division (FX).

toFX

public static float toFX(int value)
Converts a value to fixpoint value (shifting).

Parameters:
value - the value to convert.
Returns:
the fixpoint value (FX).

fromFX

public static float fromFX(float valueFX)
Converts a fixpoint value to integer

Parameters:
valueFX - the fixpoint value (FX)
Returns:
the integer value

Emini Physics Engine 1.3.5a API Documentation

Emini Physics Engine 1.3.5a API Documentation - Copyright 2014 Alexander Adensamer