diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 248 |
1 files changed, 0 insertions, 248 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs deleted file mode 100755 index 7127aaf..0000000 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ /dev/null | |||
@@ -1,248 +0,0 @@ | |||
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 copyrightD | ||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | using OMV = OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
36 | { | ||
37 | // Class to wrap all objects. | ||
38 | // The rest of BulletSim doesn't need to keep checking for avatars or prims | ||
39 | // unless the difference is significant. | ||
40 | public abstract class BSPhysObject : PhysicsActor | ||
41 | { | ||
42 | protected void BaseInitialize(BSScene parentScene, uint localID, string name, string typeName) | ||
43 | { | ||
44 | PhysicsScene = parentScene; | ||
45 | LocalID = localID; | ||
46 | PhysObjectName = name; | ||
47 | TypeName = typeName; | ||
48 | |||
49 | Linkset = BSLinkset.Factory(PhysicsScene, this); | ||
50 | LastAssetBuildFailed = false; | ||
51 | |||
52 | CollisionCollection = new CollisionEventUpdate(); | ||
53 | SubscribedEventsMs = 0; | ||
54 | CollidingStep = 0; | ||
55 | CollidingGroundStep = 0; | ||
56 | } | ||
57 | |||
58 | public BSScene PhysicsScene { get; protected set; } | ||
59 | // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor | ||
60 | public string PhysObjectName { get; protected set; } | ||
61 | public string TypeName { get; protected set; } | ||
62 | |||
63 | public BSLinkset Linkset { get; set; } | ||
64 | |||
65 | // Return the object mass without calculating it or having side effects | ||
66 | public abstract float RawMass { get; } | ||
67 | // Set the raw mass but also update physical mass properties (inertia, ...) | ||
68 | public abstract void UpdatePhysicalMassProperties(float mass); | ||
69 | |||
70 | // Reference to the physical body (btCollisionObject) of this object | ||
71 | public BulletBody PhysBody; | ||
72 | // Reference to the physical shape (btCollisionShape) of this object | ||
73 | public BulletShape PhysShape; | ||
74 | |||
75 | // 'true' if the mesh's underlying asset failed to build. | ||
76 | // This will keep us from looping after the first time the build failed. | ||
77 | public bool LastAssetBuildFailed { get; set; } | ||
78 | |||
79 | // The objects base shape information. Null if not a prim type shape. | ||
80 | public PrimitiveBaseShape BaseShape { get; protected set; } | ||
81 | // Some types of objects have preferred physical representations. | ||
82 | // Returns SHAPE_UNKNOWN if there is no preference. | ||
83 | public virtual ShapeData.PhysicsShapeType PreferredPhysicalShape | ||
84 | { | ||
85 | get { return ShapeData.PhysicsShapeType.SHAPE_UNKNOWN; } | ||
86 | } | ||
87 | |||
88 | // When the physical properties are updated, an EntityProperty holds the update values. | ||
89 | // Keep the current and last EntityProperties to enable computation of differences | ||
90 | // between the current update and the previous values. | ||
91 | public EntityProperties CurrentEntityProperties { get; set; } | ||
92 | public EntityProperties LastEntityProperties { get; set; } | ||
93 | |||
94 | public abstract OMV.Vector3 Scale { get; set; } | ||
95 | public abstract bool IsSolid { get; } | ||
96 | public abstract bool IsStatic { get; } | ||
97 | |||
98 | // Stop all physical motion. | ||
99 | public abstract void ZeroMotion(); | ||
100 | |||
101 | // Step the vehicle simulation for this object. A NOOP if the vehicle was not configured. | ||
102 | public virtual void StepVehicle(float timeStep) { } | ||
103 | |||
104 | // Update the physical location and motion of the object. Called with data from Bullet. | ||
105 | public abstract void UpdateProperties(EntityProperties entprop); | ||
106 | |||
107 | // Tell the object to clean up. | ||
108 | public abstract void Destroy(); | ||
109 | |||
110 | public abstract OMV.Vector3 RawPosition { get; set; } | ||
111 | public abstract OMV.Vector3 ForcePosition { get; set; } | ||
112 | |||
113 | public abstract OMV.Quaternion RawOrientation { get; set; } | ||
114 | public abstract OMV.Quaternion ForceOrientation { get; set; } | ||
115 | |||
116 | public abstract OMV.Vector3 ForceVelocity { get; set; } | ||
117 | |||
118 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } | ||
119 | |||
120 | public abstract float ForceBuoyancy { get; set; } | ||
121 | |||
122 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | ||
123 | |||
124 | #region Collisions | ||
125 | |||
126 | // Requested number of milliseconds between collision events. Zero means disabled. | ||
127 | protected int SubscribedEventsMs { get; set; } | ||
128 | // Given subscription, the time that a collision may be passed up | ||
129 | protected int NextCollisionOkTime { get; set; } | ||
130 | // The simulation step that last had a collision | ||
131 | protected long CollidingStep { get; set; } | ||
132 | // The simulation step that last had a collision with the ground | ||
133 | protected long CollidingGroundStep { get; set; } | ||
134 | // The collision flags we think are set in Bullet | ||
135 | protected CollisionFlags CurrentCollisionFlags { get; set; } | ||
136 | |||
137 | // The collisions that have been collected this tick | ||
138 | protected CollisionEventUpdate CollisionCollection; | ||
139 | |||
140 | // The simulation step is telling this object about a collision. | ||
141 | // Return 'true' if a collision was processed and should be sent up. | ||
142 | // Called at taint time from within the Step() function | ||
143 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, | ||
144 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | ||
145 | { | ||
146 | bool ret = false; | ||
147 | |||
148 | // The following lines make IsColliding() and IsCollidingGround() work | ||
149 | CollidingStep = PhysicsScene.SimulationStep; | ||
150 | if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) | ||
151 | { | ||
152 | CollidingGroundStep = PhysicsScene.SimulationStep; | ||
153 | } | ||
154 | |||
155 | // prims in the same linkset cannot collide with each other | ||
156 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) | ||
157 | { | ||
158 | return ret; | ||
159 | } | ||
160 | |||
161 | // if someone has subscribed for collision events.... | ||
162 | if (SubscribedEvents()) { | ||
163 | CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | ||
164 | DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", | ||
165 | LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth); | ||
166 | |||
167 | ret = true; | ||
168 | } | ||
169 | return ret; | ||
170 | } | ||
171 | |||
172 | // Send the collected collisions into the simulator. | ||
173 | // Called at taint time from within the Step() function thus no locking problems | ||
174 | // with CollisionCollection and ObjectsWithNoMoreCollisions. | ||
175 | // Return 'true' if there were some actual collisions passed up | ||
176 | public virtual bool SendCollisions() | ||
177 | { | ||
178 | bool ret = true; | ||
179 | // If the 'no collision' call, force it to happen right now so quick collision_end | ||
180 | bool force = CollisionCollection.Count == 0; | ||
181 | |||
182 | // throttle the collisions to the number of milliseconds specified in the subscription | ||
183 | if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) | ||
184 | { | ||
185 | NextCollisionOkTime = PhysicsScene.SimulationNowTime + SubscribedEventsMs; | ||
186 | |||
187 | // We are called if we previously had collisions. If there are no collisions | ||
188 | // this time, send up one last empty event so OpenSim can sense collision end. | ||
189 | if (CollisionCollection.Count == 0) | ||
190 | { | ||
191 | // If I have no collisions this time, remove me from the list of objects with collisions. | ||
192 | ret = false; | ||
193 | } | ||
194 | |||
195 | // DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); | ||
196 | base.SendCollisionUpdate(CollisionCollection); | ||
197 | |||
198 | // The collisionCollection structure is passed around in the simulator. | ||
199 | // Make sure we don't have a handle to that one and that a new one is used for next time. | ||
200 | CollisionCollection = new CollisionEventUpdate(); | ||
201 | } | ||
202 | return ret; | ||
203 | } | ||
204 | |||
205 | // Subscribe for collision events. | ||
206 | // Parameter is the millisecond rate the caller wishes collision events to occur. | ||
207 | public override void SubscribeEvents(int ms) { | ||
208 | // DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); | ||
209 | SubscribedEventsMs = ms; | ||
210 | if (ms > 0) | ||
211 | { | ||
212 | // make sure first collision happens | ||
213 | NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); | ||
214 | |||
215 | PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() | ||
216 | { | ||
217 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
218 | }); | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | // Subscribing for zero or less is the same as unsubscribing | ||
223 | UnSubscribeEvents(); | ||
224 | } | ||
225 | } | ||
226 | public override void UnSubscribeEvents() { | ||
227 | // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); | ||
228 | SubscribedEventsMs = 0; | ||
229 | PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() | ||
230 | { | ||
231 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
232 | }); | ||
233 | } | ||
234 | // Return 'true' if the simulator wants collision events | ||
235 | public override bool SubscribedEvents() { | ||
236 | return (SubscribedEventsMs > 0); | ||
237 | } | ||
238 | |||
239 | #endregion // Collisions | ||
240 | |||
241 | // High performance detailed logging routine used by the physical objects. | ||
242 | protected void DetailLog(string msg, params Object[] args) | ||
243 | { | ||
244 | if (PhysicsScene.PhysicsLogging.Enabled) | ||
245 | PhysicsScene.DetailLog(msg, args); | ||
246 | } | ||
247 | } | ||
248 | } | ||