clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using Nini.Config;
31 using OpenMetaverse;
32 using OpenSim.Framework;
33 using OpenSim.Region.Physics.Manager;
34  
35 namespace OpenSim.Region.Physics.BasicPhysicsPlugin
36 {
37 /// <summary>
38 /// This is an incomplete extremely basic physics implementation
39 /// </summary>
40 /// <remarks>
41 /// Not useful for anything at the moment apart from some regression testing in other components where some form
42 /// of physics plugin is needed.
43 /// </remarks>
44 public class BasicScene : PhysicsScene
45 {
46 private List<BasicActor> _actors = new List<BasicActor>();
47 private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>();
48 private float[] _heightMap;
49 private Vector3 m_regionExtent;
50  
51 //protected internal string sceneIdentifier;
52  
53 public BasicScene(string engineType, string _sceneIdentifier)
54 {
55 EngineType = engineType;
56 Name = EngineType + "/" + _sceneIdentifier;
57 //sceneIdentifier = _sceneIdentifier;
58 }
59  
60 public override void Initialise(IMesher meshmerizer, IConfigSource config)
61 {
62 throw new Exception("Should not be called.");
63 }
64  
65 public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent)
66 {
67 m_regionExtent = regionExtent;
68 }
69  
70 public override void Dispose() {}
71  
72 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
73 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
74 {
75 BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs);
76 prim.IsPhysical = isPhysical;
77  
78 _prims.Add(prim);
79  
80 return prim;
81 }
82  
83 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
84 {
85 BasicActor act = new BasicActor(size);
86 act.Position = position;
87 act.Flying = isFlying;
88 _actors.Add(act);
89 return act;
90 }
91  
92 public override void RemovePrim(PhysicsActor actor)
93 {
94 BasicPhysicsPrim prim = (BasicPhysicsPrim)actor;
95 if (_prims.Contains(prim))
96 _prims.Remove(prim);
97 }
98  
99 public override void RemoveAvatar(PhysicsActor actor)
100 {
101 BasicActor act = (BasicActor)actor;
102 if (_actors.Contains(act))
103 _actors.Remove(act);
104 }
105  
106 public override void AddPhysicsActorTaint(PhysicsActor prim)
107 {
108 }
109  
110 public override float Simulate(float timeStep)
111 {
112 // Console.WriteLine("Simulating");
113  
114 float fps = 0;
115 for (int i = 0; i < _actors.Count; ++i)
116 {
117 BasicActor actor = _actors[i];
118 Vector3 actorPosition = actor.Position;
119 Vector3 actorVelocity = actor.Velocity;
120  
121 // Console.WriteLine(
122 // "Processing actor {0}, starting pos {1}, starting vel {2}", i, actorPosition, actorVelocity);
123  
124 actorPosition.X += actor.Velocity.X * timeStep;
125 actorPosition.Y += actor.Velocity.Y * timeStep;
126  
127 if (actor.Position.Y < 0)
128 {
129 actorPosition.Y = 0.1F;
130 }
131 else if (actor.Position.Y >= m_regionExtent.Y)
132 {
133 actorPosition.Y = (m_regionExtent.Y - 0.1f);
134 }
135  
136 if (actor.Position.X < 0)
137 {
138 actorPosition.X = 0.1F;
139 }
140 else if (actor.Position.X >= m_regionExtent.X)
141 {
142 actorPosition.X = (m_regionExtent.X - 0.1f);
143 }
144  
145 float terrainHeight = 0;
146 if (_heightMap != null)
147 terrainHeight = _heightMap[(int)actor.Position.Y * (int)m_regionExtent.Y + (int)actor.Position.X];
148  
149 float height = terrainHeight + actor.Size.Z;
150 // Console.WriteLine("height {0}, actorPosition {1}", height, actorPosition);
151  
152 if (actor.Flying)
153 {
154 if (actor.Position.Z + (actor.Velocity.Z * timeStep) < terrainHeight + 2)
155 {
156 actorPosition.Z = height;
157 actorVelocity.Z = 0;
158 actor.IsColliding = true;
159 }
160 else
161 {
162 actorPosition.Z += actor.Velocity.Z * timeStep;
163 actor.IsColliding = false;
164 }
165 }
166 else
167 {
168 actorPosition.Z = height;
169 actorVelocity.Z = 0;
170 actor.IsColliding = true;
171 }
172  
173 actor.Position = actorPosition;
174 actor.Velocity = actorVelocity;
175 }
176  
177 return fps;
178 }
179  
180 public override void GetResults()
181 {
182 }
183  
184 public override bool IsThreaded
185 {
186 get { return (false); // for now we won't be multithreaded
187 }
188 }
189  
190 public override void SetTerrain(float[] heightMap)
191 {
192 _heightMap = heightMap;
193 }
194  
195 public override void DeleteTerrain()
196 {
197 }
198  
199 public override void SetWaterLevel(float baseheight)
200 {
201 }
202  
203 public override Dictionary<uint, float> GetTopColliders()
204 {
205 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
206 return returncolliders;
207 }
208 }
209 }