A 3D renderer written in pure Java with no external libraries — just Swing, math, and a lot of triangles!
This project builds a rotating, shaded sphere using triangle subdivision, z-buffering, and basic flat shading.
- Renders 3D triangles onto a 2D panel
- Sphere-like shape using triangle inflation
- Real-time rotation using sliders
- Flat shading based on light angle
- Z-buffering for correct depth sorting
- All rendering handled pixel-by-pixel using
BufferedImage
-
Tetrahedron → Sphere:
A basic tetrahedron is subdivided multiple times using theinflate()function to approximate a sphere. -
Matrix Transformations:
Rotation is applied via 3x3 matrix multiplication (Matrix3) based on slider values. -
Flat Shading:
Calculates light intensity using surface normals and simple dot product. -
Z-buffer:
Keeps track of depth values for each pixel to render the closest triangle only.
- Horizontal Slider (Bottom): Rotate left/right (rotates around XZ plane)
- Vertical Slider (Right): Rotate up/down (rotates the object around YZ plane) The 3D shape updates in real-time as you drag the sliders.
None!
Built only with core Java:
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;Feel free to fork, suggest improvements, or just reach out — I'm always learning and happy to connect.
