View Javadoc

1   /*
2    * @(#) BoundingBox.java Jun 17, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.language.d3;
11  
12  import javax.media.j3d.Bounds;
13  import javax.vecmath.Point3d;
14  
15  /***
16   * <p>
17   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
18   * University of Technology </a>, the Netherlands. <br>
19   * See for project information <a
20   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22   * License (GPL) </a>, no warranty <br>
23   * 
24   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
25   *         Jacobs </a>
26   * @version 1.2 Jun 17, 2004
27   * @since 1.4
28   */
29  public class BoundingBox extends javax.media.j3d.BoundingBox
30  {
31  	/***
32  	 * constructs a new BoundingBox
33  	 */
34  	public BoundingBox()
35  	{
36  		super();
37  	}
38  
39  	/***
40  	 * constructs a new BoundingBox around [0;0;0]
41  	 * 
42  	 * @param deltaX the deltaX
43  	 * @param deltaY the deltaY
44  	 * @param deltaZ the deltaZ
45  	 */
46  	public BoundingBox(final double deltaX, final double deltaY,
47  			final double deltaZ)
48  	{
49  		super(new Point3d(-0.5 * deltaX, -0.5 * deltaY, -0.5 * deltaZ),
50  				new Point3d(0.5 * deltaX, 0.5 * deltaY, 0.5 * deltaZ));
51  		this.normalize();
52  	}
53  
54  	/***
55  	 * constructs a new BoundingBox
56  	 * 
57  	 * @param arg0 the boundaries
58  	 */
59  	public BoundingBox(final Bounds arg0)
60  	{
61  		super(arg0);
62  		this.normalize();
63  	}
64  
65  	/***
66  	 * constructs a new BoundingBox
67  	 * 
68  	 * @param arg0 the boundaries
69  	 */
70  	public BoundingBox(final Bounds[] arg0)
71  	{
72  		super(arg0);
73  		this.normalize();
74  	}
75  
76  	/***
77  	 * constructs a new BoundingBox
78  	 * 
79  	 * @param arg0 the boundaries
80  	 * @param arg1 the point
81  	 */
82  	public BoundingBox(final Point3d arg0, final Point3d arg1)
83  	{
84  		super(arg0, arg1);
85  		this.normalize();
86  	}
87  
88  	/***
89  	 * normalizes the boundingBox
90  	 */
91  	public void normalize()
92  	{
93  		Point3d p1 = new Point3d();
94  		Point3d p2 = new Point3d();
95  		this.getLower(p1);
96  		this.getUpper(p2);
97  		this.setLower(new Point3d(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y),
98  				Math.min(p1.z, p2.z)));
99  		this.setUpper(new Point3d(Math.max(p1.x, p2.x), Math.max(p1.y, p2.y),
100 				Math.max(p1.z, p2.z)));
101 	}
102 }