mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Continue PC
This commit is contained in:
parent
1f0aa51429
commit
438c4d7db3
2 changed files with 51 additions and 35 deletions
78
s3l.h
78
s3l.h
|
@ -116,7 +116,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef S3L_PERSPECTIVE_CORRECTION
|
#ifndef S3L_PERSPECTIVE_CORRECTION
|
||||||
#define S3L_PERSPECTIVE_CORRECTION 0
|
#define S3L_PERSPECTIVE_CORRECTION 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define S3L_HALF_RESOLUTION_X (S3L_RESOLUTION_X >> 1)
|
#define S3L_HALF_RESOLUTION_X (S3L_RESOLUTION_X >> 1)
|
||||||
|
@ -847,6 +847,8 @@ void _S3L_drawFilledTriangle(
|
||||||
S3L_Unit *barycentric1; // bar. coord that gets higher from R to L
|
S3L_Unit *barycentric1; // bar. coord that gets higher from R to L
|
||||||
S3L_Unit *barycentric2; // bar. coord that gets higher from bottom up
|
S3L_Unit *barycentric2; // bar. coord that gets higher from bottom up
|
||||||
|
|
||||||
|
printf("-------\n");
|
||||||
|
|
||||||
// Sort the points.
|
// Sort the points.
|
||||||
|
|
||||||
#define assignPoints(t,a,b)\
|
#define assignPoints(t,a,b)\
|
||||||
|
@ -948,8 +950,8 @@ void _S3L_drawFilledTriangle(
|
||||||
lErrSub, rErrSub; // error value to substract when moving in x direction
|
lErrSub, rErrSub; // error value to substract when moving in x direction
|
||||||
|
|
||||||
S3L_Unit
|
S3L_Unit
|
||||||
lSideUnitStep, rSideUnitStep,
|
lSideStep, rSideStep,
|
||||||
lSideUnitPos, rSideUnitPos;
|
lSideUnitPosScaled, rSideUnitPosScaled;
|
||||||
|
|
||||||
/* init side for the algorithm, params:
|
/* init side for the algorithm, params:
|
||||||
s - which side (l or r)
|
s - which side (l or r)
|
||||||
|
@ -961,13 +963,13 @@ void _S3L_drawFilledTriangle(
|
||||||
s##X = p1##PointSx;\
|
s##X = p1##PointSx;\
|
||||||
s##Dx = p2##PointSx - p1##PointSx;\
|
s##Dx = p2##PointSx - p1##PointSx;\
|
||||||
s##Dy = p2##PointSy - p1##PointSy;\
|
s##Dy = p2##PointSy - p1##PointSy;\
|
||||||
s##SideUnitStep = (S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY)\
|
s##SideStep = (S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY)\
|
||||||
/ (s##Dy != 0 ? s##Dy : 1);\
|
/ (s##Dy != 0 ? s##Dy : 1);\
|
||||||
s##SideUnitPos = 0;\
|
s##SideUnitPosScaled = 0;\
|
||||||
if (!down)\
|
if (!down)\
|
||||||
{\
|
{\
|
||||||
s##SideUnitPos = S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY;\
|
s##SideUnitPosScaled = S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY;\
|
||||||
s##SideUnitStep *= -1;\
|
s##SideStep *= -1;\
|
||||||
}\
|
}\
|
||||||
s##Inc = s##Dx >= 0 ? 1 : -1;\
|
s##Inc = s##Dx >= 0 ? 1 : -1;\
|
||||||
if (s##Dx < 0)\
|
if (s##Dx < 0)\
|
||||||
|
@ -1002,6 +1004,8 @@ void _S3L_drawFilledTriangle(
|
||||||
|
|
||||||
#if S3L_PERSPECTIVE_CORRECTION == 1
|
#if S3L_PERSPECTIVE_CORRECTION == 1
|
||||||
S3L_PerspectiveCorrectionState lPC, rPC, rowPC;
|
S3L_PerspectiveCorrectionState lPC, rPC, rowPC;
|
||||||
|
int8_t topPart = 1; // whether drawing top or bottom part of the triangle
|
||||||
|
|
||||||
initPC(t,l,l)
|
initPC(t,l,l)
|
||||||
initPC(t,r,r)
|
initPC(t,r,r)
|
||||||
#endif
|
#endif
|
||||||
|
@ -1017,17 +1021,21 @@ void _S3L_drawFilledTriangle(
|
||||||
S3L_Unit *tmp = barycentric##b0;\
|
S3L_Unit *tmp = barycentric##b0;\
|
||||||
barycentric##b0 = barycentric##b1;\
|
barycentric##b0 = barycentric##b1;\
|
||||||
barycentric##b1 = tmp;\
|
barycentric##b1 = tmp;\
|
||||||
s##SideUnitPos =\
|
s##SideUnitPosScaled =\
|
||||||
(S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY) - s##SideUnitPos;\
|
(S3L_FRACTIONS_PER_UNIT << S3L_LERP_QUALITY) - s##SideUnitPosScaled;\
|
||||||
s##SideUnitStep *= -1;
|
s##SideStep *= -1;
|
||||||
|
|
||||||
if (splitOnLeft)
|
if (splitOnLeft)
|
||||||
{
|
{
|
||||||
initSide(l,l,r,0);
|
initSide(l,l,r,0);
|
||||||
manageSplit(0,2,r)
|
manageSplit(0,2,r)
|
||||||
|
|
||||||
|
printf("split L\n");
|
||||||
|
|
||||||
#if S3L_PERSPECTIVE_CORRECTION == 1
|
#if S3L_PERSPECTIVE_CORRECTION == 1
|
||||||
initPC(l,r,l)
|
initPC(l,r,l)
|
||||||
|
initPC(r,t,r)
|
||||||
|
topPart = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1035,8 +1043,12 @@ void _S3L_drawFilledTriangle(
|
||||||
initSide(r,r,l,0);
|
initSide(r,r,l,0);
|
||||||
manageSplit(1,2,l)
|
manageSplit(1,2,l)
|
||||||
|
|
||||||
|
printf("split R\n");
|
||||||
|
|
||||||
#if S3L_PERSPECTIVE_CORRECTION == 1
|
#if S3L_PERSPECTIVE_CORRECTION == 1
|
||||||
initPC(r,l,r)
|
initPC(r,l,r)
|
||||||
|
initPC(l,t,l)
|
||||||
|
topPart = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1050,22 +1062,17 @@ void _S3L_drawFilledTriangle(
|
||||||
|
|
||||||
S3L_Unit rowLength = S3L_nonZero(rX - lX - 1); // prevent zero div
|
S3L_Unit rowLength = S3L_nonZero(rX - lX - 1); // prevent zero div
|
||||||
|
|
||||||
S3L_Unit b0 = 0;
|
|
||||||
S3L_Unit b1 = lSideUnitPos;
|
|
||||||
|
|
||||||
S3L_Unit b0Step = rSideUnitPos / rowLength;
|
|
||||||
S3L_Unit b1Step = lSideUnitPos / rowLength;
|
|
||||||
|
|
||||||
#if S3L_PERSPECTIVE_CORRECTION == 1
|
#if S3L_PERSPECTIVE_CORRECTION == 1
|
||||||
S3L_Unit lDepth, rDepth, lT, rT;
|
S3L_Unit lDepth, rDepth, lT, rT;
|
||||||
|
|
||||||
lT = lSideUnitPos >> S3L_LERP_QUALITY; // CHANGEEEE
|
lT = S3L_correctPerspective(lSideUnitPosScaled >> S3L_LERP_QUALITY,&lPC);
|
||||||
rT = rSideUnitPos >> S3L_LERP_QUALITY; // CHANGEEEE
|
rT = S3L_correctPerspective(rSideUnitPosScaled >> S3L_LERP_QUALITY,&rPC);
|
||||||
|
|
||||||
rT = S3L_correctPerspective(rT,&rPC);
|
lDepth = S3L_interpolateByUnit(lPC.a[2],lPC.b[2],lT);
|
||||||
|
rDepth = S3L_interpolateByUnit(rPC.a[2],rPC.b[2],rT);
|
||||||
|
|
||||||
lDepth = S3L_interpolateByUnit(lPC.p0[2],lPC.p1[2],lT);
|
printf("l: %d %d\n",lSideUnitPosScaled >> S3L_LERP_QUALITY,lT);
|
||||||
rDepth = S3L_interpolateByUnit(rPC.p0[2],rPC.p1[2],rT);
|
printf("r: %d %d\n",rSideUnitPosScaled >> S3L_LERP_QUALITY,rT);
|
||||||
|
|
||||||
S3L_initPerspectiveCorrectionState(
|
S3L_initPerspectiveCorrectionState(
|
||||||
S3L_interpolateByUnit(lPC.a[0],lPC.b[0],lT),
|
S3L_interpolateByUnit(lPC.a[0],lPC.b[0],lT),
|
||||||
|
@ -1077,31 +1084,40 @@ void _S3L_drawFilledTriangle(
|
||||||
camera->focalLength,
|
camera->focalLength,
|
||||||
&rowPC
|
&rowPC
|
||||||
);
|
);
|
||||||
|
#else
|
||||||
|
S3L_Unit b0 = 0;
|
||||||
|
S3L_Unit b1 = lSideUnitPosScaled;
|
||||||
|
|
||||||
|
S3L_Unit b0Step = rSideUnitPosScaled / rowLength;
|
||||||
|
S3L_Unit b1Step = lSideUnitPosScaled / rowLength;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (S3L_ScreenCoord x = lX; x < rX; ++x)
|
for (S3L_ScreenCoord x = lX; x < rX; ++x)
|
||||||
{
|
{
|
||||||
|
#if S3L_PERSPECTIVE_CORRECTION == 1
|
||||||
|
S3L_Unit rowT =
|
||||||
|
S3L_correctPerspective(S3L_interpolateFrom0(S3L_FRACTIONS_PER_UNIT,
|
||||||
|
x - lX,rowLength),&rowPC);
|
||||||
|
|
||||||
|
*barycentric0 = S3L_interpolateByUnitFrom0(lT,rowT);
|
||||||
|
*barycentric1 = S3L_FRACTIONS_PER_UNIT -
|
||||||
|
S3L_interpolateByUnitFrom0(S3L_FRACTIONS_PER_UNIT - rT,S3L_FRACTIONS_PER_UNIT - rowT);
|
||||||
|
#else
|
||||||
*barycentric0 = b0 >> S3L_LERP_QUALITY;
|
*barycentric0 = b0 >> S3L_LERP_QUALITY;
|
||||||
*barycentric1 = b1 >> S3L_LERP_QUALITY;
|
*barycentric1 = b1 >> S3L_LERP_QUALITY;
|
||||||
|
|
||||||
#if S3L_PERSPECTIVE_CORRECTION == 1
|
b0 += b0Step;
|
||||||
S3L_Unit rowT = S3L_interpolateFrom0(S3L_FRACTIONS_PER_UNIT,x - lX,rX - lX);
|
b1 -= b1Step;
|
||||||
|
|
||||||
*barycentric0 = S3L_interpolateByUnitFrom0(lT,rowT);
|
|
||||||
*barycentric1 = S3L_interpolateByUnitFrom0(rT,S3L_FRACTIONS_PER_UNIT - rowT);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*barycentric2 = S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1;
|
*barycentric2 = S3L_FRACTIONS_PER_UNIT - *barycentric0 - *barycentric1;
|
||||||
|
|
||||||
p->x = x;
|
p->x = x;
|
||||||
S3L_PIXEL_FUNCTION(p);
|
S3L_PIXEL_FUNCTION(p);
|
||||||
|
|
||||||
b0 += b0Step;
|
|
||||||
b1 -= b1Step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lSideUnitPos += lSideUnitStep;
|
lSideUnitPosScaled += lSideStep;
|
||||||
rSideUnitPos += rSideUnitStep;
|
rSideUnitPosScaled += rSideStep;
|
||||||
|
|
||||||
++currentY;
|
++currentY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,11 +119,11 @@ void draw()
|
||||||
|
|
||||||
//frame = 853;
|
//frame = 853;
|
||||||
|
|
||||||
modelTransform.rotation.z = frame * 0.1;
|
modelTransform.rotation.z = 30;//frame * 0.1;
|
||||||
modelTransform.rotation.x = frame * 0.3;
|
modelTransform.rotation.x = 90;//frame * 0.3;
|
||||||
|
|
||||||
S3L_drawModelIndexed(ver,tri,12,modelTransform,&camera,&conf);
|
// S3L_drawModelIndexed(ver,tri,12,modelTransform,&camera,&conf);
|
||||||
// S3L_drawModelIndexed(ver,tri + 3,1,modelTransform,&camera,&conf);
|
S3L_drawModelIndexed(ver,tri + 3,1,modelTransform,&camera,&conf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
conf.backfaceCulling = S3L_BACKFACE_CULLING_NONE;
|
conf.backfaceCulling = S3L_BACKFACE_CULLING_NONE;
|
||||||
|
|
Loading…
Reference in a new issue