SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
maths3D.h File Reference

3D math engine. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Vect3D_u16
 3D Vector structure - u16 type. More...
 
struct  Vect3D_s16
 3D Vector structure - s16 type. More...
 
struct  Vect3D_u32
 3D Vector structure - u32 type. More...
 
struct  Vect3D_s32
 3D Vector structure - s32 type. More...
 
struct  Vect3D_f16
 3D Vector structure - f16 (fix16) type. More...
 
struct  Vect3D_f32
 3D Vector structure - f32 (fix32) type. More...
 
struct  Mat3D_f16
 3x3 Matrice structure - f16 (fix16) type.
Internally uses 3 3D vectors. More...
 
struct  Mat3D_f32
 3x3 Matrice structure - f32 (fix32) type.
Internally uses 3 3D vectors. More...
 
struct  Vect4D_f16
 4D Vector structure - f16 (fix16) type. More...
 
struct  Vect4D_f32
 4D Vector structure - f32 (fix32) type. More...
 
struct  Mat4D_f16
 4x4 Matrice structure - f16 (fix16) type.
Internally uses 4 4D vectors. More...
 
struct  Mat4D_f32
 4x4 Matrice structure - f32 (fix32) type.
Internally uses 4 4D vectors. More...
 
struct  Context3D
 Structure hosting settings / context for the 3D transform engine. More...
 
struct  Transformation3D
 3D transformation object - f16 (fix16) type.
This object define the global 3D transformation informations and associated cached data.
If rotation information is modified the rebuildMat flag should be set to 1.
Rotation and translation objects are reference so don't forget to set them. More...
 

Typedefs

typedef Vect3D_u16 V3u16
 alias for Vect3D_u16
 
typedef Vect3D_s16 V3s16
 alias for Vect3D_s16
 
typedef Vect3D_u32 V3u32
 alias for Vect3D_u32
 
typedef Vect3D_s32 V3s32
 alias for Vect3D_s32
 
typedef Vect3D_f16 V3f16
 alias for Vect3D_f16
 
typedef Vect3D_f32 V3f32
 alias for Vect3D_f32
 
typedef Vect4D_f16 V4f16
 alias for Vect4D_f16
 
typedef Vect4D_f32 V4f32
 alias for Vect4D_f32
 
typedef Mat3D_f16 M3f16
 alias for Mat3D_f16
 
typedef Mat3D_f32 M3f32
 alias for Mat3D_f32
 
typedef Mat4D_f16 M4f16
 alias for Mat4D_f16
 
typedef Mat4D_f32 M4f32
 alias for Mat4D_f32
 
typedef V3f16 Translation3D
 3D translation informations object - f16 (fix16) type.
 
typedef V3f16 Rotation3D
 3D rotation informations object (angles are stored in degree) - f16 (fix16) type.
 

Functions

void M3D_reset (void)
 Reset math 3D engine (reset matrices and transformation parameters mainly).
 
void M3D_setLightEnabled (u16 enabled)
 Enable or disable light transformation calculation.
 
u16 M3D_getLightEnabled (void)
 Get light transformation calculation enabled flag.
 
void M3D_setViewport (u16 w, u16 h)
 Set viewport dimension.
 
void M3D_setCamDistance (fix16 value)
 Set camera scene distance.
 
void M3D_setLightXYZ (fix16 x, fix16 y, fix16 z)
 Set light direction vector.
 
void M3D_setLight (V3f16 *value)
 Set light direction vector.
 
void M3D_resetTransform (Transformation3D *t)
 Reset the specified Transformation3D object.
 
void M3D_setTransform (Transformation3D *tr, Translation3D *t, Rotation3D *r)
 Set translation and rotation objects to the specified transformation object.
 
void M3D_setTranslation (Transformation3D *t, fix16 x, fix16 y, fix16 z)
 Set translation parameters to the specified transformation object.
 
void M3D_setRotation (Transformation3D *t, fix16 x, fix16 y, fix16 z)
 Set rotation parameters to the specified Transformation3D object.
x, y, z angle values are given in degree (fix16)
 
void M3D_combineTransform (Transformation3D *left, Transformation3D *right, Transformation3D *result)
 Combine the specified right and left Transformation3D objects and store result in result. result cannot be the same transformation object as left or right.
 
void M3D_combineTranslationLeft (Translation3D *left, Transformation3D *right, Transformation3D *result)
 Combine the specified left Translation3D and right Transformation3D and store result in result.
right and result transformation object can be the same.
 
void M3D_combineTranslationRight (Transformation3D *left, Translation3D *right, Transformation3D *result)
 Combine the specified left Transformation3D with right Translation3D and store result in result.
left and result transformation object can be the same.
 
void M3D_buildMat3D (Transformation3D *t)
 Build the transformation matrix of the specified Transformation3D object.
This also rebuild cached informations as inverse transformation matrix, inverse camera view...
 
void M3D_buildMat3DOnly (Transformation3D *t)
 Build the transformation matrix of the specified transformation object. Only rebuild the transformation matrix (faster), cached infos as inverse matrix are not rebuild.
 
void M3D_buildMat3DExtras (Transformation3D *t)
 Only rebuild the cached infos as inverse matrix, inverse camera view...
 
void M3D_translate (Transformation3D *t, V3f16 *vertices, u16 numv)
 Process 3D translation only to specified 3D vertices buffer.
 
