Skip to content

Daniele1717/3D-java-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

3D render engine in Java Project

Description of the project

Create the three sides of your figure, add them to the list, run, and... here's your 3D visualization!

Project structure

5 possible iterations, from simple to complex:

  • Orthographic projection (top-down view)
  • Horizontal movement (left to right)
  • Full 3D rotation and translation
  • color assignment
  • Depth-based rendering using a Z-buffe

Render logic

Each vertex is represented as a vector A = [aₓ, aᵧ, a𝓏]. To apply rotation, the vector is multiplied by rotation matrices. Matrix multiplication follows the associative property:

$$ \text{Rotation XY} = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} $$

$$ \text{Rotation YZ} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos\theta & \sin\theta \\ 0 & -\sin\theta & \cos\theta \end{bmatrix} $$

$$ \text{Rotation XZ} = \begin{bmatrix} \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \end{bmatrix} $$

examples: (AT₁)T₂ = A(T₁T₂)

Moving the mouse on the x or y axis will trigger the listener to update the pixels.

The Z-buffer

To manage visibility and occlusion, the engine uses a Z-buffer. This is a 2D array that stores the depth value of the closest triangle rendered at each pixel.

  • At initialization, the Z-buffer is filled with a maximum depth value.
  • During rasterization, each triangle fragment is compared against the current depth value at its pixel.
  • If the fragment is closer to the camera, the Z-buffer and pixel color are updated.
  • If it is farther, the fragment is discarded. This technique ensures that only the front-most surfaces are visible, eliminating the need for manual geometry sorting. The Z-buffer is a standard feature in modern rendering pipelines and is essential for producing accurate and realistic 3D scenes.

About

3D engine with no external library. Just Java!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages