Class LightingManager

java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.lighting.LightingManager

public class LightingManager extends Object
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 Details

    • LightingManager

      public LightingManager()
      Creates a new lighting manager with no light sources.
  • Method Details

    • addLight

      public void addLight(LightSource light)
      Adds a light source to the scene.
      Parameters:
      light - the light source to add
    • calculateLighting

      public Color calculateLighting(Point3D polygonCenter, Point3D normal, Color baseColor)
      Calculates the shaded color for a polygon based on lighting.
      Parameters:
      polygonCenter - the center point of the polygon in world space
      normal - the surface normal vector (should be normalized)
      baseColor - the original color of the polygon
      Returns:
      the shaded color after applying lighting
    • getAmbientLight

      public Color getAmbientLight()
      Returns the ambient light color.
      Returns:
      the ambient light color
    • getLights

      public List<LightSource> getLights()
      Returns all light sources in the scene.
      Returns:
      list of light sources
    • removeLight

      public void removeLight(LightSource light)
      Removes a light source from the scene.
      Parameters:
      light - the light source to remove
    • setAmbientLight

      public void setAmbientLight(Color ambientLight)
      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