aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ConvertToPlugins/src/physics/plugins/PhysXplugin.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ConvertToPlugins/src/physics/plugins/PhysXplugin.cs199
-rw-r--r--ConvertToPlugins/src/physics/plugins/PhysXplugin.csproj41
2 files changed, 240 insertions, 0 deletions
diff --git a/ConvertToPlugins/src/physics/plugins/PhysXplugin.cs b/ConvertToPlugins/src/physics/plugins/PhysXplugin.cs
new file mode 100644
index 0000000..58a82fb
--- /dev/null
+++ b/ConvertToPlugins/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}
diff --git a/ConvertToPlugins/src/physics/plugins/PhysXplugin.csproj b/ConvertToPlugins/src/physics/plugins/PhysXplugin.csproj
new file mode 100644
index 0000000..1b84046
--- /dev/null
+++ b/ConvertToPlugins/src/physics/plugins/PhysXplugin.csproj
@@ -0,0 +1,41 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <OutputType>Library</OutputType>
4 <RootNamespace>PhysXplugin</RootNamespace>
5 <AssemblyName>PhysXplugin</AssemblyName>
6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8 <ProjectGuid>{ADB751AA-8426-4668-B1FA-43762126CEB3}</ProjectGuid>
9 </PropertyGroup>
10 <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
11 <OutputPath>bin\Debug\</OutputPath>
12 <Optimize>False</Optimize>
13 <DefineConstants>DEBUG;TRACE</DefineConstants>
14 <DebugSymbols>True</DebugSymbols>
15 <DebugType>Full</DebugType>
16 <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
17 </PropertyGroup>
18 <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
19 <OutputPath>bin\Release\</OutputPath>
20 <Optimize>True</Optimize>
21 <DefineConstants>TRACE</DefineConstants>
22 <DebugSymbols>False</DebugSymbols>
23 <DebugType>None</DebugType>
24 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
25 </PropertyGroup>
26 <ItemGroup>
27 <Reference Include="System" />
28 <Reference Include="System.Xml" />
29 </ItemGroup>
30 <ItemGroup>
31 <Compile Include="PhysXplugin.cs" />
32 <Compile Include="AssemblyInfo.cs" />
33 </ItemGroup>
34 <ItemGroup>
35 <ProjectReference Include="..\PhysicsManager.csproj">
36 <Project>{3C86A846-7977-4EE7-A8DC-DD487FA5DC2B}</Project>
37 <Name>PhysicsManager</Name>
38 </ProjectReference>
39 </ItemGroup>
40 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
41</Project> \ No newline at end of file