aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/Manager/VehicleConstants.cs113
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs213
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs392
3 files changed, 535 insertions, 183 deletions
diff --git a/OpenSim/Region/Physics/Manager/VehicleConstants.cs b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
new file mode 100644
index 0000000..97f66d3
--- /dev/null
+++ b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
@@ -0,0 +1,113 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29
30namespace OpenSim.Region.Physics.Manager
31{
32 public enum Vehicle : int
33 {
34 /// <summary>
35 /// Turns off Vehicle Support
36 /// </summary>
37 TYPE_NONE = 0,
38
39 /// <summary>
40 /// No Angular motor, High Left right friction, No Hover, Linear Deflection 1, no angular deflection
41 /// no vertical attractor, No banking, Identity rotation frame
42 /// </summary>
43 TYPE_SLED = 1,
44
45 /// <summary>
46 /// Needs Motors to be driven by timer or control events High left/right friction, No angular friction
47 /// Linear Motor wins in a second, decays in 60 seconds. Angular motor wins in a second, decays in 8/10ths of a second
48 /// linear deflection 2 seconds
49 /// Vertical Attractor locked UP
50 /// </summary>
51 TYPE_CAR = 2,
52 TYPE_BOAT = 3,
53 TYPE_AIRPLANE = 4,
54 TYPE_BALLOON = 5,
55 LINEAR_FRICTION_TIMESCALE = 16,
56 /// <summary>
57 /// vector of timescales for exponential decay of angular velocity about three axis
58 /// </summary>
59 ANGULAR_FRICTION_TIMESCALE = 17,
60 /// <summary>
61 /// linear velocity vehicle will try for
62 /// </summary>
63 LINEAR_MOTOR_DIRECTION = 18,
64
65 /// <summary>
66 /// Offset from center of mass where linear motor forces are added
67 /// </summary>
68 LINEAR_MOTOR_OFFSET = 20,
69 /// <summary>
70 /// angular velocity that vehicle will try for
71 /// </summary>
72 ANGULAR_MOTOR_DIRECTION = 19,
73 HOVER_HEIGHT = 24,
74 HOVER_EFFICIENCY = 25,
75 HOVER_TIMESCALE = 26,
76 BUOYANCY = 27,
77 LINEAR_DEFLECTION_EFFICIENCY = 28,
78 LINEAR_DEFLECTION_TIMESCALE = 29,
79 LINEAR_MOTOR_TIMESCALE = 30,
80 LINEAR_MOTOR_DECAY_TIMESCALE = 31,
81
82 /// <summary>
83 /// slide between 0 and 1
84 /// </summary>
85 ANGULAR_DEFLECTION_EFFICIENCY = 32,
86 ANGULAR_DEFLECTION_TIMESCALE = 33,
87 ANGULAR_MOTOR_TIMESCALE = 34,
88 ANGULAR_MOTOR_DECAY_TIMESCALE = 35,
89 VERTICAL_ATTRACTION_EFFICIENCY = 36,
90 VERTICAL_ATTRACTION_TIMESCALE = 37,
91 BANKING_EFFICIENCY = 38,
92 BANKING_MIX = 39,
93 BANKING_TIMESCALE = 40,
94 REFERENCE_FRAME = 44
95
96 }
97
98 [Flags]
99 public enum VehicleFlag
100 {
101 NO_DEFLECTION_UP = 1,
102 LIMIT_ROLL_ONLY = 2,
103 HOVER_WATER_ONLY = 4,
104 HOVER_TERRAIN_ONLY = 8,
105 HOVER_GLOBAL_HEIGHT = 16,
106 HOVER_UP_ONLY = 32,
107 LIMIT_MOTOR_UP = 64,
108 MOUSELOOK_STEER = 128,
109 MOUSELOOK_BANK = 256,
110 CAMERA_DECOUPLED = 512
111 }
112
113}
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 5e7ec37..8711937 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -166,10 +166,13 @@ namespace OpenSim.Region.Physics.OdePlugin
166 166
167 public volatile bool childPrim = false; 167 public volatile bool childPrim = false;
168 168
169 private ODEVehicleSettings m_vehicle;
170
169 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 171 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
170 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 172 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
171 { 173 {
172 _target_velocity = new PhysicsVector(0, 0, 0); 174 _target_velocity = new PhysicsVector(0, 0, 0);
175 m_vehicle = new ODEVehicleSettings();
173 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); 176 //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned);
174 ode = dode; 177 ode = dode;
175 _velocity = new PhysicsVector(); 178 _velocity = new PhysicsVector();
@@ -308,7 +311,10 @@ namespace OpenSim.Region.Physics.OdePlugin
308 if (!childPrim) 311 if (!childPrim)
309 { 312 {
310 if (m_isphysical && Body != IntPtr.Zero) 313 if (m_isphysical && Body != IntPtr.Zero)
314 {
311 d.BodyEnable(Body); 315 d.BodyEnable(Body);
316 m_vehicle.Enable(Body, _parent_scene);
317 }
312 318
313 m_disabled = false; 319 m_disabled = false;
314 } 320 }
@@ -319,7 +325,10 @@ namespace OpenSim.Region.Physics.OdePlugin
319 m_disabled = true; 325 m_disabled = true;
320 326
321 if (m_isphysical && Body != IntPtr.Zero) 327 if (m_isphysical && Body != IntPtr.Zero)
328 {
322 d.BodyDisable(Body); 329 d.BodyDisable(Body);
330 m_vehicle.Disable();
331 }
323 } 332 }
324 333
325 public void enableBody() 334 public void enableBody()
@@ -358,6 +367,10 @@ namespace OpenSim.Region.Physics.OdePlugin
358 { 367 {
359 createAMotor(m_angularlock); 368 createAMotor(m_angularlock);
360 } 369 }
370 if (m_vehicle.Type != Vehicle.TYPE_NONE)
371 {
372 m_vehicle.Enable(Body, _parent_scene);
373 }
361 374
362 _parent_scene.addActivePrim(this); 375 _parent_scene.addActivePrim(this);
363 } 376 }
@@ -722,7 +735,7 @@ namespace OpenSim.Region.Physics.OdePlugin
722 if (Body != IntPtr.Zero) 735 if (Body != IntPtr.Zero)
723 { 736 {
724 _parent_scene.remActivePrim(this); 737 _parent_scene.remActivePrim(this);
725 738 m_vehicle.Destroy();
726 m_collisionCategories &= ~CollisionCategories.Body; 739 m_collisionCategories &= ~CollisionCategories.Body;
727 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 740 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
728 741
@@ -925,10 +938,16 @@ namespace OpenSim.Region.Physics.OdePlugin
925 Amotor = IntPtr.Zero; 938 Amotor = IntPtr.Zero;
926 } 939 }
927 } 940 }
941
942 if (m_vehicle.Type != Vehicle.TYPE_NONE)
943 {
944 m_vehicle.Reset();
945 }
928 } 946 }
929 } 947 }
930 // Store this for later in case we get turned into a separate body 948 // Store this for later in case we get turned into a separate body
931 m_angularlock = new PhysicsVector(m_taintAngularLock.X, m_taintAngularLock.Y, m_taintAngularLock.Z); 949 m_angularlock = new PhysicsVector(m_taintAngularLock.X, m_taintAngularLock.Y, m_taintAngularLock.Z);
950
932 } 951 }
933 952
934 private void changelink(float timestep) 953 private void changelink(float timestep)
@@ -1113,7 +1132,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1113 createAMotor(m_angularlock); 1132 createAMotor(m_angularlock);
1114 } 1133 }
1115 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); 1134 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1116 1135 m_vehicle.Enable(Body, _parent_scene);
1117 _parent_scene.addActivePrim(this); 1136 _parent_scene.addActivePrim(this);
1118 } 1137 }
1119 } 1138 }
@@ -1706,6 +1725,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1706 fy = nmin; 1725 fy = nmin;
1707 d.BodyAddForce(Body, fx, fy, fz); 1726 d.BodyAddForce(Body, fx, fy, fz);
1708 } 1727 }
1728
1729 m_vehicle.Step(timestep);
1709 } 1730 }
1710 else 1731 else
1711 { 1732 {
@@ -1816,11 +1837,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1816 1837
1817 public void changesize(float timestamp) 1838 public void changesize(float timestamp)
1818 { 1839 {
1819 //if (!_parent_scene.geom_name_map.ContainsKey(prim_geom)) 1840
1820 //{
1821 // m_taintsize = _size;
1822 //return;
1823 //}
1824 string oldname = _parent_scene.geom_name_map[prim_geom]; 1841 string oldname = _parent_scene.geom_name_map[prim_geom];
1825 1842
1826 if (_size.X <= 0) _size.X = 0.01f; 1843 if (_size.X <= 0) _size.X = 0.01f;
@@ -1915,177 +1932,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1915 m_taintsize = _size; 1932 m_taintsize = _size;
1916 } 1933 }
1917 1934
1918 //public void changesize(float timestamp) 1935
1919 //{
1920 // //if (!_parent_scene.geom_name_map.ContainsKey(prim_geom))
1921 // //{
1922 // // m_taintsize = _size;
1923 // //return;
1924 // //}
1925 // string oldname = _parent_scene.geom_name_map[prim_geom];
1926
1927 // if (_size.X <= 0) _size.X = 0.01f;
1928 // if (_size.Y <= 0) _size.Y = 0.01f;
1929 // if (_size.Z <= 0) _size.Z = 0.01f;
1930
1931 // // Cleanup of old prim geometry
1932 // if (_mesh != null)
1933 // {
1934 // // Cleanup meshing here
1935 // }
1936 // //kill body to rebuild
1937 // if (IsPhysical && Body != (IntPtr) 0)
1938 // {
1939 // disableBody();
1940 // }
1941 // if (d.SpaceQuery(m_targetSpace, prim_geom))
1942 // {
1943 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
1944 // d.SpaceRemove(m_targetSpace, prim_geom);
1945 // }
1946 // d.GeomDestroy(prim_geom);
1947 // prim_geom = (IntPtr)0;
1948 // // we don't need to do space calculation because the client sends a position update also.
1949
1950 // // Construction of new prim
1951 // if (_parent_scene.needsMeshing(_pbs))
1952 // {
1953 // float meshlod = _parent_scene.meshSculptLOD;
1954
1955 // if (IsPhysical)
1956 // meshlod = _parent_scene.MeshSculptphysicalLOD;
1957 // // Don't need to re-enable body.. it's done in SetMesh
1958 // IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
1959 // // createmesh returns null when it's a shape that isn't a cube.
1960 // if (mesh != null)
1961 // {
1962 // setMesh(_parent_scene, mesh);
1963 // d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1964 // d.Quaternion myrot = new d.Quaternion();
1965 // myrot.W = _orientation.w;
1966 // myrot.X = _orientation.X;
1967 // myrot.Y = _orientation.Y;
1968 // myrot.Z = _orientation.Z;
1969 // d.GeomSetQuaternion(prim_geom, ref myrot);
1970
1971 // //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1972 // if (IsPhysical && Body == (IntPtr)0)
1973 // {
1974 // // Re creates body on size.
1975 // // EnableBody also does setMass()
1976 // enableBody();
1977 // d.BodyEnable(Body);
1978 // }
1979 // }
1980 // else
1981 // {
1982 // if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
1983 // {
1984 // if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
1985 // {
1986 // if (((_size.X / 2f) > 0f) && ((_size.X / 2f) < 1000))
1987 // {
1988 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
1989 // SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
1990 // }
1991 // else
1992 // {
1993 // m_log.Info("[PHYSICS]: Failed to load a sphere bad size");
1994 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
1995 // SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
1996 // }
1997
1998 // }
1999 // else
2000 // {
2001 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
2002 // SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
2003 // }
2004 // }
2005 // //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
2006 // //{
2007 // //Cyllinder
2008 // //if (_size.X == _size.Y)
2009 // //{
2010 // // prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
2011 // //}
2012 // //else
2013 // //{
2014 // //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
2015 // //}
2016 // //}
2017 // else
2018 // {
2019 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
2020 // SetGeom(prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
2021 // }
2022 // //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
2023 // d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2024 // d.Quaternion myrot = new d.Quaternion();
2025 // myrot.W = _orientation.w;
2026 // myrot.X = _orientation.X;
2027 // myrot.Y = _orientation.Y;
2028 // myrot.Z = _orientation.Z;
2029 // d.GeomSetQuaternion(prim_geom, ref myrot);
2030 // }
2031 // }
2032 // else
2033 // {
2034 // if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
2035 // {
2036 // if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
2037 // {
2038 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
2039 // SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
2040 // }
2041 // else
2042 // {
2043 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
2044 // SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
2045 // }
2046 // }
2047 // //else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
2048 // //{
2049 // //Cyllinder
2050 // //if (_size.X == _size.Y)
2051 // //{
2052 // //prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
2053 // //}
2054 // //else
2055 // //{
2056 // //prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
2057 // //}
2058 // //}
2059 // else
2060 // {
2061 // _parent_scene.waitForSpaceUnlock(m_targetSpace);
2062 // SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
2063 // }
2064 // d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2065 // d.Quaternion myrot = new d.Quaternion();
2066 // myrot.W = _orientation.w;
2067 // myrot.X = _orientation.X;
2068 // myrot.Y = _orientation.Y;
2069 // myrot.Z = _orientation.Z;
2070 // d.GeomSetQuaternion(prim_geom, ref myrot);
2071
2072 // //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
2073 // if (IsPhysical && Body == (IntPtr) 0)
2074 // {
2075 // // Re creates body on size.
2076 // // EnableBody also does setMass()
2077 // enableBody();
2078 // d.BodyEnable(Body);
2079 // }
2080 // }
2081
2082 // _parent_scene.geom_name_map[prim_geom] = oldname;
2083
2084 // changeSelectedStatus(timestamp);
2085
2086 // resetCollisionAccounting();
2087 // m_taintsize = _size;
2088 //}
2089 1936
2090 public void changefloatonwater(float timestep) 1937 public void changefloatonwater(float timestep)
2091 { 1938 {
@@ -2380,23 +2227,23 @@ namespace OpenSim.Region.Physics.OdePlugin
2380 2227
2381 public override int VehicleType 2228 public override int VehicleType
2382 { 2229 {
2383 get { return 0; } 2230 get { return (int)m_vehicle.Type; }
2384 set { return; } 2231 set { m_vehicle.ProcessTypeChange((Vehicle)value); }
2385 } 2232 }
2386 2233
2387 public override void VehicleFloatParam(int param, float value) 2234 public override void VehicleFloatParam(int param, float value)
2388 { 2235 {
2389 2236 m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value);
2390 } 2237 }
2391 2238
2392 public override void VehicleVectorParam(int param, PhysicsVector value) 2239 public override void VehicleVectorParam(int param, PhysicsVector value)
2393 { 2240 {
2394 2241 m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value);
2395 } 2242 }
2396 2243
2397 public override void VehicleRotationParam(int param, Quaternion rotation) 2244 public override void VehicleRotationParam(int param, Quaternion rotation)
2398 { 2245 {
2399 2246 m_vehicle.ProcessRotationVehicleParam((Vehicle) param, rotation);
2400 } 2247 }
2401 2248
2402 public override void SetVolumeDetect(int param) 2249 public override void SetVolumeDetect(int param)
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
new file mode 100644
index 0000000..c4c3044
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
@@ -0,0 +1,392 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Runtime.InteropServices;
32using log4net;
33using OpenMetaverse;
34using Ode.NET;
35using OpenSim.Framework;
36using OpenSim.Region.Physics.Manager;
37
38namespace OpenSim.Region.Physics.OdePlugin
39{
40 public class ODEVehicleSettings
41 {
42 public Vehicle Type
43 {
44 get { return m_type; }
45 }
46
47 private Vehicle m_type = Vehicle.TYPE_NONE;
48 private OdeScene m_parentScene = null;
49 private IntPtr m_body = IntPtr.Zero;
50 private IntPtr m_jointGroup = IntPtr.Zero;
51 private IntPtr m_aMotor = IntPtr.Zero;
52 private IntPtr m_lMotor = IntPtr.Zero;
53
54 // Vehicle properties
55 private Quaternion m_referenceFrame = Quaternion.Identity;
56 private Vector3 m_angularFrictionTimescale = Vector3.Zero;
57 private Vector3 m_angularMotorDirection = Vector3.Zero;
58 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
59 private Vector3 m_linearMotorDirection = Vector3.Zero;
60 private Vector3 m_linearMotorOffset = Vector3.Zero;
61 private float m_angularDeflectionEfficiency = 0;
62 private float m_angularDeflectionTimescale = 0;
63 private float m_angularMotorDecayTimescale = 0;
64 private float m_angularMotorTimescale = 0;
65 private float m_bankingEfficiency = 0;
66 private float m_bankingMix = 0;
67 private float m_bankingTimescale = 0;
68 private float m_buoyancy = 0;
69 private float m_hoverHeight = 0;
70 private float m_hoverEfficiency = 0;
71 private float m_hoverTimescale = 0;
72 private float m_linearDeflectionEfficiency = 0;
73 private float m_linearDeflectionTimescale = 0;
74 private float m_linearMotorDecayTimescale = 0;
75 private float m_linearMotorTimescale = 0;
76 private float m_verticalAttractionEfficiency = 0;
77 private float m_verticalAttractionTimescale = 0;
78 private VehicleFlag m_flags = (VehicleFlag) 0;
79
80
81
82
83 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
84 {
85 switch (pParam)
86 {
87 case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
88 m_angularDeflectionEfficiency = pValue;
89 break;
90 case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
91 m_angularDeflectionTimescale = pValue;
92 break;
93 case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
94 m_angularMotorDecayTimescale = pValue;
95 break;
96 case Vehicle.ANGULAR_MOTOR_TIMESCALE:
97 m_angularMotorTimescale = pValue;
98 break;
99 case Vehicle.BANKING_EFFICIENCY:
100 m_bankingEfficiency = pValue;
101 break;
102 case Vehicle.BANKING_MIX:
103 m_bankingMix = pValue;
104 break;
105 case Vehicle.BANKING_TIMESCALE:
106 m_bankingTimescale = pValue;
107 break;
108 case Vehicle.BUOYANCY:
109 m_buoyancy = pValue;
110 break;
111 case Vehicle.HOVER_EFFICIENCY:
112 m_hoverEfficiency = pValue;
113 break;
114 case Vehicle.HOVER_HEIGHT:
115 m_hoverHeight = pValue;
116 break;
117 case Vehicle.HOVER_TIMESCALE:
118 m_hoverTimescale = pValue;
119 break;
120 case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
121 m_linearDeflectionEfficiency = pValue;
122 break;
123 case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
124 m_linearDeflectionTimescale = pValue;
125 break;
126 case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
127 m_linearMotorDecayTimescale = pValue;
128 break;
129 case Vehicle.LINEAR_MOTOR_TIMESCALE:
130 m_linearMotorTimescale = pValue;
131 break;
132 case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
133 m_verticalAttractionEfficiency = pValue;
134 break;
135 case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
136 m_verticalAttractionTimescale = pValue;
137 break;
138
139 // These are vector properties but the engine lets you use a single float value to
140 // set all of the components to the same value
141 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
142 m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
143 break;
144 case Vehicle.ANGULAR_MOTOR_DIRECTION:
145 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
146 break;
147 case Vehicle.LINEAR_FRICTION_TIMESCALE:
148 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
149 break;
150 case Vehicle.LINEAR_MOTOR_DIRECTION:
151 m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
152 break;
153 case Vehicle.LINEAR_MOTOR_OFFSET:
154 m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
155 break;
156
157 }
158 Reset();
159 }
160
161 internal void ProcessVectorVehicleParam(Vehicle pParam, PhysicsVector pValue)
162 {
163 switch (pParam)
164 {
165 case Vehicle.ANGULAR_FRICTION_TIMESCALE:
166 m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
167 break;
168 case Vehicle.ANGULAR_MOTOR_DIRECTION:
169 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
170 break;
171 case Vehicle.LINEAR_FRICTION_TIMESCALE:
172 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
173 break;
174 case Vehicle.LINEAR_MOTOR_DIRECTION:
175 m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
176 break;
177 case Vehicle.LINEAR_MOTOR_OFFSET:
178 m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
179 break;
180 }
181 Reset();
182 }
183
184 internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
185 {
186 switch (pParam)
187 {
188 case Vehicle.REFERENCE_FRAME:
189 m_referenceFrame = pValue;
190 break;
191 }
192 Reset();
193 }
194
195 internal void ProcessTypeChange(Vehicle pType)
196 {
197 if (m_type == Vehicle.TYPE_NONE && pType != Vehicle.TYPE_NONE)
198 {
199 // Activate whatever it is
200 SetDefaultsForType(pType);
201 Reset();
202 }
203 else if (m_type != Vehicle.TYPE_NONE && pType != Vehicle.TYPE_NONE )
204 {
205 // Set properties
206 SetDefaultsForType(pType);
207 // then reset
208 Reset();
209 }
210 else if (m_type != Vehicle.TYPE_NONE && pType == Vehicle.TYPE_NONE)
211 {
212 Destroy();
213 }
214 }
215
216 internal void Disable()
217 {
218 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
219 return;
220
221 }
222
223 internal void Enable(IntPtr pBody, OdeScene pParentScene)
224 {
225 if (pBody == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
226 return;
227 m_body = pBody;
228 m_parentScene = pParentScene;
229 }
230
231 internal void Reset()
232 {
233 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
234 return;
235
236 }
237
238 internal void Destroy()
239 {
240 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
241 return;
242
243 }
244
245 internal void Step(float pTimestep)
246 {
247 if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE)
248 return;
249
250 }
251
252 private void SetDefaultsForType(Vehicle pType)
253 {
254 switch (pType)
255 {
256 case Vehicle.TYPE_SLED:
257 m_linearFrictionTimescale = new Vector3(30, 1, 1000);
258 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
259 m_linearMotorDirection = Vector3.Zero;
260 m_linearMotorTimescale = 1000;
261 m_linearMotorDecayTimescale = 120;
262 m_angularMotorDirection = Vector3.Zero;
263 m_angularMotorTimescale = 1000;
264 m_angularMotorDecayTimescale = 120;
265 m_hoverHeight = 0;
266 m_hoverEfficiency = 10;
267 m_hoverTimescale = 10;
268 m_buoyancy = 0;
269 m_linearDeflectionEfficiency = 1;
270 m_linearDeflectionTimescale = 1;
271 m_angularDeflectionEfficiency = 1;
272 m_angularDeflectionTimescale = 1000;
273 m_bankingEfficiency = 0;
274 m_bankingMix = 1;
275 m_bankingTimescale = 10;
276 m_referenceFrame = Quaternion.Identity;
277 m_flags &=
278 ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
279 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
280 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
281 break;
282 case Vehicle.TYPE_CAR:
283 m_linearFrictionTimescale = new Vector3(100, 2, 1000);
284 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
285 m_linearMotorDirection = Vector3.Zero;
286 m_linearMotorTimescale = 1;
287 m_linearMotorDecayTimescale = 60;
288 m_angularMotorDirection = Vector3.Zero;
289 m_angularMotorTimescale = 1;
290 m_angularMotorDecayTimescale = 0.8f;
291 m_hoverHeight = 0;
292 m_hoverEfficiency = 0;
293 m_hoverTimescale = 1000;
294 m_buoyancy = 0;
295 m_linearDeflectionEfficiency = 1;
296 m_linearDeflectionTimescale = 2;
297 m_angularDeflectionEfficiency = 0;
298 m_angularDeflectionTimescale = 10;
299 m_verticalAttractionEfficiency = 1;
300 m_verticalAttractionTimescale = 10;
301 m_bankingEfficiency = -0.2f;
302 m_bankingMix = 1;
303 m_bankingTimescale = 1;
304 m_referenceFrame = Quaternion.Identity;
305 m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
306 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_UP_ONLY |
307 VehicleFlag.LIMIT_MOTOR_UP);
308 break;
309 case Vehicle.TYPE_BOAT:
310 m_linearFrictionTimescale = new Vector3(10, 3, 2);
311 m_angularFrictionTimescale = new Vector3(10,10,10);
312 m_linearMotorDirection = Vector3.Zero;
313 m_linearMotorTimescale = 5;
314 m_linearMotorDecayTimescale = 60;
315 m_angularMotorDirection = Vector3.Zero;
316 m_angularMotorTimescale = 4;
317 m_angularMotorDecayTimescale = 4;
318 m_hoverHeight = 0;
319 m_hoverEfficiency = 0.5f;
320 m_hoverTimescale = 2;
321 m_buoyancy = 1;
322 m_linearDeflectionEfficiency = 0.5f;
323 m_linearDeflectionTimescale = 3;
324 m_angularDeflectionEfficiency = 0.5f;
325 m_angularDeflectionTimescale = 5;
326 m_verticalAttractionEfficiency = 0.5f;
327 m_verticalAttractionTimescale = 5;
328 m_bankingEfficiency = -0.3f;
329 m_bankingMix = 0.8f;
330 m_bankingTimescale = 1;
331 m_referenceFrame = Quaternion.Identity;
332 m_flags &= ~( VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT);
333 m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_UP_ONLY |
334 VehicleFlag.LIMIT_MOTOR_UP);
335 break;
336 case Vehicle.TYPE_AIRPLANE:
337 m_linearFrictionTimescale = new Vector3(200, 10, 5);
338 m_angularFrictionTimescale = new Vector3(20, 20, 20);
339 m_linearMotorDirection = Vector3.Zero;
340 m_linearMotorTimescale = 2;
341 m_linearMotorDecayTimescale = 60;
342 m_angularMotorDirection = Vector3.Zero;
343 m_angularMotorTimescale = 4;
344 m_angularMotorDecayTimescale = 4;
345 m_hoverHeight = 0;
346 m_hoverEfficiency = 0.5f;
347 m_hoverTimescale = 1000;
348 m_buoyancy = 0;
349 m_linearDeflectionEfficiency = 0.5f;
350 m_linearDeflectionTimescale = 3;
351 m_angularDeflectionEfficiency = 1;
352 m_angularDeflectionTimescale = 2;
353 m_verticalAttractionEfficiency = 0.9f;
354 m_verticalAttractionTimescale = 2;
355 m_bankingEfficiency = 1;
356 m_bankingMix = 0.7f;
357 m_bankingTimescale = 2;
358 m_referenceFrame = Quaternion.Identity;
359 m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
360 VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
361 m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
362 break;
363 case Vehicle.TYPE_BALLOON:
364 m_linearFrictionTimescale = new Vector3(5, 5, 5);
365 m_angularFrictionTimescale = new Vector3(10, 10, 10);
366 m_linearMotorDirection = Vector3.Zero;
367 m_linearMotorTimescale = 5;
368 m_linearMotorDecayTimescale = 60;
369 m_angularMotorDirection = Vector3.Zero;
370 m_angularMotorTimescale = 6;
371 m_angularMotorDecayTimescale = 10;
372 m_hoverHeight = 5;
373 m_hoverEfficiency = 0.8f;
374 m_hoverTimescale = 10;
375 m_buoyancy = 1;
376 m_linearDeflectionEfficiency = 0;
377 m_linearDeflectionTimescale = 5;
378 m_angularDeflectionEfficiency = 0;
379 m_angularDeflectionTimescale = 5;
380 m_verticalAttractionEfficiency = 1;
381 m_verticalAttractionTimescale = 1000;
382 m_bankingEfficiency = 0;
383 m_bankingMix = 0.7f;
384 m_bankingTimescale = 5;
385 m_referenceFrame = Quaternion.Identity;
386 m_flags = (VehicleFlag)0;
387 break;
388
389 }
390 }
391 }
392}