aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs118
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs179
2 files changed, 297 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
new file mode 100755
index 0000000..6401308
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs
@@ -0,0 +1,118 @@
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 * The quotations from http://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial
28 * are Copyright (c) 2009 Linden Research, Inc and are used under their license
29 * of Creative Commons Attribution-Share Alike 3.0
30 * (http://creativecommons.org/licenses/by-sa/3.0/).
31 */
32
33using System;
34using System.Collections.Generic;
35using System.Reflection;
36using System.Runtime.InteropServices;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Region.Physics.Manager;
40
41using OMV = OpenMetaverse;
42
43namespace OpenSim.Region.Physics.BulletSPlugin
44{
45public class BSPrimDisplaced : BSPrim
46{
47 // 'Position' and 'Orientation' is what the simulator thinks the positions of the prim is.
48 // Because Bullet needs the zero coordinate to be the center of mass of the linkset,
49 // sometimes it is necessary to displace the position the physics engine thinks
50 // the position is. PositionDisplacement must be added and removed from the
51 // position as the simulator position is stored and fetched from the physics
52 // engine. Similar to OrientationDisplacement.
53 public virtual OMV.Vector3 PositionDisplacement { get; set; }
54 public virtual OMV.Quaternion OrientationDisplacement { get; set; }
55 public virtual OMV.Vector3 CenterOfMassLocation { get; set; }
56 public virtual OMV.Vector3 GeometricCenterLocation { get; set; }
57
58 public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
59 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
60 : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical)
61 {
62 CenterOfMassLocation = RawPosition;
63 GeometricCenterLocation = RawPosition;
64 }
65
66 public override Vector3 ForcePosition
67 {
68 get
69 {
70 return base.ForcePosition;
71 }
72 set
73 {
74 base.ForcePosition = value;
75 CenterOfMassLocation = RawPosition;
76 GeometricCenterLocation = RawPosition;
77 }
78 }
79
80 public override Quaternion ForceOrientation
81 {
82 get
83 {
84 return base.ForceOrientation;
85 }
86 set
87 {
88 base.ForceOrientation = value;
89 }
90 }
91
92 // Is this used?
93 public override OMV.Vector3 CenterOfMass
94 {
95 get { return CenterOfMassLocation; }
96 }
97
98 // Is this used?
99 public override OMV.Vector3 GeometricCenter
100 {
101 get { return GeometricCenterLocation; }
102 }
103
104
105 public override void UpdateProperties(EntityProperties entprop)
106 {
107 // Undo any center-of-mass displacement that might have been done.
108 if (PositionDisplacement != OMV.Vector3.Zero)
109 {
110 // Correct for any rotation around the center-of-mass
111 // TODO!!!
112 entprop.Position -= PositionDisplacement;
113 }
114
115 base.UpdateProperties(entprop);
116 }
117}
118}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrimLinkable.cs
new file mode 100755
index 0000000..fd66d1c
--- /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 Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this);
164
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}