sparrowDefines

SparrowDefines contains many #defines used by the library or which may be usefull for your application

Summary
sparrowDefinesSparrowDefines contains many #defines used by the library or which may be usefull for your application
Macros
Fixed Point Arithmetic ConstantsThe following #defines are for the fixed point arithmetic in sparrow3d.
Fixed Point ArithmeticsThese are some #defines for fast multiplication and division of fixed point numbers.
Fixed Point ConversionThese conversions are no function calls, but defines.
Generic ButtonsThe following (long) list of #defines gives you the numbers and names of the generic device buttons or of the buttons on the explicit device.
Generic Buttons Names
Generic Buttons MasksMask of the buttons, Useful for spPollKeyboardInputs last parameter.
DirectionsThese are some #defines e.g.
SP_NO_TOUCHSCREEN_EMULATIONUsed by spSetTouchscreenEmulationButtons
SP_ALPHA_COLORIf alphatest is enabled, this (pink) color will not be drawn, it is “transparent”.
SP_DEVICE_STRINGGives you the name of the device, e.g.

Macros

Fixed Point Arithmetic Constants

The following #defines are for the fixed point arithmetic in sparrow3d.  Change the values only, if you know, what you are doing.  There should be optimal already.

SP_ACCURACYDefines how many bits are used for the decimal place
SP_HALF_ACCURACYThe half of SP_ACCURACY
SP_ACCURACY_FACTOR2 ^ SP_ACCURACY.  Needed for float conversation
SP_SQRT_ACCURACYAccurary of the internal sqrt lookuptable
SP_PIFixed point Pi
SP_MATH_ACCURACY(In)accuracy of the cos and sin lookup table
SP_ONE1.0f in fixed point

Fixed Point Arithmetics

These are some #defines for fast multiplication and division of fixed point numbers.  Use them like normal functions, e.g.  Sint32 a = spMul(b,c); instead of a = b * c (which will not work).  However multiplying a fixed point number with a “normal” integer just works with the normal multiplication.  For addition you have to convert!

spMul(a,b)Multiplies fixed point number a with the fixed point number b
spMulHigh(a,b)Does the same as spMul(a,b), but with guaranteed high precision
spMulLow(a,b)Does the same as spMul(a,b), but maybe with lower precision
spDiv(a,b)Divides fixed point number a with the fixed point number b
spDivHigh(a,b)Does the same as spDiv(a,b), but with guaranteed high precision
spDivLow(a,b)Does the same as spDiv(a,b), but maybe with lower precision
spSquare(a)Squares the fixed point number a with the help of spMul(a,b).

Fixed Point Conversion

These conversions are no function calls, but defines.  That means before the compiler compiles the code, it is replaced by the defined rule.  E.g., you want to convert the float a to a fixed point number using spFloatToFixed.  You call

Sint32 foo = spFloatToFixed(bar);

Internal the compiler will make this:

Sint32 foo = ((Sint32)((float)(bar)*SP_ACCURACY_FACTOR));

This saves you a function call.  But it gets MUCH cheaper, if you don’t have a float variable as parameter, but a number like 1.5f.  Example:

Sint32 foo = spFloatToFixed(1.5);

will become to:

Sint32 foo = ((Sint32)((float)(1.5f)*SP_ACCURACY_FACTOR));

As no unknown parameter is in this equation the compiler will calculate it at compile time, which means: In you final binary, the (binary) code will just be:

Sint32 foo = 98304;

which is obviouly incredible fast.

spFixedToFloat(x)converts the fixed point number a to a float
spFloatToFixed(x)converts the float a to a fixed point number
spIntToFixed(x)converts the int x to a fixed point number
spFixedToInt(x)converts the fixed point number x to an int with cutting of the decimal place.
spFixedRoundInt(x)converts the fixed point number x with round to an int

Generic Buttons

The following (long) list of #defines gives you the numbers and names of the generic device buttons or of the buttons on the explicit device.  The Dingoo e.g. has the A button on the right, but GP2X and others on the left.  That means: If you want the button with the CAPTION “A” use SP_BUTTON_A, but if you want the LEFT Button on every device use SP_BUTTON_LEFT, which will be SP_BUTTON_A on the gp2x or SP_BUTTON_Y on the Dingoo.  The same for the names.  Buttons like SP_BUTTON_L or similar are defined just one time - because they are the same on every device.