void M3D_rotate (Transformation3D *t, const V3f16 *src, V3f16 *dest, u16 numv)
 Process 3D rotation only to specified 3D vertices buffer.
 
void M3D_rotateInv (Transformation3D *t, const V3f16 *src, V3f16 *dest)
 Process 3D inverse rotation only to specified 3D vertex.
 
void M3D_transform (Transformation3D *t, const V3f16 *src, V3f16 *dest, u16 numv)
 Process 3D transform (rotation and translation) to specified 3D vertices buffer.
 
void M3D_project_f16 (const V3f16 *src, V2f16 *dest, u16 numv)
 Process 2D projection to specified 3D vertices buffer (fix16 version).
 
void M3D_project_s16 (const V3f16 *src, V2s16 *dest, u16 numv)
 Process 2D projection to specified 3D vertices buffer (s16 version).
 

Detailed Description

3D math engine.

Author
Stephane Dallongeville
Date
08/2011

This unit provides 3D transformation methods :

  • translation X, Y, Z
  • rotation X, Y, Z
  • one directionnal light
  • 2D projection

    Can transform (including 2D projection) about ~10000 vertices / seconde.

Function Documentation

◆ M3D_buildMat3D()

void M3D_buildMat3D ( Transformation3D * t)

Build the transformation matrix of the specified Transformation3D object.
This also rebuild cached informations as inverse transformation matrix, inverse camera view...

Parameters
tTransformation3D object.

◆ M3D_buildMat3DExtras()

void M3D_buildMat3DExtras ( Transformation3D * t)

Only rebuild the cached infos as inverse matrix, inverse camera view...

Parameters
tTransformation object.

◆ M3D_buildMat3DOnly()

void M3D_buildMat3DOnly ( Transformation3D * t)

Build the transformation matrix of the specified transformation object. Only rebuild the transformation matrix (faster), cached infos as inverse matrix are not rebuild.

Parameters
tTransformation object.

◆ M3D_combineTransform()

void M3D_combineTransform ( Transformation3D * left,
Transformation3D * right,
Transformation3D * result )

Combine the specified right and left Transformation3D objects and store result in result. result cannot be the same transformation object as left or right.

Parameters
leftLeft Transformation3D object.
rightRight Transformation3D object.
resultResult Transformation3D object.

◆ M3D_combineTranslationLeft()

void M3D_combineTranslationLeft ( Translation3D * left,
Transformation3D * right,
Transformation3D * result )

Combine the specified left Translation3D and right Transformation3D and store result in result.
right and result transformation object can be the same.

Parameters
leftLeft Transformation3D object.
rightRight Transformation3D object.
resultResult Transformation3D object.

◆ M3D_combineTranslationRight()

void M3D_combineTranslationRight ( Transformation3D * left,
Translation3D * right,
Transformation3D * result )

Combine the specified left Transformation3D with right Translation3D and store result in result.
left and result transformation object can be the same.

Parameters
leftLeft Transformation3D object.
rightRight Translation3D object.
resultResult Transformation3D object.

◆ M3D_project_f16()

void M3D_project_f16 ( const V3f16 * src,
V2f16 * dest,
u16 numv )

Process 2D projection to specified 3D vertices buffer (fix16 version).

Parameters
srcSource 3D vertices buffer.
destDestination 2D vertices buffer - fix16 format
numvNumber of vertices to project.

◆ M3D_project_s16()

void M3D_project_s16 ( const V3f16 * src,
V2s16 * dest,
u16 numv )

Process 2D projection to specified 3D vertices buffer (s16 version).

Parameters
srcSource 3D vertices buffer.
destDestination 2D vertices buffer - s16 format
numvNumber of vertices to project.

◆ M3D_rotate()

void M3D_rotate ( Transformation3D * t,
const V3f16 * src,
V3f16 * dest,
u16 numv )

Process 3D rotation only to specified 3D vertices buffer.

Parameters
tTransformation object containing rotation parameter.
srcSource 3D vertices buffer.
destDestination 3D vertices buffer.
numvNumber of vertices to rotate.

◆ M3D_rotateInv()

void M3D_rotateInv ( Transformation3D * t,
const V3f16 * src,
V3f16 * dest )

Process 3D inverse rotation only to specified 3D vertex.

Parameters
tTransformation object containing rotation parameter.
srcSource 3D vertex.
destDestination 3D vertex.

◆ M3D_setCamDistance()

void M3D_setCamDistance ( fix16 value)

Set camera scene distance.

Parameters
valueDistance between the camera and the scene.

◆ M3D_setViewport()

void M3D_setViewport ( u16 w,
u16 h )

Set viewport dimension.

Parameters
wViewport width (use BMP_WIDTH if you use 3D with software bitmap engine)
hViewport height (use BMP_HEIGHT if you use 3D with software bitmap engine)

◆ M3D_transform()

void M3D_transform ( Transformation3D * t,
const V3f16 * src,
V3f16 * dest,
u16 numv )

Process 3D transform (rotation and translation) to specified 3D vertices buffer.

Parameters
tTransformation object containing rotation and translation parameters.
srcSource 3D vertices buffer.
destDestination 3D vertices buffer.
numvNumber of vertices to transform.

◆ M3D_translate()

void M3D_translate ( Transformation3D * t,
V3f16 * vertices,
u16 numv )

Process 3D translation only to specified 3D vertices buffer.

Parameters
tTransformation object containing translation parameter.
vertices3D vertices buffer to translate.
numvNumber of vertices to translate.