1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-26 21:30:17 +01:00
This commit is contained in:
Miloslav Číž 2019-05-20 17:35:12 +02:00
parent ee5548f1d4
commit 4784993e63
2 changed files with 31 additions and 29 deletions

59
s3l.h
View file

@ -41,8 +41,6 @@
We use row vectors. We use row vectors.
COORDINATE SYSTEMS:
In 3D space, a left-handed coord. system is used. One spatial unit is split In 3D space, a left-handed coord. system is used. One spatial unit is split
into S3L_FRACTIONS_PER_UNIT fractions (fixed point arithmetic). into S3L_FRACTIONS_PER_UNIT fractions (fixed point arithmetic).
@ -69,6 +67,9 @@
| |
| |
Rotations use Euler angles and are generally in the extinsic Euler angles in
ZXY order (by Z, then by X, then by Y).
Coordinates of pixels on screen start typically at the top left, from [0,0]. Coordinates of pixels on screen start typically at the top left, from [0,0].
Triangle rasterization rules are these (mostly same as OpenGL, D3D etc.): Triangle rasterization rules are these (mostly same as OpenGL, D3D etc.):
@ -248,9 +249,9 @@ typedef struct
{ {
S3L_Vec4 translation; S3L_Vec4 translation;
S3L_Vec4 rotation; /**< Euler angles. Rortation is applied in this order: S3L_Vec4 rotation; /**< Euler angles. Rortation is applied in this order:
1. z = around z (roll) CW looking along z+ 1. z = by z (roll) CW looking along z+
2. x = around x (pitch) CW looking along x+ 2. x = by x (pitch) CW looking along x+
3. y = around y (yaw) CW looking along y+ */ 3. y = by y (yaw) CW looking along y+ */
S3L_Vec4 scale; S3L_Vec4 scale;
} S3L_Transform3D; } S3L_Transform3D;
@ -295,15 +296,15 @@ void S3L_makeScaleMatrix(
/** Makes a matrixfor rotation in the ZXY order. */ /** Makes a matrixfor rotation in the ZXY order. */
void S3L_makeRotationMatrixZXY( void S3L_makeRotationMatrixZXY(
S3L_Unit aroundX, S3L_Unit byX,
S3L_Unit aroundY, S3L_Unit byY,
S3L_Unit aroundZ, S3L_Unit byZ,
S3L_Mat4 *m); S3L_Mat4 *m);
void S3L_makeRotationMatrixYXZ( void S3L_makeRotationMatrixYXZ(
S3L_Unit aroundX, S3L_Unit byX,
S3L_Unit aroundY, S3L_Unit byY,
S3L_Unit aroundZ, S3L_Unit byZ,
S3L_Mat4 *m); S3L_Mat4 *m);
void S3L_makeWorldMatrix(S3L_Transform3D worldTransform, S3L_Mat4 *m); void S3L_makeWorldMatrix(S3L_Transform3D worldTransform, S3L_Mat4 *m);
@ -717,18 +718,18 @@ void S3L_makeScaleMatrix(
} }
void S3L_makeRotationMatrixZXY( void S3L_makeRotationMatrixZXY(
S3L_Unit aroundX, S3L_Unit byX,
S3L_Unit aroundY, S3L_Unit byY,
S3L_Unit aroundZ, S3L_Unit byZ,
S3L_Mat4 *m) S3L_Mat4 *m)
{ {
S3L_Unit sx = S3L_sin(aroundX); S3L_Unit sx = S3L_sin(byX);
S3L_Unit sy = S3L_sin(aroundY); S3L_Unit sy = S3L_sin(byY);
S3L_Unit sz = S3L_sin(aroundZ); S3L_Unit sz = S3L_sin(byZ);
S3L_Unit cx = S3L_cos(aroundX); S3L_Unit cx = S3L_cos(byX);
S3L_Unit cy = S3L_cos(aroundY); S3L_Unit cy = S3L_cos(byY);
S3L_Unit cz = S3L_cos(aroundZ); S3L_Unit cz = S3L_cos(byZ);
#define M(x,y) (*m)[x][y] #define M(x,y) (*m)[x][y]
#define S S3L_FRACTIONS_PER_UNIT #define S S3L_FRACTIONS_PER_UNIT
@ -758,18 +759,18 @@ void S3L_makeRotationMatrixZXY(
} }
void S3L_makeRotationMatrixYXZ( void S3L_makeRotationMatrixYXZ(
S3L_Unit aroundX, S3L_Unit byX,
S3L_Unit aroundY, S3L_Unit byY,
S3L_Unit aroundZ, S3L_Unit byZ,
S3L_Mat4 *m) S3L_Mat4 *m)
{ {
S3L_Unit sx = S3L_sin(aroundX); S3L_Unit sx = S3L_sin(byX);
S3L_Unit sy = S3L_sin(aroundY); S3L_Unit sy = S3L_sin(byY);
S3L_Unit sz = S3L_sin(aroundZ); S3L_Unit sz = S3L_sin(byZ);
S3L_Unit cx = S3L_cos(aroundX); S3L_Unit cx = S3L_cos(byX);
S3L_Unit cy = S3L_cos(aroundY); S3L_Unit cy = S3L_cos(byY);
S3L_Unit cz = S3L_cos(aroundZ); S3L_Unit cz = S3L_cos(byZ);
#define M(x,y) (*m)[x][y] #define M(x,y) (*m)[x][y]
#define S S3L_FRACTIONS_PER_UNIT #define S S3L_FRACTIONS_PER_UNIT

View file

@ -35,6 +35,7 @@ features:
- create demos - create demos
- drawModel: create an option that would use a cache to not transform the same - drawModel: create an option that would use a cache to not transform the same
point twice point twice
- Change the rotations to use yaw-pitch-roll instead of extrinsic Euler angles?
bugs: bugs: