aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Physics/OdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
authorgareth2007-03-27 02:42:06 +0000
committergareth2007-03-27 02:42:06 +0000
commit8b8f62f0191c31a045913edec702ca23fab5f6d6 (patch)
tree2b1a1e73c5e15403f28a812a0d4435e0d4422e33 /OpenSim.Physics/OdePlugin/OdePlugin.cs
parentMovement? (diff)
downloadopensim-SC-8b8f62f0191c31a045913edec702ca23fab5f6d6.zip
opensim-SC-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.gz
opensim-SC-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.bz2
opensim-SC-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.xz
ODE plugin now can fly but sinks through ground when walking (?!!!??!??!)
Diffstat (limited to '')
-rw-r--r--OpenSim.Physics/OdePlugin/OdePlugin.cs70
1 files changed, 50 insertions, 20 deletions
diff --git a/OpenSim.Physics/OdePlugin/OdePlugin.cs b/OpenSim.Physics/OdePlugin/OdePlugin.cs
index 352084c..01eaf77 100644
--- a/OpenSim.Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim.Physics/OdePlugin/OdePlugin.cs
@@ -70,31 +70,54 @@ namespace OpenSim.Physics.OdePlugin
70 70
71 public class OdeScene :PhysicsScene 71 public class OdeScene :PhysicsScene
72 { 72 {
73 public IntPtr world; 73 static public IntPtr world;
74 public IntPtr space; 74 static public IntPtr space;
75 private IntPtr contactgroup; 75 static private IntPtr contactgroup;
76 static private IntPtr LandGeom;
77 static private IntPtr Land;
76 private double[] _heightmap; 78 private double[] _heightmap;
79 static private d.NearCallback nearCallback = near;
80 private List<OdeCharacter> _characters = new List<OdeCharacter>();
81 private static d.ContactGeom[] contacts = new d.ContactGeom[500];
82 private static d.Contact contact;
77 83
78 public OdeScene() 84 public OdeScene() {
79 {
80 world = d.WorldCreate(); 85 world = d.WorldCreate();
81 space = d.HashSpaceCreate(IntPtr.Zero); 86 space = d.HashSpaceCreate(IntPtr.Zero);
82 contactgroup = d.JointGroupCreate(0); 87 contactgroup = d.JointGroupCreate(0);
83 d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f); 88 d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f);
84 d.WorldSetCFM(world, 1e-5f); 89 d.WorldSetCFM(world, 1e-5f);
85 d.WorldSetAutoDisableFlag(world, true); 90 d.WorldSetAutoDisableFlag(world, false);
86 d.WorldSetContactMaxCorrectingVel(world, 0.1f);
87 d.WorldSetContactSurfaceLayer(world, 0.001f);
88 this._heightmap=new double[65536]; 91 this._heightmap=new double[65536];
89 } 92 }
90 93
94 // This function blatantly ripped off from BoxStack.cs
95 static private void near(IntPtr space, IntPtr g1, IntPtr g2)
96 {
97 IntPtr b1 = d.GeomGetBody(g1);
98 IntPtr b2 = d.GeomGetBody(g2);
99 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
100 return;
101
102 int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf);
103 for (int i = 0; i < count; ++i)
104 {
105 contact.geom = contacts[i];
106 IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
107 d.JointAttach(joint, b1, b2);
108 }
109
110 }
111
91 public override PhysicsActor AddAvatar(PhysicsVector position) 112 public override PhysicsActor AddAvatar(PhysicsVector position)
92 { 113 {
93 PhysicsVector pos = new PhysicsVector(); 114 PhysicsVector pos = new PhysicsVector();
94 pos.X = position.X; 115 pos.X = position.X;
95 pos.Y = position.Y; 116 pos.Y = position.Y;
96 pos.Z = position.Z; 117 pos.Z = position.Z;
97 return new OdeCharacter(this,pos); 118 OdeCharacter newAv= new OdeCharacter(this,pos);
119 this._characters.Add(newAv);
120 return newAv;
98 } 121 }
99 122
100 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) 123 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
@@ -112,7 +135,16 @@ namespace OpenSim.Physics.OdePlugin
112 135
113 public override void Simulate(float timeStep) 136 public override void Simulate(float timeStep)
114 { 137 {
115 138 foreach (OdeCharacter actor in _characters) {
139 actor.Move(timeStep*5f);
140 }
141 d.SpaceCollide(space, IntPtr.Zero, nearCallback);
142 d.WorldQuickStep(world, timeStep*5f);
143 foreach (OdeCharacter actor in _characters)
144 {
145 actor.UpdatePosition();
146 }
147
116 } 148 }
117 149
118 public override void GetResults() 150 public override void GetResults()
@@ -135,7 +167,8 @@ namespace OpenSim.Physics.OdePlugin
135 } 167 }
136 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 168 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
137 d.GeomHeightfieldDataBuildDouble(HeightmapData,_heightmap,1,256,256,256,256,1.0f,0.0f,2.0f,0); 169 d.GeomHeightfieldDataBuildDouble(HeightmapData,_heightmap,1,256,256,256,256,1.0f,0.0f,2.0f,0);
138 d.CreateHeightfield(space, HeightmapData, 0); 170 LandGeom=d.CreateHeightfield(space, HeightmapData, 1);
171 d.GeomSetPosition(LandGeom,0,0,0);
139 } 172 }
140 } 173 }
141 174
@@ -156,7 +189,10 @@ namespace OpenSim.Physics.OdePlugin
156 _position = pos; 189 _position = pos;
157 _acceleration = new PhysicsVector(); 190 _acceleration = new PhysicsVector();
158 d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f); 191 d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f);
159 capsule_geom = d.CreateCapsule(parent_scene.space, 0.5f, 2f); 192 capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f);
193 this.BoundingCapsule=d.BodyCreate(OdeScene.world);
194 d.BodySetMass(BoundingCapsule, ref capsule_mass);
195 d.BodySetPosition(BoundingCapsule,pos.X,pos.Y,pos.Z);
160 } 196 }
161 197
162 public override bool Flying 198 public override bool Flying
@@ -249,12 +285,7 @@ namespace OpenSim.Physics.OdePlugin
249 vec.Y = this._velocity.Y * timeStep; 285 vec.Y = this._velocity.Y * timeStep;
250 if(flying) 286 if(flying)
251 { 287 {
252 vec.Z = ( this._velocity.Z) * timeStep; 288 vec.Z = ( this._velocity.Z+0.5f) * timeStep;
253 }
254 else
255 {
256 gravityAccel+= -9.8f;
257 vec.Z = (gravityAccel + this._velocity.Z) * timeStep;
258 } 289 }
259 d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z); 290 d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z);
260 } 291 }
@@ -265,7 +296,6 @@ namespace OpenSim.Physics.OdePlugin
265 this._position.X = vec.X; 296 this._position.X = vec.X;
266 this._position.Y = vec.Y; 297 this._position.Y = vec.Y;
267 this._position.Z = vec.Z; 298 this._position.Z = vec.Z;
268
269 } 299 }
270 } 300 }
271 301
@@ -297,7 +327,7 @@ namespace OpenSim.Physics.OdePlugin
297 get 327 get
298 { 328 {
299 PhysicsVector pos = new PhysicsVector(); 329 PhysicsVector pos = new PhysicsVector();
300 //PhysicsVector vec = this._prim.Position; 330 // PhysicsVector vec = this._prim.Position;
301 //pos.X = vec.X; 331 //pos.X = vec.X;
302 //pos.Y = vec.Y; 332 //pos.Y = vec.Y;
303 //pos.Z = vec.Z; 333 //pos.Z = vec.Z;