1
2
3
4
5
6
7
8
9
10
11 package nl.tudelft.simulation.traffic.vehicle;
12
13 import java.awt.Color;
14 import java.rmi.RemoteException;
15 import javax.media.j3d.Bounds;
16 import javax.media.j3d.Transform3D;
17 import javax.vecmath.Point3d;
18 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
19 import nl.tudelft.simulation.dsol.simulators.AnimatorInterface;
20 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
21 import nl.tudelft.simulation.language.d3.BoundingBox;
22 import nl.tudelft.simulation.language.d3.DirectedPoint;
23 import nl.tudelft.simulation.traffic.animation.SegmentedVehicleAnimation;
24
25 /***
26 * <br>
27 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
28 * University of Technology </a>, the Netherlands. <br>
29 * See for project information <a href="http://www.simulation.tudelft.nl">
30 * www.simulation.tudelft.nl </a> <br>
31 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
32 * License (GPL) </a>, no warranty <br>
33 *
34 * @version Jun 20, 2004 <br>
35 * @author <a
36 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
37 * Verbraeck </a>
38 */
39 public class VehicleSegment implements LocatableInterface
40 {
41 /*** the vehicle */
42 private VehiclePhysicalInterface vehicle;
43
44 /*** front delta to vehicle front */
45 private double front;
46
47 /*** axle1 delta to vehicle front */
48 private double axle1;
49
50 /*** axle2 delta to vehicle front */
51 private double axle2;
52
53 /*** segment length */
54 private double length;
55
56 /***
57 * @param vehicle
58 * @param devs
59 * @param color
60 * @param front
61 * @param axle1
62 * @param axle2
63 * @param length
64 */
65 public VehicleSegment(final VehiclePhysicalInterface vehicle,
66 final DEVSSimulatorInterface devs, final Color color,
67 final double front, final double axle1, final double axle2,
68 final double length)
69 {
70 this.vehicle = vehicle;
71 this.front = front;
72 this.axle1 = axle1;
73 this.axle2 = axle2;
74 this.length = length;
75 if (devs instanceof AnimatorInterface)
76 {
77 new SegmentedVehicleAnimation(this, devs, color);
78 }
79 }
80
81 /***
82 * @return Returns the axle1.
83 */
84 public double getAxle1()
85 {
86 return this.axle1;
87 }
88
89 /***
90 * @return Returns the axle2.
91 */
92 public double getAxle2()
93 {
94 return this.axle2;
95 }
96
97 /***
98 * @return Returns the front.
99 */
100 public double getFront()
101 {
102 return this.front;
103 }
104
105 /***
106 * @return Returns the length.
107 */
108 public double getLength()
109 {
110 return this.length;
111 }
112
113 /***
114 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
115 */
116 public DirectedPoint getLocation() throws RemoteException
117 {
118 Point3d front = this.vehicle.getBackwardLocation(this.front);
119 Point3d back = this.vehicle.getBackwardLocation(this.front
120 + this.length);
121 double theta = Math.atan2(back.y - front.y, back.x - front.x);
122 return new DirectedPoint(front.x, front.y, front.z + 0.05, 0, 0, theta);
123 }
124
125 /***
126 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
127 */
128 public Bounds getBounds() throws RemoteException
129 {
130 DirectedPoint location = getLocation();
131 double width = this.vehicle.getVehicleType().getWidth();
132
133 Bounds box = new BoundingBox(new Point3d(0, -width / 2.0, 0.0),
134 new Point3d(this.length, width / 2.0, 0.0));
135 Transform3D rot = new Transform3D();
136 rot.rotZ(location.getRotZ());
137 box.transform(rot);
138 return box;
139 }
140
141 /***
142 * @return Returns the vehicle.
143 */
144 public VehiclePhysicalInterface getVehicle()
145 {
146 return this.vehicle;
147 }
148 }