mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Update hq program
This commit is contained in:
parent
42b558f486
commit
c27f3575ba
1 changed files with 29 additions and 8 deletions
|
@ -76,6 +76,7 @@ S3L_Model3D models[MODELS_TOTAL];
|
||||||
S3L_Scene scene;
|
S3L_Scene scene;
|
||||||
|
|
||||||
int previousTriangle = -1;
|
int previousTriangle = -1;
|
||||||
|
int previousModel = -1;
|
||||||
|
|
||||||
S3L_Vec4 toLightDirection;
|
S3L_Vec4 toLightDirection;
|
||||||
|
|
||||||
|
@ -140,9 +141,24 @@ void drawPixel(S3L_PixelInfo *p)
|
||||||
|
|
||||||
float diffuseIntensity, specularIntensity, specularPower;
|
float diffuseIntensity, specularIntensity, specularPower;
|
||||||
|
|
||||||
S3L_Unit *normals = p->modelIndex == 0 ? terrainNormals : waterNormals;
|
S3L_Unit *normals;
|
||||||
|
|
||||||
if (p->triangleIndex != previousTriangle)
|
switch (p->modelIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
normals = treeNormals; break;
|
||||||
|
|
||||||
|
case ISLAND_MODEL_INDEX:
|
||||||
|
normals = terrainNormals; break;
|
||||||
|
|
||||||
|
case WATER_MODEL_INDEX:
|
||||||
|
default:
|
||||||
|
normals = waterNormals; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->triangleIndex != previousTriangle || p->modelIndex != previousModel)
|
||||||
{
|
{
|
||||||
int index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3;
|
int index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3;
|
||||||
|
|
||||||
|
@ -176,6 +192,9 @@ void drawPixel(S3L_PixelInfo *p)
|
||||||
index++;
|
index++;
|
||||||
n2.z = normals[index];
|
n2.z = normals[index];
|
||||||
v2.z = scene.models[p->modelIndex].vertices[index];
|
v2.z = scene.models[p->modelIndex].vertices[index];
|
||||||
|
|
||||||
|
previousTriangle = p->triangleIndex;
|
||||||
|
previousModel = p->modelIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
S3L_correctBarycentricCoords(p->barycentric);
|
S3L_correctBarycentricCoords(p->barycentric);
|
||||||
|
@ -352,7 +371,7 @@ void animateWater()
|
||||||
for (int i = 1; i < GRID_W * GRID_H * 3; i += 3)
|
for (int i = 1; i < GRID_W * GRID_H * 3; i += 3)
|
||||||
waterVertices[i] = S3L_FRACTIONS_PER_UNIT / 4 + sin(frame * 0.2) * S3L_FRACTIONS_PER_UNIT / 4;
|
waterVertices[i] = S3L_FRACTIONS_PER_UNIT / 4 + sin(frame * 0.2) * S3L_FRACTIONS_PER_UNIT / 4;
|
||||||
|
|
||||||
S3L_computeModelNormals(models[MODELS_TOTAL - 1],waterNormals,0);
|
S3L_computeModelNormals(models[WATER_MODEL_INDEX],waterNormals,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearFrameBuffer()
|
void clearFrameBuffer()
|
||||||
|
@ -391,9 +410,11 @@ int main()
|
||||||
models[1] = treeModel;
|
models[1] = treeModel;
|
||||||
models[2] = treeModel;
|
models[2] = treeModel;
|
||||||
|
|
||||||
S3L_setTransform3D(0,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,&(models[0].transform));
|
S3L_Unit scale = S3L_FRACTIONS_PER_UNIT / 4;
|
||||||
S3L_setTransform3D(S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,&(models[1].transform));
|
|
||||||
S3L_setTransform3D(-S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT,&(models[2].transform));
|
S3L_setTransform3D(0,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,scale,scale,scale,&(models[0].transform));
|
||||||
|
S3L_setTransform3D(S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,scale,scale,scale,&(models[1].transform));
|
||||||
|
S3L_setTransform3D(-S3L_FRACTIONS_PER_UNIT,S3L_FRACTIONS_PER_UNIT * 2,0,0,0,0,scale,scale,scale,&(models[2].transform));
|
||||||
|
|
||||||
S3L_initModel3D(
|
S3L_initModel3D(
|
||||||
terrainVertices,
|
terrainVertices,
|
||||||
|
@ -402,7 +423,7 @@ int main()
|
||||||
GRID_TRIANGLES,
|
GRID_TRIANGLES,
|
||||||
&(models[ISLAND_MODEL_INDEX]));
|
&(models[ISLAND_MODEL_INDEX]));
|
||||||
|
|
||||||
S3L_computeModelNormals(models[0],terrainNormals,0);
|
S3L_computeModelNormals(models[ISLAND_MODEL_INDEX],terrainNormals,0);
|
||||||
S3L_computeModelNormals(treeModel,treeNormals,0);
|
S3L_computeModelNormals(treeModel,treeNormals,0);
|
||||||
|
|
||||||
S3L_initModel3D(
|
S3L_initModel3D(
|
||||||
|
@ -416,7 +437,7 @@ int main()
|
||||||
|
|
||||||
char fileName[] = "test00.ppm";
|
char fileName[] = "test00.ppm";
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i) // render the frames
|
for (int i = 0; i < 50; ++i) // render the frames
|
||||||
{
|
{
|
||||||
animateWater();
|
animateWater();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue