Add sun
This commit is contained in:
parent
c0b408d106
commit
b8fb21ec7a
|
@ -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
|
||||
|
||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue