/*
- * Sixth 3D engine. Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import java.io.IOException;
import java.net.URL;
+/**
+ * Camera that sees the raytraced scene.
+ * It is represented on the scene as a textured rectangle.
+ */
public class Camera extends TexturedRectangle {
- public static final int CAMERA_SIZE = 100;
+ public static final int SIZE = 100;
public static final int IMAGE_SIZE = 500;
private final CameraView cameraView;
- private Point3D camCenter;
public Camera(final Avatar avatar, final double zoom) {
super(new Transform(avatar.getLocation().clone()));
}
private void computeCameraCoordinates(final Avatar avatar) {
- initialize(CAMERA_SIZE, CAMERA_SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
+ initialize(SIZE, SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
- camCenter = new Point3D();
-
- topLeft.setValues(camCenter.x, camCenter.y, camCenter.z + CAMERA_SIZE);
+ Point3D cameraCenter = new Point3D();
+ topLeft.setValues(cameraCenter.x, cameraCenter.y, cameraCenter.z + SIZE);
topRight.clone(topLeft);
bottomLeft.clone(topLeft);
bottomRight.clone(topLeft);
final float viewAngle = (float) .6;
- topLeft.rotate(camCenter, -viewAngle, -viewAngle);
- topRight.rotate(camCenter, viewAngle, -viewAngle);
- bottomLeft.rotate(camCenter, -viewAngle, viewAngle);
- bottomRight.rotate(camCenter, viewAngle, viewAngle);
+ topLeft.rotate(cameraCenter, -viewAngle, -viewAngle);
+ topRight.rotate(cameraCenter, viewAngle, -viewAngle);
+ bottomLeft.rotate(cameraCenter, -viewAngle, viewAngle);
+ bottomRight.rotate(cameraCenter, viewAngle, viewAngle);
- topLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- topRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ topLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ topRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ bottomLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ bottomRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
final Color cameraColor = new Color(255, 255, 0, 255);
final LineAppearance appearance = new LineAppearance(2, cameraColor);
- // addShape(appearance.getLine(camCenter, upLeft));
- // addShape(appearance.getLine(camCenter, upRight));
- // addShape(appearance.getLine(camCenter, downLeft));
- // addShape(appearance.getLine(camCenter, downRight));
-
addShape(appearance.getLine(topLeft, topRight));
addShape(appearance.getLine(bottomLeft, bottomRight));
addShape(appearance.getLine(topLeft, bottomLeft));