import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.math.Transform;
-import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
import eu.svjatoslav.sixth.e3d.renderer.raster.lighting.LightSource;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.solid.SolidPolygonCube;
import static eu.svjatoslav.sixth.e3d.geometry.Point3D.origin;
import static eu.svjatoslav.sixth.e3d.geometry.Point3D.point;
-import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.hex;
+import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.*;
/**
* Demo showcasing Constructive Solid Geometry (CSG) boolean operations.
public class CSGDemo {
/**
- * Color for the first argument in boolean operations (cube).
+ * Distance between shapes on the X axis.
*/
- private static final Color COLOR_FIRST = hex("FF6464D9");
+ private static final double SPACING = 400;
+
+ // ==================== SHAPE FACTORY METHODS ====================
/**
- * Color for the second argument in boolean operations (sphere).
+ * Creates a cube for CSG operations with current demo parameters.
+ *
+ * <p>The cube is created with shading enabled for realistic lighting.</p>
+ *
+ * @return a new SolidPolygonCube centered at origin with shading enabled
*/
- private static final Color COLOR_SECOND = hex("6496FFD9");
+ private static SolidPolygonCube createCube() {
+ final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, hex("39FF14D9"));
+ cube.setShadingEnabled(true);
+ return cube;
+ }
/**
- * Distance between shapes on the X axis.
+ * Creates a sphere for CSG operations with current demo parameters.
+ *
+ * <p>The sphere is created with shading disabled, causing it to glow
+ * at full intensity regardless of lighting conditions.</p>
+ *
+ * @return a new SolidPolygonSphere centered at origin with shading disabled
*/
- private static final double SPACING = 400;
+ private static SolidPolygonSphere createSphere() {
+ final SolidPolygonSphere sphere = new SolidPolygonSphere(origin(), 96, 12, hex("FF6600C0"));
+ sphere.setShadingEnabled(false);
+ return sphere;
+ }
+
+ // ==================== MAIN ENTRY POINT ====================
/**
* Entry point for the CSG demo.
viewPanel.getCamera().getTransform().set(-244.24, 254.40, -458.83, -0.26, 0.24, -0.00);
// Set up lighting
- viewPanel.getLightingManager().setAmbientLight(hex("3C3C46"));
+ viewPanel.getLightingManager().setAmbientLight(hex("0D0D0D"));
// Create lights
createLights(viewPanel, shapes);
*/
private static void createSubtractDemo(final ShapeCollection shapes, final Point3D location) {
- final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
- cube.subtract(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+ final SolidPolygonCube cube = createCube();
+ cube.subtract(createSphere());
shapes.addShape(cube
.setTransform(new Transform(location))
- .setShadingEnabled(true)
.setBackfaceCulling(true));
final String description =
"Subtract: Cube - Sphere\n" +
"\n" +
- "Red = Cube (kept)\n" +
- "Blue = Sphere (carved out)";
+ "Green = Cube (kept)\n" +
+ "Orange = Sphere (carved out)";
shapes.addShape(createDescriptionPanel(location, description));
}
*/
private static void createUnionDemo(final ShapeCollection shapes, final Point3D location) {
- final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
- cube.union(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+ final SolidPolygonCube cube = createCube();
+ cube.union(createSphere());
shapes.addShape(cube
.setTransform(new Transform(location))
- .setShadingEnabled(true)
.setBackfaceCulling(true));
final String description =
"Union: Cube + Sphere\n" +
"\n" +
- "Red = Cube\n" +
- "Blue = Sphere";
+ "Green = Cube\n" +
+ "Orange = Sphere";
shapes.addShape(createDescriptionPanel(location, description));
}
*/
private static void createIntersectDemo(final ShapeCollection shapes, final Point3D location) {
- final SolidPolygonCube cube = new SolidPolygonCube(origin(), 80, COLOR_FIRST);
- cube.intersect(new SolidPolygonSphere(origin(), 96, 12, COLOR_SECOND));
+ final SolidPolygonCube cube = createCube();
+ cube.intersect(createSphere());
shapes.addShape(cube
.setTransform(new Transform(location))
- .setShadingEnabled(true)
.setBackfaceCulling(true));
final String description =
"Intersect: Cube ∩ Sphere\n" +
"\n" +
- "Red = from Cube\n" +
- "Blue = from Sphere";
+ "Green = from Cube\n" +
+ "Orange = from Sphere";
shapes.addShape(createDescriptionPanel(location, description));
}
final TextCanvas panel = new TextCanvas(
transform,
new TextPointer(5, 35),
- Color.WHITE,
- new Color(0, 0, 40, 180));
+ WHITE,
+ TRANSPARENT);
panel.setText(text);
return panel;
* @param shapes the shape collection
*/
private static void createLights(final ViewPanel viewPanel, final ShapeCollection shapes) {
- // Main light from above-front
+ // Main light from above-front - bright white
final LightSource mainLight = new LightSource(
point(0, -300, -400),
hex("FFFFFF"),
- 1.5
+ 5.5
);
viewPanel.getLightingManager().addLight(mainLight);
- // Fill light from the side
+ // Fill light from the side - warm orange tint
final LightSource fillLight = new LightSource(
point(500, 100, -200),
- hex("9696C8"),
- 0.8
+ hex("FF6600"),
+ 5.5
);
viewPanel.getLightingManager().addLight(fillLight);
+
+ viewPanel.getLightingManager().setAmbientLight(hex("3D3D5D"));
}
}
\ No newline at end of file