1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d;
21
22 /*
23 * Title: Câmera Virtual - LIVES
24 * Description: Câmera Virtual para Controle via Sockets
25 * Copyright: Copyright (c) 2001
26 * Company: Centro de Educação em Informática - SENAC - SP
27 */
28
29 import javax.media.j3d.Shape3D;
30 import javax.media.j3d.*;
31 import com.sun.j3d.*;
32 import com.sun.j3d.utils.universe.*;
33 import com.sun.j3d.utils.behaviors.keyboard.*;
34 import javax.swing.*;
35 import javax.vecmath.*;
36 import java.awt.*;
37 import java.util.Random;
38
39 /***
40 * This class assembles an 1-unit spaced grid, intended to be used as a helper
41 * The grid covers by now negative z and positive x space
42 * @author Fábio Roberto de Miranda
43 * @version 1.0
44 */
45 class TerrainGrid extends TransformGroup {
46
47 Shape3D shape;
48 LineArray lineArray;
49 int xGridLines = 50;
50 int zGridLines = 50;
51 float xUnit = 1;
52 float zUnit = 1;
53 double[][] xCoordinates;
54 double[][] zCoordinates;
55
56 Random rand = new Random();
57
58 TerrainGrid(Transform3D t) {
59 super(t);
60 shape = new Shape3D();
61 xCoordinates = new double[2*xGridLines][];
62 zCoordinates = new double[2*zGridLines][];
63 lineArray = new LineArray((2*xGridLines + 2*zGridLines), LineArray.COORDINATES| LineArray.COLOR_3);
64 Color3f blue = new Color3f(0.3f,0.3f,1.0f);
65
66 for (int i=0; i<xCoordinates.length; i++){
67 xCoordinates[i] = new double[3];
68 }
69 for (int i=0; i<zCoordinates.length; i++){
70 zCoordinates[i] = new double[3];
71 }
72
73 for (int i=0;i<(xGridLines);i=i+2) {
74 xCoordinates[i][0] = xUnit*i;
75 xCoordinates[i][1] = rand.nextDouble()*2.0;
76 xCoordinates[i][2] = 0.0;
77 xCoordinates[i+1][0] = xUnit*i;
78 xCoordinates[i+1][1] = 0.0;
79 xCoordinates[i+1][2] = -xUnit*zGridLines;
80 }
81
82 for (int i=0;i<(zGridLines);i=i+2) {
83 zCoordinates[i][0] = 0.0;
84 zCoordinates[i][1] = 0.0;
85 zCoordinates[i][2] = -zUnit*i;
86 zCoordinates[i+1][0] = zUnit*xGridLines;
87 zCoordinates[i+1][1] = rand.nextDouble()*.20;
88 zCoordinates[i+1][2] = -zUnit*i;
89 }
90 for (int i=0;i<xCoordinates.length;i++ ) {
91 lineArray.setCoordinate(i, xCoordinates[i]);
92 lineArray.setColor(i, blue);
93 }
94 for (int i=xCoordinates.length; i <(xCoordinates.length + zCoordinates.length); i++){
95 lineArray.setCoordinate(i, zCoordinates[i-xCoordinates.length]);
96 lineArray.setColor(i, blue);
97 }
98 shape.setGeometry(lineArray);
99 this.addChild(shape);
100
101 }
102
103 public static void main(String[] args) {
104 JFrame frame = new JFrame();
105 GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
106 Canvas3D canvas3d = new Canvas3D(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration( template ));
107 SimpleUniverse su = new SimpleUniverse(canvas3d);
108 TransformGroup tGroup = new TransformGroup();
109 Transform3D t3D = new Transform3D();
110 TerrainGrid grid = new TerrainGrid(t3D);
111 tGroup.addChild(grid);
112 BranchGroup bg = new BranchGroup();
113 TransformGroup vpTrans = su.getViewingPlatform().getViewPlatformTransform();
114 KeyNavigatorBehavior keynav = new KeyNavigatorBehavior(vpTrans);
115 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),1000);
116 keynav.setSchedulingBounds(bounds);
117 tGroup.addChild(keynav);
118 Color3f white = new Color3f(1.0f,1.0f,1.0f);
119 Point3f center = new Point3f(0.0f, 0.0f, 0.0f);
120 Point3f attenuation = new Point3f(0.1f,0.1f,0.1f);
121 PointLight light = new PointLight(true, white, center, attenuation);
122 tGroup.addChild(light);
123 //Background background = new Background(1.0f, 1.0f, 1.0f);
124 //background.setApplicationBounds(bounds);
125 //bg.addChild(background);
126 /*
127 vpTrans.setCapability(Group.ALLOW_CHILDREN_READ);
128 vpTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);
129 vpTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
130 vpTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
131 */
132 frame.getContentPane().add(canvas3d);
133 frame.setSize(300,300);
134 frame.setVisible(true);
135 bg.addChild(tGroup);
136 su.getLocale().addBranchGraph(bg);
137
138 }
139
140 }
This page was automatically generated by Maven