diff options
author | KittoFlora | 2009-10-27 22:42:55 +0100 |
---|---|---|
committer | KittoFlora | 2009-10-27 22:42:55 +0100 |
commit | 1113b3b6ebba3e358326a7be90b338d8c95af688 (patch) | |
tree | d923340600e5a2699ceaceeb52fd6c45994f334a /OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |
parent | llRotLookAt Pt 2 (diff) | |
parent | Merge branch 'master' into vehicles (diff) | |
download | opensim-SC_OLD-1113b3b6ebba3e358326a7be90b338d8c95af688.zip opensim-SC_OLD-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.gz opensim-SC_OLD-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.bz2 opensim-SC_OLD-1113b3b6ebba3e358326a7be90b338d8c95af688.tar.xz |
Merge branch 'vehicles' into tests
Conflicts:
OpenSim/Region/Physics/Manager/PhysicsActor.cs
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODEPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 304 |
1 files changed, 163 insertions, 141 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 93c9a44..62c5c81 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -1,7 +1,5 @@ | |||
1 | /* | 1 | /* Copyright (c) Contributors, http://opensimulator.org/ |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 2 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | 3 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 4 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 5 | * * Redistributions of source code must retain the above copyright |
@@ -36,6 +34,20 @@ | |||
36 | * switch between 'VEHICLE' parameter use and general dynamics | 34 | * switch between 'VEHICLE' parameter use and general dynamics |
37 | * settings use. | 35 | * settings use. |
38 | */ | 36 | */ |
37 | |||
38 | /* | ||
39 | * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces | ||
40 | * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised: | ||
41 | * ODEPrim.cs contains methods dealing with Prim editing, Prim | ||
42 | * characteristics and Kinetic motion. | ||
43 | * ODEDynamics.cs contains methods dealing with Prim Physical motion | ||
44 | * (dynamics) and the associated settings. Old Linear and angular | ||
45 | * motors for dynamic motion have been replace with MoveLinear() | ||
46 | * and MoveAngular(); 'Physical' is used only to switch ODE dynamic | ||
47 | * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to | ||
48 | * switch between 'VEHICLE' parameter use and general dynamics | ||
49 | * settings use. | ||
50 | */ | ||
39 | using System; | 51 | using System; |
40 | using System.Collections.Generic; | 52 | using System.Collections.Generic; |
41 | using System.Reflection; | 53 | using System.Reflection; |
@@ -57,29 +69,28 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
57 | { | 69 | { |
58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 70 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
59 | 71 | ||
60 | private PhysicsVector _position; | 72 | private Vector3 _position; |
61 | private PhysicsVector _velocity; | 73 | private Vector3 _velocity; |
62 | private PhysicsVector _torque = new PhysicsVector(0,0,0); | 74 | private Vector3 _torque; |
63 | private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); | 75 | private Vector3 m_lastVelocity; |
64 | private PhysicsVector m_lastposition = new PhysicsVector(0.0f, 0.0f, 0.0f); | 76 | private Vector3 m_lastposition; |
65 | private Quaternion m_lastorientation = new Quaternion(); | 77 | private Quaternion m_lastorientation = new Quaternion(); |
66 | private PhysicsVector m_rotationalVelocity; | 78 | private Vector3 m_rotationalVelocity; |
67 | private PhysicsVector _size; | 79 | private Vector3 _size; |
68 | private PhysicsVector _acceleration; | 80 | private Vector3 _acceleration; |
69 | // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f); | 81 | // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f); |
70 | private Quaternion _orientation; | 82 | private Quaternion _orientation; |
71 | private PhysicsVector m_taintposition; | 83 | private Vector3 m_taintposition; |
72 | private PhysicsVector m_taintsize; | 84 | private Vector3 m_taintsize; |
73 | private PhysicsVector m_taintVelocity = new PhysicsVector(0, 0, 0); | 85 | private Vector3 m_taintVelocity; |
74 | private PhysicsVector m_taintTorque = new PhysicsVector(0, 0, 0); | 86 | private Vector3 m_taintTorque; |
75 | private Quaternion m_taintrot; | 87 | private Quaternion m_taintrot; |
76 | private PhysicsVector m_angularlock = new PhysicsVector(1f, 1f, 1f); | 88 | private Vector3 m_angularlock = Vector3.One; |
77 | private PhysicsVector m_taintAngularLock = new PhysicsVector(1f, 1f, 1f); | 89 | private Vector3 m_taintAngularLock = Vector3.One; |
78 | private IntPtr Amotor = IntPtr.Zero; | 90 | private IntPtr Amotor = IntPtr.Zero; |
79 | 91 | ||
80 | private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); | 92 | private Vector3 m_PIDTarget; |
81 | // private PhysicsVector m_taintPIDTarget = new PhysicsVector(0, 0, 0); | 93 | private float m_PIDTau; |
82 | private float m_PIDTau = 0f; | ||
83 | private float PID_D = 35f; | 94 | private float PID_D = 35f; |
84 | private float PID_G = 25f; | 95 | private float PID_G = 25f; |
85 | private bool m_usePID = false; | 96 | private bool m_usePID = false; |
@@ -91,15 +102,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
91 | 102 | ||
92 | // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), | 103 | // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), |
93 | // and are for non-VEHICLES only. | 104 | // and are for non-VEHICLES only. |
94 | 105 | ||
95 | private float m_PIDHoverHeight = 0f; | 106 | private float m_PIDHoverHeight; |
96 | private float m_PIDHoverTau = 0f; | 107 | private float m_PIDHoverTau; |
97 | private bool m_useHoverPID = false; | 108 | private bool m_useHoverPID; |
98 | private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; | 109 | private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; |
110 | <<<<<<< HEAD:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | ||
99 | private float m_targetHoverHeight = 0f; | 111 | private float m_targetHoverHeight = 0f; |
100 | private float m_groundHeight = 0f; | 112 | private float m_groundHeight = 0f; |
101 | private float m_waterHeight = 0f; | 113 | private float m_waterHeight = 0f; |
102 | private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles. | 114 | private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles. |
115 | ======= | ||
116 | private float m_targetHoverHeight; | ||
117 | private float m_groundHeight; | ||
118 | private float m_waterHeight; | ||
119 | private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. | ||
120 | >>>>>>> vehicles:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | ||
103 | 121 | ||
104 | // private float m_tensor = 5f; | 122 | // private float m_tensor = 5f; |
105 | private int body_autodisable_frames = 20; | 123 | private int body_autodisable_frames = 20; |
@@ -110,11 +128,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
110 | | CollisionCategories.Body | 128 | | CollisionCategories.Body |
111 | | CollisionCategories.Character | 129 | | CollisionCategories.Character |
112 | ); | 130 | ); |
113 | private bool m_taintshape = false; | 131 | private bool m_taintshape; |
114 | private bool m_taintPhysics = false; | 132 | private bool m_taintPhysics; |
115 | private bool m_collidesLand = true; | 133 | private bool m_collidesLand = true; |
116 | private bool m_collidesWater = false; | 134 | private bool m_collidesWater; |
117 | public bool m_returnCollisions = false; | 135 | public bool m_returnCollisions; |
118 | 136 | ||
119 | // Default we're a Geometry | 137 | // Default we're a Geometry |
120 | private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); | 138 | private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); |
@@ -122,69 +140,68 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
122 | // Default, Collide with Other Geometries, spaces and Bodies | 140 | // Default, Collide with Other Geometries, spaces and Bodies |
123 | private CollisionCategories m_collisionFlags = m_default_collisionFlags; | 141 | private CollisionCategories m_collisionFlags = m_default_collisionFlags; |
124 | 142 | ||
125 | public bool m_taintremove = false; | 143 | public bool m_taintremove; |
126 | public bool m_taintdisable = false; | 144 | public bool m_taintdisable; |
127 | public bool m_disabled = false; | 145 | public bool m_disabled; |
128 | public bool m_taintadd = false; | 146 | public bool m_taintadd; |
129 | public bool m_taintselected = false; | 147 | public bool m_taintselected; |
130 | public bool m_taintCollidesWater = false; | 148 | public bool m_taintCollidesWater; |
131 | 149 | ||
132 | public uint m_localID = 0; | 150 | public uint m_localID; |
133 | 151 | ||
134 | //public GCHandle gc; | 152 | //public GCHandle gc; |
135 | private CollisionLocker ode; | 153 | private CollisionLocker ode; |
136 | 154 | ||
137 | private bool m_taintforce = false; | 155 | private bool m_taintforce = false; |
138 | private bool m_taintaddangularforce = false; | 156 | private bool m_taintaddangularforce = false; |
139 | private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f); | 157 | private Vector3 m_force; |
140 | private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); | 158 | private List<Vector3> m_forcelist = new List<Vector3>(); |
141 | private List<PhysicsVector> m_angularforcelist = new List<PhysicsVector>(); | 159 | private List<Vector3> m_angularforcelist = new List<Vector3>(); |
142 | 160 | ||
143 | private IMesh _mesh; | 161 | private IMesh _mesh; |
144 | private PrimitiveBaseShape _pbs; | 162 | private PrimitiveBaseShape _pbs; |
145 | private OdeScene _parent_scene; | 163 | private OdeScene _parent_scene; |
146 | public IntPtr m_targetSpace = (IntPtr) 0; | 164 | public IntPtr m_targetSpace = IntPtr.Zero; |
147 | public IntPtr prim_geom; | 165 | public IntPtr prim_geom; |
148 | public IntPtr prev_geom; | 166 | public IntPtr prev_geom; |
149 | public IntPtr _triMeshData; | 167 | public IntPtr _triMeshData; |
150 | 168 | ||
151 | private IntPtr _linkJointGroup = (IntPtr)0; | 169 | private IntPtr _linkJointGroup = IntPtr.Zero; |
152 | private PhysicsActor _parent = null; | 170 | private PhysicsActor _parent; |
153 | private PhysicsActor m_taintparent = null; | 171 | private PhysicsActor m_taintparent; |
154 | 172 | ||
155 | private List<OdePrim> childrenPrim = new List<OdePrim>(); | 173 | private List<OdePrim> childrenPrim = new List<OdePrim>(); |
156 | 174 | ||
157 | private bool iscolliding = false; | 175 | private bool iscolliding; |
158 | private bool m_isphysical = false; | 176 | private bool m_isphysical; |
159 | private bool m_isSelected = false; | 177 | private bool m_isSelected; |
160 | 178 | ||
161 | internal bool m_isVolumeDetect = false; // If true, this prim only detects collisions but doesn't collide actively | 179 | internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively |
162 | 180 | ||
163 | private bool m_throttleUpdates = false; | 181 | private bool m_throttleUpdates; |
164 | private int throttleCounter = 0; | 182 | private int throttleCounter; |
165 | public int m_interpenetrationcount = 0; | 183 | public int m_interpenetrationcount; |
166 | public float m_collisionscore = 0; | 184 | public float m_collisionscore; |
167 | public int m_roundsUnderMotionThreshold = 0; | 185 | public int m_roundsUnderMotionThreshold; |
168 | private int m_crossingfailures = 0; | 186 | private int m_crossingfailures; |
169 | 187 | ||
170 | public bool outofBounds = false; | 188 | public bool outofBounds; |
171 | private float m_density = 10.000006836f; // Aluminum g/cm3; | 189 | private float m_density = 10.000006836f; // Aluminum g/cm3; |
172 | 190 | ||
173 | public bool _zeroFlag = false; | 191 | public bool _zeroFlag; |
174 | private bool m_lastUpdateSent = false; | 192 | private bool m_lastUpdateSent; |
175 | 193 | ||
176 | public IntPtr Body = (IntPtr) 0; | 194 | public IntPtr Body = IntPtr.Zero; |
177 | public String m_primName; | 195 | public String m_primName; |
178 | // private String m_primName; | 196 | private Vector3 _target_velocity; |
179 | private PhysicsVector _target_velocity; | ||
180 | public d.Mass pMass; | 197 | public d.Mass pMass; |
181 | 198 | ||
182 | public int m_eventsubscription = 0; | 199 | public int m_eventsubscription; |
183 | private CollisionEventUpdate CollisionEventsThisFrame = null; | 200 | private CollisionEventUpdate CollisionEventsThisFrame; |
184 | 201 | ||
185 | private IntPtr m_linkJoint = (IntPtr)0; | 202 | private IntPtr m_linkJoint = IntPtr.Zero; |
186 | 203 | ||
187 | public volatile bool childPrim = false; | 204 | public volatile bool childPrim; |
188 | 205 | ||
189 | private ODEDynamics m_vehicle; | 206 | private ODEDynamics m_vehicle; |
190 | 207 | ||
@@ -193,17 +210,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
193 | private int frcount = 0; // Used to limit dynamics debug output to | 210 | private int frcount = 0; // Used to limit dynamics debug output to |
194 | 211 | ||
195 | 212 | ||
196 | public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, | 213 | public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, |
197 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) | 214 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) |
198 | { | 215 | { |
199 | _target_velocity = new PhysicsVector(0, 0, 0); | ||
200 | m_vehicle = new ODEDynamics(); | 216 | m_vehicle = new ODEDynamics(); |
201 | //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); | 217 | //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned); |
202 | ode = dode; | 218 | ode = dode; |
203 | _velocity = new PhysicsVector(); | 219 | if (!pos.IsFinite()) |
204 | if (!PhysicsVector.isFinite(pos)) | ||
205 | { | 220 | { |
206 | pos = new PhysicsVector(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), parent_scene.GetTerrainHeightAtXY(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f)) + 0.5f); | 221 | pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), |
222 | parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f); | ||
207 | m_log.Warn("[PHYSICS]: Got nonFinite Object create Position"); | 223 | m_log.Warn("[PHYSICS]: Got nonFinite Object create Position"); |
208 | } | 224 | } |
209 | _position = pos; | 225 | _position = pos; |
@@ -218,9 +234,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
218 | prim_geom = IntPtr.Zero; | 234 | prim_geom = IntPtr.Zero; |
219 | prev_geom = IntPtr.Zero; | 235 | prev_geom = IntPtr.Zero; |
220 | 236 | ||
221 | if (!PhysicsVector.isFinite(pos)) | 237 | if (!pos.IsFinite()) |
222 | { | 238 | { |
223 | size = new PhysicsVector(0.5f, 0.5f, 0.5f); | 239 | size = new Vector3(0.5f, 0.5f, 0.5f); |
224 | m_log.Warn("[PHYSICS]: Got nonFinite Object create Size"); | 240 | m_log.Warn("[PHYSICS]: Got nonFinite Object create Size"); |
225 | } | 241 | } |
226 | 242 | ||
@@ -230,8 +246,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
230 | 246 | ||
231 | _size = size; | 247 | _size = size; |
232 | m_taintsize = _size; | 248 | m_taintsize = _size; |
233 | _acceleration = new PhysicsVector(); | ||
234 | m_rotationalVelocity = PhysicsVector.Zero; | ||
235 | 249 | ||
236 | if (!QuaternionIsFinite(rotation)) | 250 | if (!QuaternionIsFinite(rotation)) |
237 | { | 251 | { |
@@ -396,7 +410,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
396 | m_disabled = false; | 410 | m_disabled = false; |
397 | 411 | ||
398 | // The body doesn't already have a finite rotation mode set here | 412 | // The body doesn't already have a finite rotation mode set here |
399 | if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) | 413 | if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0.0f)) && _parent == null) |
400 | { | 414 | { |
401 | createAMotor(m_angularlock); | 415 | createAMotor(m_angularlock); |
402 | } | 416 | } |
@@ -809,6 +823,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
809 | m_collisionscore = 0; | 823 | m_collisionscore = 0; |
810 | } | 824 | } |
811 | 825 | ||
826 | private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>(); | ||
827 | |||
812 | public void setMesh(OdeScene parent_scene, IMesh mesh) | 828 | public void setMesh(OdeScene parent_scene, IMesh mesh) |
813 | { | 829 | { |
814 | // This sleeper is there to moderate how long it takes between | 830 | // This sleeper is there to moderate how long it takes between |
@@ -840,19 +856,24 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
840 | mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage | 856 | mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage |
841 | 857 | ||
842 | mesh.releaseSourceMeshData(); // free up the original mesh data to save memory | 858 | mesh.releaseSourceMeshData(); // free up the original mesh data to save memory |
859 | if (m_MeshToTriMeshMap.ContainsKey(mesh)) | ||
860 | { | ||
861 | _triMeshData = m_MeshToTriMeshMap[mesh]; | ||
862 | } | ||
863 | else | ||
864 | { | ||
865 | _triMeshData = d.GeomTriMeshDataCreate(); | ||
843 | 866 | ||
844 | _triMeshData = d.GeomTriMeshDataCreate(); | 867 | d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); |
845 | 868 | d.GeomTriMeshDataPreprocess(_triMeshData); | |
846 | d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); | 869 | m_MeshToTriMeshMap[mesh] = _triMeshData; |
847 | d.GeomTriMeshDataPreprocess(_triMeshData); | 870 | } |
848 | 871 | ||
849 | _parent_scene.waitForSpaceUnlock(m_targetSpace); | 872 | _parent_scene.waitForSpaceUnlock(m_targetSpace); |
850 | |||
851 | try | 873 | try |
852 | { | 874 | { |
853 | if (prim_geom == IntPtr.Zero) | 875 | if (prim_geom == IntPtr.Zero) |
854 | { | 876 | { |
855 | //Console.WriteLine(" setMesh 1"); | ||
856 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); | 877 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); |
857 | } | 878 | } |
858 | } | 879 | } |
@@ -862,6 +883,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
862 | return; | 883 | return; |
863 | } | 884 | } |
864 | 885 | ||
886 | |||
865 | // if (IsPhysical && Body == (IntPtr) 0) | 887 | // if (IsPhysical && Body == (IntPtr) 0) |
866 | // { | 888 | // { |
867 | // Recreate the body | 889 | // Recreate the body |
@@ -882,7 +904,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
882 | 904 | ||
883 | if (prim_geom != IntPtr.Zero) | 905 | if (prim_geom != IntPtr.Zero) |
884 | { | 906 | { |
885 | if (!_position.IsIdentical(m_taintposition,0f)) | 907 | if (!_position.ApproxEquals(m_taintposition, 0f)) |
886 | changemove(timestep); | 908 | changemove(timestep); |
887 | 909 | ||
888 | if (m_taintrot != _orientation) | 910 | if (m_taintrot != _orientation) |
@@ -907,7 +929,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
907 | changePhysicsStatus(timestep); | 929 | changePhysicsStatus(timestep); |
908 | // | 930 | // |
909 | 931 | ||
910 | if (!_size.IsIdentical(m_taintsize,0)) | 932 | if (!_size.ApproxEquals(m_taintsize,0f)) |
911 | changesize(timestep); | 933 | changesize(timestep); |
912 | // | 934 | // |
913 | 935 | ||
@@ -921,7 +943,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
921 | if (m_taintaddangularforce) | 943 | if (m_taintaddangularforce) |
922 | changeAddAngularForce(timestep); | 944 | changeAddAngularForce(timestep); |
923 | 945 | ||
924 | if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f)) | 946 | if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) |
925 | changeSetTorque(timestep); | 947 | changeSetTorque(timestep); |
926 | 948 | ||
927 | if (m_taintdisable) | 949 | if (m_taintdisable) |
@@ -930,7 +952,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
930 | if (m_taintselected != m_isSelected) | 952 | if (m_taintselected != m_isSelected) |
931 | changeSelectedStatus(timestep); | 953 | changeSelectedStatus(timestep); |
932 | 954 | ||
933 | if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f)) | 955 | if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) |
934 | changevelocity(timestep); | 956 | changevelocity(timestep); |
935 | 957 | ||
936 | if (m_taintparent != _parent) | 958 | if (m_taintparent != _parent) |
@@ -939,7 +961,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
939 | if (m_taintCollidesWater != m_collidesWater) | 961 | if (m_taintCollidesWater != m_collidesWater) |
940 | changefloatonwater(timestep); | 962 | changefloatonwater(timestep); |
941 | 963 | ||
942 | if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) | 964 | if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f)) |
943 | changeAngularLock(timestep); | 965 | changeAngularLock(timestep); |
944 | 966 | ||
945 | } | 967 | } |
@@ -959,7 +981,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
959 | //If we have a parent then we're not authorative here | 981 | //If we have a parent then we're not authorative here |
960 | if (_parent == null) | 982 | if (_parent == null) |
961 | { | 983 | { |
962 | if (!m_taintAngularLock.IsIdentical(new PhysicsVector(1f,1f,1f), 0)) | 984 | if (!m_taintAngularLock.ApproxEquals(Vector3.One, 0f)) |
963 | { | 985 | { |
964 | //d.BodySetFiniteRotationMode(Body, 0); | 986 | //d.BodySetFiniteRotationMode(Body, 0); |
965 | //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z); | 987 | //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z); |
@@ -976,7 +998,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
976 | } | 998 | } |
977 | } | 999 | } |
978 | // Store this for later in case we get turned into a separate body | 1000 | // Store this for later in case we get turned into a separate body |
979 | m_angularlock = new PhysicsVector(m_taintAngularLock.X, m_taintAngularLock.Y, m_taintAngularLock.Z); | 1001 | m_angularlock = m_taintAngularLock; |
980 | 1002 | ||
981 | } | 1003 | } |
982 | 1004 | ||
@@ -1120,7 +1142,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1120 | prm.m_disabled = false; | 1142 | prm.m_disabled = false; |
1121 | 1143 | ||
1122 | // The body doesn't already have a finite rotation mode set here | 1144 | // The body doesn't already have a finite rotation mode set here |
1123 | if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) | 1145 | if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) |
1124 | { | 1146 | { |
1125 | prm.createAMotor(m_angularlock); | 1147 | prm.createAMotor(m_angularlock); |
1126 | } | 1148 | } |
@@ -1163,7 +1185,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1163 | m_disabled = false; | 1185 | m_disabled = false; |
1164 | 1186 | ||
1165 | // The body doesn't already have a finite rotation mode set here | 1187 | // The body doesn't already have a finite rotation mode set here |
1166 | if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) | 1188 | if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) |
1167 | { | 1189 | { |
1168 | createAMotor(m_angularlock); | 1190 | createAMotor(m_angularlock); |
1169 | } | 1191 | } |
@@ -1347,7 +1369,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1347 | m_taintshape = false; | 1369 | m_taintshape = false; |
1348 | m_taintforce = false; | 1370 | m_taintforce = false; |
1349 | m_taintdisable = false; | 1371 | m_taintdisable = false; |
1350 | m_taintVelocity = PhysicsVector.Zero; | 1372 | m_taintVelocity = Vector3.Zero; |
1351 | } | 1373 | } |
1352 | 1374 | ||
1353 | public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) | 1375 | public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) |
@@ -1580,7 +1602,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle | |||
1580 | { | 1602 | { |
1581 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 | 1603 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 |
1582 | // NON-'VEHICLES' are dealt with here | 1604 | // NON-'VEHICLES' are dealt with here |
1583 | if (d.BodyIsEnabled(Body) && !m_angularlock.IsIdentical(PhysicsVector.Zero, 0.003f)) | 1605 | if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f)) |
1584 | { | 1606 | { |
1585 | d.Vector3 avel2 = d.BodyGetAngularVel(Body); | 1607 | d.Vector3 avel2 = d.BodyGetAngularVel(Body); |
1586 | if (m_angularlock.X == 1) | 1608 | if (m_angularlock.X == 1) |
@@ -1634,7 +1656,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle | |||
1634 | 1656 | ||
1635 | d.Vector3 pos = d.BodyGetPosition(Body); | 1657 | d.Vector3 pos = d.BodyGetPosition(Body); |
1636 | _target_velocity = | 1658 | _target_velocity = |
1637 | new PhysicsVector( | 1659 | new Vector3( |
1638 | (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), | 1660 | (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), |
1639 | (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), | 1661 | (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), |
1640 | (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) | 1662 | (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) |
@@ -1642,7 +1664,7 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle | |||
1642 | 1664 | ||
1643 | // if velocity is zero, use position control; otherwise, velocity control | 1665 | // if velocity is zero, use position control; otherwise, velocity control |
1644 | 1666 | ||
1645 | if (_target_velocity.IsIdentical(PhysicsVector.Zero,0.1f)) | 1667 | if (_target_velocity.ApproxEquals(Vector3.Zero,0.1f)) |
1646 | { | 1668 | { |
1647 | // keep track of where we stopped. No more slippin' & slidin' | 1669 | // keep track of where we stopped. No more slippin' & slidin' |
1648 | 1670 | ||
@@ -1727,13 +1749,13 @@ if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle | |||
1727 | 1749 | ||
1728 | 1750 | ||
1729 | _target_velocity = | 1751 | _target_velocity = |
1730 | new PhysicsVector(0.0f, 0.0f, | 1752 | new Vector3(0.0f, 0.0f, |
1731 | (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) | 1753 | (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) |
1732 | ); | 1754 | ); |
1733 | 1755 | ||
1734 | // if velocity is zero, use position control; otherwise, velocity control | 1756 | // if velocity is zero, use position control; otherwise, velocity control |
1735 | 1757 | ||
1736 | if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) | 1758 | if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f)) |
1737 | { | 1759 | { |
1738 | // keep track of where we stopped. No more slippin' & slidin' | 1760 | // keep track of where we stopped. No more slippin' & slidin' |
1739 | 1761 | ||
@@ -1860,7 +1882,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
1860 | d.BodySetQuaternion(Body, ref myrot); | 1882 | d.BodySetQuaternion(Body, ref myrot); |
1861 | if (m_isphysical) | 1883 | if (m_isphysical) |
1862 | { | 1884 | { |
1863 | if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) | 1885 | if (!m_angularlock.ApproxEquals(Vector3.One, 0f)) |
1864 | createAMotor(m_angularlock); | 1886 | createAMotor(m_angularlock); |
1865 | } | 1887 | } |
1866 | } | 1888 | } |
@@ -2169,7 +2191,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2169 | //m_log.Info("[PHYSICS]: dequeing forcelist"); | 2191 | //m_log.Info("[PHYSICS]: dequeing forcelist"); |
2170 | if (IsPhysical) | 2192 | if (IsPhysical) |
2171 | { | 2193 | { |
2172 | PhysicsVector iforce = new PhysicsVector(); | 2194 | Vector3 iforce = Vector3.Zero; |
2173 | for (int i = 0; i < m_forcelist.Count; i++) | 2195 | for (int i = 0; i < m_forcelist.Count; i++) |
2174 | { | 2196 | { |
2175 | iforce = iforce + (m_forcelist[i] * 100); | 2197 | iforce = iforce + (m_forcelist[i] * 100); |
@@ -2199,8 +2221,8 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2199 | d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z); | 2221 | d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z); |
2200 | } | 2222 | } |
2201 | } | 2223 | } |
2202 | 2224 | ||
2203 | m_taintTorque = new PhysicsVector(0, 0, 0); | 2225 | m_taintTorque = Vector3.Zero; |
2204 | } | 2226 | } |
2205 | 2227 | ||
2206 | public void changeAddAngularForce(float timestamp) | 2228 | public void changeAddAngularForce(float timestamp) |
@@ -2212,7 +2234,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2212 | //m_log.Info("[PHYSICS]: dequeing forcelist"); | 2234 | //m_log.Info("[PHYSICS]: dequeing forcelist"); |
2213 | if (IsPhysical) | 2235 | if (IsPhysical) |
2214 | { | 2236 | { |
2215 | PhysicsVector iforce = new PhysicsVector(); | 2237 | Vector3 iforce = Vector3.Zero; |
2216 | for (int i = 0; i < m_angularforcelist.Count; i++) | 2238 | for (int i = 0; i < m_angularforcelist.Count; i++) |
2217 | { | 2239 | { |
2218 | iforce = iforce + (m_angularforcelist[i] * 100); | 2240 | iforce = iforce + (m_angularforcelist[i] * 100); |
@@ -2246,7 +2268,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2246 | 2268 | ||
2247 | //resetCollisionAccounting(); | 2269 | //resetCollisionAccounting(); |
2248 | } | 2270 | } |
2249 | m_taintVelocity = PhysicsVector.Zero; | 2271 | m_taintVelocity = Vector3.Zero; |
2250 | } | 2272 | } |
2251 | 2273 | ||
2252 | public override bool IsPhysical | 2274 | public override bool IsPhysical |
@@ -2255,7 +2277,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2255 | set { | 2277 | set { |
2256 | m_isphysical = value; | 2278 | m_isphysical = value; |
2257 | if (!m_isphysical) // Zero the remembered last velocity | 2279 | if (!m_isphysical) // Zero the remembered last velocity |
2258 | m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); | 2280 | m_lastVelocity = Vector3.Zero; |
2259 | } | 2281 | } |
2260 | } | 2282 | } |
2261 | 2283 | ||
@@ -2300,7 +2322,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2300 | get { return _zeroFlag; } | 2322 | get { return _zeroFlag; } |
2301 | } | 2323 | } |
2302 | 2324 | ||
2303 | public override PhysicsVector Position | 2325 | public override Vector3 Position |
2304 | { | 2326 | { |
2305 | get { return _position; } | 2327 | get { return _position; } |
2306 | 2328 | ||
@@ -2309,12 +2331,12 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2309 | } | 2331 | } |
2310 | } | 2332 | } |
2311 | 2333 | ||
2312 | public override PhysicsVector Size | 2334 | public override Vector3 Size |
2313 | { | 2335 | { |
2314 | get { return _size; } | 2336 | get { return _size; } |
2315 | set | 2337 | set |
2316 | { | 2338 | { |
2317 | if (PhysicsVector.isFinite(value)) | 2339 | if (value.IsFinite()) |
2318 | { | 2340 | { |
2319 | _size = value; | 2341 | _size = value; |
2320 | } | 2342 | } |
@@ -2330,13 +2352,13 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2330 | get { return CalculateMass(); } | 2352 | get { return CalculateMass(); } |
2331 | } | 2353 | } |
2332 | 2354 | ||
2333 | public override PhysicsVector Force | 2355 | public override Vector3 Force |
2334 | { | 2356 | { |
2335 | //get { return PhysicsVector.Zero; } | 2357 | //get { return Vector3.Zero; } |
2336 | get { return m_force; } | 2358 | get { return m_force; } |
2337 | set | 2359 | set |
2338 | { | 2360 | { |
2339 | if (PhysicsVector.isFinite(value)) | 2361 | if (value.IsFinite()) |
2340 | { | 2362 | { |
2341 | m_force = value; | 2363 | m_force = value; |
2342 | } | 2364 | } |
@@ -2358,7 +2380,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2358 | m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value); | 2380 | m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value); |
2359 | } | 2381 | } |
2360 | 2382 | ||
2361 | public override void VehicleVectorParam(int param, PhysicsVector value) | 2383 | public override void VehicleVectorParam(int param, Vector3 value) |
2362 | { | 2384 | { |
2363 | m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value); | 2385 | m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value); |
2364 | } | 2386 | } |
@@ -2376,14 +2398,14 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2376 | } | 2398 | } |
2377 | } | 2399 | } |
2378 | 2400 | ||
2379 | public override PhysicsVector CenterOfMass | 2401 | public override Vector3 CenterOfMass |
2380 | { | 2402 | { |
2381 | get { return PhysicsVector.Zero; } | 2403 | get { return Vector3.Zero; } |
2382 | } | 2404 | } |
2383 | 2405 | ||
2384 | public override PhysicsVector GeometricCenter | 2406 | public override Vector3 GeometricCenter |
2385 | { | 2407 | { |
2386 | get { return PhysicsVector.Zero; } | 2408 | get { return Vector3.Zero; } |
2387 | } | 2409 | } |
2388 | 2410 | ||
2389 | public override PrimitiveBaseShape Shape | 2411 | public override PrimitiveBaseShape Shape |
@@ -2395,13 +2417,13 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2395 | } | 2417 | } |
2396 | } | 2418 | } |
2397 | 2419 | ||
2398 | public override PhysicsVector Velocity | 2420 | public override Vector3 Velocity |
2399 | { | 2421 | { |
2400 | get | 2422 | get |
2401 | { | 2423 | { |
2402 | // Averate previous velocity with the new one so | 2424 | // Averate previous velocity with the new one so |
2403 | // client object interpolation works a 'little' better | 2425 | // client object interpolation works a 'little' better |
2404 | PhysicsVector returnVelocity = new PhysicsVector(); | 2426 | Vector3 returnVelocity = Vector3.Zero; |
2405 | returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; | 2427 | returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; |
2406 | returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; | 2428 | returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; |
2407 | returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; | 2429 | returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; |
@@ -2409,7 +2431,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2409 | } | 2431 | } |
2410 | set | 2432 | set |
2411 | { | 2433 | { |
2412 | if (PhysicsVector.isFinite(value)) | 2434 | if (value.IsFinite()) |
2413 | { | 2435 | { |
2414 | _velocity = value; | 2436 | _velocity = value; |
2415 | 2437 | ||
@@ -2424,19 +2446,19 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2424 | } | 2446 | } |
2425 | } | 2447 | } |
2426 | 2448 | ||
2427 | public override PhysicsVector Torque | 2449 | public override Vector3 Torque |
2428 | { | 2450 | { |
2429 | get | 2451 | get |
2430 | { | 2452 | { |
2431 | if (!m_isphysical || Body == IntPtr.Zero) | 2453 | if (!m_isphysical || Body == IntPtr.Zero) |
2432 | return new PhysicsVector(0,0,0); | 2454 | return Vector3.Zero; |
2433 | 2455 | ||
2434 | return _torque; | 2456 | return _torque; |
2435 | } | 2457 | } |
2436 | 2458 | ||
2437 | set | 2459 | set |
2438 | { | 2460 | { |
2439 | if (PhysicsVector.isFinite(value)) | 2461 | if (value.IsFinite()) |
2440 | { | 2462 | { |
2441 | m_taintTorque = value; | 2463 | m_taintTorque = value; |
2442 | _parent_scene.AddPhysicsActorTaint(this); | 2464 | _parent_scene.AddPhysicsActorTaint(this); |
@@ -2488,20 +2510,20 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2488 | return true; | 2510 | return true; |
2489 | } | 2511 | } |
2490 | 2512 | ||
2491 | public override PhysicsVector Acceleration | 2513 | public override Vector3 Acceleration |
2492 | { | 2514 | { |
2493 | get { return _acceleration; } | 2515 | get { return _acceleration; } |
2494 | } | 2516 | } |
2495 | 2517 | ||
2496 | 2518 | ||
2497 | public void SetAcceleration(PhysicsVector accel) | 2519 | public void SetAcceleration(Vector3 accel) |
2498 | { | 2520 | { |
2499 | _acceleration = accel; | 2521 | _acceleration = accel; |
2500 | } | 2522 | } |
2501 | 2523 | ||
2502 | public override void AddForce(PhysicsVector force, bool pushforce) | 2524 | public override void AddForce(Vector3 force, bool pushforce) |
2503 | { | 2525 | { |
2504 | if (PhysicsVector.isFinite(force)) | 2526 | if (force.IsFinite()) |
2505 | { | 2527 | { |
2506 | m_forcelist.Add(force); | 2528 | m_forcelist.Add(force); |
2507 | m_taintforce = true; | 2529 | m_taintforce = true; |
@@ -2513,9 +2535,9 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2513 | //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString()); | 2535 | //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString()); |
2514 | } | 2536 | } |
2515 | 2537 | ||
2516 | public override void AddAngularForce(PhysicsVector force, bool pushforce) | 2538 | public override void AddAngularForce(Vector3 force, bool pushforce) |
2517 | { | 2539 | { |
2518 | if (PhysicsVector.isFinite(force)) | 2540 | if (force.IsFinite()) |
2519 | { | 2541 | { |
2520 | m_angularforcelist.Add(force); | 2542 | m_angularforcelist.Add(force); |
2521 | m_taintaddangularforce = true; | 2543 | m_taintaddangularforce = true; |
@@ -2526,23 +2548,23 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2526 | } | 2548 | } |
2527 | } | 2549 | } |
2528 | 2550 | ||
2529 | public override PhysicsVector RotationalVelocity | 2551 | public override Vector3 RotationalVelocity |
2530 | { | 2552 | { |
2531 | get | 2553 | get |
2532 | { | 2554 | { |
2533 | PhysicsVector pv = new PhysicsVector(0, 0, 0); | 2555 | Vector3 pv = Vector3.Zero; |
2534 | if (_zeroFlag) | 2556 | if (_zeroFlag) |
2535 | return pv; | 2557 | return pv; |
2536 | m_lastUpdateSent = false; | 2558 | m_lastUpdateSent = false; |
2537 | 2559 | ||
2538 | if (m_rotationalVelocity.IsIdentical(pv, 0.2f)) | 2560 | if (m_rotationalVelocity.ApproxEquals(pv, 0.2f)) |
2539 | return pv; | 2561 | return pv; |
2540 | 2562 | ||
2541 | return m_rotationalVelocity; | 2563 | return m_rotationalVelocity; |
2542 | } | 2564 | } |
2543 | set | 2565 | set |
2544 | { | 2566 | { |
2545 | if (PhysicsVector.isFinite(value)) | 2567 | if (value.IsFinite()) |
2546 | { | 2568 | { |
2547 | m_rotationalVelocity = value; | 2569 | m_rotationalVelocity = value; |
2548 | } | 2570 | } |
@@ -2583,16 +2605,16 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2583 | m_taintparent = null; | 2605 | m_taintparent = null; |
2584 | } | 2606 | } |
2585 | 2607 | ||
2586 | public override void LockAngularMotion(PhysicsVector axis) | 2608 | public override void LockAngularMotion(Vector3 axis) |
2587 | { | 2609 | { |
2588 | // reverse the zero/non zero values for ODE. | 2610 | // reverse the zero/non zero values for ODE. |
2589 | if (PhysicsVector.isFinite(axis)) | 2611 | if (axis.IsFinite()) |
2590 | { | 2612 | { |
2591 | axis.X = (axis.X > 0) ? 1f : 0f; | 2613 | axis.X = (axis.X > 0) ? 1f : 0f; |
2592 | axis.Y = (axis.Y > 0) ? 1f : 0f; | 2614 | axis.Y = (axis.Y > 0) ? 1f : 0f; |
2593 | axis.Z = (axis.Z > 0) ? 1f : 0f; | 2615 | axis.Z = (axis.Z > 0) ? 1f : 0f; |
2594 | m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z); | 2616 | m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z); |
2595 | m_taintAngularLock = new PhysicsVector(axis.X, axis.Y, axis.Z); | 2617 | m_taintAngularLock = axis; |
2596 | } | 2618 | } |
2597 | else | 2619 | else |
2598 | { | 2620 | { |
@@ -2605,7 +2627,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2605 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 2627 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! |
2606 | if (_parent == null) | 2628 | if (_parent == null) |
2607 | { | 2629 | { |
2608 | PhysicsVector pv = new PhysicsVector(0, 0, 0); | 2630 | Vector3 pv = Vector3.Zero; |
2609 | bool lastZeroFlag = _zeroFlag; | 2631 | bool lastZeroFlag = _zeroFlag; |
2610 | if (Body != (IntPtr)0) // FIXME -> or if it is a joint | 2632 | if (Body != (IntPtr)0) // FIXME -> or if it is a joint |
2611 | { | 2633 | { |
@@ -2614,9 +2636,9 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2614 | d.Vector3 vel = d.BodyGetLinearVel(Body); | 2636 | d.Vector3 vel = d.BodyGetLinearVel(Body); |
2615 | d.Vector3 rotvel = d.BodyGetAngularVel(Body); | 2637 | d.Vector3 rotvel = d.BodyGetAngularVel(Body); |
2616 | d.Vector3 torque = d.BodyGetTorque(Body); | 2638 | d.Vector3 torque = d.BodyGetTorque(Body); |
2617 | _torque.setValues(torque.X, torque.Y, torque.Z); | 2639 | _torque = new Vector3(torque.X, torque.Y, torque.Z); |
2618 | PhysicsVector l_position = new PhysicsVector(); | 2640 | Vector3 l_position = Vector3.Zero; |
2619 | Quaternion l_orientation = new Quaternion(); | 2641 | Quaternion l_orientation = Quaternion.Identity; |
2620 | 2642 | ||
2621 | // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) | 2643 | // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) |
2622 | //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); } | 2644 | //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); } |
@@ -2751,16 +2773,16 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2751 | _velocity.Z = vel.Z; | 2773 | _velocity.Z = vel.Z; |
2752 | 2774 | ||
2753 | _acceleration = ((_velocity - m_lastVelocity) / 0.1f); | 2775 | _acceleration = ((_velocity - m_lastVelocity) / 0.1f); |
2754 | _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); | 2776 | _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); |
2755 | //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); | 2777 | //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); |
2756 | 2778 | ||
2757 | if (_velocity.IsIdentical(pv, 0.5f)) | 2779 | if (_velocity.ApproxEquals(pv, 0.5f)) |
2758 | { | 2780 | { |
2759 | m_rotationalVelocity = pv; | 2781 | m_rotationalVelocity = pv; |
2760 | } | 2782 | } |
2761 | else | 2783 | else |
2762 | { | 2784 | { |
2763 | m_rotationalVelocity.setValues(rotvel.X, rotvel.Y, rotvel.Z); | 2785 | m_rotationalVelocity = new Vector3(rotvel.X, rotvel.Y, rotvel.Z); |
2764 | } | 2786 | } |
2765 | 2787 | ||
2766 | //m_log.Debug("ODE: " + m_rotationalVelocity.ToString()); | 2788 | //m_log.Debug("ODE: " + m_rotationalVelocity.ToString()); |
@@ -2808,15 +2830,15 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2808 | } | 2830 | } |
2809 | } | 2831 | } |
2810 | 2832 | ||
2811 | public override void SetMomentum(PhysicsVector momentum) | 2833 | public override void SetMomentum(Vector3 momentum) |
2812 | { | 2834 | { |
2813 | } | 2835 | } |
2814 | 2836 | ||
2815 | public override PhysicsVector PIDTarget | 2837 | public override Vector3 PIDTarget |
2816 | { | 2838 | { |
2817 | set | 2839 | set |
2818 | { | 2840 | { |
2819 | if (PhysicsVector.isFinite(value)) | 2841 | if (value.IsFinite()) |
2820 | { | 2842 | { |
2821 | m_PIDTarget = value; | 2843 | m_PIDTarget = value; |
2822 | } | 2844 | } |
@@ -2838,7 +2860,7 @@ if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + | |||
2838 | public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } } | 2860 | public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } } |
2839 | public override float PIDHoverTau { set { m_PIDHoverTau = value; } } | 2861 | public override float PIDHoverTau { set { m_PIDHoverTau = value; } } |
2840 | 2862 | ||
2841 | private void createAMotor(PhysicsVector axis) | 2863 | private void createAMotor(Vector3 axis) |
2842 | { | 2864 | { |
2843 | if (Body == IntPtr.Zero) | 2865 | if (Body == IntPtr.Zero) |
2844 | return; | 2866 | return; |