aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs3962
1 files changed, 3962 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..1dbf164
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
@@ -0,0 +1,3962 @@
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 if (vertexCount > 64000 || indexCount > 64000)
1483 {
1484 m_log.WarnFormat("[PHYSICS]: large mesh data on OdePrim {0}, mesh {1} at {2}, {3} vertices, {4} indexes",
1485 Name, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh",
1486 _position.ToString() ,vertexCount , indexCount );
1487 }
1488 IntPtr geo = IntPtr.Zero;
1489
1490 try
1491 {
1492 _triMeshData = d.GeomTriMeshDataCreate();
1493
1494 d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
1495 d.GeomTriMeshDataPreprocess(_triMeshData);
1496
1497 geo = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
1498 }
1499
1500 catch (Exception e)
1501 {
1502 m_log.ErrorFormat("[PHYSICS]: SetGeom Mesh failed for {0} exception: {1}", Name, e);
1503 if (_triMeshData != IntPtr.Zero)
1504 {
1505 try
1506 {
1507 d.GeomTriMeshDataDestroy(_triMeshData);
1508 }
1509 catch
1510 {
1511 }
1512 }
1513 _triMeshData = IntPtr.Zero;
1514
1515 m_hasOBB = false;
1516 m_OBBOffset = Vector3.Zero;
1517 m_OBB = _size * 0.5f;
1518 m_physCost = 0.1f;
1519 m_streamCost = 1.0f;
1520
1521 _parent_scene.mesher.ReleaseMesh(mesh);
1522 m_meshState = MeshState.MeshFailed;
1523 m_mesh = null;
1524 return false;
1525 }
1526
1527 m_physCost = 0.0013f * (float)indexCount;
1528 // todo
1529 m_streamCost = 1.0f;
1530
1531 SetGeom(geo);
1532
1533 return true;
1534 }
1535
1536 private void CreateGeom()
1537 {
1538 bool hasMesh = false;
1539
1540 m_NoColide = false;
1541
1542 if ((m_meshState & MeshState.MeshNoColide) != 0)
1543 m_NoColide = true;
1544
1545 else if(m_mesh != null)
1546 {
1547 if (GetMeshGeom())
1548 hasMesh = true;
1549 else
1550 m_NoColide = true;
1551 }
1552
1553
1554 if (!hasMesh)
1555 {
1556 IntPtr geo = IntPtr.Zero;
1557
1558 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1
1559 && _size.X == _size.Y && _size.Y == _size.Z)
1560 { // it's a sphere
1561 try
1562 {
1563 geo = d.CreateSphere(m_targetSpace, _size.X * 0.5f);
1564 }
1565 catch (Exception e)
1566 {
1567 m_log.WarnFormat("[PHYSICS]: Create sphere failed: {0}", e);
1568 return;
1569 }
1570 }
1571 else
1572 {// do it as a box
1573 try
1574 {
1575 geo = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1576 }
1577 catch (Exception e)
1578 {
1579 m_log.Warn("[PHYSICS]: Create box failed: {0}", e);
1580 return;
1581 }
1582 }
1583 m_physCost = 0.1f;
1584 m_streamCost = 1.0f;
1585 SetGeom(geo);
1586 }
1587 }
1588
1589 private void RemoveGeom()
1590 {
1591 if (prim_geom != IntPtr.Zero)
1592 {
1593 _parent_scene.actor_name_map.Remove(prim_geom);
1594
1595 try
1596 {
1597 d.GeomDestroy(prim_geom);
1598 if (_triMeshData != IntPtr.Zero)
1599 {
1600 d.GeomTriMeshDataDestroy(_triMeshData);
1601 _triMeshData = IntPtr.Zero;
1602 }
1603 }
1604 catch (Exception e)
1605 {
1606 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction failed for {0} exception {1}", Name, e);
1607 }
1608
1609 prim_geom = IntPtr.Zero;
1610 collide_geom = IntPtr.Zero;
1611 m_targetSpace = IntPtr.Zero;
1612 }
1613 else
1614 {
1615 m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction BAD {0}", Name);
1616 }
1617
1618 lock (m_meshlock)
1619 {
1620 if (m_mesh != null)
1621 {
1622 _parent_scene.mesher.ReleaseMesh(m_mesh);
1623 m_mesh = null;
1624 }
1625 }
1626
1627 Body = IntPtr.Zero;
1628 m_hasOBB = false;
1629 }
1630
1631 //sets non physical prim m_targetSpace to right space in spaces grid for static prims
1632 // should only be called for non physical prims unless they are becoming non physical
1633 private void SetInStaticSpace(OdePrim prim)
1634 {
1635 IntPtr targetSpace = _parent_scene.MoveGeomToStaticSpace(prim.prim_geom, prim._position, prim.m_targetSpace);
1636 prim.m_targetSpace = targetSpace;
1637 collide_geom = IntPtr.Zero;
1638 }
1639
1640 public void enableBodySoft()
1641 {
1642 m_disabled = false;
1643 if (!childPrim && !m_isSelected)
1644 {
1645 if (m_isphysical && Body != IntPtr.Zero)
1646 {
1647 UpdateCollisionCatFlags();
1648 ApplyCollisionCatFlags();
1649
1650 _zeroFlag = true;
1651 d.BodyEnable(Body);
1652
1653 }
1654 }
1655 resetCollisionAccounting();
1656 }
1657
1658 private void disableBodySoft()
1659 {
1660 m_disabled = true;
1661 if (!childPrim)
1662 {
1663 if (m_isphysical && Body != IntPtr.Zero)
1664 {
1665 if (m_isSelected)
1666 m_collisionFlags = CollisionCategories.Selected;
1667 else
1668 m_collisionCategories = 0;
1669 m_collisionFlags = 0;
1670 ApplyCollisionCatFlags();
1671 d.BodyDisable(Body);
1672 }
1673 }
1674 }
1675
1676 private void MakeBody()
1677 {
1678 if (!m_isphysical) // only physical get bodies
1679 return;
1680
1681 if (childPrim) // child prims don't get bodies;
1682 return;
1683
1684 if (m_building)
1685 return;
1686
1687 if (prim_geom == IntPtr.Zero)
1688 {
1689 m_log.Warn("[PHYSICS]: Unable to link the linkset. Root has no geom yet");
1690 return;
1691 }
1692
1693 if (Body != IntPtr.Zero)
1694 {
1695 DestroyBody();
1696 m_log.Warn("[PHYSICS]: MakeBody called having a body");
1697 }
1698
1699 if (d.GeomGetBody(prim_geom) != IntPtr.Zero)
1700 {
1701 d.GeomSetBody(prim_geom, IntPtr.Zero);
1702 m_log.Warn("[PHYSICS]: MakeBody root geom already had a body");
1703 }
1704
1705 d.Matrix3 mymat = new d.Matrix3();
1706 d.Quaternion myrot = new d.Quaternion();
1707 d.Mass objdmass = new d.Mass { };
1708
1709 Body = d.BodyCreate(_parent_scene.world);
1710
1711 objdmass = primdMass;
1712
1713 // rotate inertia
1714 myrot.X = _orientation.X;
1715 myrot.Y = _orientation.Y;
1716 myrot.Z = _orientation.Z;
1717 myrot.W = _orientation.W;
1718
1719 d.RfromQ(out mymat, ref myrot);
1720 d.MassRotate(ref objdmass, ref mymat);
1721
1722 // set the body rotation
1723 d.BodySetRotation(Body, ref mymat);
1724
1725 // recompute full object inertia if needed
1726 if (childrenPrim.Count > 0)
1727 {
1728 d.Matrix3 mat = new d.Matrix3();
1729 d.Quaternion quat = new d.Quaternion();
1730 d.Mass tmpdmass = new d.Mass { };
1731 Vector3 rcm;
1732
1733 rcm.X = _position.X;
1734 rcm.Y = _position.Y;
1735 rcm.Z = _position.Z;
1736
1737 lock (childrenPrim)
1738 {
1739 foreach (OdePrim prm in childrenPrim)
1740 {
1741 if (prm.prim_geom == IntPtr.Zero)
1742 {
1743 m_log.Warn("[PHYSICS]: Unable to link one of the linkset elements, skipping it. No geom yet");
1744 continue;
1745 }
1746
1747 tmpdmass = prm.primdMass;
1748
1749 // apply prim current rotation to inertia
1750 quat.X = prm._orientation.X;
1751 quat.Y = prm._orientation.Y;
1752 quat.Z = prm._orientation.Z;
1753 quat.W = prm._orientation.W;
1754 d.RfromQ(out mat, ref quat);
1755 d.MassRotate(ref tmpdmass, ref mat);
1756
1757 Vector3 ppos = prm._position;
1758 ppos.X -= rcm.X;
1759 ppos.Y -= rcm.Y;
1760 ppos.Z -= rcm.Z;
1761 // refer inertia to root prim center of mass position
1762 d.MassTranslate(ref tmpdmass,
1763 ppos.X,
1764 ppos.Y,
1765 ppos.Z);
1766
1767 d.MassAdd(ref objdmass, ref tmpdmass); // add to total object inertia
1768 // fix prim colision cats
1769
1770 if (d.GeomGetBody(prm.prim_geom) != IntPtr.Zero)
1771 {
1772 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
1773 m_log.Warn("[PHYSICS]: MakeBody child geom already had a body");
1774 }
1775
1776 d.GeomClearOffset(prm.prim_geom);
1777 d.GeomSetBody(prm.prim_geom, Body);
1778 prm.Body = Body;
1779 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat); // set relative rotation
1780 }
1781 }
1782 }
1783
1784 d.GeomClearOffset(prim_geom); // make sure we don't have a hidden offset
1785 // associate root geom with body
1786 d.GeomSetBody(prim_geom, Body);
1787
1788 d.BodySetPosition(Body, _position.X + objdmass.c.X, _position.Y + objdmass.c.Y, _position.Z + objdmass.c.Z);
1789 d.GeomSetOffsetWorldPosition(prim_geom, _position.X, _position.Y, _position.Z);
1790
1791 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
1792 myrot.X = -myrot.X;
1793 myrot.Y = -myrot.Y;
1794 myrot.Z = -myrot.Z;
1795
1796 d.RfromQ(out mymat, ref myrot);
1797 d.MassRotate(ref objdmass, ref mymat);
1798
1799 d.BodySetMass(Body, ref objdmass);
1800 _mass = objdmass.mass;
1801
1802 // disconnect from world gravity so we can apply buoyancy
1803 d.BodySetGravityMode(Body, false);
1804
1805 d.BodySetAutoDisableFlag(Body, true);
1806 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1807 d.BodySetAutoDisableAngularThreshold(Body, 0.05f);
1808 d.BodySetAutoDisableLinearThreshold(Body, 0.05f);
1809 d.BodySetDamping(Body, .004f, .001f);
1810
1811 if (m_targetSpace != IntPtr.Zero)
1812 {
1813 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1814 if (d.SpaceQuery(m_targetSpace, prim_geom))
1815 d.SpaceRemove(m_targetSpace, prim_geom);
1816 }
1817
1818 if (childrenPrim.Count == 0)
1819 {
1820 collide_geom = prim_geom;
1821 m_targetSpace = _parent_scene.ActiveSpace;
1822 }
1823 else
1824 {
1825 m_targetSpace = d.HashSpaceCreate(_parent_scene.ActiveSpace);
1826 d.HashSpaceSetLevels(m_targetSpace, -2, 8);
1827 d.SpaceSetSublevel(m_targetSpace, 3);
1828 d.SpaceSetCleanup(m_targetSpace, false);
1829
1830 d.GeomSetCategoryBits(m_targetSpace, (uint)(CollisionCategories.Space |
1831 CollisionCategories.Geom |
1832 CollisionCategories.Phantom |
1833 CollisionCategories.VolumeDtc
1834 ));
1835 d.GeomSetCollideBits(m_targetSpace, 0);
1836 collide_geom = m_targetSpace;
1837 }
1838
1839 d.SpaceAdd(m_targetSpace, prim_geom);
1840
1841 if (m_delaySelect)
1842 {
1843 m_isSelected = true;
1844 m_delaySelect = false;
1845 }
1846
1847 m_collisionscore = 0;
1848
1849 UpdateCollisionCatFlags();
1850 ApplyCollisionCatFlags();
1851
1852 _parent_scene.addActivePrim(this);
1853
1854 lock (childrenPrim)
1855 {
1856 foreach (OdePrim prm in childrenPrim)
1857 {
1858 if (prm.prim_geom == IntPtr.Zero)
1859 continue;
1860
1861 Vector3 ppos = prm._position;
1862 d.GeomSetOffsetWorldPosition(prm.prim_geom, ppos.X, ppos.Y, ppos.Z); // set relative position
1863
1864 if (prm.m_targetSpace != m_targetSpace)
1865 {
1866 if (prm.m_targetSpace != IntPtr.Zero)
1867 {
1868 _parent_scene.waitForSpaceUnlock(prm.m_targetSpace);
1869 if (d.SpaceQuery(prm.m_targetSpace, prm.prim_geom))
1870 d.SpaceRemove(prm.m_targetSpace, prm.prim_geom);
1871 }
1872 prm.m_targetSpace = m_targetSpace;
1873 d.SpaceAdd(m_targetSpace, prm.prim_geom);
1874 }
1875
1876 prm.m_collisionscore = 0;
1877
1878 if(!m_disabled)
1879 prm.m_disabled = false;
1880
1881 _parent_scene.addActivePrim(prm);
1882 }
1883 }
1884
1885 // The body doesn't already have a finite rotation mode set here
1886 if (m_angularlocks != 0 && _parent == null)
1887 {
1888 createAMotor(m_angularlocks);
1889 }
1890
1891 if (m_isSelected || m_disabled)
1892 {
1893 d.BodyDisable(Body);
1894 _zeroFlag = true;
1895 }
1896 else
1897 {
1898 d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z);
1899 d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z);
1900 _zeroFlag = false;
1901 bodydisablecontrol = 0;
1902 }
1903 _parent_scene.addActiveGroups(this);
1904 }
1905
1906 private void DestroyBody()
1907 {
1908 if (Body != IntPtr.Zero)
1909 {
1910 _parent_scene.remActivePrim(this);
1911
1912 collide_geom = IntPtr.Zero;
1913
1914 if (m_disabled)
1915 m_collisionCategories = 0;
1916 else if (m_isSelected)
1917 m_collisionCategories = CollisionCategories.Selected;
1918 else if (m_isVolumeDetect)
1919 m_collisionCategories = CollisionCategories.VolumeDtc;
1920 else if (m_isphantom)
1921 m_collisionCategories = CollisionCategories.Phantom;
1922 else
1923 m_collisionCategories = CollisionCategories.Geom;
1924
1925 m_collisionFlags = 0;
1926
1927 if (prim_geom != IntPtr.Zero)
1928 {
1929 if (m_NoColide)
1930 {
1931 d.GeomSetCategoryBits(prim_geom, 0);
1932 d.GeomSetCollideBits(prim_geom, 0);
1933 }
1934 else
1935 {
1936 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
1937 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
1938 }
1939 UpdateDataFromGeom();
1940 d.GeomSetBody(prim_geom, IntPtr.Zero);
1941 SetInStaticSpace(this);
1942 }
1943
1944 if (!childPrim)
1945 {
1946 lock (childrenPrim)
1947 {
1948 foreach (OdePrim prm in childrenPrim)
1949 {
1950 _parent_scene.remActivePrim(prm);
1951
1952 if (prm.m_isSelected)
1953 prm.m_collisionCategories = CollisionCategories.Selected;
1954 else if (prm.m_isVolumeDetect)
1955 prm.m_collisionCategories = CollisionCategories.VolumeDtc;
1956 else if (prm.m_isphantom)
1957 prm.m_collisionCategories = CollisionCategories.Phantom;
1958 else
1959 prm.m_collisionCategories = CollisionCategories.Geom;
1960
1961 prm.m_collisionFlags = 0;
1962
1963 if (prm.prim_geom != IntPtr.Zero)
1964 {
1965 if (prm.m_NoColide)
1966 {
1967 d.GeomSetCategoryBits(prm.prim_geom, 0);
1968 d.GeomSetCollideBits(prm.prim_geom, 0);
1969 }
1970 else
1971 {
1972 d.GeomSetCategoryBits(prm.prim_geom, (uint)prm.m_collisionCategories);
1973 d.GeomSetCollideBits(prm.prim_geom, (uint)prm.m_collisionFlags);
1974 }
1975 prm.UpdateDataFromGeom();
1976 SetInStaticSpace(prm);
1977 }
1978 prm.Body = IntPtr.Zero;
1979 prm._mass = prm.primMass;
1980 prm.m_collisionscore = 0;
1981 }
1982 }
1983 if (Amotor != IntPtr.Zero)
1984 {
1985 d.JointDestroy(Amotor);
1986 Amotor = IntPtr.Zero;
1987 }
1988 _parent_scene.remActiveGroup(this);
1989 d.BodyDestroy(Body);
1990 }
1991 Body = IntPtr.Zero;
1992 }
1993 _mass = primMass;
1994 m_collisionscore = 0;
1995 }
1996
1997 private void FixInertia(Vector3 NewPos,Quaternion newrot)
1998 {
1999 d.Matrix3 mat = new d.Matrix3();
2000 d.Quaternion quat = new d.Quaternion();
2001
2002 d.Mass tmpdmass = new d.Mass { };
2003 d.Mass objdmass = new d.Mass { };
2004
2005 d.BodyGetMass(Body, out tmpdmass);
2006 objdmass = tmpdmass;
2007
2008 d.Vector3 dobjpos;
2009 d.Vector3 thispos;
2010
2011 // get current object position and rotation
2012 dobjpos = d.BodyGetPosition(Body);
2013
2014 // get prim own inertia in its local frame
2015 tmpdmass = primdMass;
2016
2017 // transform to object frame
2018 mat = d.GeomGetOffsetRotation(prim_geom);
2019 d.MassRotate(ref tmpdmass, ref mat);
2020
2021 thispos = d.GeomGetOffsetPosition(prim_geom);
2022 d.MassTranslate(ref tmpdmass,
2023 thispos.X,
2024 thispos.Y,
2025 thispos.Z);
2026
2027 // subtract current prim inertia from object
2028 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2029
2030 // back prim own inertia
2031 tmpdmass = primdMass;
2032
2033 // update to new position and orientation
2034 _position = NewPos;
2035 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2036 _orientation = newrot;
2037 quat.X = newrot.X;
2038 quat.Y = newrot.Y;
2039 quat.Z = newrot.Z;
2040 quat.W = newrot.W;
2041 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2042
2043 mat = d.GeomGetOffsetRotation(prim_geom);
2044 d.MassRotate(ref tmpdmass, ref mat);
2045
2046 thispos = d.GeomGetOffsetPosition(prim_geom);
2047 d.MassTranslate(ref tmpdmass,
2048 thispos.X,
2049 thispos.Y,
2050 thispos.Z);
2051
2052 d.MassAdd(ref objdmass, ref tmpdmass);
2053
2054 // fix all positions
2055 IntPtr g = d.BodyGetFirstGeom(Body);
2056 while (g != IntPtr.Zero)
2057 {
2058 thispos = d.GeomGetOffsetPosition(g);
2059 thispos.X -= objdmass.c.X;
2060 thispos.Y -= objdmass.c.Y;
2061 thispos.Z -= objdmass.c.Z;
2062 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2063 g = d.dBodyGetNextGeom(g);
2064 }
2065 d.BodyVectorToWorld(Body,objdmass.c.X, objdmass.c.Y, objdmass.c.Z,out thispos);
2066
2067 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2068 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2069 d.BodySetMass(Body, ref objdmass);
2070 _mass = objdmass.mass;
2071 }
2072
2073 private void FixInertia(Vector3 NewPos)
2074 {
2075 d.Matrix3 primmat = new d.Matrix3();
2076 d.Mass tmpdmass = new d.Mass { };
2077 d.Mass objdmass = new d.Mass { };
2078 d.Mass primmass = new d.Mass { };
2079
2080 d.Vector3 dobjpos;
2081 d.Vector3 thispos;
2082
2083 d.BodyGetMass(Body, out objdmass);
2084
2085 // get prim own inertia in its local frame
2086 primmass = primdMass;
2087 // transform to object frame
2088 primmat = d.GeomGetOffsetRotation(prim_geom);
2089 d.MassRotate(ref primmass, ref primmat);
2090
2091 tmpdmass = primmass;
2092
2093 thispos = d.GeomGetOffsetPosition(prim_geom);
2094 d.MassTranslate(ref tmpdmass,
2095 thispos.X,
2096 thispos.Y,
2097 thispos.Z);
2098
2099 // subtract current prim inertia from object
2100 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2101
2102 // update to new position
2103 _position = NewPos;
2104 d.GeomSetOffsetWorldPosition(prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
2105
2106 thispos = d.GeomGetOffsetPosition(prim_geom);
2107 d.MassTranslate(ref primmass,
2108 thispos.X,
2109 thispos.Y,
2110 thispos.Z);
2111
2112 d.MassAdd(ref objdmass, ref primmass);
2113
2114 // fix all positions
2115 IntPtr g = d.BodyGetFirstGeom(Body);
2116 while (g != IntPtr.Zero)
2117 {
2118 thispos = d.GeomGetOffsetPosition(g);
2119 thispos.X -= objdmass.c.X;
2120 thispos.Y -= objdmass.c.Y;
2121 thispos.Z -= objdmass.c.Z;
2122 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2123 g = d.dBodyGetNextGeom(g);
2124 }
2125
2126 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2127
2128 // get current object position and rotation
2129 dobjpos = d.BodyGetPosition(Body);
2130
2131 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2132 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2133 d.BodySetMass(Body, ref objdmass);
2134 _mass = objdmass.mass;
2135 }
2136
2137 private void FixInertia(Quaternion newrot)
2138 {
2139 d.Matrix3 mat = new d.Matrix3();
2140 d.Quaternion quat = new d.Quaternion();
2141
2142 d.Mass tmpdmass = new d.Mass { };
2143 d.Mass objdmass = new d.Mass { };
2144 d.Vector3 dobjpos;
2145 d.Vector3 thispos;
2146
2147 d.BodyGetMass(Body, out objdmass);
2148
2149 // get prim own inertia in its local frame
2150 tmpdmass = primdMass;
2151 mat = d.GeomGetOffsetRotation(prim_geom);
2152 d.MassRotate(ref tmpdmass, ref mat);
2153 // transform to object frame
2154 thispos = d.GeomGetOffsetPosition(prim_geom);
2155 d.MassTranslate(ref tmpdmass,
2156 thispos.X,
2157 thispos.Y,
2158 thispos.Z);
2159
2160 // subtract current prim inertia from object
2161 DMassSubPartFromObj(ref tmpdmass, ref objdmass);
2162
2163 // update to new orientation
2164 _orientation = newrot;
2165 quat.X = newrot.X;
2166 quat.Y = newrot.Y;
2167 quat.Z = newrot.Z;
2168 quat.W = newrot.W;
2169 d.GeomSetOffsetWorldQuaternion(prim_geom, ref quat);
2170
2171 tmpdmass = primdMass;
2172 mat = d.GeomGetOffsetRotation(prim_geom);
2173 d.MassRotate(ref tmpdmass, ref mat);
2174 d.MassTranslate(ref tmpdmass,
2175 thispos.X,
2176 thispos.Y,
2177 thispos.Z);
2178
2179 d.MassAdd(ref objdmass, ref tmpdmass);
2180
2181 // fix all positions
2182 IntPtr g = d.BodyGetFirstGeom(Body);
2183 while (g != IntPtr.Zero)
2184 {
2185 thispos = d.GeomGetOffsetPosition(g);
2186 thispos.X -= objdmass.c.X;
2187 thispos.Y -= objdmass.c.Y;
2188 thispos.Z -= objdmass.c.Z;
2189 d.GeomSetOffsetPosition(g, thispos.X, thispos.Y, thispos.Z);
2190 g = d.dBodyGetNextGeom(g);
2191 }
2192
2193 d.BodyVectorToWorld(Body, objdmass.c.X, objdmass.c.Y, objdmass.c.Z, out thispos);
2194 // get current object position and rotation
2195 dobjpos = d.BodyGetPosition(Body);
2196
2197 d.BodySetPosition(Body, dobjpos.X + thispos.X, dobjpos.Y + thispos.Y, dobjpos.Z + thispos.Z);
2198 d.MassTranslate(ref objdmass, -objdmass.c.X, -objdmass.c.Y, -objdmass.c.Z); // ode wants inertia at center of body
2199 d.BodySetMass(Body, ref objdmass);
2200 _mass = objdmass.mass;
2201 }
2202
2203
2204 #region Mass Calculation
2205
2206 private void UpdatePrimBodyData()
2207 {
2208 primMass = m_density * primVolume;
2209
2210 if (primMass <= 0)
2211 primMass = 0.0001f;//ckrinke: Mass must be greater then zero.
2212 if (primMass > _parent_scene.maximumMassObject)
2213 primMass = _parent_scene.maximumMassObject;
2214
2215 _mass = primMass; // just in case
2216
2217 d.MassSetBoxTotal(out primdMass, primMass, 2.0f * m_OBB.X, 2.0f * m_OBB.Y, 2.0f * m_OBB.Z);
2218
2219 d.MassTranslate(ref primdMass,
2220 m_OBBOffset.X,
2221 m_OBBOffset.Y,
2222 m_OBBOffset.Z);
2223
2224 primOOBradiusSQ = m_OBB.LengthSquared();
2225
2226 if (_triMeshData != IntPtr.Zero)
2227 {
2228 float pc = m_physCost;
2229 float psf = primOOBradiusSQ;
2230 psf *= 1.33f * .2f;
2231 pc *= psf;
2232 if (pc < 0.1f)
2233 pc = 0.1f;
2234
2235 m_physCost = pc;
2236 }
2237 else
2238 m_physCost = 0.1f;
2239
2240 m_streamCost = 1.0f;
2241 }
2242
2243 #endregion
2244
2245
2246 /// <summary>
2247 /// Add a child prim to this parent prim.
2248 /// </summary>
2249 /// <param name="prim">Child prim</param>
2250 // I'm the parent
2251 // prim is the child
2252 public void ParentPrim(OdePrim prim)
2253 {
2254 //Console.WriteLine("ParentPrim " + m_primName);
2255 if (this.m_localID != prim.m_localID)
2256 {
2257 DestroyBody(); // for now we need to rebuil entire object on link change
2258
2259 lock (childrenPrim)
2260 {
2261 // adopt the prim
2262 if (!childrenPrim.Contains(prim))
2263 childrenPrim.Add(prim);
2264
2265 // see if this prim has kids and adopt them also
2266 // should not happen for now
2267 foreach (OdePrim prm in prim.childrenPrim)
2268 {
2269 if (!childrenPrim.Contains(prm))
2270 {
2271 if (prm.Body != IntPtr.Zero)
2272 {
2273 if (prm.prim_geom != IntPtr.Zero)
2274 d.GeomSetBody(prm.prim_geom, IntPtr.Zero);
2275 if (prm.Body != prim.Body)
2276 prm.DestroyBody(); // don't loose bodies around
2277 prm.Body = IntPtr.Zero;
2278 }
2279
2280 childrenPrim.Add(prm);
2281 prm._parent = this;
2282 }
2283 }
2284 }
2285 //Remove old children from the prim
2286 prim.childrenPrim.Clear();
2287
2288 if (prim.Body != IntPtr.Zero)
2289 {
2290 if (prim.prim_geom != IntPtr.Zero)
2291 d.GeomSetBody(prim.prim_geom, IntPtr.Zero);
2292 prim.DestroyBody(); // don't loose bodies around
2293 prim.Body = IntPtr.Zero;
2294 }
2295
2296 prim.childPrim = true;
2297 prim._parent = this;
2298
2299 MakeBody(); // full nasty reconstruction
2300 }
2301 }
2302
2303 private void UpdateChildsfromgeom()
2304 {
2305 if (childrenPrim.Count > 0)
2306 {
2307 foreach (OdePrim prm in childrenPrim)
2308 prm.UpdateDataFromGeom();
2309 }
2310 }
2311
2312 private void UpdateDataFromGeom()
2313 {
2314 if (prim_geom != IntPtr.Zero)
2315 {
2316 d.Quaternion qtmp;
2317 d.GeomCopyQuaternion(prim_geom, out qtmp);
2318 _orientation.X = qtmp.X;
2319 _orientation.Y = qtmp.Y;
2320 _orientation.Z = qtmp.Z;
2321 _orientation.W = qtmp.W;
2322/*
2323// Debug
2324 float qlen = _orientation.Length();
2325 if (qlen > 1.01f || qlen < 0.99)
2326 m_log.WarnFormat("[PHYSICS]: Got nonnorm quaternion from geom in Object {0} norm {1}", Name, qlen);
2327//
2328*/
2329 _orientation.Normalize();
2330
2331 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
2332 _position.X = lpos.X;
2333 _position.Y = lpos.Y;
2334 _position.Z = lpos.Z;
2335 }
2336 }
2337
2338 private void ChildDelink(OdePrim odePrim, bool remakebodies)
2339 {
2340 // Okay, we have a delinked child.. destroy all body and remake
2341 if (odePrim != this && !childrenPrim.Contains(odePrim))
2342 return;
2343
2344 DestroyBody();
2345
2346 if (odePrim == this) // delinking the root prim
2347 {
2348 OdePrim newroot = null;
2349 lock (childrenPrim)
2350 {
2351 if (childrenPrim.Count > 0)
2352 {
2353 newroot = childrenPrim[0];
2354 childrenPrim.RemoveAt(0);
2355 foreach (OdePrim prm in childrenPrim)
2356 {
2357 newroot.childrenPrim.Add(prm);
2358 }
2359 childrenPrim.Clear();
2360 }
2361 if (newroot != null)
2362 {
2363 newroot.childPrim = false;
2364 newroot._parent = null;
2365 if (remakebodies)
2366 newroot.MakeBody();
2367 }
2368 }
2369 }
2370
2371 else
2372 {
2373 lock (childrenPrim)
2374 {
2375 childrenPrim.Remove(odePrim);
2376 odePrim.childPrim = false;
2377 odePrim._parent = null;
2378 // odePrim.UpdateDataFromGeom();
2379 if (remakebodies)
2380 odePrim.MakeBody();
2381 }
2382 }
2383 if (remakebodies)
2384 MakeBody();
2385 }
2386
2387 protected void ChildRemove(OdePrim odePrim, bool reMakeBody)
2388 {
2389 // Okay, we have a delinked child.. destroy all body and remake
2390 if (odePrim != this && !childrenPrim.Contains(odePrim))
2391 return;
2392
2393 DestroyBody();
2394
2395 if (odePrim == this)
2396 {
2397 OdePrim newroot = null;
2398 lock (childrenPrim)
2399 {
2400 if (childrenPrim.Count > 0)
2401 {
2402 newroot = childrenPrim[0];
2403 childrenPrim.RemoveAt(0);
2404 foreach (OdePrim prm in childrenPrim)
2405 {
2406 newroot.childrenPrim.Add(prm);
2407 }
2408 childrenPrim.Clear();
2409 }
2410 if (newroot != null)
2411 {
2412 newroot.childPrim = false;
2413 newroot._parent = null;
2414 newroot.MakeBody();
2415 }
2416 }
2417 if (reMakeBody)
2418 MakeBody();
2419 return;
2420 }
2421 else
2422 {
2423 lock (childrenPrim)
2424 {
2425 childrenPrim.Remove(odePrim);
2426 odePrim.childPrim = false;
2427 odePrim._parent = null;
2428 if (reMakeBody)
2429 odePrim.MakeBody();
2430 }
2431 }
2432 MakeBody();
2433 }
2434
2435
2436 #region changes
2437
2438 private void changeadd()
2439 {
2440 }
2441
2442 private void changeAngularLock(byte newLocks)
2443 {
2444 // do we have a Physical object?
2445 if (Body != IntPtr.Zero)
2446 {
2447 //Check that we have a Parent
2448 //If we have a parent then we're not authorative here
2449 if (_parent == null)
2450 {
2451 if (newLocks != 0)
2452 {
2453 createAMotor(newLocks);
2454 }
2455 else
2456 {
2457 if (Amotor != IntPtr.Zero)
2458 {
2459 d.JointDestroy(Amotor);
2460 Amotor = IntPtr.Zero;
2461 }
2462 }
2463 }
2464 }
2465 // Store this for later in case we get turned into a separate body
2466 m_angularlocks = newLocks;
2467 }
2468
2469 private void changeLink(OdePrim NewParent)
2470 {
2471 if (_parent == null && NewParent != null)
2472 {
2473 NewParent.ParentPrim(this);
2474 }
2475 else if (_parent != null)
2476 {
2477 if (_parent is OdePrim)
2478 {
2479 if (NewParent != _parent)
2480 {
2481 (_parent as OdePrim).ChildDelink(this, false); // for now...
2482 childPrim = false;
2483
2484 if (NewParent != null)
2485 {
2486 NewParent.ParentPrim(this);
2487 }
2488 }
2489 }
2490 }
2491 _parent = NewParent;
2492 }
2493
2494
2495 private void Stop()
2496 {
2497 if (!childPrim)
2498 {
2499// m_force = Vector3.Zero;
2500 m_forceacc = Vector3.Zero;
2501 m_angularForceacc = Vector3.Zero;
2502// m_torque = Vector3.Zero;
2503 _velocity = Vector3.Zero;
2504 _acceleration = Vector3.Zero;
2505 m_rotationalVelocity = Vector3.Zero;
2506 _target_velocity = Vector3.Zero;
2507 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
2508 m_vehicle.Stop();
2509
2510 _zeroFlag = false;
2511 base.RequestPhysicsterseUpdate();
2512 }
2513
2514 if (Body != IntPtr.Zero)
2515 {
2516 d.BodySetForce(Body, 0f, 0f, 0f);
2517 d.BodySetTorque(Body, 0f, 0f, 0f);
2518 d.BodySetLinearVel(Body, 0f, 0f, 0f);
2519 d.BodySetAngularVel(Body, 0f, 0f, 0f);
2520 }
2521 }
2522
2523 private void changePhantomStatus(bool newval)
2524 {
2525 m_isphantom = newval;
2526
2527 UpdateCollisionCatFlags();
2528 ApplyCollisionCatFlags();
2529 }
2530
2531/* not in use
2532 internal void ChildSelectedChange(bool childSelect)
2533 {
2534 if(childPrim)
2535 return;
2536
2537 if (childSelect == m_isSelected)
2538 return;
2539
2540 if (childSelect)
2541 {
2542 DoSelectedStatus(true);
2543 }
2544
2545 else
2546 {
2547 foreach (OdePrim prm in childrenPrim)
2548 {
2549 if (prm.m_isSelected)
2550 return;
2551 }
2552 DoSelectedStatus(false);
2553 }
2554 }
2555*/
2556 private void changeSelectedStatus(bool newval)
2557 {
2558 if (m_lastdoneSelected == newval)
2559 return;
2560
2561 m_lastdoneSelected = newval;
2562 DoSelectedStatus(newval);
2563 }
2564
2565 private void CheckDelaySelect()
2566 {
2567 if (m_delaySelect)
2568 {
2569 DoSelectedStatus(m_isSelected);
2570 }
2571 }
2572
2573 private void DoSelectedStatus(bool newval)
2574 {
2575 m_isSelected = newval;
2576 Stop();
2577
2578 if (newval)
2579 {
2580 if (!childPrim && Body != IntPtr.Zero)
2581 d.BodyDisable(Body);
2582
2583 if (m_delaySelect || m_isphysical)
2584 {
2585 m_collisionCategories = CollisionCategories.Selected;
2586 m_collisionFlags = 0;
2587
2588 if (!childPrim)
2589 {
2590 foreach (OdePrim prm in childrenPrim)
2591 {
2592 prm.m_collisionCategories = m_collisionCategories;
2593 prm.m_collisionFlags = m_collisionFlags;
2594
2595 if (prm.prim_geom != IntPtr.Zero)
2596 {
2597
2598 if (prm.m_NoColide)
2599 {
2600 d.GeomSetCategoryBits(prm.prim_geom, 0);
2601 d.GeomSetCollideBits(prm.prim_geom, 0);
2602 }
2603 else
2604 {
2605 d.GeomSetCategoryBits(prm.prim_geom, (uint)m_collisionCategories);
2606 d.GeomSetCollideBits(prm.prim_geom, (uint)m_collisionFlags);
2607 }
2608 }
2609 prm.m_delaySelect = false;
2610 }
2611 }
2612// else if (_parent != null)
2613// ((OdePrim)_parent).ChildSelectedChange(true);
2614
2615
2616 if (prim_geom != IntPtr.Zero)
2617 {
2618 if (m_NoColide)
2619 {
2620 d.GeomSetCategoryBits(prim_geom, 0);
2621 d.GeomSetCollideBits(prim_geom, 0);
2622 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2623 {
2624 d.GeomSetCategoryBits(collide_geom, 0);
2625 d.GeomSetCollideBits(collide_geom, 0);
2626 }
2627
2628 }
2629 else
2630 {
2631 d.GeomSetCategoryBits(prim_geom, (uint)m_collisionCategories);
2632 d.GeomSetCollideBits(prim_geom, (uint)m_collisionFlags);
2633 if (collide_geom != prim_geom && collide_geom != IntPtr.Zero)
2634 {
2635 d.GeomSetCategoryBits(collide_geom, (uint)m_collisionCategories);
2636 d.GeomSetCollideBits(collide_geom, (uint)m_collisionFlags);
2637 }
2638 }
2639 }
2640
2641 m_delaySelect = false;
2642 }
2643 else if(!m_isphysical)
2644 {
2645 m_delaySelect = true;
2646 }
2647 }
2648 else
2649 {
2650 if (!childPrim)
2651 {
2652 if (Body != IntPtr.Zero && !m_disabled)
2653 {
2654 _zeroFlag = true;
2655 d.BodyEnable(Body);
2656 }
2657 }
2658// else if (_parent != null)
2659// ((OdePrim)_parent).ChildSelectedChange(false);
2660
2661 UpdateCollisionCatFlags();
2662 ApplyCollisionCatFlags();
2663
2664 m_delaySelect = false;
2665 }
2666
2667 resetCollisionAccounting();
2668 }
2669
2670 private void changePosition(Vector3 newPos)
2671 {
2672 CheckDelaySelect();
2673 if (m_isphysical)
2674 {
2675 if (childPrim) // inertia is messed, must rebuild
2676 {
2677 if (m_building)
2678 {
2679 _position = newPos;
2680 }
2681
2682 else if (m_forcePosOrRotation && _position != newPos && Body != IntPtr.Zero)
2683 {
2684 FixInertia(newPos);
2685 if (!d.BodyIsEnabled(Body))
2686 {
2687 _zeroFlag = true;
2688 d.BodyEnable(Body);
2689 }
2690 }
2691 }
2692 else
2693 {
2694 if (_position != newPos)
2695 {
2696 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2697 _position = newPos;
2698 }
2699 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2700 {
2701 _zeroFlag = true;
2702 d.BodyEnable(Body);
2703 }
2704 }
2705 }
2706 else
2707 {
2708 if (prim_geom != IntPtr.Zero)
2709 {
2710 if (newPos != _position)
2711 {
2712 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2713 _position = newPos;
2714
2715 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2716 }
2717 }
2718 }
2719 givefakepos--;
2720 if (givefakepos < 0)
2721 givefakepos = 0;
2722// changeSelectedStatus();
2723 resetCollisionAccounting();
2724 }
2725
2726 private void changeOrientation(Quaternion newOri)
2727 {
2728 CheckDelaySelect();
2729 if (m_isphysical)
2730 {
2731 if (childPrim) // inertia is messed, must rebuild
2732 {
2733 if (m_building)
2734 {
2735 _orientation = newOri;
2736 }
2737/*
2738 else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero)
2739 {
2740 FixInertia(_position, newOri);
2741 if (!d.BodyIsEnabled(Body))
2742 d.BodyEnable(Body);
2743 }
2744*/
2745 }
2746 else
2747 {
2748 if (newOri != _orientation)
2749 {
2750 d.Quaternion myrot = new d.Quaternion();
2751 myrot.X = newOri.X;
2752 myrot.Y = newOri.Y;
2753 myrot.Z = newOri.Z;
2754 myrot.W = newOri.W;
2755 d.GeomSetQuaternion(prim_geom, ref myrot);
2756 _orientation = newOri;
2757 if (Body != IntPtr.Zero && m_angularlocks != 0)
2758 createAMotor(m_angularlocks);
2759 }
2760 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2761 {
2762 _zeroFlag = true;
2763 d.BodyEnable(Body);
2764 }
2765 }
2766 }
2767 else
2768 {
2769 if (prim_geom != IntPtr.Zero)
2770 {
2771 if (newOri != _orientation)
2772 {
2773 d.Quaternion myrot = new d.Quaternion();
2774 myrot.X = newOri.X;
2775 myrot.Y = newOri.Y;
2776 myrot.Z = newOri.Z;
2777 myrot.W = newOri.W;
2778 d.GeomSetQuaternion(prim_geom, ref myrot);
2779 _orientation = newOri;
2780 }
2781 }
2782 }
2783 givefakeori--;
2784 if (givefakeori < 0)
2785 givefakeori = 0;
2786 resetCollisionAccounting();
2787 }
2788
2789 private void changePositionAndOrientation(Vector3 newPos, Quaternion newOri)
2790 {
2791 CheckDelaySelect();
2792 if (m_isphysical)
2793 {
2794 if (childPrim && m_building) // inertia is messed, must rebuild
2795 {
2796 _position = newPos;
2797 _orientation = newOri;
2798 }
2799 else
2800 {
2801 if (newOri != _orientation)
2802 {
2803 d.Quaternion myrot = new d.Quaternion();
2804 myrot.X = newOri.X;
2805 myrot.Y = newOri.Y;
2806 myrot.Z = newOri.Z;
2807 myrot.W = newOri.W;
2808 d.GeomSetQuaternion(prim_geom, ref myrot);
2809 _orientation = newOri;
2810 if (Body != IntPtr.Zero && m_angularlocks != 0)
2811 createAMotor(m_angularlocks);
2812 }
2813 if (_position != newPos)
2814 {
2815 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2816 _position = newPos;
2817 }
2818 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
2819 {
2820 _zeroFlag = true;
2821 d.BodyEnable(Body);
2822 }
2823 }
2824 }
2825 else
2826 {
2827 // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
2828 // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
2829
2830 if (prim_geom != IntPtr.Zero)
2831 {
2832 if (newOri != _orientation)
2833 {
2834 d.Quaternion myrot = new d.Quaternion();
2835 myrot.X = newOri.X;
2836 myrot.Y = newOri.Y;
2837 myrot.Z = newOri.Z;
2838 myrot.W = newOri.W;
2839 d.GeomSetQuaternion(prim_geom, ref myrot);
2840 _orientation = newOri;
2841 }
2842
2843 if (newPos != _position)
2844 {
2845 d.GeomSetPosition(prim_geom, newPos.X, newPos.Y, newPos.Z);
2846 _position = newPos;
2847
2848 m_targetSpace = _parent_scene.MoveGeomToStaticSpace(prim_geom, _position, m_targetSpace);
2849 }
2850 }
2851 }
2852 givefakepos--;
2853 if (givefakepos < 0)
2854 givefakepos = 0;
2855 givefakeori--;
2856 if (givefakeori < 0)
2857 givefakeori = 0;
2858 resetCollisionAccounting();
2859 }
2860
2861 private void changeDisable(bool disable)
2862 {
2863 if (disable)
2864 {
2865 if (!m_disabled)
2866 disableBodySoft();
2867 }
2868 else
2869 {
2870 if (m_disabled)
2871 enableBodySoft();
2872 }
2873 }
2874
2875 private void changePhysicsStatus(bool NewStatus)
2876 {
2877 CheckDelaySelect();
2878
2879 m_isphysical = NewStatus;
2880
2881 if (!childPrim)
2882 {
2883 if (NewStatus)
2884 {
2885 if (Body == IntPtr.Zero)
2886 MakeBody();
2887 }
2888 else
2889 {
2890 if (Body != IntPtr.Zero)
2891 {
2892 DestroyBody();
2893 }
2894 Stop();
2895 }
2896 }
2897
2898 resetCollisionAccounting();
2899 }
2900
2901 private void changeSize(Vector3 newSize)
2902 {
2903 }
2904
2905 private void changeShape(PrimitiveBaseShape newShape)
2906 {
2907 }
2908
2909 private void changeAddPhysRep(ODEPhysRepData repData)
2910 {
2911 _size = repData.size; //??
2912 _pbs = repData.pbs;
2913 m_shapetype = repData.shapetype;
2914
2915 m_mesh = repData.mesh;
2916
2917 m_assetID = repData.assetID;
2918 m_meshState = repData.meshState;
2919
2920 m_hasOBB = repData.hasOBB;
2921 m_OBBOffset = repData.OBBOffset;
2922 m_OBB = repData.OBB;
2923
2924 primVolume = repData.volume;
2925
2926 CreateGeom();
2927
2928 if (prim_geom != IntPtr.Zero)
2929 {
2930 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2931 d.Quaternion myrot = new d.Quaternion();
2932 myrot.X = _orientation.X;
2933 myrot.Y = _orientation.Y;
2934 myrot.Z = _orientation.Z;
2935 myrot.W = _orientation.W;
2936 d.GeomSetQuaternion(prim_geom, ref myrot);
2937 }
2938
2939 if (!m_isphysical)
2940 {
2941 SetInStaticSpace(this);
2942 UpdateCollisionCatFlags();
2943 ApplyCollisionCatFlags();
2944 }
2945 else
2946 MakeBody();
2947
2948 if ((m_meshState & MeshState.NeedMask) != 0)
2949 {
2950 repData.size = _size;
2951 repData.pbs = _pbs;
2952 repData.shapetype = m_shapetype;
2953 _parent_scene.m_meshWorker.RequestMesh(repData);
2954 }
2955 }
2956
2957 private void changePhysRepData(ODEPhysRepData repData)
2958 {
2959 CheckDelaySelect();
2960
2961 OdePrim parent = (OdePrim)_parent;
2962
2963 bool chp = childPrim;
2964
2965 if (chp)
2966 {
2967 if (parent != null)
2968 {
2969 parent.DestroyBody();
2970 }
2971 }
2972 else
2973 {
2974 DestroyBody();
2975 }
2976
2977 RemoveGeom();
2978
2979 _size = repData.size;
2980 _pbs = repData.pbs;
2981 m_shapetype = repData.shapetype;
2982
2983 m_mesh = repData.mesh;
2984
2985 m_assetID = repData.assetID;
2986 m_meshState = repData.meshState;
2987
2988 m_hasOBB = repData.hasOBB;
2989 m_OBBOffset = repData.OBBOffset;
2990 m_OBB = repData.OBB;
2991
2992 primVolume = repData.volume;
2993
2994 CreateGeom();
2995
2996 if (prim_geom != IntPtr.Zero)
2997 {
2998 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2999 d.Quaternion myrot = new d.Quaternion();
3000 myrot.X = _orientation.X;
3001 myrot.Y = _orientation.Y;
3002 myrot.Z = _orientation.Z;
3003 myrot.W = _orientation.W;
3004 d.GeomSetQuaternion(prim_geom, ref myrot);
3005 }
3006
3007 if (m_isphysical)
3008 {
3009 if (chp)
3010 {
3011 if (parent != null)
3012 {
3013 parent.MakeBody();
3014 }
3015 }
3016 else
3017 MakeBody();
3018 }
3019 else
3020 {
3021 SetInStaticSpace(this);
3022 UpdateCollisionCatFlags();
3023 ApplyCollisionCatFlags();
3024 }
3025
3026 resetCollisionAccounting();
3027
3028 if ((m_meshState & MeshState.NeedMask) != 0)
3029 {
3030 repData.size = _size;
3031 repData.pbs = _pbs;
3032 repData.shapetype = m_shapetype;
3033 _parent_scene.m_meshWorker.RequestMesh(repData);
3034 }
3035 }
3036
3037 private void changeFloatOnWater(bool newval)
3038 {
3039 m_collidesWater = newval;
3040
3041 UpdateCollisionCatFlags();
3042 ApplyCollisionCatFlags();
3043 }
3044
3045 private void changeSetTorque(Vector3 newtorque)
3046 {
3047 if (!m_isSelected)
3048 {
3049 if (m_isphysical && Body != IntPtr.Zero)
3050 {
3051 if (m_disabled)
3052 enableBodySoft();
3053 else if (!d.BodyIsEnabled(Body))
3054 d.BodyEnable(Body);
3055
3056 }
3057 m_torque = newtorque;
3058 }
3059 }
3060
3061 private void changeForce(Vector3 force)
3062 {
3063 m_force = force;
3064 if (Body != IntPtr.Zero && !d.BodyIsEnabled(Body))
3065 d.BodyEnable(Body);
3066 }
3067
3068 private void changeAddForce(Vector3 theforce)
3069 {
3070 m_forceacc += theforce;
3071 if (!m_isSelected)
3072 {
3073 lock (this)
3074 {
3075 //m_log.Info("[PHYSICS]: dequeing forcelist");
3076 if (m_isphysical && Body != IntPtr.Zero)
3077 {
3078 if (m_disabled)
3079 enableBodySoft();
3080 else if (!d.BodyIsEnabled(Body))
3081 d.BodyEnable(Body);
3082 }
3083 }
3084 m_collisionscore = 0;
3085 }
3086 }
3087
3088 // actually angular impulse
3089 private void changeAddAngularImpulse(Vector3 aimpulse)
3090 {
3091 m_angularForceacc += aimpulse * m_invTimeStep;
3092 if (!m_isSelected)
3093 {
3094 lock (this)
3095 {
3096 if (m_isphysical && Body != IntPtr.Zero)
3097 {
3098 if (m_disabled)
3099 enableBodySoft();
3100 else if (!d.BodyIsEnabled(Body))
3101 d.BodyEnable(Body);
3102 }
3103 }
3104 m_collisionscore = 0;
3105 }
3106 }
3107
3108 private void changevelocity(Vector3 newVel)
3109 {
3110 float len = newVel.LengthSquared();
3111 if (len > 100000.0f) // limit to 100m/s
3112 {
3113 len = 100.0f / (float)Math.Sqrt(len);
3114 newVel *= len;
3115 }
3116
3117 if (!m_isSelected)
3118 {
3119 if (Body != IntPtr.Zero)
3120 {
3121 if (m_disabled)
3122 enableBodySoft();
3123 else if (!d.BodyIsEnabled(Body))
3124 d.BodyEnable(Body);
3125
3126 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
3127 }
3128 //resetCollisionAccounting();
3129 }
3130 _velocity = newVel;
3131 }
3132
3133 private void changeangvelocity(Vector3 newAngVel)
3134 {
3135 float len = newAngVel.LengthSquared();
3136 if (len > _parent_scene.maxAngVelocitySQ)
3137 {
3138 len = _parent_scene.maximumAngularVelocity / (float)Math.Sqrt(len);
3139 newAngVel *= len;
3140 }
3141
3142 if (!m_isSelected)
3143 {
3144 if (Body != IntPtr.Zero)
3145 {
3146 if (m_disabled)
3147 enableBodySoft();
3148 else if (!d.BodyIsEnabled(Body))
3149 d.BodyEnable(Body);
3150
3151
3152 d.BodySetAngularVel(Body, newAngVel.X, newAngVel.Y, newAngVel.Z);
3153 }
3154 //resetCollisionAccounting();
3155 }
3156 m_rotationalVelocity = newAngVel;
3157 }
3158
3159 private void changeVolumedetetion(bool newVolDtc)
3160 {
3161 m_isVolumeDetect = newVolDtc;
3162 m_fakeisVolumeDetect = newVolDtc;
3163 UpdateCollisionCatFlags();
3164 ApplyCollisionCatFlags();
3165 }
3166
3167 protected void changeBuilding(bool newbuilding)
3168 {
3169 // Check if we need to do anything
3170 if (newbuilding == m_building)
3171 return;
3172
3173 if ((bool)newbuilding)
3174 {
3175 m_building = true;
3176 if (!childPrim)
3177 DestroyBody();
3178 }
3179 else
3180 {
3181 m_building = false;
3182 CheckDelaySelect();
3183 if (!childPrim)
3184 MakeBody();
3185 }
3186 if (!childPrim && childrenPrim.Count > 0)
3187 {
3188 foreach (OdePrim prm in childrenPrim)
3189 prm.changeBuilding(m_building); // call directly
3190 }
3191 }
3192
3193 public void changeSetVehicle(VehicleData vdata)
3194 {
3195 if (m_vehicle == null)
3196 m_vehicle = new ODEDynamics(this);
3197 m_vehicle.DoSetVehicle(vdata);
3198 }
3199
3200 private void changeVehicleType(int value)
3201 {
3202 if (value == (int)Vehicle.TYPE_NONE)
3203 {
3204 if (m_vehicle != null)
3205 m_vehicle = null;
3206 }
3207 else
3208 {
3209 if (m_vehicle == null)
3210 m_vehicle = new ODEDynamics(this);
3211
3212 m_vehicle.ProcessTypeChange((Vehicle)value);
3213 }
3214 }
3215
3216 private void changeVehicleFloatParam(strVehicleFloatParam fp)
3217 {
3218 if (m_vehicle == null)
3219 return;
3220
3221 m_vehicle.ProcessFloatVehicleParam((Vehicle)fp.param, fp.value);
3222 }
3223
3224 private void changeVehicleVectorParam(strVehicleVectorParam vp)
3225 {
3226 if (m_vehicle == null)
3227 return;
3228 m_vehicle.ProcessVectorVehicleParam((Vehicle)vp.param, vp.value);
3229 }
3230
3231 private void changeVehicleRotationParam(strVehicleQuatParam qp)
3232 {
3233 if (m_vehicle == null)
3234 return;
3235 m_vehicle.ProcessRotationVehicleParam((Vehicle)qp.param, qp.value);
3236 }
3237
3238 private void changeVehicleFlags(strVehicleBoolParam bp)
3239 {
3240 if (m_vehicle == null)
3241 return;
3242 m_vehicle.ProcessVehicleFlags(bp.param, bp.value);
3243 }
3244
3245 private void changeBuoyancy(float b)
3246 {
3247 m_buoyancy = b;
3248 }
3249
3250 private void changePIDTarget(Vector3 trg)
3251 {
3252 m_PIDTarget = trg;
3253 }
3254
3255 private void changePIDTau(float tau)
3256 {
3257 m_PIDTau = tau;
3258 }
3259
3260 private void changePIDActive(bool val)
3261 {
3262 m_usePID = val;
3263 }
3264
3265 private void changePIDHoverHeight(float val)
3266 {
3267 m_PIDHoverHeight = val;
3268 if (val == 0)
3269 m_useHoverPID = false;
3270 }
3271
3272 private void changePIDHoverType(PIDHoverType type)
3273 {
3274 m_PIDHoverType = type;
3275 }
3276
3277 private void changePIDHoverTau(float tau)
3278 {
3279 m_PIDHoverTau = tau;
3280 }
3281
3282 private void changePIDHoverActive(bool active)
3283 {
3284 m_useHoverPID = active;
3285 }
3286
3287 #endregion
3288
3289 public void Move()
3290 {
3291 if (!childPrim && m_isphysical && Body != IntPtr.Zero &&
3292 !m_disabled && !m_isSelected && !m_building && !m_outbounds)
3293 {
3294 if (!d.BodyIsEnabled(Body))
3295 {
3296 // let vehicles sleep
3297 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3298 return;
3299
3300 if (++bodydisablecontrol < 50)
3301 return;
3302
3303 // clear residuals
3304 d.BodySetAngularVel(Body,0f,0f,0f);
3305 d.BodySetLinearVel(Body,0f,0f,0f);
3306 _zeroFlag = true;
3307 d.BodyEnable(Body);
3308 bodydisablecontrol = -4;
3309 }
3310
3311 if(bodydisablecontrol < 0)
3312 bodydisablecontrol ++;
3313
3314 d.Vector3 lpos = d.GeomGetPosition(prim_geom); // root position that is seem by rest of simulator
3315
3316 if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE)
3317 {
3318 // 'VEHICLES' are dealt with in ODEDynamics.cs
3319 m_vehicle.Step();
3320 return;
3321 }
3322
3323 float fx = 0;
3324 float fy = 0;
3325 float fz = 0;
3326
3327 float m_mass = _mass;
3328
3329 if (m_usePID && m_PIDTau > 0)
3330 {
3331 // for now position error
3332 _target_velocity =
3333 new Vector3(
3334 (m_PIDTarget.X - lpos.X),
3335 (m_PIDTarget.Y - lpos.Y),
3336 (m_PIDTarget.Z - lpos.Z)
3337 );
3338
3339 if (_target_velocity.ApproxEquals(Vector3.Zero, 0.02f))
3340 {
3341 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
3342 d.BodySetLinearVel(Body, 0, 0, 0);
3343 return;
3344 }
3345 else
3346 {
3347 _zeroFlag = false;
3348
3349 float tmp = 1 / m_PIDTau;
3350 _target_velocity *= tmp;
3351
3352 // apply limits
3353 tmp = _target_velocity.Length();
3354 if (tmp > 50.0f)
3355 {
3356 tmp = 50 / tmp;
3357 _target_velocity *= tmp;
3358 }
3359 else if (tmp < 0.05f)
3360 {
3361 tmp = 0.05f / tmp;
3362 _target_velocity *= tmp;
3363 }
3364
3365 d.Vector3 vel = d.BodyGetLinearVel(Body);
3366 fx = (_target_velocity.X - vel.X) * m_invTimeStep;
3367 fy = (_target_velocity.Y - vel.Y) * m_invTimeStep;
3368 fz = (_target_velocity.Z - vel.Z) * m_invTimeStep;
3369// d.BodySetLinearVel(Body, _target_velocity.X, _target_velocity.Y, _target_velocity.Z);
3370 }
3371 } // end if (m_usePID)
3372
3373 // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
3374 else if (m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
3375 {
3376
3377 // Non-Vehicles have a limited set of Hover options.
3378 // determine what our target height really is based on HoverType
3379
3380 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(lpos.X, lpos.Y);
3381
3382 switch (m_PIDHoverType)
3383 {
3384 case PIDHoverType.Ground:
3385 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3386 break;
3387
3388 case PIDHoverType.GroundAndWater:
3389 m_waterHeight = _parent_scene.GetWaterLevel();
3390 if (m_groundHeight > m_waterHeight)
3391 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
3392 else
3393 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
3394 break;
3395 } // end switch (m_PIDHoverType)
3396
3397 // don't go underground unless volumedetector
3398
3399 if (m_targetHoverHeight > m_groundHeight || m_isVolumeDetect)
3400 {
3401 d.Vector3 vel = d.BodyGetLinearVel(Body);
3402
3403 fz = (m_targetHoverHeight - lpos.Z);
3404
3405 // if error is zero, use position control; otherwise, velocity control
3406 if (Math.Abs(fz) < 0.01f)
3407 {
3408 d.BodySetPosition(Body, lpos.X, lpos.Y, m_targetHoverHeight);
3409 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
3410 }
3411 else
3412 {
3413 _zeroFlag = false;
3414 fz /= m_PIDHoverTau;
3415
3416 float tmp = Math.Abs(fz);
3417 if (tmp > 50)
3418 fz = 50 * Math.Sign(fz);
3419 else if (tmp < 0.1)
3420 fz = 0.1f * Math.Sign(fz);
3421
3422 fz = ((fz - vel.Z) * m_invTimeStep);
3423 }
3424 }
3425 }
3426 else
3427 {
3428 float b = (1.0f - m_buoyancy) * m_gravmod;
3429 fx = _parent_scene.gravityx * b;
3430 fy = _parent_scene.gravityy * b;
3431 fz = _parent_scene.gravityz * b;
3432 }
3433
3434 fx *= m_mass;
3435 fy *= m_mass;
3436 fz *= m_mass;
3437
3438 // constant force
3439 fx += m_force.X;
3440 fy += m_force.Y;
3441 fz += m_force.Z;
3442
3443 fx += m_forceacc.X;
3444 fy += m_forceacc.Y;
3445 fz += m_forceacc.Z;
3446
3447 m_forceacc = Vector3.Zero;
3448
3449 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
3450 if (fx != 0 || fy != 0 || fz != 0)
3451 {
3452 d.BodyAddForce(Body, fx, fy, fz);
3453 //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
3454 }
3455
3456 Vector3 trq;
3457
3458 trq = m_torque;
3459 trq += m_angularForceacc;
3460 m_angularForceacc = Vector3.Zero;
3461 if (trq.X != 0 || trq.Y != 0 || trq.Z != 0)
3462 {
3463 d.BodyAddTorque(Body, trq.X, trq.Y, trq.Z);
3464 }
3465 }
3466 else
3467 { // is not physical, or is not a body or is selected
3468 // _zeroPosition = d.BodyGetPosition(Body);
3469 return;
3470 //Console.WriteLine("Nothing " + Name);
3471
3472 }
3473 }
3474
3475 public void UpdatePositionAndVelocity(int frame)
3476 {
3477 if (_parent == null && !m_disabled && !m_building && !m_outbounds && Body != IntPtr.Zero)
3478 {
3479 bool bodyenabled = d.BodyIsEnabled(Body);
3480
3481 if(bodydisablecontrol < 0)
3482 return;
3483
3484 if (bodyenabled || !_zeroFlag)
3485 {
3486 bool lastZeroFlag = _zeroFlag;
3487
3488 d.Vector3 lpos = d.GeomGetPosition(prim_geom);
3489
3490 // check outside region
3491 if (lpos.Z < -100 || lpos.Z > 100000f)
3492 {
3493 m_outbounds = true;
3494
3495 lpos.Z = Util.Clip(lpos.Z, -100f, 100000f);
3496 _acceleration.X = 0;
3497 _acceleration.Y = 0;
3498 _acceleration.Z = 0;
3499
3500 _velocity.X = 0;
3501 _velocity.Y = 0;
3502 _velocity.Z = 0;
3503 m_rotationalVelocity.X = 0;
3504 m_rotationalVelocity.Y = 0;
3505 m_rotationalVelocity.Z = 0;
3506
3507 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3508 d.BodySetAngularVel(Body, 0, 0, 0); // stop it
3509 d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere
3510 m_lastposition = _position;
3511 m_lastorientation = _orientation;
3512
3513 base.RequestPhysicsterseUpdate();
3514
3515// throttleCounter = 0;
3516 _zeroFlag = true;
3517
3518 disableBodySoft(); // disable it and colisions
3519 base.RaiseOutOfBounds(_position);
3520 return;
3521 }
3522
3523 if (lpos.X < 0f)
3524 {
3525 _position.X = Util.Clip(lpos.X, -2f, -0.1f);
3526 m_outbounds = true;
3527 }
3528 else if (lpos.X > _parent_scene.WorldExtents.X)
3529 {
3530 _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f);
3531 m_outbounds = true;
3532 }
3533 if (lpos.Y < 0f)
3534 {
3535 _position.Y = Util.Clip(lpos.Y, -2f, -0.1f);
3536 m_outbounds = true;
3537 }
3538 else if (lpos.Y > _parent_scene.WorldExtents.Y)
3539 {
3540 _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f);
3541 m_outbounds = true;
3542 }
3543
3544 if (m_outbounds)
3545 {
3546 m_lastposition = _position;
3547 m_lastorientation = _orientation;
3548
3549 d.Vector3 dtmp = d.BodyGetAngularVel(Body);
3550 m_rotationalVelocity.X = dtmp.X;
3551 m_rotationalVelocity.Y = dtmp.Y;
3552 m_rotationalVelocity.Z = dtmp.Z;
3553
3554 dtmp = d.BodyGetLinearVel(Body);
3555 _velocity.X = dtmp.X;
3556 _velocity.Y = dtmp.Y;
3557 _velocity.Z = dtmp.Z;
3558
3559 d.BodySetLinearVel(Body, 0, 0, 0); // stop it
3560 d.BodySetAngularVel(Body, 0, 0, 0);
3561 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
3562 disableBodySoft(); // stop collisions
3563 UnSubscribeEvents();
3564
3565 base.RequestPhysicsterseUpdate();
3566 return;
3567 }
3568
3569 d.Quaternion ori;
3570 d.GeomCopyQuaternion(prim_geom, out ori);
3571
3572 // decide if moving
3573 // use positions since this are integrated quantities
3574 // tolerance values depende a lot on simulation noise...
3575 // use simple math.abs since we dont need to be exact
3576 if(!bodyenabled)
3577 {
3578 _zeroFlag = true;
3579 }
3580 else
3581 {
3582 float poserror;
3583 float angerror;
3584 if(_zeroFlag)
3585 {
3586 poserror = 0.01f;
3587 angerror = 0.001f;
3588 }
3589 else
3590 {
3591 poserror = 0.005f;
3592 angerror = 0.0005f;
3593 }
3594
3595 if (
3596 (Math.Abs(_position.X - lpos.X) < poserror)
3597 && (Math.Abs(_position.Y - lpos.Y) < poserror)
3598 && (Math.Abs(_position.Z - lpos.Z) < poserror)
3599 && (Math.Abs(_orientation.X - ori.X) < angerror)
3600 && (Math.Abs(_orientation.Y - ori.Y) < angerror)
3601 && (Math.Abs(_orientation.Z - ori.Z) < angerror) // ignore W
3602 )
3603 _zeroFlag = true;
3604 else
3605 _zeroFlag = false;
3606 }
3607
3608 // update position
3609 if (!(_zeroFlag && lastZeroFlag))
3610 {
3611 _position.X = lpos.X;
3612 _position.Y = lpos.Y;
3613 _position.Z = lpos.Z;
3614
3615 _orientation.X = ori.X;
3616 _orientation.Y = ori.Y;
3617 _orientation.Z = ori.Z;
3618 _orientation.W = ori.W;
3619 }
3620
3621 // update velocities and aceleration
3622 if (_zeroFlag || lastZeroFlag)
3623 {
3624 // disable interpolators
3625 _velocity = Vector3.Zero;
3626 _acceleration = Vector3.Zero;
3627 m_rotationalVelocity = Vector3.Zero;
3628 }
3629 else
3630 {
3631 d.Vector3 vel = d.BodyGetLinearVel(Body);
3632
3633 _acceleration = _velocity;
3634
3635 if ((Math.Abs(vel.X) < 0.005f) &&
3636 (Math.Abs(vel.Y) < 0.005f) &&
3637 (Math.Abs(vel.Z) < 0.005f))
3638 {
3639 _velocity = Vector3.Zero;
3640 float t = -m_invTimeStep;
3641 _acceleration = _acceleration * t;
3642 }
3643 else
3644 {
3645 _velocity.X = vel.X;
3646 _velocity.Y = vel.Y;
3647 _velocity.Z = vel.Z;
3648 _acceleration = (_velocity - _acceleration) * m_invTimeStep;
3649 }
3650
3651 if ((Math.Abs(_acceleration.X) < 0.01f) &&
3652 (Math.Abs(_acceleration.Y) < 0.01f) &&
3653 (Math.Abs(_acceleration.Z) < 0.01f))
3654 {
3655 _acceleration = Vector3.Zero;
3656 }
3657
3658 vel = d.BodyGetAngularVel(Body);
3659 if ((Math.Abs(vel.X) < 0.0001) &&
3660 (Math.Abs(vel.Y) < 0.0001) &&
3661 (Math.Abs(vel.Z) < 0.0001)
3662 )
3663 {
3664 m_rotationalVelocity = Vector3.Zero;
3665 }
3666 else
3667 {
3668 m_rotationalVelocity.X = vel.X;
3669 m_rotationalVelocity.Y = vel.Y;
3670 m_rotationalVelocity.Z = vel.Z;
3671 }
3672 }
3673
3674 if (_zeroFlag)
3675 {
3676 if (!m_lastUpdateSent)
3677 {
3678 base.RequestPhysicsterseUpdate();
3679 if (lastZeroFlag)
3680 m_lastUpdateSent = true;
3681 }
3682 return;
3683 }
3684
3685 base.RequestPhysicsterseUpdate();
3686 m_lastUpdateSent = false;
3687 }
3688 }
3689 }
3690
3691 internal static bool QuaternionIsFinite(Quaternion q)
3692 {
3693 if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
3694 return false;
3695 if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
3696 return false;
3697 if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
3698 return false;
3699 if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
3700 return false;
3701 return true;
3702 }
3703
3704 internal static void DMassSubPartFromObj(ref d.Mass part, ref d.Mass theobj)
3705 {
3706 // assumes object center of mass is zero
3707 float smass = part.mass;
3708 theobj.mass -= smass;
3709
3710 smass *= 1.0f / (theobj.mass); ;
3711
3712 theobj.c.X -= part.c.X * smass;
3713 theobj.c.Y -= part.c.Y * smass;
3714 theobj.c.Z -= part.c.Z * smass;
3715
3716 theobj.I.M00 -= part.I.M00;
3717 theobj.I.M01 -= part.I.M01;
3718 theobj.I.M02 -= part.I.M02;
3719 theobj.I.M10 -= part.I.M10;
3720 theobj.I.M11 -= part.I.M11;
3721 theobj.I.M12 -= part.I.M12;
3722 theobj.I.M20 -= part.I.M20;
3723 theobj.I.M21 -= part.I.M21;
3724 theobj.I.M22 -= part.I.M22;
3725 }
3726
3727 private void donullchange()
3728 {
3729 }
3730
3731 public bool DoAChange(changes what, object arg)
3732 {
3733 if (prim_geom == IntPtr.Zero && what != changes.Add && what != changes.AddPhysRep && what != changes.Remove)
3734 {
3735 return false;
3736 }
3737
3738 // nasty switch
3739 switch (what)
3740 {
3741 case changes.Add:
3742 changeadd();
3743 break;
3744
3745 case changes.AddPhysRep:
3746 changeAddPhysRep((ODEPhysRepData)arg);
3747 break;
3748
3749 case changes.Remove:
3750 //If its being removed, we don't want to rebuild the physical rep at all, so ignore this stuff...
3751 //When we return true, it destroys all of the prims in the linkset anyway
3752 if (_parent != null)
3753 {
3754 OdePrim parent = (OdePrim)_parent;
3755 parent.ChildRemove(this, false);
3756 }
3757 else
3758 ChildRemove(this, false);
3759
3760 m_vehicle = null;
3761 RemoveGeom();
3762 m_targetSpace = IntPtr.Zero;
3763 UnSubscribeEvents();
3764 return true;
3765
3766 case changes.Link:
3767 OdePrim tmp = (OdePrim)arg;
3768 changeLink(tmp);
3769 break;
3770
3771 case changes.DeLink:
3772 changeLink(null);
3773 break;
3774
3775 case changes.Position:
3776 changePosition((Vector3)arg);
3777 break;
3778
3779 case changes.Orientation:
3780 changeOrientation((Quaternion)arg);
3781 break;
3782
3783 case changes.PosOffset:
3784 donullchange();
3785 break;
3786
3787 case changes.OriOffset:
3788 donullchange();
3789 break;
3790
3791 case changes.Velocity:
3792 changevelocity((Vector3)arg);
3793 break;
3794
3795// case changes.Acceleration:
3796// changeacceleration((Vector3)arg);
3797// break;
3798
3799 case changes.AngVelocity:
3800 changeangvelocity((Vector3)arg);
3801 break;
3802
3803 case changes.Force:
3804 changeForce((Vector3)arg);
3805 break;
3806
3807 case changes.Torque:
3808 changeSetTorque((Vector3)arg);
3809 break;
3810
3811 case changes.AddForce:
3812 changeAddForce((Vector3)arg);
3813 break;
3814
3815 case changes.AddAngForce:
3816 changeAddAngularImpulse((Vector3)arg);
3817 break;
3818
3819 case changes.AngLock:
3820 changeAngularLock((byte)arg);
3821 break;
3822
3823 case changes.Size:
3824 changeSize((Vector3)arg);
3825 break;
3826
3827 case changes.Shape:
3828 changeShape((PrimitiveBaseShape)arg);
3829 break;
3830
3831 case changes.PhysRepData:
3832 changePhysRepData((ODEPhysRepData) arg);
3833 break;
3834
3835 case changes.CollidesWater:
3836 changeFloatOnWater((bool)arg);
3837 break;
3838
3839 case changes.VolumeDtc:
3840 changeVolumedetetion((bool)arg);
3841 break;
3842
3843 case changes.Phantom:
3844 changePhantomStatus((bool)arg);
3845 break;
3846
3847 case changes.Physical:
3848 changePhysicsStatus((bool)arg);
3849 break;
3850
3851 case changes.Selected:
3852 changeSelectedStatus((bool)arg);
3853 break;
3854
3855 case changes.disabled:
3856 changeDisable((bool)arg);
3857 break;
3858
3859 case changes.building:
3860 changeBuilding((bool)arg);
3861 break;
3862
3863 case changes.VehicleType:
3864 changeVehicleType((int)arg);
3865 break;
3866
3867 case changes.VehicleFlags:
3868 changeVehicleFlags((strVehicleBoolParam) arg);
3869 break;
3870
3871 case changes.VehicleFloatParam:
3872 changeVehicleFloatParam((strVehicleFloatParam) arg);
3873 break;
3874
3875 case changes.VehicleVectorParam:
3876 changeVehicleVectorParam((strVehicleVectorParam) arg);
3877 break;
3878
3879 case changes.VehicleRotationParam:
3880 changeVehicleRotationParam((strVehicleQuatParam) arg);
3881 break;
3882
3883 case changes.SetVehicle:
3884 changeSetVehicle((VehicleData) arg);
3885 break;
3886
3887 case changes.Buoyancy:
3888 changeBuoyancy((float)arg);
3889 break;
3890
3891 case changes.PIDTarget:
3892 changePIDTarget((Vector3)arg);
3893 break;
3894
3895 case changes.PIDTau:
3896 changePIDTau((float)arg);
3897 break;
3898
3899 case changes.PIDActive:
3900 changePIDActive((bool)arg);
3901 break;
3902
3903 case changes.PIDHoverHeight:
3904 changePIDHoverHeight((float)arg);
3905 break;
3906
3907 case changes.PIDHoverType:
3908 changePIDHoverType((PIDHoverType)arg);
3909 break;
3910
3911 case changes.PIDHoverTau:
3912 changePIDHoverTau((float)arg);
3913 break;
3914
3915 case changes.PIDHoverActive:
3916 changePIDHoverActive((bool)arg);
3917 break;
3918
3919 case changes.Null:
3920 donullchange();
3921 break;
3922
3923
3924
3925 default:
3926 donullchange();
3927 break;
3928 }
3929 return false;
3930 }
3931
3932 public void AddChange(changes what, object arg)
3933 {
3934 _parent_scene.AddChange((PhysicsActor) this, what, arg);
3935 }
3936
3937
3938 private struct strVehicleBoolParam
3939 {
3940 public int param;
3941 public bool value;
3942 }
3943
3944 private struct strVehicleFloatParam
3945 {
3946 public int param;
3947 public float value;
3948 }
3949
3950 private struct strVehicleQuatParam
3951 {
3952 public int param;
3953 public Quaternion value;
3954 }
3955
3956 private struct strVehicleVectorParam
3957 {
3958 public int param;
3959 public Vector3 value;
3960 }
3961 }
3962}