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