-
Initializes a
JFramewith sliders for horizontal and vertical rotation. -
Uses a
JPanel(renderPanel) as the main rendering area. -
The resulting window would be resembling this:
-
Vertexclass represents a point in 3D space. -
Triangleclass represents a 3D triangle with three vertices and a color. -
Matrix3represents a 3x3 matrix with methods for matrix multiplication and vertex transformation. -
We can observe the formulae for rotation matrices in the below image:
-
At this point wireframe of our shape is completed and it looks like this:
-
Initializes GUI components and rendering panel.
-
The central panel renders colored triangles in 3D space using BufferedImage for improved performance.
-
Triangles are transformed based on the combined horizontal and vertical rotation from sliders.
- Implementing a z-buffer for hidden surface removal during rendering.
- The rendering panel uses a z-buffer for depth calculations, enhancing the visual quality of the 3D object.
-
Shading is applied to colored triangles based on the angle of incidence
(angleCos)of light source and normal direction. -
Defining
getShademethod for shading colors based on a given shade factor.
-
Implementing
inflatemethod to subdivide triangles, adding detail to the scene. -
The final result is a dynamic 3D rendering of a sphere that responds to user-controlled rotations.
- Populates a list of triangles with initial vertices and colors.
- Applies rotation transformations based on slider values.
- Uses a z-buffer for hidden surface removal during rendering.
- Paints each pixel in the rendering panel based on transformed vertices and shading.






