aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs179
1 files changed, 179 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs
new file mode 100755
index 0000000..9898562
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs
@@ -0,0 +1,179 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Linq;
30using System.Text;
31
32using OpenSim.Framework;
33
34using OMV = OpenMetaverse;
35
36namespace OpenSim.Region.Physics.BulletSPlugin
37{
38public class BSPrimLinkable : BSPrimDisplaced
39{
40 public BSLinkset Linkset { get; set; }
41 public BSLinksetInfo LinksetInfo { get; set; }
42
43 public BSPrimLinkable(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
44 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
45 : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical)
46 {
47 Linkset = BSLinkset.Factory(PhysicsScene, this);
48
49 PhysicsScene.TaintedObject("BSPrimLinksetCompound.Refresh", delegate()
50 {
51 Linkset.Refresh(this);
52 });
53 }
54
55 public override void Destroy()
56 {
57 Linkset = Linkset.RemoveMeFromLinkset(this);
58 base.Destroy();
59 }
60
61 public override BSPhysicsShapeType PreferredPhysicalShape
62 { get { return Linkset.PreferredPhysicalShape(this); } }
63
64 public override void link(Manager.PhysicsActor obj)
65 {
66 BSPrimLinkable parent = obj as BSPrimLinkable;
67 if (parent != null)
68 {
69 BSPhysObject parentBefore = Linkset.LinksetRoot;
70 int childrenBefore = Linkset.NumberOfChildren;
71
72 Linkset = parent.Linkset.AddMeToLinkset(this);
73
74 DetailLog("{0},BSPrimLinkset.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
75 LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
76 }
77 return;
78 }
79
80 public override void delink()
81 {
82 // TODO: decide if this parent checking needs to happen at taint time
83 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
84
85 BSPhysObject parentBefore = Linkset.LinksetRoot;
86 int childrenBefore = Linkset.NumberOfChildren;
87
88 Linkset = Linkset.RemoveMeFromLinkset(this);
89
90 DetailLog("{0},BSPrimLinkset.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ",
91 LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
92 return;
93 base.delink();
94 }
95
96 // When simulator changes position, this might be moving a child of the linkset.
97 public override OMV.Vector3 Position
98 {
99 get { return base.Position; }
100 set
101 {
102 base.Position = value;
103 PhysicsScene.TaintedObject("BSPrimLinkset.setPosition", delegate()
104 {
105 Linkset.UpdateProperties(UpdatedProperties.Position, this);
106 });
107 }
108 }
109
110 // When simulator changes orientation, this might be moving a child of the linkset.
111 public override OMV.Quaternion Orientation
112 {
113 get { return base.Orientation; }
114 set
115 {
116 base.Orientation = value;
117 PhysicsScene.TaintedObject("BSPrimLinkset.setOrientation", delegate()
118 {
119 Linkset.UpdateProperties(UpdatedProperties.Orientation, this);
120 });
121 }
122 }
123
124 public override float TotalMass
125 {
126 get { return Linkset.LinksetMass; }
127 }
128
129 public override void UpdatePhysicalParameters()
130 {
131 base.UpdatePhysicalParameters();
132 // Recompute any linkset parameters.
133 // When going from non-physical to physical, this re-enables the constraints that
134 // had been automatically disabled when the mass was set to zero.
135 // For compound based linksets, this enables and disables interactions of the children.
136 Linkset.Refresh(this);
137 }
138
139 protected override void MakeDynamic(bool makeStatic)
140 {
141 base.MakeDynamic(makeStatic);
142 if (makeStatic)
143 Linkset.MakeStatic(this);
144 else
145 Linkset.MakeDynamic(this);
146 }
147
148 // Body is being taken apart. Remove physical dependencies and schedule a rebuild.
149 protected override void RemoveBodyDependencies()
150 {
151 Linkset.RemoveBodyDependencies(this);
152 base.RemoveBodyDependencies();
153 }
154
155 public override void UpdateProperties(EntityProperties entprop)
156 {
157 if (Linkset.IsRoot(this))
158 {
159 // Properties are only updated for the roots of a linkset.
160 // TODO: this will have to change when linksets are articulated.
161 base.UpdateProperties(entprop);
162 }
163 // The linkset might like to know about changing locations
164 Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this);
165 }
166
167 public override bool Collide(uint collidingWith, BSPhysObject collidee,
168 OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
169 {
170 // prims in the same linkset cannot collide with each other
171 BSPrimLinkable convCollidee = collidee as BSPrimLinkable;
172 if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID))
173 {
174 return false;
175 }
176 return base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth);
177 }
178}
179}