SP_BUTTON_STARTnumber of the “Start” or “Menu” button
SP_BUTTON_SELECTnumber of the “Select”, “||” or similar button
SP_BUTTON_Lnumber of the left shoulder button
SP_BUTTON_Rnumber of the right shoulder button
SP_BUTTON_Anumber of the A button.  On every device at another position!
SP_BUTTON_Bnumber of the B button.  On every device at another position!
SP_BUTTON_Xnumber of the X button.  On every device at another position!
SP_BUTTON_Ynumber of the Y button.  On every device at another position!
SP_BUTTON_LEFTnumber of the left button.  On every device at the same position!
SP_BUTTON_RIGHTnumber of the right button.  On every device at the same position!
SP_BUTTON_UPnumber of the up button.  On every device at the same position!
SP_BUTTON_DOWNnumber of the down button.  On every device at the same position!
SP_PRACTICE_OKnumber of the button, which is on the specific device the standard button for “ok”.
SP_PRACTICE_CANCELnumber of the button, which is on the specific device
SP_PRACTICE_3number of the button, which is on the specific device the neither ok nor cancel.
SP_PRACTICE_4number of the other button, which is on the specific device neither ok nor cancel.

Generic Buttons Names

SP_BUTTON_START_NAMEname of the “Start” or “Menu” button
SP_BUTTON_SELECT_NAMEname of the “Select”, “||” or similar button
SP_BUTTON_L_NAMEname of the left shoulder button
SP_BUTTON_R_NAMEname of the right shoulder button
SP_BUTTON_A_NAMEname of the A button.
SP_BUTTON_B_NAMEname of the B button.
SP_BUTTON_X_NAMEname of the X button.
SP_BUTTON_Y_NAMEname of the Y button.
SP_BUTTON_LEFT_NAMEname of the left button.
SP_BUTTON_RIGHT_NAMEname of the right button.
SP_BUTTON_UP_NAMEname of the up button.
SP_BUTTON_DOWN_NAMEname of the down button.
SP_PAD_NAMEname of the pad (e.g.  “Arrows keys” on the PC)
SP_PRACTICE_OK_NAMEname of the button, which is on the specific device the standard button for “ok”.
SP_PRACTICE_CANCEL_NAMEname of the button, which is on the specific device the standard button for canceling an action.
SP_PRACTICE_3_NAMEname of the button, which is on the specific device the neither ok nor cancel.
SP_PRACTICE_4_NAMEname of the other button, which is on the specific device neither ok nor cancel

Generic Buttons Masks

Mask of the buttons, Useful for spPollKeyboardInputs last parameter.

SP_BUTTON_START_MASKmask of the “Start” or “Menu” button
SP_BUTTON_SELECT_MASKmask of the “Select”, “||” or similar button
SP_BUTTON_L_MASKmask of the left shoulder button
SP_BUTTON_R_MASKmask of the right shoulder button
SP_BUTTON_A_MASKmask of the A button.
SP_BUTTON_B_MASKmask of the B button.
SP_BUTTON_X_MASKmask of the X button.
SP_BUTTON_Y_MASKmask of the Y button.
SP_BUTTON_LEFT_MASKmask of the left button.
SP_BUTTON_RIGHT_MASKmask of the right button.
SP_BUTTON_UP_MASKmask of the up button.
SP_BUTTON_DOWN_MASKmask of the down button.
SP_PRACTICE_OK_MASKmask of the button, which is on the specific device the standard button for “ok”.
SP_PRACTICE_CANCEL_MASKmask of the button, which is on the specific device the standard button for canceling an action.
SP_PRACTICE_3_MASKmask of the button, which is on the specific device the neither ok nor cancel.
SP_PRACTICE_4_MASKmask of the other button, which is on the specific device neither ok nor cancel.

Directions

These are some #defines e.g. for sparrowPrimitives to determine, where the base of the drawn primitive is.

SP_CENTERcenter
SP_LEFTleft
SP_TOPtop
SP_RIGHTright
SP_BOTTOMbottom
SP_FIXEDsets the base to a fixed position

SP_NO_TOUCHSCREEN_EMULATION

SP_ALPHA_COLOR

If alphatest is enabled, this (pink) color will not be drawn, it is “transparent”.

SP_DEVICE_STRING

Gives you the name of the device, e.g.  “GP2X F100” or “Personal Computer”

PREFIX void spPollKeyboardInput(char *buffer,
int bufferSize,
Sint32 enter_key_mask)
Prints all following keyboard input (that is numbers, letters and symbols) into the passed buffer.
PREFIX void spSetTouchscreenEmulationButtons(int switch_button,
int ok_button)
Sets, whether on systems without touchscreen or mouse (like the GP2X F100) a touchscreen is emulated.
Defines how many bits are used for the decimal place
Multiplies fixed point number a with the fixed point number b
Divides fixed point number a with the fixed point number b
Close