Add cones

This commit is contained in:
duarteapcoelho 2022-09-05 11:57:28 +01:00
parent d8bd4e1ec0
commit 270f57c707
2 changed files with 195 additions and 1 deletions

View file

@ -135,6 +135,13 @@ public:
};
}
static mat4 translate(mat4 matrix, vec3d p){
mat4 t;
t.m[3][0] = p.x;
t.m[3][1] = p.y;
t.m[3][2] = p.z;
return matrix * t;
}
static mat4 translate(mat4 matrix, fp x, fp y, fp z){
mat4 t;
t.m[3][0] = x;

View file

@ -31,6 +31,176 @@ int main(){
fp depthBuffer[RENDER_WIDTH*RENDER_HEIGHT];
Rasterizer::depthBuffer = depthBuffer;
Triangle coneTriangles[28] = {
{
{1.000, 0.193, 1.000},
{-0.656, 0.193, 0.656},
{0.656, 0.193, 0.656},
{0.000, -1.000, -0.000},
newColor(255, 100, 0)},
{
{-1.000, 0.193, -1.000},
{0.656, 0.193, -0.656},
{-0.656, 0.193, -0.656},
{-0.000, -1.000, 0.000},
newColor(255, 100, 0)},
{
{-1.000, 0.193, 1.000},
{-0.656, 0.193, -0.656},
{-0.656, 0.193, 0.656},
{0.000, -1.000, 0.000},
newColor(255, 100, 0)},
{
{1.000, 0.193, -1.000},
{0.656, 0.193, 0.656},
{0.656, 0.193, -0.656},
{-0.000, -1.000, 0.000},
newColor(255, 100, 0)},
{
{0.328, -0.679, 0.328},
{-0.328, -0.679, 0.328},
{0.000, -1.552, 0.000},
{-0.000, -0.352, 0.936},
newColor(255, 100, 0)},
{
{-0.328, -0.679, -0.328},
{0.328, -0.679, -0.328},
{0.000, -1.552, 0.000},
{0.000, -0.352, -0.936},
newColor(255, 100, 0)},
{
{-0.328, -0.679, 0.328},
{-0.328, -0.679, -0.328},
{0.000, -1.552, 0.000},
{-0.936, -0.352, 0.000},
newColor(255, 100, 0)},
{
{0.328, -0.679, -0.328},
{0.328, -0.679, 0.328},
{0.000, -1.552, 0.000},
{0.936, -0.352, -0.000},
newColor(255, 100, 0)},
{
{0.492, -0.243, 0.492},
{0.328, -0.679, -0.328},
{0.492, -0.243, -0.492},
{0.936, -0.352, -0.000},
newColor(255, 255, 255)},
{
{-0.492, -0.243, -0.492},
{-0.328, -0.679, 0.328},
{-0.492, -0.243, 0.492},
{-0.936, -0.352, 0.000},
newColor(255, 255, 255)},
{
{-0.492, -0.243, -0.492},
{0.328, -0.679, -0.328},
{-0.328, -0.679, -0.328},
{0.000, -0.352, -0.936},
newColor(255, 255, 255)},
{
{0.492, -0.243, 0.492},
{-0.328, -0.679, 0.328},
{0.328, -0.679, 0.328},
{-0.000, -0.352, 0.936},
newColor(255, 255, 255)},
{
{-0.656, 0.193, 0.656},
{0.492, -0.243, 0.492},
{0.656, 0.193, 0.656},
{0.000, -0.352, 0.936},
newColor(255, 100, 0)},
{
{0.656, 0.193, -0.656},
{-0.492, -0.243, -0.492},
{-0.656, 0.193, -0.656},
{0.000, -0.352, -0.936},
newColor(255, 100, 0)},
{
{-0.656, 0.193, -0.656},
{-0.492, -0.243, 0.492},
{-0.656, 0.193, 0.656},
{-0.936, -0.352, 0.000},
newColor(255, 100, 0)},
{
{0.656, 0.193, 0.656},
{0.492, -0.243, -0.492},
{0.656, 0.193, -0.656},
{0.936, -0.352, 0.000},
newColor(255, 100, 0)},
{
{1.000, 0.193, 1.000},
{-1.000, 0.193, 1.000},
{-0.656, 0.193, 0.656},
{0.000, -1.000, -0.000},
newColor(255, 100, 0)},
{
{-1.000, 0.193, -1.000},
{1.000, 0.193, -1.000},
{0.656, 0.193, -0.656},
{0.000, -1.000, 0.000},
newColor(255, 100, 0)},
{
{-1.000, 0.193, 1.000},
{-1.000, 0.193, -1.000},
{-0.656, 0.193, -0.656},
{0.000, -1.000, -0.000},
newColor(255, 100, 0)},
{
{1.000, 0.193, -1.000},
{1.000, 0.193, 1.000},
{0.656, 0.193, 0.656},
{-0.000, -1.000, 0.000},
newColor(255, 100, 0)},
{
{0.492, -0.243, 0.492},
{0.328, -0.679, 0.328},
{0.328, -0.679, -0.328},
{0.936, -0.352, -0.000},
newColor(255, 255, 255)},
{
{-0.492, -0.243, -0.492},
{-0.328, -0.679, -0.328},
{-0.328, -0.679, 0.328},
{-0.936, -0.352, 0.000},
newColor(255, 255, 255)},
{
{-0.492, -0.243, -0.492},
{0.492, -0.243, -0.492},
{0.328, -0.679, -0.328},
{0.000, -0.352, -0.936},
newColor(255, 255, 255)},
{
{0.492, -0.243, 0.492},
{-0.492, -0.243, 0.492},
{-0.328, -0.679, 0.328},
{-0.000, -0.352, 0.936},
newColor(255, 255, 255)},
{
{-0.656, 0.193, 0.656},
{-0.492, -0.243, 0.492},
{0.492, -0.243, 0.492},
{-0.000, -0.352, 0.936},
newColor(255, 100, 0)},
{
{0.656, 0.193, -0.656},
{0.492, -0.243, -0.492},
{-0.492, -0.243, -0.492},
{0.000, -0.352, -0.936},
newColor(255, 100, 0)},
{
{-0.656, 0.193, -0.656},
{-0.492, -0.243, -0.492},
{-0.492, -0.243, 0.492},
{-0.936, -0.352, 0.000},
newColor(255, 100, 0)},
{
{0.656, 0.193, 0.656},
{0.492, -0.243, 0.492},
{0.492, -0.243, -0.492},
{0.936, -0.352, -0.000},
newColor(255, 100, 0)},
};
Triangle carTriangles[134] = {
{
@ -844,6 +1014,12 @@ int main(){
carTriangles
};
Mesh coneMesh = {
28,
coneTriangles
};
srand(0);
// Triangle treeTriangles[10*10];
@ -906,6 +1082,7 @@ int main(){
}
Triangle trackTriangles[NUM_TRACK_POINTS*2-2];
Model coneModels[NUM_TRACK_POINTS*2-2];
for(int i = 0; i < NUM_TRACK_POINTS-1; i++){
vec3f pos = trackPoints[i];
@ -930,6 +1107,11 @@ int main(){
{0, -1, 0},
newColor(50, 50, 50)
};
coneModels[i].mesh = coneMesh;
coneModels[i].modelMatrix = mat4::scale(mat4::translate(mat4(), vec3d(pos - perpendicular)), 1, 1, 1);
coneModels[i+NUM_TRACK_POINTS-1].mesh = coneMesh;
coneModels[i+NUM_TRACK_POINTS-1].modelMatrix = mat4::scale(mat4::translate(mat4(), vec3d(pos + perpendicular)), 1, 1, 1);
}
Model trackModel = Model({NUM_TRACK_POINTS*2-2, trackTriangles});
@ -999,8 +1181,13 @@ int main(){
carModel.viewMatrix = view;
trackModel.viewMatrix = view;
trackModel.draw(false, false);
for(int i = 0; i < NUM_TRACK_POINTS*2-2; i++){
coneModels[i].viewMatrix = view;
coneModels[i].draw(true, true);
}
trackModel.draw(false, true);
carModel.draw(true, true);
char buffer[10];