diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | 192 |
1 files changed, 192 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..235da78 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs | |||
@@ -0,0 +1,192 @@ | |||
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(PhysScene, this); | ||
51 | |||
52 | PhysScene.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 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 | } | ||
94 | |||
95 | // When simulator changes position, this might be moving a child of the linkset. | ||
96 | public override OMV.Vector3 Position | ||
97 | { | ||
98 | get { return base.Position; } | ||
99 | set | ||
100 | { | ||
101 | base.Position = value; | ||
102 | PhysScene.TaintedObject("BSPrimLinkset.setPosition", delegate() | ||
103 | { | ||
104 | Linkset.UpdateProperties(UpdatedProperties.Position, this); | ||
105 | }); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // When simulator changes orientation, this might be moving a child of the linkset. | ||
110 | public override OMV.Quaternion Orientation | ||
111 | { | ||
112 | get { return base.Orientation; } | ||
113 | set | ||
114 | { | ||
115 | base.Orientation = value; | ||
116 | PhysScene.TaintedObject("BSPrimLinkset.setOrientation", delegate() | ||
117 | { | ||
118 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); | ||
119 | }); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | public override float TotalMass | ||
124 | { | ||
125 | get { return Linkset.LinksetMass; } | ||
126 | } | ||
127 | |||
128 | public override void UpdatePhysicalParameters() | ||
129 | { | ||
130 | base.UpdatePhysicalParameters(); | ||
131 | // Recompute any linkset parameters. | ||
132 | // When going from non-physical to physical, this re-enables the constraints that | ||
133 | // had been automatically disabled when the mass was set to zero. | ||
134 | // For compound based linksets, this enables and disables interactions of the children. | ||
135 | if (Linkset != null) // null can happen during initialization | ||
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 RemoveDependencies() | ||
150 | { | ||
151 | Linkset.RemoveDependencies(this); | ||
152 | base.RemoveDependencies(); | ||
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 | /* | ||
164 | else | ||
165 | { | ||
166 | // For debugging, report the movement of children | ||
167 | DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
168 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | ||
169 | entprop.Acceleration, entprop.RotationalVelocity); | ||
170 | } | ||
171 | */ | ||
172 | // The linkset might like to know about changing locations | ||
173 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); | ||
174 | } | ||
175 | |||
176 | public override bool Collide(uint collidingWith, BSPhysObject collidee, | ||
177 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | ||
178 | { | ||
179 | // prims in the same linkset cannot collide with each other | ||
180 | BSPrimLinkable convCollidee = collidee as BSPrimLinkable; | ||
181 | if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID)) | ||
182 | { | ||
183 | return false; | ||
184 | } | ||
185 | |||
186 | // TODO: handle collisions of other objects with with children of linkset. | ||
187 | // This is a problem for LinksetCompound since the children are packed into the root. | ||
188 | |||
189 | return base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth); | ||
190 | } | ||
191 | } | ||
192 | } | ||