This is a simple program for rendering a 3D cube using the SDL2 library in C#. The project demonstrates the basics of 3D graphics, including coordinate transformations, projection, and camera control.
- Rendering of a rotating 3D cube using SDL2
- Simple movable camera
- Mathematics for 3D transformations (rotation, translation, projection)
- Vector math basics (Vec2, Vec3)
- W/S: Move camera forward/backward (Z-axis)
- A/D: Move camera left/right (X-axis)
- Q/E: Move camera up/down (Y-axis)
- Close window: Quit the program
-
WindowManager - manages SDL2 window and renderer
GetRenderer()- gets the SDL rendererClearBackground()- clears the screenPresent()- displays rendered content
-
Vec2/Vec3 - classes for 2D and 3D vector operations
- Basic operations (+, -, *, /)
- Normalization, dot product
- Rotation (Vec3 only)
-
Camera - simple 3D camera
WorldToViewSpace()- transforms world coordinates to camera space- Configurable FOV, near and far clipping planes
-
Core - utility functions
Vec3toVec2()- projects 3D point to 2D screenRotate()- rotates vector around axisScreenSpaceToSDLCoords()- converts normalized coordinates to pixel coordinates
- Ensure you have .NET SDK installed (version 5.0 or higher)
- Install SDL2 dependencies (via NuGet or manually)
- Build the project:
dotnet build - Run:
dotnet run
All contributions are welcome! Here are some ideas:
-
Graphics Improvements:
- Add lighting
- Implement filled polygons instead of wireframe
- Add texturing
-
New Features:
- Load 3D models from files
- More advanced camera controls (free flight)
- Mouse camera control
-
Optimizations:
- Improve math operations
- Add backface culling
- More efficient rendering
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to your fork (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
