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.gizmo;
21
22
23 import javax.vecmath.*;
24 import javax.media.j3d.*;
25 import camera3d.test.NodeTester;
26
27 /***
28 * @author Fábio de Miranda
29 * @version 1.0
30 */
31 public class SimpleLineGizmo extends SimpleBagGizmo {
32
33 private Vector3d lineVec = new Vector3d();
34 private Point3d tempP3d = new Point3d();
35 private Point3d p1;
36 private Point3d p2;
37
38 public SimpleLineGizmo(Color3b color, Point3d p1, Point3d p2) {
39 super(color);
40 this.p1 = p1;
41 this.p2 = p2;
42 buildLine(p1, p2);
43 this.addChild(shape);
44 }
45
46 public SimpleLineGizmo(Point3d p1, Point3d p2){
47 this(new Color3b((byte)127, (byte)255, (byte)0), p1, p2);
48 }
49
50 public SimpleLineGizmo(Point3d p1, Vector3d director, double length){
51 super(new Color3b((byte) 127, (byte) 255, (byte) 0));
52 lineVec.set(director);
53 lineVec.normalize();
54 tempP3d.scaleAdd(length, lineVec, p1);
55 this.p1 = p1;
56 this.p2 = tempP3d;
57 buildLine(p1, p2);
58 this.addChild(shape);
59
60 }
61
62 public void buildLine(Point3d p1, Point3d p2){
63 double[][] coordinates = {{p1.x, p1.y, p1.z}, {p2.x, p2.y, p2.z}};
64
65 LineAttributes lineAttributes;
66
67 LineArray lineArray = new LineArray(coordinates.length, LineArray.COORDINATES| LineArray.COLOR_3);
68 if (appearance!=null){
69 lineAttributes = appearance.getLineAttributes();
70 } else {
71 appearance = new Appearance();
72 lineAttributes = new LineAttributes();
73 lineAttributes.setLineWidth(2.0f);
74 appearance.setLineAttributes(lineAttributes);
75 }
76
77 for (int i=0; i<coordinates.length; i++){
78 //lineArray.setColor(i, colorArray);
79 lineArray.setColor(i, color);
80 lineArray.setCoordinate(i, coordinates[i]);
81 }
82
83 shape = new Shape3D(lineArray, appearance);
84
85 }
86
87 public static void main(String[] args) {
88 NodeTester tester = new NodeTester();
89 Point3d p1 = new Point3d(0.0, 0.0, 0.0);
90 Point3d p2 = new Point3d(5.0, 5.0, 5.0);
91 SimpleLineGizmo line = new SimpleLineGizmo(p1, p2);
92 SimplePointGizmo pt1 = new SimplePointGizmo(p1);
93 SimplePointGizmo pt2 = new SimplePointGizmo(p2);
94 tester.add(line);
95 tester.add(pt1);
96 tester.add(pt2);
97 }
98 }
This page was automatically generated by Maven