aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/physics/plugins/PhysXplugin.cs
diff options
context:
space:
mode:
authorgareth2007-03-07 19:07:00 +0000
committergareth2007-03-07 19:07:00 +0000
commit2159b3079ec8df2a7337a9d4ea54810b7028c4e1 (patch)
tree5473123011f7a302e63f89ec6ccb4477032fd1db /src/physics/plugins/PhysXplugin.cs
parentImported branch (diff)
downloadopensim-SC-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.zip
opensim-SC-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.gz
opensim-SC-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.bz2
opensim-SC-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.xz
fixed last screwup
Diffstat (limited to 'src/physics/plugins/PhysXplugin.cs')
-rw-r--r--src/physics/plugins/PhysXplugin.cs199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/physics/plugins/PhysXplugin.cs b/src/physics/plugins/PhysXplugin.cs
new file mode 100644
index 0000000..58a82fb
--- /dev/null
+++ b/src/physics/plugins/PhysXplugin.cs
@@ -0,0 +1,199 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27using System;
28using System.Collections.Generic;
29using PhysicsSystem;
30
31namespace PhysXplugin
32{
33 /// <summary>
34 /// Will be the PhysX plugin but for now will be a very basic physics engine
35 /// </summary>
36 public class PhysXPlugin : IPhysicsPlugin
37 {
38 private PhysXScene _mScene;
39
40 public PhysXPlugin()
41 {
42
43 }
44
45 public bool Init()
46 {
47 return true;
48 }
49
50 public PhysicsScene GetScene()
51 {
52 if(_mScene == null)
53 {
54 _mScene = new PhysXScene();
55 }
56 return(_mScene);
57 }
58
59 public string GetName()
60 {
61 return("PhysX");
62 }
63
64 public void Dispose()
65 {
66
67 }
68 }
69
70 public class PhysXScene :PhysicsScene
71 {
72 private List<PhysXActor> _actors = new List<PhysXActor>();
73 private float[] _heightMap;
74
75 public PhysXScene()
76 {
77
78 }
79
80 public override PhysicsActor AddAvatar(PhysicsVector position)
81 {
82 PhysXActor act = new PhysXActor();
83 act.Position = position;
84 _actors.Add(act);
85 return act;
86 }
87
88 public override void Simulate(float timeStep)
89 {
90 foreach (PhysXActor actor in _actors)
91 {
92 actor.Position.X = actor.Position.X + actor.Velocity.X * timeStep;
93 actor.Position.Y = actor.Position.Y + actor.Velocity.Y * timeStep;
94 actor.Position.Z = actor.Position.Z + actor.Velocity.Z * timeStep;
95 actor.Position.Z = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1;
96 if(actor.Position.X<0)
97 {
98 actor.Position.X = 0;
99 actor.Velocity.X = 0;
100 }
101 if(actor.Position.Y < 0)
102 {
103 actor.Position.Y = 0;
104 actor.Velocity.Y = 0;
105 }
106 if(actor.Position.X > 255)
107 {
108 actor.Position.X = 255;
109 actor.Velocity.X = 0;
110 }
111 if(actor.Position.Y > 255)
112 {
113 actor.Position.Y = 255;
114 actor.Velocity.X = 0;
115 }
116 }
117 }
118
119 public override void GetResults()
120 {
121
122 }
123
124 public override bool IsThreaded
125 {
126 get
127 {
128 return(false); // for now we won't be multithreaded
129 }
130 }
131
132 public override void SetTerrain(float[] heightMap)
133 {
134 this._heightMap = heightMap;
135 }
136 }
137
138 public class PhysXActor : PhysicsActor
139 {
140 private PhysicsVector _position;
141 private PhysicsVector _velocity;
142 private PhysicsVector _acceleration;
143
144 public PhysXActor()
145 {
146 _velocity = new PhysicsVector();
147 _position = new PhysicsVector();
148 _acceleration = new PhysicsVector();
149 }
150
151 public override PhysicsVector Position
152 {
153 get
154 {
155 return _position;
156 }
157 set
158 {
159 _position = value;
160 }
161 }
162
163 public override PhysicsVector Velocity
164 {
165 get
166 {
167 return _velocity;
168 }
169 set
170 {
171 _velocity = value;
172 }
173 }
174
175 public override PhysicsVector Acceleration
176 {
177 get
178 {
179 return _acceleration;
180 }
181
182 }
183 public void SetAcceleration (PhysicsVector accel)
184 {
185 this._acceleration = accel;
186 }
187
188 public override void AddForce(PhysicsVector force)
189 {
190
191 }
192
193 public override void SetMomentum(PhysicsVector momentum)
194 {
195
196 }
197 }
198
199}