From fbc5c101783533f90a3053671de5314c2c6a1c1a Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Fri, 13 Feb 2026 10:13:59 +0100 Subject: Directory cleanup --- sample2.cpp | 102 ------------------------------------------------------------ 1 file changed, 102 deletions(-) delete mode 100644 sample2.cpp (limited to 'sample2.cpp') diff --git a/sample2.cpp b/sample2.cpp deleted file mode 100644 index 02e1718..0000000 --- a/sample2.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "graphics.h" -#include -#include - -struct Vec3 { - float x, y, z; -}; - -// Rotate point around X axis -Vec3 rotateX(const Vec3& v, float angle) { - float c = std::cos(angle); - float s = std::sin(angle); - return { - v.x, - v.y * c - v.z * s, - v.y * s + v.z * c - }; -} - -// Rotate point around Y axis -Vec3 rotateY(const Vec3& v, float angle) { - float c = std::cos(angle); - float s = std::sin(angle); - return { - v.x * c + v.z * s, - v.y, - -v.x * s + v.z * c - }; -} - -// Perspective projection -void project(const Vec3& v, int& x2d, int& y2d, float width, float height) { - float distance = 2.0f; // camera distance - float scale = 100.0f; // zoom factor - - float z = v.z + distance; - float factor = scale / z; - - x2d = static_cast(v.x * factor + width / 2); - y2d = static_cast(v.y * factor + height / 2); -} - -int main() { - const int width = 640; - const int height = 480; - - WindowHandle* window = createWindow("3D Spinning Cube", width, height); - if (!window) return -1; - - // Cube vertices - std::vector vertices = { - {-1, -1, -1}, - { 1, -1, -1}, - { 1, 1, -1}, - {-1, 1, -1}, - {-1, -1, 1}, - { 1, -1, 1}, - { 1, 1, 1}, - {-1, 1, 1} - }; - - // Cube edges (pairs of vertex indices) - std::vector> edges = { - {0,1},{1,2},{2,3},{3,0}, // back face - {4,5},{5,6},{6,7},{7,4}, // front face - {0,4},{1,5},{2,6},{3,7} // connecting edges - }; - - float angle = 0.0f; - - while (!windowShouldClose(window)) { - pollEvents(window); - clearScreen(window, Color(0, 0, 0)); // RGB 20, 20, 30 - - std::vector transformed; - - // Rotate cube - for (const auto& v : vertices) { - Vec3 r = rotateX(v, angle); - r = rotateY(r, angle * 0.7f); - transformed.push_back(r); - } - - // Draw edges - for (const auto& edge : edges) { - int x1, y1, x2, y2; - - project(transformed[edge.first], x1, y1, width, height); - project(transformed[edge.second], x2, y2, width, height); - - drawLine(window, x1, y1, x2, y2, Color(255, 255, 255)); // RGB 0 255 180 - } - - swapBuffers(window); - - angle += 0.01f; - delay(16); // ~60 FPS - } - - destroyWindow(window); - return 0; -} -- cgit v1.2.3