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 public class CameraView {
13
14     Point3D cameraCenter;
15     Point3D topLeft;
16     Point3D topRight;
17     Point3D bottomLeft;
18     Point3D bottomRight;
19
20     public CameraView(final Avatar avatar, final double zoom) {
21         computeCameraCoordinates(avatar, zoom);
22     }
23
24     private void computeCameraCoordinates(final Avatar avatar, final double zoom) {
25
26         // compute camera view coordinates as if camera is at (0,0,0) and look at (0,0,1)
27         final float viewAngle = (float) .6;
28         cameraCenter = new Point3D();
29         topLeft = new Point3D(0,0, SIZE).rotate(-viewAngle, -viewAngle);
30         topRight = new Point3D(0,0, SIZE).rotate(viewAngle, -viewAngle);
31         bottomLeft = new Point3D(0,0,SIZE).rotate(-viewAngle, viewAngle);
32         bottomRight = new Point3D(0,0,SIZE).rotate(viewAngle, viewAngle);
33
34         topLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
35         topRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
36         bottomLeft.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
37         bottomRight.rotate(-avatar.getAngleXZ(), -avatar.getAngleYZ());
38
39         // place camera view at avatar location
40         avatar.getLocation().clone().scaleDown(zoom).addTo(cameraCenter, topLeft, topRight, bottomLeft, bottomRight);
41     }
42
43 }