This commit is contained in:
duarteapcoelho 2022-09-08 15:20:00 +01:00
parent c0b408d106
commit b8fb21ec7a
3 changed files with 28 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include "fp.h"
#define I_SQRT_2 0.707106
#define I_SQRT_3 0.577350
#define PI 3.141592654
#define HALF_PI 1.570796327

View File

@ -1623,6 +1623,25 @@ int main(){
Model floor({2, floorTriangles});
Triangle sunTriangles[2] = {
{
{-1, -1, 0},
{-1, 1, 0},
{1, -1, 0},
{0, 1, 0},
newColor(255, 255, 0)
},
{
{-1, 1, 0},
{1, 1, 0},
{1, -1, 0},
{0, 1, 0},
newColor(255, 255, 0)
},
};
Model sun({2, sunTriangles});
#define NUM_TRACK_POINTS 29
#define TRACK_WIDTH 10
vec3f trackPoints[NUM_TRACK_POINTS+1] = {
@ -1767,6 +1786,13 @@ int main(){
carModel.modelMatrix = carMatrix;
carModel.viewMatrix = view;
sun.viewMatrix = view;
sun.modelMatrix = mat4();
sun.modelMatrix = mat4::translate(sun.modelMatrix, 20, -6, -20);
sun.modelMatrix = mat4::translate(sun.modelMatrix, cameraPos.x, 0, cameraPos.z);
sun.modelMatrix = mat4::rotateY(sun.modelMatrix, cameraAngle + HALF_PI);
sun.draw(false, false, true);
floor.viewMatrix = view;
floor.draw(false, false, true);

View File

@ -132,7 +132,7 @@ namespace Rasterizer {
fp z = (p0.z + p1.z + p2.z) / 3;
if(isShaded){
fp brightness = dot3(mat4::toMat3(model->modelMatrix) * triangle.normal, {-0.2, -0.6, 0.2}) + fp(0.2);
fp brightness = dot3(mat4::toMat3(model->modelMatrix) * triangle.normal, {I_SQRT_3, -I_SQRT_3, -I_SQRT_3}) * fp(0.6) + fp(0.4);
if(brightness > 1)
brightness = 1;
if(brightness < 0)