aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTeravus Ovares2009-04-05 08:43:29 +0000
committerTeravus Ovares2009-04-05 08:43:29 +0000
commitcf1e8b17237a7e4e5367e7bde887f97eba2547d8 (patch)
tree0c0fcd4b5473fdc5fedbd1c756dddc509d3e416f
parent* Committing what I have on the BulletDotNETPlugin that I have so far. (diff)
downloadopensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.zip
opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.gz
opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.bz2
opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.xz
* Fixing SVN properties
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/AssemblyInfo.cs116
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs2208
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPlugin.cs128
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPluginStructs.cs64
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs4262
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs1284
6 files changed, 4031 insertions, 4031 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/AssemblyInfo.cs
index d10c8ad..0594cff 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/AssemblyInfo.cs
@@ -1,58 +1,58 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30 30
31// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
32// attributes. 32// attributes.
33// 33//
34// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
35// you compile. 35// you compile.
36 36
37[assembly : AssemblyTitle("BulletDotNETPlugin")] 37[assembly : AssemblyTitle("BulletDotNETPlugin")]
38[assembly : AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
39[assembly : AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")] 40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("OdePlugin")] 41[assembly : AssemblyProduct("OdePlugin")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")] 42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")]
43[assembly : AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
44[assembly : AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
45 45
46// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
47// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
48 48
49[assembly : ComVisible(false)] 49[assembly : ComVisible(false)]
50 50
51// The assembly version has following format : 51// The assembly version has following format :
52// 52//
53// Major.Minor.Build.Revision 53// Major.Minor.Build.Revision
54// 54//
55// You can specify all values by your own or you can build default build and revision 55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
57 57
58[assembly : AssemblyVersion("0.6.3.*")] 58[assembly : AssemblyVersion("0.6.3.*")]
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs
index 6791671..9f3349e 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs
@@ -1,1104 +1,1104 @@
1using System; 1using System;
2using System.Reflection; 2using System.Reflection;
3using BulletDotNET; 3using BulletDotNET;
4using OpenMetaverse; 4using OpenMetaverse;
5using OpenSim.Framework; 5using OpenSim.Framework;
6using OpenSim.Region.Physics.Manager; 6using OpenSim.Region.Physics.Manager;
7using log4net; 7using log4net;
8 8
9namespace OpenSim.Region.Physics.BulletDotNETPlugin 9namespace OpenSim.Region.Physics.BulletDotNETPlugin
10{ 10{
11 public class BulletDotNETCharacter : PhysicsActor 11 public class BulletDotNETCharacter : PhysicsActor
12 { 12 {
13 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 13 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14 14
15 public btRigidBody Body; 15 public btRigidBody Body;
16 public btCollisionShape Shell; 16 public btCollisionShape Shell;
17 public btVector3 tempVector1; 17 public btVector3 tempVector1;
18 public btVector3 tempVector2; 18 public btVector3 tempVector2;
19 public btVector3 tempVector3; 19 public btVector3 tempVector3;
20 public btVector3 tempVector4; 20 public btVector3 tempVector4;
21 21
22 public btVector3 tempVector5RayCast; 22 public btVector3 tempVector5RayCast;
23 public btVector3 tempVector6RayCast; 23 public btVector3 tempVector6RayCast;
24 public btVector3 tempVector7RayCast; 24 public btVector3 tempVector7RayCast;
25 25
26 public btQuaternion tempQuat1; 26 public btQuaternion tempQuat1;
27 public btTransform tempTrans1; 27 public btTransform tempTrans1;
28 28
29 public ClosestNotMeRayResultCallback ClosestCastResult; 29 public ClosestNotMeRayResultCallback ClosestCastResult;
30 private btTransform m_bodyTransform; 30 private btTransform m_bodyTransform;
31 private btVector3 m_bodyPosition; 31 private btVector3 m_bodyPosition;
32 private btVector3 m_CapsuleOrientationAxis; 32 private btVector3 m_CapsuleOrientationAxis;
33 private btQuaternion m_bodyOrientation; 33 private btQuaternion m_bodyOrientation;
34 private btDefaultMotionState m_bodyMotionState; 34 private btDefaultMotionState m_bodyMotionState;
35 private btGeneric6DofConstraint m_aMotor; 35 private btGeneric6DofConstraint m_aMotor;
36 private PhysicsVector m_movementComparision; 36 private PhysicsVector m_movementComparision;
37 private PhysicsVector m_position; 37 private PhysicsVector m_position;
38 private PhysicsVector m_zeroPosition; 38 private PhysicsVector m_zeroPosition;
39 private bool m_zeroFlag = false; 39 private bool m_zeroFlag = false;
40 private bool m_lastUpdateSent = false; 40 private bool m_lastUpdateSent = false;
41 private PhysicsVector m_velocity; 41 private PhysicsVector m_velocity;
42 private PhysicsVector m_target_velocity; 42 private PhysicsVector m_target_velocity;
43 private PhysicsVector m_acceleration; 43 private PhysicsVector m_acceleration;
44 private PhysicsVector m_rotationalVelocity; 44 private PhysicsVector m_rotationalVelocity;
45 private bool m_pidControllerActive = true; 45 private bool m_pidControllerActive = true;
46 public float PID_D = 80.0f; 46 public float PID_D = 80.0f;
47 public float PID_P = 90.0f; 47 public float PID_P = 90.0f;
48 public float CAPSULE_RADIUS = 0.37f; 48 public float CAPSULE_RADIUS = 0.37f;
49 public float CAPSULE_LENGTH = 2.140599f; 49 public float CAPSULE_LENGTH = 2.140599f;
50 public float heightFudgeFactor = 0.52f; 50 public float heightFudgeFactor = 0.52f;
51 public float walkDivisor = 1.3f; 51 public float walkDivisor = 1.3f;
52 public float runDivisor = 0.8f; 52 public float runDivisor = 0.8f;
53 private float m_mass = 80f; 53 private float m_mass = 80f;
54 public float m_density = 60f; 54 public float m_density = 60f;
55 private bool m_flying = false; 55 private bool m_flying = false;
56 private bool m_iscolliding = false; 56 private bool m_iscolliding = false;
57 private bool m_iscollidingGround = false; 57 private bool m_iscollidingGround = false;
58 private bool m_wascolliding = false; 58 private bool m_wascolliding = false;
59 private bool m_wascollidingGround = false; 59 private bool m_wascollidingGround = false;
60 private bool m_iscollidingObj = false; 60 private bool m_iscollidingObj = false;
61 private bool m_alwaysRun = false; 61 private bool m_alwaysRun = false;
62 private bool m_hackSentFall = false; 62 private bool m_hackSentFall = false;
63 private bool m_hackSentFly = false; 63 private bool m_hackSentFly = false;
64 public uint m_localID = 0; 64 public uint m_localID = 0;
65 public bool m_returnCollisions = false; 65 public bool m_returnCollisions = false;
66 // taints and their non-tainted counterparts 66 // taints and their non-tainted counterparts
67 public bool m_isPhysical = false; // the current physical status 67 public bool m_isPhysical = false; // the current physical status
68 public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing) 68 public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing)
69 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes. 69 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
70 private bool m_taintRemove = false; 70 private bool m_taintRemove = false;
71 private bool m_taintedPosition = false; 71 private bool m_taintedPosition = false;
72 private PhysicsVector m_taintedPosition_value; 72 private PhysicsVector m_taintedPosition_value;
73 private PhysicsVector m_taintedForce; 73 private PhysicsVector m_taintedForce;
74 74
75 private float m_buoyancy = 0f; 75 private float m_buoyancy = 0f;
76 76
77 // private CollisionLocker ode; 77 // private CollisionLocker ode;
78 78
79 private string m_name = String.Empty; 79 private string m_name = String.Empty;
80 80
81 private bool[] m_colliderarr = new bool[11]; 81 private bool[] m_colliderarr = new bool[11];
82 private bool[] m_colliderGroundarr = new bool[11]; 82 private bool[] m_colliderGroundarr = new bool[11];
83 83
84 84
85 85
86 private BulletDotNETScene m_parent_scene; 86 private BulletDotNETScene m_parent_scene;
87 87
88 public int m_eventsubscription = 0; 88 public int m_eventsubscription = 0;
89 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); 89 private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
90 90
91 public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor) 91 public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
92 { 92 {
93 m_taintedForce = new PhysicsVector(); 93 m_taintedForce = new PhysicsVector();
94 m_velocity = new PhysicsVector(); 94 m_velocity = new PhysicsVector();
95 m_target_velocity = new PhysicsVector(); 95 m_target_velocity = new PhysicsVector();
96 m_position = pos; 96 m_position = pos;
97 m_zeroPosition = new PhysicsVector(pos.X, pos.Y, pos.Z); // this is a class, not a struct. Must make new, or m_zeroPosition will == position regardless 97 m_zeroPosition = new PhysicsVector(pos.X, pos.Y, pos.Z); // this is a class, not a struct. Must make new, or m_zeroPosition will == position regardless
98 m_acceleration = new PhysicsVector(); 98 m_acceleration = new PhysicsVector();
99 m_parent_scene = parent_scene; 99 m_parent_scene = parent_scene;
100 PID_D = pid_d; 100 PID_D = pid_d;
101 PID_P = pid_p; 101 PID_P = pid_p;
102 CAPSULE_RADIUS = capsule_radius; 102 CAPSULE_RADIUS = capsule_radius;
103 m_density = density; 103 m_density = density;
104 heightFudgeFactor = height_fudge_factor; 104 heightFudgeFactor = height_fudge_factor;
105 walkDivisor = walk_divisor; 105 walkDivisor = walk_divisor;
106 runDivisor = rundivisor; 106 runDivisor = rundivisor;
107 107
108 for (int i = 0; i < 11; i++) 108 for (int i = 0; i < 11; i++)
109 { 109 {
110 m_colliderarr[i] = false; 110 m_colliderarr[i] = false;
111 } 111 }
112 for (int i = 0; i < 11; i++) 112 for (int i = 0; i < 11; i++)
113 { 113 {
114 m_colliderGroundarr[i] = false; 114 m_colliderGroundarr[i] = false;
115 } 115 }
116 CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; 116 CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
117 m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH; 117 m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
118 m_isPhysical = false; // current status: no ODE information exists 118 m_isPhysical = false; // current status: no ODE information exists
119 m_tainted_isPhysical = true; // new tainted status: need to create ODE information 119 m_tainted_isPhysical = true; // new tainted status: need to create ODE information
120 120
121 m_parent_scene.AddPhysicsActorTaint(this); 121 m_parent_scene.AddPhysicsActorTaint(this);
122 122
123 m_name = avName; 123 m_name = avName;
124 tempVector1 = new btVector3(0, 0, 0); 124 tempVector1 = new btVector3(0, 0, 0);
125 tempVector2 = new btVector3(0, 0, 0); 125 tempVector2 = new btVector3(0, 0, 0);
126 tempVector3 = new btVector3(0, 0, 0); 126 tempVector3 = new btVector3(0, 0, 0);
127 tempVector4 = new btVector3(0, 0, 0); 127 tempVector4 = new btVector3(0, 0, 0);
128 128
129 tempVector5RayCast = new btVector3(0, 0, 0); 129 tempVector5RayCast = new btVector3(0, 0, 0);
130 tempVector6RayCast = new btVector3(0, 0, 0); 130 tempVector6RayCast = new btVector3(0, 0, 0);
131 tempVector7RayCast = new btVector3(0, 0, 0); 131 tempVector7RayCast = new btVector3(0, 0, 0);
132 132
133 tempQuat1 = new btQuaternion(0, 0, 0, 1); 133 tempQuat1 = new btQuaternion(0, 0, 0, 1);
134 tempTrans1 = new btTransform(tempQuat1, tempVector1); 134 tempTrans1 = new btTransform(tempQuat1, tempVector1);
135 m_movementComparision = new PhysicsVector(0, 0, 0); 135 m_movementComparision = new PhysicsVector(0, 0, 0);
136 m_CapsuleOrientationAxis = new btVector3(1, 0, 1); 136 m_CapsuleOrientationAxis = new btVector3(1, 0, 1);
137 137
138 138
139 139
140 } 140 }
141 141
142 /// <summary> 142 /// <summary>
143 /// This creates the Avatar's physical Surrogate at the position supplied 143 /// This creates the Avatar's physical Surrogate at the position supplied
144 /// </summary> 144 /// </summary>
145 /// <param name="npositionX"></param> 145 /// <param name="npositionX"></param>
146 /// <param name="npositionY"></param> 146 /// <param name="npositionY"></param>
147 /// <param name="npositionZ"></param> 147 /// <param name="npositionZ"></param>
148 148
149 // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access 149 // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access
150 // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only 150 // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only
151 // place that is safe to call this routine AvatarGeomAndBodyCreation. 151 // place that is safe to call this routine AvatarGeomAndBodyCreation.
152 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) 152 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ)
153 { 153 {
154 154
155 if (CAPSULE_LENGTH <= 0) 155 if (CAPSULE_LENGTH <= 0)
156 { 156 {
157 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); 157 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
158 CAPSULE_LENGTH = 0.01f; 158 CAPSULE_LENGTH = 0.01f;
159 159
160 } 160 }
161 161
162 if (CAPSULE_RADIUS <= 0) 162 if (CAPSULE_RADIUS <= 0)
163 { 163 {
164 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); 164 m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
165 CAPSULE_RADIUS = 0.01f; 165 CAPSULE_RADIUS = 0.01f;
166 166
167 } 167 }
168 168
169 Shell = new btCapsuleShape(CAPSULE_RADIUS, CAPSULE_LENGTH); 169 Shell = new btCapsuleShape(CAPSULE_RADIUS, CAPSULE_LENGTH);
170 170
171 if (m_bodyPosition == null) 171 if (m_bodyPosition == null)
172 m_bodyPosition = new btVector3(npositionX, npositionY, npositionZ); 172 m_bodyPosition = new btVector3(npositionX, npositionY, npositionZ);
173 173
174 m_bodyPosition.setValue(npositionX, npositionY, npositionZ); 174 m_bodyPosition.setValue(npositionX, npositionY, npositionZ);
175 175
176 if (m_bodyOrientation == null) 176 if (m_bodyOrientation == null)
177 m_bodyOrientation = new btQuaternion(m_CapsuleOrientationAxis, (Utils.DEG_TO_RAD * 90)); 177 m_bodyOrientation = new btQuaternion(m_CapsuleOrientationAxis, (Utils.DEG_TO_RAD * 90));
178 178
179 if (m_bodyTransform == null) 179 if (m_bodyTransform == null)
180 m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); 180 m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition);
181 else 181 else
182 { 182 {
183 m_bodyTransform.Dispose(); 183 m_bodyTransform.Dispose();
184 m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); 184 m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition);
185 } 185 }
186 186
187 if (m_bodyMotionState == null) 187 if (m_bodyMotionState == null)
188 m_bodyMotionState = new btDefaultMotionState(m_bodyTransform); 188 m_bodyMotionState = new btDefaultMotionState(m_bodyTransform);
189 else 189 else
190 m_bodyMotionState.setWorldTransform(m_bodyTransform); 190 m_bodyMotionState.setWorldTransform(m_bodyTransform);
191 191
192 m_mass = Mass; 192 m_mass = Mass;
193 193
194 Body = new btRigidBody(m_mass, m_bodyMotionState, Shell); 194 Body = new btRigidBody(m_mass, m_bodyMotionState, Shell);
195 Body.setUserPointer(new IntPtr((int)Body.Handle)); 195 Body.setUserPointer(new IntPtr((int)Body.Handle));
196 196
197 if (ClosestCastResult != null) 197 if (ClosestCastResult != null)
198 ClosestCastResult.Dispose(); 198 ClosestCastResult.Dispose();
199 ClosestCastResult = new ClosestNotMeRayResultCallback(Body); 199 ClosestCastResult = new ClosestNotMeRayResultCallback(Body);
200 200
201 m_parent_scene.AddRigidBody(Body); 201 m_parent_scene.AddRigidBody(Body);
202 Body.setActivationState(4); 202 Body.setActivationState(4);
203 if (m_aMotor != null) 203 if (m_aMotor != null)
204 { 204 {
205 if (m_aMotor.Handle != IntPtr.Zero) 205 if (m_aMotor.Handle != IntPtr.Zero)
206 { 206 {
207 m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); 207 m_parent_scene.getBulletWorld().removeConstraint(m_aMotor);
208 m_aMotor.Dispose(); 208 m_aMotor.Dispose();
209 } 209 }
210 m_aMotor = null; 210 m_aMotor = null;
211 } 211 }
212 212
213 m_aMotor = new btGeneric6DofConstraint(Body, m_parent_scene.TerrainBody, 213 m_aMotor = new btGeneric6DofConstraint(Body, m_parent_scene.TerrainBody,
214 m_parent_scene.TransZero, 214 m_parent_scene.TransZero,
215 m_parent_scene.TransZero, false); 215 m_parent_scene.TransZero, false);
216 m_aMotor.setAngularLowerLimit(m_parent_scene.VectorZero); 216 m_aMotor.setAngularLowerLimit(m_parent_scene.VectorZero);
217 m_aMotor.setAngularUpperLimit(m_parent_scene.VectorZero); 217 m_aMotor.setAngularUpperLimit(m_parent_scene.VectorZero);
218 218
219 219
220 } 220 }
221 public void Remove() 221 public void Remove()
222 { 222 {
223 m_taintRemove = true; 223 m_taintRemove = true;
224 } 224 }
225 public override bool Stopped 225 public override bool Stopped
226 { 226 {
227 get { return m_zeroFlag; } 227 get { return m_zeroFlag; }
228 } 228 }
229 229
230 public override PhysicsVector Size 230 public override PhysicsVector Size
231 { 231 {
232 get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); } 232 get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); }
233 set 233 set
234 { 234 {
235 m_pidControllerActive = true; 235 m_pidControllerActive = true;
236 236
237 PhysicsVector SetSize = value; 237 PhysicsVector SetSize = value;
238 m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; 238 m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
239 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); 239 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
240 240
241 Velocity = new PhysicsVector(0f, 0f, 0f); 241 Velocity = new PhysicsVector(0f, 0f, 0f);
242 242
243 m_parent_scene.AddPhysicsActorTaint(this); 243 m_parent_scene.AddPhysicsActorTaint(this);
244 } 244 }
245 } 245 }
246 246
247 /// <summary> 247 /// <summary>
248 /// turn the PID controller on or off. 248 /// turn the PID controller on or off.
249 /// The PID Controller will turn on all by itself in many situations 249 /// The PID Controller will turn on all by itself in many situations
250 /// </summary> 250 /// </summary>
251 /// <param name="status"></param> 251 /// <param name="status"></param>
252 public void SetPidStatus(bool status) 252 public void SetPidStatus(bool status)
253 { 253 {
254 m_pidControllerActive = status; 254 m_pidControllerActive = status;
255 } 255 }
256 256
257 public override PrimitiveBaseShape Shape 257 public override PrimitiveBaseShape Shape
258 { 258 {
259 set { return; } 259 set { return; }
260 } 260 }
261 261
262 public override uint LocalID 262 public override uint LocalID
263 { 263 {
264 set { m_localID = value; } 264 set { m_localID = value; }
265 } 265 }
266 266
267 public override bool Grabbed 267 public override bool Grabbed
268 { 268 {
269 set { return; } 269 set { return; }
270 } 270 }
271 271
272 public override bool Selected 272 public override bool Selected
273 { 273 {
274 set { return; } 274 set { return; }
275 } 275 }
276 276
277 277
278 public override void CrossingFailure() 278 public override void CrossingFailure()
279 { 279 {
280 280
281 } 281 }
282 282
283 public override void link(PhysicsActor obj) 283 public override void link(PhysicsActor obj)
284 { 284 {
285 285
286 } 286 }
287 287
288 public override void delink() 288 public override void delink()
289 { 289 {
290 290
291 } 291 }
292 292
293 public override void LockAngularMotion(PhysicsVector axis) 293 public override void LockAngularMotion(PhysicsVector axis)
294 { 294 {
295 295
296 } 296 }
297 297
298 public override PhysicsVector Position 298 public override PhysicsVector Position
299 { 299 {
300 get { return m_position; } 300 get { return m_position; }
301 set 301 set
302 { 302 {
303 m_taintedPosition_value = value; 303 m_taintedPosition_value = value;
304 m_position = value; 304 m_position = value;
305 m_taintedPosition = true; 305 m_taintedPosition = true;
306 } 306 }
307 } 307 }
308 308
309 public override float Mass 309 public override float Mass
310 { 310 {
311 get 311 get
312 { 312 {
313 float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH); 313 float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH);
314 return m_density * AVvolume; 314 return m_density * AVvolume;
315 } 315 }
316 } 316 }
317 317
318 public override PhysicsVector Force 318 public override PhysicsVector Force
319 { 319 {
320 get { return new PhysicsVector(m_target_velocity.X, m_target_velocity.Y, m_target_velocity.Z); } 320 get { return new PhysicsVector(m_target_velocity.X, m_target_velocity.Y, m_target_velocity.Z); }
321 set { return; } 321 set { return; }
322 } 322 }
323 323
324 public override int VehicleType 324 public override int VehicleType
325 { 325 {
326 get { return 0; } 326 get { return 0; }
327 set { return; } 327 set { return; }
328 } 328 }
329 329
330 public override void VehicleFloatParam(int param, float value) 330 public override void VehicleFloatParam(int param, float value)
331 { 331 {
332 332
333 } 333 }
334 334
335 public override void VehicleVectorParam(int param, PhysicsVector value) 335 public override void VehicleVectorParam(int param, PhysicsVector value)
336 { 336 {
337 337
338 } 338 }
339 339
340 public override void VehicleRotationParam(int param, Quaternion rotation) 340 public override void VehicleRotationParam(int param, Quaternion rotation)
341 { 341 {
342 342
343 } 343 }
344 344
345 public override void SetVolumeDetect(int param) 345 public override void SetVolumeDetect(int param)
346 { 346 {
347 347
348 } 348 }
349 349
350 public override PhysicsVector GeometricCenter 350 public override PhysicsVector GeometricCenter
351 { 351 {
352 get { return PhysicsVector.Zero; } 352 get { return PhysicsVector.Zero; }
353 } 353 }
354 354
355 public override PhysicsVector CenterOfMass 355 public override PhysicsVector CenterOfMass
356 { 356 {
357 get { return PhysicsVector.Zero; } 357 get { return PhysicsVector.Zero; }
358 } 358 }
359 359
360 public override PhysicsVector Velocity 360 public override PhysicsVector Velocity
361 { 361 {
362 get 362 get
363 { 363 {
364 // There's a problem with PhysicsVector.Zero! Don't Use it Here! 364 // There's a problem with PhysicsVector.Zero! Don't Use it Here!
365 if (m_zeroFlag) 365 if (m_zeroFlag)
366 return new PhysicsVector(0f, 0f, 0f); 366 return new PhysicsVector(0f, 0f, 0f);
367 m_lastUpdateSent = false; 367 m_lastUpdateSent = false;
368 return m_velocity; 368 return m_velocity;
369 } 369 }
370 set 370 set
371 { 371 {
372 m_pidControllerActive = true; 372 m_pidControllerActive = true;
373 m_target_velocity = value; 373 m_target_velocity = value;
374 } 374 }
375 } 375 }
376 376
377 public override PhysicsVector Torque 377 public override PhysicsVector Torque
378 { 378 {
379 get { return PhysicsVector.Zero; } 379 get { return PhysicsVector.Zero; }
380 set { return; } 380 set { return; }
381 } 381 }
382 382
383 public override float CollisionScore 383 public override float CollisionScore
384 { 384 {
385 get { return 0f; } 385 get { return 0f; }
386 set { } 386 set { }
387 } 387 }
388 388
389 public override PhysicsVector Acceleration 389 public override PhysicsVector Acceleration
390 { 390 {
391 get { return m_acceleration; } 391 get { return m_acceleration; }
392 } 392 }
393 393
394 public override Quaternion Orientation 394 public override Quaternion Orientation
395 { 395 {
396 get { return Quaternion.Identity; } 396 get { return Quaternion.Identity; }
397 set 397 set
398 { 398 {
399 399
400 } 400 }
401 } 401 }
402 402
403 public override int PhysicsActorType 403 public override int PhysicsActorType
404 { 404 {
405 get { return (int)ActorTypes.Agent; } 405 get { return (int)ActorTypes.Agent; }
406 set { return; } 406 set { return; }
407 } 407 }
408 408
409 public override bool IsPhysical 409 public override bool IsPhysical
410 { 410 {
411 get { return false; } 411 get { return false; }
412 set { return; } 412 set { return; }
413 } 413 }
414 414
415 public override bool Flying 415 public override bool Flying
416 { 416 {
417 get { return m_flying; } 417 get { return m_flying; }
418 set { m_flying = value; } 418 set { m_flying = value; }
419 } 419 }
420 420
421 public override bool SetAlwaysRun 421 public override bool SetAlwaysRun
422 { 422 {
423 get { return m_alwaysRun; } 423 get { return m_alwaysRun; }
424 set { m_alwaysRun = value; } 424 set { m_alwaysRun = value; }
425 } 425 }
426 426
427 427
428 public override bool ThrottleUpdates 428 public override bool ThrottleUpdates
429 { 429 {
430 get { return false; } 430 get { return false; }
431 set { return; } 431 set { return; }
432 } 432 }
433 433
434 /// <summary> 434 /// <summary>
435 /// Returns if the avatar is colliding in general. 435 /// Returns if the avatar is colliding in general.
436 /// This includes the ground and objects and avatar. 436 /// This includes the ground and objects and avatar.
437 /// </summary> 437 /// </summary>
438 public override bool IsColliding 438 public override bool IsColliding
439 { 439 {
440 get { return m_iscolliding; } 440 get { return m_iscolliding; }
441 set 441 set
442 { 442 {
443 int i; 443 int i;
444 int truecount = 0; 444 int truecount = 0;
445 int falsecount = 0; 445 int falsecount = 0;
446 446
447 if (m_colliderarr.Length >= 10) 447 if (m_colliderarr.Length >= 10)
448 { 448 {
449 for (i = 0; i < 10; i++) 449 for (i = 0; i < 10; i++)
450 { 450 {
451 m_colliderarr[i] = m_colliderarr[i + 1]; 451 m_colliderarr[i] = m_colliderarr[i + 1];
452 } 452 }
453 } 453 }
454 m_colliderarr[10] = value; 454 m_colliderarr[10] = value;
455 455
456 for (i = 0; i < 11; i++) 456 for (i = 0; i < 11; i++)
457 { 457 {
458 if (m_colliderarr[i]) 458 if (m_colliderarr[i])
459 { 459 {
460 truecount++; 460 truecount++;
461 } 461 }
462 else 462 else
463 { 463 {
464 falsecount++; 464 falsecount++;
465 } 465 }
466 } 466 }
467 467
468 // Equal truecounts and false counts means we're colliding with something. 468 // Equal truecounts and false counts means we're colliding with something.
469 m_log.DebugFormat("[PHYSICS]: TrueCount:{0}, FalseCount:{1}",truecount,falsecount); 469 m_log.DebugFormat("[PHYSICS]: TrueCount:{0}, FalseCount:{1}",truecount,falsecount);
470 if (falsecount > 1.2 * truecount) 470 if (falsecount > 1.2 * truecount)
471 { 471 {
472 m_iscolliding = false; 472 m_iscolliding = false;
473 } 473 }
474 else 474 else
475 { 475 {
476 m_iscolliding = true; 476 m_iscolliding = true;
477 } 477 }
478 if (m_wascolliding != m_iscolliding) 478 if (m_wascolliding != m_iscolliding)
479 { 479 {
480 //base.SendCollisionUpdate(new CollisionEventUpdate()); 480 //base.SendCollisionUpdate(new CollisionEventUpdate());
481 } 481 }
482 m_wascolliding = m_iscolliding; 482 m_wascolliding = m_iscolliding;
483 } 483 }
484 } 484 }
485 485
486 /// <summary> 486 /// <summary>
487 /// Returns if an avatar is colliding with the ground 487 /// Returns if an avatar is colliding with the ground
488 /// </summary> 488 /// </summary>
489 public override bool CollidingGround 489 public override bool CollidingGround
490 { 490 {
491 get { return m_iscollidingGround; } 491 get { return m_iscollidingGround; }
492 set 492 set
493 { 493 {
494 // Collisions against the ground are not really reliable 494 // Collisions against the ground are not really reliable
495 // So, to get a consistant value we have to average the current result over time 495 // So, to get a consistant value we have to average the current result over time
496 // Currently we use 1 second = 10 calls to this. 496 // Currently we use 1 second = 10 calls to this.
497 int i; 497 int i;
498 int truecount = 0; 498 int truecount = 0;
499 int falsecount = 0; 499 int falsecount = 0;
500 500
501 if (m_colliderGroundarr.Length >= 10) 501 if (m_colliderGroundarr.Length >= 10)
502 { 502 {
503 for (i = 0; i < 10; i++) 503 for (i = 0; i < 10; i++)
504 { 504 {
505 m_colliderGroundarr[i] = m_colliderGroundarr[i + 1]; 505 m_colliderGroundarr[i] = m_colliderGroundarr[i + 1];
506 } 506 }
507 } 507 }
508 m_colliderGroundarr[10] = value; 508 m_colliderGroundarr[10] = value;
509 509
510 for (i = 0; i < 11; i++) 510 for (i = 0; i < 11; i++)
511 { 511 {
512 if (m_colliderGroundarr[i]) 512 if (m_colliderGroundarr[i])
513 { 513 {
514 truecount++; 514 truecount++;
515 } 515 }
516 else 516 else
517 { 517 {
518 falsecount++; 518 falsecount++;
519 } 519 }
520 } 520 }
521 521
522 // Equal truecounts and false counts means we're colliding with something. 522 // Equal truecounts and false counts means we're colliding with something.
523 523
524 if (falsecount > 1.2 * truecount) 524 if (falsecount > 1.2 * truecount)
525 { 525 {
526 m_iscollidingGround = false; 526 m_iscollidingGround = false;
527 } 527 }
528 else 528 else
529 { 529 {
530 m_iscollidingGround = true; 530 m_iscollidingGround = true;
531 } 531 }
532 if (m_wascollidingGround != m_iscollidingGround) 532 if (m_wascollidingGround != m_iscollidingGround)
533 { 533 {
534 //base.SendCollisionUpdate(new CollisionEventUpdate()); 534 //base.SendCollisionUpdate(new CollisionEventUpdate());
535 } 535 }
536 m_wascollidingGround = m_iscollidingGround; 536 m_wascollidingGround = m_iscollidingGround;
537 } 537 }
538 } 538 }
539 539
540 /// <summary> 540 /// <summary>
541 /// Returns if the avatar is colliding with an object 541 /// Returns if the avatar is colliding with an object
542 /// </summary> 542 /// </summary>
543 public override bool CollidingObj 543 public override bool CollidingObj
544 { 544 {
545 get { return m_iscollidingObj; } 545 get { return m_iscollidingObj; }
546 set 546 set
547 { 547 {
548 m_iscollidingObj = value; 548 m_iscollidingObj = value;
549 if (value) 549 if (value)
550 m_pidControllerActive = false; 550 m_pidControllerActive = false;
551 else 551 else
552 m_pidControllerActive = true; 552 m_pidControllerActive = true;
553 } 553 }
554 } 554 }
555 555
556 556
557 public override bool FloatOnWater 557 public override bool FloatOnWater
558 { 558 {
559 set { return; } 559 set { return; }
560 } 560 }
561 561
562 public override PhysicsVector RotationalVelocity 562 public override PhysicsVector RotationalVelocity
563 { 563 {
564 get { return m_rotationalVelocity; } 564 get { return m_rotationalVelocity; }
565 set { m_rotationalVelocity = value; } 565 set { m_rotationalVelocity = value; }
566 } 566 }
567 567
568 public override bool Kinematic 568 public override bool Kinematic
569 { 569 {
570 get { return false; } 570 get { return false; }
571 set { } 571 set { }
572 } 572 }
573 573
574 public override float Buoyancy 574 public override float Buoyancy
575 { 575 {
576 get { return m_buoyancy; } 576 get { return m_buoyancy; }
577 set { m_buoyancy = value; } 577 set { m_buoyancy = value; }
578 } 578 }
579 579
580 public override PhysicsVector PIDTarget { set { return; } } 580 public override PhysicsVector PIDTarget { set { return; } }
581 public override bool PIDActive { set { return; } } 581 public override bool PIDActive { set { return; } }
582 public override float PIDTau { set { return; } } 582 public override float PIDTau { set { return; } }
583 583
584 public override bool PIDHoverActive 584 public override bool PIDHoverActive
585 { 585 {
586 set { return; } 586 set { return; }
587 } 587 }
588 588
589 public override float PIDHoverHeight 589 public override float PIDHoverHeight
590 { 590 {
591 set { return; } 591 set { return; }
592 } 592 }
593 593
594 public override PIDHoverType PIDHoverType 594 public override PIDHoverType PIDHoverType
595 { 595 {
596 set { return; } 596 set { return; }
597 } 597 }
598 598
599 public override float PIDHoverTau 599 public override float PIDHoverTau
600 { 600 {
601 set { return; } 601 set { return; }
602 } 602 }
603 603
604 /// <summary> 604 /// <summary>
605 /// Adds the force supplied to the Target Velocity 605 /// Adds the force supplied to the Target Velocity
606 /// The PID controller takes this target velocity and tries to make it a reality 606 /// The PID controller takes this target velocity and tries to make it a reality
607 /// </summary> 607 /// </summary>
608 /// <param name="force"></param> 608 /// <param name="force"></param>
609 /// <param name="pushforce">Is this a push by a script?</param> 609 /// <param name="pushforce">Is this a push by a script?</param>
610 public override void AddForce(PhysicsVector force, bool pushforce) 610 public override void AddForce(PhysicsVector force, bool pushforce)
611 { 611 {
612 if (pushforce) 612 if (pushforce)
613 { 613 {
614 m_pidControllerActive = false; 614 m_pidControllerActive = false;
615 force *= 100f; 615 force *= 100f;
616 doForce(force, false); 616 doForce(force, false);
617 //System.Console.WriteLine("Push!"); 617 //System.Console.WriteLine("Push!");
618 //_target_velocity.X += force.X; 618 //_target_velocity.X += force.X;
619 // _target_velocity.Y += force.Y; 619 // _target_velocity.Y += force.Y;
620 //_target_velocity.Z += force.Z; 620 //_target_velocity.Z += force.Z;
621 } 621 }
622 else 622 else
623 { 623 {
624 m_pidControllerActive = true; 624 m_pidControllerActive = true;
625 m_target_velocity.X += force.X; 625 m_target_velocity.X += force.X;
626 m_target_velocity.Y += force.Y; 626 m_target_velocity.Y += force.Y;
627 m_target_velocity.Z += force.Z; 627 m_target_velocity.Z += force.Z;
628 } 628 }
629 //m_lastUpdateSent = false; 629 //m_lastUpdateSent = false;
630 } 630 }
631 631
632 public void doForce(PhysicsVector force, bool now) 632 public void doForce(PhysicsVector force, bool now)
633 { 633 {
634 634
635 tempVector3.setValue(force.X, force.Y, force.Z); 635 tempVector3.setValue(force.X, force.Y, force.Z);
636 if (now) 636 if (now)
637 { 637 {
638 Body.applyCentralForce(tempVector3); 638 Body.applyCentralForce(tempVector3);
639 } 639 }
640 else 640 else
641 { 641 {
642 m_taintedForce += force; 642 m_taintedForce += force;
643 m_parent_scene.AddPhysicsActorTaint(this); 643 m_parent_scene.AddPhysicsActorTaint(this);
644 } 644 }
645 } 645 }
646 646
647 public void doImpulse(PhysicsVector force, bool now) 647 public void doImpulse(PhysicsVector force, bool now)
648 { 648 {
649 649
650 tempVector3.setValue(force.X, force.Y, force.Z); 650 tempVector3.setValue(force.X, force.Y, force.Z);
651 if (now) 651 if (now)
652 { 652 {
653 Body.applyCentralImpulse(tempVector3); 653 Body.applyCentralImpulse(tempVector3);
654 } 654 }
655 else 655 else
656 { 656 {
657 m_taintedForce += force; 657 m_taintedForce += force;
658 m_parent_scene.AddPhysicsActorTaint(this); 658 m_parent_scene.AddPhysicsActorTaint(this);
659 } 659 }
660 } 660 }
661 661
662 public override void AddAngularForce(PhysicsVector force, bool pushforce) 662 public override void AddAngularForce(PhysicsVector force, bool pushforce)
663 { 663 {
664 664
665 } 665 }
666 666
667 public override void SetMomentum(PhysicsVector momentum) 667 public override void SetMomentum(PhysicsVector momentum)
668 { 668 {
669 669
670 } 670 }
671 671
672 public override void SubscribeEvents(int ms) 672 public override void SubscribeEvents(int ms)
673 { 673 {
674 m_eventsubscription = ms; 674 m_eventsubscription = ms;
675 m_parent_scene.addCollisionEventReporting(this); 675 m_parent_scene.addCollisionEventReporting(this);
676 } 676 }
677 677
678 public override void UnSubscribeEvents() 678 public override void UnSubscribeEvents()
679 { 679 {
680 m_parent_scene.remCollisionEventReporting(this); 680 m_parent_scene.remCollisionEventReporting(this);
681 m_eventsubscription = 0; 681 m_eventsubscription = 0;
682 } 682 }
683 683
684 public override bool SubscribedEvents() 684 public override bool SubscribedEvents()
685 { 685 {
686 if (m_eventsubscription > 0) 686 if (m_eventsubscription > 0)
687 return true; 687 return true;
688 return false; 688 return false;
689 } 689 }
690 690
691 internal void Dispose() 691 internal void Dispose()
692 { 692 {
693 if (Body.isInWorld()) 693 if (Body.isInWorld())
694 m_parent_scene.removeFromWorld(Body); 694 m_parent_scene.removeFromWorld(Body);
695 695
696 if (m_aMotor.Handle != IntPtr.Zero) 696 if (m_aMotor.Handle != IntPtr.Zero)
697 m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); 697 m_parent_scene.getBulletWorld().removeConstraint(m_aMotor);
698 698
699 m_aMotor.Dispose(); m_aMotor = null; 699 m_aMotor.Dispose(); m_aMotor = null;
700 ClosestCastResult.Dispose(); ClosestCastResult = null; 700 ClosestCastResult.Dispose(); ClosestCastResult = null;
701 Body.Dispose(); Body = null; 701 Body.Dispose(); Body = null;
702 Shell.Dispose(); Shell = null; 702 Shell.Dispose(); Shell = null;
703 tempQuat1.Dispose(); 703 tempQuat1.Dispose();
704 tempTrans1.Dispose(); 704 tempTrans1.Dispose();
705 tempVector1.Dispose(); 705 tempVector1.Dispose();
706 tempVector2.Dispose(); 706 tempVector2.Dispose();
707 tempVector3.Dispose(); 707 tempVector3.Dispose();
708 tempVector4.Dispose(); 708 tempVector4.Dispose();
709 tempVector5RayCast.Dispose(); 709 tempVector5RayCast.Dispose();
710 tempVector6RayCast.Dispose(); 710 tempVector6RayCast.Dispose();
711 711
712 } 712 }
713 713
714 public void ProcessTaints(float timestep) 714 public void ProcessTaints(float timestep)
715 { 715 {
716 716
717 if (m_tainted_isPhysical != m_isPhysical) 717 if (m_tainted_isPhysical != m_isPhysical)
718 { 718 {
719 if (m_tainted_isPhysical) 719 if (m_tainted_isPhysical)
720 { 720 {
721 // Create avatar capsule and related ODE data 721 // Create avatar capsule and related ODE data
722 if (!(Shell == null && Body == null)) 722 if (!(Shell == null && Body == null))
723 { 723 {
724 m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - " 724 m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - "
725 + (Shell != null ? "Shell " : "") 725 + (Shell != null ? "Shell " : "")
726 + (Body != null ? "Body " : "")); 726 + (Body != null ? "Body " : ""));
727 } 727 }
728 AvatarGeomAndBodyCreation(m_position.X, m_position.Y, m_position.Z); 728 AvatarGeomAndBodyCreation(m_position.X, m_position.Y, m_position.Z);
729 729
730 730
731 } 731 }
732 else 732 else
733 { 733 {
734 // destroy avatar capsule and related ODE data 734 // destroy avatar capsule and related ODE data
735 735
736 Dispose(); 736 Dispose();
737 tempVector1 = new btVector3(0, 0, 0); 737 tempVector1 = new btVector3(0, 0, 0);
738 tempVector2 = new btVector3(0, 0, 0); 738 tempVector2 = new btVector3(0, 0, 0);
739 tempVector3 = new btVector3(0, 0, 0); 739 tempVector3 = new btVector3(0, 0, 0);
740 tempVector4 = new btVector3(0, 0, 0); 740 tempVector4 = new btVector3(0, 0, 0);
741 741
742 tempVector5RayCast = new btVector3(0, 0, 0); 742 tempVector5RayCast = new btVector3(0, 0, 0);
743 tempVector6RayCast = new btVector3(0, 0, 0); 743 tempVector6RayCast = new btVector3(0, 0, 0);
744 tempVector7RayCast = new btVector3(0, 0, 0); 744 tempVector7RayCast = new btVector3(0, 0, 0);
745 745
746 tempQuat1 = new btQuaternion(0, 0, 0, 1); 746 tempQuat1 = new btQuaternion(0, 0, 0, 1);
747 tempTrans1 = new btTransform(tempQuat1, tempVector1); 747 tempTrans1 = new btTransform(tempQuat1, tempVector1);
748 m_movementComparision = new PhysicsVector(0, 0, 0); 748 m_movementComparision = new PhysicsVector(0, 0, 0);
749 m_CapsuleOrientationAxis = new btVector3(1, 0, 1); 749 m_CapsuleOrientationAxis = new btVector3(1, 0, 1);
750 } 750 }
751 751
752 m_isPhysical = m_tainted_isPhysical; 752 m_isPhysical = m_tainted_isPhysical;
753 } 753 }
754 754
755 if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH) 755 if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH)
756 { 756 {
757 if (Body != null) 757 if (Body != null)
758 { 758 {
759 759
760 m_pidControllerActive = true; 760 m_pidControllerActive = true;
761 // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() 761 // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate()
762 //d.JointDestroy(Amotor); 762 //d.JointDestroy(Amotor);
763 float prevCapsule = CAPSULE_LENGTH; 763 float prevCapsule = CAPSULE_LENGTH;
764 CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; 764 CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH;
765 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); 765 //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
766 Dispose(); 766 Dispose();
767 767
768 tempVector1 = new btVector3(0, 0, 0); 768 tempVector1 = new btVector3(0, 0, 0);
769 tempVector2 = new btVector3(0, 0, 0); 769 tempVector2 = new btVector3(0, 0, 0);
770 tempVector3 = new btVector3(0, 0, 0); 770 tempVector3 = new btVector3(0, 0, 0);
771 tempVector4 = new btVector3(0, 0, 0); 771 tempVector4 = new btVector3(0, 0, 0);
772 772
773 tempVector5RayCast = new btVector3(0, 0, 0); 773 tempVector5RayCast = new btVector3(0, 0, 0);
774 tempVector6RayCast = new btVector3(0, 0, 0); 774 tempVector6RayCast = new btVector3(0, 0, 0);
775 tempVector7RayCast = new btVector3(0, 0, 0); 775 tempVector7RayCast = new btVector3(0, 0, 0);
776 776
777 tempQuat1 = new btQuaternion(0, 0, 0, 1); 777 tempQuat1 = new btQuaternion(0, 0, 0, 1);
778 tempTrans1 = new btTransform(tempQuat1, tempVector1); 778 tempTrans1 = new btTransform(tempQuat1, tempVector1);
779 m_movementComparision = new PhysicsVector(0, 0, 0); 779 m_movementComparision = new PhysicsVector(0, 0, 0);
780 m_CapsuleOrientationAxis = new btVector3(1, 0, 1); 780 m_CapsuleOrientationAxis = new btVector3(1, 0, 1);
781 781
782 AvatarGeomAndBodyCreation(m_position.X, m_position.Y, 782 AvatarGeomAndBodyCreation(m_position.X, m_position.Y,
783 m_position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2)); 783 m_position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2));
784 Velocity = new PhysicsVector(0f, 0f, 0f); 784 Velocity = new PhysicsVector(0f, 0f, 0f);
785 785
786 } 786 }
787 else 787 else
788 { 788 {
789 m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - " 789 m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - "
790 + (Shell == null ? "Shell " : "") 790 + (Shell == null ? "Shell " : "")
791 + (Body == null ? "Body " : "")); 791 + (Body == null ? "Body " : ""));
792 } 792 }
793 } 793 }
794 if (m_taintRemove) 794 if (m_taintRemove)
795 { 795 {
796 Dispose(); 796 Dispose();
797 } 797 }
798 } 798 }
799 799
800 /// <summary> 800 /// <summary>
801 /// Called from Simulate 801 /// Called from Simulate
802 /// This is the avatar's movement control + PID Controller 802 /// This is the avatar's movement control + PID Controller
803 /// </summary> 803 /// </summary>
804 /// <param name="timeStep"></param> 804 /// <param name="timeStep"></param>
805 public void Move(float timeStep) 805 public void Move(float timeStep)
806 { 806 {
807 // no lock; for now it's only called from within Simulate() 807 // no lock; for now it's only called from within Simulate()
808 808
809 // If the PID Controller isn't active then we set our force 809 // If the PID Controller isn't active then we set our force
810 // calculating base velocity to the current position 810 // calculating base velocity to the current position
811 if (Body == null) 811 if (Body == null)
812 return; 812 return;
813 tempTrans1.Dispose(); 813 tempTrans1.Dispose();
814 tempTrans1 = Body.getInterpolationWorldTransform(); 814 tempTrans1 = Body.getInterpolationWorldTransform();
815 tempVector1.Dispose(); 815 tempVector1.Dispose();
816 tempVector1 = tempTrans1.getOrigin(); 816 tempVector1 = tempTrans1.getOrigin();
817 tempVector2.Dispose(); 817 tempVector2.Dispose();
818 tempVector2 = Body.getInterpolationLinearVelocity(); 818 tempVector2 = Body.getInterpolationLinearVelocity();
819 819
820 if (m_pidControllerActive == false) 820 if (m_pidControllerActive == false)
821 { 821 {
822 m_zeroPosition.X = tempVector1.getX(); 822 m_zeroPosition.X = tempVector1.getX();
823 m_zeroPosition.Y = tempVector1.getY(); 823 m_zeroPosition.Y = tempVector1.getY();
824 m_zeroPosition.Z = tempVector1.getZ(); 824 m_zeroPosition.Z = tempVector1.getZ();
825 } 825 }
826 //PidStatus = true; 826 //PidStatus = true;
827 827
828 PhysicsVector vec = new PhysicsVector(); 828 PhysicsVector vec = new PhysicsVector();
829 829
830 PhysicsVector vel = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); 830 PhysicsVector vel = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ());
831 831
832 float movementdivisor = 1f; 832 float movementdivisor = 1f;
833 833
834 if (!m_alwaysRun) 834 if (!m_alwaysRun)
835 { 835 {
836 movementdivisor = walkDivisor; 836 movementdivisor = walkDivisor;
837 } 837 }
838 else 838 else
839 { 839 {
840 movementdivisor = runDivisor; 840 movementdivisor = runDivisor;
841 } 841 }
842 842
843 // if velocity is zero, use position control; otherwise, velocity control 843 // if velocity is zero, use position control; otherwise, velocity control
844 if (m_target_velocity.X == 0.0f && m_target_velocity.Y == 0.0f && m_target_velocity.Z == 0.0f && m_iscolliding) 844 if (m_target_velocity.X == 0.0f && m_target_velocity.Y == 0.0f && m_target_velocity.Z == 0.0f && m_iscolliding)
845 { 845 {
846 // keep track of where we stopped. No more slippin' & slidin' 846 // keep track of where we stopped. No more slippin' & slidin'
847 if (!m_zeroFlag) 847 if (!m_zeroFlag)
848 { 848 {
849 m_zeroFlag = true; 849 m_zeroFlag = true;
850 m_zeroPosition.X = tempVector1.getX(); 850 m_zeroPosition.X = tempVector1.getX();
851 m_zeroPosition.Y = tempVector1.getY(); 851 m_zeroPosition.Y = tempVector1.getY();
852 m_zeroPosition.Z = tempVector1.getZ(); 852 m_zeroPosition.Z = tempVector1.getZ();
853 } 853 }
854 if (m_pidControllerActive) 854 if (m_pidControllerActive)
855 { 855 {
856 // We only want to deactivate the PID Controller if we think we want to have our surrogate 856 // We only want to deactivate the PID Controller if we think we want to have our surrogate
857 // react to the physics scene by moving it's position. 857 // react to the physics scene by moving it's position.
858 // Avatar to Avatar collisions 858 // Avatar to Avatar collisions
859 // Prim to avatar collisions 859 // Prim to avatar collisions
860 860
861 PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); 861 PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ());
862 vec.X = (m_target_velocity.X - vel.X) * (PID_D) + (m_zeroPosition.X - pos.X) * (PID_P * 2); 862 vec.X = (m_target_velocity.X - vel.X) * (PID_D) + (m_zeroPosition.X - pos.X) * (PID_P * 2);
863 vec.Y = (m_target_velocity.Y - vel.Y) * (PID_D) + (m_zeroPosition.Y - pos.Y) * (PID_P * 2); 863 vec.Y = (m_target_velocity.Y - vel.Y) * (PID_D) + (m_zeroPosition.Y - pos.Y) * (PID_P * 2);
864 if (m_flying) 864 if (m_flying)
865 { 865 {
866 vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D) + (m_zeroPosition.Z - pos.Z) * PID_P; 866 vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D) + (m_zeroPosition.Z - pos.Z) * PID_P;
867 } 867 }
868 } 868 }
869 //PidStatus = true; 869 //PidStatus = true;
870 } 870 }
871 else 871 else
872 { 872 {
873 m_pidControllerActive = true; 873 m_pidControllerActive = true;
874 m_zeroFlag = false; 874 m_zeroFlag = false;
875 if (m_iscolliding && !m_flying) 875 if (m_iscolliding && !m_flying)
876 { 876 {
877 // We're standing on something 877 // We're standing on something
878 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D); 878 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D);
879 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D); 879 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D);
880 } 880 }
881 else if (m_iscolliding && m_flying) 881 else if (m_iscolliding && m_flying)
882 { 882 {
883 // We're flying and colliding with something 883 // We're flying and colliding with something
884 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 16); 884 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 16);
885 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 16); 885 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 16);
886 } 886 }
887 else if (!m_iscolliding && m_flying) 887 else if (!m_iscolliding && m_flying)
888 { 888 {
889 // we're in mid air suspended 889 // we're in mid air suspended
890 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 6); 890 vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 6);
891 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 6); 891 vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 6);
892 } 892 }
893 893
894 if (m_iscolliding && !m_flying && m_target_velocity.Z > 0.0f) 894 if (m_iscolliding && !m_flying && m_target_velocity.Z > 0.0f)
895 { 895 {
896 // We're colliding with something and we're not flying but we're moving 896 // We're colliding with something and we're not flying but we're moving
897 // This means we're walking or running. 897 // This means we're walking or running.
898 PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); 898 PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ());
899 vec.Z = (m_target_velocity.Z - vel.Z) * PID_D + (m_zeroPosition.Z - pos.Z) * PID_P; 899 vec.Z = (m_target_velocity.Z - vel.Z) * PID_D + (m_zeroPosition.Z - pos.Z) * PID_P;
900 if (m_target_velocity.X > 0) 900 if (m_target_velocity.X > 0)
901 { 901 {
902 vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; 902 vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D;
903 } 903 }
904 if (m_target_velocity.Y > 0) 904 if (m_target_velocity.Y > 0)
905 { 905 {
906 vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; 906 vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D;
907 } 907 }
908 } 908 }
909 else if (!m_iscolliding && !m_flying) 909 else if (!m_iscolliding && !m_flying)
910 { 910 {
911 // we're not colliding and we're not flying so that means we're falling! 911 // we're not colliding and we're not flying so that means we're falling!
912 // m_iscolliding includes collisions with the ground. 912 // m_iscolliding includes collisions with the ground.
913 913
914 // d.Vector3 pos = d.BodyGetPosition(Body); 914 // d.Vector3 pos = d.BodyGetPosition(Body);
915 if (m_target_velocity.X > 0) 915 if (m_target_velocity.X > 0)
916 { 916 {
917 vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; 917 vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D;
918 } 918 }
919 if (m_target_velocity.Y > 0) 919 if (m_target_velocity.Y > 0)
920 { 920 {
921 vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; 921 vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D;
922 } 922 }
923 } 923 }
924 924
925 925
926 if (m_flying) 926 if (m_flying)
927 { 927 {
928 vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D); 928 vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D);
929 } 929 }
930 } 930 }
931 if (m_flying) 931 if (m_flying)
932 { 932 {
933 //vec.Z += ((-1 * m_parent_scene.gravityz) * m_mass); 933 //vec.Z += ((-1 * m_parent_scene.gravityz) * m_mass);
934 } 934 }
935 if (Body != null && (((m_target_velocity.X > 0.2f || m_target_velocity.X < -0.2f) || (m_target_velocity.Y > 0.2f || m_target_velocity.Y < -0.2f)))) 935 if (Body != null && (((m_target_velocity.X > 0.2f || m_target_velocity.X < -0.2f) || (m_target_velocity.Y > 0.2f || m_target_velocity.Y < -0.2f))))
936 { 936 {
937 Body.setFriction(0.001f); 937 Body.setFriction(0.001f);
938 //m_log.DebugFormat("[PHYSICS]: Avatar force applied: {0}, Target:{1}", vec.ToString(), m_target_velocity.ToString()); 938 //m_log.DebugFormat("[PHYSICS]: Avatar force applied: {0}, Target:{1}", vec.ToString(), m_target_velocity.ToString());
939 } 939 }
940 940
941 if (Body != null) 941 if (Body != null)
942 { 942 {
943 int activationstate = Body.getActivationState(); 943 int activationstate = Body.getActivationState();
944 if (activationstate == 0) 944 if (activationstate == 0)
945 { 945 {
946 Body.forceActivationState(1); 946 Body.forceActivationState(1);
947 } 947 }
948 948
949 949
950 } 950 }
951 doImpulse(vec, true); 951 doImpulse(vec, true);
952 } 952 }
953 953
954 /// <summary> 954 /// <summary>
955 /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. 955 /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence.
956 /// </summary> 956 /// </summary>
957 public void UpdatePositionAndVelocity() 957 public void UpdatePositionAndVelocity()
958 { 958 {
959 if (Body == null) 959 if (Body == null)
960 return; 960 return;
961 //int val = Environment.TickCount; 961 //int val = Environment.TickCount;
962 CheckIfStandingOnObject(); 962 CheckIfStandingOnObject();
963 //m_log.DebugFormat("time:{0}", Environment.TickCount - val); 963 //m_log.DebugFormat("time:{0}", Environment.TickCount - val);
964 964
965 //IsColliding = Body.checkCollideWith(m_parent_scene.TerrainBody); 965 //IsColliding = Body.checkCollideWith(m_parent_scene.TerrainBody);
966 966
967 tempTrans1.Dispose(); 967 tempTrans1.Dispose();
968 tempTrans1 = Body.getInterpolationWorldTransform(); 968 tempTrans1 = Body.getInterpolationWorldTransform();
969 tempVector1.Dispose(); 969 tempVector1.Dispose();
970 tempVector1 = tempTrans1.getOrigin(); 970 tempVector1 = tempTrans1.getOrigin();
971 tempVector2.Dispose(); 971 tempVector2.Dispose();
972 tempVector2 = Body.getInterpolationLinearVelocity(); 972 tempVector2 = Body.getInterpolationLinearVelocity();
973 973
974 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 974 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
975 PhysicsVector vec = new PhysicsVector(tempVector1.getX(),tempVector1.getY(),tempVector1.getZ()); 975 PhysicsVector vec = new PhysicsVector(tempVector1.getX(),tempVector1.getY(),tempVector1.getZ());
976 976
977 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) 977 // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
978 if (vec.X < 0.0f) vec.X = 0.0f; 978 if (vec.X < 0.0f) vec.X = 0.0f;
979 if (vec.Y < 0.0f) vec.Y = 0.0f; 979 if (vec.Y < 0.0f) vec.Y = 0.0f;
980 if (vec.X > (int)Constants.RegionSize - 0.2f) vec.X = (int)Constants.RegionSize - 0.2f; 980 if (vec.X > (int)Constants.RegionSize - 0.2f) vec.X = (int)Constants.RegionSize - 0.2f;
981 if (vec.Y > (int)Constants.RegionSize - 0.2f) vec.Y = (int)Constants.RegionSize - 0.2f; 981 if (vec.Y > (int)Constants.RegionSize - 0.2f) vec.Y = (int)Constants.RegionSize - 0.2f;
982 982
983 m_position.X = vec.X; 983 m_position.X = vec.X;
984 m_position.Y = vec.Y; 984 m_position.Y = vec.Y;
985 m_position.Z = vec.Z; 985 m_position.Z = vec.Z;
986 986
987 // Did we move last? = zeroflag 987 // Did we move last? = zeroflag
988 // This helps keep us from sliding all over 988 // This helps keep us from sliding all over
989 989
990 if (m_zeroFlag) 990 if (m_zeroFlag)
991 { 991 {
992 m_velocity.X = 0.0f; 992 m_velocity.X = 0.0f;
993 m_velocity.Y = 0.0f; 993 m_velocity.Y = 0.0f;
994 m_velocity.Z = 0.0f; 994 m_velocity.Z = 0.0f;
995 995
996 // Did we send out the 'stopped' message? 996 // Did we send out the 'stopped' message?
997 if (!m_lastUpdateSent) 997 if (!m_lastUpdateSent)
998 { 998 {
999 m_lastUpdateSent = true; 999 m_lastUpdateSent = true;
1000 //base.RequestPhysicsterseUpdate(); 1000 //base.RequestPhysicsterseUpdate();
1001 1001
1002 } 1002 }
1003 } 1003 }
1004 else 1004 else
1005 { 1005 {
1006 m_lastUpdateSent = false; 1006 m_lastUpdateSent = false;
1007 vec = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); 1007 vec = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ());
1008 m_velocity.X = (vec.X); 1008 m_velocity.X = (vec.X);
1009 m_velocity.Y = (vec.Y); 1009 m_velocity.Y = (vec.Y);
1010 1010
1011 m_velocity.Z = (vec.Z); 1011 m_velocity.Z = (vec.Z);
1012 1012
1013 if (m_velocity.Z < -6 && !m_hackSentFall) 1013 if (m_velocity.Z < -6 && !m_hackSentFall)
1014 { 1014 {
1015 m_hackSentFall = true; 1015 m_hackSentFall = true;
1016 m_pidControllerActive = false; 1016 m_pidControllerActive = false;
1017 } 1017 }
1018 else if (m_flying && !m_hackSentFly) 1018 else if (m_flying && !m_hackSentFly)
1019 { 1019 {
1020 //m_hackSentFly = true; 1020 //m_hackSentFly = true;
1021 //base.SendCollisionUpdate(new CollisionEventUpdate()); 1021 //base.SendCollisionUpdate(new CollisionEventUpdate());
1022 } 1022 }
1023 else 1023 else
1024 { 1024 {
1025 m_hackSentFly = false; 1025 m_hackSentFly = false;
1026 m_hackSentFall = false; 1026 m_hackSentFall = false;
1027 } 1027 }
1028 } 1028 }
1029 if (Body != null) 1029 if (Body != null)
1030 { 1030 {
1031 if (Body.getFriction() < 0.9f) 1031 if (Body.getFriction() < 0.9f)
1032 Body.setFriction(0.9f); 1032 Body.setFriction(0.9f);
1033 } 1033 }
1034 //if (Body != null) 1034 //if (Body != null)
1035 // Body.clearForces(); 1035 // Body.clearForces();
1036 } 1036 }
1037 1037
1038 public void CheckIfStandingOnObject() 1038 public void CheckIfStandingOnObject()
1039 { 1039 {
1040 1040
1041 float capsuleHalfHeight = ((CAPSULE_LENGTH + 2*CAPSULE_RADIUS)*0.5f); 1041 float capsuleHalfHeight = ((CAPSULE_LENGTH + 2*CAPSULE_RADIUS)*0.5f);
1042 1042
1043 tempVector5RayCast.setValue(m_position.X, m_position.Y, m_position.Z); 1043 tempVector5RayCast.setValue(m_position.X, m_position.Y, m_position.Z);
1044 tempVector6RayCast.setValue(m_position.X, m_position.Y, m_position.Z - 1 * capsuleHalfHeight * 1.1f); 1044 tempVector6RayCast.setValue(m_position.X, m_position.Y, m_position.Z - 1 * capsuleHalfHeight * 1.1f);
1045 1045
1046 1046
1047 ClosestCastResult.Dispose(); 1047 ClosestCastResult.Dispose();
1048 ClosestCastResult = new ClosestNotMeRayResultCallback(Body); 1048 ClosestCastResult = new ClosestNotMeRayResultCallback(Body);
1049 1049
1050 try 1050 try
1051 { 1051 {
1052 m_parent_scene.getBulletWorld().rayTest(tempVector5RayCast, tempVector6RayCast, ClosestCastResult); 1052 m_parent_scene.getBulletWorld().rayTest(tempVector5RayCast, tempVector6RayCast, ClosestCastResult);
1053 } 1053 }
1054 catch (AccessViolationException) 1054 catch (AccessViolationException)
1055 { 1055 {
1056 m_log.Debug("BAD!"); 1056 m_log.Debug("BAD!");
1057 } 1057 }
1058 if (ClosestCastResult.hasHit()) 1058 if (ClosestCastResult.hasHit())
1059 { 1059 {
1060 1060
1061 if (tempVector7RayCast != null) 1061 if (tempVector7RayCast != null)
1062 tempVector7RayCast.Dispose(); 1062 tempVector7RayCast.Dispose();
1063 1063
1064 //tempVector7RayCast = ClosestCastResult.getHitPointWorld(); 1064 //tempVector7RayCast = ClosestCastResult.getHitPointWorld();
1065 1065
1066 /*if (tempVector7RayCast == null) // null == no result also 1066 /*if (tempVector7RayCast == null) // null == no result also
1067 { 1067 {
1068 CollidingObj = false; 1068 CollidingObj = false;
1069 IsColliding = false; 1069 IsColliding = false;
1070 CollidingGround = false; 1070 CollidingGround = false;
1071 1071
1072 return; 1072 return;
1073 } 1073 }
1074 float zVal = tempVector7RayCast.getZ(); 1074 float zVal = tempVector7RayCast.getZ();
1075 if (zVal != 0) 1075 if (zVal != 0)
1076 m_log.Debug("[PHYSICS]: HAAAA"); 1076 m_log.Debug("[PHYSICS]: HAAAA");
1077 if (zVal < m_position.Z && zVal > ((CAPSULE_LENGTH + 2 * CAPSULE_RADIUS) *0.5f)) 1077 if (zVal < m_position.Z && zVal > ((CAPSULE_LENGTH + 2 * CAPSULE_RADIUS) *0.5f))
1078 { 1078 {
1079 CollidingObj = true; 1079 CollidingObj = true;
1080 IsColliding = true; 1080 IsColliding = true;
1081 } 1081 }
1082 else 1082 else
1083 { 1083 {
1084 CollidingObj = false; 1084 CollidingObj = false;
1085 IsColliding = false; 1085 IsColliding = false;
1086 CollidingGround = false; 1086 CollidingGround = false;
1087 }*/ 1087 }*/
1088 1088
1089 //height+2*radius = capsule full length 1089 //height+2*radius = capsule full length
1090 //CollidingObj = true; 1090 //CollidingObj = true;
1091 //IsColliding = true; 1091 //IsColliding = true;
1092 m_iscolliding = true; 1092 m_iscolliding = true;
1093 } 1093 }
1094 else 1094 else
1095 { 1095 {
1096 //CollidingObj = false; 1096 //CollidingObj = false;
1097 //IsColliding = false; 1097 //IsColliding = false;
1098 //CollidingGround = false; 1098 //CollidingGround = false;
1099 m_iscolliding = false; 1099 m_iscolliding = false;
1100 } 1100 }
1101 } 1101 }
1102 } 1102 }
1103 1103
1104} 1104}
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPlugin.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPlugin.cs
index 262e5c3..cf75c48 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPlugin.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPlugin.cs
@@ -1,65 +1,65 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using OpenSim.Region.Physics.Manager; 28using OpenSim.Region.Physics.Manager;
29 29
30namespace OpenSim.Region.Physics.BulletDotNETPlugin 30namespace OpenSim.Region.Physics.BulletDotNETPlugin
31{ 31{
32 public class BulletDotNetPlugin : IPhysicsPlugin 32 public class BulletDotNetPlugin : IPhysicsPlugin
33 { 33 {
34 private BulletDotNETScene m_scene; 34 private BulletDotNETScene m_scene;
35 private const string m_pluginName = "BulletDotNETPlugin"; 35 private const string m_pluginName = "BulletDotNETPlugin";
36 36
37 #region IPhysicsPlugin Members 37 #region IPhysicsPlugin Members
38 38
39 public bool Init() 39 public bool Init()
40 { 40 {
41 return true; 41 return true;
42 } 42 }
43 43
44 public PhysicsScene GetScene(string sceneIdentifier) 44 public PhysicsScene GetScene(string sceneIdentifier)
45 { 45 {
46 if (m_scene == null) 46 if (m_scene == null)
47 { 47 {
48 m_scene = new BulletDotNETScene(sceneIdentifier); 48 m_scene = new BulletDotNETScene(sceneIdentifier);
49 } 49 }
50 return m_scene; 50 return m_scene;
51 } 51 }
52 52
53 public string GetName() 53 public string GetName()
54 { 54 {
55 return m_pluginName; 55 return m_pluginName;
56 } 56 }
57 57
58 public void Dispose() 58 public void Dispose()
59 { 59 {
60 60
61 } 61 }
62 62
63 #endregion 63 #endregion
64 } 64 }
65} \ No newline at end of file 65} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPluginStructs.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPluginStructs.cs
index 382f445..26517dc 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPluginStructs.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPluginStructs.cs
@@ -1,33 +1,33 @@
1using System; 1using System;
2 2
3public enum StatusIndicators : int 3public enum StatusIndicators : int
4{ 4{
5 Generic = 0, 5 Generic = 0,
6 Start = 1, 6 Start = 1,
7 End = 2 7 End = 2
8} 8}
9 9
10public struct sCollisionData 10public struct sCollisionData
11{ 11{
12 public uint ColliderLocalId; 12 public uint ColliderLocalId;
13 public uint CollidedWithLocalId; 13 public uint CollidedWithLocalId;
14 public int NumberOfCollisions; 14 public int NumberOfCollisions;
15 public int CollisionType; 15 public int CollisionType;
16 public int StatusIndicator; 16 public int StatusIndicator;
17 public int lastframe; 17 public int lastframe;
18} 18}
19 19
20[Flags] 20[Flags]
21public enum CollisionCategories : int 21public enum CollisionCategories : int
22{ 22{
23 Disabled = 0, 23 Disabled = 0,
24 Geom = 0x00000001, 24 Geom = 0x00000001,
25 Body = 0x00000002, 25 Body = 0x00000002,
26 Space = 0x00000004, 26 Space = 0x00000004,
27 Character = 0x00000008, 27 Character = 0x00000008,
28 Land = 0x00000010, 28 Land = 0x00000010,
29 Water = 0x00000020, 29 Water = 0x00000020,
30 Wind = 0x00000040, 30 Wind = 0x00000040,
31 Sensor = 0x00000080, 31 Sensor = 0x00000080,
32 Selected = 0x00000100 32 Selected = 0x00000100
33} \ No newline at end of file 33} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
index 3e26456..6fb82ef 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
@@ -1,2131 +1,2131 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection; 29using System.Reflection;
30using System.Runtime.InteropServices; 30using System.Runtime.InteropServices;
31using System.Threading; 31using System.Threading;
32using log4net; 32using log4net;
33using OpenMetaverse; 33using OpenMetaverse;
34using BulletDotNET; 34using BulletDotNET;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Physics.Manager; 36using OpenSim.Region.Physics.Manager;
37 37
38namespace OpenSim.Region.Physics.BulletDotNETPlugin 38namespace OpenSim.Region.Physics.BulletDotNETPlugin
39{ 39{
40 public class BulletDotNETPrim : PhysicsActor 40 public class BulletDotNETPrim : PhysicsActor
41 { 41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 private PhysicsVector _position; 44 private PhysicsVector _position;
45 private PhysicsVector _velocity; 45 private PhysicsVector _velocity;
46 private PhysicsVector _torque = new PhysicsVector(0, 0, 0); 46 private PhysicsVector _torque = new PhysicsVector(0, 0, 0);
47 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 47 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f);
48 private PhysicsVector m_lastposition = new PhysicsVector(0.0f, 0.0f, 0.0f); 48 private PhysicsVector m_lastposition = new PhysicsVector(0.0f, 0.0f, 0.0f);
49 private Quaternion m_lastorientation = new Quaternion(); 49 private Quaternion m_lastorientation = new Quaternion();
50 private PhysicsVector m_rotationalVelocity; 50 private PhysicsVector m_rotationalVelocity;
51 private PhysicsVector _size; 51 private PhysicsVector _size;
52 private PhysicsVector _acceleration; 52 private PhysicsVector _acceleration;
53 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f); 53 // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f);
54 private Quaternion _orientation; 54 private Quaternion _orientation;
55 private PhysicsVector m_taintposition; 55 private PhysicsVector m_taintposition;
56 private PhysicsVector m_taintsize; 56 private PhysicsVector m_taintsize;
57 private PhysicsVector m_taintVelocity = new PhysicsVector(0, 0, 0); 57 private PhysicsVector m_taintVelocity = new PhysicsVector(0, 0, 0);
58 private PhysicsVector m_taintTorque = new PhysicsVector(0, 0, 0); 58 private PhysicsVector m_taintTorque = new PhysicsVector(0, 0, 0);
59 private Quaternion m_taintrot; 59 private Quaternion m_taintrot;
60 private PhysicsVector m_angularlock = new PhysicsVector(1f, 1f, 1f); 60 private PhysicsVector m_angularlock = new PhysicsVector(1f, 1f, 1f);
61 private PhysicsVector m_taintAngularLock = new PhysicsVector(1f, 1f, 1f); 61 private PhysicsVector m_taintAngularLock = new PhysicsVector(1f, 1f, 1f);
62 private btGeneric6DofConstraint Amotor; 62 private btGeneric6DofConstraint Amotor;
63 63
64 private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); 64 private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0);
65 private float m_PIDTau = 0f; 65 private float m_PIDTau = 0f;
66 private float m_PIDHoverHeight = 0f; 66 private float m_PIDHoverHeight = 0f;
67 private float m_PIDHoverTau = 0f; 67 private float m_PIDHoverTau = 0f;
68 private bool m_useHoverPID = false; 68 private bool m_useHoverPID = false;
69 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; 69 private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
70 private float m_targetHoverHeight = 0f; 70 private float m_targetHoverHeight = 0f;
71 private float m_groundHeight = 0f; 71 private float m_groundHeight = 0f;
72 private float m_waterHeight = 0f; 72 private float m_waterHeight = 0f;
73 private float PID_D = 35f; 73 private float PID_D = 35f;
74 private float PID_G = 25f; 74 private float PID_G = 25f;
75 private float m_tensor = 5f; 75 private float m_tensor = 5f;
76 private int body_autodisable_frames = 20; 76 private int body_autodisable_frames = 20;
77 private IMesh primMesh = null; 77 private IMesh primMesh = null;
78 78
79 private bool m_usePID = false; 79 private bool m_usePID = false;
80 80
81 81
82 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom 82 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
83 | CollisionCategories.Space 83 | CollisionCategories.Space
84 | CollisionCategories.Body 84 | CollisionCategories.Body
85 | CollisionCategories.Character 85 | CollisionCategories.Character
86 ); 86 );
87 87
88 private bool m_taintshape = false; 88 private bool m_taintshape = false;
89 private bool m_taintPhysics = false; 89 private bool m_taintPhysics = false;
90 private bool m_collidesLand = true; 90 private bool m_collidesLand = true;
91 private bool m_collidesWater = false; 91 private bool m_collidesWater = false;
92 public bool m_returnCollisions = false; 92 public bool m_returnCollisions = false;
93 93
94 // Default we're a Geometry 94 // Default we're a Geometry
95 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom); 95 private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
96 96
97 // Default, Collide with Other Geometries, spaces and Bodies 97 // Default, Collide with Other Geometries, spaces and Bodies
98 private CollisionCategories m_collisionFlags = m_default_collisionFlags; 98 private CollisionCategories m_collisionFlags = m_default_collisionFlags;
99 99
100 public bool m_taintremove = false; 100 public bool m_taintremove = false;
101 public bool m_taintdisable = false; 101 public bool m_taintdisable = false;
102 public bool m_disabled = false; 102 public bool m_disabled = false;
103 public bool m_taintadd = false; 103 public bool m_taintadd = false;
104 public bool m_taintselected = false; 104 public bool m_taintselected = false;
105 public bool m_taintCollidesWater = false; 105 public bool m_taintCollidesWater = false;
106 106
107 public uint m_localID = 0; 107 public uint m_localID = 0;
108 108
109 //public GCHandle gc; 109 //public GCHandle gc;
110 private CollisionLocker ode; 110 private CollisionLocker ode;
111 111
112 private bool m_taintforce = false; 112 private bool m_taintforce = false;
113 private bool m_taintaddangularforce = false; 113 private bool m_taintaddangularforce = false;
114 private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f); 114 private PhysicsVector m_force = new PhysicsVector(0.0f, 0.0f, 0.0f);
115 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>(); 115 private List<PhysicsVector> m_forcelist = new List<PhysicsVector>();
116 private List<PhysicsVector> m_angularforcelist = new List<PhysicsVector>(); 116 private List<PhysicsVector> m_angularforcelist = new List<PhysicsVector>();
117 117
118 private IMesh _mesh; 118 private IMesh _mesh;
119 private PrimitiveBaseShape _pbs; 119 private PrimitiveBaseShape _pbs;
120 private BulletDotNETScene _parent_scene; 120 private BulletDotNETScene _parent_scene;
121 public btCollisionShape prim_geom; 121 public btCollisionShape prim_geom;
122 public IntPtr _triMeshData; 122 public IntPtr _triMeshData;
123 123
124 private PhysicsActor _parent = null; 124 private PhysicsActor _parent = null;
125 private PhysicsActor m_taintparent = null; 125 private PhysicsActor m_taintparent = null;
126 126
127 private List<BulletDotNETPrim> childrenPrim = new List<BulletDotNETPrim>(); 127 private List<BulletDotNETPrim> childrenPrim = new List<BulletDotNETPrim>();
128 128
129 private bool iscolliding = false; 129 private bool iscolliding = false;
130 private bool m_isphysical = false; 130 private bool m_isphysical = false;
131 private bool m_isSelected = false; 131 private bool m_isSelected = false;
132 132
133 internal bool m_isVolumeDetect = false; // If true, this prim only detects collisions but doesn't collide actively 133 internal bool m_isVolumeDetect = false; // If true, this prim only detects collisions but doesn't collide actively
134 134
135 private bool m_throttleUpdates = false; 135 private bool m_throttleUpdates = false;
136 private int throttleCounter = 0; 136 private int throttleCounter = 0;
137 public int m_interpenetrationcount = 0; 137 public int m_interpenetrationcount = 0;
138 public float m_collisionscore = 0; 138 public float m_collisionscore = 0;
139 public int m_roundsUnderMotionThreshold = 0; 139 public int m_roundsUnderMotionThreshold = 0;
140 private int m_crossingfailures = 0; 140 private int m_crossingfailures = 0;
141 141
142 public float m_buoyancy = 0f; 142 public float m_buoyancy = 0f;
143 143
144 public bool outofBounds = false; 144 public bool outofBounds = false;
145 private float m_density = 10.000006836f; // Aluminum g/cm3; 145 private float m_density = 10.000006836f; // Aluminum g/cm3;
146 146
147 public bool _zeroFlag = false; 147 public bool _zeroFlag = false;
148 private bool m_lastUpdateSent = false; 148 private bool m_lastUpdateSent = false;
149 149
150 150
151 private String m_primName; 151 private String m_primName;
152 private PhysicsVector _target_velocity; 152 private PhysicsVector _target_velocity;
153 153
154 public int m_eventsubscription = 0; 154 public int m_eventsubscription = 0;
155 private CollisionEventUpdate CollisionEventsThisFrame = null; 155 private CollisionEventUpdate CollisionEventsThisFrame = null;
156 156
157 public volatile bool childPrim = false; 157 public volatile bool childPrim = false;
158 158
159 private btVector3 tempPosition1; 159 private btVector3 tempPosition1;
160 private btVector3 tempPosition2; 160 private btVector3 tempPosition2;
161 private btVector3 tempPosition3; 161 private btVector3 tempPosition3;
162 private btVector3 tempSize1; 162 private btVector3 tempSize1;
163 private btVector3 tempSize2; 163 private btVector3 tempSize2;
164 private btVector3 tempLinearVelocity1; 164 private btVector3 tempLinearVelocity1;
165 private btVector3 tempLinearVelocity2; 165 private btVector3 tempLinearVelocity2;
166 private btVector3 tempAngularVelocity1; 166 private btVector3 tempAngularVelocity1;
167 private btVector3 tempAngularVelocity2; 167 private btVector3 tempAngularVelocity2;
168 private btVector3 tempInertia1; 168 private btVector3 tempInertia1;
169 private btVector3 tempInertia2; 169 private btVector3 tempInertia2;
170 private btQuaternion tempOrientation1; 170 private btQuaternion tempOrientation1;
171 private btQuaternion tempOrientation2; 171 private btQuaternion tempOrientation2;
172 private btMotionState tempMotionState1; 172 private btMotionState tempMotionState1;
173 private btMotionState tempMotionState2; 173 private btMotionState tempMotionState2;
174 private btMotionState tempMotionState3; 174 private btMotionState tempMotionState3;
175 private btTransform tempTransform1; 175 private btTransform tempTransform1;
176 private btTransform tempTransform2; 176 private btTransform tempTransform2;
177 private btTransform tempTransform3; 177 private btTransform tempTransform3;
178 private btTransform tempTransform4; 178 private btTransform tempTransform4;
179 private btTriangleIndexVertexArray btshapeArray; 179 private btTriangleIndexVertexArray btshapeArray;
180 180
181 public btRigidBody Body; 181 public btRigidBody Body;
182 182
183 public BulletDotNETPrim(String primName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, 183 public BulletDotNETPrim(String primName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size,
184 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical) 184 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical)
185 { 185 {
186 tempPosition1 = new btVector3(0, 0, 0); 186 tempPosition1 = new btVector3(0, 0, 0);
187 tempPosition2 = new btVector3(0, 0, 0); 187 tempPosition2 = new btVector3(0, 0, 0);
188 tempPosition3 = new btVector3(0, 0, 0); 188 tempPosition3 = new btVector3(0, 0, 0);
189 tempSize1 = new btVector3(0, 0, 0); 189 tempSize1 = new btVector3(0, 0, 0);
190 tempSize2 = new btVector3(0, 0, 0); 190 tempSize2 = new btVector3(0, 0, 0);
191 tempLinearVelocity1 = new btVector3(0, 0, 0); 191 tempLinearVelocity1 = new btVector3(0, 0, 0);
192 tempLinearVelocity2 = new btVector3(0, 0, 0); 192 tempLinearVelocity2 = new btVector3(0, 0, 0);
193 tempAngularVelocity1 = new btVector3(0, 0, 0); 193 tempAngularVelocity1 = new btVector3(0, 0, 0);
194 tempAngularVelocity2 = new btVector3(0, 0, 0); 194 tempAngularVelocity2 = new btVector3(0, 0, 0);
195 tempInertia1 = new btVector3(0, 0, 0); 195 tempInertia1 = new btVector3(0, 0, 0);
196 tempInertia2 = new btVector3(0, 0, 0); 196 tempInertia2 = new btVector3(0, 0, 0);
197 tempOrientation1 = new btQuaternion(0,0,0,1); 197 tempOrientation1 = new btQuaternion(0,0,0,1);
198 tempOrientation2 = new btQuaternion(0, 0, 0, 1); 198 tempOrientation2 = new btQuaternion(0, 0, 0, 1);
199 _parent_scene = parent_scene; 199 _parent_scene = parent_scene;
200 tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); 200 tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero);
201 tempTransform2 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ; 201 tempTransform2 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;
202 tempTransform3 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ; 202 tempTransform3 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;
203 tempTransform4 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ; 203 tempTransform4 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); ;
204 204
205 tempMotionState1 = new btDefaultMotionState(_parent_scene.TransZero); 205 tempMotionState1 = new btDefaultMotionState(_parent_scene.TransZero);
206 tempMotionState2 = new btDefaultMotionState(_parent_scene.TransZero); 206 tempMotionState2 = new btDefaultMotionState(_parent_scene.TransZero);
207 tempMotionState3 = new btDefaultMotionState(_parent_scene.TransZero); 207 tempMotionState3 = new btDefaultMotionState(_parent_scene.TransZero);
208 208
209 _target_velocity = new PhysicsVector(0, 0, 0); 209 _target_velocity = new PhysicsVector(0, 0, 0);
210 _velocity = new PhysicsVector(); 210 _velocity = new PhysicsVector();
211 _position = pos; 211 _position = pos;
212 m_taintposition = pos; 212 m_taintposition = pos;
213 PID_D = parent_scene.bodyPIDD; 213 PID_D = parent_scene.bodyPIDD;
214 PID_G = parent_scene.bodyPIDG; 214 PID_G = parent_scene.bodyPIDG;
215 m_density = parent_scene.geomDefaultDensity; 215 m_density = parent_scene.geomDefaultDensity;
216 m_tensor = parent_scene.bodyMotorJointMaxforceTensor; 216 m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
217 body_autodisable_frames = parent_scene.bodyFramesAutoDisable; 217 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
218 218
219 prim_geom = null; 219 prim_geom = null;
220 Body = null; 220 Body = null;
221 221
222 if (size.X <= 0) size.X = 0.01f; 222 if (size.X <= 0) size.X = 0.01f;
223 if (size.Y <= 0) size.Y = 0.01f; 223 if (size.Y <= 0) size.Y = 0.01f;
224 if (size.Z <= 0) size.Z = 0.01f; 224 if (size.Z <= 0) size.Z = 0.01f;
225 225
226 _size = size; 226 _size = size;
227 m_taintsize = _size; 227 m_taintsize = _size;
228 _acceleration = new PhysicsVector(); 228 _acceleration = new PhysicsVector();
229 m_rotationalVelocity = PhysicsVector.Zero; 229 m_rotationalVelocity = PhysicsVector.Zero;
230 _orientation = rotation; 230 _orientation = rotation;
231 m_taintrot = _orientation; 231 m_taintrot = _orientation;
232 _mesh = mesh; 232 _mesh = mesh;
233 _pbs = pbs; 233 _pbs = pbs;
234 234
235 _parent_scene = parent_scene; 235 _parent_scene = parent_scene;
236 236
237 if (pos.Z < 0) 237 if (pos.Z < 0)
238 m_isphysical = false; 238 m_isphysical = false;
239 else 239 else
240 { 240 {
241 m_isphysical = pisPhysical; 241 m_isphysical = pisPhysical;
242 // If we're physical, we need to be in the master space for now. 242 // If we're physical, we need to be in the master space for now.
243 // linksets *should* be in a space together.. but are not currently 243 // linksets *should* be in a space together.. but are not currently
244 } 244 }
245 m_primName = primName; 245 m_primName = primName;
246 m_taintadd = true; 246 m_taintadd = true;
247 _parent_scene.AddPhysicsActorTaint(this); 247 _parent_scene.AddPhysicsActorTaint(this);
248 248
249 } 249 }
250 250
251 #region PhysicsActor overrides 251 #region PhysicsActor overrides
252 252
253 public override bool Stopped 253 public override bool Stopped
254 { 254 {
255 get { return _zeroFlag; } 255 get { return _zeroFlag; }
256 } 256 }
257 257
258 public override PhysicsVector Size 258 public override PhysicsVector Size
259 { 259 {
260 get { return _size; } 260 get { return _size; }
261 set { _size = value; } 261 set { _size = value; }
262 } 262 }
263 263
264 public override PrimitiveBaseShape Shape 264 public override PrimitiveBaseShape Shape
265 { 265 {
266 set 266 set
267 { 267 {
268 _pbs = value; 268 _pbs = value;
269 m_taintshape = true; 269 m_taintshape = true;
270 } 270 }
271 } 271 }
272 272
273 public override uint LocalID 273 public override uint LocalID
274 { 274 {
275 set 275 set
276 { 276 {
277 //m_log.Info("[PHYSICS]: Setting TrackerID: " + value); 277 //m_log.Info("[PHYSICS]: Setting TrackerID: " + value);
278 m_localID = value; 278 m_localID = value;
279 } 279 }
280 } 280 }
281 281
282 public override bool Grabbed 282 public override bool Grabbed
283 { 283 {
284 set { return; } 284 set { return; }
285 } 285 }
286 286
287 public override bool Selected 287 public override bool Selected
288 { 288 {
289 set 289 set
290 { 290 {
291 // This only makes the object not collidable if the object 291 // This only makes the object not collidable if the object
292 // is physical or the object is modified somehow *IN THE FUTURE* 292 // is physical or the object is modified somehow *IN THE FUTURE*
293 // without this, if an avatar selects prim, they can walk right 293 // without this, if an avatar selects prim, they can walk right
294 // through it while it's selected 294 // through it while it's selected
295 m_collisionscore = 0; 295 m_collisionscore = 0;
296 if ((m_isphysical && !_zeroFlag) || !value) 296 if ((m_isphysical && !_zeroFlag) || !value)
297 { 297 {
298 m_taintselected = value; 298 m_taintselected = value;
299 _parent_scene.AddPhysicsActorTaint(this); 299 _parent_scene.AddPhysicsActorTaint(this);
300 } 300 }
301 else 301 else
302 { 302 {
303 m_taintselected = value; 303 m_taintselected = value;
304 m_isSelected = value; 304 m_isSelected = value;
305 } 305 }
306 } 306 }
307 } 307 }
308 308
309 public override void CrossingFailure() 309 public override void CrossingFailure()
310 { 310 {
311 m_crossingfailures++; 311 m_crossingfailures++;
312 if (m_crossingfailures > _parent_scene.geomCrossingFailuresBeforeOutofbounds) 312 if (m_crossingfailures > _parent_scene.geomCrossingFailuresBeforeOutofbounds)
313 { 313 {
314 base.RaiseOutOfBounds(_position); 314 base.RaiseOutOfBounds(_position);
315 return; 315 return;
316 } 316 }
317 else if (m_crossingfailures == _parent_scene.geomCrossingFailuresBeforeOutofbounds) 317 else if (m_crossingfailures == _parent_scene.geomCrossingFailuresBeforeOutofbounds)
318 { 318 {
319 m_log.Warn("[PHYSICS]: Too many crossing failures for: " + m_primName); 319 m_log.Warn("[PHYSICS]: Too many crossing failures for: " + m_primName);
320 } 320 }
321 } 321 }
322 public override void link(PhysicsActor obj) 322 public override void link(PhysicsActor obj)
323 { 323 {
324 //TODO: 324 //TODO:
325 } 325 }
326 326
327 public override void delink() 327 public override void delink()
328 { 328 {
329 //TODO: 329 //TODO:
330 } 330 }
331 331
332 public override void LockAngularMotion(PhysicsVector axis) 332 public override void LockAngularMotion(PhysicsVector axis)
333 { 333 {
334 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z); 334 m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
335 m_taintAngularLock = new PhysicsVector(axis.X, axis.Y, axis.Z); 335 m_taintAngularLock = new PhysicsVector(axis.X, axis.Y, axis.Z);
336 } 336 }
337 337
338 public override PhysicsVector Position 338 public override PhysicsVector Position
339 { 339 {
340 get { return _position; } 340 get { return _position; }
341 341
342 set 342 set
343 { 343 {
344 _position = value; 344 _position = value;
345 //m_log.Info("[PHYSICS]: " + _position.ToString()); 345 //m_log.Info("[PHYSICS]: " + _position.ToString());
346 } 346 }
347 } 347 }
348 348
349 public override float Mass 349 public override float Mass
350 { 350 {
351 get { return CalculateMass(); } 351 get { return CalculateMass(); }
352 } 352 }
353 353
354 public override PhysicsVector Force 354 public override PhysicsVector Force
355 { 355 {
356 //get { return PhysicsVector.Zero; } 356 //get { return PhysicsVector.Zero; }
357 get { return m_force; } 357 get { return m_force; }
358 set { m_force = value; } 358 set { m_force = value; }
359 } 359 }
360 360
361 public override int VehicleType 361 public override int VehicleType
362 { 362 {
363 get { return 0; } 363 get { return 0; }
364 set { return; } 364 set { return; }
365 } 365 }
366 366
367 public override void VehicleFloatParam(int param, float value) 367 public override void VehicleFloatParam(int param, float value)
368 { 368 {
369 //TODO: 369 //TODO:
370 } 370 }
371 371
372 public override void VehicleVectorParam(int param, PhysicsVector value) 372 public override void VehicleVectorParam(int param, PhysicsVector value)
373 { 373 {
374 //TODO: 374 //TODO:
375 } 375 }
376 376
377 public override void VehicleRotationParam(int param, Quaternion rotation) 377 public override void VehicleRotationParam(int param, Quaternion rotation)
378 { 378 {
379 //TODO: 379 //TODO:
380 } 380 }
381 381
382 public override void SetVolumeDetect(int param) 382 public override void SetVolumeDetect(int param)
383 { 383 {
384 //TODO: GhostObject 384 //TODO: GhostObject
385 m_isVolumeDetect = (param != 0); 385 m_isVolumeDetect = (param != 0);
386 386
387 } 387 }
388 388
389 public override PhysicsVector GeometricCenter 389 public override PhysicsVector GeometricCenter
390 { 390 {
391 get { return PhysicsVector.Zero; } 391 get { return PhysicsVector.Zero; }
392 } 392 }
393 393
394 public override PhysicsVector CenterOfMass 394 public override PhysicsVector CenterOfMass
395 { 395 {
396 get { return PhysicsVector.Zero; } 396 get { return PhysicsVector.Zero; }
397 } 397 }
398 398
399 public override PhysicsVector Velocity 399 public override PhysicsVector Velocity
400 { 400 {
401 get 401 get
402 { 402 {
403 // Averate previous velocity with the new one so 403 // Averate previous velocity with the new one so
404 // client object interpolation works a 'little' better 404 // client object interpolation works a 'little' better
405 PhysicsVector returnVelocity = new PhysicsVector(); 405 PhysicsVector returnVelocity = new PhysicsVector();
406 returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2; 406 returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2;
407 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2; 407 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2;
408 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2; 408 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2;
409 return returnVelocity; 409 return returnVelocity;
410 } 410 }
411 set 411 set
412 { 412 {
413 _velocity = value; 413 _velocity = value;
414 414
415 m_taintVelocity = value; 415 m_taintVelocity = value;
416 _parent_scene.AddPhysicsActorTaint(this); 416 _parent_scene.AddPhysicsActorTaint(this);
417 } 417 }
418 } 418 }
419 419
420 public override PhysicsVector Torque 420 public override PhysicsVector Torque
421 { 421 {
422 get 422 get
423 { 423 {
424 if (!m_isphysical || Body.Handle == IntPtr.Zero) 424 if (!m_isphysical || Body.Handle == IntPtr.Zero)
425 return new PhysicsVector(0, 0, 0); 425 return new PhysicsVector(0, 0, 0);
426 426
427 return _torque; 427 return _torque;
428 } 428 }
429 429
430 set 430 set
431 { 431 {
432 m_taintTorque = value; 432 m_taintTorque = value;
433 _parent_scene.AddPhysicsActorTaint(this); 433 _parent_scene.AddPhysicsActorTaint(this);
434 } 434 }
435 } 435 }
436 436
437 public override float CollisionScore 437 public override float CollisionScore
438 { 438 {
439 get { return m_collisionscore; } 439 get { return m_collisionscore; }
440 set { m_collisionscore = value; } 440 set { m_collisionscore = value; }
441 } 441 }
442 442
443 public override PhysicsVector Acceleration 443 public override PhysicsVector Acceleration
444 { 444 {
445 get { return _acceleration; } 445 get { return _acceleration; }
446 } 446 }
447 447
448 public override Quaternion Orientation 448 public override Quaternion Orientation
449 { 449 {
450 get { return _orientation; } 450 get { return _orientation; }
451 set { _orientation = value; } 451 set { _orientation = value; }
452 } 452 }
453 453
454 public override int PhysicsActorType 454 public override int PhysicsActorType
455 { 455 {
456 get { return (int)ActorTypes.Prim; } 456 get { return (int)ActorTypes.Prim; }
457 set { return; } 457 set { return; }
458 } 458 }
459 459
460 public override bool IsPhysical 460 public override bool IsPhysical
461 { 461 {
462 get { return m_isphysical; } 462 get { return m_isphysical; }
463 set { m_isphysical = value; } 463 set { m_isphysical = value; }
464 } 464 }
465 465
466 public override bool Flying 466 public override bool Flying
467 { 467 {
468 // no flying prims for you 468 // no flying prims for you
469 get { return false; } 469 get { return false; }
470 set { } 470 set { }
471 } 471 }
472 472
473 public override bool SetAlwaysRun 473 public override bool SetAlwaysRun
474 { 474 {
475 get { return false; } 475 get { return false; }
476 set { return; } 476 set { return; }
477 } 477 }
478 478
479 public override bool ThrottleUpdates 479 public override bool ThrottleUpdates
480 { 480 {
481 get { return m_throttleUpdates; } 481 get { return m_throttleUpdates; }
482 set { m_throttleUpdates = value; } 482 set { m_throttleUpdates = value; }
483 } 483 }
484 484
485 public override bool IsColliding 485 public override bool IsColliding
486 { 486 {
487 get { return iscolliding; } 487 get { return iscolliding; }
488 set { iscolliding = value; } 488 set { iscolliding = value; }
489 } 489 }
490 490
491 public override bool CollidingGround 491 public override bool CollidingGround
492 { 492 {
493 get { return false; } 493 get { return false; }
494 set { return; } 494 set { return; }
495 } 495 }
496 496
497 public override bool CollidingObj 497 public override bool CollidingObj
498 { 498 {
499 get { return false; } 499 get { return false; }
500 set { return; } 500 set { return; }
501 } 501 }
502 502
503 public override bool FloatOnWater 503 public override bool FloatOnWater
504 { 504 {
505 set 505 set
506 { 506 {
507 m_taintCollidesWater = value; 507 m_taintCollidesWater = value;
508 _parent_scene.AddPhysicsActorTaint(this); 508 _parent_scene.AddPhysicsActorTaint(this);
509 } 509 }
510 } 510 }
511 511
512 public override PhysicsVector RotationalVelocity 512 public override PhysicsVector RotationalVelocity
513 { 513 {
514 get 514 get
515 { 515 {
516 PhysicsVector pv = new PhysicsVector(0, 0, 0); 516 PhysicsVector pv = new PhysicsVector(0, 0, 0);
517 if (_zeroFlag) 517 if (_zeroFlag)
518 return pv; 518 return pv;
519 m_lastUpdateSent = false; 519 m_lastUpdateSent = false;
520 520
521 if (m_rotationalVelocity.IsIdentical(pv, 0.2f)) 521 if (m_rotationalVelocity.IsIdentical(pv, 0.2f))
522 return pv; 522 return pv;
523 523
524 return m_rotationalVelocity; 524 return m_rotationalVelocity;
525 } 525 }
526 set { m_rotationalVelocity = value; } 526 set { m_rotationalVelocity = value; }
527 } 527 }
528 528
529 public override bool Kinematic 529 public override bool Kinematic
530 { 530 {
531 get { return false; } 531 get { return false; }
532 set { } 532 set { }
533 } 533 }
534 534
535 public override float Buoyancy 535 public override float Buoyancy
536 { 536 {
537 get { return m_buoyancy; } 537 get { return m_buoyancy; }
538 set { m_buoyancy = value; } 538 set { m_buoyancy = value; }
539 } 539 }
540 540
541 public override PhysicsVector PIDTarget { set { m_PIDTarget = value; ; } } 541 public override PhysicsVector PIDTarget { set { m_PIDTarget = value; ; } }
542 public override bool PIDActive { set { m_usePID = value; } } 542 public override bool PIDActive { set { m_usePID = value; } }
543 public override float PIDTau { set { m_PIDTau = value; } } 543 public override float PIDTau { set { m_PIDTau = value; } }
544 544
545 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } 545 public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
546 public override bool PIDHoverActive { set { m_useHoverPID = value; } } 546 public override bool PIDHoverActive { set { m_useHoverPID = value; } }
547 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } } 547 public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
548 public override float PIDHoverTau { set { m_PIDHoverTau = value; } } 548 public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
549 549
550 550
551 public override void AddForce(PhysicsVector force, bool pushforce) 551 public override void AddForce(PhysicsVector force, bool pushforce)
552 { 552 {
553 m_forcelist.Add(force); 553 m_forcelist.Add(force);
554 m_taintforce = true; 554 m_taintforce = true;
555 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString()); 555 //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
556 } 556 }
557 557
558 public override void AddAngularForce(PhysicsVector force, bool pushforce) 558 public override void AddAngularForce(PhysicsVector force, bool pushforce)
559 { 559 {
560 m_angularforcelist.Add(force); 560 m_angularforcelist.Add(force);
561 m_taintaddangularforce = true; 561 m_taintaddangularforce = true;
562 } 562 }
563 563
564 public override void SetMomentum(PhysicsVector momentum) 564 public override void SetMomentum(PhysicsVector momentum)
565 { 565 {
566 } 566 }
567 567
568 public override void SubscribeEvents(int ms) 568 public override void SubscribeEvents(int ms)
569 { 569 {
570 m_eventsubscription = ms; 570 m_eventsubscription = ms;
571 _parent_scene.addCollisionEventReporting(this); 571 _parent_scene.addCollisionEventReporting(this);
572 } 572 }
573 573
574 public override void UnSubscribeEvents() 574 public override void UnSubscribeEvents()
575 { 575 {
576 _parent_scene.remCollisionEventReporting(this); 576 _parent_scene.remCollisionEventReporting(this);
577 m_eventsubscription = 0; 577 m_eventsubscription = 0;
578 } 578 }
579 579
580 public override bool SubscribedEvents() 580 public override bool SubscribedEvents()
581 { 581 {
582 return (m_eventsubscription > 0); 582 return (m_eventsubscription > 0);
583 } 583 }
584 584
585 #endregion 585 #endregion
586 586
587 587
588 588
589 internal void Dispose() 589 internal void Dispose()
590 { 590 {
591 //TODO: 591 //TODO:
592 DisposeOfBody(); 592 DisposeOfBody();
593 SetCollisionShape(null); 593 SetCollisionShape(null);
594 594
595 if (tempMotionState3 != null && tempMotionState3.Handle != IntPtr.Zero) 595 if (tempMotionState3 != null && tempMotionState3.Handle != IntPtr.Zero)
596 { 596 {
597 tempMotionState3.Dispose(); 597 tempMotionState3.Dispose();
598 tempMotionState3 = null; 598 tempMotionState3 = null;
599 } 599 }
600 600
601 if (tempMotionState2 != null && tempMotionState2.Handle != IntPtr.Zero) 601 if (tempMotionState2 != null && tempMotionState2.Handle != IntPtr.Zero)
602 { 602 {
603 tempMotionState2.Dispose(); 603 tempMotionState2.Dispose();
604 tempMotionState2 = null; 604 tempMotionState2 = null;
605 } 605 }
606 606
607 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero) 607 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
608 { 608 {
609 tempMotionState1.Dispose(); 609 tempMotionState1.Dispose();
610 tempMotionState1 = null; 610 tempMotionState1 = null;
611 } 611 }
612 612
613 if (tempTransform4 != null && tempTransform4.Handle != IntPtr.Zero) 613 if (tempTransform4 != null && tempTransform4.Handle != IntPtr.Zero)
614 { 614 {
615 tempTransform4.Dispose(); 615 tempTransform4.Dispose();
616 tempTransform4 = null; 616 tempTransform4 = null;
617 } 617 }
618 618
619 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero) 619 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero)
620 { 620 {
621 tempTransform3.Dispose(); 621 tempTransform3.Dispose();
622 tempTransform3 = null; 622 tempTransform3 = null;
623 } 623 }
624 624
625 if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero) 625 if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
626 { 626 {
627 tempTransform2.Dispose(); 627 tempTransform2.Dispose();
628 tempTransform2 = null; 628 tempTransform2 = null;
629 } 629 }
630 630
631 if (tempTransform1 != null && tempTransform1.Handle != IntPtr.Zero) 631 if (tempTransform1 != null && tempTransform1.Handle != IntPtr.Zero)
632 { 632 {
633 tempTransform1.Dispose(); 633 tempTransform1.Dispose();
634 tempTransform1 = null; 634 tempTransform1 = null;
635 } 635 }
636 636
637 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero) 637 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
638 { 638 {
639 tempOrientation2.Dispose(); 639 tempOrientation2.Dispose();
640 tempOrientation2 = null; 640 tempOrientation2 = null;
641 } 641 }
642 642
643 if (tempOrientation1 != null && tempOrientation1.Handle != IntPtr.Zero) 643 if (tempOrientation1 != null && tempOrientation1.Handle != IntPtr.Zero)
644 { 644 {
645 tempOrientation1.Dispose(); 645 tempOrientation1.Dispose();
646 tempOrientation1 = null; 646 tempOrientation1 = null;
647 } 647 }
648 648
649 if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero) 649 if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
650 { 650 {
651 tempInertia1.Dispose(); 651 tempInertia1.Dispose();
652 tempInertia1 = null; 652 tempInertia1 = null;
653 } 653 }
654 654
655 if (tempInertia2 != null && tempInertia2.Handle != IntPtr.Zero) 655 if (tempInertia2 != null && tempInertia2.Handle != IntPtr.Zero)
656 { 656 {
657 tempInertia2.Dispose(); 657 tempInertia2.Dispose();
658 tempInertia1 = null; 658 tempInertia1 = null;
659 } 659 }
660 660
661 661
662 if (tempAngularVelocity2 != null && tempAngularVelocity2.Handle != IntPtr.Zero) 662 if (tempAngularVelocity2 != null && tempAngularVelocity2.Handle != IntPtr.Zero)
663 { 663 {
664 tempAngularVelocity2.Dispose(); 664 tempAngularVelocity2.Dispose();
665 tempAngularVelocity2 = null; 665 tempAngularVelocity2 = null;
666 } 666 }
667 667
668 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero) 668 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero)
669 { 669 {
670 tempAngularVelocity1.Dispose(); 670 tempAngularVelocity1.Dispose();
671 tempAngularVelocity1 = null; 671 tempAngularVelocity1 = null;
672 } 672 }
673 673
674 if (tempLinearVelocity2 != null && tempLinearVelocity2.Handle != IntPtr.Zero) 674 if (tempLinearVelocity2 != null && tempLinearVelocity2.Handle != IntPtr.Zero)
675 { 675 {
676 tempLinearVelocity2.Dispose(); 676 tempLinearVelocity2.Dispose();
677 tempLinearVelocity2 = null; 677 tempLinearVelocity2 = null;
678 } 678 }
679 679
680 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero) 680 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero)
681 { 681 {
682 tempLinearVelocity1.Dispose(); 682 tempLinearVelocity1.Dispose();
683 tempLinearVelocity1 = null; 683 tempLinearVelocity1 = null;
684 } 684 }
685 685
686 if (tempSize2 != null && tempSize2.Handle != IntPtr.Zero) 686 if (tempSize2 != null && tempSize2.Handle != IntPtr.Zero)
687 { 687 {
688 tempSize2.Dispose(); 688 tempSize2.Dispose();
689 tempSize2 = null; 689 tempSize2 = null;
690 } 690 }
691 691
692 if (tempSize1 != null && tempSize1.Handle != IntPtr.Zero) 692 if (tempSize1 != null && tempSize1.Handle != IntPtr.Zero)
693 { 693 {
694 tempSize1.Dispose(); 694 tempSize1.Dispose();
695 tempSize1 = null; 695 tempSize1 = null;
696 } 696 }
697 697
698 if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero) 698 if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero)
699 { 699 {
700 tempPosition3.Dispose(); 700 tempPosition3.Dispose();
701 tempPosition3 = null; 701 tempPosition3 = null;
702 } 702 }
703 703
704 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero) 704 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
705 { 705 {
706 tempPosition2.Dispose(); 706 tempPosition2.Dispose();
707 tempPosition2 = null; 707 tempPosition2 = null;
708 } 708 }
709 709
710 if (tempPosition1 != null && tempPosition1.Handle != IntPtr.Zero) 710 if (tempPosition1 != null && tempPosition1.Handle != IntPtr.Zero)
711 { 711 {
712 tempPosition1.Dispose(); 712 tempPosition1.Dispose();
713 tempPosition1 = null; 713 tempPosition1 = null;
714 } 714 }
715 715
716 } 716 }
717 717
718 718
719 719
720 public void ProcessTaints(float timestep) 720 public void ProcessTaints(float timestep)
721 { 721 {
722 if (m_taintadd) 722 if (m_taintadd)
723 { 723 {
724 changeadd(timestep); 724 changeadd(timestep);
725 } 725 }
726 726
727 if (prim_geom.Handle == IntPtr.Zero) 727 if (prim_geom.Handle == IntPtr.Zero)
728 { 728 {
729 CreateGeom(IntPtr.Zero, primMesh); 729 CreateGeom(IntPtr.Zero, primMesh);
730 730
731 if (IsPhysical) 731 if (IsPhysical)
732 SetBody(Mass); 732 SetBody(Mass);
733 else 733 else
734 SetBody(0); 734 SetBody(0);
735 735
736 } 736 }
737 737
738 if (!_position.IsIdentical(m_taintposition, 0f)) 738 if (!_position.IsIdentical(m_taintposition, 0f))
739 changemove(timestep); 739 changemove(timestep);
740 740
741 if (m_taintrot != _orientation) 741 if (m_taintrot != _orientation)
742 rotate(timestep); 742 rotate(timestep);
743 // 743 //
744 744
745 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) 745 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent))
746 changePhysicsStatus(timestep); 746 changePhysicsStatus(timestep);
747 // 747 //
748 748
749 if (!_size.IsIdentical(m_taintsize, 0)) 749 if (!_size.IsIdentical(m_taintsize, 0))
750 changesize(timestep); 750 changesize(timestep);
751 // 751 //
752 752
753 if (m_taintshape) 753 if (m_taintshape)
754 changeshape(timestep); 754 changeshape(timestep);
755 // 755 //
756 756
757 if (m_taintforce) 757 if (m_taintforce)
758 changeAddForce(timestep); 758 changeAddForce(timestep);
759 759
760 if (m_taintaddangularforce) 760 if (m_taintaddangularforce)
761 changeAddAngularForce(timestep); 761 changeAddAngularForce(timestep);
762 762
763 if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f)) 763 if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f))
764 changeSetTorque(timestep); 764 changeSetTorque(timestep);
765 765
766 if (m_taintdisable) 766 if (m_taintdisable)
767 changedisable(timestep); 767 changedisable(timestep);
768 768
769 if (m_taintselected != m_isSelected) 769 if (m_taintselected != m_isSelected)
770 changeSelectedStatus(timestep); 770 changeSelectedStatus(timestep);
771 771
772 if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f)) 772 if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f))
773 changevelocity(timestep); 773 changevelocity(timestep);
774 774
775 if (m_taintparent != _parent) 775 if (m_taintparent != _parent)
776 changelink(timestep); 776 changelink(timestep);
777 777
778 if (m_taintCollidesWater != m_collidesWater) 778 if (m_taintCollidesWater != m_collidesWater)
779 changefloatonwater(timestep); 779 changefloatonwater(timestep);
780 780
781 if (!m_angularlock.IsIdentical(m_taintAngularLock, 0)) 781 if (!m_angularlock.IsIdentical(m_taintAngularLock, 0))
782 changeAngularLock(timestep); 782 changeAngularLock(timestep);
783 783
784 784
785 } 785 }
786 786
787 #region Physics Scene Change Action routines 787 #region Physics Scene Change Action routines
788 788
789 private void changeadd(float timestep) 789 private void changeadd(float timestep)
790 { 790 {
791 if (_mesh == null) 791 if (_mesh == null)
792 { 792 {
793 if (_parent_scene.needsMeshing(_pbs)) 793 if (_parent_scene.needsMeshing(_pbs))
794 { 794 {
795 // Don't need to re-enable body.. it's done in SetMesh 795 // Don't need to re-enable body.. it's done in SetMesh
796 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); 796 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
797 // createmesh returns null when it's a shape that isn't a cube. 797 // createmesh returns null when it's a shape that isn't a cube.
798 } 798 }
799 } 799 }
800 CreateGeom(IntPtr.Zero, primMesh); 800 CreateGeom(IntPtr.Zero, primMesh);
801 801
802 enableBody(); 802 enableBody();
803 changeSelectedStatus(timestep); 803 changeSelectedStatus(timestep);
804 m_taintadd = false; 804 m_taintadd = false;
805 805
806 } 806 }
807 807
808 private void changemove(float timestep) 808 private void changemove(float timestep)
809 { 809 {
810 810
811 811
812 tempTransform2 = Body.getWorldTransform(); 812 tempTransform2 = Body.getWorldTransform();
813 btQuaternion quat = tempTransform2.getRotation(); 813 btQuaternion quat = tempTransform2.getRotation();
814 tempPosition2.setValue(_position.X, _position.Y, _position.Z); 814 tempPosition2.setValue(_position.X, _position.Y, _position.Z);
815 tempTransform2.Dispose(); 815 tempTransform2.Dispose();
816 tempTransform2 = new btTransform(quat, tempPosition2); 816 tempTransform2 = new btTransform(quat, tempPosition2);
817 Body.setWorldTransform(tempTransform2); 817 Body.setWorldTransform(tempTransform2);
818 818
819 changeSelectedStatus(timestep); 819 changeSelectedStatus(timestep);
820 820
821 resetCollisionAccounting(); 821 resetCollisionAccounting();
822 m_taintposition = _position; 822 m_taintposition = _position;
823 } 823 }
824 824
825 private void rotate(float timestep) 825 private void rotate(float timestep)
826 { 826 {
827 827
828 tempTransform2 = Body.getWorldTransform(); 828 tempTransform2 = Body.getWorldTransform();
829 tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W); 829 tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W);
830 tempTransform2.setRotation(tempOrientation2); 830 tempTransform2.setRotation(tempOrientation2);
831 Body.setWorldTransform(tempTransform2); 831 Body.setWorldTransform(tempTransform2);
832 832
833 resetCollisionAccounting(); 833 resetCollisionAccounting();
834 m_taintrot = _orientation; 834 m_taintrot = _orientation;
835 } 835 }
836 836
837 private void changePhysicsStatus(float timestep) 837 private void changePhysicsStatus(float timestep)
838 { 838 {
839 SetCollisionShape(prim_geom); 839 SetCollisionShape(prim_geom);
840 SetBody(Mass); 840 SetBody(Mass);
841 changeSelectedStatus(timestep); 841 changeSelectedStatus(timestep);
842 842
843 resetCollisionAccounting(); 843 resetCollisionAccounting();
844 m_taintPhysics = m_isphysical; 844 m_taintPhysics = m_isphysical;
845 } 845 }
846 846
847 private void changesize(float timestep) 847 private void changesize(float timestep)
848 { 848 {
849 SetCollisionShape(null); 849 SetCollisionShape(null);
850 // Construction of new prim 850 // Construction of new prim
851 if (_parent_scene.needsMeshing(_pbs)) 851 if (_parent_scene.needsMeshing(_pbs))
852 { 852 {
853 float meshlod = _parent_scene.meshSculptLOD; 853 float meshlod = _parent_scene.meshSculptLOD;
854 854
855 if (IsPhysical) 855 if (IsPhysical)
856 meshlod = _parent_scene.MeshSculptphysicalLOD; 856 meshlod = _parent_scene.MeshSculptphysicalLOD;
857 // Don't need to re-enable body.. it's done in SetMesh 857 // Don't need to re-enable body.. it's done in SetMesh
858 858
859 IMesh mesh = null; 859 IMesh mesh = null;
860 860
861 if (_parent_scene.needsMeshing(_pbs)) 861 if (_parent_scene.needsMeshing(_pbs))
862 mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical); 862 mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
863 863
864 //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); 864 //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
865 865
866 CreateGeom(IntPtr.Zero, mesh); 866 CreateGeom(IntPtr.Zero, mesh);
867 867
868 868
869 } 869 }
870 else 870 else
871 { 871 {
872 _mesh = null; 872 _mesh = null;
873 CreateGeom(IntPtr.Zero, _mesh); 873 CreateGeom(IntPtr.Zero, _mesh);
874 } 874 }
875 875
876 if (IsPhysical) 876 if (IsPhysical)
877 SetBody(Mass); 877 SetBody(Mass);
878 else 878 else
879 SetBody(0); 879 SetBody(0);
880 880
881 m_taintsize = _size; 881 m_taintsize = _size;
882 882
883 } 883 }
884 884
885 private void changeshape(float timestep) 885 private void changeshape(float timestep)
886 { 886 {
887 // Cleanup of old prim geometry and Bodies 887 // Cleanup of old prim geometry and Bodies
888 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero) 888 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero)
889 { 889 {
890 if (childPrim) 890 if (childPrim)
891 { 891 {
892 if (_parent != null) 892 if (_parent != null)
893 { 893 {
894 BulletDotNETPrim parent = (BulletDotNETPrim)_parent; 894 BulletDotNETPrim parent = (BulletDotNETPrim)_parent;
895 parent.ChildDelink(this); 895 parent.ChildDelink(this);
896 } 896 }
897 } 897 }
898 else 898 else
899 { 899 {
900 disableBody(); 900 disableBody();
901 } 901 }
902 } 902 }
903 try 903 try
904 { 904 {
905 SetCollisionShape(null); 905 SetCollisionShape(null);
906 } 906 }
907 catch (System.AccessViolationException) 907 catch (System.AccessViolationException)
908 { 908 {
909 //prim_geom = IntPtr.Zero; 909 //prim_geom = IntPtr.Zero;
910 m_log.Error("[PHYSICS]: PrimGeom dead"); 910 m_log.Error("[PHYSICS]: PrimGeom dead");
911 } 911 }
912 912
913 // we don't need to do space calculation because the client sends a position update also. 913 // we don't need to do space calculation because the client sends a position update also.
914 if (_size.X <= 0) _size.X = 0.01f; 914 if (_size.X <= 0) _size.X = 0.01f;
915 if (_size.Y <= 0) _size.Y = 0.01f; 915 if (_size.Y <= 0) _size.Y = 0.01f;
916 if (_size.Z <= 0) _size.Z = 0.01f; 916 if (_size.Z <= 0) _size.Z = 0.01f;
917 // Construction of new prim 917 // Construction of new prim
918 918
919 if (_parent_scene.needsMeshing(_pbs)) 919 if (_parent_scene.needsMeshing(_pbs))
920 { 920 {
921 // Don't need to re-enable body.. it's done in SetMesh 921 // Don't need to re-enable body.. it's done in SetMesh
922 float meshlod = _parent_scene.meshSculptLOD; 922 float meshlod = _parent_scene.meshSculptLOD;
923 923
924 if (IsPhysical) 924 if (IsPhysical)
925 meshlod = _parent_scene.MeshSculptphysicalLOD; 925 meshlod = _parent_scene.MeshSculptphysicalLOD;
926 926
927 IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical); 927 IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
928 // createmesh returns null when it doesn't mesh. 928 // createmesh returns null when it doesn't mesh.
929 CreateGeom(IntPtr.Zero, mesh); 929 CreateGeom(IntPtr.Zero, mesh);
930 } 930 }
931 else 931 else
932 { 932 {
933 _mesh = null; 933 _mesh = null;
934 CreateGeom(IntPtr.Zero, null); 934 CreateGeom(IntPtr.Zero, null);
935 } 935 }
936 tempPosition1.setValue(_position.X, _position.Y, _position.Z); 936 tempPosition1.setValue(_position.X, _position.Y, _position.Z);
937 if (tempOrientation1.Handle != IntPtr.Zero) 937 if (tempOrientation1.Handle != IntPtr.Zero)
938 tempOrientation1.Dispose(); 938 tempOrientation1.Dispose();
939 tempOrientation1 = new btQuaternion(_orientation.X, Orientation.Y, _orientation.Z, _orientation.W); 939 tempOrientation1 = new btQuaternion(_orientation.X, Orientation.Y, _orientation.Z, _orientation.W);
940 if (tempTransform1 != null && tempTransform1.Handle != IntPtr.Zero) 940 if (tempTransform1 != null && tempTransform1.Handle != IntPtr.Zero)
941 tempTransform1.Dispose(); 941 tempTransform1.Dispose();
942 tempTransform1 = new btTransform(tempOrientation1, tempPosition1); 942 tempTransform1 = new btTransform(tempOrientation1, tempPosition1);
943 943
944 944
945 945
946 946
947 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 947 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
948 if (IsPhysical) 948 if (IsPhysical)
949 { 949 {
950 SetBody(Mass); 950 SetBody(Mass);
951 // Re creates body on size. 951 // Re creates body on size.
952 // EnableBody also does setMass() 952 // EnableBody also does setMass()
953 953
954 } 954 }
955 else 955 else
956 { 956 {
957 SetBody(0); 957 SetBody(0);
958 } 958 }
959 959
960 changeSelectedStatus(timestep); 960 changeSelectedStatus(timestep);
961 if (childPrim) 961 if (childPrim)
962 { 962 {
963 if (_parent is BulletDotNETPrim) 963 if (_parent is BulletDotNETPrim)
964 { 964 {
965 BulletDotNETPrim parent = (BulletDotNETPrim)_parent; 965 BulletDotNETPrim parent = (BulletDotNETPrim)_parent;
966 parent.ChildSetGeom(this); 966 parent.ChildSetGeom(this);
967 } 967 }
968 } 968 }
969 resetCollisionAccounting(); 969 resetCollisionAccounting();
970 m_taintshape = false; 970 m_taintshape = false;
971 } 971 }
972 972
973 private void resetCollisionAccounting() 973 private void resetCollisionAccounting()
974 { 974 {
975 m_collisionscore = 0; 975 m_collisionscore = 0;
976 } 976 }
977 977
978 private void ChildSetGeom(BulletDotNETPrim bulletDotNETPrim) 978 private void ChildSetGeom(BulletDotNETPrim bulletDotNETPrim)
979 { 979 {
980 // TODO: throw new NotImplementedException(); 980 // TODO: throw new NotImplementedException();
981 } 981 }
982 982
983 private void changeAddForce(float timestep) 983 private void changeAddForce(float timestep)
984 { 984 {
985 // TODO: throw new NotImplementedException(); 985 // TODO: throw new NotImplementedException();
986 } 986 }
987 987
988 private void changeAddAngularForce(float timestep) 988 private void changeAddAngularForce(float timestep)
989 { 989 {
990 // TODO: throw new NotImplementedException(); 990 // TODO: throw new NotImplementedException();
991 } 991 }
992 992
993 private void changeSetTorque(float timestep) 993 private void changeSetTorque(float timestep)
994 { 994 {
995 // TODO: throw new NotImplementedException(); 995 // TODO: throw new NotImplementedException();
996 } 996 }
997 997
998 private void changedisable(float timestep) 998 private void changedisable(float timestep)
999 { 999 {
1000 // TODO: throw new NotImplementedException(); 1000 // TODO: throw new NotImplementedException();
1001 } 1001 }
1002 1002
1003 private void changeSelectedStatus(float timestep) 1003 private void changeSelectedStatus(float timestep)
1004 { 1004 {
1005 // TODO: throw new NotImplementedException(); 1005 // TODO: throw new NotImplementedException();
1006 } 1006 }
1007 1007
1008 private void changevelocity(float timestep) 1008 private void changevelocity(float timestep)
1009 { 1009 {
1010 // TODO: throw new NotImplementedException(); 1010 // TODO: throw new NotImplementedException();
1011 } 1011 }
1012 1012
1013 private void changelink(float timestep) 1013 private void changelink(float timestep)
1014 { 1014 {
1015 // TODO: throw new NotImplementedException(); 1015 // TODO: throw new NotImplementedException();
1016 } 1016 }
1017 1017
1018 private void changefloatonwater(float timestep) 1018 private void changefloatonwater(float timestep)
1019 { 1019 {
1020 // TODO: throw new NotImplementedException(); 1020 // TODO: throw new NotImplementedException();
1021 } 1021 }
1022 1022
1023 private void changeAngularLock(float timestep) 1023 private void changeAngularLock(float timestep)
1024 { 1024 {
1025 // TODO: throw new NotImplementedException(); 1025 // TODO: throw new NotImplementedException();
1026 } 1026 }
1027 #endregion 1027 #endregion
1028 1028
1029 1029
1030 1030
1031 1031
1032 internal void Move(float timestep) 1032 internal void Move(float timestep)
1033 { 1033 {
1034 //TODO: 1034 //TODO:
1035 float fx = 0; 1035 float fx = 0;
1036 float fy = 0; 1036 float fy = 0;
1037 float fz = 0; 1037 float fz = 0;
1038 1038
1039 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero && !m_isSelected) 1039 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero && !m_isSelected)
1040 { 1040 {
1041 float m_mass = CalculateMass(); 1041 float m_mass = CalculateMass();
1042 1042
1043 fz = 0f; 1043 fz = 0f;
1044 //m_log.Info(m_collisionFlags.ToString()); 1044 //m_log.Info(m_collisionFlags.ToString());
1045 1045
1046 if (m_buoyancy != 0) 1046 if (m_buoyancy != 0)
1047 { 1047 {
1048 if (m_buoyancy > 0) 1048 if (m_buoyancy > 0)
1049 { 1049 {
1050 fz = (((-1 * _parent_scene.gravityz) * m_buoyancy) * m_mass); 1050 fz = (((-1 * _parent_scene.gravityz) * m_buoyancy) * m_mass);
1051 1051
1052 //d.Vector3 l_velocity = d.BodyGetLinearVel(Body); 1052 //d.Vector3 l_velocity = d.BodyGetLinearVel(Body);
1053 //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (_parent_scene.gravityz * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString()); 1053 //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (_parent_scene.gravityz * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString());
1054 } 1054 }
1055 else 1055 else
1056 { 1056 {
1057 fz = (-1 * (((-1 * _parent_scene.gravityz) * (-1 * m_buoyancy)) * m_mass)); 1057 fz = (-1 * (((-1 * _parent_scene.gravityz) * (-1 * m_buoyancy)) * m_mass));
1058 } 1058 }
1059 } 1059 }
1060 1060
1061 if (m_usePID) 1061 if (m_usePID)
1062 { 1062 {
1063 //if (!d.BodyIsEnabled(Body)) 1063 //if (!d.BodyIsEnabled(Body))
1064 //d.BodySetForce(Body, 0f, 0f, 0f); 1064 //d.BodySetForce(Body, 0f, 0f, 0f);
1065 // If we're using the PID controller, then we have no gravity 1065 // If we're using the PID controller, then we have no gravity
1066 fz = (-1 * _parent_scene.gravityz) * m_mass; 1066 fz = (-1 * _parent_scene.gravityz) * m_mass;
1067 1067
1068 // no lock; for now it's only called from within Simulate() 1068 // no lock; for now it's only called from within Simulate()
1069 1069
1070 // If the PID Controller isn't active then we set our force 1070 // If the PID Controller isn't active then we set our force
1071 // calculating base velocity to the current position 1071 // calculating base velocity to the current position
1072 1072
1073 if ((m_PIDTau < 1) && (m_PIDTau != 0)) 1073 if ((m_PIDTau < 1) && (m_PIDTau != 0))
1074 { 1074 {
1075 //PID_G = PID_G / m_PIDTau; 1075 //PID_G = PID_G / m_PIDTau;
1076 m_PIDTau = 1; 1076 m_PIDTau = 1;
1077 } 1077 }
1078 1078
1079 if ((PID_G - m_PIDTau) <= 0) 1079 if ((PID_G - m_PIDTau) <= 0)
1080 { 1080 {
1081 PID_G = m_PIDTau + 1; 1081 PID_G = m_PIDTau + 1;
1082 } 1082 }
1083 1083
1084 // TODO: NEED btVector3 for Linear Velocity 1084 // TODO: NEED btVector3 for Linear Velocity
1085 // NEED btVector3 for Position 1085 // NEED btVector3 for Position
1086 1086
1087 PhysicsVector pos = new PhysicsVector(0, 0, 0); //TODO: Insert values gotten from bullet 1087 PhysicsVector pos = new PhysicsVector(0, 0, 0); //TODO: Insert values gotten from bullet
1088 PhysicsVector vel = new PhysicsVector(0, 0, 0); 1088 PhysicsVector vel = new PhysicsVector(0, 0, 0);
1089 1089
1090 _target_velocity = 1090 _target_velocity =
1091 new PhysicsVector( 1091 new PhysicsVector(
1092 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep), 1092 (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
1093 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep), 1093 (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
1094 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep) 1094 (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
1095 ); 1095 );
1096 1096
1097 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) 1097 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f))
1098 { 1098 {
1099 1099
1100 /* TODO: Do Bullet equiv 1100 /* TODO: Do Bullet equiv
1101 * 1101 *
1102 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z); 1102 d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
1103 d.BodySetLinearVel(Body, 0, 0, 0); 1103 d.BodySetLinearVel(Body, 0, 0, 0);
1104 d.BodyAddForce(Body, 0, 0, fz); 1104 d.BodyAddForce(Body, 0, 0, fz);
1105 return; 1105 return;
1106 */ 1106 */
1107 } 1107 }
1108 else 1108 else
1109 { 1109 {
1110 _zeroFlag = false; 1110 _zeroFlag = false;
1111 1111
1112 fx = ((_target_velocity.X) - vel.X) * (PID_D); 1112 fx = ((_target_velocity.X) - vel.X) * (PID_D);
1113 fy = ((_target_velocity.Y) - vel.Y) * (PID_D); 1113 fy = ((_target_velocity.Y) - vel.Y) * (PID_D);
1114 fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); 1114 fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
1115 1115
1116 } 1116 }
1117 1117
1118 } 1118 }
1119 1119
1120 if (m_useHoverPID && !m_usePID) 1120 if (m_useHoverPID && !m_usePID)
1121 { 1121 {
1122 // If we're using the PID controller, then we have no gravity 1122 // If we're using the PID controller, then we have no gravity
1123 fz = (-1 * _parent_scene.gravityz) * m_mass; 1123 fz = (-1 * _parent_scene.gravityz) * m_mass;
1124 1124
1125 // no lock; for now it's only called from within Simulate() 1125 // no lock; for now it's only called from within Simulate()
1126 1126
1127 // If the PID Controller isn't active then we set our force 1127 // If the PID Controller isn't active then we set our force
1128 // calculating base velocity to the current position 1128 // calculating base velocity to the current position
1129 1129
1130 if ((m_PIDTau < 1)) 1130 if ((m_PIDTau < 1))
1131 { 1131 {
1132 PID_G = PID_G / m_PIDTau; 1132 PID_G = PID_G / m_PIDTau;
1133 } 1133 }
1134 1134
1135 if ((PID_G - m_PIDTau) <= 0) 1135 if ((PID_G - m_PIDTau) <= 0)
1136 { 1136 {
1137 PID_G = m_PIDTau + 1; 1137 PID_G = m_PIDTau + 1;
1138 } 1138 }
1139 PhysicsVector pos = new PhysicsVector(0, 0, 0); //TODO: Insert values gotten from bullet 1139 PhysicsVector pos = new PhysicsVector(0, 0, 0); //TODO: Insert values gotten from bullet
1140 PhysicsVector vel = new PhysicsVector(0, 0, 0); 1140 PhysicsVector vel = new PhysicsVector(0, 0, 0);
1141 1141
1142 // determine what our target height really is based on HoverType 1142 // determine what our target height really is based on HoverType
1143 switch (m_PIDHoverType) 1143 switch (m_PIDHoverType)
1144 { 1144 {
1145 case PIDHoverType.Absolute: 1145 case PIDHoverType.Absolute:
1146 m_targetHoverHeight = m_PIDHoverHeight; 1146 m_targetHoverHeight = m_PIDHoverHeight;
1147 break; 1147 break;
1148 case PIDHoverType.Ground: 1148 case PIDHoverType.Ground:
1149 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); 1149 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
1150 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; 1150 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
1151 break; 1151 break;
1152 case PIDHoverType.GroundAndWater: 1152 case PIDHoverType.GroundAndWater:
1153 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y); 1153 m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
1154 m_waterHeight = _parent_scene.GetWaterLevel(); 1154 m_waterHeight = _parent_scene.GetWaterLevel();
1155 if (m_groundHeight > m_waterHeight) 1155 if (m_groundHeight > m_waterHeight)
1156 { 1156 {
1157 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight; 1157 m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
1158 } 1158 }
1159 else 1159 else
1160 { 1160 {
1161 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight; 1161 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
1162 } 1162 }
1163 break; 1163 break;
1164 case PIDHoverType.Water: 1164 case PIDHoverType.Water:
1165 m_waterHeight = _parent_scene.GetWaterLevel(); 1165 m_waterHeight = _parent_scene.GetWaterLevel();
1166 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight; 1166 m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
1167 break; 1167 break;
1168 } 1168 }
1169 1169
1170 1170
1171 _target_velocity = 1171 _target_velocity =
1172 new PhysicsVector(0.0f, 0.0f, 1172 new PhysicsVector(0.0f, 0.0f,
1173 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep) 1173 (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
1174 ); 1174 );
1175 1175
1176 // if velocity is zero, use position control; otherwise, velocity control 1176 // if velocity is zero, use position control; otherwise, velocity control
1177 1177
1178 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f)) 1178 if (_target_velocity.IsIdentical(PhysicsVector.Zero, 0.1f))
1179 { 1179 {
1180 1180
1181 /* TODO: Do Bullet Equiv 1181 /* TODO: Do Bullet Equiv
1182 d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); 1182 d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
1183 d.BodySetLinearVel(Body, vel.X, vel.Y, 0); 1183 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
1184 d.BodyAddForce(Body, 0, 0, fz); 1184 d.BodyAddForce(Body, 0, 0, fz);
1185 */ 1185 */
1186 return; 1186 return;
1187 } 1187 }
1188 else 1188 else
1189 { 1189 {
1190 _zeroFlag = false; 1190 _zeroFlag = false;
1191 1191
1192 // We're flying and colliding with something 1192 // We're flying and colliding with something
1193 fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); 1193 fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
1194 } 1194 }
1195 } 1195 }
1196 1196
1197 fx *= m_mass; 1197 fx *= m_mass;
1198 fy *= m_mass; 1198 fy *= m_mass;
1199 //fz *= m_mass; 1199 //fz *= m_mass;
1200 1200
1201 fx += m_force.X; 1201 fx += m_force.X;
1202 fy += m_force.Y; 1202 fy += m_force.Y;
1203 fz += m_force.Z; 1203 fz += m_force.Z;
1204 1204
1205 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString()); 1205 //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
1206 if (fx != 0 || fy != 0 || fz != 0) 1206 if (fx != 0 || fy != 0 || fz != 0)
1207 { 1207 {
1208 /* 1208 /*
1209 * TODO: Do Bullet Equiv 1209 * TODO: Do Bullet Equiv
1210 if (!d.BodyIsEnabled(Body)) 1210 if (!d.BodyIsEnabled(Body))
1211 { 1211 {
1212 d.BodySetLinearVel(Body, 0f, 0f, 0f); 1212 d.BodySetLinearVel(Body, 0f, 0f, 0f);
1213 d.BodySetForce(Body, 0, 0, 0); 1213 d.BodySetForce(Body, 0, 0, 0);
1214 enableBodySoft(); 1214 enableBodySoft();
1215 } 1215 }
1216 */ 1216 */
1217 // 35x10 = 350n times the mass per second applied maximum. 1217 // 35x10 = 350n times the mass per second applied maximum.
1218 1218
1219 float nmax = 35f * m_mass; 1219 float nmax = 35f * m_mass;
1220 float nmin = -35f * m_mass; 1220 float nmin = -35f * m_mass;
1221 1221
1222 1222
1223 if (fx > nmax) 1223 if (fx > nmax)
1224 fx = nmax; 1224 fx = nmax;
1225 if (fx < nmin) 1225 if (fx < nmin)
1226 fx = nmin; 1226 fx = nmin;
1227 if (fy > nmax) 1227 if (fy > nmax)
1228 fy = nmax; 1228 fy = nmax;
1229 if (fy < nmin) 1229 if (fy < nmin)
1230 fy = nmin; 1230 fy = nmin;
1231 1231
1232 // TODO: Do Bullet Equiv 1232 // TODO: Do Bullet Equiv
1233 // d.BodyAddForce(Body, fx, fy, fz); 1233 // d.BodyAddForce(Body, fx, fy, fz);
1234 } 1234 }
1235 } 1235 }
1236 else 1236 else
1237 { 1237 {
1238 // _zeroPosition = d.BodyGetPosition(Body); 1238 // _zeroPosition = d.BodyGetPosition(Body);
1239 return; 1239 return;
1240 } 1240 }
1241 } 1241 }
1242 1242
1243 1243
1244 1244
1245 1245
1246 #region Mass Calculation 1246 #region Mass Calculation
1247 1247
1248 private float CalculateMass() 1248 private float CalculateMass()
1249 { 1249 {
1250 float volume = 0; 1250 float volume = 0;
1251 1251
1252 // No material is passed to the physics engines yet.. soo.. 1252 // No material is passed to the physics engines yet.. soo..
1253 // we're using the m_density constant in the class definition 1253 // we're using the m_density constant in the class definition
1254 1254
1255 float returnMass = 0; 1255 float returnMass = 0;
1256 1256
1257 switch (_pbs.ProfileShape) 1257 switch (_pbs.ProfileShape)
1258 { 1258 {
1259 case ProfileShape.Square: 1259 case ProfileShape.Square:
1260 // Profile Volume 1260 // Profile Volume
1261 1261
1262 volume = _size.X * _size.Y * _size.Z; 1262 volume = _size.X * _size.Y * _size.Z;
1263 1263
1264 // If the user has 'hollowed out' 1264 // If the user has 'hollowed out'
1265 // ProfileHollow is one of those 0 to 50000 values :P 1265 // ProfileHollow is one of those 0 to 50000 values :P
1266 // we like percentages better.. so turning into a percentage 1266 // we like percentages better.. so turning into a percentage
1267 1267
1268 if (((float)_pbs.ProfileHollow / 50000f) > 0.0) 1268 if (((float)_pbs.ProfileHollow / 50000f) > 0.0)
1269 { 1269 {
1270 float hollowAmount = (float)_pbs.ProfileHollow / 50000f; 1270 float hollowAmount = (float)_pbs.ProfileHollow / 50000f;
1271 1271
1272 // calculate the hollow volume by it's shape compared to the prim shape 1272 // calculate the hollow volume by it's shape compared to the prim shape
1273 float hollowVolume = 0; 1273 float hollowVolume = 0;
1274 switch (_pbs.HollowShape) 1274 switch (_pbs.HollowShape)
1275 { 1275 {
1276 case HollowShape.Square: 1276 case HollowShape.Square:
1277 case HollowShape.Same: 1277 case HollowShape.Same:
1278 // Cube Hollow volume calculation 1278 // Cube Hollow volume calculation
1279 float hollowsizex = _size.X * hollowAmount; 1279 float hollowsizex = _size.X * hollowAmount;
1280 float hollowsizey = _size.Y * hollowAmount; 1280 float hollowsizey = _size.Y * hollowAmount;
1281 float hollowsizez = _size.Z * hollowAmount; 1281 float hollowsizez = _size.Z * hollowAmount;
1282 hollowVolume = hollowsizex * hollowsizey * hollowsizez; 1282 hollowVolume = hollowsizex * hollowsizey * hollowsizez;
1283 break; 1283 break;
1284 1284
1285 case HollowShape.Circle: 1285 case HollowShape.Circle:
1286 // Hollow shape is a perfect cyllinder in respect to the cube's scale 1286 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1287 // Cyllinder hollow volume calculation 1287 // Cyllinder hollow volume calculation
1288 float hRadius = _size.X / 2; 1288 float hRadius = _size.X / 2;
1289 float hLength = _size.Z; 1289 float hLength = _size.Z;
1290 1290
1291 // pi * r2 * h 1291 // pi * r2 * h
1292 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount); 1292 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount);
1293 break; 1293 break;
1294 1294
1295 case HollowShape.Triangle: 1295 case HollowShape.Triangle:
1296 // Equilateral Triangular Prism volume hollow calculation 1296 // Equilateral Triangular Prism volume hollow calculation
1297 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y 1297 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y
1298 1298
1299 float aLength = _size.Y; 1299 float aLength = _size.Y;
1300 // 1/2 abh 1300 // 1/2 abh
1301 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); 1301 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount);
1302 break; 1302 break;
1303 1303
1304 default: 1304 default:
1305 hollowVolume = 0; 1305 hollowVolume = 0;
1306 break; 1306 break;
1307 } 1307 }
1308 volume = volume - hollowVolume; 1308 volume = volume - hollowVolume;
1309 } 1309 }
1310 1310
1311 break; 1311 break;
1312 case ProfileShape.Circle: 1312 case ProfileShape.Circle:
1313 if (_pbs.PathCurve == (byte)Extrusion.Straight) 1313 if (_pbs.PathCurve == (byte)Extrusion.Straight)
1314 { 1314 {
1315 // Cylinder 1315 // Cylinder
1316 float volume1 = (float)(Math.PI * Math.Pow(_size.X / 2, 2) * _size.Z); 1316 float volume1 = (float)(Math.PI * Math.Pow(_size.X / 2, 2) * _size.Z);
1317 float volume2 = (float)(Math.PI * Math.Pow(_size.Y / 2, 2) * _size.Z); 1317 float volume2 = (float)(Math.PI * Math.Pow(_size.Y / 2, 2) * _size.Z);
1318 1318
1319 // Approximating the cylinder's irregularity. 1319 // Approximating the cylinder's irregularity.
1320 if (volume1 > volume2) 1320 if (volume1 > volume2)
1321 { 1321 {
1322 volume = (float)volume1 - (volume1 - volume2); 1322 volume = (float)volume1 - (volume1 - volume2);
1323 } 1323 }
1324 else if (volume2 > volume1) 1324 else if (volume2 > volume1)
1325 { 1325 {
1326 volume = (float)volume2 - (volume2 - volume1); 1326 volume = (float)volume2 - (volume2 - volume1);
1327 } 1327 }
1328 else 1328 else
1329 { 1329 {
1330 // Regular cylinder 1330 // Regular cylinder
1331 volume = volume1; 1331 volume = volume1;
1332 } 1332 }
1333 } 1333 }
1334 else 1334 else
1335 { 1335 {
1336 // We don't know what the shape is yet, so use default 1336 // We don't know what the shape is yet, so use default
1337 volume = _size.X * _size.Y * _size.Z; 1337 volume = _size.X * _size.Y * _size.Z;
1338 } 1338 }
1339 // If the user has 'hollowed out' 1339 // If the user has 'hollowed out'
1340 // ProfileHollow is one of those 0 to 50000 values :P 1340 // ProfileHollow is one of those 0 to 50000 values :P
1341 // we like percentages better.. so turning into a percentage 1341 // we like percentages better.. so turning into a percentage
1342 1342
1343 if (((float)_pbs.ProfileHollow / 50000f) > 0.0) 1343 if (((float)_pbs.ProfileHollow / 50000f) > 0.0)
1344 { 1344 {
1345 float hollowAmount = (float)_pbs.ProfileHollow / 50000f; 1345 float hollowAmount = (float)_pbs.ProfileHollow / 50000f;
1346 1346
1347 // calculate the hollow volume by it's shape compared to the prim shape 1347 // calculate the hollow volume by it's shape compared to the prim shape
1348 float hollowVolume = 0; 1348 float hollowVolume = 0;
1349 switch (_pbs.HollowShape) 1349 switch (_pbs.HollowShape)
1350 { 1350 {
1351 case HollowShape.Same: 1351 case HollowShape.Same:
1352 case HollowShape.Circle: 1352 case HollowShape.Circle:
1353 // Hollow shape is a perfect cyllinder in respect to the cube's scale 1353 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1354 // Cyllinder hollow volume calculation 1354 // Cyllinder hollow volume calculation
1355 float hRadius = _size.X / 2; 1355 float hRadius = _size.X / 2;
1356 float hLength = _size.Z; 1356 float hLength = _size.Z;
1357 1357
1358 // pi * r2 * h 1358 // pi * r2 * h
1359 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount); 1359 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount);
1360 break; 1360 break;
1361 1361
1362 case HollowShape.Square: 1362 case HollowShape.Square:
1363 // Cube Hollow volume calculation 1363 // Cube Hollow volume calculation
1364 float hollowsizex = _size.X * hollowAmount; 1364 float hollowsizex = _size.X * hollowAmount;
1365 float hollowsizey = _size.Y * hollowAmount; 1365 float hollowsizey = _size.Y * hollowAmount;
1366 float hollowsizez = _size.Z * hollowAmount; 1366 float hollowsizez = _size.Z * hollowAmount;
1367 hollowVolume = hollowsizex * hollowsizey * hollowsizez; 1367 hollowVolume = hollowsizex * hollowsizey * hollowsizez;
1368 break; 1368 break;
1369 1369
1370 case HollowShape.Triangle: 1370 case HollowShape.Triangle:
1371 // Equilateral Triangular Prism volume hollow calculation 1371 // Equilateral Triangular Prism volume hollow calculation
1372 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y 1372 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y
1373 1373
1374 float aLength = _size.Y; 1374 float aLength = _size.Y;
1375 // 1/2 abh 1375 // 1/2 abh
1376 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); 1376 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount);
1377 break; 1377 break;
1378 1378
1379 default: 1379 default:
1380 hollowVolume = 0; 1380 hollowVolume = 0;
1381 break; 1381 break;
1382 } 1382 }
1383 volume = volume - hollowVolume; 1383 volume = volume - hollowVolume;
1384 } 1384 }
1385 break; 1385 break;
1386 1386
1387 case ProfileShape.HalfCircle: 1387 case ProfileShape.HalfCircle:
1388 if (_pbs.PathCurve == (byte)Extrusion.Curve1) 1388 if (_pbs.PathCurve == (byte)Extrusion.Curve1)
1389 { 1389 {
1390 if (_size.X == _size.Y && _size.Z == _size.X) 1390 if (_size.X == _size.Y && _size.Z == _size.X)
1391 { 1391 {
1392 // regular sphere 1392 // regular sphere
1393 // v = 4/3 * pi * r^3 1393 // v = 4/3 * pi * r^3
1394 float sradius3 = (float)Math.Pow((_size.X / 2), 3); 1394 float sradius3 = (float)Math.Pow((_size.X / 2), 3);
1395 volume = (float)((4 / 3f) * Math.PI * sradius3); 1395 volume = (float)((4 / 3f) * Math.PI * sradius3);
1396 } 1396 }
1397 else 1397 else
1398 { 1398 {
1399 // we treat this as a box currently 1399 // we treat this as a box currently
1400 volume = _size.X * _size.Y * _size.Z; 1400 volume = _size.X * _size.Y * _size.Z;
1401 } 1401 }
1402 } 1402 }
1403 else 1403 else
1404 { 1404 {
1405 // We don't know what the shape is yet, so use default 1405 // We don't know what the shape is yet, so use default
1406 volume = _size.X * _size.Y * _size.Z; 1406 volume = _size.X * _size.Y * _size.Z;
1407 } 1407 }
1408 break; 1408 break;
1409 1409
1410 case ProfileShape.EquilateralTriangle: 1410 case ProfileShape.EquilateralTriangle:
1411 /* 1411 /*
1412 v = (abs((xB*yA-xA*yB)+(xC*yB-xB*yC)+(xA*yC-xC*yA))/2) * h 1412 v = (abs((xB*yA-xA*yB)+(xC*yB-xB*yC)+(xA*yC-xC*yA))/2) * h
1413 1413
1414 // seed mesh 1414 // seed mesh
1415 Vertex MM = new Vertex(-0.25f, -0.45f, 0.0f); 1415 Vertex MM = new Vertex(-0.25f, -0.45f, 0.0f);
1416 Vertex PM = new Vertex(+0.5f, 0f, 0.0f); 1416 Vertex PM = new Vertex(+0.5f, 0f, 0.0f);
1417 Vertex PP = new Vertex(-0.25f, +0.45f, 0.0f); 1417 Vertex PP = new Vertex(-0.25f, +0.45f, 0.0f);
1418 */ 1418 */
1419 float xA = -0.25f * _size.X; 1419 float xA = -0.25f * _size.X;
1420 float yA = -0.45f * _size.Y; 1420 float yA = -0.45f * _size.Y;
1421 1421
1422 float xB = 0.5f * _size.X; 1422 float xB = 0.5f * _size.X;
1423 float yB = 0; 1423 float yB = 0;
1424 1424
1425 float xC = -0.25f * _size.X; 1425 float xC = -0.25f * _size.X;
1426 float yC = 0.45f * _size.Y; 1426 float yC = 0.45f * _size.Y;
1427 1427
1428 volume = (float)((Math.Abs((xB * yA - xA * yB) + (xC * yB - xB * yC) + (xA * yC - xC * yA)) / 2) * _size.Z); 1428 volume = (float)((Math.Abs((xB * yA - xA * yB) + (xC * yB - xB * yC) + (xA * yC - xC * yA)) / 2) * _size.Z);
1429 1429
1430 // If the user has 'hollowed out' 1430 // If the user has 'hollowed out'
1431 // ProfileHollow is one of those 0 to 50000 values :P 1431 // ProfileHollow is one of those 0 to 50000 values :P
1432 // we like percentages better.. so turning into a percentage 1432 // we like percentages better.. so turning into a percentage
1433 float fhollowFactor = ((float)_pbs.ProfileHollow / 1.9f); 1433 float fhollowFactor = ((float)_pbs.ProfileHollow / 1.9f);
1434 if (((float)fhollowFactor / 50000f) > 0.0) 1434 if (((float)fhollowFactor / 50000f) > 0.0)
1435 { 1435 {
1436 float hollowAmount = (float)fhollowFactor / 50000f; 1436 float hollowAmount = (float)fhollowFactor / 50000f;
1437 1437
1438 // calculate the hollow volume by it's shape compared to the prim shape 1438 // calculate the hollow volume by it's shape compared to the prim shape
1439 float hollowVolume = 0; 1439 float hollowVolume = 0;
1440 switch (_pbs.HollowShape) 1440 switch (_pbs.HollowShape)
1441 { 1441 {
1442 case HollowShape.Same: 1442 case HollowShape.Same:
1443 case HollowShape.Triangle: 1443 case HollowShape.Triangle:
1444 // Equilateral Triangular Prism volume hollow calculation 1444 // Equilateral Triangular Prism volume hollow calculation
1445 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y 1445 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y
1446 1446
1447 float aLength = _size.Y; 1447 float aLength = _size.Y;
1448 // 1/2 abh 1448 // 1/2 abh
1449 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); 1449 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount);
1450 break; 1450 break;
1451 1451
1452 case HollowShape.Square: 1452 case HollowShape.Square:
1453 // Cube Hollow volume calculation 1453 // Cube Hollow volume calculation
1454 float hollowsizex = _size.X * hollowAmount; 1454 float hollowsizex = _size.X * hollowAmount;
1455 float hollowsizey = _size.Y * hollowAmount; 1455 float hollowsizey = _size.Y * hollowAmount;
1456 float hollowsizez = _size.Z * hollowAmount; 1456 float hollowsizez = _size.Z * hollowAmount;
1457 hollowVolume = hollowsizex * hollowsizey * hollowsizez; 1457 hollowVolume = hollowsizex * hollowsizey * hollowsizez;
1458 break; 1458 break;
1459 1459
1460 case HollowShape.Circle: 1460 case HollowShape.Circle:
1461 // Hollow shape is a perfect cyllinder in respect to the cube's scale 1461 // Hollow shape is a perfect cyllinder in respect to the cube's scale
1462 // Cyllinder hollow volume calculation 1462 // Cyllinder hollow volume calculation
1463 float hRadius = _size.X / 2; 1463 float hRadius = _size.X / 2;
1464 float hLength = _size.Z; 1464 float hLength = _size.Z;
1465 1465
1466 // pi * r2 * h 1466 // pi * r2 * h
1467 hollowVolume = ((float)((Math.PI * Math.Pow(hRadius, 2) * hLength) / 2) * hollowAmount); 1467 hollowVolume = ((float)((Math.PI * Math.Pow(hRadius, 2) * hLength) / 2) * hollowAmount);
1468 break; 1468 break;
1469 1469
1470 default: 1470 default:
1471 hollowVolume = 0; 1471 hollowVolume = 0;
1472 break; 1472 break;
1473 } 1473 }
1474 volume = volume - hollowVolume; 1474 volume = volume - hollowVolume;
1475 } 1475 }
1476 break; 1476 break;
1477 1477
1478 default: 1478 default:
1479 // we don't have all of the volume formulas yet so 1479 // we don't have all of the volume formulas yet so
1480 // use the common volume formula for all 1480 // use the common volume formula for all
1481 volume = _size.X * _size.Y * _size.Z; 1481 volume = _size.X * _size.Y * _size.Z;
1482 break; 1482 break;
1483 } 1483 }
1484 1484
1485 // Calculate Path cut effect on volume 1485 // Calculate Path cut effect on volume
1486 // Not exact, in the triangle hollow example 1486 // Not exact, in the triangle hollow example
1487 // They should never be zero or less then zero.. 1487 // They should never be zero or less then zero..
1488 // we'll ignore it if it's less then zero 1488 // we'll ignore it if it's less then zero
1489 1489
1490 // ProfileEnd and ProfileBegin are values 1490 // ProfileEnd and ProfileBegin are values
1491 // from 0 to 50000 1491 // from 0 to 50000
1492 1492
1493 // Turning them back into percentages so that I can cut that percentage off the volume 1493 // Turning them back into percentages so that I can cut that percentage off the volume
1494 1494
1495 float PathCutEndAmount = _pbs.ProfileEnd; 1495 float PathCutEndAmount = _pbs.ProfileEnd;
1496 float PathCutStartAmount = _pbs.ProfileBegin; 1496 float PathCutStartAmount = _pbs.ProfileBegin;
1497 if (((PathCutStartAmount + PathCutEndAmount) / 50000f) > 0.0f) 1497 if (((PathCutStartAmount + PathCutEndAmount) / 50000f) > 0.0f)
1498 { 1498 {
1499 float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount) / 50000f); 1499 float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount) / 50000f);
1500 1500
1501 // Check the return amount for sanity 1501 // Check the return amount for sanity
1502 if (pathCutAmount >= 0.99f) 1502 if (pathCutAmount >= 0.99f)
1503 pathCutAmount = 0.99f; 1503 pathCutAmount = 0.99f;
1504 1504
1505 volume = volume - (volume * pathCutAmount); 1505 volume = volume - (volume * pathCutAmount);
1506 } 1506 }
1507 UInt16 taperX = _pbs.PathScaleX; 1507 UInt16 taperX = _pbs.PathScaleX;
1508 UInt16 taperY = _pbs.PathScaleY; 1508 UInt16 taperY = _pbs.PathScaleY;
1509 float taperFactorX = 0; 1509 float taperFactorX = 0;
1510 float taperFactorY = 0; 1510 float taperFactorY = 0;
1511 1511
1512 // Mass = density * volume 1512 // Mass = density * volume
1513 if (taperX != 100) 1513 if (taperX != 100)
1514 { 1514 {
1515 if (taperX > 100) 1515 if (taperX > 100)
1516 { 1516 {
1517 taperFactorX = 1.0f - ((float)taperX / 200); 1517 taperFactorX = 1.0f - ((float)taperX / 200);
1518 //m_log.Warn("taperTopFactorX: " + extr.taperTopFactorX.ToString()); 1518 //m_log.Warn("taperTopFactorX: " + extr.taperTopFactorX.ToString());
1519 } 1519 }
1520 else 1520 else
1521 { 1521 {
1522 taperFactorX = 1.0f - ((100 - (float)taperX) / 100); 1522 taperFactorX = 1.0f - ((100 - (float)taperX) / 100);
1523 //m_log.Warn("taperBotFactorX: " + extr.taperBotFactorX.ToString()); 1523 //m_log.Warn("taperBotFactorX: " + extr.taperBotFactorX.ToString());
1524 } 1524 }
1525 volume = (float)volume * ((taperFactorX / 3f) + 0.001f); 1525 volume = (float)volume * ((taperFactorX / 3f) + 0.001f);
1526 } 1526 }
1527 1527
1528 if (taperY != 100) 1528 if (taperY != 100)
1529 { 1529 {
1530 if (taperY > 100) 1530 if (taperY > 100)
1531 { 1531 {
1532 taperFactorY = 1.0f - ((float)taperY / 200); 1532 taperFactorY = 1.0f - ((float)taperY / 200);
1533 //m_log.Warn("taperTopFactorY: " + extr.taperTopFactorY.ToString()); 1533 //m_log.Warn("taperTopFactorY: " + extr.taperTopFactorY.ToString());
1534 } 1534 }
1535 else 1535 else
1536 { 1536 {
1537 taperFactorY = 1.0f - ((100 - (float)taperY) / 100); 1537 taperFactorY = 1.0f - ((100 - (float)taperY) / 100);
1538 //m_log.Warn("taperBotFactorY: " + extr.taperBotFactorY.ToString()); 1538 //m_log.Warn("taperBotFactorY: " + extr.taperBotFactorY.ToString());
1539 } 1539 }
1540 volume = (float)volume * ((taperFactorY / 3f) + 0.001f); 1540 volume = (float)volume * ((taperFactorY / 3f) + 0.001f);
1541 } 1541 }
1542 returnMass = m_density * volume; 1542 returnMass = m_density * volume;
1543 if (returnMass <= 0) returnMass = 0.0001f;//ckrinke: Mass must be greater then zero. 1543 if (returnMass <= 0) returnMass = 0.0001f;//ckrinke: Mass must be greater then zero.
1544 1544
1545 1545
1546 1546
1547 // Recursively calculate mass 1547 // Recursively calculate mass
1548 bool HasChildPrim = false; 1548 bool HasChildPrim = false;
1549 lock (childrenPrim) 1549 lock (childrenPrim)
1550 { 1550 {
1551 if (childrenPrim.Count > 0) 1551 if (childrenPrim.Count > 0)
1552 { 1552 {
1553 HasChildPrim = true; 1553 HasChildPrim = true;
1554 } 1554 }
1555 1555
1556 } 1556 }
1557 if (HasChildPrim) 1557 if (HasChildPrim)
1558 { 1558 {
1559 BulletDotNETPrim[] childPrimArr = new BulletDotNETPrim[0]; 1559 BulletDotNETPrim[] childPrimArr = new BulletDotNETPrim[0];
1560 1560
1561 lock (childrenPrim) 1561 lock (childrenPrim)
1562 childPrimArr = childrenPrim.ToArray(); 1562 childPrimArr = childrenPrim.ToArray();
1563 1563
1564 for (int i = 0; i < childPrimArr.Length; i++) 1564 for (int i = 0; i < childPrimArr.Length; i++)
1565 { 1565 {
1566 if (childPrimArr[i] != null && !childPrimArr[i].m_taintremove) 1566 if (childPrimArr[i] != null && !childPrimArr[i].m_taintremove)
1567 returnMass += childPrimArr[i].CalculateMass(); 1567 returnMass += childPrimArr[i].CalculateMass();
1568 // failsafe, this shouldn't happen but with OpenSim, you never know :) 1568 // failsafe, this shouldn't happen but with OpenSim, you never know :)
1569 if (i > 256) 1569 if (i > 256)
1570 break; 1570 break;
1571 } 1571 }
1572 } 1572 }
1573 1573
1574 1574
1575 1575
1576 1576
1577 1577
1578 return returnMass; 1578 return returnMass;
1579 } 1579 }
1580 1580
1581 #endregion 1581 #endregion
1582 1582
1583 1583
1584 public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh) 1584 public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh)
1585 { 1585 {
1586 if (p_mesh != null) 1586 if (p_mesh != null)
1587 { 1587 {
1588 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); 1588 _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
1589 setMesh(_parent_scene, _mesh); 1589 setMesh(_parent_scene, _mesh);
1590 1590
1591 } 1591 }
1592 else 1592 else
1593 { 1593 {
1594 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1) 1594 if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
1595 { 1595 {
1596 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z) 1596 if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
1597 { 1597 {
1598 if (((_size.X / 2f) > 0f)) 1598 if (((_size.X / 2f) > 0f))
1599 { 1599 {
1600 //SetGeom to a Regular Sphere 1600 //SetGeom to a Regular Sphere
1601 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f); 1601 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
1602 SetCollisionShape(new btSphereShape(_size.X*0.5f)); 1602 SetCollisionShape(new btSphereShape(_size.X*0.5f));
1603 } 1603 }
1604 else 1604 else
1605 { 1605 {
1606 // uses halfextents 1606 // uses halfextents
1607 tempSize1.setValue(_size.X*0.5f, _size.Y*0.5f, _size.Z*0.5f); 1607 tempSize1.setValue(_size.X*0.5f, _size.Y*0.5f, _size.Z*0.5f);
1608 SetCollisionShape(new btBoxShape(tempSize1)); 1608 SetCollisionShape(new btBoxShape(tempSize1));
1609 } 1609 }
1610 } 1610 }
1611 else 1611 else
1612 { 1612 {
1613 // uses halfextents 1613 // uses halfextents
1614 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f); 1614 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
1615 SetCollisionShape(new btBoxShape(tempSize1)); 1615 SetCollisionShape(new btBoxShape(tempSize1));
1616 } 1616 }
1617 1617
1618 } 1618 }
1619 else 1619 else
1620 { 1620 {
1621 // uses halfextents 1621 // uses halfextents
1622 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f); 1622 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
1623 SetCollisionShape(new btBoxShape(tempSize1)); 1623 SetCollisionShape(new btBoxShape(tempSize1));
1624 } 1624 }
1625 } 1625 }
1626 } 1626 }
1627 1627
1628 private void setMesh(BulletDotNETScene _parent_scene, IMesh mesh) 1628 private void setMesh(BulletDotNETScene _parent_scene, IMesh mesh)
1629 { 1629 {
1630 // TODO: Set Collision Body Mesh 1630 // TODO: Set Collision Body Mesh
1631 // This sleeper is there to moderate how long it takes between 1631 // This sleeper is there to moderate how long it takes between
1632 // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object 1632 // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
1633 1633
1634 Thread.Sleep(10); 1634 Thread.Sleep(10);
1635 1635
1636 //Kill Body so that mesh can re-make the geom 1636 //Kill Body so that mesh can re-make the geom
1637 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero) 1637 if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero)
1638 { 1638 {
1639 if (childPrim) 1639 if (childPrim)
1640 { 1640 {
1641 if (_parent != null) 1641 if (_parent != null)
1642 { 1642 {
1643 BulletDotNETPrim parent = (BulletDotNETPrim)_parent; 1643 BulletDotNETPrim parent = (BulletDotNETPrim)_parent;
1644 parent.ChildDelink(this); 1644 parent.ChildDelink(this);
1645 } 1645 }
1646 } 1646 }
1647 else 1647 else
1648 { 1648 {
1649 disableBody(); 1649 disableBody();
1650 } 1650 }
1651 } 1651 }
1652 1652
1653 IMesh oldMesh = primMesh; 1653 IMesh oldMesh = primMesh;
1654 1654
1655 primMesh = mesh; 1655 primMesh = mesh;
1656 1656
1657 float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 1657 float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
1658 int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 1658 int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
1659 //Array.Reverse(indexList); 1659 //Array.Reverse(indexList);
1660 primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory 1660 primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
1661 1661
1662 int VertexCount = vertexList.GetLength(0) / 3; 1662 int VertexCount = vertexList.GetLength(0) / 3;
1663 int IndexCount = indexList.GetLength(0); 1663 int IndexCount = indexList.GetLength(0);
1664 1664
1665 if (btshapeArray != null && btshapeArray.Handle != IntPtr.Zero) 1665 if (btshapeArray != null && btshapeArray.Handle != IntPtr.Zero)
1666 btshapeArray.Dispose(); 1666 btshapeArray.Dispose();
1667 //Array.Reverse(indexList); 1667 //Array.Reverse(indexList);
1668 btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)), 1668 btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)),
1669 VertexCount, vertexList, 3*sizeof (float)); 1669 VertexCount, vertexList, 3*sizeof (float));
1670 SetCollisionShape(new btGImpactMeshShape(btshapeArray)); 1670 SetCollisionShape(new btGImpactMeshShape(btshapeArray));
1671 //((btGImpactMeshShape) prim_geom).updateBound(); 1671 //((btGImpactMeshShape) prim_geom).updateBound();
1672 ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1,1, 1)); 1672 ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1,1, 1));
1673 ((btGImpactMeshShape)prim_geom).updateBound(); 1673 ((btGImpactMeshShape)prim_geom).updateBound();
1674 _parent_scene.SetUsingGImpact(); 1674 _parent_scene.SetUsingGImpact();
1675 if (oldMesh != null) 1675 if (oldMesh != null)
1676 { 1676 {
1677 oldMesh.releasePinned(); 1677 oldMesh.releasePinned();
1678 oldMesh = null; 1678 oldMesh = null;
1679 } 1679 }
1680 1680
1681 } 1681 }
1682 1682
1683 private void SetCollisionShape(btCollisionShape shape) 1683 private void SetCollisionShape(btCollisionShape shape)
1684 { 1684 {
1685 if (shape == null) 1685 if (shape == null)
1686 m_log.Debug("[PHYSICS]:SetShape!Null"); 1686 m_log.Debug("[PHYSICS]:SetShape!Null");
1687 else 1687 else
1688 m_log.Debug("[PHYSICS]:SetShape!"); 1688 m_log.Debug("[PHYSICS]:SetShape!");
1689 1689
1690 if (Body != null) 1690 if (Body != null)
1691 { 1691 {
1692 DisposeOfBody(); 1692 DisposeOfBody();
1693 } 1693 }
1694 1694
1695 if (prim_geom != null) 1695 if (prim_geom != null)
1696 { 1696 {
1697 prim_geom.Dispose(); 1697 prim_geom.Dispose();
1698 prim_geom = null; 1698 prim_geom = null;
1699 } 1699 }
1700 prim_geom = shape; 1700 prim_geom = shape;
1701 1701
1702 //Body.set 1702 //Body.set
1703 } 1703 }
1704 1704
1705 public void SetBody(float mass) 1705 public void SetBody(float mass)
1706 { 1706 {
1707 m_log.DebugFormat("[PHYSICS]: SetBody! {0}",mass); 1707 m_log.DebugFormat("[PHYSICS]: SetBody! {0}",mass);
1708 if (Body != null && Body.Handle != IntPtr.Zero) 1708 if (Body != null && Body.Handle != IntPtr.Zero)
1709 { 1709 {
1710 DisposeOfBody(); 1710 DisposeOfBody();
1711 } 1711 }
1712 1712
1713 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero) 1713 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
1714 tempMotionState1.Dispose(); 1714 tempMotionState1.Dispose();
1715 if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero) 1715 if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
1716 tempTransform2.Dispose(); 1716 tempTransform2.Dispose();
1717 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero) 1717 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
1718 tempOrientation2.Dispose(); 1718 tempOrientation2.Dispose();
1719 1719
1720 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero) 1720 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
1721 tempPosition2.Dispose(); 1721 tempPosition2.Dispose();
1722 1722
1723 tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W); 1723 tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W);
1724 tempPosition2 = new btVector3(_position.X, _position.Y, _position.Z); 1724 tempPosition2 = new btVector3(_position.X, _position.Y, _position.Z);
1725 tempTransform2 = new btTransform(tempOrientation2, tempPosition2); 1725 tempTransform2 = new btTransform(tempOrientation2, tempPosition2);
1726 tempMotionState1 = new btDefaultMotionState(tempTransform2, _parent_scene.TransZero); 1726 tempMotionState1 = new btDefaultMotionState(tempTransform2, _parent_scene.TransZero);
1727 if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero) 1727 if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
1728 tempInertia1.Dispose(); 1728 tempInertia1.Dispose();
1729 tempInertia1 = new btVector3(0, 0, 0); 1729 tempInertia1 = new btVector3(0, 0, 0);
1730 if (prim_geom.Handle == IntPtr.Zero) 1730 if (prim_geom.Handle == IntPtr.Zero)
1731 { 1731 {
1732 m_log.Warn("[PHYSICS]:PrimGeom is Disposed!"); 1732 m_log.Warn("[PHYSICS]:PrimGeom is Disposed!");
1733 CreateGeom(IntPtr.Zero, primMesh); 1733 CreateGeom(IntPtr.Zero, primMesh);
1734 1734
1735 } 1735 }
1736 prim_geom.calculateLocalInertia(mass, tempInertia1); 1736 prim_geom.calculateLocalInertia(mass, tempInertia1);
1737 1737
1738 if (mass == 0) 1738 if (mass == 0)
1739 Body = new btRigidBody(mass, tempMotionState1, prim_geom); 1739 Body = new btRigidBody(mass, tempMotionState1, prim_geom);
1740 else 1740 else
1741 Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); 1741 Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1);
1742 1742
1743 if (prim_geom is btGImpactMeshShape) 1743 if (prim_geom is btGImpactMeshShape)
1744 { 1744 {
1745 ((btGImpactMeshShape) prim_geom).setLocalScaling(new btVector3(1, 1, 1)); 1745 ((btGImpactMeshShape) prim_geom).setLocalScaling(new btVector3(1, 1, 1));
1746 ((btGImpactMeshShape) prim_geom).updateBound(); 1746 ((btGImpactMeshShape) prim_geom).updateBound();
1747 } 1747 }
1748 _parent_scene.AddPrimToScene(this); 1748 _parent_scene.AddPrimToScene(this);
1749 } 1749 }
1750 1750
1751 private void DisposeOfBody() 1751 private void DisposeOfBody()
1752 { 1752 {
1753 if (Body != null) 1753 if (Body != null)
1754 { 1754 {
1755 if (Body.Handle != IntPtr.Zero) 1755 if (Body.Handle != IntPtr.Zero)
1756 { 1756 {
1757 _parent_scene.removeFromWorld(this,Body); 1757 _parent_scene.removeFromWorld(this,Body);
1758 Body.Dispose(); 1758 Body.Dispose();
1759 } 1759 }
1760 Body = null; 1760 Body = null;
1761 // TODO: dispose parts that make up body 1761 // TODO: dispose parts that make up body
1762 } 1762 }
1763 } 1763 }
1764 1764
1765 private void ChildDelink(BulletDotNETPrim pPrim) 1765 private void ChildDelink(BulletDotNETPrim pPrim)
1766 { 1766 {
1767 // Okay, we have a delinked child.. need to rebuild the body. 1767 // Okay, we have a delinked child.. need to rebuild the body.
1768 lock (childrenPrim) 1768 lock (childrenPrim)
1769 { 1769 {
1770 foreach (BulletDotNETPrim prm in childrenPrim) 1770 foreach (BulletDotNETPrim prm in childrenPrim)
1771 { 1771 {
1772 prm.childPrim = true; 1772 prm.childPrim = true;
1773 prm.disableBody(); 1773 prm.disableBody();
1774 1774
1775 } 1775 }
1776 } 1776 }
1777 disableBody(); 1777 disableBody();
1778 1778
1779 lock (childrenPrim) 1779 lock (childrenPrim)
1780 { 1780 {
1781 childrenPrim.Remove(pPrim); 1781 childrenPrim.Remove(pPrim);
1782 } 1782 }
1783 1783
1784 1784
1785 1785
1786 1786
1787 if (Body != null && Body.Handle != IntPtr.Zero) 1787 if (Body != null && Body.Handle != IntPtr.Zero)
1788 { 1788 {
1789 _parent_scene.remActivePrim(this); 1789 _parent_scene.remActivePrim(this);
1790 } 1790 }
1791 1791
1792 1792
1793 1793
1794 lock (childrenPrim) 1794 lock (childrenPrim)
1795 { 1795 {
1796 foreach (BulletDotNETPrim prm in childrenPrim) 1796 foreach (BulletDotNETPrim prm in childrenPrim)
1797 { 1797 {
1798 ParentPrim(prm); 1798 ParentPrim(prm);
1799 } 1799 }
1800 } 1800 }
1801 1801
1802 } 1802 }
1803 1803
1804 private void ParentPrim(BulletDotNETPrim prm) 1804 private void ParentPrim(BulletDotNETPrim prm)
1805 { 1805 {
1806 // TODO: Parent Linking algorithm. Use btComplexObject 1806 // TODO: Parent Linking algorithm. Use btComplexObject
1807 } 1807 }
1808 1808
1809 public void disableBody() 1809 public void disableBody()
1810 { 1810 {
1811 //this kills the body so things like 'mesh' can re-create it. 1811 //this kills the body so things like 'mesh' can re-create it.
1812 lock (this) 1812 lock (this)
1813 { 1813 {
1814 if (!childPrim) 1814 if (!childPrim)
1815 { 1815 {
1816 if (Body != null && Body.Handle != IntPtr.Zero) 1816 if (Body != null && Body.Handle != IntPtr.Zero)
1817 { 1817 {
1818 _parent_scene.remActivePrim(this); 1818 _parent_scene.remActivePrim(this);
1819 1819
1820 m_collisionCategories &= ~CollisionCategories.Body; 1820 m_collisionCategories &= ~CollisionCategories.Body;
1821 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 1821 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1822 1822
1823 if (prim_geom != null && prim_geom.Handle != IntPtr.Zero) 1823 if (prim_geom != null && prim_geom.Handle != IntPtr.Zero)
1824 { 1824 {
1825 // TODO: Set Category bits and Flags 1825 // TODO: Set Category bits and Flags
1826 } 1826 }
1827 1827
1828 // TODO: destroy body 1828 // TODO: destroy body
1829 DisposeOfBody(); 1829 DisposeOfBody();
1830 1830
1831 lock (childrenPrim) 1831 lock (childrenPrim)
1832 { 1832 {
1833 if (childrenPrim.Count > 0) 1833 if (childrenPrim.Count > 0)
1834 { 1834 {
1835 foreach (BulletDotNETPrim prm in childrenPrim) 1835 foreach (BulletDotNETPrim prm in childrenPrim)
1836 { 1836 {
1837 _parent_scene.remActivePrim(prm); 1837 _parent_scene.remActivePrim(prm);
1838 prm.DisposeOfBody(); 1838 prm.DisposeOfBody();
1839 prm.SetCollisionShape(null); 1839 prm.SetCollisionShape(null);
1840 } 1840 }
1841 } 1841 }
1842 1842
1843 } 1843 }
1844 1844
1845 DisposeOfBody(); 1845 DisposeOfBody();
1846 } 1846 }
1847 } 1847 }
1848 else 1848 else
1849 { 1849 {
1850 _parent_scene.remActivePrim(this); 1850 _parent_scene.remActivePrim(this);
1851 m_collisionCategories &= ~CollisionCategories.Body; 1851 m_collisionCategories &= ~CollisionCategories.Body;
1852 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 1852 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
1853 1853
1854 if (prim_geom != null && prim_geom.Handle != IntPtr.Zero) 1854 if (prim_geom != null && prim_geom.Handle != IntPtr.Zero)
1855 { 1855 {
1856 // TODO: Set Category bits and Flags 1856 // TODO: Set Category bits and Flags
1857 } 1857 }
1858 1858
1859 DisposeOfBody(); 1859 DisposeOfBody();
1860 } 1860 }
1861 1861
1862 } 1862 }
1863 m_disabled = true; 1863 m_disabled = true;
1864 m_collisionscore = 0; 1864 m_collisionscore = 0;
1865 } 1865 }
1866 1866
1867 public void disableBodySoft() 1867 public void disableBodySoft()
1868 { 1868 {
1869 m_disabled = true; 1869 m_disabled = true;
1870 1870
1871 if (m_isphysical && Body.Handle != IntPtr.Zero) 1871 if (m_isphysical && Body.Handle != IntPtr.Zero)
1872 { 1872 {
1873 Body.clearForces(); 1873 Body.clearForces();
1874 Body.forceActivationState(0); 1874 Body.forceActivationState(0);
1875 1875
1876 } 1876 }
1877 1877
1878 } 1878 }
1879 1879
1880 public void enableBodySoft() 1880 public void enableBodySoft()
1881 { 1881 {
1882 if (!childPrim) 1882 if (!childPrim)
1883 { 1883 {
1884 if (m_isphysical && Body.Handle != IntPtr.Zero) 1884 if (m_isphysical && Body.Handle != IntPtr.Zero)
1885 { 1885 {
1886 Body.clearForces(); 1886 Body.clearForces();
1887 Body.forceActivationState(1); 1887 Body.forceActivationState(1);
1888 } 1888 }
1889 m_disabled = false; 1889 m_disabled = false;
1890 } 1890 }
1891 } 1891 }
1892 1892
1893 public void enableBody() 1893 public void enableBody()
1894 { 1894 {
1895 if (!childPrim) 1895 if (!childPrim)
1896 { 1896 {
1897 //SetCollisionShape(prim_geom); 1897 //SetCollisionShape(prim_geom);
1898 if (IsPhysical) 1898 if (IsPhysical)
1899 SetBody(Mass); 1899 SetBody(Mass);
1900 else 1900 else
1901 SetBody(0); 1901 SetBody(0);
1902 1902
1903 // TODO: Set Collision Category Bits and Flags 1903 // TODO: Set Collision Category Bits and Flags
1904 // TODO: Set Auto Disable data 1904 // TODO: Set Auto Disable data
1905 1905
1906 m_interpenetrationcount = 0; 1906 m_interpenetrationcount = 0;
1907 m_collisionscore = 0; 1907 m_collisionscore = 0;
1908 m_disabled = false; 1908 m_disabled = false;
1909 // The body doesn't already have a finite rotation mode set here 1909 // The body doesn't already have a finite rotation mode set here
1910 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 1910 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
1911 { 1911 {
1912 // TODO: Create Angular Motor on Axis Lock! 1912 // TODO: Create Angular Motor on Axis Lock!
1913 } 1913 }
1914 _parent_scene.addActivePrim(this); 1914 _parent_scene.addActivePrim(this);
1915 } 1915 }
1916 } 1916 }
1917 1917
1918 public void UpdatePositionAndVelocity() 1918 public void UpdatePositionAndVelocity()
1919 { 1919 {
1920 if (_parent == null) 1920 if (_parent == null)
1921 { 1921 {
1922 PhysicsVector pv = new PhysicsVector(0, 0, 0); 1922 PhysicsVector pv = new PhysicsVector(0, 0, 0);
1923 bool lastZeroFlag = _zeroFlag; 1923 bool lastZeroFlag = _zeroFlag;
1924 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero) 1924 if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero)
1925 tempPosition2.Dispose(); 1925 tempPosition2.Dispose();
1926 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero) 1926 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero)
1927 tempTransform3.Dispose(); 1927 tempTransform3.Dispose();
1928 1928
1929 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero) 1929 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
1930 tempOrientation2.Dispose(); 1930 tempOrientation2.Dispose();
1931 1931
1932 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero) 1932 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero)
1933 tempAngularVelocity1.Dispose(); 1933 tempAngularVelocity1.Dispose();
1934 1934
1935 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero) 1935 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero)
1936 tempLinearVelocity1.Dispose(); 1936 tempLinearVelocity1.Dispose();
1937 1937
1938 1938
1939 1939
1940 tempTransform3 = Body.getInterpolationWorldTransform(); 1940 tempTransform3 = Body.getInterpolationWorldTransform();
1941 tempPosition2 = tempTransform3.getOrigin(); // vec 1941 tempPosition2 = tempTransform3.getOrigin(); // vec
1942 tempOrientation2 = tempTransform3.getRotation(); // ori 1942 tempOrientation2 = tempTransform3.getRotation(); // ori
1943 tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel 1943 tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel
1944 tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel 1944 tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel
1945 1945
1946 _torque.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getX(), tempAngularVelocity1.getZ()); 1946 _torque.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getX(), tempAngularVelocity1.getZ());
1947 PhysicsVector l_position = new PhysicsVector(); 1947 PhysicsVector l_position = new PhysicsVector();
1948 Quaternion l_orientation = new Quaternion(); 1948 Quaternion l_orientation = new Quaternion();
1949 m_lastposition = _position; 1949 m_lastposition = _position;
1950 m_lastorientation = _orientation; 1950 m_lastorientation = _orientation;
1951 1951
1952 l_position.X = tempPosition2.getX(); 1952 l_position.X = tempPosition2.getX();
1953 l_position.Y = tempPosition2.getY(); 1953 l_position.Y = tempPosition2.getY();
1954 l_position.Z = tempPosition2.getZ(); 1954 l_position.Z = tempPosition2.getZ();
1955 l_orientation.X = tempOrientation2.getX(); 1955 l_orientation.X = tempOrientation2.getX();
1956 l_orientation.Y = tempOrientation2.getY(); 1956 l_orientation.Y = tempOrientation2.getY();
1957 l_orientation.Z = tempOrientation2.getZ(); 1957 l_orientation.Z = tempOrientation2.getZ();
1958 l_orientation.W = tempOrientation2.getW(); 1958 l_orientation.W = tempOrientation2.getW();
1959 1959
1960 if (l_position.X > 255.95f || l_position.X < 0f || l_position.Y > 255.95f || l_position.Y < 0f) 1960 if (l_position.X > 255.95f || l_position.X < 0f || l_position.Y > 255.95f || l_position.Y < 0f)
1961 { 1961 {
1962 //base.RaiseOutOfBounds(l_position); 1962 //base.RaiseOutOfBounds(l_position);
1963 1963
1964 if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds) 1964 if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds)
1965 { 1965 {
1966 _position = l_position; 1966 _position = l_position;
1967 //_parent_scene.remActivePrim(this); 1967 //_parent_scene.remActivePrim(this);
1968 if (_parent == null) 1968 if (_parent == null)
1969 base.RequestPhysicsterseUpdate(); 1969 base.RequestPhysicsterseUpdate();
1970 return; 1970 return;
1971 } 1971 }
1972 else 1972 else
1973 { 1973 {
1974 if (_parent == null) 1974 if (_parent == null)
1975 base.RaiseOutOfBounds(l_position); 1975 base.RaiseOutOfBounds(l_position);
1976 return; 1976 return;
1977 } 1977 }
1978 } 1978 }
1979 1979
1980 if (l_position.Z < -200000f) 1980 if (l_position.Z < -200000f)
1981 { 1981 {
1982 // This is so prim that get lost underground don't fall forever and suck up 1982 // This is so prim that get lost underground don't fall forever and suck up
1983 // 1983 //
1984 // Sim resources and memory. 1984 // Sim resources and memory.
1985 // Disables the prim's movement physics.... 1985 // Disables the prim's movement physics....
1986 // It's a hack and will generate a console message if it fails. 1986 // It's a hack and will generate a console message if it fails.
1987 1987
1988 //IsPhysical = false; 1988 //IsPhysical = false;
1989 //if (_parent == null) 1989 //if (_parent == null)
1990 //base.RaiseOutOfBounds(_position); 1990 //base.RaiseOutOfBounds(_position);
1991 1991
1992 _acceleration.X = 0; 1992 _acceleration.X = 0;
1993 _acceleration.Y = 0; 1993 _acceleration.Y = 0;
1994 _acceleration.Z = 0; 1994 _acceleration.Z = 0;
1995 1995
1996 _velocity.X = 0; 1996 _velocity.X = 0;
1997 _velocity.Y = 0; 1997 _velocity.Y = 0;
1998 _velocity.Z = 0; 1998 _velocity.Z = 0;
1999 m_rotationalVelocity.X = 0; 1999 m_rotationalVelocity.X = 0;
2000 m_rotationalVelocity.Y = 0; 2000 m_rotationalVelocity.Y = 0;
2001 m_rotationalVelocity.Z = 0; 2001 m_rotationalVelocity.Z = 0;
2002 2002
2003 if (_parent == null) 2003 if (_parent == null)
2004 base.RequestPhysicsterseUpdate(); 2004 base.RequestPhysicsterseUpdate();
2005 2005
2006 m_throttleUpdates = false; 2006 m_throttleUpdates = false;
2007 throttleCounter = 0; 2007 throttleCounter = 0;
2008 _zeroFlag = true; 2008 _zeroFlag = true;
2009 //outofBounds = true; 2009 //outofBounds = true;
2010 } 2010 }
2011 2011
2012 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) 2012 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)
2013 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) 2013 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02)
2014 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) 2014 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02)
2015 && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01 )) 2015 && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01 ))
2016 { 2016 {
2017 _zeroFlag = true; 2017 _zeroFlag = true;
2018 m_throttleUpdates = false; 2018 m_throttleUpdates = false;
2019 } 2019 }
2020 else 2020 else
2021 { 2021 {
2022 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString()); 2022 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
2023 _zeroFlag = false; 2023 _zeroFlag = false;
2024 } 2024 }
2025 2025
2026 if (_zeroFlag) 2026 if (_zeroFlag)
2027 { 2027 {
2028 _velocity.X = 0.0f; 2028 _velocity.X = 0.0f;
2029 _velocity.Y = 0.0f; 2029 _velocity.Y = 0.0f;
2030 _velocity.Z = 0.0f; 2030 _velocity.Z = 0.0f;
2031 2031
2032 _acceleration.X = 0; 2032 _acceleration.X = 0;
2033 _acceleration.Y = 0; 2033 _acceleration.Y = 0;
2034 _acceleration.Z = 0; 2034 _acceleration.Z = 0;
2035 2035
2036 //_orientation.w = 0f; 2036 //_orientation.w = 0f;
2037 //_orientation.X = 0f; 2037 //_orientation.X = 0f;
2038 //_orientation.Y = 0f; 2038 //_orientation.Y = 0f;
2039 //_orientation.Z = 0f; 2039 //_orientation.Z = 0f;
2040 m_rotationalVelocity.X = 0; 2040 m_rotationalVelocity.X = 0;
2041 m_rotationalVelocity.Y = 0; 2041 m_rotationalVelocity.Y = 0;
2042 m_rotationalVelocity.Z = 0; 2042 m_rotationalVelocity.Z = 0;
2043 if (!m_lastUpdateSent) 2043 if (!m_lastUpdateSent)
2044 { 2044 {
2045 m_throttleUpdates = false; 2045 m_throttleUpdates = false;
2046 throttleCounter = 0; 2046 throttleCounter = 0;
2047 m_rotationalVelocity = pv; 2047 m_rotationalVelocity = pv;
2048 2048
2049 if (_parent == null) 2049 if (_parent == null)
2050 base.RequestPhysicsterseUpdate(); 2050 base.RequestPhysicsterseUpdate();
2051 2051
2052 m_lastUpdateSent = true; 2052 m_lastUpdateSent = true;
2053 } 2053 }
2054 } 2054 }
2055 else 2055 else
2056 { 2056 {
2057 if (lastZeroFlag != _zeroFlag) 2057 if (lastZeroFlag != _zeroFlag)
2058 { 2058 {
2059 if (_parent == null) 2059 if (_parent == null)
2060 base.RequestPhysicsterseUpdate(); 2060 base.RequestPhysicsterseUpdate();
2061 } 2061 }
2062 2062
2063 m_lastVelocity = _velocity; 2063 m_lastVelocity = _velocity;
2064 2064
2065 _position = l_position; 2065 _position = l_position;
2066 2066
2067 _velocity.X = tempLinearVelocity1.getX(); 2067 _velocity.X = tempLinearVelocity1.getX();
2068 _velocity.Y = tempLinearVelocity1.getY(); 2068 _velocity.Y = tempLinearVelocity1.getY();
2069 _velocity.Z = tempLinearVelocity1.getZ(); 2069 _velocity.Z = tempLinearVelocity1.getZ();
2070 2070
2071 _acceleration = ((_velocity - m_lastVelocity) / 0.1f); 2071 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2072 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); 2072 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
2073 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); 2073 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2074 2074
2075 if (_velocity.IsIdentical(pv, 0.5f)) 2075 if (_velocity.IsIdentical(pv, 0.5f))
2076 { 2076 {
2077 m_rotationalVelocity = pv; 2077 m_rotationalVelocity = pv;
2078 } 2078 }
2079 else 2079 else
2080 { 2080 {
2081 2081
2082 m_rotationalVelocity.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getY(), tempAngularVelocity1.getZ()); 2082 m_rotationalVelocity.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getY(), tempAngularVelocity1.getZ());
2083 } 2083 }
2084 2084
2085 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString()); 2085 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
2086 2086
2087 _orientation.X = l_orientation.X; 2087 _orientation.X = l_orientation.X;
2088 _orientation.Y = l_orientation.Y; 2088 _orientation.Y = l_orientation.Y;
2089 _orientation.Z = l_orientation.Z; 2089 _orientation.Z = l_orientation.Z;
2090 _orientation.W = l_orientation.W; 2090 _orientation.W = l_orientation.W;
2091 m_lastUpdateSent = false; 2091 m_lastUpdateSent = false;
2092 2092
2093 //if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate) 2093 //if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
2094 //{ 2094 //{
2095 if (_parent == null) 2095 if (_parent == null)
2096 base.RequestPhysicsterseUpdate(); 2096 base.RequestPhysicsterseUpdate();
2097 // } 2097 // }
2098 // else 2098 // else
2099 // { 2099 // {
2100 // throttleCounter++; 2100 // throttleCounter++;
2101 //} 2101 //}
2102 2102
2103 } 2103 }
2104 m_lastposition = l_position; 2104 m_lastposition = l_position;
2105 } 2105 }
2106 else 2106 else
2107 { 2107 {
2108 // Not a body.. so Make sure the client isn't interpolating 2108 // Not a body.. so Make sure the client isn't interpolating
2109 _velocity.X = 0; 2109 _velocity.X = 0;
2110 _velocity.Y = 0; 2110 _velocity.Y = 0;
2111 _velocity.Z = 0; 2111 _velocity.Z = 0;
2112 2112
2113 _acceleration.X = 0; 2113 _acceleration.X = 0;
2114 _acceleration.Y = 0; 2114 _acceleration.Y = 0;
2115 _acceleration.Z = 0; 2115 _acceleration.Z = 0;
2116 2116
2117 m_rotationalVelocity.X = 0; 2117 m_rotationalVelocity.X = 0;
2118 m_rotationalVelocity.Y = 0; 2118 m_rotationalVelocity.Y = 0;
2119 m_rotationalVelocity.Z = 0; 2119 m_rotationalVelocity.Z = 0;
2120 _zeroFlag = true; 2120 _zeroFlag = true;
2121 } 2121 }
2122 } 2122 }
2123 2123
2124 2124
2125 internal void setPrimForRemoval() 2125 internal void setPrimForRemoval()
2126 { 2126 {
2127 m_taintremove = true; 2127 m_taintremove = true;
2128 } 2128 }
2129 } 2129 }
2130} 2130}
2131 2131
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
index 4fcf035..f3fee33 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
@@ -1,642 +1,642 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Reflection; 3using System.Reflection;
4using System.IO; 4using System.IO;
5using System.Diagnostics; 5using System.Diagnostics;
6using System.Threading; 6using System.Threading;
7using log4net; 7using log4net;
8using Nini.Config; 8using Nini.Config;
9using OpenSim.Framework; 9using OpenSim.Framework;
10using OpenSim.Region.Physics.Manager; 10using OpenSim.Region.Physics.Manager;
11using OpenMetaverse; 11using OpenMetaverse;
12using BulletDotNET; 12using BulletDotNET;
13 13
14namespace OpenSim.Region.Physics.BulletDotNETPlugin 14namespace OpenSim.Region.Physics.BulletDotNETPlugin
15{ 15{
16 public class BulletDotNETScene : PhysicsScene 16 public class BulletDotNETScene : PhysicsScene
17 { 17 {
18 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 18 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
19 19
20 private string m_sceneIdentifier = string.Empty; 20 private string m_sceneIdentifier = string.Empty;
21 21
22 private List<BulletDotNETCharacter> m_characters = new List<BulletDotNETCharacter>(); 22 private List<BulletDotNETCharacter> m_characters = new List<BulletDotNETCharacter>();
23 private List<BulletDotNETPrim> m_prims = new List<BulletDotNETPrim>(); 23 private List<BulletDotNETPrim> m_prims = new List<BulletDotNETPrim>();
24 private List<BulletDotNETPrim> m_activePrims = new List<BulletDotNETPrim>(); 24 private List<BulletDotNETPrim> m_activePrims = new List<BulletDotNETPrim>();
25 private List<PhysicsActor> m_taintedActors = new List<PhysicsActor>(); 25 private List<PhysicsActor> m_taintedActors = new List<PhysicsActor>();
26 private btDiscreteDynamicsWorld m_world; 26 private btDiscreteDynamicsWorld m_world;
27 private btAxisSweep3 m_broadphase; 27 private btAxisSweep3 m_broadphase;
28 private btCollisionConfiguration m_collisionConfiguration; 28 private btCollisionConfiguration m_collisionConfiguration;
29 private btConstraintSolver m_solver; 29 private btConstraintSolver m_solver;
30 private btCollisionDispatcher m_dispatcher; 30 private btCollisionDispatcher m_dispatcher;
31 private btHeightfieldTerrainShape m_terrainShape; 31 private btHeightfieldTerrainShape m_terrainShape;
32 public btRigidBody TerrainBody; 32 public btRigidBody TerrainBody;
33 private btVector3 m_terrainPosition; 33 private btVector3 m_terrainPosition;
34 private btVector3 m_gravity; 34 private btVector3 m_gravity;
35 public btMotionState m_terrainMotionState; 35 public btMotionState m_terrainMotionState;
36 public btTransform m_terrainTransform; 36 public btTransform m_terrainTransform;
37 public btVector3 VectorZero; 37 public btVector3 VectorZero;
38 public btQuaternion QuatIdentity; 38 public btQuaternion QuatIdentity;
39 public btTransform TransZero; 39 public btTransform TransZero;
40 40
41 public float geomDefaultDensity = 10.000006836f; 41 public float geomDefaultDensity = 10.000006836f;
42 42
43 private float avPIDD = 65f; 43 private float avPIDD = 65f;
44 private float avPIDP = 28f; 44 private float avPIDP = 28f;
45 private float avCapRadius = 0.37f; 45 private float avCapRadius = 0.37f;
46 private float avStandupTensor = 2000000f; 46 private float avStandupTensor = 2000000f;
47 private float avDensity = 80f; 47 private float avDensity = 80f;
48 private float avHeightFudgeFactor = 0.52f; 48 private float avHeightFudgeFactor = 0.52f;
49 private float avMovementDivisorWalk = 1.0f; 49 private float avMovementDivisorWalk = 1.0f;
50 private float avMovementDivisorRun = 0.75f; 50 private float avMovementDivisorRun = 0.75f;
51 51
52 private float minimumGroundFlightOffset = 3f; 52 private float minimumGroundFlightOffset = 3f;
53 53
54 public bool meshSculptedPrim = true; 54 public bool meshSculptedPrim = true;
55 55
56 public float meshSculptLOD = 32; 56 public float meshSculptLOD = 32;
57 public float MeshSculptphysicalLOD = 16; 57 public float MeshSculptphysicalLOD = 16;
58 58
59 public float bodyPIDD = 35f; 59 public float bodyPIDD = 35f;
60 public float bodyPIDG = 25; 60 public float bodyPIDG = 25;
61 internal int geomCrossingFailuresBeforeOutofbounds = 4; 61 internal int geomCrossingFailuresBeforeOutofbounds = 4;
62 62
63 public float bodyMotorJointMaxforceTensor = 2; 63 public float bodyMotorJointMaxforceTensor = 2;
64 64
65 public int bodyFramesAutoDisable = 20; 65 public int bodyFramesAutoDisable = 20;
66 66
67 public float WorldTimeStep = 10f/60f; 67 public float WorldTimeStep = 10f/60f;
68 public const float WorldTimeComp = 1/60f; 68 public const float WorldTimeComp = 1/60f;
69 public float gravityz = -9.8f; 69 public float gravityz = -9.8f;
70 70
71 private float[] _origheightmap; // Used for Fly height. Kitto Flora 71 private float[] _origheightmap; // Used for Fly height. Kitto Flora
72 private bool usingGImpactAlgorithm = false; 72 private bool usingGImpactAlgorithm = false;
73 73
74 private IConfigSource m_config; 74 private IConfigSource m_config;
75 private readonly btVector3 worldAabbMin = new btVector3(0, 0, 0); 75 private readonly btVector3 worldAabbMin = new btVector3(0, 0, 0);
76 private readonly btVector3 worldAabbMax = new btVector3(Constants.RegionSize, Constants.RegionSize , 9000); 76 private readonly btVector3 worldAabbMax = new btVector3(Constants.RegionSize, Constants.RegionSize , 9000);
77 77
78 public IMesher mesher; 78 public IMesher mesher;
79 79
80 public BulletDotNETScene(string sceneIdentifier) 80 public BulletDotNETScene(string sceneIdentifier)
81 { 81 {
82 m_sceneIdentifier = sceneIdentifier; 82 m_sceneIdentifier = sceneIdentifier;
83 VectorZero = new btVector3(0, 0, 0); 83 VectorZero = new btVector3(0, 0, 0);
84 QuatIdentity = new btQuaternion(0, 0, 0, 1); 84 QuatIdentity = new btQuaternion(0, 0, 0, 1);
85 TransZero = new btTransform(QuatIdentity, VectorZero); 85 TransZero = new btTransform(QuatIdentity, VectorZero);
86 m_gravity = new btVector3(0, 0, gravityz); 86 m_gravity = new btVector3(0, 0, gravityz);
87 _origheightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize]; 87 _origheightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize];
88 } 88 }
89 89
90 public override void Initialise(IMesher meshmerizer, IConfigSource config) 90 public override void Initialise(IMesher meshmerizer, IConfigSource config)
91 { 91 {
92 mesher = meshmerizer; 92 mesher = meshmerizer;
93 m_config = config; 93 m_config = config;
94 if (Environment.OSVersion.Platform == PlatformID.Unix) 94 if (Environment.OSVersion.Platform == PlatformID.Unix)
95 { 95 {
96 m_log.Fatal("[BulletDotNET]: This configuration is not supported on *nix currently"); 96 m_log.Fatal("[BulletDotNET]: This configuration is not supported on *nix currently");
97 Thread.Sleep(5000); 97 Thread.Sleep(5000);
98 Environment.Exit(0); 98 Environment.Exit(0);
99 } 99 }
100 m_broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax, 16000); 100 m_broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax, 16000);
101 m_collisionConfiguration = new btDefaultCollisionConfiguration(); 101 m_collisionConfiguration = new btDefaultCollisionConfiguration();
102 m_solver = new btSequentialImpulseConstraintSolver(); 102 m_solver = new btSequentialImpulseConstraintSolver();
103 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); 103 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
104 m_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration); 104 m_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
105 m_world.setGravity(m_gravity); 105 m_world.setGravity(m_gravity);
106 } 106 }
107 107
108 public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size, bool isFlying) 108 public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size, bool isFlying)
109 { 109 {
110 BulletDotNETCharacter chr = new BulletDotNETCharacter(avName, this, position, size, avPIDD, avPIDP, 110 BulletDotNETCharacter chr = new BulletDotNETCharacter(avName, this, position, size, avPIDD, avPIDP,
111 avCapRadius, avStandupTensor, avDensity, 111 avCapRadius, avStandupTensor, avDensity,
112 avHeightFudgeFactor, avMovementDivisorWalk, 112 avHeightFudgeFactor, avMovementDivisorWalk,
113 avMovementDivisorRun); 113 avMovementDivisorRun);
114 m_characters.Add(chr); 114 m_characters.Add(chr);
115 AddPhysicsActorTaint(chr); 115 AddPhysicsActorTaint(chr);
116 return chr; 116 return chr;
117 } 117 }
118 118
119 public override void RemoveAvatar(PhysicsActor actor) 119 public override void RemoveAvatar(PhysicsActor actor)
120 { 120 {
121 BulletDotNETCharacter chr = (BulletDotNETCharacter) actor; 121 BulletDotNETCharacter chr = (BulletDotNETCharacter) actor;
122 122
123 m_characters.Remove(chr); 123 m_characters.Remove(chr);
124 m_world.removeRigidBody(chr.Body); 124 m_world.removeRigidBody(chr.Body);
125 m_world.removeCollisionObject(chr.Body); 125 m_world.removeCollisionObject(chr.Body);
126 126
127 chr.Remove(); 127 chr.Remove();
128 AddPhysicsActorTaint(chr); 128 AddPhysicsActorTaint(chr);
129 //chr = null; 129 //chr = null;
130 } 130 }
131 131
132 public override void RemovePrim(PhysicsActor prim) 132 public override void RemovePrim(PhysicsActor prim)
133 { 133 {
134 if (prim is BulletDotNETPrim) 134 if (prim is BulletDotNETPrim)
135 { 135 {
136 136
137 BulletDotNETPrim p = (BulletDotNETPrim)prim; 137 BulletDotNETPrim p = (BulletDotNETPrim)prim;
138 138
139 p.setPrimForRemoval(); 139 p.setPrimForRemoval();
140 AddPhysicsActorTaint(prim); 140 AddPhysicsActorTaint(prim);
141 //RemovePrimThreadLocked(p); 141 //RemovePrimThreadLocked(p);
142 142
143 } 143 }
144 } 144 }
145 145
146 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, 146 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation,
147 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) 147 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical)
148 { 148 {
149 PhysicsVector pos = new PhysicsVector(position.X, position.Y, position.Z); 149 PhysicsVector pos = new PhysicsVector(position.X, position.Y, position.Z);
150 //pos.X = position.X; 150 //pos.X = position.X;
151 //pos.Y = position.Y; 151 //pos.Y = position.Y;
152 //pos.Z = position.Z; 152 //pos.Z = position.Z;
153 PhysicsVector siz = new PhysicsVector(); 153 PhysicsVector siz = new PhysicsVector();
154 siz.X = size.X; 154 siz.X = size.X;
155 siz.Y = size.Y; 155 siz.Y = size.Y;
156 siz.Z = size.Z; 156 siz.Z = size.Z;
157 Quaternion rot = rotation; 157 Quaternion rot = rotation;
158 158
159 BulletDotNETPrim newPrim; 159 BulletDotNETPrim newPrim;
160 160
161 newPrim = new BulletDotNETPrim(name, this, pos, siz, rot, mesh, pbs, isphysical); 161 newPrim = new BulletDotNETPrim(name, this, pos, siz, rot, mesh, pbs, isphysical);
162 162
163 lock (m_prims) 163 lock (m_prims)
164 m_prims.Add(newPrim); 164 m_prims.Add(newPrim);
165 165
166 166
167 return newPrim; 167 return newPrim;
168 } 168 }
169 169
170 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) 170 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation)
171 { 171 {
172 return AddPrimShape(primName, pbs, position, size, rotation, false); 172 return AddPrimShape(primName, pbs, position, size, rotation, false);
173 } 173 }
174 174
175 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical) 175 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation, bool isPhysical)
176 { 176 {
177 PhysicsActor result; 177 PhysicsActor result;
178 IMesh mesh = null; 178 IMesh mesh = null;
179 179
180 //switch (pbs.ProfileShape) 180 //switch (pbs.ProfileShape)
181 //{ 181 //{
182 // case ProfileShape.Square: 182 // case ProfileShape.Square:
183 // //support simple box & hollow box now; later, more shapes 183 // //support simple box & hollow box now; later, more shapes
184 // if (needsMeshing(pbs)) 184 // if (needsMeshing(pbs))
185 // { 185 // {
186 // mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); 186 // mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical);
187 // } 187 // }
188 188
189 // break; 189 // break;
190 //} 190 //}
191 191
192 if (needsMeshing(pbs)) 192 if (needsMeshing(pbs))
193 mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); 193 mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical);
194 194
195 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); 195 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical);
196 196
197 return result; 197 return result;
198 } 198 }
199 199
200 public override void AddPhysicsActorTaint(PhysicsActor prim) 200 public override void AddPhysicsActorTaint(PhysicsActor prim)
201 { 201 {
202 lock (m_taintedActors) 202 lock (m_taintedActors)
203 { 203 {
204 if (!m_taintedActors.Contains(prim)) 204 if (!m_taintedActors.Contains(prim))
205 { 205 {
206 m_taintedActors.Add(prim); 206 m_taintedActors.Add(prim);
207 } 207 }
208 } 208 }
209 } 209 }
210 internal void SetUsingGImpact() 210 internal void SetUsingGImpact()
211 { 211 {
212 if (!usingGImpactAlgorithm) 212 if (!usingGImpactAlgorithm)
213 btGImpactCollisionAlgorithm.registerAlgorithm(m_dispatcher); 213 btGImpactCollisionAlgorithm.registerAlgorithm(m_dispatcher);
214 usingGImpactAlgorithm = true; 214 usingGImpactAlgorithm = true;
215 } 215 }
216 216
217 public override float Simulate(float timeStep) 217 public override float Simulate(float timeStep)
218 { 218 {
219 lock (m_taintedActors) 219 lock (m_taintedActors)
220 { 220 {
221 foreach (PhysicsActor act in m_taintedActors) 221 foreach (PhysicsActor act in m_taintedActors)
222 { 222 {
223 if (act is BulletDotNETCharacter) 223 if (act is BulletDotNETCharacter)
224 ((BulletDotNETCharacter) act).ProcessTaints(timeStep); 224 ((BulletDotNETCharacter) act).ProcessTaints(timeStep);
225 if (act is BulletDotNETPrim) 225 if (act is BulletDotNETPrim)
226 ((BulletDotNETPrim)act).ProcessTaints(timeStep); 226 ((BulletDotNETPrim)act).ProcessTaints(timeStep);
227 } 227 }
228 m_taintedActors.Clear(); 228 m_taintedActors.Clear();
229 } 229 }
230 230
231 lock (m_characters) 231 lock (m_characters)
232 { 232 {
233 foreach (BulletDotNETCharacter chr in m_characters) 233 foreach (BulletDotNETCharacter chr in m_characters)
234 { 234 {
235 chr.Move(timeStep); 235 chr.Move(timeStep);
236 } 236 }
237 } 237 }
238 238
239 lock (m_prims) 239 lock (m_prims)
240 { 240 {
241 foreach (BulletDotNETPrim prim in m_prims) 241 foreach (BulletDotNETPrim prim in m_prims)
242 { 242 {
243 prim.Move(timeStep); 243 prim.Move(timeStep);
244 } 244 }
245 } 245 }
246 float steps = m_world.stepSimulation(WorldTimeStep, 5, WorldTimeComp); 246 float steps = m_world.stepSimulation(WorldTimeStep, 5, WorldTimeComp);
247 247
248 foreach (BulletDotNETCharacter chr in m_characters) 248 foreach (BulletDotNETCharacter chr in m_characters)
249 { 249 {
250 chr.UpdatePositionAndVelocity(); 250 chr.UpdatePositionAndVelocity();
251 } 251 }
252 252
253 foreach (BulletDotNETPrim prm in m_activePrims) 253 foreach (BulletDotNETPrim prm in m_activePrims)
254 { 254 {
255 prm.UpdatePositionAndVelocity(); 255 prm.UpdatePositionAndVelocity();
256 } 256 }
257 257
258 return steps; 258 return steps;
259 } 259 }
260 260
261 public override void GetResults() 261 public override void GetResults()
262 { 262 {
263 263
264 } 264 }
265 265
266 public override void SetTerrain(float[] heightMap) 266 public override void SetTerrain(float[] heightMap)
267 { 267 {
268 if (m_terrainShape != null) 268 if (m_terrainShape != null)
269 DeleteTerrain(); 269 DeleteTerrain();
270 270
271 float hfmax = -9000; 271 float hfmax = -9000;
272 float hfmin = 90000; 272 float hfmin = 90000;
273 273
274 for (int i = 0; i <heightMap.Length;i++) 274 for (int i = 0; i <heightMap.Length;i++)
275 { 275 {
276 if (Single.IsNaN(heightMap[i]) || Single.IsInfinity(heightMap[i])) 276 if (Single.IsNaN(heightMap[i]) || Single.IsInfinity(heightMap[i]))
277 { 277 {
278 heightMap[i] = 0f; 278 heightMap[i] = 0f;
279 } 279 }
280 280
281 hfmin = (heightMap[i] < hfmin) ? heightMap[i] : hfmin; 281 hfmin = (heightMap[i] < hfmin) ? heightMap[i] : hfmin;
282 hfmax = (heightMap[i] > hfmax) ? heightMap[i] : hfmax; 282 hfmax = (heightMap[i] > hfmax) ? heightMap[i] : hfmax;
283 } 283 }
284 // store this for later reference. 284 // store this for later reference.
285 // Note, we're storing it after we check it for anomolies above 285 // Note, we're storing it after we check it for anomolies above
286 _origheightmap = heightMap; 286 _origheightmap = heightMap;
287 287
288 hfmin = 0; 288 hfmin = 0;
289 hfmax = 256; 289 hfmax = 256;
290 290
291 m_terrainShape = new btHeightfieldTerrainShape((int)Constants.RegionSize, (int)Constants.RegionSize, heightMap, 291 m_terrainShape = new btHeightfieldTerrainShape((int)Constants.RegionSize, (int)Constants.RegionSize, heightMap,
292 1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z, 292 1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z,
293 (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false); 293 (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false);
294 float AabbCenterX = Constants.RegionSize/2f; 294 float AabbCenterX = Constants.RegionSize/2f;
295 float AabbCenterY = Constants.RegionSize/2f; 295 float AabbCenterY = Constants.RegionSize/2f;
296 296
297 float AabbCenterZ = 0; 297 float AabbCenterZ = 0;
298 float temphfmin, temphfmax; 298 float temphfmin, temphfmax;
299 299
300 temphfmin = hfmin; 300 temphfmin = hfmin;
301 temphfmax = hfmax; 301 temphfmax = hfmax;
302 302
303 if (temphfmin < 0) 303 if (temphfmin < 0)
304 { 304 {
305 temphfmax = 0 - temphfmin; 305 temphfmax = 0 - temphfmin;
306 temphfmin = 0 - temphfmin; 306 temphfmin = 0 - temphfmin;
307 } 307 }
308 else if (temphfmin > 0) 308 else if (temphfmin > 0)
309 { 309 {
310 temphfmax = temphfmax + (0 - temphfmin); 310 temphfmax = temphfmax + (0 - temphfmin);
311 //temphfmin = temphfmin + (0 - temphfmin); 311 //temphfmin = temphfmin + (0 - temphfmin);
312 } 312 }
313 AabbCenterZ = temphfmax/2f; 313 AabbCenterZ = temphfmax/2f;
314 314
315 if (m_terrainPosition == null) 315 if (m_terrainPosition == null)
316 { 316 {
317 m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ); 317 m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
318 } 318 }
319 else 319 else
320 { 320 {
321 try 321 try
322 { 322 {
323 m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ); 323 m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
324 } 324 }
325 catch (ObjectDisposedException) 325 catch (ObjectDisposedException)
326 { 326 {
327 m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ); 327 m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
328 } 328 }
329 } 329 }
330 if (m_terrainMotionState != null) 330 if (m_terrainMotionState != null)
331 { 331 {
332 m_terrainMotionState.Dispose(); 332 m_terrainMotionState.Dispose();
333 m_terrainMotionState = null; 333 m_terrainMotionState = null;
334 } 334 }
335 m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition); 335 m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition);
336 m_terrainMotionState = new btDefaultMotionState(m_terrainTransform); 336 m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
337 TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape); 337 TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
338 m_world.addRigidBody(TerrainBody); 338 m_world.addRigidBody(TerrainBody);
339 339
340 340
341 } 341 }
342 342
343 public override void SetWaterLevel(float baseheight) 343 public override void SetWaterLevel(float baseheight)
344 { 344 {
345 345
346 } 346 }
347 347
348 public override void DeleteTerrain() 348 public override void DeleteTerrain()
349 { 349 {
350 if (TerrainBody != null) 350 if (TerrainBody != null)
351 { 351 {
352 m_world.removeRigidBody(TerrainBody); 352 m_world.removeRigidBody(TerrainBody);
353 } 353 }
354 354
355 if (m_terrainShape != null) 355 if (m_terrainShape != null)
356 { 356 {
357 m_terrainShape.Dispose(); 357 m_terrainShape.Dispose();
358 m_terrainShape = null; 358 m_terrainShape = null;
359 } 359 }
360 360
361 if (m_terrainMotionState != null) 361 if (m_terrainMotionState != null)
362 { 362 {
363 m_terrainMotionState.Dispose(); 363 m_terrainMotionState.Dispose();
364 m_terrainMotionState = null; 364 m_terrainMotionState = null;
365 } 365 }
366 366
367 if (m_terrainTransform != null) 367 if (m_terrainTransform != null)
368 { 368 {
369 m_terrainTransform.Dispose(); 369 m_terrainTransform.Dispose();
370 m_terrainTransform = null; 370 m_terrainTransform = null;
371 } 371 }
372 372
373 if (m_terrainPosition != null) 373 if (m_terrainPosition != null)
374 { 374 {
375 m_terrainPosition.Dispose(); 375 m_terrainPosition.Dispose();
376 m_terrainPosition = null; 376 m_terrainPosition = null;
377 } 377 }
378 } 378 }
379 379
380 public override void Dispose() 380 public override void Dispose()
381 { 381 {
382 disposeAllBodies(); 382 disposeAllBodies();
383 m_world.Dispose(); 383 m_world.Dispose();
384 m_broadphase.Dispose(); 384 m_broadphase.Dispose();
385 ((btDefaultCollisionConfiguration) m_collisionConfiguration).Dispose(); 385 ((btDefaultCollisionConfiguration) m_collisionConfiguration).Dispose();
386 ((btSequentialImpulseConstraintSolver) m_solver).Dispose(); 386 ((btSequentialImpulseConstraintSolver) m_solver).Dispose();
387 worldAabbMax.Dispose(); 387 worldAabbMax.Dispose();
388 worldAabbMin.Dispose(); 388 worldAabbMin.Dispose();
389 VectorZero.Dispose(); 389 VectorZero.Dispose();
390 QuatIdentity.Dispose(); 390 QuatIdentity.Dispose();
391 m_gravity.Dispose(); 391 m_gravity.Dispose();
392 VectorZero = null; 392 VectorZero = null;
393 QuatIdentity = null; 393 QuatIdentity = null;
394 } 394 }
395 395
396 public override Dictionary<uint, float> GetTopColliders() 396 public override Dictionary<uint, float> GetTopColliders()
397 { 397 {
398 return new Dictionary<uint, float>(); 398 return new Dictionary<uint, float>();
399 } 399 }
400 400
401 public btDiscreteDynamicsWorld getBulletWorld() 401 public btDiscreteDynamicsWorld getBulletWorld()
402 { 402 {
403 return m_world; 403 return m_world;
404 } 404 }
405 405
406 private void disposeAllBodies() 406 private void disposeAllBodies()
407 { 407 {
408 lock (m_prims) 408 lock (m_prims)
409 { 409 {
410 foreach ( BulletDotNETPrim prim in m_prims) 410 foreach ( BulletDotNETPrim prim in m_prims)
411 { 411 {
412 if (prim.Body != null) 412 if (prim.Body != null)
413 m_world.removeRigidBody(prim.Body); 413 m_world.removeRigidBody(prim.Body);
414 414
415 prim.Dispose(); 415 prim.Dispose();
416 } 416 }
417 m_prims.Clear(); 417 m_prims.Clear();
418 418
419 foreach (BulletDotNETCharacter chr in m_characters) 419 foreach (BulletDotNETCharacter chr in m_characters)
420 { 420 {
421 if (chr.Body != null) 421 if (chr.Body != null)
422 m_world.removeRigidBody(chr.Body); 422 m_world.removeRigidBody(chr.Body);
423 chr.Dispose(); 423 chr.Dispose();
424 } 424 }
425 m_characters.Clear(); 425 m_characters.Clear();
426 } 426 }
427 } 427 }
428 428
429 public override bool IsThreaded 429 public override bool IsThreaded
430 { 430 {
431 get { return false; } 431 get { return false; }
432 } 432 }
433 433
434 internal void addCollisionEventReporting(PhysicsActor bulletDotNETCharacter) 434 internal void addCollisionEventReporting(PhysicsActor bulletDotNETCharacter)
435 { 435 {
436 //TODO: FIXME: 436 //TODO: FIXME:
437 } 437 }
438 438
439 internal void remCollisionEventReporting(PhysicsActor bulletDotNETCharacter) 439 internal void remCollisionEventReporting(PhysicsActor bulletDotNETCharacter)
440 { 440 {
441 //TODO: FIXME: 441 //TODO: FIXME:
442 } 442 }
443 443
444 internal void AddRigidBody(btRigidBody Body) 444 internal void AddRigidBody(btRigidBody Body)
445 { 445 {
446 m_world.addRigidBody(Body); 446 m_world.addRigidBody(Body);
447 } 447 }
448 [Obsolete("bad!")] 448 [Obsolete("bad!")]
449 internal void removeFromWorld(btRigidBody body) 449 internal void removeFromWorld(btRigidBody body)
450 { 450 {
451 451
452 m_world.removeRigidBody(body); 452 m_world.removeRigidBody(body);
453 } 453 }
454 454
455 internal void removeFromWorld(BulletDotNETPrim prm ,btRigidBody body) 455 internal void removeFromWorld(BulletDotNETPrim prm ,btRigidBody body)
456 { 456 {
457 lock (m_prims) 457 lock (m_prims)
458 { 458 {
459 if (m_prims.Contains(prm)) 459 if (m_prims.Contains(prm))
460 { 460 {
461 m_world.removeRigidBody(body); 461 m_world.removeRigidBody(body);
462 } 462 }
463 m_prims.Remove(prm); 463 m_prims.Remove(prm);
464 } 464 }
465 465
466 } 466 }
467 467
468 internal float GetWaterLevel() 468 internal float GetWaterLevel()
469 { 469 {
470 throw new NotImplementedException(); 470 throw new NotImplementedException();
471 } 471 }
472 472
473 // Recovered for use by fly height. Kitto Flora 473 // Recovered for use by fly height. Kitto Flora
474 public float GetTerrainHeightAtXY(float x, float y) 474 public float GetTerrainHeightAtXY(float x, float y)
475 { 475 {
476 // Teravus: Kitto, this code causes recurring errors that stall physics permenantly unless 476 // Teravus: Kitto, this code causes recurring errors that stall physics permenantly unless
477 // the values are checked, so checking below. 477 // the values are checked, so checking below.
478 // Is there any reason that we don't do this in ScenePresence? 478 // Is there any reason that we don't do this in ScenePresence?
479 // The only physics engine that benefits from it in the physics plugin is this one 479 // The only physics engine that benefits from it in the physics plugin is this one
480 480
481 if ((int)x > Constants.RegionSize || (int)y > Constants.RegionSize || 481 if ((int)x > Constants.RegionSize || (int)y > Constants.RegionSize ||
482 (int)x < 0.001f || (int)y < 0.001f) 482 (int)x < 0.001f || (int)y < 0.001f)
483 return 0; 483 return 0;
484 484
485 return _origheightmap[(int)y * Constants.RegionSize + (int)x]; 485 return _origheightmap[(int)y * Constants.RegionSize + (int)x];
486 } 486 }
487 // End recovered. Kitto Flora 487 // End recovered. Kitto Flora
488 488
489 /// <summary> 489 /// <summary>
490 /// Routine to figure out if we need to mesh this prim with our mesher 490 /// Routine to figure out if we need to mesh this prim with our mesher
491 /// </summary> 491 /// </summary>
492 /// <param name="pbs"></param> 492 /// <param name="pbs"></param>
493 /// <returns></returns> 493 /// <returns></returns>
494 public bool needsMeshing(PrimitiveBaseShape pbs) 494 public bool needsMeshing(PrimitiveBaseShape pbs)
495 { 495 {
496 // most of this is redundant now as the mesher will return null if it cant mesh a prim 496 // most of this is redundant now as the mesher will return null if it cant mesh a prim
497 // but we still need to check for sculptie meshing being enabled so this is the most 497 // but we still need to check for sculptie meshing being enabled so this is the most
498 // convenient place to do it for now... 498 // convenient place to do it for now...
499 499
500 // //if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle && pbs.ProfileCurve == (byte)Primitive.ProfileCurve.Circle && pbs.PathScaleY <= 0.75f) 500 // //if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle && pbs.ProfileCurve == (byte)Primitive.ProfileCurve.Circle && pbs.PathScaleY <= 0.75f)
501 // //m_log.Debug("needsMeshing: " + " pathCurve: " + pbs.PathCurve.ToString() + " profileCurve: " + pbs.ProfileCurve.ToString() + " pathScaleY: " + Primitive.UnpackPathScale(pbs.PathScaleY).ToString()); 501 // //m_log.Debug("needsMeshing: " + " pathCurve: " + pbs.PathCurve.ToString() + " profileCurve: " + pbs.ProfileCurve.ToString() + " pathScaleY: " + Primitive.UnpackPathScale(pbs.PathScaleY).ToString());
502 int iPropertiesNotSupportedDefault = 0; 502 int iPropertiesNotSupportedDefault = 0;
503 503
504 if (pbs.SculptEntry && !meshSculptedPrim) 504 if (pbs.SculptEntry && !meshSculptedPrim)
505 { 505 {
506#if SPAM 506#if SPAM
507 m_log.Warn("NonMesh"); 507 m_log.Warn("NonMesh");
508#endif 508#endif
509 return false; 509 return false;
510 } 510 }
511 511
512 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim 512 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim
513 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight) 513 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
514 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 514 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
515 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z)) 515 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
516 { 516 {
517 517
518 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 518 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
519 && pbs.ProfileHollow == 0 519 && pbs.ProfileHollow == 0
520 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 520 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
521 && pbs.PathBegin == 0 && pbs.PathEnd == 0 521 && pbs.PathBegin == 0 && pbs.PathEnd == 0
522 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0 522 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
523 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 523 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
524 && pbs.PathShearX == 0 && pbs.PathShearY == 0) 524 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
525 { 525 {
526#if SPAM 526#if SPAM
527 m_log.Warn("NonMesh"); 527 m_log.Warn("NonMesh");
528#endif 528#endif
529 return false; 529 return false;
530 } 530 }
531 } 531 }
532 532
533 if (pbs.ProfileHollow != 0) 533 if (pbs.ProfileHollow != 0)
534 iPropertiesNotSupportedDefault++; 534 iPropertiesNotSupportedDefault++;
535 535
536 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0)) 536 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0))
537 iPropertiesNotSupportedDefault++; 537 iPropertiesNotSupportedDefault++;
538 538
539 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0) 539 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
540 iPropertiesNotSupportedDefault++; 540 iPropertiesNotSupportedDefault++;
541 541
542 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100)) 542 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
543 iPropertiesNotSupportedDefault++; 543 iPropertiesNotSupportedDefault++;
544 544
545 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0)) 545 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
546 iPropertiesNotSupportedDefault++; 546 iPropertiesNotSupportedDefault++;
547 547
548 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight) 548 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
549 iPropertiesNotSupportedDefault++; 549 iPropertiesNotSupportedDefault++;
550 550
551 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X)) 551 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
552 iPropertiesNotSupportedDefault++; 552 iPropertiesNotSupportedDefault++;
553 553
554 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) 554 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1)
555 iPropertiesNotSupportedDefault++; 555 iPropertiesNotSupportedDefault++;
556 556
557 // test for torus 557 // test for torus
558 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square) 558 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
559 { 559 {
560 if (pbs.PathCurve == (byte)Extrusion.Curve1) 560 if (pbs.PathCurve == (byte)Extrusion.Curve1)
561 { 561 {
562 iPropertiesNotSupportedDefault++; 562 iPropertiesNotSupportedDefault++;
563 } 563 }
564 } 564 }
565 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) 565 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
566 { 566 {
567 if (pbs.PathCurve == (byte)Extrusion.Straight) 567 if (pbs.PathCurve == (byte)Extrusion.Straight)
568 { 568 {
569 iPropertiesNotSupportedDefault++; 569 iPropertiesNotSupportedDefault++;
570 } 570 }
571 571
572 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits 572 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
573 else if (pbs.PathCurve == (byte)Extrusion.Curve1) 573 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
574 { 574 {
575 iPropertiesNotSupportedDefault++; 575 iPropertiesNotSupportedDefault++;
576 } 576 }
577 } 577 }
578 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) 578 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
579 { 579 {
580 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2) 580 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
581 { 581 {
582 iPropertiesNotSupportedDefault++; 582 iPropertiesNotSupportedDefault++;
583 } 583 }
584 } 584 }
585 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) 585 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
586 { 586 {
587 if (pbs.PathCurve == (byte)Extrusion.Straight) 587 if (pbs.PathCurve == (byte)Extrusion.Straight)
588 { 588 {
589 iPropertiesNotSupportedDefault++; 589 iPropertiesNotSupportedDefault++;
590 } 590 }
591 else if (pbs.PathCurve == (byte)Extrusion.Curve1) 591 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
592 { 592 {
593 iPropertiesNotSupportedDefault++; 593 iPropertiesNotSupportedDefault++;
594 } 594 }
595 } 595 }
596 596
597 597
598 if (iPropertiesNotSupportedDefault == 0) 598 if (iPropertiesNotSupportedDefault == 0)
599 { 599 {
600#if SPAM 600#if SPAM
601 m_log.Warn("NonMesh"); 601 m_log.Warn("NonMesh");
602#endif 602#endif
603 return false; 603 return false;
604 } 604 }
605#if SPAM 605#if SPAM
606 m_log.Debug("Mesh"); 606 m_log.Debug("Mesh");
607#endif 607#endif
608 return true; 608 return true;
609 } 609 }
610 610
611 internal void addActivePrim(BulletDotNETPrim pPrim) 611 internal void addActivePrim(BulletDotNETPrim pPrim)
612 { 612 {
613 lock (m_activePrims) 613 lock (m_activePrims)
614 { 614 {
615 if (!m_activePrims.Contains(pPrim)) 615 if (!m_activePrims.Contains(pPrim))
616 { 616 {
617 m_activePrims.Add(pPrim); 617 m_activePrims.Add(pPrim);
618 } 618 }
619 } 619 }
620 } 620 }
621 621
622 public void remActivePrim(BulletDotNETPrim pDeactivatePrim) 622 public void remActivePrim(BulletDotNETPrim pDeactivatePrim)
623 { 623 {
624 lock (m_activePrims) 624 lock (m_activePrims)
625 { 625 {
626 m_activePrims.Remove(pDeactivatePrim); 626 m_activePrims.Remove(pDeactivatePrim);
627 } 627 }
628 } 628 }
629 629
630 internal void AddPrimToScene(BulletDotNETPrim pPrim) 630 internal void AddPrimToScene(BulletDotNETPrim pPrim)
631 { 631 {
632 lock (m_prims) 632 lock (m_prims)
633 { 633 {
634 if (!m_prims.Contains(pPrim)) 634 if (!m_prims.Contains(pPrim))
635 { 635 {
636 m_prims.Add(pPrim); 636 m_prims.Add(pPrim);
637 m_world.addRigidBody(pPrim.Body); 637 m_world.addRigidBody(pPrim.Body);
638 } 638 }
639 } 639 }
640 } 640 }
641 } 641 }
642} 642}