Created
January 10, 2026 20:48
-
-
Save celsowm/d1cab8f5e26e127b1decce4e63cfe664 to your computer and use it in GitHub Desktop.
simple cube saturn ring lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <srl.hpp> | |
| using namespace SRL::Types; | |
| using namespace SRL::Math::Types; | |
| // Cube vertices (8 corners) | |
| Vector3D cubeVertices[8] = { | |
| Vector3D(-10.0, -10.0, -10.0), // 0: front bottom left | |
| Vector3D( 10.0, -10.0, -10.0), // 1: front bottom right | |
| Vector3D( 10.0, 10.0, -10.0), // 2: front top right | |
| Vector3D(-10.0, 10.0, -10.0), // 3: front top left | |
| Vector3D(-10.0, -10.0, 10.0), // 4: back bottom left | |
| Vector3D( 10.0, -10.0, 10.0), // 5: back bottom right | |
| Vector3D( 10.0, 10.0, 10.0), // 6: back top right | |
| Vector3D(-10.0, 10.0, 10.0), // 7: back top left | |
| }; | |
| // Cube faces (6 quads) | |
| Polygon cubeFaces[6] = { | |
| Polygon(Vector3D(0.0, 0.0, -1.0), (uint16_t[]){0, 1, 2, 3}), // front | |
| Polygon(Vector3D(0.0, 0.0, 1.0), (uint16_t[]){5, 4, 7, 6}), // back | |
| Polygon(Vector3D(-1.0, 0.0, 0.0), (uint16_t[]){4, 0, 3, 7}), // left | |
| Polygon(Vector3D( 1.0, 0.0, 0.0), (uint16_t[]){1, 5, 6, 2}), // right | |
| Polygon(Vector3D(0.0, 1.0, 0.0), (uint16_t[]){3, 2, 6, 7}), // top | |
| Polygon(Vector3D(0.0, -1.0, 0.0), (uint16_t[]){4, 5, 1, 0}), // bottom | |
| }; | |
| // Cube face attributes (colors for each face) | |
| Attribute cubeAttributes[6] = { | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::Red, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::Green, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::Blue, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::Yellow, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::Magenta, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| Attribute(Attribute::FaceVisibility::SingleSided, Attribute::SortMode::Center, No_Texture, HighColor::Colors::White, CL32KRGB, CL32KRGB, sprPolygon, No_Option), | |
| }; | |
| int main() | |
| { | |
| SRL::Core::Initialize(HighColor(0, 0, 128)); | |
| // Create cube mesh | |
| Mesh cube = Mesh(8, cubeVertices, 6, cubeFaces, cubeAttributes); | |
| // Camera position | |
| Vector3D cameraPos = Vector3D(0.0, 0.0, -50.0); | |
| // Rotation angles | |
| Angle rotX = Angle::Zero(); | |
| Angle rotY = Angle::Zero(); | |
| while(1) | |
| { | |
| SRL::Debug::Print(10, 1, "Sonic Saturn - 3D Cube"); | |
| // Reset matrix | |
| SRL::Scene3D::LoadIdentity(); | |
| // Set camera | |
| SRL::Scene3D::LookAt(cameraPos, Vector3D(0.0, 0.0, 0.0), Angle::Zero()); | |
| // Apply rotation | |
| SRL::Scene3D::RotateX(rotX); | |
| SRL::Scene3D::RotateY(rotY); | |
| // Draw the cube | |
| SRL::Scene3D::DrawMesh(cube); | |
| // Increment rotation | |
| rotX += Angle::FromDegrees(1.0); | |
| rotY += Angle::FromDegrees(0.7); | |
| SRL::Core::Synchronize(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment