summaryrefslogtreecommitdiff
path: root/src/scene.cpp
diff options
context:
space:
mode:
authorElizabeth (Lizzy) Hunt <elizabeth.hunt@simponic.xyz>2023-11-28 14:47:29 -0700
committerGitHub <noreply@github.com>2023-11-28 14:47:29 -0700
commit4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd (patch)
tree2d9eb3fbc17d453ee33e478bafb9936beff12eb3 /src/scene.cpp
parentebc517c800a90f6f0ed157e5c3bd7c3bd18165b5 (diff)
parent3197f9e40cd7079e19990c64c98de667e2457d75 (diff)
downloadgbarubik-4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd.tar.gz
gbarubik-4dcdd32bf7578acf3ea9bc1e98d39d82e3e1afdd.zip
Merge pull request #1 from Simponic/cubeHEADmain
Cube
Diffstat (limited to 'src/scene.cpp')
-rw-r--r--src/scene.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scene.cpp b/src/scene.cpp
index e69de29..44e7028 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -0,0 +1,38 @@
+#include "scene.hpp"
+
+Scene::Scene() {
+ directional_light = {0, 0, -1};
+ viewport_dimension = {3, 2};
+ scene_dimension = {SCREEN_WIDTH / 2, SCREEN_HEIGHT};
+
+ z_plane = int2fx(1);
+}
+
+POINT Scene::project_2d(VECTOR vertex) {
+ POINT pt = {0, 0};
+
+ if (vertex.z != 0) {
+ pt.x = fxdiv(z_plane, vertex.z);
+ pt.y = fxmul(vertex.y, pt.x);
+ pt.x = fxmul(vertex.x, pt.x);
+ }
+
+ return pt;
+}
+
+POINT Scene::viewport_to_scene(POINT p) {
+ FIXED x = fxmul(p.x, int2fx(std::get<0>(scene_dimension) /
+ std::get<0>(viewport_dimension)));
+ FIXED y = fxmul(p.y, int2fx(std::get<1>(scene_dimension) /
+ std::get<1>(viewport_dimension)));
+ return {x >> FIX_SHIFT, y >> FIX_SHIFT};
+}
+
+void Scene::draw_line(POINT p0, POINT p1, std::uint8_t pal_idx) {
+ POINT scene_p0 = viewport_to_scene(p0);
+ POINT scene_p1 = viewport_to_scene(p1);
+
+ std::uint16_t pixels = (pal_idx << 8) | pal_idx;
+ bmp16_line(scene_p0.x, scene_p0.y, scene_p1.x, scene_p1.y, pixels, vid_page,
+ SCREEN_WIDTH);
+}