Fixed git clone URL
[sixth-3d.git] / raytracer / CameraView.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.gui.Avatar;
14
15 public class CameraView {
16
17     Point3D camCenter;
18     Point3D upLeft;
19     Point3D upRight;
20     Point3D downLeft;
21     Point3D downRight;
22
23     public CameraView(final Avatar avatar, final double zoom) {
24         computeCameraCoordinates(avatar, zoom);
25     }
26
27     private void computeCameraCoordinates(final Avatar avatar, final double zoom) {
28         camCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
29
30         upLeft = new Point3D(camCenter.x, camCenter.y, camCenter.z
31                 + Camera.CAMERA_SIZE);
32         upRight = new Point3D(upLeft);
33         downLeft = new Point3D(upLeft);
34         downRight = new Point3D(upLeft);
35
36         final float viewAngle = (float) .6;
37
38         upLeft.rotate(camCenter, -viewAngle, -viewAngle);
39         upRight.rotate(camCenter, viewAngle, -viewAngle);
40         downLeft.rotate(camCenter, -viewAngle, viewAngle);
41         downRight.rotate(camCenter, viewAngle, viewAngle);
42
43         upLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
44         upRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
45         downLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
46         downRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
47     }
48
49 }