1 package eu.svjatoslav.sixth.e3d.examples.life;
3 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
4 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
5 import eu.svjatoslav.sixth.e3d.math.Transform;
6 import eu.svjatoslav.sixth.e3d.gui.Avatar;
7 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
8 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
9 import eu.svjatoslav.sixth.e3d.gui.humaninput.WorldNavigationTracker;
10 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
11 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
12 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid2D;
15 import java.awt.event.KeyEvent;
18 public class Main extends WorldNavigationTracker {
20 private static final Matrix MATRIX = new Matrix(
21 new Point3D() // position matrix in the center of the scene
24 public static void main(final String[] args) {
29 * Handle keyboard input.
32 public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
33 switch (event.getKeyChar()) {
34 case ' ': // space key
40 case 'c': // reset matrix
44 super.keyPressed(event, viewContext);
50 // create application frame visible to the user
51 final ViewFrame viewFrame = new ViewFrame();
53 final ShapeCollection shapeCollection = viewFrame.getView()
54 .getContext().getRootShapeCollection();
57 shapeCollection.addShape(MATRIX);
59 // add wireframe grid (optional)
60 shapeCollection.addShape(createGrid());
62 final ViewContext context = viewFrame.getView().getContext();
64 setAvatarOrientation(context.getAvatar());
66 // enable receiving of keyboard events
67 context.getKeyboardFocusTracker().setFocusOwner(this);
69 // Done! World is built. So ensure screen is updated too.
70 context.getView().repaintDuringNextViewUpdate();
74 * Create pink wireframe grid below (for decorative purposes).
76 private Grid2D createGrid() {
79 new Point3D( // Grid positioning:
81 100, // below the main scene
85 0, // no rotation along XZ axis
86 Math.PI / 2), // face down
88 new Rectangle(800), // large enough, square grid
90 5, 5, // grid will be divided to 5x5 segments
92 new LineAppearance(3, // line thickness
93 new Color("FF000050") // red and quite transparent
99 * Set Avatar/Camera initial position in the world.
101 private void setAvatarOrientation(final Avatar avatar) {
102 avatar.setLocation(new Point3D(100, -50, -200));
103 avatar.setAngleXZ(0.2f);
104 avatar.setAngleYZ(-0.7f);