aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Physics/OdePlugin
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
parentMovement? (diff)
downloadopensim-SC_OLD-8b8f62f0191c31a045913edec702ca23fab5f6d6.zip
opensim-SC_OLD-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.gz
opensim-SC_OLD-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.bz2
opensim-SC_OLD-8b8f62f0191c31a045913edec702ca23fab5f6d6.tar.xz
ODE plugin now can fly but sinks through ground when walking (?!!!??!??!)
Diffstat (limited to 'OpenSim.Physics/OdePlugin')
-rw-r--r--OpenSim.Physics/OdePlugin/OdePlugin.cs70
-rw-r--r--OpenSim.Physics/OdePlugin/OpenSim.Physics.OdePlugin.dll.build86
2 files changed, 93 insertions, 63 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;
diff --git a/OpenSim.Physics/OdePlugin/OpenSim.Physics.OdePlugin.dll.build b/OpenSim.Physics/OdePlugin/OpenSim.Physics.OdePlugin.dll.build
index c67d820..e738ab1 100644
--- a/OpenSim.Physics/OdePlugin/OpenSim.Physics.OdePlugin.dll.build
+++ b/OpenSim.Physics/OdePlugin/OpenSim.Physics.OdePlugin.dll.build
@@ -1,43 +1,43 @@
1<?xml version="1.0" ?> 1<?xml version="1.0" ?>
2<project name="OpenSim.Physics.OdePlugin" default="build"> 2<project name="OpenSim.Physics.OdePlugin" default="build">
3 <target name="build"> 3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" /> 4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" /> 5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}"> 6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}"> 7 <fileset basedir="${project::get-base-directory()}">
8 </fileset> 8 </fileset>
9 </copy> 9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll"> 10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Physics.OdePlugin" dynamicprefix="true" > 11 <resources prefix="OpenSim.Physics.OdePlugin" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AssemblyInfo.cs" /> 14 <include name="AssemblyInfo.cs" />
15 <include name="OdePlugin.cs" /> 15 <include name="OdePlugin.cs" />
16 </sources> 16 </sources>
17 <references basedir="${project::get-base-directory()}"> 17 <references basedir="${project::get-base-directory()}">
18 <lib> 18 <lib>
19 <include name="${project::get-base-directory()}" /> 19 <include name="${project::get-base-directory()}" />
20 <include name="${project::get-base-directory()}/${build.dir}" /> 20 <include name="${project::get-base-directory()}/${build.dir}" />
21 </lib> 21 </lib>
22 <include name="System.dll" /> 22 <include name="System.dll" />
23 <include name="../../bin/Axiom.MathLib.dll" /> 23 <include name="../../bin/Axiom.MathLib.dll" />
24 <include name="../Manager/${build.dir}/OpenSim.Physics.Manager.dll" /> 24 <include name="../Manager/${build.dir}/OpenSim.Physics.Manager.dll" />
25 <include name="../../bin/../lib/Ode.NET.dll" /> 25 <include name="../../bin/../lib/Ode.NET.dll" />
26 </references> 26 </references>
27 </csc> 27 </csc>
28 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../bin/Physics/" /> 28 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../bin/Physics/" />
29 <mkdir dir="${project::get-base-directory()}/../../bin/Physics/"/> 29 <mkdir dir="${project::get-base-directory()}/../../bin/Physics/"/>
30 <copy todir="${project::get-base-directory()}/../../bin/Physics/"> 30 <copy todir="${project::get-base-directory()}/../../bin/Physics/">
31 <fileset basedir="${project::get-base-directory()}/${build.dir}/" > 31 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
32 <include name="*.dll"/> 32 <include name="*.dll"/>
33 <include name="*.exe"/> 33 <include name="*.exe"/>
34 </fileset> 34 </fileset>
35 </copy> 35 </copy>
36 </target> 36 </target>
37 <target name="clean"> 37 <target name="clean">
38 <delete dir="${bin.dir}" failonerror="false" /> 38 <delete dir="${bin.dir}" failonerror="false" />
39 <delete dir="${obj.dir}" failonerror="false" /> 39 <delete dir="${obj.dir}" failonerror="false" />
40 </target> 40 </target>
41 <target name="doc" description="Creates documentation."> 41 <target name="doc" description="Creates documentation.">
42 </target> 42 </target>
43</project> 43</project>