opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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  
50 //protected internal string sceneIdentifier;
51  
52 public BasicScene(string engineType, string _sceneIdentifier)
53 {
54 EngineType = engineType;
55 Name = EngineType + "/" + _sceneIdentifier;
56 //sceneIdentifier = _sceneIdentifier;
57 }
58  
59 public override void Initialise(IMesher meshmerizer, IConfigSource config)
60 {
61 }
62  
63 public override void Dispose() {}
64  
65 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
66 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
67 {
68 BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs);
69 prim.IsPhysical = isPhysical;
70  
71 _prims.Add(prim);
72  
73 return prim;
74 }
75  
76 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
77 {
78 BasicActor act = new BasicActor(size);
79 act.Position = position;
80 act.Flying = isFlying;
81 _actors.Add(act);
82 return act;
83 }
84  
85 public override void RemovePrim(PhysicsActor actor)
86 {
87 BasicPhysicsPrim prim = (BasicPhysicsPrim)actor;
88 if (_prims.Contains(prim))
89 _prims.Remove(prim);
90 }
91  
92 public override void RemoveAvatar(PhysicsActor actor)
93 {
94 BasicActor act = (BasicActor)actor;
95 if (_actors.Contains(act))
96 _actors.Remove(act);
97 }
98  
99 public override void AddPhysicsActorTaint(PhysicsActor prim)
100 {
101 }
102  
103 public override float Simulate(float timeStep)
104 {
105 // Console.WriteLine("Simulating");
106  
107 float fps = 0;
108 for (int i = 0; i < _actors.Count; ++i)
109 {
110 BasicActor actor = _actors[i];
111 Vector3 actorPosition = actor.Position;
112 Vector3 actorVelocity = actor.Velocity;
113  
114 // Console.WriteLine(
115 // "Processing actor {0}, starting pos {1}, starting vel {2}", i, actorPosition, actorVelocity);
116  
117 actorPosition.X += actor.Velocity.X * timeStep;
118 actorPosition.Y += actor.Velocity.Y * timeStep;
119  
120 if (actor.Position.Y < 0)
121 {
122 actorPosition.Y = 0.1F;
123 }
124 else if (actor.Position.Y >= Constants.RegionSize)
125 {
126 actorPosition.Y = ((int)Constants.RegionSize - 0.1f);
127 }
128  
129 if (actor.Position.X < 0)
130 {
131 actorPosition.X = 0.1F;
132 }
133 else if (actor.Position.X >= Constants.RegionSize)
134 {
135 actorPosition.X = ((int)Constants.RegionSize - 0.1f);
136 }
137  
138 float terrainHeight = 0;
139 if (_heightMap != null)
140 terrainHeight = _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X];
141  
142 float height = terrainHeight + actor.Size.Z;
143  
144 if (actor.Flying)
145 {
146 if (actor.Position.Z + (actor.Velocity.Z * timeStep) < terrainHeight + 2)
147 {
148 actorPosition.Z = height;
149 actorVelocity.Z = 0;
150 actor.IsColliding = true;
151 }
152 else
153 {
154 actorPosition.Z += actor.Velocity.Z * timeStep;
155 actor.IsColliding = false;
156 }
157 }
158 else
159 {
160 actorPosition.Z = height;
161 actorVelocity.Z = 0;
162 actor.IsColliding = true;
163 }
164  
165 actor.Position = actorPosition;
166 actor.Velocity = actorVelocity;
167 }
168  
169 return fps;
170 }
171  
172 public override void GetResults()
173 {
174 }
175  
176 public override bool IsThreaded
177 {
178 get { return (false); // for now we won't be multithreaded
179 }
180 }
181  
182 public override void SetTerrain(float[] heightMap)
183 {
184 _heightMap = heightMap;
185 }
186  
187 public override void DeleteTerrain()
188 {
189 }
190  
191 public override void SetWaterLevel(float baseheight)
192 {
193 }
194  
195 public override Dictionary<uint, float> GetTopColliders()
196 {
197 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
198 return returncolliders;
199 }
200 }
201 }