2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.gui.Avatar;
10 import static eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera.SIZE;
13 * Represents camera view. Used to compute direction of rays during ray tracing.
15 public class CameraView {
18 * Camera view coordinates.
20 Point3D cameraCenter, topLeft, topRight, bottomLeft, bottomRight;
22 public CameraView(final Avatar avatar, final double zoom) {
23 // compute camera view coordinates as if camera is at (0,0,0) and look at (0,0,1)
24 final float viewAngle = (float) .6;
25 cameraCenter = new Point3D();
26 topLeft = new Point3D(0, 0, SIZE).rotate(-viewAngle, -viewAngle);
27 topRight = new Point3D(0, 0, SIZE).rotate(viewAngle, -viewAngle);
28 bottomLeft = new Point3D(0, 0, SIZE).rotate(-viewAngle, viewAngle);
29 bottomRight = new Point3D(0, 0, SIZE).rotate(viewAngle, viewAngle);
31 topLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
32 topRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
33 bottomLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
34 bottomRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
36 // place camera view at avatar location
37 avatar.getLocation().clone().scaleDown(zoom).addTo(cameraCenter, topLeft, topRight, bottomLeft, bottomRight);