initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "renderer/calls.hpp"
|
||||
|
||||
void rasterizeTriangle(SDL_Renderer *renderer, const DeltaVector2 &a, const DeltaVector2 &b, const DeltaVector2 &c) {
|
||||
DeltaVector2 begin, end, p;
|
||||
begin.x = std::min(a.x, std::min(b.x, c.x));
|
||||
begin.y = std::min(a.y, std::min(b.y, c.y));
|
||||
end.x = std::max(a.x, std::max(b.x, c.x));
|
||||
end.y = std::max(a.y, std::max(b.y, c.y));
|
||||
|
||||
for (int y = begin.y; y < end.y; y++) {
|
||||
for (int x = begin.x; x < end.x; x++) {
|
||||
p.x = x; p.y = y;
|
||||
|
||||
if (getDeterminant(a, b, p) >= 0 && getDeterminant(b, c, p) >= 0 && getDeterminant(c, a, p) >= 0) {
|
||||
SDL_RenderPoint(renderer, p.x, p.y);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// please do not touch this code.
|
||||
// it is a waste of time looking at this code.
|
||||
// please, dont. if you do continue, edit the value below
|
||||
// as a warning for future you.
|
||||
|
||||
// hoursWasted = 2
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <cmath>
|
||||
|
||||
#include "renderer/camera.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
DeltaCamera::DeltaCamera(float x, float y, float z) {
|
||||
pos = DeltaVector3(x, y, z);
|
||||
angle = DeltaVector2();
|
||||
}
|
||||
|
||||
DeltaVector2 DeltaCamera::projectPointVec(const DeltaVector3 &worldPos) {
|
||||
DeltaVector3 calculatedPos; DeltaVector2 projected;
|
||||
float sineX = std::sin(angle.x);
|
||||
float cosineX = std::cos(angle.x);
|
||||
|
||||
float sineY = std::sin(angle.y);
|
||||
float cosineY = std::cos(angle.y);
|
||||
|
||||
// yaw translate
|
||||
|
||||
calculatedPos.x = (worldPos.x - pos.x) * cosineX - (worldPos.y - pos.y) * sineX;
|
||||
calculatedPos.y = (worldPos.y - pos.y) * cosineX + (worldPos.x - pos.x) * sineX;
|
||||
calculatedPos.z = (worldPos.z - pos.z);
|
||||
|
||||
// pitch translate
|
||||
|
||||
calculatedPos.y = calculatedPos.y * cosineY - calculatedPos.z * sineY;
|
||||
calculatedPos.z = calculatedPos.y * sineY + calculatedPos.z * cosineY;
|
||||
// dont touch calculatedPos.x
|
||||
|
||||
projected.x = calculatedPos.x * FOCAL / calculatedPos.y + SIMULATED_WIDTH / 2;
|
||||
projected.y = calculatedPos.y * FOCAL / calculatedPos.y + SIMULATED_HEIGHT / 2;
|
||||
|
||||
// now gotta convert y to our y
|
||||
projected.y = SIMULATED_HEIGHT - projected.y;
|
||||
|
||||
// we are done =D
|
||||
return projected;
|
||||
}
|
||||
|
||||
DeltaVector2 DeltaCamera::projectPoint(float worldX, float worldY, float worldZ) {
|
||||
// simple conversion, dont iterate further
|
||||
return projectPointVec({ worldX, worldY, worldZ });
|
||||
}
|
||||
Reference in New Issue
Block a user