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 cameraCenter;
}
private void computeCameraCoordinates(final Avatar avatar, final double zoom) {
- cameraCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
-
- topLeft = new Point3D(cameraCenter.x, cameraCenter.y, cameraCenter.z
- + Camera.SIZE);
- topRight = new Point3D(topLeft);
- bottomLeft = new Point3D(topLeft);
- bottomRight = new Point3D(topLeft);
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(cameraCenter, -viewAngle, -viewAngle);
- topRight.rotate(cameraCenter, viewAngle, -viewAngle);
- bottomLeft.rotate(cameraCenter, -viewAngle, viewAngle);
- bottomRight.rotate(cameraCenter, 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);
- topLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- topRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomLeft.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomRight.rotate(cameraCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
}
}