* @param angleXZ angle around XZ axis.
* @param angleYZ angle around YZ axis.
*/
- public void rotate(final Point3D center, final double angleXZ,
+ public Point3D rotate(final Point3D center, final double angleXZ,
final double angleYZ) {
final double s1 = sin(angleXZ);
final double c1 = cos(angleXZ);
x = x1 + center.x;
y = y1 + center.y;
z = z2 + center.z;
+
+ return this;
}
/**
import java.io.IOException;
import java.net.URL;
+/**
+ * Camera that sees the raytraced scene.
+ * It is represented on the scene as a textured rectangle.
+ */
public class Camera extends TexturedRectangle {
- public static final int CAMERA_SIZE = 100;
+ public static final int SIZE = 100;
public static final int IMAGE_SIZE = 500;
private final CameraView cameraView;
- private Point3D camCenter;
public Camera(final Avatar avatar, final double zoom) {
super(new Transform(avatar.getLocation().clone()));
}
private void computeCameraCoordinates(final Avatar avatar) {
- initialize(CAMERA_SIZE, CAMERA_SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
-
- camCenter = new Point3D();
+ initialize(SIZE, SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
- topLeft.setValues(camCenter.x, camCenter.y, camCenter.z + CAMERA_SIZE);
+ Point3D cameraCenter = new Point3D();
+ topLeft.setValues(cameraCenter.x, cameraCenter.y, cameraCenter.z + SIZE);
topRight.clone(topLeft);
bottomLeft.clone(topLeft);
bottomRight.clone(topLeft);
final float viewAngle = (float) .6;
- topLeft.rotate(camCenter, -viewAngle, -viewAngle);
- topRight.rotate(camCenter, viewAngle, -viewAngle);
- bottomLeft.rotate(camCenter, -viewAngle, viewAngle);
- bottomRight.rotate(camCenter, viewAngle, viewAngle);
+ topLeft.rotate(cameraCenter, -viewAngle, -viewAngle);
+ topRight.rotate(cameraCenter, viewAngle, -viewAngle);
+ bottomLeft.rotate(cameraCenter, -viewAngle, viewAngle);
+ bottomRight.rotate(cameraCenter, viewAngle, viewAngle);
- topLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- topRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ 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());
final Color cameraColor = new Color(255, 255, 0, 255);
final LineAppearance appearance = new LineAppearance(2, cameraColor);
- // addShape(appearance.getLine(camCenter, upLeft));
- // addShape(appearance.getLine(camCenter, upRight));
- // addShape(appearance.getLine(camCenter, downLeft));
- // addShape(appearance.getLine(camCenter, downRight));
-
addShape(appearance.getLine(topLeft, topRight));
addShape(appearance.getLine(bottomLeft, bottomRight));
addShape(appearance.getLine(topLeft, bottomLeft));
public class CameraView {
- Point3D camCenter;
- Point3D upLeft;
- Point3D upRight;
- Point3D downLeft;
- Point3D downRight;
+ Point3D cameraCenter;
+ Point3D topLeft;
+ Point3D topRight;
+ Point3D bottomLeft;
+ Point3D bottomRight;
public CameraView(final Avatar avatar, final double zoom) {
computeCameraCoordinates(avatar, zoom);
}
private void computeCameraCoordinates(final Avatar avatar, final double zoom) {
- camCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
+ cameraCenter = new Point3D(avatar.getLocation()).scaleDown(zoom);
- upLeft = new Point3D(camCenter.x, camCenter.y, camCenter.z
- + Camera.CAMERA_SIZE);
- upRight = new Point3D(upLeft);
- downLeft = new Point3D(upLeft);
- downRight = new Point3D(upLeft);
+ 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;
- upLeft.rotate(camCenter, -viewAngle, -viewAngle);
- upRight.rotate(camCenter, viewAngle, -viewAngle);
- downLeft.rotate(camCenter, -viewAngle, viewAngle);
- downRight.rotate(camCenter, viewAngle, viewAngle);
+ topLeft.rotate(cameraCenter, -viewAngle, -viewAngle);
+ topRight.rotate(cameraCenter, viewAngle, -viewAngle);
+ bottomLeft.rotate(cameraCenter, -viewAngle, viewAngle);
+ bottomRight.rotate(cameraCenter, viewAngle, viewAngle);
- upLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- upRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- downLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- downRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ 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());
}
}
private final Camera camera;
private final Texture texture;
private final ViewPanel viewPanel;
- private OctreeVolume octreeVolume;
- private Vector<LightSource> lights;
+ private final OctreeVolume octreeVolume;
+ private final Vector<LightSource> lights;
private int computedLights;
public RayTracer(final Texture texture, final OctreeVolume octreeVolume,
final CameraView cameraView = camera.getCameraView();
// calculate vertical vectors
- final double x1p = cameraView.downLeft.x - cameraView.upLeft.x;
- final double y1p = cameraView.downLeft.y - cameraView.upLeft.y;
- final double z1p = cameraView.downLeft.z - cameraView.upLeft.z;
+ final double x1p = cameraView.bottomLeft.x - cameraView.topLeft.x;
+ final double y1p = cameraView.bottomLeft.y - cameraView.topLeft.y;
+ final double z1p = cameraView.bottomLeft.z - cameraView.topLeft.z;
- final double x2p = cameraView.downRight.x - cameraView.upRight.x;
- final double y2p = cameraView.downRight.y - cameraView.upRight.y;
- final double z2p = cameraView.downRight.z - cameraView.upRight.z;
+ final double x2p = cameraView.bottomRight.x - cameraView.topRight.x;
+ final double y2p = cameraView.bottomRight.y - cameraView.topRight.y;
+ final double z2p = cameraView.bottomRight.z - cameraView.topRight.z;
long nextBitmapUpdate = System.currentTimeMillis()
+ PROGRESS_UPDATE_FREQUENCY_MILLIS;
for (int y = 0; y < height; y++) {
- final double cx1 = cameraView.upLeft.x + ((x1p * y) / height);
- final double cy1 = cameraView.upLeft.y + ((y1p * y) / height);
- final double cz1 = cameraView.upLeft.z + ((z1p * y) / height);
+ final double cx1 = cameraView.topLeft.x + ((x1p * y) / height);
+ final double cy1 = cameraView.topLeft.y + ((y1p * y) / height);
+ final double cz1 = cameraView.topLeft.z + ((z1p * y) / height);
- final double cx2 = cameraView.upRight.x + ((x2p * y) / height);
- final double cy2 = cameraView.upRight.y + ((y2p * y) / height);
- final double cz2 = cameraView.upRight.z + ((z2p * y) / height);
+ final double cx2 = cameraView.topRight.x + ((x2p * y) / height);
+ final double cy2 = cameraView.topRight.y + ((y2p * y) / height);
+ final double cz2 = cameraView.topRight.z + ((z2p * y) / height);
// calculate horisontal vector
final double x3p = cx2 - cx1;
final double cy3 = cy1 + ((y3p * x) / width);
final double cz3 = cz1 + ((z3p * x) / width);
- final Ray r = new Ray(cameraView.camCenter.x,
- cameraView.camCenter.y, cameraView.camCenter.z, cx3
- - cameraView.camCenter.x, cy3
- - cameraView.camCenter.y, cz3
- - cameraView.camCenter.z);
+ final Ray r = new Ray(cameraView.cameraCenter.x,
+ cameraView.cameraCenter.y, cameraView.cameraCenter.z, cx3
+ - cameraView.cameraCenter.x, cy3
+ - cameraView.cameraCenter.y, cz3
+ - cameraView.cameraCenter.z);
final int c = traceRay(r);
final Color color = new Color(c);