aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs3958
1 files changed, 3958 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
new file mode 100644
index 0000000..7d57cb4
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
@@ -0,0 +1,3958 @@
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
28/*
29 * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
30 * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
31 * ODEPrim.cs contains methods dealing with Prim editing, Prim
32 * characteristics and Kinetic motion.
33 * ODEDynamics.cs contains methods dealing with Prim Physical motion
34 * (dynamics) and the associated settings. Old Linear and angular
35 * motors for dynamic motion have been replace with MoveLinear()
36 * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
37 * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
38 * switch between 'VEHICLE' parameter use and general dynamics
39 * settings use.
40 */
41
42//#define SPAM
43
44using System;
45using System.Collections.Generic;
46using System.Reflection;
47using System.Runtime.InteropServices;
48using System.Threading;
49using log4net;
50using OpenMetaverse;
51using OdeAPI;
52using OpenSim.Framework;
53using OpenSim.Region.PhysicsModules.SharedBase;
54
55namespace OpenSim.Region.PhysicsModule.ubOde
56{
57 public class OdePrim : PhysicsActor
58 {
59 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
60
61 private bool m_isphysical;
62 private bool m_fakeisphysical;
63 private bool m_isphantom;
64 private bool m_fakeisphantom;
65 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
66 private bool m_fakeisVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
67
68 protected bool m_building;
69 protected bool m_forcePosOrRotation;
70 private bool m_iscolliding;
71
72 internal bool m_isSelected;
73 private bool m_delaySelect;
74 private bool m_lastdoneSelected;
75 internal bool m_outbounds;
76
77 private byte m_angularlocks = 0;
78
79 private Quaternion m_lastorientation;
80 private Quaternion _orientation;
81
82 private Vector3 _position;
83 private Vector3 _velocity;
84 private Vector3 m_torque;
85 private Vector3 m_lastVelocity;
86 private Vector3 m_lastposition;
87 private Vector3 m_rotationalVelocity;
88 private Vector3 _size;
89 private Vector3 _acceleration;
90 private IntPtr Amotor;
91
92 private Vector3 m_force;
93 private Vector3 m_forceacc;
94 private Vector3 m_angularForceacc;
95
96 private float m_invTimeStep;
97 private float m_timeStep;
98
99 private Vector3 m_PIDTarget;
100 private float m_PIDTau;
101 private bool m_usePID;
102
103 private float m_PIDHoverHeight;
104 private float m_PIDHoverTau;
105 private bool m_useHoverPID;
106 private PIDHoverType m_PIDHoverType;
107 private float m_targetHoverHeight;
108 private float m_groundHeight;
109 private float m_waterHeight;
110 private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
111
112 private int body_autodisable_frames;
113 public int bodydisablecontrol = 0;
114 private float m_gravmod = 1.0f;
115
116 // Default we're a Geometry
117 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
118 // Default colide nonphysical don't try to colide with anything
119 private const CollisionCategories m_default_collisionFlagsNotPhysical = 0;
120
121 private const CollisionCategories m_default_collisionFlagsPhysical = (CollisionCategories.Geom |
122 CollisionCategories.Character |
123 CollisionCategories.Land |
124 CollisionCategories.VolumeDtc);
125
126// private bool m_collidesLand = true;
127 private bool m_collidesWater;
128// public bool m_returnCollisions;
129
130 private bool m_NoColide; // for now only for internal use for bad meshs
131
132
133 // Default, Collide with Other Geometries, spaces and Bodies
134 private CollisionCategories m_collisionFlags = m_default_collisionFlagsNotPhysical;
135
136 public bool m_disabled;
137
138 private uint m_localID;
139
140 private IMesh m_mesh;
141 private object m_meshlock = new object();
142 private PrimitiveBaseShape _pbs;
143
144 private UUID? m_assetID;
145 private MeshState m_meshState;
146
147 public ODEScene _parent_scene;
148
149 /// <summary>
150 /// The physics space which contains prim geometry
151 /// </summary>
152 public IntPtr m_targetSpace;
153
154 public IntPtr prim_geom;
155 public IntPtr _triMeshData;
156
157 private PhysicsActor _parent;
158
159 private List<OdePrim> childrenPrim = new List<OdePrim>();
160
161 public float m_collisionscore;
162 private int m_colliderfilter = 0;
163
164 public IntPtr collide_geom; // for objects: geom if single prim space it linkset
165
166 private float m_density;
167 private byte m_shapetype;
168 public bool _zeroFlag;
169 private bool m_lastUpdateSent;
170
171 public IntPtr Body;
172
173 private Vector3 _target_velocity;
174
175 public Vector3 m_OBBOffset;
176 public Vector3 m_OBB;
177 public float primOOBradiusSQ;
178
179 private bool m_hasOBB = true;
180
181 private float m_physCost;
182 private float m_streamCost;
183
184 public d.Mass primdMass; // prim inertia information on it's own referencial
185 float primMass; // prim own mass
186 float primVolume; // prim own volume;
187 float _mass; // object mass acording to case
188
189 public int givefakepos;
190 private Vector3 fakepos;
191 public int givefakeori;
192 private Quaternion fakeori;
193
194 private int m_eventsubscription;
195 private int m_cureventsubscription;
196 private CollisionEventUpdate CollisionEventsThisFrame = null;
197 private bool SentEmptyCollisionsEvent;
198
199 public volatile bool childPrim;
200
201 public ODEDynamics m_vehicle;
202
203 internal int m_material = (int)Material.Wood;
204 private float mu;
205 private float bounce;
206
207 /// <summary>
208 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
209 /// </summary>
210 public override bool IsPhysical // this is not reliable for internal use
211 {
212 get { return m_fakeisphysical; }
213 set
214 {
215 m_fakeisphysical = value; // we show imediatly to outside that we changed physical
216 // and also to stop imediatly some updates
217 // but real change will only happen in taintprocessing
218
219 if (!value) // Zero the remembered last velocity
220 m_lastVelocity = Vector3.Zero;
221 AddChange(changes.Physical, value);
222 }
223 }
224
225 public override bool IsVolumeDtc
226 {
227 get { return m_fakeisVolumeDetect; }
228 set
229 {
230 m_fakeisVolumeDetect = value;
231 AddChange(changes.VolumeDtc, value);
232 }
233 }
234
235 public override bool Phantom // this is not reliable for internal use
236 {
237 get { return m_fakeisphantom; }
238 set
239 {
240 m_fakeisphantom = value;
241 AddChange(changes.Phantom, value);
242 }
243 }
244
245 public override bool Building // this is not reliable for internal use
246 {
247 get { return m_building; }
248 set
249 {
250// if (value)
251// m_building = true;
252 AddChange(changes.building, value);
253 }
254 }
255
256 public override void getContactData(ref ContactData cdata)
257 {
258 cdata.mu = mu;
259 cdata.bounce = bounce;
260
261 // cdata.softcolide = m_softcolide;
262 cdata.softcolide = false;
263
264 if (m_isphysical)
265 {
266 ODEDynamics veh;
267 if (_parent != null)
268 veh = ((OdePrim)_parent).m_vehicle;
269 else
270 veh = m_vehicle;
271
272 if (veh != null && veh.Type != Vehicle.TYPE_NONE)
273 cdata.mu *= veh.FrictionFactor;
274// cdata.mu *= 0;
275 }
276 }
277
278 public override float PhysicsCost
279 {
280 get
281 {
282 return m_physCost;
283 }
284 }
285
286 public override float StreamCost
287 {
288 get
289 {
290 return m_streamCost;
291 }
292 }
293
294 public override int PhysicsActorType
295 {
296 get { return (int)ActorTypes.Prim; }
297 set { return; }
298 }
299
300 public override bool SetAlwaysRun
301 {
302 get { return false; }
303 set { return; }
304 }
305
306 public override uint LocalID
307 {
308 get { return m_localID; }
309 set { m_localID = value; }
310 }
311
312 public override PhysicsActor ParentActor
313 {
314 get
315 {
316 if (childPrim)
317 return _parent;
318 else
319 return (PhysicsActor)this;
320 }
321 }
322
323 public override bool Grabbed
324 {
325 set { return; }
326 }
327
328 public override bool Selected
329 {
330 set
331 {
332 if (value)
333 m_isSelected = value; // if true set imediatly to stop moves etc
334 AddChange(changes.Selected, value);
335 }
336 }
337
338 public override bool Flying
339 {
340 // no flying prims for you
341 get { return false; }
342 set { }
343 }
344
345 public override bool IsColliding
346 {
347 get { return m_iscolliding; }
348 set
349 {
350 if (value)
351 {
352 m_colliderfilter += 2;
353 if (m_colliderfilter > 2)
354 m_colliderfilter = 2;
355 }
356 else
357 {
358 m_colliderfilter--;
359 if (m_colliderfilter < 0)
360 m_colliderfilter = 0;
361 }
362
363 if (m_colliderfilter == 0)
364 m_iscolliding = false;
365 else
366 m_iscolliding = true;
367 }
368 }
369
370 public override bool CollidingGround
371 {
372 get { return false; }
373 set { return; }
374 }
375
376 public override bool CollidingObj
377 {
378 get { return false; }
379 set { return; }
380 }
381
382
383 public override bool ThrottleUpdates {get;set;}
384
385 public override bool Stopped
386 {
387 get { return _zeroFlag; }
388 }
389
390 public override Vector3 Position
391 {
392 get
393 {
394 if (givefakepos > 0)
395 return fakepos;
396 else
397 return _position;
398 }
399
400 set
401 {
402 fakepos = value;
403 givefakepos++;
404 AddChange(changes.Position, value);
405 }
406 }
407
408 public override Vector3 Size
409 {
410 get { return _size; }
411 set
412 {
413 if (value.IsFinite())
414 {
415 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, _pbs, value, m_shapetype);
416 }
417 else
418 {
419 m_log.WarnFormat("[PHYSICS]: Got NaN Size on object {0}", Name);
420 }
421 }
422 }
423
424 public override float Mass
425 {
426 get { return primMass; }
427 }
428
429 public override Vector3 Force
430 {
431 get { return m_force; }
432 set
433 {
434 if (value.IsFinite())
435 {
436 AddChange(changes.Force, value);
437 }
438 else
439 {
440 m_log.WarnFormat("[PHYSICS]: NaN in Force Applied to an Object {0}", Name);
441 }
442 }
443 }
444
445 public override void SetVolumeDetect(int param)
446 {
447 m_fakeisVolumeDetect = (param != 0);
448 AddChange(changes.VolumeDtc, m_fakeisVolumeDetect);
449 }
450
451 public override Vector3 GeometricCenter
452 {
453 // this is not real geometric center but a average of positions relative to root prim acording to
454 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
455 // ignoring tortured prims details since sl also seems to ignore
456 // so no real use in doing it on physics
457 get
458 {
459 return Vector3.Zero;
460 }
461 }
462
463 public override Vector3 CenterOfMass
464 {
465 get
466 {
467 lock (_parent_scene.OdeLock)
468 {
469 d.Vector3 dtmp;
470 if (!childPrim && Body != IntPtr.Zero)
471 {
472 dtmp = d.BodyGetPosition(Body);
473 return new Vector3(dtmp.X, dtmp.Y, dtmp.Z);
474 }
475 else if (prim_geom != IntPtr.Zero)
476 {
477 d.Quaternion dq;
478 d.GeomCopyQuaternion(prim_geom, out dq);
479 Quaternion q;
480 q.X = dq.X;
481 q.Y = dq.Y;
482 q.Z = dq.Z;
483 q.W = dq.W;
484
485 Vector3 Ptot = m_OBBOffset * q;
486 dtmp = d.GeomGetPosition(prim_geom);
487 Ptot.X += dtmp.X;
488 Ptot.Y += dtmp.Y;
489 Ptot.Z += dtmp.Z;
490
491 // if(childPrim) we only know about physical linksets
492 return Ptot;
493/*
494 float tmass = _mass;
495 Ptot *= tmass;
496
497 float m;
498
499 foreach (OdePrim prm in childrenPrim)
500 {
501 m = prm._mass;
502 Ptot += prm.CenterOfMass * m;
503 tmass += m;
504 }
505
506 if (tmass == 0)
507 tmass = 0;
508 else
509 tmass = 1.0f / tmass;
510
511 Ptot *= tmass;
512 return Ptot;
513*/
514 }
515 else
516 return _position;
517 }
518 }
519 }
520
521 public override Vector3 OOBsize
522 {
523 get
524 {
525 return m_OBB;
526 }
527 }
528
529 public override Vector3 OOBoffset
530 {
531 get
532 {
533 return m_OBBOffset;
534 }
535 }
536
537 public override float OOBRadiusSQ
538 {
539 get
540 {
541 return primOOBradiusSQ;
542 }
543 }
544
545 public override PrimitiveBaseShape Shape
546 {
547 set
548 {
549// AddChange(changes.Shape, value);
550 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, value, _size, m_shapetype);
551 }
552 }
553
554 public override byte PhysicsShapeType
555 {
556 get
557 {
558 return m_shapetype;
559 }
560 set
561 {
562 m_shapetype = value;
563 _parent_scene.m_meshWorker.ChangeActorPhysRep(this, _pbs, _size, value);
564 }
565 }
566
567 public override Vector3 Velocity
568 {
569 get
570 {
571 if (_zeroFlag)
572 return Vector3.Zero;
573 return _velocity;
574 }
575 set
576 {
577 if (value.IsFinite())
578 {
579 AddChange(changes.Velocity, value);
580 }
581 else
582 {
583 m_log.WarnFormat("[PHYSICS]: Got NaN Velocity in Object {0}", Name);
584 }
585
586 }
587 }
588
589 public override Vector3 Torque
590 {
591 get
592 {
593 if (!IsPhysical || Body == IntPtr.Zero)
594 return Vector3.Zero;
595
596 return m_torque;
597 }
598
599 set
600 {
601 if (value.IsFinite())
602 {
603 AddChange(changes.Torque, value);
604 }
605 else
606 {
607 m_log.WarnFormat("[PHYSICS]: Got NaN Torque in Object {0}", Name);
608 }
609 }
610 }
611
612 public override float CollisionScore
613 {
614 get { return m_collisionscore; }
615 set { m_collisionscore = value; }
616 }
617
618 public override bool Kinematic
619 {
620 get { return false; }
621 set { }
622 }
623
624 public override Quaternion Orientation
625 {
626 get
627 {
628 if (givefakeori > 0)
629 return fakeori;
630 else
631
632 return _orientation;
633 }
634 set
635 {
636 if (QuaternionIsFinite(value))
637 {
638 fakeori = value;
639 givefakeori++;
640
641 value.Normalize();
642
643 AddChange(changes.Orientation, value);
644 }
645 else
646 m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name);
647
648 }
649 }
650
651 public override Vector3 Acceleration
652 {
653 get { return _acceleration; }
654 set { }
655 }
656
657 public override Vector3 RotationalVelocity
658 {
659 get
660 {
661 Vector3 pv = Vector3.Zero;
662 if (_zeroFlag)
663 return pv;
664
665 if (m_rotationalVelocity.ApproxEquals(pv, 0.0001f))
666 return pv;
667
668 return m_rotationalVelocity;
669 }
670 set
671 {
672 if (value.IsFinite())
673 {
674 AddChange(changes.AngVelocity, value);
675 }
676 else
677 {
678 m_log.WarnFormat("[PHYSICS]: Got NaN RotationalVelocity in Object {0}", Name);
679 }
680 }
681 }
682
683 public override float Buoyancy
684 {
685 get { return m_buoyancy; }
686 set
687 {
688 AddChange(changes.Buoyancy,value);
689 }
690 }
691
692 public override bool FloatOnWater
693 {
694 set
695 {
696 AddChange(changes.CollidesWater, value);
697 }
698 }
699
700 public override Vector3 PIDTarget
701 {
702 set
703 {
704 if (value.IsFinite())
705 {
706 AddChange(changes.PIDTarget,value);
707 }
708 else
709 m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name);
710 }
711 }
712
713 public override bool PIDActive
714 {
715 get
716 {
717 return m_usePID;
718 }
719 set
720 {
721 AddChange(changes.PIDActive,value);
722 }
723 }
724
725 public override float PIDTau
726 {
727 set
728 {
729 float tmp = 0;
730 if (value > 0)
731 {
732 float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
733 if (value < mint)
734 tmp = mint;
735 else
736 tmp = value;
737 }
738 AddChange(changes.PIDTau,tmp);
739 }
740 }
741
742 public override float PIDHoverHeight
743 {
744 set
745 {
746 AddChange(changes.PIDHoverHeight,value);
747 }
748 }
749 public override bool PIDHoverActive
750 {
751 get
752 {
753 return m_useHoverPID;
754 }
755 set
756 {
757 AddChange(changes.PIDHoverActive, value);
758 }
759 }
760
761 public override PIDHoverType PIDHoverType
762 {
763 set
764 {
765 AddChange(changes.PIDHoverType,value);
766 }
767 }
768
769 public override float PIDHoverTau
770 {
771 set
772 {
773 float tmp =0;
774 if (value > 0)
775 {
776 float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep);
777 if (value < mint)
778 tmp = mint;
779 else
780 tmp = value;
781 }
782 AddChange(changes.PIDHoverTau, tmp);
783 }
784 }
785
786 public override Quaternion APIDTarget { set { return; } }
787
788 public override bool APIDActive { set { return; } }
789
790 public override float APIDStrength { set { return; } }
791
792 public override float APIDDamping { set { return; } }
793
794 public override int VehicleType
795 {
796 // we may need to put a fake on this
797 get
798 {
799 if (m_vehicle == null)
800 return (int)Vehicle.TYPE_NONE;
801 else
802 return (int)m_vehicle.Type;
803 }
804 set
805 {
806 AddChange(changes.VehicleType, value);
807 }
808 }
809
810 public override void VehicleFloatParam(int param, float value)
811 {
812 strVehicleFloatParam fp = new strVehicleFloatParam();
813 fp.param = param;
814 fp.value = value;
815 AddChange(changes.VehicleFloatParam, fp);
816 }
817
818 public override void VehicleVectorParam(int param, Vector3 value)
819 {
820 strVehicleVectorParam fp = new strVehicleVectorParam();
821 fp.param = param;
822 fp.value = value;
823 AddChange(changes.VehicleVectorParam, fp);
824 }
825
826 public override void VehicleRotationParam(int param, Quaternion value)
827 {
828 strVehicleQuatParam fp = new strVehicleQuatParam();
829 fp.param = param;
830 fp.value = value;
831 AddChange(changes.VehicleRotationParam, fp);
832 }
833
834 public override void VehicleFlags(int param, bool value)
835 {
836 strVehicleBoolParam bp = new strVehicleBoolParam();
837 bp.param = param;
838 bp.value = value;
839 AddChange(changes.VehicleFlags, bp);
840 }
841
842 public override void SetVehicle(object vdata)
843 {
844 AddChange(changes.SetVehicle, vdata);
845 }
846 public void SetAcceleration(Vector3 accel)
847 {
848 _acceleration = accel;
849 }
850
851 public override void AddForce(Vector3 force, bool pushforce)
852 {
853 if (force.IsFinite())
854 {
855 if(pushforce)
856 AddChange(changes.AddForce, force);
857 else // a impulse
858 AddChange(changes.AddForce, force * m_invTimeStep);
859 }
860 else
861 {
862 m_log.WarnFormat("[PHYSICS]: Got Invalid linear force vector from Scene in Object {0}", Name);
863 }
864 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
865 }
866
867 public override void AddAngularForce(Vector3 force, bool pushforce)
868 {
869 if (force.IsFinite())
870 {
871// if(pushforce) for now applyrotationimpulse seems more happy applied as a force
872 AddChange(changes.AddAngForce, force);
873// else // a impulse
874// AddChange(changes.AddAngForce, force * m_invTimeStep);
875 }
876 else
877 {
878 m_log.WarnFormat("[PHYSICS]: Got Invalid Angular force vector from Scene in Object {0}", Name);
879 }
880 }
881
882 public override void CrossingFailure()
883 {
884 if (m_outbounds)
885 {
886 _position.X = Util.Clip(_position.X, 0.5f, _parent_scene.WorldExtents.X - 0.5f);
887 _position.Y = Util.Clip(_position.Y, 0.5f, _parent_scene.WorldExtents.Y - 0.5f);
888 _position.Z = Util.Clip(_position.Z + 0.2f, -100f, 50000f);
889
890 m_lastposition = _position;
891 _velocity.X = 0;
892 _velocity.Y = 0;
893 _velocity.Z = 0;
894
895 m_lastVelocity = _velocity;
896 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
897 m_vehicle.Stop();
898
899 if(Body != IntPtr.Zero)
900 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
901 if (prim_geom != IntPtr.Zero)
902 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
903
904 m_outbounds = false;
905 changeDisable(false);
906 base.RequestPhysicsterseUpdate();
907 }
908 }
909
910 public override void SetMomentum(Vector3 momentum)
911 {
912 }
913
914 public override void SetMaterial(int pMaterial)
915 {
916 m_material = pMaterial;
917 mu = _parent_scene.m_materialContactsData[pMaterial].mu;
918 bounce = _parent_scene.m_materialContactsData[pMaterial].bounce;
919 }
920
921 public override float Density
922 {
923 get
924 {
925 return m_density * 100f;
926 }
927 set
928 {
929 m_density = value / 100f;
930 // for not prim mass is not updated since this implies full rebuild of body inertia TODO
931 }
932 }
933 public override float GravModifier
934 {
935 get
936 {
937 return m_gravmod;
938 }
939 set
940 {
941 m_gravmod = value;
942 if (m_vehicle != null)
943 m_vehicle.GravMod = m_gravmod;
944 }
945 }
946 public override float Friction
947 {
948 get
949 {
950 return mu;
951 }
952 set
953 {
954 mu = value;
955 }
956 }
957
958 public override float Restitution
959 {
960 get
961 {
962 return bounce;
963 }
964 set
965 {
966 bounce = value;
967 }
968 }
969
970 public void setPrimForRemoval()
971 {
972 AddChange(changes.Remove, null);
973 }
974
975 public override void link(PhysicsActor obj)
976 {
977 AddChange(changes.Link, obj);
978 }
979
980 public override void delink()
981 {
982 AddChange(changes.DeLink, null);
983 }
984
985 public override void LockAngularMotion(byte axislock)
986 {
987// m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
988 AddChange(changes.AngLock, axislock);
989
990 }
991
992 public override void SubscribeEvents(int ms)
993 {
994 m_eventsubscription = ms;
995 m_cureventsubscription = 0;
996 if (CollisionEventsThisFrame == null)
997 CollisionEventsThisFrame = new CollisionEventUpdate();
998 SentEmptyCollisionsEvent = false;
999 }
1000
1001 public override void UnSubscribeEvents()
1002 {
1003 if (CollisionEventsThisFrame != null)
1004 {
1005 CollisionEventsThisFrame.Clear();
1006 CollisionEventsThisFrame = null;
1007 }
1008 m_eventsubscription = 0;
1009 _parent_scene.RemoveCollisionEventReporting(this);
1010 }
1011
1012 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
1013 {
1014 if (CollisionEventsThisFrame == null)
1015 CollisionEventsThisFrame = new CollisionEventUpdate();
1016// if(CollisionEventsThisFrame.Count < 32)
1017 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1018 }
1019
1020 public void SendCollisions()
1021 {
1022 if (CollisionEventsThisFrame == null)
1023 return;
1024
1025 if (m_cureventsubscription < m_eventsubscription)
1026 return;
1027
1028 m_cureventsubscription = 0;
1029
1030 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
1031
1032 if (!SentEmptyCollisionsEvent || ncolisions > 0)
1033 {
1034 base.SendCollisionUpdate(CollisionEventsThisFrame);
1035
1036 if (ncolisions == 0)
1037 {
1038 SentEmptyCollisionsEvent = true;
1039 _parent_scene.RemoveCollisionEventReporting(this);
1040 }
1041 else
1042 {
1043 SentEmptyCollisionsEvent = false;
1044 CollisionEventsThisFrame.Clear();
1045 }
1046 }
1047 }
1048
1049 internal void AddCollisionFrameTime(int t)
1050 {
1051 if (m_cureventsubscription < 50000)
1052 m_cureventsubscription += t;
1053 }
1054
1055 public override bool SubscribedEvents()
1056 {
1057 if (m_eventsubscription > 0)
1058 return true;
1059 return false;
1060 }
1061
1062 public OdePrim(String primName, ODEScene parent_scene, Vector3 pos, Vector3 size,
1063 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID)
1064 {
1065 Name = primName;
1066 LocalID = plocalID;
1067
1068 m_vehicle = null;
1069
1070 if (!pos.IsFinite())
1071 {
1072 pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
1073 parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
1074 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Position for {0}", Name);
1075 }
1076 _position = pos;
1077 givefakepos = 0;
1078
1079 m_timeStep = parent_scene.ODE_STEPSIZE;
1080 m_invTimeStep = 1f / m_timeStep;
1081
1082 m_density = parent_scene.geomDefaultDensity;
1083 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
1084
1085 prim_geom = IntPtr.Zero;
1086 collide_geom = IntPtr.Zero;
1087 Body = IntPtr.Zero;
1088
1089 if (!size.IsFinite())
1090 {
1091 size = new Vector3(0.5f, 0.5f, 0.5f);
1092 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Size for {0}", Name);
1093 }
1094
1095 if (size.X <= 0) size.X = 0.01f;
1096 if (size.Y <= 0) size.Y = 0.01f;
1097 if (size.Z <= 0) size.Z = 0.01f;
1098
1099 _size = size;
1100
1101 if (!QuaternionIsFinite(rotation))
1102 {
1103 rotation = Quaternion.Identity;
1104 m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Rotation for {0}", Name);
1105 }
1106
1107 _orientation = rotation;
1108 givefakeori = 0;
1109
1110 _pbs = pbs;
1111
1112 _parent_scene = parent_scene;
1113 m_targetSpace = IntPtr.Zero;
1114
1115 if (pos.Z < 0)
1116 {
1117 m_isphysical = false;
1118 }
1119 else
1120 {
1121 m_isphysical = pisPhysical;
1122 }
1123 m_fakeisphysical = m_isphysical;
1124
1125 m_isVolumeDetect = false;
1126 m_fakeisVolumeDetect = false;
1127
1128 m_force = Vector3.Zero;
1129
1130 m_iscolliding = false;
1131 m_colliderfilter = 0;
1132 m_NoColide = false;
1133
1134 _triMeshData = IntPtr.Zero;
1135
1136 m_shapetype = _shapeType;
1137
1138 m_lastdoneSelected = false;
1139 m_isSelected = false;
1140 m_delaySelect = false;
1141
1142 m_isphantom = pisPhantom;
1143 m_fakeisphantom = pisPhantom;
1144
1145 mu = parent_scene.m_materialContactsData[(int)Material.Wood].mu;
1146 bounce = parent_scene.m_materialContactsData[(int)Material.Wood].bounce;
1147
1148 m_building = true; // control must set this to false when done
1149
1150 // get basic mass parameters
1151 ODEPhysRepData repData = _parent_scene.m_meshWorker.NewActorPhysRep(this, _pbs, _size, m_shapetype);
1152
1153 primVolume = repData.volume;
1154 m_OBB = repData.OBB;
1155 m_OBBOffset = repData.OBBOffset;
1156
1157 UpdatePrimBodyData();
1158 }
1159
1160 private void resetCollisionAccounting()
1161 {
1162 m_collisionscore = 0;
1163 }
1164
1165 private void UpdateCollisionCatFlags()
1166 {
1167 if(m_isphysical && m_disabled)
1168 {
1169 m_collisionCategories = 0;
1170 m_collisionFlags = 0;
1171 }
1172
1173 else if (m_isSelected)
1174 {
1175 m_collisionCategories = CollisionCategories.Selected;
1176 m_collisionFlags = 0;
1177 }
1178
1179 else if (m_isVolumeDetect)
1180 {
1181 m_collisionCategories = CollisionCategories.VolumeDtc;
1182 if (m_isphysical)
1183 m_collisionFlags = CollisionCategories.Geom | CollisionCategories.Character;
1184 else
1185 m_collisionFlags = 0;
1186 }
1187 else if (m_isphantom)
1188 {
1189 m_collisionCategories = CollisionCategories.Phantom;
1190 if (m_isphysical)
1191 m_collisionFlags = CollisionCategories.Land;
1192 else
1193 m_collisionFlags = 0;
1194 }
1195 else
1196 {
1197 m_collisionCategories = CollisionCategories.Geom;
1198 if (m_isphysical)
1199 m_collisionFlags = m_default_collisionFlagsPhysical;
1200 else
1201 m_collisionFlags = m_default_collisionFlagsNotPhysical;
1202 }
1203 }
1204
1205 private void ApplyCollisionCatFlags()
1206 {
1207 if (prim_geom != IntPtr.Zero)
1208 {
1209 if (!childPrim && childrenPrim.Count > 0)
1210 {
1211 foreach (OdePrim prm in childrenPrim)
1212 {
1213 if (m_isphysical && m_disabled)
1214 {
1215 prm.m_collisionCategories = 0;
1216 prm.m_collisionFlags = 0;
1217 }
1218 else
1219 {
1220 // preserve some
1221 if (prm.m_isSelected)
1222 {
1223 prm.m_collisionCategories = CollisionCategories.Selected;
1224 prm.m_collisionFlags = 0;
1225 }
1226 else if (prm.m_isVolumeDetect)
1227 {
1228 prm.m_collisionCategories = CollisionCategories.VolumeDtc;
1229 if (m_isphysical)
1230 prm.m_collisionFlags = CollisionCategories.Geom | CollisionCategories.Character;
1231 else
1232 prm.m_collisionFlags = 0;
1233 }
1234 else if (prm.m_isphantom)
1235 {
1236 prm.m_collisionCategories = CollisionCategories.Phantom;
1237 if (m_isphysical)
1238 prm.m_collisionFlags = CollisionCategories.Land;
1239 else
1240 prm.m_collisionFlags = 0;
1241 }
1242 else
1243 {
1244 prm.m_collisionCategories = m_collisionCategories;
1245 prm.m_collisionFlags = m_collisionFlags;
1246 }
1247 }
1248
1249 if (prm.prim_geom != IntPtr.Zero)
1250 {
1251 if (prm.m_NoColide)
1252 {
1253 d.GeomSetCategoryBits(prm.prim_geom, 0);
1254 if (m_isphysical)
1255 d.GeomSetCollideBits(prm.prim_geom, (int)CollisionCategories.Land);
1256 else
1257 d.GeomSetCollideBits(prm.prim_geom, 0);
1258 }
1259 else
1260 {
1261 d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
1262 d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
1263 }
1264 }
1265 }
1266 }
1267
1268 if (m_NoColide)
1269 {
1270 d.GeomSetCategoryBits(prim_geom, 0);
1271 d.GeomSetCollideBits(prim_geom, (uint)CollisionCategories.Land);
1272 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
1273 {
1274 d.GeomSetCategoryBits(collide_geom, 0);
1275 d.GeomSetCollideBits(collide_geom, (uint)CollisionCategories.Land);
1276 }
1277 }
1278 else
1279 {
1280 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1281 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1282 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
1283 {
1284 d.GeomSetCategoryBits(collide_geom, (uint)m_collisionCategories);
1285 d.GeomSetCollideBits(collide_geom, (uint)m_collisionFlags);
1286 }
1287 }
1288 }
1289 }
1290
1291 private void createAMotor(byte axislock)
1292 {
1293 if (Body == IntPtr.Zero)
1294 return;
1295
1296 if (Amotor != IntPtr.Zero)
1297 {
1298 d.JointDestroy(Amotor);
1299 Amotor = IntPtr.Zero;
1300 }
1301
1302 int axisnum = 0;
1303 bool axisX = false;
1304 bool axisY = false;
1305 bool axisZ = false;
1306 if((axislock & 0x02) != 0)
1307 {
1308 axisnum++;
1309 axisX = true;
1310 }
1311 if((axislock & 0x04) != 0)
1312 {
1313 axisnum++;
1314 axisY = true;
1315 }
1316 if((axislock & 0x08) != 0)
1317 {
1318 axisnum++;
1319 axisZ = true;
1320 }
1321
1322 if(axisnum == 0)
1323 return;
1324 // stop it
1325 d.BodySetTorque(Body, 0, 0, 0);
1326 d.BodySetAngularVel(Body, 0, 0, 0);
1327
1328 Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
1329 d.JointAttach(Amotor, Body, IntPtr.Zero);
1330
1331 d.JointSetAMotorMode(Amotor, 0);
1332
1333 d.JointSetAMotorNumAxes(Amotor, axisnum);
1334
1335 // get current orientation to lock
1336
1337 d.Quaternion dcur = d.BodyGetQuaternion(Body);
1338 Quaternion curr; // crap convertion between identical things
1339 curr.X = dcur.X;
1340 curr.Y = dcur.Y;
1341 curr.Z = dcur.Z;
1342 curr.W = dcur.W;
1343 Vector3 ax;
1344
1345 int i = 0;
1346 int j = 0;
1347 if (axisX)
1348 {
1349 ax = (new Vector3(1, 0, 0)) * curr; // rotate world X to current local X
1350 d.JointSetAMotorAxis(Amotor, 0, 0, ax.X, ax.Y, ax.Z);
1351 d.JointSetAMotorAngle(Amotor, 0, 0);
1352 d.JointSetAMotorParam(Amotor, (int)d.JointParam.LoStop, 0f);
1353 d.JointSetAMotorParam(Amotor, (int)d.JointParam.HiStop, 0f);
1354 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0);
1355 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FudgeFactor, 0.0001f);
1356 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Bounce, 0f);
1357 d.JointSetAMotorParam(Amotor, (int)d.JointParam.CFM, 0f);
1358 d.JointSetAMotorParam(Amotor, (int)d.JointParam.FMax, 5e8f);
1359 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopCFM, 0f);
1360 d.JointSetAMotorParam(Amotor, (int)d.JointParam.StopERP, 0.8f);
1361 i++;
1362 j = 256; // move to next axis set
1363 }
1364
1365 if (axisY)
1366 {
1367 ax = (new Vector3(0, 1, 0)) * curr;
1368 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
1369 d.JointSetAMotorAngle(Amotor, i, 0);
1370 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f);
1371 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f);
1372 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
1373 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
1374 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
1375 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.CFM, 0f);
1376 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
1377 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
1378 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
1379 i++;
1380 j += 256;
1381 }
1382
1383 if (axisZ)
1384 {
1385 ax = (new Vector3(0, 0, 1)) * curr;
1386 d.JointSetAMotorAxis(Amotor, i, 0, ax.X, ax.Y, ax.Z);
1387 d.JointSetAMotorAngle(Amotor, i, 0);
1388 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.LoStop, 0f);
1389 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.HiStop, 0f);
1390 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Vel, 0);
1391 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FudgeFactor, 0.0001f);
1392 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.Bounce, 0f);
1393 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.CFM, 0f);
1394 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.FMax, 5e8f);
1395 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopCFM, 0f);
1396 d.JointSetAMotorParam(Amotor, j + (int)d.JointParam.StopERP, 0.8f);
1397 }
1398 }
1399
1400
1401 private void SetGeom(IntPtr geom)
1402 {
1403 prim_geom = geom;
1404 //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
1405 if (prim_geom != IntPtr.Zero)
1406 {
1407
1408 if (m_NoColide)
1409 {
1410 d.GeomSetCategoryBits(prim_geom, 0);
1411 if (m_isphysical)
1412 {
1413 d.GeomSetCollideBits(prim_geom, (uint)CollisionCategories.Land);
1414 }
1415 else
1416 {
1417 d.GeomSetCollideBits(prim_geom, 0);
1418 d.GeomDisable(prim_geom);
1419 }
1420 }
1421 else
1422 {
1423 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1424 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1425 }
1426
1427 UpdatePrimBodyData();
1428 _parent_scene.actor_name_map[prim_geom] = this;
1429
1430/*
1431// debug
1432 d.AABB aabb;
1433 d.GeomGetAABB(prim_geom, out aabb);
1434 float x = aabb.MaxX - aabb.MinX;
1435 float y = aabb.MaxY - aabb.MinY;
1436 float z = aabb.MaxZ - aabb.MinZ;
1437 if( x > 60.0f || y > 60.0f || z > 60.0f)
1438 m_log.WarnFormat("[PHYSICS]: large prim geo {0},size {1}, AABBsize <{2},{3},{4}, mesh {5} at {6}",
1439 Name, _size.ToString(), x, y, z, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh", _position.ToString());
1440 else if (x < 0.001f || y < 0.001f || z < 0.001f)
1441 m_log.WarnFormat("[PHYSICS]: small prim geo {0},size {1}, AABBsize <{2},{3},{4}, mesh {5} at {6}",
1442 Name, _size.ToString(), x, y, z, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh", _position.ToString());
1443*/
1444
1445 }
1446 else
1447 m_log.Warn("Setting bad Geom");
1448 }
1449
1450 private bool GetMeshGeom()
1451 {
1452 IntPtr vertices, indices;
1453 int vertexCount, indexCount;
1454 int vertexStride, triStride;
1455
1456 IMesh mesh = m_mesh;
1457
1458 if (mesh == null)
1459 return false;
1460
1461 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount);
1462 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount);
1463
1464 if (vertexCount == 0 || indexCount == 0)
1465 {
1466 m_log.WarnFormat("[PHYSICS]: Invalid mesh data on OdePrim {0}, mesh {1} at {2}",
1467 Name, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh",_position.ToString());
1468
1469 m_hasOBB = false;
1470 m_OBBOffset = Vector3.Zero;
1471 m_OBB = _size * 0.5f;
1472
1473 m_physCost = 0.1f;
1474 m_streamCost = 1.0f;
1475
1476 _parent_scene.mesher.ReleaseMesh(mesh);
1477 m_meshState = MeshState.MeshFailed;
1478 m_mesh = null;
1479 return false;
1480 }
1481
1482 IntPtr geo = IntPtr.Zero;
1483
1484 try
1485 {
1486 _triMeshData = d.GeomTriMeshDataCreate();
1487
1488 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1489 d.GeomTriMeshDataPreprocess(_triMeshData);
1490
1491 geo = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
1492 }
1493
1494 catch (Exception e)
1495 {
1496 m_log.ErrorFormat("[PHYSICS]: SetGeom Mesh failed for {0} exception: {1}", Name, e);
1497 if (_triMeshData != IntPtr.Zero)
1498 {
1499 try
1500 {
1501 d.GeomTriMeshDataDestroy(_triMeshData);
1502 }
1503 catch
1504 {
1505 }
1506 }
1507 _triMeshData = IntPtr.Zero;
1508
1509 m_hasOBB = false;
1510 m_OBBOffset = Vector3.Zero;
1511 m_OBB = _size * 0.5f;
1512 m_physCost = 0.1f;
1513 m_streamCost = 1.0f;
1514
1515 _parent_scene.mesher.ReleaseMesh(mesh);
1516 m_meshState = MeshState.MeshFailed;
1517 m_mesh = null;
1518 return false;
1519 }
1520
1521 m_physCost = 0.0013f * (float)indexCount;
1522 // todo
1523 m_streamCost = 1.0f;
1524
1525 SetGeom(geo);
1526
1527 return true;
1528 }
1529
1530 private void CreateGeom()
1531 {
1532 bool hasMesh = false;
1533
1534 m_NoColide = false;
1535
1536 if ((m_meshState & MeshState.MeshNoColide) != 0)
1537 m_NoColide = true;
1538
1539 else if(m_mesh != null)
1540 {
1541 if (GetMeshGeom())
1542 hasMesh = true;
1543 else
1544 m_NoColide = true;
1545 }
1546
1547
1548 if (!hasMesh)
1549 {
1550 IntPtr geo = IntPtr.Zero;
1551
1552 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
1553 && _size.X == _size.Y && _size.Y == _size.Z)
1554 { // it's a sphere
1555 try
1556 {
1557 geo = d.CreateSphere(m_targetSpace, _size.X * 0.5f);
1558 }
1559 catch (Exception e)
1560 {
1561 m_log.WarnFormat("[PHYSICS]: Create sphere failed: {0}", e);
1562 return;
1563 }
1564 }
1565 else
1566 {// do it as a box
1567 try
1568 {
1569 geo = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1570 }
1571 catch (Exception e)
1572 {
1573 m_log.Warn("[PHYSICS]: Create box failed: {0}", e);
1574 return;
1575 }
1576 }
1577 m_physCost = 0.1f;
1578 m_streamCost = 1.0f;
1579 SetGeom(geo);
1580 }
1581 }
1582
1583 private void RemoveGeom()
1584 {
1585 if (prim_geom != IntPtr.Zero)
1586 {
1587 _parent_scene.actor_name_map.Remove(prim_geom);
1588
1589 try
1590 {
1591 d.GeomDestroy(prim_geom);
1592 if (_triMeshData != IntPtr.Zero)
1593 {
1594 d.GeomTriMeshDataDestroy(_triMeshData);
1595 _triMeshData = IntPtr.Zero;
1596 }
1597 }
1598 catch (Exception e)
1599 {
1600 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction failed for {0} exception {1}", Name, e);
1601 }
1602
1603 prim_geom = IntPtr.Zero;
1604 collide_geom = IntPtr.Zero;
1605 m_targetSpace = IntPtr.Zero;
1606 }
1607 else
1608 {
1609 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction BAD {0}", Name);
1610 }
1611
1612 lock (m_meshlock)
1613 {
1614 if (m_mesh != null)
1615 {
1616 _parent_scene.mesher.ReleaseMesh(m_mesh);
1617 m_mesh = null;
1618 }
1619 }
1620
1621 Body = IntPtr.Zero;
1622 m_hasOBB = false;
1623 }
1624
1625 //sets non physical prim m_targetSpace to right space in spaces grid for static prims
1626 // should only be called for non physical prims unless they are becoming non physical
1627 private void SetInStaticSpace(OdePrim prim)
1628 {
1629 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim._position, prim.m_targetSpace);
1630 prim.m_targetSpace = targetSpace;
1631 collide_geom = IntPtr.Zero;
1632 }
1633
1634 public void enableBodySoft()
1635 {
1636 m_disabled = false;
1637 if (!childPrim && !m_isSelected)
1638 {
1639 if (m_isphysical && Body != IntPtr.Zero)
1640 {
1641 UpdateCollisionCatFlags();
1642 ApplyCollisionCatFlags();
1643
1644 _zeroFlag = true;
1645 d.BodyEnable(Body);
1646
1647 }
1648 }
1649 resetCollisionAccounting();
1650 }
1651
1652 private void disableBodySoft()
1653 {
1654 m_disabled = true;
1655 if (!childPrim)
1656 {
1657 if (m_isphysical && Body != IntPtr.Zero)
1658 {
1659 if (m_isSelected)
1660 m_collisionFlags = CollisionCategories.Selected;
1661 else
1662 m_collisionCategories = 0;
1663 m_collisionFlags = 0;
1664 ApplyCollisionCatFlags();
1665 d.BodyDisable(Body);
1666 }
1667 }
1668 }
1669
1670 private void MakeBody()
1671 {
1672 if (!m_isphysical) // only physical get bodies
1673 return;
1674
1675 if (childPrim) // child prims don't get bodies;
1676 return;
1677
1678 if (m_building)
1679 return;
1680
1681 if (prim_geom == IntPtr.Zero)
1682 {
1683 m_log.Warn("[PHYSICS]: Unable to link the linkset. Root has no geom yet");
1684 return;
1685 }
1686
1687 if (Body != IntPtr.Zero)
1688 {
1689 DestroyBody();
1690 m_log.Warn("[PHYSICS]: MakeBody called having a body");
1691 }
1692
1693 if (d.GeomGetBody(prim_geom) != IntPtr.Zero)
1694 {
1695 d.GeomSetBody(prim_geom, IntPtr.Zero);
1696 m_log.Warn("[PHYSICS]: MakeBody root geom already had a body");
1697 }
1698
1699 d.Matrix3 mymat = new d.Matrix3();
1700 d.Quaternion myrot = new d.Quaternion();
1701 d.Mass objdmass = new d.Mass { };
1702
1703 Body = d.BodyCreate(_parent_scene.world);
1704
1705 objdmass = primdMass;
1706
1707 // rotate inertia
1708 myrot.X = _orientation.X;
1709 myrot.Y = _orientation.Y;
1710 myrot.Z = _orientation.Z;
1711 myrot.W = _orientation.W;
1712
1713 d.RfromQ(out mymat, ref myrot);
1714 d.MassRotate(ref objdmass, ref mymat);
1715
1716 // set the body rotation
1717 d.BodySetRotation(Body, ref mymat);
1718
1719 // recompute full object inertia if needed
1720 if (childrenPrim.Count > 0)
1721 {
1722 d.Matrix3 mat = new d.Matrix3();
1723 d.Quaternion quat = new d.Quaternion();
1724 d.Mass tmpdmass = new d.Mass { };
1725 Vector3 rcm;
1726
1727 rcm.X = _position.X;
1728 rcm.Y = _position.Y;
1729 rcm.Z = _position.Z;
1730
1731 lock (childrenPrim)
1732 {
1733 foreach (OdePrim prm in childrenPrim)
1734 {
1735 if (prm.prim_geom == IntPtr.Zero)
1736 {
1737 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements, skipping it. No geom yet");
1738 continue;
1739 }
1740
1741 tmpdmass = prm.primdMass;
1742
1743 // apply prim current rotation to inertia
1744 quat.X = prm._orientation.X;
1745 quat.Y = prm._orientation.Y;
1746 quat.Z = prm._orientation.Z;
1747 quat.W = prm._orientation.W;
1748 d.RfromQ(out mat, ref quat);
1749 d.MassRotate(ref tmpdmass, ref mat);
1750
1751 Vector3 ppos = prm._position;
1752 ppos.X -= rcm.X;
1753 ppos.Y -= rcm.Y;
1754 ppos.Z -= rcm.Z;
1755 // refer inertia to root prim center of mass position
1756 d.MassTranslate(ref tmpdmass,
1757 ppos.X,
1758 ppos.Y,
1759 ppos.Z);
1760
1761 d.MassAdd(ref objdmass, ref tmpdmass); // add to total object inertia
1762 // fix prim colision cats
1763
1764 if (d.GeomGetBody(prm.prim_geom) != IntPtr.Zero)
1765 {
1766 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1767 m_log.Warn("[PHYSICS]: MakeBody child geom already had a body");
1768 }
1769
1770 d.GeomClearOffset(prm.prim_geom);
1771 d.GeomSetBody(prm.prim_geom, Body);
1772 prm.Body = Body;
1773 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); // set relative rotation
1774 }
1775 }
1776 }
1777
1778 d.GeomClearOffset(prim_geom); // make sure we don't have a hidden offset
1779 // associate root geom with body
1780 d.GeomSetBody(prim_geom, Body);
1781
1782 d.BodySetPosition(Body, _position.X + objdmass.c.X, _position.Y + objdmass.c.Y, _position.Z + objdmass.c.Z);
1783 d.GeomSetOffsetWorldPosition(prim_geom, _position.X, _position.Y, _position.Z);
1784
1785 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
1786 myrot.X = -myrot.X;
1787 myrot.Y = -myrot.Y;
1788 myrot.Z = -myrot.Z;
1789
1790 d.RfromQ(out mymat, ref myrot);
1791 d.MassRotate(ref objdmass, ref mymat);
1792
1793 d.BodySetMass(Body, ref objdmass);
1794 _mass = objdmass.mass;
1795
1796 // disconnect from world gravity so we can apply buoyancy
1797 d.BodySetGravityMode(Body, false);
1798
1799 d.BodySetAutoDisableFlag(Body, true);
1800 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1801 d.BodySetAutoDisableAngularThreshold(Body, 0.05f);
1802 d.BodySetAutoDisableLinearThreshold(Body, 0.05f);
1803 d.BodySetDamping(Body, .008f, .005f);
1804
1805 if (m_targetSpace != IntPtr.Zero)
1806 {
1807 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1808 if (d.SpaceQuery(m_targetSpace, prim_geom))
1809 d.SpaceRemove(m_targetSpace, prim_geom);
1810 }
1811
1812 if (childrenPrim.Count == 0)
1813 {
1814 collide_geom = prim_geom;
1815 m_targetSpace = _parent_scene.ActiveSpace;
1816 }
1817 else
1818 {
1819 m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace);
1820 d.HashSpaceSetLevels(m_targetSpace, -2, 8);
1821 d.SpaceSetSublevel(m_targetSpace, 3);
1822 d.SpaceSetCleanup(m_targetSpace, false);
1823
1824 d.GeomSetCategoryBits(m_targetSpace, (uint)(CollisionCategories.Space |
1825 CollisionCategories.Geom |
1826 CollisionCategories.Phantom |
1827 CollisionCategories.VolumeDtc
1828 ));
1829 d.GeomSetCollideBits(m_targetSpace, 0);
1830 collide_geom = m_targetSpace;
1831 }
1832
1833 d.SpaceAdd(m_targetSpace, prim_geom);
1834
1835 if (m_delaySelect)
1836 {
1837 m_isSelected = true;
1838 m_delaySelect = false;
1839 }
1840
1841 m_collisionscore = 0;
1842
1843 UpdateCollisionCatFlags();
1844 ApplyCollisionCatFlags();
1845
1846 _parent_scene.addActivePrim(this);
1847
1848 lock (childrenPrim)
1849 {
1850 foreach (OdePrim prm in childrenPrim)
1851 {
1852 if (prm.prim_geom == IntPtr.Zero)
1853 continue;
1854
1855 Vector3 ppos = prm._position;
1856 d.GeomSetOffsetWorldPosition(prm.prim_geom, ppos.X, ppos.Y, ppos.Z); // set relative position
1857
1858 if (prm.m_targetSpace != m_targetSpace)
1859 {
1860 if (prm.m_targetSpace != IntPtr.Zero)
1861 {
1862 _parent_scene.waitForSpaceUnlock(prm.m_targetSpace);
1863 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1864 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1865 }
1866 prm.m_targetSpace = m_targetSpace;
1867 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1868 }
1869
1870 prm.m_collisionscore = 0;
1871
1872 if(!m_disabled)
1873 prm.m_disabled = false;
1874
1875 _parent_scene.addActivePrim(prm);
1876 }
1877 }
1878
1879 // The body doesn't already have a finite rotation mode set here
1880 if (m_angularlocks != 0 && _parent == null)
1881 {
1882 createAMotor(m_angularlocks);
1883 }
1884
1885 if (m_isSelected || m_disabled)
1886 {
1887 d.BodyDisable(Body);
1888 _zeroFlag = true;
1889 }
1890 else
1891 {
1892 d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z);
1893 d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z);
1894 _zeroFlag = false;
1895 bodydisablecontrol = 0;
1896 }
1897 _parent_scene.addActiveGroups(this);
1898 }
1899
1900 private void DestroyBody()
1901 {
1902 if (Body != IntPtr.Zero)
1903 {
1904 _parent_scene.remActivePrim(this);
1905
1906 collide_geom = IntPtr.Zero;
1907
1908 if (m_disabled)
1909 m_collisionCategories = 0;
1910 else if (m_isSelected)
1911 m_collisionCategories = CollisionCategories.Selected;
1912 else if (m_isVolumeDetect)
1913 m_collisionCategories = CollisionCategories.VolumeDtc;
1914 else if (m_isphantom)
1915 m_collisionCategories = CollisionCategories.Phantom;
1916 else
1917 m_collisionCategories = CollisionCategories.Geom;
1918
1919 m_collisionFlags = 0;
1920
1921 if (prim_geom != IntPtr.Zero)
1922 {
1923 if (m_NoColide)
1924 {
1925 d.GeomSetCategoryBits(prim_geom, 0);
1926 d.GeomSetCollideBits(prim_geom, 0);
1927 }
1928 else
1929 {
1930 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1931 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1932 }
1933 UpdateDataFromGeom();
1934 d.GeomSetBody(prim_geom, IntPtr.Zero);
1935 SetInStaticSpace(this);
1936 }
1937
1938 if (!childPrim)
1939 {
1940 lock (childrenPrim)
1941 {
1942 foreach (OdePrim prm in childrenPrim)
1943 {
1944 _parent_scene.remActivePrim(prm);
1945
1946 if (prm.m_isSelected)
1947 prm.m_collisionCategories = CollisionCategories.Selected;
1948 else if (prm.m_isVolumeDetect)
1949 prm.m_collisionCategories = CollisionCategories.VolumeDtc;
1950 else if (prm.m_isphantom)
1951 prm.m_collisionCategories = CollisionCategories.Phantom;
1952 else
1953 prm.m_collisionCategories = CollisionCategories.Geom;
1954
1955 prm.m_collisionFlags = 0;
1956
1957 if (prm.prim_geom != IntPtr.Zero)
1958 {
1959 if (prm.m_NoColide)
1960 {
1961 d.GeomSetCategoryBits(prm.prim_geom, 0);
1962 d.GeomSetCollideBits(prm.prim_geom, 0);
1963 }
1964 else
1965 {
1966 d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
1967 d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
1968 }
1969 prm.UpdateDataFromGeom();
1970 SetInStaticSpace(prm);
1971 }
1972 prm.Body = IntPtr.Zero;
1973 prm._mass = prm.primMass;
1974 prm.m_collisionscore = 0;
1975 }
1976 }
1977 if (Amotor != IntPtr.Zero)
1978 {
1979 d.JointDestroy(Amotor);
1980 Amotor = IntPtr.Zero;
1981 }
1982 _parent_scene.remActiveGroup(this);
1983 d.BodyDestroy(Body);
1984 }
1985 Body = IntPtr.Zero;
1986 }
1987 _mass = primMass;
1988 m_collisionscore = 0;
1989 }
1990
1991 private void FixInertia(Vector3 NewPos,Quaternion newrot)
1992 {
1993 d.Matrix3 mat = new d.Matrix3();
1994 d.Quaternion quat = new d.Quaternion();
1995
1996 d.Mass tmpdmass = new d.Mass { };
1997 d.Mass objdmass = new d.Mass { };
1998
1999 d.BodyGetMass(Body, out tmpdmass);
2000 objdmass = tmpdmass;
2001
2002 d.Vector3 dobjpos;
2003 d.Vector3 thispos;
2004
2005 // get current object position and rotation
2006 dobjpos = d.BodyGetPosition(Body);
2007
2008 // get prim own inertia in its local frame
2009 tmpdmass = primdMass;
2010
2011 // transform to object frame
2012 mat = d.GeomGetOffsetRotation(prim_geom);
2013 d.MassRotate(ref tmpdmass, ref mat);
2014
2015 thispos = d.GeomGetOffsetPosition(prim_geom);
2016 d.MassTranslate(ref tmpdmass,
2017 thispos.X,
2018 thispos.Y,
2019 thispos.Z);
2020
2021 // subtract current prim inertia from object
2022 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2023
2024 // back prim own inertia
2025 tmpdmass = primdMass;
2026
2027 // update to new position and orientation
2028 _position = NewPos;
2029 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2030 _orientation = newrot;
2031 quat.X = newrot.X;
2032 quat.Y = newrot.Y;
2033 quat.Z = newrot.Z;
2034 quat.W = newrot.W;
2035 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2036
2037 mat = d.GeomGetOffsetRotation(prim_geom);
2038 d.MassRotate(ref tmpdmass, ref mat);
2039
2040 thispos = d.GeomGetOffsetPosition(prim_geom);
2041 d.MassTranslate(ref tmpdmass,
2042 thispos.X,
2043 thispos.Y,
2044 thispos.Z);
2045
2046 d.MassAdd(ref objdmass, ref tmpdmass);
2047
2048 // fix all positions
2049 IntPtr g = d.BodyGetFirstGeom(Body);
2050 while (g != IntPtr.Zero)
2051 {
2052 thispos = d.GeomGetOffsetPosition(g);
2053 thispos.X -= objdmass.c.X;
2054 thispos.Y -= objdmass.c.Y;
2055 thispos.Z -= objdmass.c.Z;
2056 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2057 g = d.dBodyGetNextGeom(g);
2058 }
2059 d.BodyVectorToWorld(Body,objdmass.c.X, objdmass.c.Y, objdmass.c.Z,out thispos);
2060
2061 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2062 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2063 d.BodySetMass(Body, ref objdmass);
2064 _mass = objdmass.mass;
2065 }
2066
2067
2068
2069 private void FixInertia(Vector3 NewPos)
2070 {
2071 d.Matrix3 primmat = new d.Matrix3();
2072 d.Mass tmpdmass = new d.Mass { };
2073 d.Mass objdmass = new d.Mass { };
2074 d.Mass primmass = new d.Mass { };
2075
2076 d.Vector3 dobjpos;
2077 d.Vector3 thispos;
2078
2079 d.BodyGetMass(Body, out objdmass);
2080
2081 // get prim own inertia in its local frame
2082 primmass = primdMass;
2083 // transform to object frame
2084 primmat = d.GeomGetOffsetRotation(prim_geom);
2085 d.MassRotate(ref primmass, ref primmat);
2086
2087 tmpdmass = primmass;
2088
2089 thispos = d.GeomGetOffsetPosition(prim_geom);
2090 d.MassTranslate(ref tmpdmass,
2091 thispos.X,
2092 thispos.Y,
2093 thispos.Z);
2094
2095 // subtract current prim inertia from object
2096 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2097
2098 // update to new position
2099 _position = NewPos;
2100 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2101
2102 thispos = d.GeomGetOffsetPosition(prim_geom);
2103 d.MassTranslate(ref primmass,
2104 thispos.X,
2105 thispos.Y,
2106 thispos.Z);
2107
2108 d.MassAdd(ref objdmass, ref primmass);
2109
2110 // fix all positions
2111 IntPtr g = d.BodyGetFirstGeom(Body);
2112 while (g != IntPtr.Zero)
2113 {
2114 thispos = d.GeomGetOffsetPosition(g);
2115 thispos.X -= objdmass.c.X;
2116 thispos.Y -= objdmass.c.Y;
2117 thispos.Z -= objdmass.c.Z;
2118 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2119 g = d.dBodyGetNextGeom(g);
2120 }
2121
2122 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2123
2124 // get current object position and rotation
2125 dobjpos = d.BodyGetPosition(Body);
2126
2127 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2128 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2129 d.BodySetMass(Body, ref objdmass);
2130 _mass = objdmass.mass;
2131 }
2132
2133 private void FixInertia(Quaternion newrot)
2134 {
2135 d.Matrix3 mat = new d.Matrix3();
2136 d.Quaternion quat = new d.Quaternion();
2137
2138 d.Mass tmpdmass = new d.Mass { };
2139 d.Mass objdmass = new d.Mass { };
2140 d.Vector3 dobjpos;
2141 d.Vector3 thispos;
2142
2143 d.BodyGetMass(Body, out objdmass);
2144
2145 // get prim own inertia in its local frame
2146 tmpdmass = primdMass;
2147 mat = d.GeomGetOffsetRotation(prim_geom);
2148 d.MassRotate(ref tmpdmass, ref mat);
2149 // transform to object frame
2150 thispos = d.GeomGetOffsetPosition(prim_geom);
2151 d.MassTranslate(ref tmpdmass,
2152 thispos.X,
2153 thispos.Y,
2154 thispos.Z);
2155
2156 // subtract current prim inertia from object
2157 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2158
2159 // update to new orientation
2160 _orientation = newrot;
2161 quat.X = newrot.X;
2162 quat.Y = newrot.Y;
2163 quat.Z = newrot.Z;
2164 quat.W = newrot.W;
2165 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2166
2167 tmpdmass = primdMass;
2168 mat = d.GeomGetOffsetRotation(prim_geom);
2169 d.MassRotate(ref tmpdmass, ref mat);
2170 d.MassTranslate(ref tmpdmass,
2171 thispos.X,
2172 thispos.Y,
2173 thispos.Z);
2174
2175 d.MassAdd(ref objdmass, ref tmpdmass);
2176
2177 // fix all positions
2178 IntPtr g = d.BodyGetFirstGeom(Body);
2179 while (g != IntPtr.Zero)
2180 {
2181 thispos = d.GeomGetOffsetPosition(g);
2182 thispos.X -= objdmass.c.X;
2183 thispos.Y -= objdmass.c.Y;
2184 thispos.Z -= objdmass.c.Z;
2185 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2186 g = d.dBodyGetNextGeom(g);
2187 }
2188
2189 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2190 // get current object position and rotation
2191 dobjpos = d.BodyGetPosition(Body);
2192
2193 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2194 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2195 d.BodySetMass(Body, ref objdmass);
2196 _mass = objdmass.mass;
2197 }
2198
2199
2200 #region Mass Calculation
2201
2202 private void UpdatePrimBodyData()
2203 {
2204 primMass = m_density * primVolume;
2205
2206 if (primMass <= 0)
2207 primMass = 0.0001f;//ckrinke: Mass must be greater then zero.
2208 if (primMass > _parent_scene.maximumMassObject)
2209 primMass = _parent_scene.maximumMassObject;
2210
2211 _mass = primMass; // just in case
2212
2213 d.MassSetBoxTotal(out primdMass, primMass, 2.0f * m_OBB.X, 2.0f * m_OBB.Y, 2.0f * m_OBB.Z);
2214
2215 d.MassTranslate(ref primdMass,
2216 m_OBBOffset.X,
2217 m_OBBOffset.Y,
2218 m_OBBOffset.Z);
2219
2220 primOOBradiusSQ = m_OBB.LengthSquared();
2221
2222 if (_triMeshData != IntPtr.Zero)
2223 {
2224 float pc = m_physCost;
2225 float psf = primOOBradiusSQ;
2226 psf *= 1.33f * .2f;
2227 pc *= psf;
2228 if (pc < 0.1f)
2229 pc = 0.1f;
2230
2231 m_physCost = pc;
2232 }
2233 else
2234 m_physCost = 0.1f;
2235
2236 m_streamCost = 1.0f;
2237 }
2238
2239 #endregion
2240
2241
2242 /// <summary>
2243 /// Add a child prim to this parent prim.
2244 /// </summary>
2245 /// <param name="prim">Child prim</param>
2246 // I'm the parent
2247 // prim is the child
2248 public void ParentPrim(OdePrim prim)
2249 {
2250 //Console.WriteLine("ParentPrim " + m_primName);
2251 if (this.m_localID != prim.m_localID)
2252 {
2253 DestroyBody(); // for now we need to rebuil entire object on link change
2254
2255 lock (childrenPrim)
2256 {
2257 // adopt the prim
2258 if (!childrenPrim.Contains(prim))
2259 childrenPrim.Add(prim);
2260
2261 // see if this prim has kids and adopt them also
2262 // should not happen for now
2263 foreach (OdePrim prm in prim.childrenPrim)
2264 {
2265 if (!childrenPrim.Contains(prm))
2266 {
2267 if (prm.Body != IntPtr.Zero)
2268 {
2269 if (prm.prim_geom != IntPtr.Zero)
2270 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
2271 if (prm.Body != prim.Body)
2272 prm.DestroyBody(); // don't loose bodies around
2273 prm.Body = IntPtr.Zero;
2274 }
2275
2276 childrenPrim.Add(prm);
2277 prm._parent = this;
2278 }
2279 }
2280 }
2281 //Remove old children from the prim
2282 prim.childrenPrim.Clear();
2283
2284 if (prim.Body != IntPtr.Zero)
2285 {
2286 if (prim.prim_geom != IntPtr.Zero)
2287 d.GeomSetBody(prim.prim_geom, IntPtr.Zero);
2288 prim.DestroyBody(); // don't loose bodies around
2289 prim.Body = IntPtr.Zero;
2290 }
2291
2292 prim.childPrim = true;
2293 prim._parent = this;
2294
2295 MakeBody(); // full nasty reconstruction
2296 }
2297 }
2298
2299 private void UpdateChildsfromgeom()
2300 {
2301 if (childrenPrim.Count > 0)
2302 {
2303 foreach (OdePrim prm in childrenPrim)
2304 prm.UpdateDataFromGeom();
2305 }
2306 }
2307
2308 private void UpdateDataFromGeom()
2309 {
2310 if (prim_geom != IntPtr.Zero)
2311 {
2312 d.Quaternion qtmp;
2313 d.GeomCopyQuaternion(prim_geom, out qtmp);
2314 _orientation.X = qtmp.X;
2315 _orientation.Y = qtmp.Y;
2316 _orientation.Z = qtmp.Z;
2317 _orientation.W = qtmp.W;
2318/*
2319// Debug
2320 float qlen = _orientation.Length();
2321 if (qlen > 1.01f || qlen < 0.99)
2322 m_log.WarnFormat("[PHYSICS]: Got nonnorm quaternion from geom in Object {0} norm {1}", Name, qlen);
2323//
2324*/
2325 _orientation.Normalize();
2326
2327 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
2328 _position.X = lpos.X;
2329 _position.Y = lpos.Y;
2330 _position.Z = lpos.Z;
2331 }
2332 }
2333
2334 private void ChildDelink(OdePrim odePrim, bool remakebodies)
2335 {
2336 // Okay, we have a delinked child.. destroy all body and remake
2337 if (odePrim != this && !childrenPrim.Contains(odePrim))
2338 return;
2339
2340 DestroyBody();
2341
2342 if (odePrim == this) // delinking the root prim
2343 {
2344 OdePrim newroot = null;
2345 lock (childrenPrim)
2346 {
2347 if (childrenPrim.Count > 0)
2348 {
2349 newroot = childrenPrim[0];
2350 childrenPrim.RemoveAt(0);
2351 foreach (OdePrim prm in childrenPrim)
2352 {
2353 newroot.childrenPrim.Add(prm);
2354 }
2355 childrenPrim.Clear();
2356 }
2357 if (newroot != null)
2358 {
2359 newroot.childPrim = false;
2360 newroot._parent = null;
2361 if (remakebodies)
2362 newroot.MakeBody();
2363 }
2364 }
2365 }
2366
2367 else
2368 {
2369 lock (childrenPrim)
2370 {
2371 childrenPrim.Remove(odePrim);
2372 odePrim.childPrim = false;
2373 odePrim._parent = null;
2374 // odePrim.UpdateDataFromGeom();
2375 if (remakebodies)
2376 odePrim.MakeBody();
2377 }
2378 }
2379 if (remakebodies)
2380 MakeBody();
2381 }
2382
2383 protected void ChildRemove(OdePrim odePrim, bool reMakeBody)
2384 {
2385 // Okay, we have a delinked child.. destroy all body and remake
2386 if (odePrim != this && !childrenPrim.Contains(odePrim))
2387 return;
2388
2389 DestroyBody();
2390
2391 if (odePrim == this)
2392 {
2393 OdePrim newroot = null;
2394 lock (childrenPrim)
2395 {
2396 if (childrenPrim.Count > 0)
2397 {
2398 newroot = childrenPrim[0];
2399 childrenPrim.RemoveAt(0);
2400 foreach (OdePrim prm in childrenPrim)
2401 {
2402 newroot.childrenPrim.Add(prm);
2403 }
2404 childrenPrim.Clear();
2405 }
2406 if (newroot != null)
2407 {
2408 newroot.childPrim = false;
2409 newroot._parent = null;
2410 newroot.MakeBody();
2411 }
2412 }
2413 if (reMakeBody)
2414 MakeBody();
2415 return;
2416 }
2417 else
2418 {
2419 lock (childrenPrim)
2420 {
2421 childrenPrim.Remove(odePrim);
2422 odePrim.childPrim = false;
2423 odePrim._parent = null;
2424 if (reMakeBody)
2425 odePrim.MakeBody();
2426 }
2427 }
2428 MakeBody();
2429 }
2430
2431
2432 #region changes
2433
2434 private void changeadd()
2435 {
2436 }
2437
2438 private void changeAngularLock(byte newLocks)
2439 {
2440 // do we have a Physical object?
2441 if (Body != IntPtr.Zero)
2442 {
2443 //Check that we have a Parent
2444 //If we have a parent then we're not authorative here
2445 if (_parent == null)
2446 {
2447 if (newLocks != 0)
2448 {
2449 createAMotor(newLocks);
2450 }
2451 else
2452 {
2453 if (Amotor != IntPtr.Zero)
2454 {
2455 d.JointDestroy(Amotor);
2456 Amotor = IntPtr.Zero;
2457 }
2458 }
2459 }
2460 }
2461 // Store this for later in case we get turned into a separate body
2462 m_angularlocks = newLocks;
2463 }
2464
2465 private void changeLink(OdePrim NewParent)
2466 {
2467 if (_parent == null && NewParent != null)
2468 {
2469 NewParent.ParentPrim(this);
2470 }
2471 else if (_parent != null)
2472 {
2473 if (_parent is OdePrim)
2474 {
2475 if (NewParent != _parent)
2476 {
2477 (_parent as OdePrim).ChildDelink(this, false); // for now...
2478 childPrim = false;
2479
2480 if (NewParent != null)
2481 {
2482 NewParent.ParentPrim(this);
2483 }
2484 }
2485 }
2486 }
2487 _parent = NewParent;
2488 }
2489
2490
2491 private void Stop()
2492 {
2493 if (!childPrim)
2494 {
2495// m_force = Vector3.Zero;
2496 m_forceacc = Vector3.Zero;
2497 m_angularForceacc = Vector3.Zero;
2498// m_torque = Vector3.Zero;
2499 _velocity = Vector3.Zero;
2500 _acceleration = Vector3.Zero;
2501 m_rotationalVelocity = Vector3.Zero;
2502 _target_velocity = Vector3.Zero;
2503 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2504 m_vehicle.Stop();
2505
2506 _zeroFlag = false;
2507 base.RequestPhysicsterseUpdate();
2508 }
2509
2510 if (Body != IntPtr.Zero)
2511 {
2512 d.BodySetForce(Body, 0f, 0f, 0f);
2513 d.BodySetTorque(Body, 0f, 0f, 0f);
2514 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2515 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2516 }
2517 }
2518
2519 private void changePhantomStatus(bool newval)
2520 {
2521 m_isphantom = newval;
2522
2523 UpdateCollisionCatFlags();
2524 ApplyCollisionCatFlags();
2525 }
2526
2527/* not in use
2528 internal void ChildSelectedChange(bool childSelect)
2529 {
2530 if(childPrim)
2531 return;
2532
2533 if (childSelect == m_isSelected)
2534 return;
2535
2536 if (childSelect)
2537 {
2538 DoSelectedStatus(true);
2539 }
2540
2541 else
2542 {
2543 foreach (OdePrim prm in childrenPrim)
2544 {
2545 if (prm.m_isSelected)
2546 return;
2547 }
2548 DoSelectedStatus(false);
2549 }
2550 }
2551*/
2552 private void changeSelectedStatus(bool newval)
2553 {
2554 if (m_lastdoneSelected == newval)
2555 return;
2556
2557 m_lastdoneSelected = newval;
2558 DoSelectedStatus(newval);
2559 }
2560
2561 private void CheckDelaySelect()
2562 {
2563 if (m_delaySelect)
2564 {
2565 DoSelectedStatus(m_isSelected);
2566 }
2567 }
2568
2569 private void DoSelectedStatus(bool newval)
2570 {
2571 m_isSelected = newval;
2572 Stop();
2573
2574 if (newval)
2575 {
2576 if (!childPrim && Body != IntPtr.Zero)
2577 d.BodyDisable(Body);
2578
2579 if (m_delaySelect || m_isphysical)
2580 {
2581 m_collisionCategories = CollisionCategories.Selected;
2582 m_collisionFlags = 0;
2583
2584 if (!childPrim)
2585 {
2586 foreach (OdePrim prm in childrenPrim)
2587 {
2588 prm.m_collisionCategories = m_collisionCategories;
2589 prm.m_collisionFlags = m_collisionFlags;
2590
2591 if (prm.prim_geom != IntPtr.Zero)
2592 {
2593
2594 if (prm.m_NoColide)
2595 {
2596 d.GeomSetCategoryBits(prm.prim_geom, 0);
2597 d.GeomSetCollideBits(prm.prim_geom, 0);
2598 }
2599 else
2600 {
2601 d.GeomSetCategoryBits(prm.prim_geom, (uint)m_collisionCategories);
2602 d.GeomSetCollideBits(prm.prim_geom, (uint)m_collisionFlags);
2603 }
2604 }
2605 prm.m_delaySelect = false;
2606 }
2607 }
2608// else if (_parent != null)
2609// ((OdePrim)_parent).ChildSelectedChange(true);
2610
2611
2612 if (prim_geom != IntPtr.Zero)
2613 {
2614 if (m_NoColide)
2615 {
2616 d.GeomSetCategoryBits(prim_geom, 0);
2617 d.GeomSetCollideBits(prim_geom, 0);
2618 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2619 {
2620 d.GeomSetCategoryBits(collide_geom, 0);
2621 d.GeomSetCollideBits(collide_geom, 0);
2622 }
2623
2624 }
2625 else
2626 {
2627 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
2628 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
2629 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2630 {
2631 d.GeomSetCategoryBits(collide_geom, (uint)m_collisionCategories);
2632 d.GeomSetCollideBits(collide_geom, (uint)m_collisionFlags);
2633 }
2634 }
2635 }
2636
2637 m_delaySelect = false;
2638 }
2639 else if(!m_isphysical)
2640 {
2641 m_delaySelect = true;
2642 }
2643 }
2644 else
2645 {
2646 if (!childPrim)
2647 {
2648 if (Body != IntPtr.Zero && !m_disabled)
2649 {
2650 _zeroFlag = true;
2651 d.BodyEnable(Body);
2652 }
2653 }
2654// else if (_parent != null)
2655// ((OdePrim)_parent).ChildSelectedChange(false);
2656
2657 UpdateCollisionCatFlags();
2658 ApplyCollisionCatFlags();
2659
2660 m_delaySelect = false;
2661 }
2662
2663 resetCollisionAccounting();
2664 }
2665
2666 private void changePosition(Vector3 newPos)
2667 {
2668 CheckDelaySelect();
2669 if (m_isphysical)
2670 {
2671 if (childPrim) // inertia is messed, must rebuild
2672 {
2673 if (m_building)
2674 {
2675 _position = newPos;
2676 }
2677
2678 else if (m_forcePosOrRotation && _position != newPos && Body != IntPtr.Zero)
2679 {
2680 FixInertia(newPos);
2681 if (!d.BodyIsEnabled(Body))
2682 {
2683 _zeroFlag = true;
2684 d.BodyEnable(Body);
2685 }
2686 }
2687 }
2688 else
2689 {
2690 if (_position != newPos)
2691 {
2692 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2693 _position = newPos;
2694 }
2695 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2696 {
2697 _zeroFlag = true;
2698 d.BodyEnable(Body);
2699 }
2700 }
2701 }
2702 else
2703 {
2704 if (prim_geom != IntPtr.Zero)
2705 {
2706 if (newPos != _position)
2707 {
2708 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2709 _position = newPos;
2710
2711 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2712 }
2713 }
2714 }
2715 givefakepos--;
2716 if (givefakepos < 0)
2717 givefakepos = 0;
2718// changeSelectedStatus();
2719 resetCollisionAccounting();
2720 }
2721
2722 private void changeOrientation(Quaternion newOri)
2723 {
2724 CheckDelaySelect();
2725 if (m_isphysical)
2726 {
2727 if (childPrim) // inertia is messed, must rebuild
2728 {
2729 if (m_building)
2730 {
2731 _orientation = newOri;
2732 }
2733/*
2734 else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero)
2735 {
2736 FixInertia(_position, newOri);
2737 if (!d.BodyIsEnabled(Body))
2738 d.BodyEnable(Body);
2739 }
2740*/
2741 }
2742 else
2743 {
2744 if (newOri != _orientation)
2745 {
2746 d.Quaternion myrot = new d.Quaternion();
2747 myrot.X = newOri.X;
2748 myrot.Y = newOri.Y;
2749 myrot.Z = newOri.Z;
2750 myrot.W = newOri.W;
2751 d.GeomSetQuaternion(prim_geom, ref myrot);
2752 _orientation = newOri;
2753 if (Body != IntPtr.Zero && m_angularlocks != 0)
2754 createAMotor(m_angularlocks);
2755 }
2756 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2757 {
2758 _zeroFlag = true;
2759 d.BodyEnable(Body);
2760 }
2761 }
2762 }
2763 else
2764 {
2765 if (prim_geom != IntPtr.Zero)
2766 {
2767 if (newOri != _orientation)
2768 {
2769 d.Quaternion myrot = new d.Quaternion();
2770 myrot.X = newOri.X;
2771 myrot.Y = newOri.Y;
2772 myrot.Z = newOri.Z;
2773 myrot.W = newOri.W;
2774 d.GeomSetQuaternion(prim_geom, ref myrot);
2775 _orientation = newOri;
2776 }
2777 }
2778 }
2779 givefakeori--;
2780 if (givefakeori < 0)
2781 givefakeori = 0;
2782 resetCollisionAccounting();
2783 }
2784
2785 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2786 {
2787 CheckDelaySelect();
2788 if (m_isphysical)
2789 {
2790 if (childPrim && m_building) // inertia is messed, must rebuild
2791 {
2792 _position = newPos;
2793 _orientation = newOri;
2794 }
2795 else
2796 {
2797 if (newOri != _orientation)
2798 {
2799 d.Quaternion myrot = new d.Quaternion();
2800 myrot.X = newOri.X;
2801 myrot.Y = newOri.Y;
2802 myrot.Z = newOri.Z;
2803 myrot.W = newOri.W;
2804 d.GeomSetQuaternion(prim_geom, ref myrot);
2805 _orientation = newOri;
2806 if (Body != IntPtr.Zero && m_angularlocks != 0)
2807 createAMotor(m_angularlocks);
2808 }
2809 if (_position != newPos)
2810 {
2811 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2812 _position = newPos;
2813 }
2814 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2815 {
2816 _zeroFlag = true;
2817 d.BodyEnable(Body);
2818 }
2819 }
2820 }
2821 else
2822 {
2823 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2824 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2825
2826 if (prim_geom != IntPtr.Zero)
2827 {
2828 if (newOri != _orientation)
2829 {
2830 d.Quaternion myrot = new d.Quaternion();
2831 myrot.X = newOri.X;
2832 myrot.Y = newOri.Y;
2833 myrot.Z = newOri.Z;
2834 myrot.W = newOri.W;
2835 d.GeomSetQuaternion(prim_geom, ref myrot);
2836 _orientation = newOri;
2837 }
2838
2839 if (newPos != _position)
2840 {
2841 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2842 _position = newPos;
2843
2844 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2845 }
2846 }
2847 }
2848 givefakepos--;
2849 if (givefakepos < 0)
2850 givefakepos = 0;
2851 givefakeori--;
2852 if (givefakeori < 0)
2853 givefakeori = 0;
2854 resetCollisionAccounting();
2855 }
2856
2857 private void changeDisable(bool disable)
2858 {
2859 if (disable)
2860 {
2861 if (!m_disabled)
2862 disableBodySoft();
2863 }
2864 else
2865 {
2866 if (m_disabled)
2867 enableBodySoft();
2868 }
2869 }
2870
2871 private void changePhysicsStatus(bool NewStatus)
2872 {
2873 CheckDelaySelect();
2874
2875 m_isphysical = NewStatus;
2876
2877 if (!childPrim)
2878 {
2879 if (NewStatus)
2880 {
2881 if (Body == IntPtr.Zero)
2882 MakeBody();
2883 }
2884 else
2885 {
2886 if (Body != IntPtr.Zero)
2887 {
2888 DestroyBody();
2889 }
2890 Stop();
2891 }
2892 }
2893
2894 resetCollisionAccounting();
2895 }
2896
2897 private void changeSize(Vector3 newSize)
2898 {
2899 }
2900
2901 private void changeShape(PrimitiveBaseShape newShape)
2902 {
2903 }
2904
2905 private void changeAddPhysRep(ODEPhysRepData repData)
2906 {
2907 _size = repData.size; //??
2908 _pbs = repData.pbs;
2909 m_shapetype = repData.shapetype;
2910
2911 m_mesh = repData.mesh;
2912
2913 m_assetID = repData.assetID;
2914 m_meshState = repData.meshState;
2915
2916 m_hasOBB = repData.hasOBB;
2917 m_OBBOffset = repData.OBBOffset;
2918 m_OBB = repData.OBB;
2919
2920 primVolume = repData.volume;
2921
2922 CreateGeom();
2923
2924 if (prim_geom != IntPtr.Zero)
2925 {
2926 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2927 d.Quaternion myrot = new d.Quaternion();
2928 myrot.X = _orientation.X;
2929 myrot.Y = _orientation.Y;
2930 myrot.Z = _orientation.Z;
2931 myrot.W = _orientation.W;
2932 d.GeomSetQuaternion(prim_geom, ref myrot);
2933 }
2934
2935 if (!m_isphysical)
2936 {
2937 SetInStaticSpace(this);
2938 UpdateCollisionCatFlags();
2939 ApplyCollisionCatFlags();
2940 }
2941 else
2942 MakeBody();
2943
2944 if ((m_meshState & MeshState.NeedMask) != 0)
2945 {
2946 repData.size = _size;
2947 repData.pbs = _pbs;
2948 repData.shapetype = m_shapetype;
2949 _parent_scene.m_meshWorker.RequestMesh(repData);
2950 }
2951 }
2952
2953 private void changePhysRepData(ODEPhysRepData repData)
2954 {
2955 CheckDelaySelect();
2956
2957 OdePrim parent = (OdePrim)_parent;
2958
2959 bool chp = childPrim;
2960
2961 if (chp)
2962 {
2963 if (parent != null)
2964 {
2965 parent.DestroyBody();
2966 }
2967 }
2968 else
2969 {
2970 DestroyBody();
2971 }
2972
2973 RemoveGeom();
2974
2975 _size = repData.size;
2976 _pbs = repData.pbs;
2977 m_shapetype = repData.shapetype;
2978
2979 m_mesh = repData.mesh;
2980
2981 m_assetID = repData.assetID;
2982 m_meshState = repData.meshState;
2983
2984 m_hasOBB = repData.hasOBB;
2985 m_OBBOffset = repData.OBBOffset;
2986 m_OBB = repData.OBB;
2987
2988 primVolume = repData.volume;
2989
2990 CreateGeom();
2991
2992 if (prim_geom != IntPtr.Zero)
2993 {
2994 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2995 d.Quaternion myrot = new d.Quaternion();
2996 myrot.X = _orientation.X;
2997 myrot.Y = _orientation.Y;
2998 myrot.Z = _orientation.Z;
2999 myrot.W = _orientation.W;
3000 d.GeomSetQuaternion(prim_geom, ref myrot);
3001 }
3002
3003 if (m_isphysical)
3004 {
3005 if (chp)
3006 {
3007 if (parent != null)
3008 {
3009 parent.MakeBody();
3010 }
3011 }
3012 else
3013 MakeBody();
3014 }
3015 else
3016 {
3017 SetInStaticSpace(this);
3018 UpdateCollisionCatFlags();
3019 ApplyCollisionCatFlags();
3020 }
3021
3022 resetCollisionAccounting();
3023
3024 if ((m_meshState & MeshState.NeedMask) != 0)
3025 {
3026 repData.size = _size;
3027 repData.pbs = _pbs;
3028 repData.shapetype = m_shapetype;
3029 _parent_scene.m_meshWorker.RequestMesh(repData);
3030 }
3031 }
3032
3033 private void changeFloatOnWater(bool newval)
3034 {
3035 m_collidesWater = newval;
3036
3037 UpdateCollisionCatFlags();
3038 ApplyCollisionCatFlags();
3039 }
3040
3041 private void changeSetTorque(Vector3 newtorque)
3042 {
3043 if (!m_isSelected)
3044 {
3045 if (m_isphysical && Body != IntPtr.Zero)
3046 {
3047 if (m_disabled)
3048 enableBodySoft();
3049 else if (!d.BodyIsEnabled(Body))
3050 d.BodyEnable(Body);
3051
3052 }
3053 m_torque = newtorque;
3054 }
3055 }
3056
3057 private void changeForce(Vector3 force)
3058 {
3059 m_force = force;
3060 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
3061 d.BodyEnable(Body);
3062 }
3063
3064 private void changeAddForce(Vector3 theforce)
3065 {
3066 m_forceacc += theforce;
3067 if (!m_isSelected)
3068 {
3069 lock (this)
3070 {
3071 //m_log.Info("[PHYSICS]: dequeing forcelist");
3072 if (m_isphysical && Body != IntPtr.Zero)
3073 {
3074 if (m_disabled)
3075 enableBodySoft();
3076 else if (!d.BodyIsEnabled(Body))
3077 d.BodyEnable(Body);
3078 }
3079 }
3080 m_collisionscore = 0;
3081 }
3082 }
3083
3084 // actually angular impulse
3085 private void changeAddAngularImpulse(Vector3 aimpulse)
3086 {
3087 m_angularForceacc += aimpulse * m_invTimeStep;
3088 if (!m_isSelected)
3089 {
3090 lock (this)
3091 {
3092 if (m_isphysical && Body != IntPtr.Zero)
3093 {
3094 if (m_disabled)
3095 enableBodySoft();
3096 else if (!d.BodyIsEnabled(Body))
3097 d.BodyEnable(Body);
3098 }
3099 }
3100 m_collisionscore = 0;
3101 }
3102 }
3103
3104 private void changevelocity(Vector3 newVel)
3105 {
3106 float len = newVel.LengthSquared();
3107 if (len > 100000.0f) // limit to 100m/s
3108 {
3109 len = 100.0f / (float)Math.Sqrt(len);
3110 newVel *= len;
3111 }
3112
3113 if (!m_isSelected)
3114 {
3115 if (Body != IntPtr.Zero)
3116 {
3117 if (m_disabled)
3118 enableBodySoft();
3119 else if (!d.BodyIsEnabled(Body))
3120 d.BodyEnable(Body);
3121
3122 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
3123 }
3124 //resetCollisionAccounting();
3125 }
3126 _velocity = newVel;
3127 }
3128
3129 private void changeangvelocity(Vector3 newAngVel)
3130 {
3131 float len = newAngVel.LengthSquared();
3132 if (len > 144.0f) // limit to 12rad/s
3133 {
3134 len = 12.0f / (float)Math.Sqrt(len);
3135 newAngVel *= len;
3136 }
3137
3138 if (!m_isSelected)
3139 {
3140 if (Body != IntPtr.Zero)
3141 {
3142 if (m_disabled)
3143 enableBodySoft();
3144 else if (!d.BodyIsEnabled(Body))
3145 d.BodyEnable(Body);
3146
3147
3148 d.BodySetAngularVel(Body, newAngVel.X, newAngVel.Y, newAngVel.Z);
3149 }
3150 //resetCollisionAccounting();
3151 }
3152 m_rotationalVelocity = newAngVel;
3153 }
3154
3155 private void changeVolumedetetion(bool newVolDtc)
3156 {
3157 m_isVolumeDetect = newVolDtc;
3158 m_fakeisVolumeDetect = newVolDtc;
3159 UpdateCollisionCatFlags();
3160 ApplyCollisionCatFlags();
3161 }
3162
3163 protected void changeBuilding(bool newbuilding)
3164 {
3165 // Check if we need to do anything
3166 if (newbuilding == m_building)
3167 return;
3168
3169 if ((bool)newbuilding)
3170 {
3171 m_building = true;
3172 if (!childPrim)
3173 DestroyBody();
3174 }
3175 else
3176 {
3177 m_building = false;
3178 CheckDelaySelect();
3179 if (!childPrim)
3180 MakeBody();
3181 }
3182 if (!childPrim && childrenPrim.Count > 0)
3183 {
3184 foreach (OdePrim prm in childrenPrim)
3185 prm.changeBuilding(m_building); // call directly
3186 }
3187 }
3188
3189 public void changeSetVehicle(VehicleData vdata)
3190 {
3191 if (m_vehicle == null)
3192 m_vehicle = new ODEDynamics(this);
3193 m_vehicle.DoSetVehicle(vdata);
3194 }
3195
3196 private void changeVehicleType(int value)
3197 {
3198 if (value == (int)Vehicle.TYPE_NONE)
3199 {
3200 if (m_vehicle != null)
3201 m_vehicle = null;
3202 }
3203 else
3204 {
3205 if (m_vehicle == null)
3206 m_vehicle = new ODEDynamics(this);
3207
3208 m_vehicle.ProcessTypeChange((Vehicle)value);
3209 }
3210 }
3211
3212 private void changeVehicleFloatParam(strVehicleFloatParam fp)
3213 {
3214 if (m_vehicle == null)
3215 return;
3216
3217 m_vehicle.ProcessFloatVehicleParam((Vehicle)fp.param, fp.value);
3218 }
3219
3220 private void changeVehicleVectorParam(strVehicleVectorParam vp)
3221 {
3222 if (m_vehicle == null)
3223 return;
3224 m_vehicle.ProcessVectorVehicleParam((Vehicle)vp.param, vp.value);
3225 }
3226
3227 private void changeVehicleRotationParam(strVehicleQuatParam qp)
3228 {
3229 if (m_vehicle == null)
3230 return;
3231 m_vehicle.ProcessRotationVehicleParam((Vehicle)qp.param, qp.value);
3232 }
3233
3234 private void changeVehicleFlags(strVehicleBoolParam bp)
3235 {
3236 if (m_vehicle == null)
3237 return;
3238 m_vehicle.ProcessVehicleFlags(bp.param, bp.value);
3239 }
3240
3241 private void changeBuoyancy(float b)
3242 {
3243 m_buoyancy = b;
3244 }
3245
3246 private void changePIDTarget(Vector3 trg)
3247 {
3248 m_PIDTarget = trg;
3249 }
3250
3251 private void changePIDTau(float tau)
3252 {
3253 m_PIDTau = tau;
3254 }
3255
3256 private void changePIDActive(bool val)
3257 {
3258 m_usePID = val;
3259 }
3260
3261 private void changePIDHoverHeight(float val)
3262 {
3263 m_PIDHoverHeight = val;
3264 if (val == 0)
3265 m_useHoverPID = false;
3266 }
3267
3268 private void changePIDHoverType(PIDHoverType type)
3269 {
3270 m_PIDHoverType = type;
3271 }
3272
3273 private void changePIDHoverTau(float tau)
3274 {
3275 m_PIDHoverTau = tau;
3276 }
3277
3278 private void changePIDHoverActive(bool active)
3279 {
3280 m_useHoverPID = active;
3281 }
3282
3283 #endregion
3284
3285 public void Move()
3286 {
3287 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
3288 !m_disabled && !m_isSelected && !m_building && !m_outbounds)
3289 {
3290 if (!d.BodyIsEnabled(Body))
3291 {
3292 // let vehicles sleep
3293 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3294 return;
3295
3296 if (++bodydisablecontrol < 50)
3297 return;
3298
3299 // clear residuals
3300 d.BodySetAngularVel(Body,0f,0f,0f);
3301 d.BodySetLinearVel(Body,0f,0f,0f);
3302 _zeroFlag = true;
3303 d.BodyEnable(Body);
3304 bodydisablecontrol = -4;
3305 }
3306
3307 if(bodydisablecontrol < 0)
3308 bodydisablecontrol ++;
3309
3310 d.Vector3 lpos = d.GeomGetPosition(prim_geom); // root position that is seem by rest of simulator
3311
3312 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3313 {
3314 // 'VEHICLES' are dealt with in ODEDynamics.cs
3315 m_vehicle.Step();
3316 return;
3317 }
3318
3319 float fx = 0;
3320 float fy = 0;
3321 float fz = 0;
3322
3323 float m_mass = _mass;
3324
3325 if (m_usePID && m_PIDTau > 0)
3326 {
3327 // for now position error
3328 _target_velocity =
3329 new Vector3(
3330 (m_PIDTarget.X - lpos.X),
3331 (m_PIDTarget.Y - lpos.Y),
3332 (m_PIDTarget.Z - lpos.Z)
3333 );
3334
3335 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.02f))
3336 {
3337 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
3338 d.BodySetLinearVel(Body, 0, 0, 0);
3339 return;
3340 }
3341 else
3342 {
3343 _zeroFlag = false;
3344
3345 float tmp = 1 / m_PIDTau;
3346 _target_velocity *= tmp;
3347
3348 // apply limits
3349 tmp = _target_velocity.Length();
3350 if (tmp > 50.0f)
3351 {
3352 tmp = 50 / tmp;
3353 _target_velocity *= tmp;
3354 }
3355 else if (tmp < 0.05f)
3356 {
3357 tmp = 0.05f / tmp;
3358 _target_velocity *= tmp;
3359 }
3360
3361 d.Vector3 vel = d.BodyGetLinearVel(Body);
3362 fx = (_target_velocity.X - vel.X) * m_invTimeStep;
3363 fy = (_target_velocity.Y - vel.Y) * m_invTimeStep;
3364 fz = (_target_velocity.Z - vel.Z) * m_invTimeStep;
3365// d.BodySetLinearVel(Body, _target_velocity.X, _target_velocity.Y, _target_velocity.Z);
3366 }
3367 } // end if (m_usePID)
3368
3369 // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
3370 else if (m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
3371 {
3372
3373 // Non-Vehicles have a limited set of Hover options.
3374 // determine what our target height really is based on HoverType
3375
3376 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(lpos.X, lpos.Y);
3377
3378 switch (m_PIDHoverType)
3379 {
3380 case PIDHoverType.Ground:
3381 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3382 break;
3383
3384 case PIDHoverType.GroundAndWater:
3385 m_waterHeight = _parent_scene.GetWaterLevel();
3386 if (m_groundHeight > m_waterHeight)
3387 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3388 else
3389 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
3390 break;
3391 } // end switch (m_PIDHoverType)
3392
3393 // don't go underground unless volumedetector
3394
3395 if (m_targetHoverHeight > m_groundHeight || m_isVolumeDetect)
3396 {
3397 d.Vector3 vel = d.BodyGetLinearVel(Body);
3398
3399 fz = (m_targetHoverHeight - lpos.Z);
3400
3401 // if error is zero, use position control; otherwise, velocity control
3402 if (Math.Abs(fz) < 0.01f)
3403 {
3404 d.BodySetPosition(Body, lpos.X, lpos.Y, m_targetHoverHeight);
3405 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
3406 }
3407 else
3408 {
3409 _zeroFlag = false;
3410 fz /= m_PIDHoverTau;
3411
3412 float tmp = Math.Abs(fz);
3413 if (tmp > 50)
3414 fz = 50 * Math.Sign(fz);
3415 else if (tmp < 0.1)
3416 fz = 0.1f * Math.Sign(fz);
3417
3418 fz = ((fz - vel.Z) * m_invTimeStep);
3419 }
3420 }
3421 }
3422 else
3423 {
3424 float b = (1.0f - m_buoyancy) * m_gravmod;
3425 fx = _parent_scene.gravityx * b;
3426 fy = _parent_scene.gravityy * b;
3427 fz = _parent_scene.gravityz * b;
3428 }
3429
3430 fx *= m_mass;
3431 fy *= m_mass;
3432 fz *= m_mass;
3433
3434 // constant force
3435 fx += m_force.X;
3436 fy += m_force.Y;
3437 fz += m_force.Z;
3438
3439 fx += m_forceacc.X;
3440 fy += m_forceacc.Y;
3441 fz += m_forceacc.Z;
3442
3443 m_forceacc = Vector3.Zero;
3444
3445 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
3446 if (fx != 0 || fy != 0 || fz != 0)
3447 {
3448 d.BodyAddForce(Body, fx, fy, fz);
3449 //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
3450 }
3451
3452 Vector3 trq;
3453
3454 trq = m_torque;
3455 trq += m_angularForceacc;
3456 m_angularForceacc = Vector3.Zero;
3457 if (trq.X != 0 || trq.Y != 0 || trq.Z != 0)
3458 {
3459 d.BodyAddTorque(Body, trq.X, trq.Y, trq.Z);
3460 }
3461 }
3462 else
3463 { // is not physical, or is not a body or is selected
3464 // _zeroPosition = d.BodyGetPosition(Body);
3465 return;
3466 //Console.WriteLine("Nothing " + Name);
3467
3468 }
3469 }
3470
3471 public void UpdatePositionAndVelocity(int frame)
3472 {
3473 if (_parent == null && !m_disabled && !m_building && !m_outbounds && Body != IntPtr.Zero)
3474 {
3475 bool bodyenabled = d.BodyIsEnabled(Body);
3476
3477 if(bodydisablecontrol < 0)
3478 return;
3479
3480 if (bodyenabled || !_zeroFlag)
3481 {
3482 bool lastZeroFlag = _zeroFlag;
3483
3484 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
3485
3486 // check outside region
3487 if (lpos.Z < -100 || lpos.Z > 100000f)
3488 {
3489 m_outbounds = true;
3490
3491 lpos.Z = Util.Clip(lpos.Z, -100f, 100000f);
3492 _acceleration.X = 0;
3493 _acceleration.Y = 0;
3494 _acceleration.Z = 0;
3495
3496 _velocity.X = 0;
3497 _velocity.Y = 0;
3498 _velocity.Z = 0;
3499 m_rotationalVelocity.X = 0;
3500 m_rotationalVelocity.Y = 0;
3501 m_rotationalVelocity.Z = 0;
3502
3503 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3504 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
3505 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
3506 m_lastposition = _position;
3507 m_lastorientation = _orientation;
3508
3509 base.RequestPhysicsterseUpdate();
3510
3511// throttleCounter = 0;
3512 _zeroFlag = true;
3513
3514 disableBodySoft(); // disable it and colisions
3515 base.RaiseOutOfBounds(_position);
3516 return;
3517 }
3518
3519 if (lpos.X < 0f)
3520 {
3521 _position.X = Util.Clip(lpos.X, -2f, -0.1f);
3522 m_outbounds = true;
3523 }
3524 else if (lpos.X > _parent_scene.WorldExtents.X)
3525 {
3526 _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
3527 m_outbounds = true;
3528 }
3529 if (lpos.Y < 0f)
3530 {
3531 _position.Y = Util.Clip(lpos.Y, -2f, -0.1f);
3532 m_outbounds = true;
3533 }
3534 else if (lpos.Y > _parent_scene.WorldExtents.Y)
3535 {
3536 _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
3537 m_outbounds = true;
3538 }
3539
3540 if (m_outbounds)
3541 {
3542 m_lastposition = _position;
3543 m_lastorientation = _orientation;
3544
3545 d.Vector3 dtmp = d.BodyGetAngularVel(Body);
3546 m_rotationalVelocity.X = dtmp.X;
3547 m_rotationalVelocity.Y = dtmp.Y;
3548 m_rotationalVelocity.Z = dtmp.Z;
3549
3550 dtmp = d.BodyGetLinearVel(Body);
3551 _velocity.X = dtmp.X;
3552 _velocity.Y = dtmp.Y;
3553 _velocity.Z = dtmp.Z;
3554
3555 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3556 d.BodySetAngularVel(Body, 0, 0, 0);
3557 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
3558 disableBodySoft(); // stop collisions
3559 UnSubscribeEvents();
3560
3561 base.RequestPhysicsterseUpdate();
3562 return;
3563 }
3564
3565 d.Quaternion ori;
3566 d.GeomCopyQuaternion(prim_geom, out ori);
3567
3568 // decide if moving
3569 // use positions since this are integrated quantities
3570 // tolerance values depende a lot on simulation noise...
3571 // use simple math.abs since we dont need to be exact
3572 if(!bodyenabled)
3573 {
3574 _zeroFlag = true;
3575 }
3576 else
3577 {
3578 float poserror;
3579 float angerror;
3580 if(_zeroFlag)
3581 {
3582 poserror = 0.01f;
3583 angerror = 0.001f;
3584 }
3585 else
3586 {
3587 poserror = 0.005f;
3588 angerror = 0.0005f;
3589 }
3590
3591 if (
3592 (Math.Abs(_position.X - lpos.X) < poserror)
3593 && (Math.Abs(_position.Y - lpos.Y) < poserror)
3594 && (Math.Abs(_position.Z - lpos.Z) < poserror)
3595 && (Math.Abs(_orientation.X - ori.X) < angerror)
3596 && (Math.Abs(_orientation.Y - ori.Y) < angerror)
3597 && (Math.Abs(_orientation.Z - ori.Z) < angerror) // ignore W
3598 )
3599 _zeroFlag = true;
3600 else
3601 _zeroFlag = false;
3602 }
3603
3604 // update position
3605 if (!(_zeroFlag && lastZeroFlag))
3606 {
3607 _position.X = lpos.X;
3608 _position.Y = lpos.Y;
3609 _position.Z = lpos.Z;
3610
3611 _orientation.X = ori.X;
3612 _orientation.Y = ori.Y;
3613 _orientation.Z = ori.Z;
3614 _orientation.W = ori.W;
3615 }
3616
3617 // update velocities and aceleration
3618 if (_zeroFlag || lastZeroFlag)
3619 {
3620 // disable interpolators
3621 _velocity = Vector3.Zero;
3622 _acceleration = Vector3.Zero;
3623 m_rotationalVelocity = Vector3.Zero;
3624 }
3625 else
3626 {
3627 d.Vector3 vel = d.BodyGetLinearVel(Body);
3628
3629 _acceleration = _velocity;
3630
3631 if ((Math.Abs(vel.X) < 0.005f) &&
3632 (Math.Abs(vel.Y) < 0.005f) &&
3633 (Math.Abs(vel.Z) < 0.005f))
3634 {
3635 _velocity = Vector3.Zero;
3636 float t = -m_invTimeStep;
3637 _acceleration = _acceleration * t;
3638 }
3639 else
3640 {
3641 _velocity.X = vel.X;
3642 _velocity.Y = vel.Y;
3643 _velocity.Z = vel.Z;
3644 _acceleration = (_velocity - _acceleration) * m_invTimeStep;
3645 }
3646
3647 if ((Math.Abs(_acceleration.X) < 0.01f) &&
3648 (Math.Abs(_acceleration.Y) < 0.01f) &&
3649 (Math.Abs(_acceleration.Z) < 0.01f))
3650 {
3651 _acceleration = Vector3.Zero;
3652 }
3653
3654 if ((Math.Abs(_orientation.X - ori.X) < 0.0001) &&
3655 (Math.Abs(_orientation.Y - ori.Y) < 0.0001) &&
3656 (Math.Abs(_orientation.Z - ori.Z) < 0.0001)
3657 )
3658 {
3659 m_rotationalVelocity = Vector3.Zero;
3660 }
3661 else
3662 {
3663 vel = d.BodyGetAngularVel(Body);
3664 m_rotationalVelocity.X = vel.X;
3665 m_rotationalVelocity.Y = vel.Y;
3666 m_rotationalVelocity.Z = vel.Z;
3667 }
3668 }
3669
3670 if (_zeroFlag)
3671 {
3672 if (!m_lastUpdateSent)
3673 {
3674 base.RequestPhysicsterseUpdate();
3675 if (lastZeroFlag)
3676 m_lastUpdateSent = true;
3677 }
3678 return;
3679 }
3680
3681 base.RequestPhysicsterseUpdate();
3682 m_lastUpdateSent = false;
3683 }
3684 }
3685 }
3686
3687 internal static bool QuaternionIsFinite(Quaternion q)
3688 {
3689 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
3690 return false;
3691 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
3692 return false;
3693 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
3694 return false;
3695 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
3696 return false;
3697 return true;
3698 }
3699
3700 internal static void DMassSubPartFromObj(ref d.Mass part, ref d.Mass theobj)
3701 {
3702 // assumes object center of mass is zero
3703 float smass = part.mass;
3704 theobj.mass -= smass;
3705
3706 smass *= 1.0f / (theobj.mass); ;
3707
3708 theobj.c.X -= part.c.X * smass;
3709 theobj.c.Y -= part.c.Y * smass;
3710 theobj.c.Z -= part.c.Z * smass;
3711
3712 theobj.I.M00 -= part.I.M00;
3713 theobj.I.M01 -= part.I.M01;
3714 theobj.I.M02 -= part.I.M02;
3715 theobj.I.M10 -= part.I.M10;
3716 theobj.I.M11 -= part.I.M11;
3717 theobj.I.M12 -= part.I.M12;
3718 theobj.I.M20 -= part.I.M20;
3719 theobj.I.M21 -= part.I.M21;
3720 theobj.I.M22 -= part.I.M22;
3721 }
3722
3723 private void donullchange()
3724 {
3725 }
3726
3727 public bool DoAChange(changes what, object arg)
3728 {
3729 if (prim_geom == IntPtr.Zero && what != changes.Add && what != changes.AddPhysRep && what != changes.Remove)
3730 {
3731 return false;
3732 }
3733
3734 // nasty switch
3735 switch (what)
3736 {
3737 case changes.Add:
3738 changeadd();
3739 break;
3740
3741 case changes.AddPhysRep:
3742 changeAddPhysRep((ODEPhysRepData)arg);
3743 break;
3744
3745 case changes.Remove:
3746 //If its being removed, we don't want to rebuild the physical rep at all, so ignore this stuff...
3747 //When we return true, it destroys all of the prims in the linkset anyway
3748 if (_parent != null)
3749 {
3750 OdePrim parent = (OdePrim)_parent;
3751 parent.ChildRemove(this, false);
3752 }
3753 else
3754 ChildRemove(this, false);
3755
3756 m_vehicle = null;
3757 RemoveGeom();
3758 m_targetSpace = IntPtr.Zero;
3759 UnSubscribeEvents();
3760 return true;
3761
3762 case changes.Link:
3763 OdePrim tmp = (OdePrim)arg;
3764 changeLink(tmp);
3765 break;
3766
3767 case changes.DeLink:
3768 changeLink(null);
3769 break;
3770
3771 case changes.Position:
3772 changePosition((Vector3)arg);
3773 break;
3774
3775 case changes.Orientation:
3776 changeOrientation((Quaternion)arg);
3777 break;
3778
3779 case changes.PosOffset:
3780 donullchange();
3781 break;
3782
3783 case changes.OriOffset:
3784 donullchange();
3785 break;
3786
3787 case changes.Velocity:
3788 changevelocity((Vector3)arg);
3789 break;
3790
3791// case changes.Acceleration:
3792// changeacceleration((Vector3)arg);
3793// break;
3794
3795 case changes.AngVelocity:
3796 changeangvelocity((Vector3)arg);
3797 break;
3798
3799 case changes.Force:
3800 changeForce((Vector3)arg);
3801 break;
3802
3803 case changes.Torque:
3804 changeSetTorque((Vector3)arg);
3805 break;
3806
3807 case changes.AddForce:
3808 changeAddForce((Vector3)arg);
3809 break;
3810
3811 case changes.AddAngForce:
3812 changeAddAngularImpulse((Vector3)arg);
3813 break;
3814
3815 case changes.AngLock:
3816 changeAngularLock((byte)arg);
3817 break;
3818
3819 case changes.Size:
3820 changeSize((Vector3)arg);
3821 break;
3822
3823 case changes.Shape:
3824 changeShape((PrimitiveBaseShape)arg);
3825 break;
3826
3827 case changes.PhysRepData:
3828 changePhysRepData((ODEPhysRepData) arg);
3829 break;
3830
3831 case changes.CollidesWater:
3832 changeFloatOnWater((bool)arg);
3833 break;
3834
3835 case changes.VolumeDtc:
3836 changeVolumedetetion((bool)arg);
3837 break;
3838
3839 case changes.Phantom:
3840 changePhantomStatus((bool)arg);
3841 break;
3842
3843 case changes.Physical:
3844 changePhysicsStatus((bool)arg);
3845 break;
3846
3847 case changes.Selected:
3848 changeSelectedStatus((bool)arg);
3849 break;
3850
3851 case changes.disabled:
3852 changeDisable((bool)arg);
3853 break;
3854
3855 case changes.building:
3856 changeBuilding((bool)arg);
3857 break;
3858
3859 case changes.VehicleType:
3860 changeVehicleType((int)arg);
3861 break;
3862
3863 case changes.VehicleFlags:
3864 changeVehicleFlags((strVehicleBoolParam) arg);
3865 break;
3866
3867 case changes.VehicleFloatParam:
3868 changeVehicleFloatParam((strVehicleFloatParam) arg);
3869 break;
3870
3871 case changes.VehicleVectorParam:
3872 changeVehicleVectorParam((strVehicleVectorParam) arg);
3873 break;
3874
3875 case changes.VehicleRotationParam:
3876 changeVehicleRotationParam((strVehicleQuatParam) arg);
3877 break;
3878
3879 case changes.SetVehicle:
3880 changeSetVehicle((VehicleData) arg);
3881 break;
3882
3883 case changes.Buoyancy:
3884 changeBuoyancy((float)arg);
3885 break;
3886
3887 case changes.PIDTarget:
3888 changePIDTarget((Vector3)arg);
3889 break;
3890
3891 case changes.PIDTau:
3892 changePIDTau((float)arg);
3893 break;
3894
3895 case changes.PIDActive:
3896 changePIDActive((bool)arg);
3897 break;
3898
3899 case changes.PIDHoverHeight:
3900 changePIDHoverHeight((float)arg);
3901 break;
3902
3903 case changes.PIDHoverType:
3904 changePIDHoverType((PIDHoverType)arg);
3905 break;
3906
3907 case changes.PIDHoverTau:
3908 changePIDHoverTau((float)arg);
3909 break;
3910
3911 case changes.PIDHoverActive:
3912 changePIDHoverActive((bool)arg);
3913 break;
3914
3915 case changes.Null:
3916 donullchange();
3917 break;
3918
3919
3920
3921 default:
3922 donullchange();
3923 break;
3924 }
3925 return false;
3926 }
3927
3928 public void AddChange(changes what, object arg)
3929 {
3930 _parent_scene.AddChange((PhysicsActor) this, what, arg);
3931 }
3932
3933
3934 private struct strVehicleBoolParam
3935 {
3936 public int param;
3937 public bool value;
3938 }
3939
3940 private struct strVehicleFloatParam
3941 {
3942 public int param;
3943 public float value;
3944 }
3945
3946 private struct strVehicleQuatParam
3947 {
3948 public int param;
3949 public Quaternion value;
3950 }
3951
3952 private struct strVehicleVectorParam
3953 {
3954 public int param;
3955 public Vector3 value;
3956 }
3957 }
3958}