diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs | 165 |
1 files changed, 165 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..f5ee671 --- /dev/null +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrimDisplaced.cs | |||
@@ -0,0 +1,165 @@ | |||
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 | |||
33 | using System; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Reflection; | ||
36 | using System.Runtime.InteropServices; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.Physics.Manager; | ||
40 | |||
41 | using OMV = OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
44 | { | ||
45 | public class BSPrimDisplaced : BSPrim | ||
46 | { | ||
47 | // The purpose of this module is to do any mapping between what the simulator thinks | ||
48 | // the prim position and orientation is and what the physical position/orientation. | ||
49 | // This difference happens because Bullet assumes the center-of-mass is the <0,0,0> | ||
50 | // of the prim/linkset. The simulator tracks the location of the prim/linkset by | ||
51 | // the location of the root prim. So, if center-of-mass is anywhere but the origin | ||
52 | // of the root prim, the physical origin is displaced from the simulator origin. | ||
53 | // | ||
54 | // This routine works by capturing the Force* setting of position/orientation/... and | ||
55 | // adjusting the simulator values (being set) into the physical values. | ||
56 | // The conversion is also done in the opposite direction (physical origin -> simulator origin). | ||
57 | // | ||
58 | // The updateParameter call is also captured and the values from the physics engine | ||
59 | // are converted into simulator origin values before being passed to the base | ||
60 | // class. | ||
61 | |||
62 | public virtual OMV.Vector3 PositionDisplacement { get; set; } | ||
63 | public virtual OMV.Quaternion OrientationDisplacement { get; set; } | ||
64 | |||
65 | public BSPrimDisplaced(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, | ||
66 | OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) | ||
67 | : base(localID, primName, parent_scene, pos, size, rotation, pbs, pisPhysical) | ||
68 | { | ||
69 | ClearDisplacement(); | ||
70 | } | ||
71 | |||
72 | public void ClearDisplacement() | ||
73 | { | ||
74 | PositionDisplacement = OMV.Vector3.Zero; | ||
75 | OrientationDisplacement = OMV.Quaternion.Identity; | ||
76 | } | ||
77 | |||
78 | // Set this sets and computes the displacement from the passed prim to the center-of-mass. | ||
79 | // A user set value for center-of-mass overrides whatever might be passed in here. | ||
80 | // The displacement is in local coordinates (relative to root prim in linkset oriented coordinates). | ||
81 | public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement) | ||
82 | { | ||
83 | Vector3 comDisp; | ||
84 | if (UserSetCenterOfMassDisplacement.HasValue) | ||
85 | comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement; | ||
86 | else | ||
87 | comDisp = centerOfMassDisplacement; | ||
88 | |||
89 | DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}", | ||
90 | LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp); | ||
91 | if (comDisp == Vector3.Zero) | ||
92 | { | ||
93 | // If there is no diplacement. Things get reset. | ||
94 | PositionDisplacement = OMV.Vector3.Zero; | ||
95 | OrientationDisplacement = OMV.Quaternion.Identity; | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | // Remember the displacement from root as well as the origional rotation of the | ||
100 | // new center-of-mass. | ||
101 | PositionDisplacement = comDisp; | ||
102 | OrientationDisplacement = OMV.Quaternion.Identity; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public override Vector3 ForcePosition | ||
107 | { | ||
108 | get { return base.ForcePosition; } | ||
109 | set | ||
110 | { | ||
111 | if (PositionDisplacement != OMV.Vector3.Zero) | ||
112 | { | ||
113 | OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation); | ||
114 | DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos); | ||
115 | base.ForcePosition = displacedPos; | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | base.ForcePosition = value; | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public override Quaternion ForceOrientation | ||
125 | { | ||
126 | get { return base.ForceOrientation; } | ||
127 | set | ||
128 | { | ||
129 | // TODO: | ||
130 | base.ForceOrientation = value; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | // TODO: decide if this is the right place for these variables. | ||
135 | // Somehow incorporate the optional settability by the user. | ||
136 | // Is this used? | ||
137 | public override OMV.Vector3 CenterOfMass | ||
138 | { | ||
139 | get { return RawPosition; } | ||
140 | } | ||
141 | |||
142 | // Is this used? | ||
143 | public override OMV.Vector3 GeometricCenter | ||
144 | { | ||
145 | get { return RawPosition; } | ||
146 | } | ||
147 | |||
148 | public override void UpdateProperties(EntityProperties entprop) | ||
149 | { | ||
150 | // Undo any center-of-mass displacement that might have been done. | ||
151 | if (PositionDisplacement != OMV.Vector3.Zero || OrientationDisplacement != OMV.Quaternion.Identity) | ||
152 | { | ||
153 | // Correct for any rotation around the center-of-mass | ||
154 | // TODO!!! | ||
155 | |||
156 | OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation); | ||
157 | DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos); | ||
158 | entprop.Position = displacedPos; | ||
159 | // entprop.Rotation = something; | ||
160 | } | ||
161 | |||
162 | base.UpdateProperties(entprop); | ||
163 | } | ||
164 | } | ||
165 | } | ||