/*
- * Sixth - System for data storage, computation, exploration and interaction.
- * Copyright ©2012-2016, 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 eu.svjatoslav.sixth.e3d.gui.Avatar;
+import static eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera.SIZE;
+
public class CameraView {
- Point3D camCenter;
- Point3D upLeft;
- Point3D upRight;
- Point3D downLeft;
- Point3D downRight;
+ Point3D cameraCenter;
+ Point3D topLeft;
+ Point3D topRight;
+ Point3D bottomLeft;
+ Point3D bottomRight;
public CameraView(final Avatar avatar, final double zoom) {
computeCameraCoordinates(avatar, zoom);
}
private void computeCameraCoordinates(final Avatar avatar, final double zoom) {
- camCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
-
- upLeft = new Point3D(camCenter.x, camCenter.y, camCenter.z
- + Camera.CAMERA_SIZE);
- upRight = new Point3D(upLeft);
- downLeft = new Point3D(upLeft);
- downRight = new Point3D(upLeft);
final float viewAngle = (float) .6;
+ topLeft = new Point3D(0,0, SIZE).rotate(-viewAngle, -viewAngle);
+ topRight = new Point3D(0,0, SIZE).rotate(viewAngle, -viewAngle);
+ bottomLeft = new Point3D(0,0,SIZE).rotate(-viewAngle, viewAngle);
+ bottomRight = new Point3D(0,0,SIZE).rotate(viewAngle, viewAngle);
+
+ topLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
+ topRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
+ bottomLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
+ bottomRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
+
+ // compute camera coordinates as if camera is at avatar's location and look
+ cameraCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
+ topLeft.add(cameraCenter);
+ topRight.add(cameraCenter);
+ bottomLeft.add(cameraCenter);
+ bottomRight.add(cameraCenter);
- upLeft.rotate(camCenter, -viewAngle, -viewAngle);
- upRight.rotate(camCenter, viewAngle, -viewAngle);
- downLeft.rotate(camCenter, -viewAngle, viewAngle);
- downRight.rotate(camCenter, viewAngle, viewAngle);
-
- upLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- upRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- downLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- downRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
}
}