Class LightingManager
java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.lighting.LightingManager
Manages light sources in the scene and calculates lighting for polygons.
This class implements flat shading using the Lambert cosine law. For each polygon face, it calculates the surface normal and determines how much light each source contributes based on the angle between the normal and the light direction.
The lighting calculation considers:
- Distance from polygon center to each light source
- Angle between surface normal and light direction
- Color and intensity of each light source
Usage example:
LightingManager lighting = new LightingManager();
// Add light sources
lighting.addLight(new LightSource(new Point3D(100, -50, 200), Color.YELLOW));
lighting.addLight(new LightSource(new Point3D(-100, 50, 200), Color.BLUE));
// Set ambient light (base illumination)
lighting.setAmbientLight(new Color(30, 30, 30));
// Calculate shaded color for a polygon
Color shadedColor = lighting.calculateLighting(
polygonCenter,
surfaceNormal,
baseColor
);
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLight(LightSource light) Adds a light source to the scene.calculateLighting(Point3D polygonCenter, Point3D normal, Color baseColor) Calculates the shaded color for a polygon based on lighting.Returns the ambient light color.Returns all light sources in the scene.voidremoveLight(LightSource light) Removes a light source from the scene.voidsetAmbientLight(Color ambientLight) Sets the ambient light color for the scene.
-
Constructor Details
-
LightingManager
public LightingManager()Creates a new lighting manager with no light sources.
-
-
Method Details
-
addLight
Adds a light source to the scene.- Parameters:
light- the light source to add
-
calculateLighting
Calculates the shaded color for a polygon based on lighting.- Parameters:
polygonCenter- the center point of the polygon in world spacenormal- the surface normal vector (should be normalized)baseColor- the original color of the polygon- Returns:
- the shaded color after applying lighting
-
getAmbientLight
Returns the ambient light color.- Returns:
- the ambient light color
-
getLights
Returns all light sources in the scene.- Returns:
- list of light sources
-
removeLight
Removes a light source from the scene.- Parameters:
light- the light source to remove
-
setAmbientLight
Sets the ambient light color for the scene.Ambient light provides base illumination that affects all surfaces equally, regardless of their orientation.
- Parameters:
ambientLight- the ambient light color
-