1bcdfb3a19982d75c5a9f2a0ea074c2fc310abc2
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / TextEditorDemo.java
1 /*
2  * Sixth 3D engine demos. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 */
6
7 package eu.svjatoslav.sixth.e3d.examples;
8
9 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
12 import eu.svjatoslav.sixth.e3d.gui.Avatar;
13 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
14 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
15 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.TextEditComponent;
16 import eu.svjatoslav.sixth.e3d.math.Transform;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
20 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid2D;
21
22 public class TextEditorDemo {
23
24     public static void main(final String[] args) {
25
26         final ViewFrame viewFrame = new ViewFrame();
27         final ViewPanel viewPanel = viewFrame.getViewPanel();
28
29         final ShapeCollection shapeCollection = viewFrame.getViewPanel()
30                 .getRootShapeCollection();
31
32         setAvatarLocation(viewPanel);
33
34         addGrid(shapeCollection);
35
36         addTextEditors(viewPanel, shapeCollection);
37     }
38
39     private static void addGrid(ShapeCollection shapeCollection) {
40         final Transform transform = new Transform(new Point3D(0, 100, 0), 0,
41                 Math.PI / 2);
42
43         final Rectangle rectangle = new Rectangle(2000);
44         final LineAppearance appearance = new LineAppearance(10, new Color(
45                 "00b3ad"));
46
47         shapeCollection.addShape(new Grid2D(transform, rectangle, 10, 10, appearance));
48     }
49
50     private static void addTextEditors(ViewPanel viewPanel, ShapeCollection shapeCollection) {
51         final double m = 1.5;
52         for (double z = -500 * m; z <= (500 * m); z += 250 * m)
53             for (double x = -500 * m; x <= (500 * m); x += 250 * m) {
54
55                 final TextEditComponent textEditor = new TextEditComponent(
56                         new Transform(new Point3D(x, 0, z)), viewPanel,
57                         new Point2D(200, 120));
58
59                 shapeCollection.addShape(textEditor);
60             }
61     }
62
63     private static void setAvatarLocation(ViewPanel viewPanel) {
64         Avatar avatar = viewPanel.getAvatar();
65         avatar.setLocation(new Point3D(500, -300, -800));
66         avatar.setAngleXZ(0.6);
67         avatar.setAngleYZ(-0.5);
68     }
69 }