/*
- * Sixth - System for data storage, computation, exploration and interaction.
- * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
+ * Sixth 3D engine demos. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ *
+*/
package eu.svjatoslav.sixth.e3d.examples;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
-import eu.svjatoslav.sixth.e3d.gui.humaninput.WorldNavigationTracker;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
+import eu.svjatoslav.sixth.e3d.gui.humaninput.WorldNavigationUserInputTracker;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume;
import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.Camera;
import eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.LightSource;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid3D;
import java.awt.event.KeyEvent;
-import java.io.IOException;
import java.util.Vector;
-public class OctreeDemo extends WorldNavigationTracker {
+public class OctreeDemo extends WorldNavigationUserInputTracker {
private static final double magnification = 5;
private final LineAppearance gridAppearance = new LineAppearance(40, new Color(255,
private final Vector<LightSource> lights = new Vector<>();
private OctreeVolume octreeVolume;
private ShapeCollection shapeCollection;
- private ViewContext context;
+ private ViewPanel viewPanel;
- public static void main(final String[] args) throws IOException {
+ public static void main(final String[] args) {
new OctreeDemo().init();
}
}
}
- private void init() throws IOException {
+ private void init() {
final ViewFrame viewFrame = new ViewFrame();
- context = viewFrame.getView().getContext();
+ viewPanel = viewFrame.getViewPanel();
- context.getAvatar().setLocation(new Point3D(0, -30, -300));
+ viewPanel.getAvatar().setLocation(new Point3D(0, -30, -300));
octreeVolume = new OctreeVolume();
- shapeCollection = context.getRootShapeCollection();
+ shapeCollection = viewPanel.getRootShapeCollection();
shapeCollection.addShape(new Grid3D(
new Point3D(-10000, -10000, -10000), new Point3D(10000, 10000,
Color.WHITE, Color.PURPLE);
shapeCollection.addShape(message);
- context.getKeyboardFocusTracker().setFocusOwner(this);
- context.getView().repaintDuringNextViewUpdate();
+ viewPanel.getKeyboardFocusStack().pushFocusOwner(this);
+ viewPanel.repaintDuringNextViewUpdate();
}
@Override
- public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
+ public boolean keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
if ('r' == event.getKeyChar()) {
raytrace();
- return;
+ return true;
}
- super.keyPressed(event, viewContext);
+ return super.keyPressed(event, viewPanel);
}
private void putPixel(final int x, final int y, final int z,
private void raytrace() {
// create and add camera object to scene
- final Camera camera = new Camera(context.getAvatar(), magnification);
+ final Camera camera = new Camera(viewPanel.getAvatar(), magnification);
shapeCollection.addShape(camera);
// initialize and start Raytracer in a separate thread
final RayTracer rayTracer = new RayTracer(camera.getTexture(),
- octreeVolume, lights, camera, context.getView());
+ octreeVolume, lights, camera, viewPanel);
final Thread thread = new Thread(rayTracer);
thread.start();
}