diff options
author | Teravus Ovares | 2008-03-10 05:23:43 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-03-10 05:23:43 +0000 |
commit | 8bea3dbdb91dfb465338572e3dfb40a5adfb9bab (patch) | |
tree | d941528dbb7e5faba74037dfbc03a2edacede342 /OpenSim/Region/Physics/OdePlugin | |
parent | * Fixed a few things and enabling Physical Prim border crossings again. (diff) | |
download | opensim-SC-8bea3dbdb91dfb465338572e3dfb40a5adfb9bab.zip opensim-SC-8bea3dbdb91dfb465338572e3dfb40a5adfb9bab.tar.gz opensim-SC-8bea3dbdb91dfb465338572e3dfb40a5adfb9bab.tar.bz2 opensim-SC-8bea3dbdb91dfb465338572e3dfb40a5adfb9bab.tar.xz |
* Added ODEPlugin Support for llSetBuoyancy. Set Buoyancy to 1 for space prim.
* Added WaterLevel support to the ODEPlugin. More on this later.
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 7 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 49 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 128 |
3 files changed, 173 insertions, 11 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index b5263a6..7047ec1 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | |||
@@ -87,6 +87,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
87 | private bool m_hackSentFly = false; | 87 | private bool m_hackSentFly = false; |
88 | public uint m_localID = 0; | 88 | public uint m_localID = 0; |
89 | 89 | ||
90 | private float m_buoyancy = 0f; | ||
91 | |||
90 | private CollisionLocker ode; | 92 | private CollisionLocker ode; |
91 | 93 | ||
92 | private string m_name = String.Empty; | 94 | private string m_name = String.Empty; |
@@ -177,6 +179,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
177 | set { return; } | 179 | set { return; } |
178 | } | 180 | } |
179 | 181 | ||
182 | public override float Buoyancy | ||
183 | { | ||
184 | get { return m_buoyancy; } | ||
185 | set { m_buoyancy = value; } | ||
186 | } | ||
180 | 187 | ||
181 | public override bool IsPhysical | 188 | public override bool IsPhysical |
182 | { | 189 | { |
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index c5ffe98..5291cbf 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -55,7 +55,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
55 | private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom | 55 | private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom |
56 | | CollisionCategories.Space | 56 | | CollisionCategories.Space |
57 | | CollisionCategories.Body | 57 | | CollisionCategories.Body |
58 | | CollisionCategories.Character); | 58 | | CollisionCategories.Character |
59 | ); | ||
59 | private bool m_taintshape = false; | 60 | private bool m_taintshape = false; |
60 | private bool m_taintPhysics = false; | 61 | private bool m_taintPhysics = false; |
61 | private bool m_collidesLand = true; | 62 | private bool m_collidesLand = true; |
@@ -106,6 +107,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
106 | public int m_roundsUnderMotionThreshold = 0; | 107 | public int m_roundsUnderMotionThreshold = 0; |
107 | private int m_crossingfailures = 0; | 108 | private int m_crossingfailures = 0; |
108 | 109 | ||
110 | public float m_buoyancy = 0f; | ||
111 | |||
109 | public bool outofBounds = false; | 112 | public bool outofBounds = false; |
110 | private float m_density = 10.000006836f; // Aluminum g/cm3; | 113 | private float m_density = 10.000006836f; // Aluminum g/cm3; |
111 | 114 | ||
@@ -704,7 +707,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
704 | if (prim_geom != (IntPtr)0) | 707 | if (prim_geom != (IntPtr)0) |
705 | { | 708 | { |
706 | if (m_taintposition != _position) | 709 | if (m_taintposition != _position) |
707 | Move(timestep); | 710 | changemove(timestep); |
708 | 711 | ||
709 | if (m_taintrot != _orientation) | 712 | if (m_taintrot != _orientation) |
710 | rotate(timestep); | 713 | rotate(timestep); |
@@ -829,7 +832,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
829 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | 832 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
830 | } | 833 | } |
831 | if (m_isphysical) | 834 | if (m_isphysical) |
835 | { | ||
836 | d.BodySetLinearVel(Body, 0f, 0f, 0f); | ||
832 | enableBodySoft(); | 837 | enableBodySoft(); |
838 | } | ||
833 | 839 | ||
834 | 840 | ||
835 | } | 841 | } |
@@ -1003,7 +1009,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1003 | 1009 | ||
1004 | 1010 | ||
1005 | } | 1011 | } |
1006 | public void Move(float timestep) | 1012 | public void changemove(float timestep) |
1007 | { | 1013 | { |
1008 | 1014 | ||
1009 | 1015 | ||
@@ -1063,6 +1069,37 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1063 | m_taintposition = _position; | 1069 | m_taintposition = _position; |
1064 | } | 1070 | } |
1065 | 1071 | ||
1072 | public void Move(float timestep) | ||
1073 | { | ||
1074 | |||
1075 | if (IsPhysical && Body != (IntPtr)0 && !m_isSelected) | ||
1076 | { | ||
1077 | float m_mass = CalculateMass(); | ||
1078 | //m_log.Info(m_collisionFlags.ToString()); | ||
1079 | if (m_buoyancy != 0) | ||
1080 | { | ||
1081 | float buoyancy = 0f; | ||
1082 | if (m_buoyancy > 0) | ||
1083 | { | ||
1084 | buoyancy = ((9.8f * m_buoyancy) * m_mass); | ||
1085 | |||
1086 | //d.Vector3 l_velocity = d.BodyGetLinearVel(Body); | ||
1087 | //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (9.8f * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString()); | ||
1088 | } | ||
1089 | else | ||
1090 | { | ||
1091 | buoyancy = (-1 * ((9.8f * (-1 * m_buoyancy)) * m_mass)); | ||
1092 | } | ||
1093 | d.BodyAddForce(Body, 0, 0, buoyancy); | ||
1094 | |||
1095 | } | ||
1096 | } | ||
1097 | else | ||
1098 | { | ||
1099 | return; | ||
1100 | } | ||
1101 | } | ||
1102 | |||
1066 | public void rotate(float timestep) | 1103 | public void rotate(float timestep) |
1067 | { | 1104 | { |
1068 | 1105 | ||
@@ -1676,6 +1713,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1676 | } | 1713 | } |
1677 | } | 1714 | } |
1678 | 1715 | ||
1716 | public override float Buoyancy | ||
1717 | { | ||
1718 | get { return m_buoyancy; } | ||
1719 | set { m_buoyancy = value; } | ||
1720 | } | ||
1721 | |||
1679 | public override void link(PhysicsActor obj) | 1722 | public override void link(PhysicsActor obj) |
1680 | { | 1723 | { |
1681 | m_taintparent = obj; | 1724 | m_taintparent = obj; |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 16c6bb0..9f160a5 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -49,6 +49,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
49 | private CollisionLocker ode; | 49 | private CollisionLocker ode; |
50 | private OdeScene _mScene; | 50 | private OdeScene _mScene; |
51 | 51 | ||
52 | |||
52 | public OdePlugin() | 53 | public OdePlugin() |
53 | { | 54 | { |
54 | ode = new CollisionLocker(); | 55 | ode = new CollisionLocker(); |
@@ -98,16 +99,26 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
98 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 99 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
99 | 100 | ||
100 | CollisionLocker ode; | 101 | CollisionLocker ode; |
101 | 102 | ||
103 | protected Random fluidRandomizer = new Random(System.Environment.TickCount); | ||
104 | |||
102 | private const uint m_regionWidth = Constants.RegionSize; | 105 | private const uint m_regionWidth = Constants.RegionSize; |
103 | private const uint m_regionHeight = Constants.RegionSize; | 106 | private const uint m_regionHeight = Constants.RegionSize; |
104 | 107 | ||
105 | private static float ODE_STEPSIZE = 0.020f; | 108 | private static float ODE_STEPSIZE = 0.020f; |
106 | private static float metersInSpace = 29.9f; | 109 | private static float metersInSpace = 29.9f; |
107 | 110 | ||
111 | private float waterlevel = 0f; | ||
112 | private int framecount = 0; | ||
108 | private IntPtr contactgroup; | 113 | private IntPtr contactgroup; |
109 | private IntPtr LandGeom = (IntPtr) 0; | 114 | private IntPtr LandGeom = (IntPtr) 0; |
115 | |||
116 | private IntPtr WaterGeom = (IntPtr)0; | ||
117 | |||
110 | private float[] _heightmap; | 118 | private float[] _heightmap; |
119 | |||
120 | private float[] _watermap; | ||
121 | |||
111 | private float[] _origheightmap; | 122 | private float[] _origheightmap; |
112 | 123 | ||
113 | private d.NearCallback nearCallback; | 124 | private d.NearCallback nearCallback; |
@@ -120,13 +131,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
120 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); | 131 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); |
121 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); | 132 | public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); |
122 | private d.ContactGeom[] contacts = new d.ContactGeom[80]; | 133 | private d.ContactGeom[] contacts = new d.ContactGeom[80]; |
134 | |||
123 | private d.Contact contact; | 135 | private d.Contact contact; |
124 | private d.Contact TerrainContact; | 136 | private d.Contact TerrainContact; |
125 | private d.Contact AvatarMovementprimContact; | 137 | private d.Contact AvatarMovementprimContact; |
126 | private d.Contact AvatarMovementTerrainContact; | 138 | private d.Contact AvatarMovementTerrainContact; |
139 | private d.Contact WaterContact; | ||
127 | 140 | ||
128 | |||
129 | 141 | ||
142 | private int m_randomizeWater = 200; | ||
130 | private int m_physicsiterations = 10; | 143 | private int m_physicsiterations = 10; |
131 | private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag | 144 | private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag |
132 | private PhysicsActor PANull = new NullPhysicsActor(); | 145 | private PhysicsActor PANull = new NullPhysicsActor(); |
@@ -176,6 +189,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
176 | TerrainContact.surface.bounce = 0.1f; | 189 | TerrainContact.surface.bounce = 0.1f; |
177 | TerrainContact.surface.soft_erp = 0.1025f; | 190 | TerrainContact.surface.soft_erp = 0.1025f; |
178 | 191 | ||
192 | WaterContact.surface.mode |= (d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM); | ||
193 | WaterContact.surface.mu = 0f; // No friction | ||
194 | WaterContact.surface.bounce = 0.0f; // No bounce | ||
195 | WaterContact.surface.soft_cfm = 0.01f; | ||
196 | WaterContact.surface.soft_erp = 0.010f; | ||
197 | |||
179 | // Prim contact friction and bounce | 198 | // Prim contact friction and bounce |
180 | // THis is the *non* moving version of friction and bounce | 199 | // THis is the *non* moving version of friction and bounce |
181 | // Use this when an avatar comes in contact with a prim | 200 | // Use this when an avatar comes in contact with a prim |
@@ -187,8 +206,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
187 | // Use this when an avatar is in contact with the terrain and moving. | 206 | // Use this when an avatar is in contact with the terrain and moving. |
188 | AvatarMovementTerrainContact.surface.mode |= d.ContactFlags.SoftERP; | 207 | AvatarMovementTerrainContact.surface.mode |= d.ContactFlags.SoftERP; |
189 | AvatarMovementTerrainContact.surface.mu = 75.0f; | 208 | AvatarMovementTerrainContact.surface.mu = 75.0f; |
190 | AvatarMovementTerrainContact.surface.bounce = 0.1f; | 209 | AvatarMovementTerrainContact.surface.bounce = 0.05f; |
191 | AvatarMovementTerrainContact.surface.soft_erp = 0.1025f; | 210 | AvatarMovementTerrainContact.surface.soft_erp = 0.05025f; |
192 | 211 | ||
193 | lock (OdeLock) | 212 | lock (OdeLock) |
194 | { | 213 | { |
@@ -216,7 +235,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
216 | 235 | ||
217 | // zero out a heightmap array float array (single dimention [flattened])) | 236 | // zero out a heightmap array float array (single dimention [flattened])) |
218 | _heightmap = new float[514*514]; | 237 | _heightmap = new float[514*514]; |
219 | 238 | _watermap = new float[258 * 258]; | |
220 | 239 | ||
221 | // Zero out the prim spaces array (we split our space into smaller spaces so | 240 | // Zero out the prim spaces array (we split our space into smaller spaces so |
222 | // we can hit test less. | 241 | // we can hit test less. |
@@ -571,12 +590,36 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
571 | joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); | 590 | joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); |
572 | } | 591 | } |
573 | } | 592 | } |
593 | else if (name1 == "Water" || name2 == "Water") | ||
594 | { | ||
595 | if ((p2.PhysicsActorType == (int)ActorTypes.Prim)) | ||
596 | { | ||
597 | |||
598 | } | ||
599 | else | ||
600 | { | ||
601 | |||
602 | } | ||
603 | WaterContact.surface.soft_cfm = 0.0000f; | ||
604 | WaterContact.surface.soft_erp = 0.00000f; | ||
605 | if (contacts[i].depth > 0.1f) | ||
606 | { | ||
607 | contacts[i].depth *= 52; | ||
608 | //contacts[i].normal = new d.Vector3(0, 0, 1); | ||
609 | //contacts[i].pos = new d.Vector3(0, 0, contacts[i].pos.Z - 5f); | ||
610 | } | ||
611 | WaterContact.geom = contacts[i]; | ||
612 | |||
613 | joint = d.JointCreateContact(world, contactgroup, ref WaterContact); | ||
614 | |||
615 | //m_log.Info("[PHYSICS]: Prim Water Contact" + contacts[i].depth); | ||
616 | } | ||
574 | else | 617 | else |
575 | { | 618 | { |
576 | // we're colliding with prim or avatar | 619 | // we're colliding with prim or avatar |
577 | 620 | ||
578 | // check if we're moving | 621 | // check if we're moving |
579 | if ((p2.PhysicsActorType == (int) ActorTypes.Agent) && | 622 | if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && |
580 | (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) | 623 | (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) |
581 | { | 624 | { |
582 | // Use the Movement prim contact | 625 | // Use the Movement prim contact |
@@ -1279,6 +1322,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1279 | /// <returns></returns> | 1322 | /// <returns></returns> |
1280 | public override float Simulate(float timeStep) | 1323 | public override float Simulate(float timeStep) |
1281 | { | 1324 | { |
1325 | if (framecount >= int.MaxValue) | ||
1326 | framecount = 0; | ||
1327 | |||
1328 | framecount++; | ||
1329 | |||
1282 | float fps = 0; | 1330 | float fps = 0; |
1283 | //m_log.Info(timeStep.ToString()); | 1331 | //m_log.Info(timeStep.ToString()); |
1284 | step_time += timeStep; | 1332 | step_time += timeStep; |
@@ -1369,11 +1417,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1369 | foreach (OdePrim prim in _activeprims) | 1417 | foreach (OdePrim prim in _activeprims) |
1370 | { | 1418 | { |
1371 | prim.m_collisionscore = 0; | 1419 | prim.m_collisionscore = 0; |
1420 | prim.Move(timeStep); | ||
1372 | } | 1421 | } |
1373 | } | 1422 | } |
1374 | 1423 | ||
1375 | 1424 | //if ((framecount % m_randomizeWater) == 0) | |
1376 | 1425 | // randomizeWater(waterlevel); | |
1377 | 1426 | ||
1378 | 1427 | ||
1379 | collision_optimized(timeStep); | 1428 | collision_optimized(timeStep); |
@@ -1772,6 +1821,69 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1772 | { | 1821 | { |
1773 | } | 1822 | } |
1774 | 1823 | ||
1824 | public override void SetWaterLevel(float baseheight) | ||
1825 | { | ||
1826 | waterlevel = baseheight; | ||
1827 | randomizeWater(waterlevel); | ||
1828 | } | ||
1829 | |||
1830 | public void randomizeWater(float baseheight) | ||
1831 | { | ||
1832 | const uint heightmapWidth = m_regionWidth + 2; | ||
1833 | const uint heightmapHeight = m_regionHeight + 2; | ||
1834 | const uint heightmapWidthSamples = m_regionWidth + 2; | ||
1835 | const uint heightmapHeightSamples = m_regionHeight + 2; | ||
1836 | const float scale = 1.0f; | ||
1837 | const float offset = 0.0f; | ||
1838 | const float thickness = 2.9f; | ||
1839 | const int wrap = 0; | ||
1840 | |||
1841 | for (int i = 0; i < (258 * 258); i++) | ||
1842 | { | ||
1843 | _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f); | ||
1844 | // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f)); | ||
1845 | } | ||
1846 | |||
1847 | |||
1848 | lock (OdeLock) | ||
1849 | { | ||
1850 | if (!(WaterGeom == (IntPtr)0)) | ||
1851 | { | ||
1852 | d.SpaceRemove(space, WaterGeom); | ||
1853 | } | ||
1854 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | ||
1855 | d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight, | ||
1856 | (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale, | ||
1857 | offset, thickness, wrap); | ||
1858 | d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); | ||
1859 | WaterGeom = d.CreateHeightfield(space, HeightmapData, 1); | ||
1860 | if (WaterGeom != (IntPtr)0) | ||
1861 | { | ||
1862 | d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water)); | ||
1863 | d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space)); | ||
1864 | |||
1865 | } | ||
1866 | geom_name_map[WaterGeom] = "Water"; | ||
1867 | |||
1868 | d.Matrix3 R = new d.Matrix3(); | ||
1869 | |||
1870 | Quaternion q1 = Quaternion.FromAngleAxis(1.5707f, new Vector3(1, 0, 0)); | ||
1871 | Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0)); | ||
1872 | //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); | ||
1873 | |||
1874 | q1 = q1 * q2; | ||
1875 | //q1 = q1 * q3; | ||
1876 | Vector3 v3 = new Vector3(); | ||
1877 | float angle = 0; | ||
1878 | q1.ToAngleAxis(ref angle, ref v3); | ||
1879 | |||
1880 | d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle); | ||
1881 | d.GeomSetRotation(WaterGeom, ref R); | ||
1882 | d.GeomSetPosition(WaterGeom, 128, 128, 0); | ||
1883 | } | ||
1884 | |||
1885 | } | ||
1886 | |||
1775 | public override void Dispose() | 1887 | public override void Dispose() |
1776 | { | 1888 | { |
1777 | lock (OdeLock) | 1889 | lock (OdeLock) |