https://github.com/m3str3/rust3d
An interactive 3D viewer written in Rust, for .obj models.
https://github.com/m3str3/rust3d
geometry rust
Last synced: 8 days ago
JSON representation
An interactive 3D viewer written in Rust, for .obj models.
- Host: GitHub
- URL: https://github.com/m3str3/rust3d
- Owner: M3str3
- Created: 2024-12-28T17:00:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-28T18:00:21.000Z (over 1 year ago)
- Last Synced: 2025-01-10T10:34:55.994Z (over 1 year ago)
- Topics: geometry, rust
- Language: Rust
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Rust3D
A basic 3D viewer written in Rust for rotating, zooming, and loading `.obj` files.
## Features
- Rotate the 3D model.
- Zoom in and out.
- Load `.obj` files dynamically.
## Controls
| **Key/Mouse** | **Action** |
|------------------------|-------------------------|
| **Left Click + Drag** | Rotate the model |
| **Space** | Toggle auto-rotation |
| **B** | Change background color |
| **M** | Change object color |
| **Up / +** | Zoom in |
| **Down / -** | Zoom out |
| **L** | Load a new `.obj` file |
| **Escape** | Exit the program |
## How It Works
https://github.com/user-attachments/assets/ac892f1e-226b-4b58-ac04-caeccd5660a2
### Rotation Matrices
The 3D point \((x, y, z)\) is rotated using standard rotation matrices:
- **X-axis Rotation**:
```math
\begin{cases}
x' = x \
y' = y \cos\theta - z \sin\theta \
z' = y \sin\theta + z \cos\theta
\end{cases}
```
- **Perspective Projection**:
```math
\begin{cases}
u = x \cdot \frac{\text{scale}}{z + \text{distance}} + \frac{\text{screen\_width}}{2} \
v = -y \cdot \frac{\text{scale}}{z + \text{distance}} + \frac{\text{screen\_height}}{2}
\end{cases}
```