aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
authorTeravus Ovares2008-12-07 04:03:09 +0000
committerTeravus Ovares2008-12-07 04:03:09 +0000
commit76e1462dff5594252af8e26cc6fc9b9560af090d (patch)
treed2496eef6233445d05ea21d043344d95e4fa16c8 /OpenSim/Region/Physics/OdePlugin
parentSend the creation-date of items to the viewer. This fixes Mantis#2769. (diff)
downloadopensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.zip
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.gz
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.bz2
opensim-SC_OLD-76e1462dff5594252af8e26cc6fc9b9560af090d.tar.xz
* Tweaks physics so that linked prim are a single body. This will make linked prim more stable and probably the last obstacle to vehicles physics wise.
* Fixed a bug that caused physics proxies to be scattered when you link an object. * Single physical prim work exactly the same as before, just linked physical prim will have changed.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs489
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs183
-rw-r--r--OpenSim/Region/Physics/OdePlugin/drawstuff.cs98
3 files changed, 687 insertions, 83 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 79a7519..0a461e9 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -24,7 +24,6 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27
28using System; 27using System;
29using System.Collections.Generic; 28using System.Collections.Generic;
30using System.Reflection; 29using System.Reflection;
@@ -118,6 +117,8 @@ namespace OpenSim.Region.Physics.OdePlugin
118 private PhysicsActor _parent = null; 117 private PhysicsActor _parent = null;
119 private PhysicsActor m_taintparent = null; 118 private PhysicsActor m_taintparent = null;
120 119
120 private List<OdePrim> childrenPrim = new List<OdePrim>();
121
121 private bool iscolliding = false; 122 private bool iscolliding = false;
122 private bool m_isphysical = false; 123 private bool m_isphysical = false;
123 private bool m_isSelected = false; 124 private bool m_isSelected = false;
@@ -147,6 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin
147 148
148 private IntPtr m_linkJoint = (IntPtr)0; 149 private IntPtr m_linkJoint = (IntPtr)0;
149 150
151 public volatile bool childPrim = false;
152
150 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 153 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
151 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 154 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
152 { 155 {
@@ -161,10 +164,10 @@ namespace OpenSim.Region.Physics.OdePlugin
161 m_density = parent_scene.geomDefaultDensity; 164 m_density = parent_scene.geomDefaultDensity;
162 m_tensor = parent_scene.bodyMotorJointMaxforceTensor; 165 m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
163 body_autodisable_frames = parent_scene.bodyFramesAutoDisable; 166 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
164
165 167
166 prim_geom = (IntPtr)0; 168
167 prev_geom = (IntPtr)0; 169 prim_geom = IntPtr.Zero;
170 prev_geom = IntPtr.Zero;
168 171
169 if (size.X <= 0) size.X = 0.01f; 172 if (size.X <= 0) size.X = 0.01f;
170 if (size.Y <= 0) size.Y = 0.01f; 173 if (size.Y <= 0) size.Y = 0.01f;
@@ -247,64 +250,83 @@ namespace OpenSim.Region.Physics.OdePlugin
247 { 250 {
248 prev_geom = prim_geom; 251 prev_geom = prim_geom;
249 prim_geom = geom; 252 prim_geom = geom;
250 if (prim_geom != (IntPtr)0) 253 if (prim_geom != IntPtr.Zero)
251 { 254 {
252 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 255 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
253 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 256 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
254 } 257 }
258
259 if (childPrim)
260 {
261 if (_parent != null && _parent is OdePrim)
262 {
263 OdePrim parent = (OdePrim)_parent;
264 parent.ChildSetGeom(this);
265 }
266 }
255 //m_log.Warn("Setting Geom to: " + prim_geom); 267 //m_log.Warn("Setting Geom to: " + prim_geom);
256 } 268 }
257 269
270
271
258 public void enableBodySoft() 272 public void enableBodySoft()
259 { 273 {
260 if (m_isphysical && Body != (IntPtr)0) 274 if (!childPrim)
261 d.BodyEnable(Body); 275 {
276 if (m_isphysical && Body != IntPtr.Zero)
277 d.BodyEnable(Body);
262 278
263 m_disabled = false; 279 m_disabled = false;
280 }
264 } 281 }
265 282
266 public void disableBodySoft() 283 public void disableBodySoft()
267 { 284 {
268 m_disabled = true; 285 m_disabled = true;
269 286
270 if (m_isphysical && Body != (IntPtr)0) 287 if (m_isphysical && Body != IntPtr.Zero)
271 d.BodyDisable(Body); 288 d.BodyDisable(Body);
272 } 289 }
273 290
274 public void enableBody() 291 public void enableBody()
275 { 292 {
276 // Sets the geom to a body 293 // Don't enable this body if we're a child prim
277 Body = d.BodyCreate(_parent_scene.world); 294 // this should be taken care of in the parent function not here
295 if (!childPrim)
296 {
297 // Sets the geom to a body
298 Body = d.BodyCreate(_parent_scene.world);
278 299
279 setMass(); 300 setMass();
280 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); 301 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
281 d.Quaternion myrot = new d.Quaternion(); 302 d.Quaternion myrot = new d.Quaternion();
282 myrot.X = _orientation.X; 303 myrot.X = _orientation.X;
283 myrot.Y = _orientation.Y; 304 myrot.Y = _orientation.Y;
284 myrot.Z = _orientation.Z; 305 myrot.Z = _orientation.Z;
285 myrot.W = _orientation.W; 306 myrot.W = _orientation.W;
286 d.BodySetQuaternion(Body, ref myrot); 307 d.BodySetQuaternion(Body, ref myrot);
287 d.GeomSetBody(prim_geom, Body); 308 d.GeomSetBody(prim_geom, Body);
288 m_collisionCategories |= CollisionCategories.Body; 309 m_collisionCategories |= CollisionCategories.Body;
289 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 310 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
290 311
291 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 312 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
292 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 313 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
293 314
294 d.BodySetAutoDisableFlag(Body, true); 315 d.BodySetAutoDisableFlag(Body, true);
295 d.BodySetAutoDisableSteps(Body, body_autodisable_frames); 316 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
296 317
297 m_interpenetrationcount = 0; 318 m_interpenetrationcount = 0;
298 m_collisionscore = 0; 319 m_collisionscore = 0;
299 m_disabled = false; 320 m_disabled = false;
300 321
301 // The body doesn't already have a finite rotation mode set here 322 // The body doesn't already have a finite rotation mode set here
302 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 323 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
303 { 324 {
304 createAMotor(m_angularlock); 325 createAMotor(m_angularlock);
305 } 326 }
306 327
307 _parent_scene.addActivePrim(this); 328 _parent_scene.addActivePrim(this);
329 }
308 } 330 }
309 331
310 #region Mass Calculation 332 #region Mass Calculation
@@ -627,20 +649,41 @@ namespace OpenSim.Region.Physics.OdePlugin
627 //this kills the body so things like 'mesh' can re-create it. 649 //this kills the body so things like 'mesh' can re-create it.
628 lock (this) 650 lock (this)
629 { 651 {
630 if (Body != (IntPtr)0) 652 if (!childPrim)
653 {
654 if (Body != IntPtr.Zero)
655 {
656 _parent_scene.remActivePrim(this);
657
658 m_collisionCategories &= ~CollisionCategories.Body;
659 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
660
661 if (prim_geom != IntPtr.Zero)
662 {
663 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
664 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
665 }
666
667
668 d.BodyDestroy(Body);
669 Body = IntPtr.Zero;
670 }
671 }
672 else
631 { 673 {
674 _parent_scene.remActivePrim(this);
675
632 m_collisionCategories &= ~CollisionCategories.Body; 676 m_collisionCategories &= ~CollisionCategories.Body;
633 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 677 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
634 678
635 if (prim_geom != (IntPtr)0) 679 if (prim_geom != IntPtr.Zero)
636 { 680 {
637 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 681 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
638 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 682 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
639 } 683 }
640 684
641 _parent_scene.remActivePrim(this); 685
642 d.BodyDestroy(Body); 686 Body = IntPtr.Zero;
643 Body = (IntPtr)0;
644 } 687 }
645 } 688 }
646 m_disabled = true; 689 m_disabled = true;
@@ -655,9 +698,20 @@ namespace OpenSim.Region.Physics.OdePlugin
655 Thread.Sleep(10); 698 Thread.Sleep(10);
656 699
657 //Kill Body so that mesh can re-make the geom 700 //Kill Body so that mesh can re-make the geom
658 if (IsPhysical && Body != (IntPtr) 0) 701 if (IsPhysical && Body != IntPtr.Zero)
659 { 702 {
660 disableBody(); 703 if (childPrim)
704 {
705 if (_parent != null)
706 {
707 OdePrim parent = (OdePrim)_parent;
708 parent.ChildDelink(this);
709 }
710 }
711 else
712 {
713 disableBody();
714 }
661 } 715 }
662 716
663 IMesh oldMesh = primMesh; 717 IMesh oldMesh = primMesh;
@@ -682,7 +736,7 @@ namespace OpenSim.Region.Physics.OdePlugin
682 736
683 try 737 try
684 { 738 {
685 if (prim_geom == (IntPtr)0) 739 if (prim_geom == IntPtr.Zero)
686 { 740 {
687 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); 741 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
688 } 742 }
@@ -715,7 +769,7 @@ namespace OpenSim.Region.Physics.OdePlugin
715 { 769 {
716 changeadd(timestep); 770 changeadd(timestep);
717 } 771 }
718 if (prim_geom != (IntPtr)0) 772 if (prim_geom != IntPtr.Zero)
719 { 773 {
720 if (!_position.IsIdentical(m_taintposition,0f)) 774 if (!_position.IsIdentical(m_taintposition,0f))
721 changemove(timestep); 775 changemove(timestep);
@@ -724,7 +778,7 @@ namespace OpenSim.Region.Physics.OdePlugin
724 rotate(timestep); 778 rotate(timestep);
725 // 779 //
726 780
727 if (m_taintPhysics != m_isphysical) 781 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent))
728 changePhysicsStatus(timestep); 782 changePhysicsStatus(timestep);
729 // 783 //
730 784
@@ -783,7 +837,7 @@ namespace OpenSim.Region.Physics.OdePlugin
783 if (Amotor != IntPtr.Zero) 837 if (Amotor != IntPtr.Zero)
784 { 838 {
785 d.JointDestroy(Amotor); 839 d.JointDestroy(Amotor);
786 Amotor = (IntPtr)0; 840 Amotor = IntPtr.Zero;
787 } 841 }
788 } 842 }
789 } 843 }
@@ -794,11 +848,18 @@ namespace OpenSim.Region.Physics.OdePlugin
794 848
795 private void changelink(float timestep) 849 private void changelink(float timestep)
796 { 850 {
851 // If the newly set parent is not null
852 // create link
797 if (_parent == null && m_taintparent != null) 853 if (_parent == null && m_taintparent != null)
798 { 854 {
799 if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim) 855 if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim)
800 { 856 {
801 OdePrim obj = (OdePrim)m_taintparent; 857 OdePrim obj = (OdePrim)m_taintparent;
858 //obj.disableBody();
859
860 obj.ParentPrim(this);
861
862 /*
802 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body) 863 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body)
803 { 864 {
804 _linkJointGroup = d.JointGroupCreate(0); 865 _linkJointGroup = d.JointGroupCreate(0);
@@ -806,18 +867,245 @@ namespace OpenSim.Region.Physics.OdePlugin
806 d.JointAttach(m_linkJoint, obj.Body, Body); 867 d.JointAttach(m_linkJoint, obj.Body, Body);
807 d.JointSetFixed(m_linkJoint); 868 d.JointSetFixed(m_linkJoint);
808 } 869 }
870 */
809 } 871 }
810 } 872 }
873 // If the newly set parent is null
874 // destroy link
811 else if (_parent != null && m_taintparent == null) 875 else if (_parent != null && m_taintparent == null)
812 { 876 {
813 if (Body != (IntPtr)0 && _linkJointGroup != (IntPtr)0) 877 if (_parent is OdePrim)
878 {
879 OdePrim obj = (OdePrim)_parent;
880 obj.ChildDelink(this);
881 childPrim = false;
882 //_parent = null;
883 }
884
885 /*
886 if (Body != (IntPtr)0 && _linkJointGroup != (IntPtr)0)
814 d.JointGroupDestroy(_linkJointGroup); 887 d.JointGroupDestroy(_linkJointGroup);
815 888
816 _linkJointGroup = (IntPtr)0; 889 _linkJointGroup = (IntPtr)0;
817 m_linkJoint = (IntPtr)0; 890 m_linkJoint = (IntPtr)0;
891 */
818 } 892 }
819 893
820 _parent = m_taintparent; 894 _parent = m_taintparent;
895 m_taintPhysics = m_isphysical;
896 }
897
898 // I'm the parent
899 // prim is the child
900 public void ParentPrim(OdePrim prim)
901 {
902 if (this.m_localID != prim.m_localID)
903 {
904 if (Body == IntPtr.Zero)
905 {
906 Body = d.BodyCreate(_parent_scene.world);
907 }
908 if (Body != IntPtr.Zero)
909 {
910 lock (childrenPrim)
911 {
912 if (!childrenPrim.Contains(prim))
913 {
914 childrenPrim.Add(prim);
915
916 foreach (OdePrim prm in childrenPrim)
917 {
918 d.Mass m2;
919 d.MassSetZero(out m2);
920 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
921
922
923 d.Quaternion quat = new d.Quaternion();
924 quat.W = prm._orientation.W;
925 quat.X = prm._orientation.X;
926 quat.Y = prm._orientation.Y;
927 quat.Z = prm._orientation.Z;
928
929 d.Matrix3 mat = new d.Matrix3();
930 d.RfromQ(out mat, ref quat);
931 d.MassRotate(out m2, ref mat);
932 d.MassTranslate(out m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
933 d.MassAdd(ref pMass, ref m2);
934 }
935 foreach (OdePrim prm in childrenPrim)
936 {
937 prm.m_collisionCategories |= CollisionCategories.Body;
938 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
939
940 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
941 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
942
943
944 d.Quaternion quat = new d.Quaternion();
945 quat.W = prm._orientation.W;
946 quat.X = prm._orientation.X;
947 quat.Y = prm._orientation.Y;
948 quat.Z = prm._orientation.Z;
949
950 d.Matrix3 mat = new d.Matrix3();
951 d.RfromQ(out mat, ref quat);
952 if (Body != IntPtr.Zero)
953 {
954 d.GeomSetBody(prm.prim_geom, Body);
955 prm.childPrim = true;
956 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
957 //d.GeomSetOffsetPosition(prim.prim_geom,
958 // (Position.X - prm.Position.X) - pMass.c.X,
959 // (Position.Y - prm.Position.Y) - pMass.c.Y,
960 // (Position.Z - prm.Position.Z) - pMass.c.Z);
961 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
962 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
963 d.MassTranslate(out pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
964 d.BodySetMass(Body, ref pMass);
965 }
966 else
967 {
968 m_log.Debug("[PHYSICS]:I ain't got no boooooooooddy, no body");
969 }
970
971
972 prm.m_interpenetrationcount = 0;
973 prm.m_collisionscore = 0;
974 prm.m_disabled = false;
975
976 // The body doesn't already have a finite rotation mode set here
977 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
978 {
979 prm.createAMotor(m_angularlock);
980 }
981 prm.Body = Body;
982 _parent_scene.addActivePrim(prm);
983 }
984
985 m_collisionCategories |= CollisionCategories.Body;
986 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
987
988 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
989 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
990
991
992 d.Quaternion quat2 = new d.Quaternion();
993 quat2.W = _orientation.W;
994 quat2.X = _orientation.X;
995 quat2.Y = _orientation.Y;
996 quat2.Z = _orientation.Z;
997
998 d.Matrix3 mat2 = new d.Matrix3();
999 d.RfromQ(out mat2, ref quat2);
1000 d.GeomSetBody(prim_geom, Body);
1001 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1002 //d.GeomSetOffsetPosition(prim.prim_geom,
1003 // (Position.X - prm.Position.X) - pMass.c.X,
1004 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1005 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1006 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1007 d.MassTranslate(out pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1008 d.BodySetMass(Body, ref pMass);
1009
1010 d.BodySetAutoDisableFlag(Body, true);
1011 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1012
1013
1014 m_interpenetrationcount = 0;
1015 m_collisionscore = 0;
1016 m_disabled = false;
1017
1018 // The body doesn't already have a finite rotation mode set here
1019 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
1020 {
1021 createAMotor(m_angularlock);
1022 }
1023 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1024
1025 _parent_scene.addActivePrim(this);
1026 }
1027 }
1028 }
1029 }
1030
1031 }
1032
1033 private void ChildSetGeom(OdePrim odePrim)
1034 {
1035 //if (m_isphysical && Body != IntPtr.Zero)
1036 lock (childrenPrim)
1037 {
1038 foreach (OdePrim prm in childrenPrim)
1039 {
1040 //prm.childPrim = true;
1041 prm.disableBody();
1042 //prm.m_taintparent = null;
1043 //prm._parent = null;
1044 //prm.m_taintPhysics = false;
1045 //prm.m_disabled = true;
1046 //prm.childPrim = false;
1047 }
1048 }
1049 disableBody();
1050
1051
1052 if (Body != IntPtr.Zero)
1053 {
1054 _parent_scene.remActivePrim(this);
1055 }
1056
1057 lock (childrenPrim)
1058 {
1059 foreach (OdePrim prm in childrenPrim)
1060 {
1061 ParentPrim(prm);
1062 }
1063 }
1064
1065 }
1066
1067 private void ChildDelink(OdePrim odePrim)
1068 {
1069 // Okay, we have a delinked child.. need to rebuild the body.
1070 lock (childrenPrim)
1071 {
1072 foreach (OdePrim prm in childrenPrim)
1073 {
1074 prm.childPrim = true;
1075 prm.disableBody();
1076 //prm.m_taintparent = null;
1077 //prm._parent = null;
1078 //prm.m_taintPhysics = false;
1079 //prm.m_disabled = true;
1080 //prm.childPrim = false;
1081 }
1082 }
1083 disableBody();
1084
1085 lock (childrenPrim)
1086 {
1087 childrenPrim.Remove(odePrim);
1088 }
1089
1090
1091
1092
1093 if (Body != IntPtr.Zero)
1094 {
1095 _parent_scene.remActivePrim(this);
1096 }
1097
1098
1099
1100 lock (childrenPrim)
1101 {
1102 foreach (OdePrim prm in childrenPrim)
1103 {
1104 ParentPrim(prm);
1105 }
1106 }
1107
1108
821 } 1109 }
822 1110
823 private void changeSelectedStatus(float timestep) 1111 private void changeSelectedStatus(float timestep)
@@ -837,7 +1125,7 @@ namespace OpenSim.Region.Physics.OdePlugin
837 disableBodySoft(); 1125 disableBodySoft();
838 } 1126 }
839 1127
840 if (prim_geom != (IntPtr)0) 1128 if (prim_geom != IntPtr.Zero)
841 { 1129 {
842 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1130 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
843 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1131 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
@@ -862,7 +1150,7 @@ namespace OpenSim.Region.Physics.OdePlugin
862 if (m_collidesWater) 1150 if (m_collidesWater)
863 m_collisionFlags |= CollisionCategories.Water; 1151 m_collisionFlags |= CollisionCategories.Water;
864 1152
865 if (prim_geom != (IntPtr)0) 1153 if (prim_geom != IntPtr.Zero)
866 { 1154 {
867 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1155 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
868 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1156 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
@@ -993,7 +1281,7 @@ namespace OpenSim.Region.Physics.OdePlugin
993 { 1281 {
994 CreateGeom(m_targetSpace, _mesh); 1282 CreateGeom(m_targetSpace, _mesh);
995 1283
996 if (prim_geom != (IntPtr) 0) 1284 if (prim_geom != IntPtr.Zero)
997 { 1285 {
998 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1286 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
999 d.Quaternion myrot = new d.Quaternion(); 1287 d.Quaternion myrot = new d.Quaternion();
@@ -1004,7 +1292,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1004 d.GeomSetQuaternion(prim_geom, ref myrot); 1292 d.GeomSetQuaternion(prim_geom, ref myrot);
1005 } 1293 }
1006 1294
1007 if (m_isphysical && Body == (IntPtr)0) 1295 if (m_isphysical && Body == IntPtr.Zero)
1008 { 1296 {
1009 enableBody(); 1297 enableBody();
1010 } 1298 }
@@ -1023,16 +1311,16 @@ namespace OpenSim.Region.Physics.OdePlugin
1023 if (m_isphysical) 1311 if (m_isphysical)
1024 { 1312 {
1025 // This is a fallback.. May no longer be necessary. 1313 // This is a fallback.. May no longer be necessary.
1026 if (Body == (IntPtr) 0) 1314 if (Body == IntPtr.Zero)
1027 enableBody(); 1315 enableBody();
1028 //Prim auto disable after 20 frames, 1316 //Prim auto disable after 20 frames,
1029 //if you move it, re-enable the prim manually. 1317 //if you move it, re-enable the prim manually.
1030 if (_parent != null) 1318 if (_parent != null)
1031 { 1319 {
1032 if (m_linkJoint != (IntPtr)0) 1320 if (m_linkJoint != IntPtr.Zero)
1033 { 1321 {
1034 d.JointDestroy(m_linkJoint); 1322 d.JointDestroy(m_linkJoint);
1035 m_linkJoint = (IntPtr)0; 1323 m_linkJoint = IntPtr.Zero;
1036 } 1324 }
1037 } 1325 }
1038 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); 1326 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
@@ -1058,7 +1346,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1058 m_targetSpace = tempspace; 1346 m_targetSpace = tempspace;
1059 1347
1060 _parent_scene.waitForSpaceUnlock(m_targetSpace); 1348 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1061 if (prim_geom != (IntPtr) 0) 1349 if (prim_geom != IntPtr.Zero)
1062 { 1350 {
1063 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1351 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1064 1352
@@ -1079,7 +1367,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1079 float fy = 0; 1367 float fy = 0;
1080 float fz = 0; 1368 float fz = 0;
1081 1369
1082 if (IsPhysical && Body != (IntPtr)0 && !m_isSelected) 1370 if (IsPhysical && Body != IntPtr.Zero && !m_isSelected)
1083 { 1371 {
1084 //float PID_P = 900.0f; 1372 //float PID_P = 900.0f;
1085 1373
@@ -1201,7 +1489,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1201 myrot.Z = _orientation.Z; 1489 myrot.Z = _orientation.Z;
1202 myrot.W = _orientation.W; 1490 myrot.W = _orientation.W;
1203 d.GeomSetQuaternion(prim_geom, ref myrot); 1491 d.GeomSetQuaternion(prim_geom, ref myrot);
1204 if (m_isphysical && Body != (IntPtr) 0) 1492 if (m_isphysical && Body != IntPtr.Zero)
1205 { 1493 {
1206 d.BodySetQuaternion(Body, ref myrot); 1494 d.BodySetQuaternion(Body, ref myrot);
1207 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) 1495 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0))
@@ -1222,10 +1510,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1222 public void changedisable(float timestep) 1510 public void changedisable(float timestep)
1223 { 1511 {
1224 m_disabled = true; 1512 m_disabled = true;
1225 if (Body != (IntPtr)0) 1513 if (Body != IntPtr.Zero)
1226 { 1514 {
1227 d.BodyDisable(Body); 1515 d.BodyDisable(Body);
1228 Body = (IntPtr)0; 1516 Body = IntPtr.Zero;
1229 } 1517 }
1230 1518
1231 m_taintdisable = false; 1519 m_taintdisable = false;
@@ -1235,7 +1523,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1235 { 1523 {
1236 if (m_isphysical == true) 1524 if (m_isphysical == true)
1237 { 1525 {
1238 if (Body == (IntPtr)0) 1526 if (Body == IntPtr.Zero)
1239 { 1527 {
1240 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1528 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1241 { 1529 {
@@ -1249,7 +1537,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1249 } 1537 }
1250 else 1538 else
1251 { 1539 {
1252 if (Body != (IntPtr)0) 1540 if (Body != IntPtr.Zero)
1253 { 1541 {
1254 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1542 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1255 { 1543 {
@@ -1272,7 +1560,18 @@ namespace OpenSim.Region.Physics.OdePlugin
1272 1560
1273 changeadd(2f); 1561 changeadd(2f);
1274 } 1562 }
1275 disableBody(); 1563 if (childPrim)
1564 {
1565 if (_parent != null)
1566 {
1567 OdePrim parent = (OdePrim)_parent;
1568 parent.ChildDelink(this);
1569 }
1570 }
1571 else
1572 {
1573 disableBody();
1574 }
1276 } 1575 }
1277 } 1576 }
1278 1577
@@ -1301,9 +1600,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1301 // Cleanup meshing here 1600 // Cleanup meshing here
1302 } 1601 }
1303 //kill body to rebuild 1602 //kill body to rebuild
1304 if (IsPhysical && Body != (IntPtr)0) 1603 if (IsPhysical && Body != IntPtr.Zero)
1305 { 1604 {
1306 disableBody(); 1605 if (childPrim)
1606 {
1607 if (_parent != null)
1608 {
1609 OdePrim parent = (OdePrim)_parent;
1610 parent.ChildDelink(this);
1611 }
1612 }
1613 else
1614 {
1615 disableBody();
1616 }
1307 } 1617 }
1308 if (d.SpaceQuery(m_targetSpace, prim_geom)) 1618 if (d.SpaceQuery(m_targetSpace, prim_geom))
1309 { 1619 {
@@ -1311,7 +1621,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1311 d.SpaceRemove(m_targetSpace, prim_geom); 1621 d.SpaceRemove(m_targetSpace, prim_geom);
1312 } 1622 }
1313 d.GeomDestroy(prim_geom); 1623 d.GeomDestroy(prim_geom);
1314 prim_geom = (IntPtr)0; 1624 prim_geom = IntPtr.Zero;
1315 // we don't need to do space calculation because the client sends a position update also. 1625 // we don't need to do space calculation because the client sends a position update also.
1316 1626
1317 // Construction of new prim 1627 // Construction of new prim
@@ -1349,7 +1659,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1349 d.GeomSetQuaternion(prim_geom, ref myrot); 1659 d.GeomSetQuaternion(prim_geom, ref myrot);
1350 1660
1351 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 1661 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1352 if (IsPhysical && Body == (IntPtr)0) 1662 if (IsPhysical && Body == IntPtr.Zero && !childPrim)
1353 { 1663 {
1354 // Re creates body on size. 1664 // Re creates body on size.
1355 // EnableBody also does setMass() 1665 // EnableBody also does setMass()
@@ -1360,7 +1670,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1360 _parent_scene.geom_name_map[prim_geom] = oldname; 1670 _parent_scene.geom_name_map[prim_geom] = oldname;
1361 1671
1362 changeSelectedStatus(timestamp); 1672 changeSelectedStatus(timestamp);
1363 1673 if (childPrim)
1674 {
1675 if (_parent is OdePrim)
1676 {
1677 OdePrim parent = (OdePrim)_parent;
1678 parent.ChildSetGeom(this);
1679 }
1680 }
1364 resetCollisionAccounting(); 1681 resetCollisionAccounting();
1365 m_taintsize = _size; 1682 m_taintsize = _size;
1366 } 1683 }
@@ -1541,7 +1858,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1541 { 1858 {
1542 m_collidesWater = m_taintCollidesWater; 1859 m_collidesWater = m_taintCollidesWater;
1543 1860
1544 if (prim_geom != (IntPtr)0) 1861 if (prim_geom != IntPtr.Zero)
1545 { 1862 {
1546 if (m_collidesWater) 1863 if (m_collidesWater)
1547 { 1864 {
@@ -1560,9 +1877,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1560 string oldname = _parent_scene.geom_name_map[prim_geom]; 1877 string oldname = _parent_scene.geom_name_map[prim_geom];
1561 1878
1562 // Cleanup of old prim geometry and Bodies 1879 // Cleanup of old prim geometry and Bodies
1563 if (IsPhysical && Body != (IntPtr) 0) 1880 if (IsPhysical && Body != IntPtr.Zero)
1564 { 1881 {
1565 disableBody(); 1882 if (childPrim)
1883 {
1884 if (_parent != null)
1885 {
1886 OdePrim parent = (OdePrim)_parent;
1887 parent.ChildDelink(this);
1888 }
1889 }
1890 else
1891 {
1892 disableBody();
1893 }
1566 } 1894 }
1567 try 1895 try
1568 { 1896 {
@@ -1573,7 +1901,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1573 prim_geom = IntPtr.Zero; 1901 prim_geom = IntPtr.Zero;
1574 m_log.Error("[PHYSICS]: PrimGeom dead"); 1902 m_log.Error("[PHYSICS]: PrimGeom dead");
1575 } 1903 }
1576 prim_geom = (IntPtr) 0; 1904 prim_geom = IntPtr.Zero;
1577 // we don't need to do space calculation because the client sends a position update also. 1905 // we don't need to do space calculation because the client sends a position update also.
1578 if (_size.X <= 0) _size.X = 0.01f; 1906 if (_size.X <= 0) _size.X = 0.01f;
1579 if (_size.Y <= 0) _size.Y = 0.01f; 1907 if (_size.Y <= 0) _size.Y = 0.01f;
@@ -1608,7 +1936,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1608 d.GeomSetQuaternion(prim_geom, ref myrot); 1936 d.GeomSetQuaternion(prim_geom, ref myrot);
1609 1937
1610 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 1938 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1611 if (IsPhysical && Body == (IntPtr)0) 1939 if (IsPhysical && Body == IntPtr.Zero)
1612 { 1940 {
1613 // Re creates body on size. 1941 // Re creates body on size.
1614 // EnableBody also does setMass() 1942 // EnableBody also does setMass()
@@ -1618,7 +1946,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1618 _parent_scene.geom_name_map[prim_geom] = oldname; 1946 _parent_scene.geom_name_map[prim_geom] = oldname;
1619 1947
1620 changeSelectedStatus(timestamp); 1948 changeSelectedStatus(timestamp);
1621 1949 if (childPrim)
1950 {
1951 if (_parent is OdePrim)
1952 {
1953 OdePrim parent = (OdePrim)_parent;
1954 parent.ChildSetGeom(this);
1955 }
1956 }
1622 resetCollisionAccounting(); 1957 resetCollisionAccounting();
1623 m_taintshape = false; 1958 m_taintshape = false;
1624 } 1959 }
@@ -1658,7 +1993,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1658 Thread.Sleep(20); 1993 Thread.Sleep(20);
1659 if (IsPhysical) 1994 if (IsPhysical)
1660 { 1995 {
1661 if (Body != (IntPtr)0) 1996 if (Body != IntPtr.Zero)
1662 { 1997 {
1663 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); 1998 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
1664 } 1999 }
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0dab05c..a50c5ae 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -24,6 +24,7 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27//#define USE_DRAWSTUFF
27 28
28using System; 29using System;
29using System.Collections.Generic; 30using System.Collections.Generic;
@@ -34,6 +35,9 @@ using System.IO;
34using log4net; 35using log4net;
35using Nini.Config; 36using Nini.Config;
36using Ode.NET; 37using Ode.NET;
38#if USE_DRAWSTUFF
39using Drawstuff.NET;
40#endif
37using OpenSim.Framework; 41using OpenSim.Framework;
38using OpenSim.Region.Physics.Manager; 42using OpenSim.Region.Physics.Manager;
39using OpenMetaverse; 43using OpenMetaverse;
@@ -257,6 +261,9 @@ namespace OpenSim.Region.Physics.OdePlugin
257 public int physics_logging_interval = 0; 261 public int physics_logging_interval = 0;
258 public bool physics_logging_append_existing_logfile = false; 262 public bool physics_logging_append_existing_logfile = false;
259 263
264 public d.Vector3 xyz = new d.Vector3(2.1640f, -1.3079f, 1.7600f);
265 public d.Vector3 hpr = new d.Vector3(125.5000f, -17.0000f, 0.0000f);
266
260 /// <summary> 267 /// <summary>
261 /// Initiailizes the scene 268 /// Initiailizes the scene
262 /// Sets many properties that ODE requires to be stable 269 /// Sets many properties that ODE requires to be stable
@@ -280,6 +287,11 @@ namespace OpenSim.Region.Physics.OdePlugin
280 //contactgroup 287 //contactgroup
281 288
282 d.WorldSetAutoDisableFlag(world, false); 289 d.WorldSetAutoDisableFlag(world, false);
290 #if USE_DRAWSTUFF
291
292 Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization));
293 viewthread.Start();
294 #endif
283 } 295 }
284 296
285 // zero out a heightmap array float array (single dimention [flattened])) 297 // zero out a heightmap array float array (single dimention [flattened]))
@@ -290,6 +302,21 @@ namespace OpenSim.Region.Physics.OdePlugin
290 // we can hit test less. 302 // we can hit test less.
291 } 303 }
292 304
305#if USE_DRAWSTUFF
306 public void startvisualization(object o)
307 {
308 ds.Functions fn;
309 fn.version = ds.VERSION;
310 fn.start = new ds.CallbackFunction(start);
311 fn.step = new ds.CallbackFunction(step);
312 fn.command = new ds.CallbackFunction(command);
313 fn.stop = null;
314 fn.path_to_textures = "./textures";
315 string[] args = new string[0];
316 ds.SimulationLoop(args.Length, args, 352, 288, ref fn);
317 }
318#endif
319
293 // Initialize the mesh plugin 320 // Initialize the mesh plugin
294 public override void Initialise(IMesher meshmerizer, IConfigSource config) 321 public override void Initialise(IMesher meshmerizer, IConfigSource config)
295 { 322 {
@@ -787,6 +814,10 @@ namespace OpenSim.Region.Physics.OdePlugin
787 _perloopContact.Add(contacts[i]); 814 _perloopContact.Add(contacts[i]);
788 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); 815 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact);
789 } 816 }
817 //if (p2.PhysicsActorType == (int)ActorTypes.Prim)
818 //{
819 //m_log.Debug("[PHYSICS]: prim contacting with ground");
820 //}
790 } 821 }
791 else if (name1 == "Water" || name2 == "Water") 822 else if (name1 == "Water" || name2 == "Water")
792 { 823 {
@@ -1137,7 +1168,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1137 List<OdePrim> removeprims = null; 1168 List<OdePrim> removeprims = null;
1138 foreach (OdePrim chr in _activeprims) 1169 foreach (OdePrim chr in _activeprims)
1139 { 1170 {
1140 if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) 1171 if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
1141 { 1172 {
1142 try 1173 try
1143 { 1174 {
@@ -1243,7 +1274,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1243 { 1274 {
1244 newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, ode); 1275 newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, ode);
1245 1276
1246 _prims.Add(newPrim); 1277 lock (_prims)
1278 _prims.Add(newPrim);
1247 } 1279 }
1248 1280
1249 return newPrim; 1281 return newPrim;
@@ -1252,8 +1284,13 @@ namespace OpenSim.Region.Physics.OdePlugin
1252 public void addActivePrim(OdePrim activatePrim) 1284 public void addActivePrim(OdePrim activatePrim)
1253 { 1285 {
1254 // adds active prim.. (ones that should be iterated over in collisions_optimized 1286 // adds active prim.. (ones that should be iterated over in collisions_optimized
1255 1287 lock (_activeprims)
1256 _activeprims.Add(activatePrim); 1288 {
1289 if (!_activeprims.Contains(activatePrim))
1290 _activeprims.Add(activatePrim);
1291 //else
1292 // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
1293 }
1257 } 1294 }
1258 1295
1259 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 1296 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
@@ -1334,6 +1371,15 @@ namespace OpenSim.Region.Physics.OdePlugin
1334 if (prim.IsPhysical) 1371 if (prim.IsPhysical)
1335 { 1372 {
1336 prim.disableBody(); 1373 prim.disableBody();
1374 if (prim.childPrim)
1375 {
1376 prim.childPrim = false;
1377 prim.Body = IntPtr.Zero;
1378 prim.m_disabled = true;
1379 prim.IsPhysical = false;
1380 }
1381
1382
1337 } 1383 }
1338 // we don't want to remove the main space 1384 // we don't want to remove the main space
1339 1385
@@ -1376,6 +1422,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1376 { 1422 {
1377 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); 1423 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed.");
1378 } 1424 }
1425 lock (_prims)
1379 _prims.Remove(prim); 1426 _prims.Remove(prim);
1380 1427
1381 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 1428 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
@@ -2376,9 +2423,12 @@ namespace OpenSim.Region.Physics.OdePlugin
2376 { 2423 {
2377 lock (OdeLock) 2424 lock (OdeLock)
2378 { 2425 {
2379 foreach (OdePrim prm in _prims) 2426 lock (_prims)
2380 { 2427 {
2381 RemovePrim(prm); 2428 foreach (OdePrim prm in _prims)
2429 {
2430 RemovePrim(prm);
2431 }
2382 } 2432 }
2383 2433
2384 //foreach (OdeCharacter act in _characters) 2434 //foreach (OdeCharacter act in _characters)
@@ -2411,5 +2461,126 @@ namespace OpenSim.Region.Physics.OdePlugin
2411 } 2461 }
2412 return returncolliders; 2462 return returncolliders;
2413 } 2463 }
2464#if USE_DRAWSTUFF
2465 // Keyboard callback
2466 public void command(int cmd)
2467 {
2468 IntPtr geom;
2469 d.Mass mass;
2470 d.Vector3 sides = new d.Vector3(d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f, d.RandReal() * 0.5f + 0.1f);
2471
2472
2473
2474 Char ch = Char.ToLower((Char)cmd);
2475 switch ((Char)ch)
2476 {
2477 case 'w':
2478 Vector3 rotate = (new Vector3(1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
2479
2480 xyz.X += rotate.X; xyz.Y += rotate.Y; xyz.Z += rotate.Z;
2481 ds.SetViewpoint(ref xyz, ref hpr);
2482 break;
2483
2484 case 'a':
2485 hpr.X++;
2486 ds.SetViewpoint(ref xyz, ref hpr);
2487 break;
2488
2489 case 's':
2490 Vector3 rotate2 = (new Vector3(-1, 0, 0) * Quaternion.CreateFromEulers(hpr.Z * Utils.DEG_TO_RAD, hpr.Y * Utils.DEG_TO_RAD, hpr.X * Utils.DEG_TO_RAD));
2491
2492 xyz.X += rotate2.X; xyz.Y += rotate2.Y; xyz.Z += rotate2.Z;
2493 ds.SetViewpoint(ref xyz, ref hpr);
2494 break;
2495 case 'd':
2496 hpr.X--;
2497 ds.SetViewpoint(ref xyz, ref hpr);
2498 break;
2499 case 'r':
2500 xyz.Z++;
2501 ds.SetViewpoint(ref xyz, ref hpr);
2502 break;
2503 case 'f':
2504 xyz.Z--;
2505 ds.SetViewpoint(ref xyz, ref hpr);
2506 break;
2507 case 'e':
2508 xyz.Y++;
2509 ds.SetViewpoint(ref xyz, ref hpr);
2510 break;
2511 case 'q':
2512 xyz.Y--;
2513 ds.SetViewpoint(ref xyz, ref hpr);
2514 break;
2515 }
2516 }
2517
2518 public void step(int pause)
2519 {
2520
2521 ds.SetColor(1.0f, 1.0f, 0.0f);
2522 ds.SetTexture(ds.Texture.Wood);
2523 lock (_prims)
2524 {
2525 foreach (OdePrim prm in _prims)
2526 {
2527 //IntPtr body = d.GeomGetBody(prm.prim_geom);
2528 if (prm.prim_geom != IntPtr.Zero)
2529 {
2530 d.Vector3 pos;
2531 d.GeomCopyPosition(prm.prim_geom, out pos);
2532 //d.BodyCopyPosition(body, out pos);
2533
2534 d.Matrix3 R;
2535 d.GeomCopyRotation(prm.prim_geom, out R);
2536 //d.BodyCopyRotation(body, out R);
2537
2538
2539 d.Vector3 sides = new d.Vector3();
2540 sides.X = prm.Size.X;
2541 sides.Y = prm.Size.Y;
2542 sides.Z = prm.Size.Z;
2543
2544 ds.DrawBox(ref pos, ref R, ref sides);
2545 }
2546 }
2547 }
2548 ds.SetColor(1.0f, 0.0f, 0.0f);
2549 lock (_characters)
2550 {
2551 foreach (OdeCharacter chr in _characters)
2552 {
2553 if (chr.Shell != IntPtr.Zero)
2554 {
2555 IntPtr body = d.GeomGetBody(chr.Shell);
2556
2557 d.Vector3 pos;
2558 d.GeomCopyPosition(chr.Shell, out pos);
2559 //d.BodyCopyPosition(body, out pos);
2560
2561 d.Matrix3 R;
2562 d.GeomCopyRotation(chr.Shell, out R);
2563 //d.BodyCopyRotation(body, out R);
2564
2565 ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f);
2566 d.Vector3 sides = new d.Vector3();
2567 sides.X = 0.5f;
2568 sides.Y = 0.5f;
2569 sides.Z = 0.5f;
2570
2571 ds.DrawBox(ref pos, ref R, ref sides);
2572
2573
2574 }
2575 }
2576 }
2577 }
2578
2579 public void start(int unused)
2580 {
2581
2582 ds.SetViewpoint(ref xyz, ref hpr);
2583 }
2584#endif
2414 } 2585 }
2415} 2586}
diff --git a/OpenSim/Region/Physics/OdePlugin/drawstuff.cs b/OpenSim/Region/Physics/OdePlugin/drawstuff.cs
new file mode 100644
index 0000000..73afe12
--- /dev/null
+++ b/OpenSim/Region/Physics/OdePlugin/drawstuff.cs
@@ -0,0 +1,98 @@
1/*
2 * Copyright ODE
3 * Ode.NET - .NET bindings for ODE
4 * Jason Perkins (starkos@industriousone.com)
5 * Licensed under the New BSD
6 * Part of the OpenDynamicsEngine
7Open Dynamics Engine
8Copyright (c) 2001-2007, Russell L. Smith.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions
13are met:
14
15Redistributions of source code must retain the above copyright notice,
16this list of conditions and the following disclaimer.
17
18Redistributions in binary form must reproduce the above copyright notice,
19this list of conditions and the following disclaimer in the documentation
20and/or other materials provided with the distribution.
21
22Neither the names of ODE's copyright owner nor the names of its
23contributors may be used to endorse or promote products derived from
24this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 *
39 */
40
41using System;
42using System.Runtime.InteropServices;
43using Ode.NET;
44
45namespace Drawstuff.NET
46{
47#if dDOUBLE
48 using dReal = System.Double;
49#else
50 using dReal = System.Single;
51#endif
52
53 public static class ds
54 {
55 public const int VERSION = 2;
56
57 public enum Texture
58 {
59 None,
60 Wood
61 }
62
63 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64 public delegate void CallbackFunction(int arg);
65
66 [StructLayout(LayoutKind.Sequential)]
67 public struct Functions
68 {
69 public int version;
70 public CallbackFunction start;
71 public CallbackFunction step;
72 public CallbackFunction command;
73 public CallbackFunction stop;
74 public string path_to_textures;
75 }
76
77 [DllImport("drawstuff", EntryPoint = "dsDrawBox")]
78 public static extern void DrawBox(ref d.Vector3 pos, ref d.Matrix3 R, ref d.Vector3 sides);
79
80 [DllImport("drawstuff", EntryPoint = "dsDrawCapsule")]
81 public static extern void DrawCapsule(ref d.Vector3 pos, ref d.Matrix3 R, dReal length, dReal radius);
82
83 [DllImport("drawstuff", EntryPoint = "dsDrawConvex")]
84 public static extern void DrawConvex(ref d.Vector3 pos, ref d.Matrix3 R, dReal[] planes, int planeCount, dReal[] points, int pointCount, int[] polygons);
85
86 [DllImport("drawstuff", EntryPoint = "dsSetColor")]
87 public static extern void SetColor(float red, float green, float blue);
88
89 [DllImport("drawstuff", EntryPoint = "dsSetTexture")]
90 public static extern void SetTexture(Texture texture);
91
92 [DllImport("drawstuff", EntryPoint = "dsSetViewpoint")]
93 public static extern void SetViewpoint(ref d.Vector3 xyz, ref d.Vector3 hpr);
94
95 [DllImport("drawstuff", EntryPoint = "dsSimulationLoop")]
96 public static extern void SimulationLoop(int argc, string[] argv, int window_width, int window_height, ref Functions fn);
97 }
98} \ No newline at end of file