2 * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.geometry.Transform;
14 import eu.svjatoslav.sixth.e3d.gui.Avatar;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
20 import javax.imageio.ImageIO;
22 import java.awt.image.BufferedImage;
23 import java.io.IOException;
26 public class Camera extends TexturedRectangle {
28 public static final int CAMERA_SIZE = 100;
29 public static final int IMAGE_SIZE = 500;
30 private final CameraView cameraView;
31 private Point3D camCenter;
33 public Camera(final Avatar avatar, final double zoom) {
34 super(new Transform(avatar.getLocation().clone()));
35 cameraView = new CameraView(avatar, zoom);
37 computeCameraCoordinates(avatar);
39 addWaitNotification(getTexture());
42 private void addWaitNotification(final Texture texture) {
45 final BufferedImage sprite = getSprite("eu/svjatoslav/sixth/e3d/examples/hourglass.png");
46 texture.graphics.drawImage(sprite, IMAGE_SIZE / 2,
47 (IMAGE_SIZE / 2) - 30, null);
48 } catch (final Exception ignored) {
51 // add "Please wait..." message
52 texture.graphics.setColor(java.awt.Color.WHITE);
53 texture.graphics.setFont(new Font("Monospaced", Font.PLAIN, 10));
54 texture.graphics.drawString("Please wait...", (IMAGE_SIZE / 2) - 20,
55 (IMAGE_SIZE / 2) + 30);
58 private void computeCameraCoordinates(final Avatar avatar) {
59 initialize(CAMERA_SIZE, CAMERA_SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
61 camCenter = Point3D.ZERO.clone();
63 topLeft.setValues(camCenter.x, camCenter.y, camCenter.z + CAMERA_SIZE);
65 topRight.clone(topLeft);
66 bottomLeft.clone(topLeft);
67 bottomRight.clone(topLeft);
69 final float viewAngle = (float) .6;
71 topLeft.rotate(camCenter, -viewAngle, -viewAngle);
72 topRight.rotate(camCenter, viewAngle, -viewAngle);
73 bottomLeft.rotate(camCenter, -viewAngle, viewAngle);
74 bottomRight.rotate(camCenter, viewAngle, viewAngle);
76 topLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
77 topRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
79 .rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
80 bottomRight.rotate(camCenter, -avatar.getAngleXZ(),
81 -avatar.getAngleYZ());
83 final Color cameraColor = new Color(255, 255, 0, 255);
84 final LineAppearance appearance = new LineAppearance(2, cameraColor);
86 // addShape(appearance.getLine(camCenter, upLeft));
87 // addShape(appearance.getLine(camCenter, upRight));
88 // addShape(appearance.getLine(camCenter, downLeft));
89 // addShape(appearance.getLine(camCenter, downRight));
91 addShape(appearance.getLine(topLeft, topRight));
92 addShape(appearance.getLine(bottomLeft, bottomRight));
93 addShape(appearance.getLine(topLeft, bottomLeft));
94 addShape(appearance.getLine(topRight, bottomRight));
98 public CameraView getCameraView() {
102 public BufferedImage getSprite(final String ref) throws IOException {
103 final URL url = this.getClass().getClassLoader().getResource(ref);
104 return ImageIO.read(url);