View Javadoc
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.test; 21 22 import org.j3d.geom.Cylinder; 23 import camera3d.Axis; 24 import javax.media.j3d.Transform3D; 25 import javax.media.j3d.TransformGroup; 26 import javax.vecmath.*; 27 import camera3d.gizmo.PointGizmo; 28 29 /*** 30 * Testing drawing of cylinders. 31 */ 32 public class DrawCylinderTest { 33 34 private NodeTester tester; 35 36 public DrawCylinderTest(){ 37 Axis axis = new Axis(); 38 39 // first point of line 40 Point3f p1 = new Point3f(0.0f,1.0f,-3.0f); 41 PointGizmo g1 = new PointGizmo(new Point3d(p1)); 42 43 44 // second point of line 45 Point3f p2 = new Point3f(2.0f,-5.0f,-1.0f); 46 PointGizmo g2 = new PointGizmo(new Point3d(p2)); 47 48 // line vector 49 Vector3f lineVector = new Vector3f(); 50 // lineVector = p2 - p1 51 lineVector.sub(p2,p1); 52 // height of cylinder 53 float height = lineVector.length(); 54 55 lineVector.normalize(); 56 57 // middle point of line segment 58 Point3f middlePoint = new Point3f(); 59 // middlePoint = p1 + 0.5*height*lineVector 60 middlePoint.scaleAdd((float)0.5*height,lineVector,p1); 61 62 // Y axis vector - which is the original 63 // orientation of the cylinder 64 Vector3f yVec = new Vector3f(0.0f,1.0f,0.0f); 65 66 // rotation axis 67 Vector3f rotAxis = new Vector3f(); 68 rotAxis.cross(yVec,lineVector); 69 rotAxis.normalize(); 70 71 // cossine of the angle between the current cylinder orientation and 72 // the desired orientation 73 double angleCos = yVec.dot(lineVector); 74 // desired rotation angle 75 double rotAngle = Math.acos(angleCos); 76 77 AxisAngle4f axisAngle = new AxisAngle4f(rotAxis,(float)rotAngle); 78 79 TransformGroup cylTG = new TransformGroup(); 80 81 Cylinder cyl = new Cylinder(height, //height 82 0.1f); //radius 83 cylTG.addChild(cyl); 84 Transform3D cylT3D = new Transform3D(); 85 // sets rotation 86 cylT3D.setRotation(axisAngle); 87 // sets translation 88 cylT3D.setTranslation(new Vector3f(middlePoint)); 89 // sets cylinder transformation 90 cylTG.setTransform(cylT3D); 91 92 93 tester = new NodeTester(); 94 tester.add(cylTG); 95 tester.add(axis.getRootGroup()); 96 tester.add(g1); 97 tester.add(g2); 98 } 99 100 public static void main(String[] args) { 101 DrawCylinderTest dcTest = new DrawCylinderTest(); 102 } 103 }

This page was automatically generated by Maven