diff --git a/small3dlib.h b/small3dlib.h index 2bcf90b..fd45da5 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -371,6 +371,18 @@ typedef struct static inline void S3L_initTransoform3D(S3L_Transform3D *t); +void S3L_setTransform3D( + S3L_Unit tx, + S3L_Unit ty, + S3L_Unit tz, + S3L_Unit rx, + S3L_Unit ry, + S3L_Unit rz, + S3L_Unit sx, + S3L_Unit sy, + S3L_Unit sz, + S3L_Transform3D *t); + /** Converts rotation transformation to three direction vectors of given length (any one can be NULL, in which case it won't be computed). */ void S3L_rotationToDirections( @@ -447,7 +459,11 @@ static inline void S3L_initCamera(S3L_Camera *c); typedef struct { - uint8_t backfaceCulling; + uint8_t backfaceCulling; /**< What backface culling to use. Possible + values: + - 0 none + - 1 clock-wise + - 2 counter clock-wise */ } S3L_DrawConfig; void S3L_initDrawConfig(S3L_DrawConfig *config); @@ -489,10 +505,6 @@ typedef struct static inline void S3L_initPixelInfo(S3L_PixelInfo *p); -#define S3L_BACKFACE_CULLING_NONE 0 -#define S3L_BACKFACE_CULLING_CW 1 -#define S3L_BACKFACE_CULLING_CCW 2 - // general helper functions static inline S3L_Unit S3L_abs(S3L_Unit value); static inline S3L_Unit S3L_min(S3L_Unit v1, S3L_Unit v2); @@ -1001,6 +1013,31 @@ void S3L_initTransoform3D(S3L_Transform3D *t) t->scale.z = S3L_FRACTIONS_PER_UNIT; } +void S3L_setTransform3D( + S3L_Unit tx, + S3L_Unit ty, + S3L_Unit tz, + S3L_Unit rx, + S3L_Unit ry, + S3L_Unit rz, + S3L_Unit sx, + S3L_Unit sy, + S3L_Unit sz, + S3L_Transform3D *t) +{ + t->translation.x = tx; + t->translation.y = ty; + t->translation.z = tz; + + t->rotation.x = rx; + t->rotation.y = ry; + t->rotation.z = rz; + + t->scale.x = sx; + t->scale.y = sy; + t->scale.z = sz; +} + void S3L_initCamera(S3L_Camera *c) { c->focalLength = S3L_FRACTIONS_PER_UNIT; @@ -1733,13 +1770,13 @@ static inline int8_t S3L_triangleIsVisible( #undef clipTest - if (backfaceCulling != S3L_BACKFACE_CULLING_NONE) + if (backfaceCulling != 0) { int32_t winding = // determines CW or CCW (p1.y - p0.y) * (p2.x - p1.x) - (p1.x - p0.x) * (p2.y - p1.y); - if ((backfaceCulling == S3L_BACKFACE_CULLING_CW && winding < 0) || - (backfaceCulling == S3L_BACKFACE_CULLING_CCW && winding >= 0)) + if ((backfaceCulling == 1 && winding < 0) || + (backfaceCulling == 2 && winding >= 0)) return 0; } diff --git a/testSDL.c b/testSDL.c index 6aa27fa..b4bdec7 100644 --- a/testSDL.c +++ b/testSDL.c @@ -251,6 +251,9 @@ void draw() { nextT = nowT; printf("FPS: %d\n",fps); + + printf("camera: "); + S3L_writeTransform3D(scene.camera.transform); fps = 0; } } @@ -277,6 +280,8 @@ scene.camera.transform.rotation.x = -35; scene.camera.transform.rotation.y = 128; scene.camera.transform.rotation.z = 0; +S3L_setTransform3D(-542,-449,3259,39,216,0,512,512,512,&(scene.camera.transform)); + scene.modelCount = 2; scene.models = models;