aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-03-10 05:23:43 +0000
committerTeravus Ovares2008-03-10 05:23:43 +0000
commit8bea3dbdb91dfb465338572e3dfb40a5adfb9bab (patch)
treed941528dbb7e5faba74037dfbc03a2edacede342 /OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
parent* Fixed a few things and enabling Physical Prim border crossings again. (diff)
downloadopensim-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/OdePlugin.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs128
1 files changed, 120 insertions, 8 deletions
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)