Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / octree / raytracer / CameraView.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.gui.Avatar;
9
10 import static eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera.SIZE;
11
12 /**
13  * Represents camera view. Used to compute direction of rays during ray tracing.
14  */
15 public class CameraView {
16
17     /**
18      * Camera view coordinates.
19      */
20     Point3D cameraCenter, topLeft, topRight, bottomLeft, bottomRight;
21
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);
30
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());
35
36         // place camera view at avatar location
37         avatar.getLocation().clone().scaleDown(zoom).addTo(cameraCenter, topLeft, topRight, bottomLeft, bottomRight);
38     }
39
40 }