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.gui.Avatar;
6 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
7 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
8 import eu.svjatoslav.sixth.e3d.gui.humaninput.WorldNavigationUserInputTracker;
9 import eu.svjatoslav.sixth.e3d.math.Transform;
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 WorldNavigationUserInputTracker {
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 boolean keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
33 switch (event.getKeyChar()) {
34 case ' ': // space key
40 case 'c': // reset matrix
44 return super.keyPressed(event, viewPanel);
51 // create application frame visible to the user
52 final ViewFrame viewFrame = new ViewFrame();
54 final ShapeCollection shapeCollection = viewFrame.getViewPanel()
55 .getRootShapeCollection();
58 shapeCollection.addShape(MATRIX);
60 // add wire-frame grid (optional)
61 shapeCollection.addShape(createGrid());
63 final ViewPanel viewPanel = viewFrame.getViewPanel();
65 setAvatarOrientation(viewPanel.getAvatar());
67 // enable receiving of keyboard events
68 viewPanel.getKeyboardFocusStack().pushFocusOwner(this);
70 // Done! World is built. So ensure screen is updated too.
71 viewPanel.repaintDuringNextViewUpdate();
75 * Create pink wire-frame grid below (for decorative purposes).
77 private Grid2D createGrid() {
80 new Point3D( // Grid positioning:
82 100, // below the main scene
86 0, // no rotation along XZ axis
87 Math.PI / 2), // face down
89 new Rectangle(800), // large enough, square grid
91 5, 5, // grid will be divided to 5x5 segments
93 new LineAppearance(3, // line thickness
94 new Color("FF000050") // red and quite transparent
100 * Set Avatar/Camera initial position in the world.
102 private void setAvatarOrientation(final Avatar avatar) {
103 avatar.setLocation(new Point3D(100, -50, -200));
104 avatar.setAngleXZ(0.2f);
105 avatar.setAngleYZ(-0.7f);