fa8630d51c2d1b2b582108ebc40b4d6ff279e1a3
[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.ViewFrame;
13 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
14 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.TextEditComponent;
15 import eu.svjatoslav.sixth.e3d.math.Transform;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid2D;
20
21 public class TextEditorDemo {
22
23     public static void main(final String[] args) {
24
25         final ViewFrame viewFrame = new ViewFrame();
26         final ViewPanel viewPanel = viewFrame.getViewPanel();
27
28         final ShapeCollection shapeCollection = viewFrame.getViewPanel()
29                 .getRootShapeCollection();
30
31         setAvatarLocation(viewPanel);
32
33         addGrid(shapeCollection);
34
35         addTextEditors(viewPanel, shapeCollection);
36     }
37
38     private static void addGrid(ShapeCollection shapeCollection) {
39         final Transform transform = new Transform(new Point3D(0, 100, 0), 0,
40                 Math.PI / 2);
41
42         final Rectangle rectangle = new Rectangle(2000);
43         final LineAppearance appearance = new LineAppearance(10, new Color(
44                 "00b3ad"));
45
46         shapeCollection.addShape(new Grid2D(transform, rectangle, 10, 10, appearance));
47     }
48
49     private static void addTextEditors(ViewPanel viewPanel, ShapeCollection shapeCollection) {
50         final double m = 1.5;
51         for (double z = -500 * m; z <= (500 * m); z += 250 * m)
52             for (double x = -500 * m; x <= (500 * m); x += 250 * m) {
53
54                 final TextEditComponent textEditor = new TextEditComponent(
55                         new Transform(new Point3D(x, 0, z)), viewPanel,
56                         new Point2D(200, 120));
57
58                 shapeCollection.addShape(textEditor);
59             }
60     }
61
62     private static void setAvatarLocation(ViewPanel viewPanel) {
63         viewPanel.getAvatar().setLocation(new Point3D(500, -300, -800));
64         viewPanel.getAvatar().setAngleXZ(0.6);
65         viewPanel.getAvatar().setAngleYZ(-0.5);
66     }
67 }