mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Add model transform
This commit is contained in:
parent
360df9fe83
commit
4f14e1e1cb
1 changed files with 23 additions and 11 deletions
32
s3l.h
32
s3l.h
|
@ -284,7 +284,8 @@ void S3L_drawTriangle(
|
||||||
S3L_ScreenCoord x0, S3L_ScreenCoord y0,
|
S3L_ScreenCoord x0, S3L_ScreenCoord y0,
|
||||||
S3L_ScreenCoord x1, S3L_ScreenCoord y1,
|
S3L_ScreenCoord x1, S3L_ScreenCoord y1,
|
||||||
S3L_ScreenCoord x2, S3L_ScreenCoord y2,
|
S3L_ScreenCoord x2, S3L_ScreenCoord y2,
|
||||||
S3L_DrawConfig config)
|
S3L_DrawConfig config,
|
||||||
|
S3L_Index triangleID)
|
||||||
{
|
{
|
||||||
if (config.backfaceCulling != S3L_BACKFACE_CULLING_NONE)
|
if (config.backfaceCulling != S3L_BACKFACE_CULLING_NONE)
|
||||||
{
|
{
|
||||||
|
@ -298,6 +299,7 @@ void S3L_drawTriangle(
|
||||||
|
|
||||||
S3L_PixelInfo p;
|
S3L_PixelInfo p;
|
||||||
S3L_initPixelInfo(&p);
|
S3L_initPixelInfo(&p);
|
||||||
|
p.triangleID = triangleID;
|
||||||
|
|
||||||
// point mode
|
// point mode
|
||||||
|
|
||||||
|
@ -555,6 +557,14 @@ void S3L_drawTriangle(
|
||||||
#undef stepSide
|
#undef stepSide
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void S3L_mapModelToWorld(S3L_Vec3 point,
|
||||||
|
S3L_Transform3D *modelTransform, S3L_Vec3 *newPoint)
|
||||||
|
{
|
||||||
|
newPoint->x = point.x + modelTransform->offset.x;
|
||||||
|
newPoint->y = point.y + modelTransform->offset.y;
|
||||||
|
newPoint->z = point.z + modelTransform->offset.z;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void S3L_mapWorldToCamera(S3L_Vec3 point,
|
static inline void S3L_mapWorldToCamera(S3L_Vec3 point,
|
||||||
S3L_Transform3D *cameraTransform, S3L_Vec3 *newPoint)
|
S3L_Transform3D *cameraTransform, S3L_Vec3 *newPoint)
|
||||||
{
|
{
|
||||||
|
@ -578,34 +588,36 @@ void S3L_drawModel(
|
||||||
const S3L_Unit coords[],
|
const S3L_Unit coords[],
|
||||||
const S3L_Index triangleVertexIndices[],
|
const S3L_Index triangleVertexIndices[],
|
||||||
uint16_t triangleCount,
|
uint16_t triangleCount,
|
||||||
|
S3L_Transform3D modelTransform,
|
||||||
S3L_Camera camera,
|
S3L_Camera camera,
|
||||||
S3L_DrawConfig config)
|
S3L_DrawConfig config)
|
||||||
{
|
{
|
||||||
S3L_Index triangleIndex = 0;
|
S3L_Index triangleIndex = 0;
|
||||||
S3L_Index coordIndex = 0;
|
S3L_Index coordIndex = 0;
|
||||||
|
|
||||||
while (triangleIndex < triangleCount)
|
|
||||||
{
|
|
||||||
S3L_ScreenCoord sX0, sY0, sX1, sY1, sX2, sY2;
|
S3L_ScreenCoord sX0, sY0, sX1, sY1, sX2, sY2;
|
||||||
S3L_Vec3 point, point2;
|
S3L_Vec3 pointModel, pointWorld, pointCamera;
|
||||||
S3L_Unit indexIndex;
|
S3L_Unit indexIndex;
|
||||||
|
|
||||||
|
while (triangleIndex < triangleCount)
|
||||||
|
{
|
||||||
#define mapCoords(n)\
|
#define mapCoords(n)\
|
||||||
indexIndex = triangleVertexIndices[coordIndex] * 3;\
|
indexIndex = triangleVertexIndices[coordIndex] * 3;\
|
||||||
point.x = coords[indexIndex];\
|
pointModel.x = coords[indexIndex];\
|
||||||
++indexIndex; /* TODO: put into square brackets? */\
|
++indexIndex; /* TODO: put into square brackets? */\
|
||||||
point.y = coords[indexIndex];\
|
pointModel.y = coords[indexIndex];\
|
||||||
++indexIndex;\
|
++indexIndex;\
|
||||||
point.z = coords[indexIndex];\
|
pointModel.z = coords[indexIndex];\
|
||||||
++coordIndex;\
|
++coordIndex;\
|
||||||
S3L_mapWorldToCamera(point,&camera.transform,&point2);\
|
S3L_mapModelToWorld(pointModel,&modelTransform,&pointWorld);\
|
||||||
S3L_mapCameraToScreen(point2,&camera,&sX##n,&sY##n);
|
S3L_mapWorldToCamera(pointWorld,&camera.transform,&pointCamera);\
|
||||||
|
S3L_mapCameraToScreen(pointCamera,&camera,&sX##n,&sY##n);
|
||||||
|
|
||||||
mapCoords(0)
|
mapCoords(0)
|
||||||
mapCoords(1)
|
mapCoords(1)
|
||||||
mapCoords(2)
|
mapCoords(2)
|
||||||
|
|
||||||
S3L_drawTriangle(sX0,sY0,sX1,sY1,sX2,sY2,config);
|
S3L_drawTriangle(sX0,sY0,sX1,sY1,sX2,sY2,config,triangleIndex);
|
||||||
|
|
||||||
++triangleIndex;
|
++triangleIndex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue