();
+ m_mass = parent.RawMass;
+ Rebuilding = false;
+ }
+
+ // Link to a linkset where the child knows the parent.
+ // Parent changing should not happen so do some sanity checking.
+ // We return the parent's linkset so the child can track its membership.
+ // Called at runtime.
+ public BSLinkset AddMeToLinkset(BSPhysObject child)
+ {
+ lock (m_linksetActivityLock)
+ {
+ // Don't add the root to its own linkset
+ if (!IsRoot(child))
+ AddChildToLinkset(child);
+ m_mass = ComputeLinksetMass();
+ }
+ return this;
+ }
+
+ // Remove a child from a linkset.
+ // Returns a new linkset for the child which is a linkset of one (just the
+ // orphened child).
+ // Called at runtime.
+ public BSLinkset RemoveMeFromLinkset(BSPhysObject child)
+ {
+ lock (m_linksetActivityLock)
+ {
+ if (IsRoot(child))
+ {
+ // Cannot remove the root from a linkset.
+ return this;
+ }
+ RemoveChildFromLinkset(child);
+ m_mass = ComputeLinksetMass();
+ }
+
+ // The child is down to a linkset of just itself
+ return BSLinkset.Factory(PhysicsScene, child);
+ }
+
+ // Return 'true' if the passed object is the root object of this linkset
+ public bool IsRoot(BSPhysObject requestor)
+ {
+ return (requestor.LocalID == LinksetRoot.LocalID);
+ }
+
+ public int NumberOfChildren { get { return m_children.Count; } }
+
+ // Return 'true' if this linkset has any children (more than the root member)
+ public bool HasAnyChildren { get { return (m_children.Count > 0); } }
+
+ // Return 'true' if this child is in this linkset
+ public bool HasChild(BSPhysObject child)
+ {
+ bool ret = false;
+ lock (m_linksetActivityLock)
+ {
+ ret = m_children.Contains(child);
+ /* Safer version but the above should work
+ foreach (BSPhysObject bp in m_children)
+ {
+ if (child.LocalID == bp.LocalID)
+ {
+ ret = true;
+ break;
+ }
+ }
+ */
+ }
+ return ret;
+ }
+
+ // Perform an action on each member of the linkset including root prim.
+ // Depends on the action on whether this should be done at taint time.
+ public delegate bool ForEachMemberAction(BSPhysObject obj);
+ public virtual bool ForEachMember(ForEachMemberAction action)
+ {
+ bool ret = false;
+ lock (m_linksetActivityLock)
+ {
+ action(LinksetRoot);
+ foreach (BSPhysObject po in m_children)
+ {
+ if (action(po))
+ break;
+ }
+ }
+ return ret;
+ }
+
+ // I am the root of a linkset and a new child is being added
+ // Called while LinkActivity is locked.
+ protected abstract void AddChildToLinkset(BSPhysObject child);
+
+ // I am the root of a linkset and one of my children is being removed.
+ // Safe to call even if the child is not really in my linkset.
+ protected abstract void RemoveChildFromLinkset(BSPhysObject child);
+
+ // When physical properties are changed the linkset needs to recalculate
+ // its internal properties.
+ // May be called at runtime or taint-time.
+ public abstract void Refresh(BSPhysObject requestor);
+
+ // Flag denoting the linkset is in the process of being rebuilt.
+ // Used to know not the schedule a rebuild in the middle of a rebuild.
+ protected bool Rebuilding { get; set; }
+
+ // The object is going dynamic (physical). Do any setup necessary
+ // for a dynamic linkset.
+ // Only the state of the passed object can be modified. The rest of the linkset
+ // has not yet been fully constructed.
+ // Return 'true' if any properties updated on the passed object.
+ // Called at taint-time!
+ public abstract bool MakeDynamic(BSPhysObject child);
+
+ // The object is going static (non-physical). Do any setup necessary
+ // for a static linkset.
+ // Return 'true' if any properties updated on the passed object.
+ // Called at taint-time!
+ public abstract bool MakeStatic(BSPhysObject child);
+
+ // Called when a parameter update comes from the physics engine for any object
+ // of the linkset is received.
+ // Passed flag is update came from physics engine (true) or the user (false).
+ // Called at taint-time!!
+ public abstract void UpdateProperties(BSPhysObject physObject, bool physicalUpdate);
+
+ // Routine used when rebuilding the body of the root of the linkset
+ // Destroy all the constraints have have been made to root.
+ // This is called when the root body is changing.
+ // Returns 'true' of something was actually removed and would need restoring
+ // Called at taint-time!!
+ public abstract bool RemoveBodyDependencies(BSPrim child);
+
+ // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true',
+ // this routine will restore the removed constraints.
+ // Called at taint-time!!
+ public abstract void RestoreBodyDependencies(BSPrim child);
+
+ // ================================================================
+ protected virtual float ComputeLinksetMass()
+ {
+ float mass = LinksetRoot.RawMass;
+ if (HasAnyChildren)
+ {
+ lock (m_linksetActivityLock)
+ {
+ foreach (BSPhysObject bp in m_children)
+ {
+ mass += bp.RawMass;
+ }
+ }
+ }
+ return mass;
+ }
+
+ protected virtual OMV.Vector3 ComputeLinksetCenterOfMass()
+ {
+ OMV.Vector3 com;
+ lock (m_linksetActivityLock)
+ {
+ com = LinksetRoot.Position * LinksetRoot.RawMass;
+ float totalMass = LinksetRoot.RawMass;
+
+ foreach (BSPhysObject bp in m_children)
+ {
+ com += bp.Position * bp.RawMass;
+ totalMass += bp.RawMass;
+ }
+ if (totalMass != 0f)
+ com /= totalMass;
+ }
+
+ return com;
+ }
+
+ protected virtual OMV.Vector3 ComputeLinksetGeometricCenter()
+ {
+ OMV.Vector3 com;
+ lock (m_linksetActivityLock)
+ {
+ com = LinksetRoot.Position;
+
+ foreach (BSPhysObject bp in m_children)
+ {
+ com += bp.Position * bp.RawMass;
+ }
+ com /= (m_children.Count + 1);
+ }
+
+ return com;
+ }
+
+ // Invoke the detailed logger and output something if it's enabled.
+ protected void DetailLog(string msg, params Object[] args)
+ {
+ if (PhysicsScene.PhysicsLogging.Enabled)
+ PhysicsScene.DetailLog(msg, args);
+ }
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs
new file mode 100644
index 0000000..23a0b8b
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetCompound.cs
@@ -0,0 +1,396 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Framework;
+
+using OMV = OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+
+// When a child is linked, the relationship position of the child to the parent
+// is remembered so the child's world position can be recomputed when it is
+// removed from the linkset.
+sealed class BSLinksetCompoundInfo : BSLinksetInfo
+{
+ public OMV.Vector3 OffsetPos;
+ public OMV.Quaternion OffsetRot;
+ public BSLinksetCompoundInfo(OMV.Vector3 p, OMV.Quaternion r)
+ {
+ OffsetPos = p;
+ OffsetRot = r;
+ }
+ public override void Clear()
+ {
+ OffsetPos = OMV.Vector3.Zero;
+ OffsetRot = OMV.Quaternion.Identity;
+ }
+ public override string ToString()
+ {
+ StringBuilder buff = new StringBuilder();
+ buff.Append("");
+ return buff.ToString();
+ }
+};
+
+public sealed class BSLinksetCompound : BSLinkset
+{
+ private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]";
+
+ public BSLinksetCompound(BSScene scene, BSPhysObject parent) : base(scene, parent)
+ {
+ }
+
+ // For compound implimented linksets, if there are children, use compound shape for the root.
+ public override BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor)
+ {
+ // Returning 'unknown' means we don't have a preference.
+ BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
+ if (IsRoot(requestor) && HasAnyChildren)
+ {
+ ret = BSPhysicsShapeType.SHAPE_COMPOUND;
+ }
+ // DetailLog("{0},BSLinksetCompound.PreferredPhysicalShape,call,shape={1}", LinksetRoot.LocalID, ret);
+ return ret;
+ }
+
+ // When physical properties are changed the linkset needs to recalculate
+ // its internal properties.
+ public override void Refresh(BSPhysObject requestor)
+ {
+ // Something changed so do the rebuilding thing
+ // ScheduleRebuild();
+ }
+
+ // Schedule a refresh to happen after all the other taint processing.
+ private void ScheduleRebuild(BSPhysObject requestor)
+ {
+ DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,rebuilding={1}",
+ requestor.LocalID, Rebuilding);
+ // When rebuilding, it is possible to set properties that would normally require a rebuild.
+ // If already rebuilding, don't request another rebuild.
+ if (!Rebuilding)
+ {
+ PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", LinksetRoot.LocalID, delegate()
+ {
+ if (HasAnyChildren)
+ RecomputeLinksetCompound();
+ });
+ }
+ }
+
+ // The object is going dynamic (physical). Do any setup necessary
+ // for a dynamic linkset.
+ // Only the state of the passed object can be modified. The rest of the linkset
+ // has not yet been fully constructed.
+ // Return 'true' if any properties updated on the passed object.
+ // Called at taint-time!
+ public override bool MakeDynamic(BSPhysObject child)
+ {
+ bool ret = false;
+ DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
+ if (IsRoot(child))
+ {
+ // The root is going dynamic. Make sure mass is properly set.
+ m_mass = ComputeLinksetMass();
+ ScheduleRebuild(LinksetRoot);
+ }
+ else
+ {
+ // The origional prims are removed from the world as the shape of the root compound
+ // shape takes over.
+ BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION);
+ // We don't want collisions from the old linkset children.
+ BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+
+ child.PhysBody.collisionType = CollisionType.LinksetChild;
+
+ ret = true;
+ }
+ return ret;
+ }
+
+ // The object is going static (non-physical). Do any setup necessary for a static linkset.
+ // Return 'true' if any properties updated on the passed object.
+ // This doesn't normally happen -- OpenSim removes the objects from the physical
+ // world if it is a static linkset.
+ // Called at taint-time!
+ public override bool MakeStatic(BSPhysObject child)
+ {
+ bool ret = false;
+ DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
+ if (IsRoot(child))
+ {
+ ScheduleRebuild(LinksetRoot);
+ }
+ else
+ {
+ // The non-physical children can come back to life.
+ BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+
+ child.PhysBody.collisionType = CollisionType.LinksetChild;
+
+ // Don't force activation so setting of DISABLE_SIMULATION can stay if used.
+ BulletSimAPI.Activate2(child.PhysBody.ptr, false);
+ ret = true;
+ }
+ return ret;
+ }
+
+ public override void UpdateProperties(BSPhysObject updated, bool physicalUpdate)
+ {
+ // The user moving a child around requires the rebuilding of the linkset compound shape
+ // One problem is this happens when a border is crossed -- the simulator implementation
+ // is to store the position into the group which causes the move of the object
+ // but it also means all the child positions get updated.
+ // What would cause an unnecessary rebuild so we make sure the linkset is in a
+ // region before bothering to do a rebuild.
+ if (!IsRoot(updated)
+ && !physicalUpdate
+ && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition))
+ {
+ updated.LinksetInfo = null;
+ ScheduleRebuild(updated);
+ }
+ }
+
+ // Routine called when rebuilding the body of some member of the linkset.
+ // Since we don't keep in world relationships, do nothing unless it's a child changing.
+ // Returns 'true' of something was actually removed and would need restoring
+ // Called at taint-time!!
+ public override bool RemoveBodyDependencies(BSPrim child)
+ {
+ bool ret = false;
+
+ DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}",
+ child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString(), IsRoot(child));
+
+ if (!IsRoot(child))
+ {
+ // Because it is a convenient time, recompute child world position and rotation based on
+ // its position in the linkset.
+ RecomputeChildWorldPosition(child, true);
+ }
+
+ // Cannot schedule a refresh/rebuild here because this routine is called when
+ // the linkset is being rebuilt.
+ // InternalRefresh(LinksetRoot);
+
+ return ret;
+ }
+
+ // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true',
+ // this routine will restore the removed constraints.
+ // Called at taint-time!!
+ public override void RestoreBodyDependencies(BSPrim child)
+ {
+ }
+
+ // When the linkset is built, the child shape is added to the compound shape relative to the
+ // root shape. The linkset then moves around but this does not move the actual child
+ // prim. The child prim's location must be recomputed based on the location of the root shape.
+ private void RecomputeChildWorldPosition(BSPhysObject child, bool inTaintTime)
+ {
+ BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo;
+ if (lci != null)
+ {
+ if (inTaintTime)
+ {
+ OMV.Vector3 oldPos = child.RawPosition;
+ child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetPos;
+ child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot;
+ DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}",
+ child.LocalID, oldPos, lci, child.RawPosition);
+ }
+ else
+ {
+ // TaintedObject is not used here so the raw position is set now and not at taint-time.
+ child.Position = LinksetRoot.RawPosition + lci.OffsetPos;
+ child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot;
+ }
+ }
+ else
+ {
+ // This happens when children have been added to the linkset but the linkset
+ // has not been constructed yet. So like, at taint time, adding children to a linkset
+ // and then changing properties of the children (makePhysical, for instance)
+ // but the post-print action of actually rebuilding the linkset has not yet happened.
+ // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}",
+ // LogHeader, child.LocalID);
+ DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID);
+ }
+ }
+
+ // ================================================================
+
+ // Add a new child to the linkset.
+ // Called while LinkActivity is locked.
+ protected override void AddChildToLinkset(BSPhysObject child)
+ {
+ if (!HasChild(child))
+ {
+ m_children.Add(child);
+
+ DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
+
+ // Rebuild the compound shape with the new child shape included
+ ScheduleRebuild(child);
+ }
+ return;
+ }
+
+ // Remove the specified child from the linkset.
+ // Safe to call even if the child is not really in the linkset.
+ protected override void RemoveChildFromLinkset(BSPhysObject child)
+ {
+ if (m_children.Remove(child))
+ {
+ DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
+ child.LocalID,
+ LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString(),
+ child.LocalID, child.PhysBody.ptr.ToString());
+
+ // Cause the child's body to be rebuilt and thus restored to normal operation
+ RecomputeChildWorldPosition(child, false);
+ child.ForceBodyShapeRebuild(false);
+
+ if (!HasAnyChildren)
+ {
+ // The linkset is now empty. The root needs rebuilding.
+ LinksetRoot.ForceBodyShapeRebuild(false);
+ }
+ else
+ {
+ // Rebuild the compound shape with the child removed
+ ScheduleRebuild(child);
+ }
+ }
+ return;
+ }
+
+ // Called before the simulation step to make sure the compound based linkset
+ // is all initialized.
+ // Constraint linksets are rebuilt every time.
+ // Note that this works for rebuilding just the root after a linkset is taken apart.
+ // Called at taint time!!
+ private void RecomputeLinksetCompound()
+ {
+ try
+ {
+ // Suppress rebuilding while rebuilding
+ Rebuilding = true;
+
+ // Cause the root shape to be rebuilt as a compound object with just the root in it
+ LinksetRoot.ForceBodyShapeRebuild(true);
+
+ DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}",
+ LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren);
+
+ // Add a shape for each of the other children in the linkset
+ ForEachMember(delegate(BSPhysObject cPrim)
+ {
+ if (!IsRoot(cPrim))
+ {
+ // Compute the displacement of the child from the root of the linkset.
+ // This info is saved in the child prim so the relationship does not
+ // change over time and the new child position can be computed
+ // when the linkset is being disassembled (the linkset may have moved).
+ BSLinksetCompoundInfo lci = cPrim.LinksetInfo as BSLinksetCompoundInfo;
+ if (lci == null)
+ {
+ // Each child position and rotation is given relative to the root.
+ OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation);
+ OMV.Vector3 displacementPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation;
+ OMV.Quaternion displacementRot = cPrim.RawOrientation * invRootOrientation;
+
+ // Save relative position for recomputing child's world position after moving linkset.
+ lci = new BSLinksetCompoundInfo(displacementPos, displacementRot);
+ cPrim.LinksetInfo = lci;
+ DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,creatingRelPos,lci={1}", cPrim.LocalID, lci);
+ }
+
+ DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addMemberToShape,mID={1},mShape={2},dispPos={3},dispRot={4}",
+ LinksetRoot.LocalID, cPrim.LocalID, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
+
+ if (cPrim.PhysShape.isNativeShape)
+ {
+ // A native shape is turning into a hull collision shape because native
+ // shapes are not shared so we have to hullify it so it will be tracked
+ // and freed at the correct time. This also solves the scaling problem
+ // (native shapes scaled but hull/meshes are assumed to not be).
+ // TODO: decide of the native shape can just be used in the compound shape.
+ // Use call to CreateGeomNonSpecial().
+ BulletShape saveShape = cPrim.PhysShape;
+ cPrim.PhysShape.Clear(); // Don't let the create free the child's shape
+ // PhysicsScene.Shapes.CreateGeomNonSpecial(true, cPrim, null);
+ PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
+ BulletShape newShape = cPrim.PhysShape;
+ cPrim.PhysShape = saveShape;
+ BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot);
+ }
+ else
+ {
+ // For the shared shapes (meshes and hulls), just use the shape in the child.
+ // The reference count added here will be decremented when the compound shape
+ // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced).
+ if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape))
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
+ LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
+ }
+ BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot);
+ }
+ }
+ return false; // 'false' says to move onto the next child in the list
+ });
+
+ // With all of the linkset packed into the root prim, it has the mass of everyone.
+ float linksetMass = LinksetMass;
+ LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
+ }
+ finally
+ {
+ Rebuilding = false;
+ }
+
+ BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr);
+
+ // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets.
+ // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
+ // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
+
+ }
+}
+}
\ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs
new file mode 100644
index 0000000..5757e64
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSLinksetConstraints.cs
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OMV = OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public sealed class BSLinksetConstraints : BSLinkset
+{
+ // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
+
+ public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent)
+ {
+ }
+
+ // When physical properties are changed the linkset needs to recalculate
+ // its internal properties.
+ // This is queued in the 'post taint' queue so the
+ // refresh will happen once after all the other taints are applied.
+ public override void Refresh(BSPhysObject requestor)
+ {
+ // Queue to happen after all the other taint processing
+ PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
+ {
+ if (HasAnyChildren && IsRoot(requestor))
+ RecomputeLinksetConstraints();
+ });
+ }
+
+ // The object is going dynamic (physical). Do any setup necessary
+ // for a dynamic linkset.
+ // Only the state of the passed object can be modified. The rest of the linkset
+ // has not yet been fully constructed.
+ // Return 'true' if any properties updated on the passed object.
+ // Called at taint-time!
+ public override bool MakeDynamic(BSPhysObject child)
+ {
+ // What is done for each object in BSPrim is what we want.
+ return false;
+ }
+
+ // The object is going static (non-physical). Do any setup necessary for a static linkset.
+ // Return 'true' if any properties updated on the passed object.
+ // This doesn't normally happen -- OpenSim removes the objects from the physical
+ // world if it is a static linkset.
+ // Called at taint-time!
+ public override bool MakeStatic(BSPhysObject child)
+ {
+ // What is done for each object in BSPrim is what we want.
+ return false;
+ }
+
+ // Called at taint-time!!
+ public override void UpdateProperties(BSPhysObject updated, bool inTaintTime)
+ {
+ // Nothing to do for constraints on property updates
+ }
+
+ // Routine called when rebuilding the body of some member of the linkset.
+ // Destroy all the constraints have have been made to root and set
+ // up to rebuild the constraints before the next simulation step.
+ // Returns 'true' of something was actually removed and would need restoring
+ // Called at taint-time!!
+ public override bool RemoveBodyDependencies(BSPrim child)
+ {
+ bool ret = false;
+
+ DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
+ child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString());
+
+ lock (m_linksetActivityLock)
+ {
+ // Just undo all the constraints for this linkset. Rebuild at the end of the step.
+ ret = PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot);
+ // Cause the constraints, et al to be rebuilt before the next simulation step.
+ Refresh(LinksetRoot);
+ }
+ return ret;
+ }
+
+ // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true',
+ // this routine will restore the removed constraints.
+ // Called at taint-time!!
+ public override void RestoreBodyDependencies(BSPrim child)
+ {
+ // The Refresh operation queued by RemoveBodyDependencies() will build any missing constraints.
+ }
+
+ // ================================================================
+
+ // Add a new child to the linkset.
+ // Called while LinkActivity is locked.
+ protected override void AddChildToLinkset(BSPhysObject child)
+ {
+ if (!HasChild(child))
+ {
+ m_children.Add(child);
+
+ DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
+
+ // Cause constraints and assorted properties to be recomputed before the next simulation step.
+ Refresh(LinksetRoot);
+ }
+ return;
+ }
+
+ // Remove the specified child from the linkset.
+ // Safe to call even if the child is not really in my linkset.
+ protected override void RemoveChildFromLinkset(BSPhysObject child)
+ {
+ if (m_children.Remove(child))
+ {
+ BSPhysObject rootx = LinksetRoot; // capture the root and body as of now
+ BSPhysObject childx = child;
+
+ DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
+ childx.LocalID,
+ rootx.LocalID, rootx.PhysBody.ptr.ToString(),
+ childx.LocalID, childx.PhysBody.ptr.ToString());
+
+ PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate()
+ {
+ PhysicallyUnlinkAChildFromRoot(rootx, childx);
+ });
+ // See that the linkset parameters are recomputed at the end of the taint time.
+ Refresh(LinksetRoot);
+ }
+ else
+ {
+ // Non-fatal occurance.
+ // PhysicsScene.Logger.ErrorFormat("{0}: Asked to remove child from linkset that was not in linkset", LogHeader);
+ }
+ return;
+ }
+
+ // Create a constraint between me (root of linkset) and the passed prim (the child).
+ // Called at taint time!
+ private void PhysicallyLinkAChildToRoot(BSPhysObject rootPrim, BSPhysObject childPrim)
+ {
+ // Don't build the constraint when asked. Put it off until just before the simulation step.
+ Refresh(rootPrim);
+ }
+
+ private BSConstraint BuildConstraint(BSPhysObject rootPrim, BSPhysObject childPrim)
+ {
+ // Zero motion for children so they don't interpolate
+ childPrim.ZeroMotion(true);
+
+ // Relative position normalized to the root prim
+ // Essentually a vector pointing from center of rootPrim to center of childPrim
+ OMV.Vector3 childRelativePosition = childPrim.Position - rootPrim.Position;
+
+ // real world coordinate of midpoint between the two objects
+ OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);
+
+ DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
+ rootPrim.LocalID,
+ rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString(),
+ childPrim.LocalID, childPrim.PhysBody.ptr.ToString(),
+ rootPrim.Position, childPrim.Position, midPoint);
+
+ // create a constraint that allows no freedom of movement between the two objects
+ // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
+
+ BSConstraint6Dof constrain = new BSConstraint6Dof(
+ PhysicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true );
+ // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true );
+
+ /* NOTE: below is an attempt to build constraint with full frame computation, etc.
+ * Using the midpoint is easier since it lets the Bullet code manipulate the transforms
+ * of the objects.
+ * Code left for future programmers.
+ // ==================================================================================
+ // relative position normalized to the root prim
+ OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
+ OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation;
+
+ // relative rotation of the child to the parent
+ OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation;
+ OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);
+
+ DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
+ BS6DofConstraint constrain = new BS6DofConstraint(
+ PhysicsScene.World, rootPrim.Body, childPrim.Body,
+ OMV.Vector3.Zero,
+ OMV.Quaternion.Inverse(rootPrim.Orientation),
+ OMV.Vector3.Zero,
+ OMV.Quaternion.Inverse(childPrim.Orientation),
+ true,
+ true
+ );
+ // ==================================================================================
+ */
+
+ PhysicsScene.Constraints.AddConstraint(constrain);
+
+ // zero linear and angular limits makes the objects unable to move in relation to each other
+ constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
+ constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
+
+ // tweek the constraint to increase stability
+ constrain.UseFrameOffset(BSParam.BoolNumeric(BSParam.LinkConstraintUseFrameOffset));
+ constrain.TranslationalLimitMotor(BSParam.BoolNumeric(BSParam.LinkConstraintEnableTransMotor),
+ BSParam.LinkConstraintTransMotorMaxVel,
+ BSParam.LinkConstraintTransMotorMaxForce);
+ constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP);
+ if (BSParam.LinkConstraintSolverIterations != 0f)
+ {
+ constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations);
+ }
+ return constrain;
+ }
+
+ // Remove linkage between the linkset root and a particular child
+ // The root and child bodies are passed in because we need to remove the constraint between
+ // the bodies that were present at unlink time.
+ // Called at taint time!
+ private bool PhysicallyUnlinkAChildFromRoot(BSPhysObject rootPrim, BSPhysObject childPrim)
+ {
+ bool ret = false;
+ DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
+ rootPrim.LocalID,
+ rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString(),
+ childPrim.LocalID, childPrim.PhysBody.ptr.ToString());
+
+ // Find the constraint for this link and get rid of it from the overall collection and from my list
+ if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
+ {
+ // Make the child refresh its location
+ BulletSimAPI.PushUpdate2(childPrim.PhysBody.ptr);
+ ret = true;
+ }
+
+ return ret;
+ }
+
+ // Remove linkage between myself and any possible children I might have.
+ // Returns 'true' of any constraints were destroyed.
+ // Called at taint time!
+ private bool PhysicallyUnlinkAllChildrenFromRoot(BSPhysObject rootPrim)
+ {
+ DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID);
+
+ return PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody);
+ }
+
+ // Call each of the constraints that make up this linkset and recompute the
+ // various transforms and variables. Create constraints of not created yet.
+ // Called before the simulation step to make sure the constraint based linkset
+ // is all initialized.
+ // Called at taint time!!
+ private void RecomputeLinksetConstraints()
+ {
+ float linksetMass = LinksetMass;
+ LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
+
+ // DEBUG: see of inter-linkset collisions are causing problems
+ // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
+ // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
+ DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
+ LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString(), linksetMass);
+
+ foreach (BSPhysObject child in m_children)
+ {
+ // A child in the linkset physically shows the mass of the whole linkset.
+ // This allows Bullet to apply enough force on the child to move the whole linkset.
+ // (Also do the mass stuff before recomputing the constraint so mass is not zero.)
+ child.UpdatePhysicalMassProperties(linksetMass);
+
+ BSConstraint constrain;
+ if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain))
+ {
+ // If constraint doesn't exist yet, create it.
+ constrain = BuildConstraint(LinksetRoot, child);
+ }
+ constrain.RecomputeConstraintVariables(linksetMass);
+
+ // DEBUG: see of inter-linkset collisions are causing problems
+ // BulletSimAPI.SetCollisionFilterMask2(child.BSBody.ptr,
+ // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
+
+ // BulletSimAPI.DumpConstraint2(PhysicsScene.World.ptr, constrain.Constraint.ptr); // DEBUG DEBUG
+ }
+
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs
new file mode 100644
index 0000000..732191f
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSMaterials.cs
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Reflection;
+using Nini.Config;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+
+public struct MaterialAttributes
+{
+ // Material type values that correspond with definitions for LSL
+ public enum Material : int
+ {
+ Stone = 0,
+ Metal,
+ Glass,
+ Wood,
+ Flesh,
+ Plastic,
+ Rubber,
+ Light,
+ // Hereafter are BulletSim additions
+ Avatar,
+ NumberOfTypes // the count of types in the enum.
+ }
+
+ // Names must be in the order of the above enum.
+ // These names must coorespond to the lower case field names in the MaterialAttributes
+ // structure as reflection is used to select the field to put the value in.
+ public static readonly string[] MaterialAttribs = { "Density", "Friction", "Restitution"};
+
+ public MaterialAttributes(string t, float d, float f, float r)
+ {
+ type = t;
+ density = d;
+ friction = f;
+ restitution = r;
+ }
+ public string type;
+ public float density;
+ public float friction;
+ public float restitution;
+}
+
+public static class BSMaterials
+{
+ // Attributes for each material type
+ private static readonly MaterialAttributes[] Attributes;
+
+ // Map of material name to material type code
+ public static readonly Dictionary MaterialMap;
+
+ static BSMaterials()
+ {
+ // Attribute sets for both the non-physical and physical instances of materials.
+ Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2];
+
+ // Map of name to type code.
+ MaterialMap = new Dictionary();
+ MaterialMap.Add("Stone", MaterialAttributes.Material.Stone);
+ MaterialMap.Add("Metal", MaterialAttributes.Material.Metal);
+ MaterialMap.Add("Glass", MaterialAttributes.Material.Glass);
+ MaterialMap.Add("Wood", MaterialAttributes.Material.Wood);
+ MaterialMap.Add("Flesh", MaterialAttributes.Material.Flesh);
+ MaterialMap.Add("Plastic", MaterialAttributes.Material.Plastic);
+ MaterialMap.Add("Rubber", MaterialAttributes.Material.Rubber);
+ MaterialMap.Add("Light", MaterialAttributes.Material.Light);
+ MaterialMap.Add("Avatar", MaterialAttributes.Material.Avatar);
+ }
+
+ // This is where all the default material attributes are defined.
+ public static void InitializeFromDefaults(ConfigurationParameters parms)
+ {
+ // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL
+ float dDensity = parms.defaultDensity;
+ float dFriction = parms.defaultFriction;
+ float dRestitution = parms.defaultRestitution;
+ Attributes[(int)MaterialAttributes.Material.Stone] =
+ new MaterialAttributes("stone",dDensity, 0.8f, 0.4f);
+ Attributes[(int)MaterialAttributes.Material.Metal] =
+ new MaterialAttributes("metal",dDensity, 0.3f, 0.4f);
+ Attributes[(int)MaterialAttributes.Material.Glass] =
+ new MaterialAttributes("glass",dDensity, 0.2f, 0.7f);
+ Attributes[(int)MaterialAttributes.Material.Wood] =
+ new MaterialAttributes("wood",dDensity, 0.6f, 0.5f);
+ Attributes[(int)MaterialAttributes.Material.Flesh] =
+ new MaterialAttributes("flesh",dDensity, 0.9f, 0.3f);
+ Attributes[(int)MaterialAttributes.Material.Plastic] =
+ new MaterialAttributes("plastic",dDensity, 0.4f, 0.7f);
+ Attributes[(int)MaterialAttributes.Material.Rubber] =
+ new MaterialAttributes("rubber",dDensity, 0.9f, 0.9f);
+ Attributes[(int)MaterialAttributes.Material.Light] =
+ new MaterialAttributes("light",dDensity, dFriction, dRestitution);
+ Attributes[(int)MaterialAttributes.Material.Avatar] =
+ new MaterialAttributes("avatar",60f, 0.2f, 0f);
+
+ Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f);
+ Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f);
+ Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f);
+ Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f);
+ Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f);
+ Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f);
+ Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f);
+ Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution);
+ Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] =
+ new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f);
+ }
+
+ // Under the [BulletSim] section, one can change the individual material
+ // attribute values. The format of the configuration parameter is:
+ // ["Physical"] = floatValue
+ // For instance:
+ // [BulletSim]
+ // StoneFriction = 0.2
+ // FleshRestitutionPhysical = 0.8
+ // Materials can have different parameters for their static and
+ // physical instantiations. When setting the non-physical value,
+ // both values are changed. Setting the physical value only changes
+ // the physical value.
+ public static void InitializefromParameters(IConfig pConfig)
+ {
+ foreach (KeyValuePair kvp in MaterialMap)
+ {
+ string matName = kvp.Key;
+ foreach (string attribName in MaterialAttributes.MaterialAttribs)
+ {
+ string paramName = matName + attribName;
+ if (pConfig.Contains(paramName))
+ {
+ float paramValue = pConfig.GetFloat(paramName);
+ SetAttributeValue((int)kvp.Value, attribName, paramValue);
+ // set the physical value also
+ SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
+ }
+ paramName += "Physical";
+ if (pConfig.Contains(paramName))
+ {
+ float paramValue = pConfig.GetFloat(paramName);
+ SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue);
+ }
+ }
+ }
+ }
+
+ // Use reflection to set the value in the attribute structure.
+ private static void SetAttributeValue(int matType, string attribName, float val)
+ {
+ MaterialAttributes thisAttrib = Attributes[matType];
+ FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower());
+ if (fieldInfo != null)
+ {
+ fieldInfo.SetValue(thisAttrib, val);
+ Attributes[matType] = thisAttrib;
+ }
+ }
+
+ // Given a material type, return a structure of attributes.
+ public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical)
+ {
+ int ind = (int)type;
+ if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes;
+ return Attributes[ind];
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSMotors.cs
new file mode 100644
index 0000000..7abc9b2
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSMotors.cs
@@ -0,0 +1,347 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenMetaverse;
+using OpenSim.Framework;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public abstract class BSMotor
+{
+ // Timescales and other things can be turned off by setting them to 'infinite'.
+ public const float Infinite = 12345.6f;
+ public readonly static Vector3 InfiniteVector = new Vector3(BSMotor.Infinite, BSMotor.Infinite, BSMotor.Infinite);
+
+ public BSMotor(string useName)
+ {
+ UseName = useName;
+ PhysicsScene = null;
+ Enabled = true;
+ }
+ public virtual bool Enabled { get; set; }
+ public virtual void Reset() { }
+ public virtual void Zero() { }
+ public virtual void GenerateTestOutput(float timeStep) { }
+
+ // A name passed at motor creation for easily identifyable debugging messages.
+ public string UseName { get; private set; }
+
+ // Used only for outputting debug information. Might not be set so check for null.
+ public BSScene PhysicsScene { get; set; }
+ protected void MDetailLog(string msg, params Object[] parms)
+ {
+ if (PhysicsScene != null)
+ {
+ if (PhysicsScene.VehicleLoggingEnabled)
+ {
+ PhysicsScene.DetailLog(msg, parms);
+ }
+ }
+ }
+}
+
+// Motor which moves CurrentValue to TargetValue over TimeScale seconds.
+// The TargetValue decays in TargetValueDecayTimeScale and
+// the CurrentValue will be held back by FrictionTimeScale.
+// This motor will "zero itself" over time in that the targetValue will
+// decay to zero and the currentValue will follow it to that zero.
+// The overall effect is for the returned correction value to go from large
+// values (the total difference between current and target minus friction)
+// to small and eventually zero values.
+// TimeScale and TargetDelayTimeScale may be 'infinite' which means no decay.
+
+// For instance, if something is moving at speed X and the desired speed is Y,
+// CurrentValue is X and TargetValue is Y. As the motor is stepped, new
+// values of CurrentValue are returned that approach the TargetValue.
+// The feature of decaying TargetValue is so vehicles will eventually
+// come to a stop rather than run forever. This can be disabled by
+// setting TargetValueDecayTimescale to 'infinite'.
+// The change from CurrentValue to TargetValue is linear over TimeScale seconds.
+public class BSVMotor : BSMotor
+{
+ // public Vector3 FrameOfReference { get; set; }
+ // public Vector3 Offset { get; set; }
+
+ public virtual float TimeScale { get; set; }
+ public virtual float TargetValueDecayTimeScale { get; set; }
+ public virtual Vector3 FrictionTimescale { get; set; }
+ public virtual float Efficiency { get; set; }
+
+ public virtual float ErrorZeroThreshold { get; set; }
+
+ public virtual Vector3 TargetValue { get; protected set; }
+ public virtual Vector3 CurrentValue { get; protected set; }
+ public virtual Vector3 LastError { get; protected set; }
+
+ public virtual bool ErrorIsZero
+ { get {
+ return (LastError == Vector3.Zero || LastError.LengthSquared() <= ErrorZeroThreshold);
+ }
+ }
+
+ public BSVMotor(string useName)
+ : base(useName)
+ {
+ TimeScale = TargetValueDecayTimeScale = BSMotor.Infinite;
+ Efficiency = 1f;
+ FrictionTimescale = BSMotor.InfiniteVector;
+ CurrentValue = TargetValue = Vector3.Zero;
+ ErrorZeroThreshold = 0.001f;
+ }
+ public BSVMotor(string useName, float timeScale, float decayTimeScale, Vector3 frictionTimeScale, float efficiency)
+ : this(useName)
+ {
+ TimeScale = timeScale;
+ TargetValueDecayTimeScale = decayTimeScale;
+ FrictionTimescale = frictionTimeScale;
+ Efficiency = efficiency;
+ CurrentValue = TargetValue = Vector3.Zero;
+ }
+ public void SetCurrent(Vector3 current)
+ {
+ CurrentValue = current;
+ }
+ public void SetTarget(Vector3 target)
+ {
+ TargetValue = target;
+ }
+ public override void Zero()
+ {
+ base.Zero();
+ CurrentValue = TargetValue = Vector3.Zero;
+ }
+
+ // Compute the next step and return the new current value
+ public virtual Vector3 Step(float timeStep)
+ {
+ if (!Enabled) return TargetValue;
+
+ Vector3 origTarget = TargetValue; // DEBUG
+ Vector3 origCurrVal = CurrentValue; // DEBUG
+
+ Vector3 correction = Vector3.Zero;
+ Vector3 error = TargetValue - CurrentValue;
+ if (!error.ApproxEquals(Vector3.Zero, ErrorZeroThreshold))
+ {
+ correction = Step(timeStep, error);
+
+ CurrentValue += correction;
+
+ // The desired value reduces to zero which also reduces the difference with current.
+ // If the decay time is infinite, don't decay at all.
+ float decayFactor = 0f;
+ if (TargetValueDecayTimeScale != BSMotor.Infinite)
+ {
+ decayFactor = (1.0f / TargetValueDecayTimeScale) * timeStep;
+ TargetValue *= (1f - decayFactor);
+ }
+
+ // The amount we can correct the error is reduced by the friction
+ Vector3 frictionFactor = Vector3.Zero;
+ if (FrictionTimescale != BSMotor.InfiniteVector)
+ {
+ // frictionFactor = (Vector3.One / FrictionTimescale) * timeStep;
+ // Individual friction components can be 'infinite' so compute each separately.
+ frictionFactor.X = (FrictionTimescale.X == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.X);
+ frictionFactor.Y = (FrictionTimescale.Y == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Y);
+ frictionFactor.Z = (FrictionTimescale.Z == BSMotor.Infinite) ? 0f : (1f / FrictionTimescale.Z);
+ frictionFactor *= timeStep;
+ CurrentValue *= (Vector3.One - frictionFactor);
+ }
+
+ MDetailLog("{0}, BSVMotor.Step,nonZero,{1},origCurr={2},origTarget={3},timeStep={4},err={5},corr={6}",
+ BSScene.DetailLogZero, UseName, origCurrVal, origTarget,
+ timeStep, error, correction);
+ MDetailLog("{0}, BSVMotor.Step,nonZero,{1},tgtDecayTS={2},decayFact={3},frictTS={4},frictFact={5},tgt={6},curr={7}",
+ BSScene.DetailLogZero, UseName,
+ TargetValueDecayTimeScale, decayFactor, FrictionTimescale, frictionFactor,
+ TargetValue, CurrentValue);
+ }
+ else
+ {
+ // Difference between what we have and target is small. Motor is done.
+ CurrentValue = TargetValue;
+ MDetailLog("{0}, BSVMotor.Step,zero,{1},origTgt={2},origCurr={3},ret={4}",
+ BSScene.DetailLogZero, UseName, origCurrVal, origTarget, CurrentValue);
+ }
+
+ return CurrentValue;
+ }
+ public virtual Vector3 Step(float timeStep, Vector3 error)
+ {
+ if (!Enabled) return Vector3.Zero;
+
+ LastError = error;
+ Vector3 returnCorrection = Vector3.Zero;
+ if (!error.ApproxEquals(Vector3.Zero, ErrorZeroThreshold))
+ {
+ // correction = error / secondsItShouldTakeToCorrect
+ Vector3 correctionAmount;
+ if (TimeScale == 0f || TimeScale == BSMotor.Infinite)
+ correctionAmount = error * timeStep;
+ else
+ correctionAmount = error / TimeScale * timeStep;
+
+ returnCorrection = correctionAmount;
+ MDetailLog("{0}, BSVMotor.Step,nonZero,{1},timeStep={2},timeScale={3},err={4},corr={5}",
+ BSScene.DetailLogZero, UseName, timeStep, TimeScale, error, correctionAmount);
+ }
+ return returnCorrection;
+ }
+
+ // The user sets all the parameters and calls this which outputs values until error is zero.
+ public override void GenerateTestOutput(float timeStep)
+ {
+ // maximum number of outputs to generate.
+ int maxOutput = 50;
+ MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName);
+ MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},frictTS={4},eff={5},curr={6},tgt={7}",
+ BSScene.DetailLogZero, UseName,
+ TimeScale, TargetValueDecayTimeScale, FrictionTimescale, Efficiency,
+ CurrentValue, TargetValue);
+
+ LastError = BSMotor.InfiniteVector;
+ while (maxOutput-- > 0 && !LastError.ApproxEquals(Vector3.Zero, ErrorZeroThreshold))
+ {
+ Vector3 lastStep = Step(timeStep);
+ MDetailLog("{0},BSVMotor.Test,{1},cur={2},tgt={3},lastError={4},lastStep={5}",
+ BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, LastError, lastStep);
+ }
+ MDetailLog("{0},BSVMotor.Test,{1},===================================== END Test Output", BSScene.DetailLogZero, UseName);
+
+
+ }
+
+ public override string ToString()
+ {
+ return String.Format("<{0},curr={1},targ={2},decayTS={3},frictTS={4}>",
+ UseName, CurrentValue, TargetValue, TargetValueDecayTimeScale, FrictionTimescale);
+ }
+}
+
+public class BSFMotor : BSMotor
+{
+ public float TimeScale { get; set; }
+ public float DecayTimeScale { get; set; }
+ public float Friction { get; set; }
+ public float Efficiency { get; set; }
+
+ public float Target { get; private set; }
+ public float CurrentValue { get; private set; }
+
+ public BSFMotor(string useName, float timeScale, float decayTimescale, float friction, float efficiency)
+ : base(useName)
+ {
+ }
+ public void SetCurrent(float target)
+ {
+ }
+ public void SetTarget(float target)
+ {
+ }
+ public virtual float Step(float timeStep)
+ {
+ return 0f;
+ }
+}
+
+// Proportional, Integral, Derivitive Motor
+// Good description at http://www.answers.com/topic/pid-controller . Includes processes for choosing p, i and d factors.
+public class BSPIDVMotor : BSVMotor
+{
+ // Larger makes more overshoot, smaller means converge quicker. Range of 0.1 to 10.
+ public Vector3 proportionFactor { get; set; }
+ public Vector3 integralFactor { get; set; }
+ public Vector3 derivFactor { get; set; }
+
+ // Arbritrary factor range.
+ // EfficiencyHigh means move quickly to the correct number. EfficiencyLow means might over correct.
+ public float EfficiencyHigh = 0.4f;
+ public float EfficiencyLow = 4.0f;
+
+ // Running integration of the error
+ Vector3 RunningIntegration { get; set; }
+
+ public BSPIDVMotor(string useName)
+ : base(useName)
+ {
+ proportionFactor = new Vector3(1.00f, 1.00f, 1.00f);
+ integralFactor = new Vector3(1.00f, 1.00f, 1.00f);
+ derivFactor = new Vector3(1.00f, 1.00f, 1.00f);
+ RunningIntegration = Vector3.Zero;
+ LastError = Vector3.Zero;
+ }
+
+ public override void Zero()
+ {
+ base.Zero();
+ }
+
+ public override float Efficiency
+ {
+ get { return base.Efficiency; }
+ set
+ {
+ base.Efficiency = Util.Clamp(value, 0f, 1f);
+ // Compute factors based on efficiency.
+ // If efficiency is high (1f), use a factor value that moves the error value to zero with little overshoot.
+ // If efficiency is low (0f), use a factor value that overcorrects.
+ // TODO: might want to vary contribution of different factor depending on efficiency.
+ float factor = ((1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow) / 3f;
+ // float factor = (1f - this.Efficiency) * EfficiencyHigh + EfficiencyLow;
+ proportionFactor = new Vector3(factor, factor, factor);
+ integralFactor = new Vector3(factor, factor, factor);
+ derivFactor = new Vector3(factor, factor, factor);
+ }
+ }
+
+ // Ignore Current and Target Values and just advance the PID computation on this error.
+ public override Vector3 Step(float timeStep, Vector3 error)
+ {
+ if (!Enabled) return Vector3.Zero;
+
+ // Add up the error so we can integrate over the accumulated errors
+ RunningIntegration += error * timeStep;
+
+ // A simple derivitive is the rate of change from the last error.
+ Vector3 derivFactor = (error - LastError) * timeStep;
+ LastError = error;
+
+ // Correction = -(proportionOfPresentError + accumulationOfPastError + rateOfChangeOfError)
+ Vector3 ret = -(
+ error * proportionFactor
+ + RunningIntegration * integralFactor
+ + derivFactor * derivFactor
+ );
+
+ return ret;
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs
new file mode 100644
index 0000000..0bb1674
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs
@@ -0,0 +1,559 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Region.Physics.Manager;
+
+using OpenMetaverse;
+using Nini.Config;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public static class BSParam
+{
+ // Level of Detail values kept as float because that's what the Meshmerizer wants
+ public static float MeshLOD { get; private set; }
+ public static float MeshMegaPrimLOD { get; private set; }
+ public static float MeshMegaPrimThreshold { get; private set; }
+ public static float SculptLOD { get; private set; }
+
+ public static float MinimumObjectMass { get; private set; }
+ public static float MaximumObjectMass { get; private set; }
+
+ public static float LinearDamping { get; private set; }
+ public static float AngularDamping { get; private set; }
+ public static float DeactivationTime { get; private set; }
+ public static float LinearSleepingThreshold { get; private set; }
+ public static float AngularSleepingThreshold { get; private set; }
+ public static float CcdMotionThreshold { get; private set; }
+ public static float CcdSweptSphereRadius { get; private set; }
+ public static float ContactProcessingThreshold { get; private set; }
+
+ public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed
+ public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes
+ public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects
+
+ public static float TerrainImplementation { get; private set; }
+ public static float TerrainFriction { get; private set; }
+ public static float TerrainHitFraction { get; private set; }
+ public static float TerrainRestitution { get; private set; }
+ public static float TerrainCollisionMargin { get; private set; }
+
+ // Avatar parameters
+ public static float AvatarFriction { get; private set; }
+ public static float AvatarStandingFriction { get; private set; }
+ public static float AvatarDensity { get; private set; }
+ public static float AvatarRestitution { get; private set; }
+ public static float AvatarCapsuleWidth { get; private set; }
+ public static float AvatarCapsuleDepth { get; private set; }
+ public static float AvatarCapsuleHeight { get; private set; }
+ public static float AvatarContactProcessingThreshold { get; private set; }
+
+ public static float VehicleAngularDamping { get; private set; }
+
+ public static float LinksetImplementation { get; private set; }
+ public static float LinkConstraintUseFrameOffset { get; private set; }
+ public static float LinkConstraintEnableTransMotor { get; private set; }
+ public static float LinkConstraintTransMotorMaxVel { get; private set; }
+ public static float LinkConstraintTransMotorMaxForce { get; private set; }
+ public static float LinkConstraintERP { get; private set; }
+ public static float LinkConstraintCFM { get; private set; }
+ public static float LinkConstraintSolverIterations { get; private set; }
+
+ public static float PID_D { get; private set; } // derivative
+ public static float PID_P { get; private set; } // proportional
+
+ public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val);
+ public delegate float ParamGet(BSScene scene);
+ public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val);
+ public delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val);
+
+ public struct ParameterDefn
+ {
+ public string name; // string name of the parameter
+ public string desc; // a short description of what the parameter means
+ public float defaultValue; // default value if not specified anywhere else
+ public ParamUser userParam; // get the value from the configuration file
+ public ParamGet getter; // return the current value stored for this parameter
+ public ParamSet setter; // set the current value for this parameter
+ public SetOnObject onObject; // set the value on an object in the physical domain
+ public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s)
+ {
+ name = n;
+ desc = d;
+ defaultValue = v;
+ userParam = u;
+ getter = g;
+ setter = s;
+ onObject = null;
+ }
+ public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o)
+ {
+ name = n;
+ desc = d;
+ defaultValue = v;
+ userParam = u;
+ getter = g;
+ setter = s;
+ onObject = o;
+ }
+ }
+
+ // List of all of the externally visible parameters.
+ // For each parameter, this table maps a text name to getter and setters.
+ // To add a new externally referencable/settable parameter, add the paramter storage
+ // location somewhere in the program and make an entry in this table with the
+ // getters and setters.
+ // It is easiest to find an existing definition and copy it.
+ // Parameter values are floats. Booleans are converted to a floating value.
+ //
+ // A ParameterDefn() takes the following parameters:
+ // -- the text name of the parameter. This is used for console input and ini file.
+ // -- a short text description of the parameter. This shows up in the console listing.
+ // -- a default value (float)
+ // -- a delegate for fetching the parameter from the ini file.
+ // Should handle fetching the right type from the ini file and converting it.
+ // -- a delegate for getting the value as a float
+ // -- a delegate for setting the value from a float
+ // -- an optional delegate to update the value in the world. Most often used to
+ // push the new value to an in-world object.
+ //
+ // The single letter parameters for the delegates are:
+ // s = BSScene
+ // o = BSPhysObject
+ // p = string parameter name
+ // l = localID of referenced object
+ // v = value (float)
+ // cf = parameter configuration class (for fetching values from ini file)
+ private static ParameterDefn[] ParameterDefinitions =
+ {
+ new ParameterDefn("MeshSculptedPrim", "Whether to create meshes for sculpties",
+ ConfigurationParameters.numericTrue,
+ (s,cf,p,v) => { ShouldMeshSculptedPrim = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
+ (s) => { return BSParam.NumericBool(ShouldMeshSculptedPrim); },
+ (s,p,l,v) => { ShouldMeshSculptedPrim = BSParam.BoolNumeric(v); } ),
+ new ParameterDefn("ForceSimplePrimMeshing", "If true, only use primitive meshes for objects",
+ ConfigurationParameters.numericFalse,
+ (s,cf,p,v) => { ShouldForceSimplePrimMeshing = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
+ (s) => { return BSParam.NumericBool(ShouldForceSimplePrimMeshing); },
+ (s,p,l,v) => { ShouldForceSimplePrimMeshing = BSParam.BoolNumeric(v); } ),
+ new ParameterDefn("UseHullsForPhysicalObjects", "If true, create hulls for physical objects",
+ ConfigurationParameters.numericTrue,
+ (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); },
+ (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); },
+ (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ),
+
+ new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)",
+ 8f,
+ (s,cf,p,v) => { MeshLOD = (float)cf.GetInt(p, (int)v); },
+ (s) => { return MeshLOD; },
+ (s,p,l,v) => { MeshLOD = v; } ),
+ new ParameterDefn("MeshLevelOfDetailMegaPrim", "Level of detail to render meshes larger than threshold meters",
+ 16f,
+ (s,cf,p,v) => { MeshMegaPrimLOD = (float)cf.GetInt(p, (int)v); },
+ (s) => { return MeshMegaPrimLOD; },
+ (s,p,l,v) => { MeshMegaPrimLOD = v; } ),
+ new ParameterDefn("MeshLevelOfDetailMegaPrimThreshold", "Size (in meters) of a mesh before using MeshMegaPrimLOD",
+ 10f,
+ (s,cf,p,v) => { MeshMegaPrimThreshold = (float)cf.GetInt(p, (int)v); },
+ (s) => { return MeshMegaPrimThreshold; },
+ (s,p,l,v) => { MeshMegaPrimThreshold = v; } ),
+ new ParameterDefn("SculptLevelOfDetail", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)",
+ 32f,
+ (s,cf,p,v) => { SculptLOD = (float)cf.GetInt(p, (int)v); },
+ (s) => { return SculptLOD; },
+ (s,p,l,v) => { SculptLOD = v; } ),
+
+ new ParameterDefn("MaxSubStep", "In simulation step, maximum number of substeps",
+ 10f,
+ (s,cf,p,v) => { s.m_maxSubSteps = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.m_maxSubSteps; },
+ (s,p,l,v) => { s.m_maxSubSteps = (int)v; } ),
+ new ParameterDefn("FixedTimeStep", "In simulation step, seconds of one substep (1/60)",
+ 1f / 60f,
+ (s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); },
+ (s) => { return (float)s.m_fixedTimeStep; },
+ (s,p,l,v) => { s.m_fixedTimeStep = v; } ),
+ new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame",
+ 2048f,
+ (s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.m_maxCollisionsPerFrame; },
+ (s,p,l,v) => { s.m_maxCollisionsPerFrame = (int)v; } ),
+ new ParameterDefn("MaxUpdatesPerFrame", "Max updates returned at end of each frame",
+ 8000f,
+ (s,cf,p,v) => { s.m_maxUpdatesPerFrame = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.m_maxUpdatesPerFrame; },
+ (s,p,l,v) => { s.m_maxUpdatesPerFrame = (int)v; } ),
+ new ParameterDefn("MaxTaintsToProcessPerStep", "Number of update taints to process before each simulation step",
+ 500f,
+ (s,cf,p,v) => { s.m_taintsToProcessPerStep = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.m_taintsToProcessPerStep; },
+ (s,p,l,v) => { s.m_taintsToProcessPerStep = (int)v; } ),
+ new ParameterDefn("MinObjectMass", "Minimum object mass (0.0001)",
+ 0.0001f,
+ (s,cf,p,v) => { MinimumObjectMass = cf.GetFloat(p, v); },
+ (s) => { return (float)MinimumObjectMass; },
+ (s,p,l,v) => { MinimumObjectMass = v; } ),
+ new ParameterDefn("MaxObjectMass", "Maximum object mass (10000.01)",
+ 10000.01f,
+ (s,cf,p,v) => { MaximumObjectMass = cf.GetFloat(p, v); },
+ (s) => { return (float)MaximumObjectMass; },
+ (s,p,l,v) => { MaximumObjectMass = v; } ),
+
+ new ParameterDefn("PID_D", "Derivitive factor for motion smoothing",
+ 2200f,
+ (s,cf,p,v) => { PID_D = cf.GetFloat(p, v); },
+ (s) => { return (float)PID_D; },
+ (s,p,l,v) => { PID_D = v; } ),
+ new ParameterDefn("PID_P", "Parameteric factor for motion smoothing",
+ 900f,
+ (s,cf,p,v) => { PID_P = cf.GetFloat(p, v); },
+ (s) => { return (float)PID_P; },
+ (s,p,l,v) => { PID_P = v; } ),
+
+ new ParameterDefn("DefaultFriction", "Friction factor used on new objects",
+ 0.2f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].defaultFriction = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].defaultFriction; },
+ (s,p,l,v) => { s.UnmanagedParams[0].defaultFriction = v; } ),
+ new ParameterDefn("DefaultDensity", "Density for new objects" ,
+ 10.000006836f, // Aluminum g/cm3
+ (s,cf,p,v) => { s.UnmanagedParams[0].defaultDensity = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].defaultDensity; },
+ (s,p,l,v) => { s.UnmanagedParams[0].defaultDensity = v; } ),
+ new ParameterDefn("DefaultRestitution", "Bouncyness of an object" ,
+ 0f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].defaultRestitution = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].defaultRestitution; },
+ (s,p,l,v) => { s.UnmanagedParams[0].defaultRestitution = v; } ),
+ new ParameterDefn("CollisionMargin", "Margin around objects before collisions are calculated (must be zero!)",
+ 0.04f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].collisionMargin = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].collisionMargin; },
+ (s,p,l,v) => { s.UnmanagedParams[0].collisionMargin = v; } ),
+ new ParameterDefn("Gravity", "Vertical force of gravity (negative means down)",
+ -9.80665f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].gravity; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); },
+ (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ),
+
+
+ new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
+ 0f,
+ (s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); },
+ (s) => { return LinearDamping; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, v, AngularDamping); } ),
+ new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
+ 0f,
+ (s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); },
+ (s) => { return AngularDamping; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, LinearDamping, v); } ),
+ new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
+ 0.2f,
+ (s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
+ (s) => { return DeactivationTime; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.PhysBody.ptr, v); } ),
+ new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
+ 0.8f,
+ (s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
+ (s) => { return LinearSleepingThreshold; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ),
+ new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
+ 1.0f,
+ (s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); },
+ (s) => { return AngularSleepingThreshold; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ),
+ new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
+ 0f, // set to zero to disable
+ (s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
+ (s) => { return CcdMotionThreshold; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.PhysBody.ptr, v); } ),
+ new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
+ 0f,
+ (s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); },
+ (s) => { return CcdSweptSphereRadius; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetCcdSweptSphereRadius2(o.PhysBody.ptr, v); } ),
+ new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
+ 0.1f,
+ (s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); },
+ (s) => { return ContactProcessingThreshold; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); },
+ (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ),
+
+ new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
+ (float)BSTerrainPhys.TerrainImplementation.Mesh,
+ (s,cf,p,v) => { TerrainImplementation = cf.GetFloat(p,v); },
+ (s) => { return TerrainImplementation; },
+ (s,p,l,v) => { TerrainImplementation = v; } ),
+ new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" ,
+ 0.3f,
+ (s,cf,p,v) => { TerrainFriction = cf.GetFloat(p, v); },
+ (s) => { return TerrainFriction; },
+ (s,p,l,v) => { TerrainFriction = v; /* TODO: set on real terrain */} ),
+ new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" ,
+ 0.8f,
+ (s,cf,p,v) => { TerrainHitFraction = cf.GetFloat(p, v); },
+ (s) => { return TerrainHitFraction; },
+ (s,p,l,v) => { TerrainHitFraction = v; /* TODO: set on real terrain */ } ),
+ new ParameterDefn("TerrainRestitution", "Bouncyness" ,
+ 0f,
+ (s,cf,p,v) => { TerrainRestitution = cf.GetFloat(p, v); },
+ (s) => { return TerrainRestitution; },
+ (s,p,l,v) => { TerrainRestitution = v; /* TODO: set on real terrain */ } ),
+ new ParameterDefn("TerrainCollisionMargin", "Margin where collision checking starts" ,
+ 0.04f,
+ (s,cf,p,v) => { TerrainCollisionMargin = cf.GetFloat(p, v); },
+ (s) => { return TerrainCollisionMargin; },
+ (s,p,l,v) => { TerrainCollisionMargin = v; /* TODO: set on real terrain */ } ),
+
+ new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.",
+ 0.2f,
+ (s,cf,p,v) => { AvatarFriction = cf.GetFloat(p, v); },
+ (s) => { return AvatarFriction; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarFriction=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarStandingFriction", "Avatar friction when standing. Changed on avatar recreation.",
+ 10.0f,
+ (s,cf,p,v) => { AvatarStandingFriction = cf.GetFloat(p, v); },
+ (s) => { return AvatarStandingFriction; },
+ (s,p,l,v) => { AvatarStandingFriction = v; } ),
+ new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.",
+ 60f,
+ (s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); },
+ (s) => { return AvatarDensity; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.",
+ 0f,
+ (s,cf,p,v) => { AvatarRestitution = cf.GetFloat(p, v); },
+ (s) => { return AvatarRestitution; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarRestitution=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule",
+ 0.6f,
+ (s,cf,p,v) => { AvatarCapsuleWidth = cf.GetFloat(p, v); },
+ (s) => { return AvatarCapsuleWidth; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleWidth=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule",
+ 0.45f,
+ (s,cf,p,v) => { AvatarCapsuleDepth = cf.GetFloat(p, v); },
+ (s) => { return AvatarCapsuleDepth; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleDepth=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar",
+ 1.5f,
+ (s,cf,p,v) => { AvatarCapsuleHeight = cf.GetFloat(p, v); },
+ (s) => { return AvatarCapsuleHeight; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarCapsuleHeight=x;}, p, l, v); } ),
+ new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions",
+ 0.1f,
+ (s,cf,p,v) => { AvatarContactProcessingThreshold = cf.GetFloat(p, v); },
+ (s) => { return AvatarContactProcessingThreshold; },
+ (s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarContactProcessingThreshold=x;}, p, l, v); } ),
+
+ new ParameterDefn("VehicleAngularDamping", "Factor to damp vehicle angular movement per second (0.0 - 1.0)",
+ 0.95f,
+ (s,cf,p,v) => { VehicleAngularDamping = cf.GetFloat(p, v); },
+ (s) => { return VehicleAngularDamping; },
+ (s,p,l,v) => { VehicleAngularDamping = v; } ),
+
+ new ParameterDefn("MaxPersistantManifoldPoolSize", "Number of manifolds pooled (0 means default of 4096)",
+ 0f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].maxPersistantManifoldPoolSize; },
+ (s,p,l,v) => { s.UnmanagedParams[0].maxPersistantManifoldPoolSize = v; } ),
+ new ParameterDefn("MaxCollisionAlgorithmPoolSize", "Number of collisions pooled (0 means default of 4096)",
+ 0f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize; },
+ (s,p,l,v) => { s.UnmanagedParams[0].maxCollisionAlgorithmPoolSize = v; } ),
+ new ParameterDefn("ShouldDisableContactPoolDynamicAllocation", "Enable to allow large changes in object count",
+ ConfigurationParameters.numericFalse,
+ (s,cf,p,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation; },
+ (s,p,l,v) => { s.UnmanagedParams[0].shouldDisableContactPoolDynamicAllocation = v; } ),
+ new ParameterDefn("ShouldForceUpdateAllAabbs", "Enable to recomputer AABBs every simulator step",
+ ConfigurationParameters.numericFalse,
+ (s,cf,p,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return s.UnmanagedParams[0].shouldForceUpdateAllAabbs; },
+ (s,p,l,v) => { s.UnmanagedParams[0].shouldForceUpdateAllAabbs = v; } ),
+ new ParameterDefn("ShouldRandomizeSolverOrder", "Enable for slightly better stacking interaction",
+ ConfigurationParameters.numericTrue,
+ (s,cf,p,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return s.UnmanagedParams[0].shouldRandomizeSolverOrder; },
+ (s,p,l,v) => { s.UnmanagedParams[0].shouldRandomizeSolverOrder = v; } ),
+ new ParameterDefn("ShouldSplitSimulationIslands", "Enable splitting active object scanning islands",
+ ConfigurationParameters.numericTrue,
+ (s,cf,p,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return s.UnmanagedParams[0].shouldSplitSimulationIslands; },
+ (s,p,l,v) => { s.UnmanagedParams[0].shouldSplitSimulationIslands = v; } ),
+ new ParameterDefn("ShouldEnableFrictionCaching", "Enable friction computation caching",
+ ConfigurationParameters.numericFalse,
+ (s,cf,p,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return s.UnmanagedParams[0].shouldEnableFrictionCaching; },
+ (s,p,l,v) => { s.UnmanagedParams[0].shouldEnableFrictionCaching = v; } ),
+ new ParameterDefn("NumberOfSolverIterations", "Number of internal iterations (0 means default)",
+ 0f, // zero says use Bullet default
+ (s,cf,p,v) => { s.UnmanagedParams[0].numberOfSolverIterations = cf.GetFloat(p, v); },
+ (s) => { return s.UnmanagedParams[0].numberOfSolverIterations; },
+ (s,p,l,v) => { s.UnmanagedParams[0].numberOfSolverIterations = v; } ),
+
+ new ParameterDefn("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)",
+ (float)BSLinkset.LinksetImplementation.Compound,
+ (s,cf,p,v) => { LinksetImplementation = cf.GetFloat(p,v); },
+ (s) => { return LinksetImplementation; },
+ (s,p,l,v) => { LinksetImplementation = v; } ),
+ new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.",
+ ConfigurationParameters.numericFalse,
+ (s,cf,p,v) => { LinkConstraintUseFrameOffset = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return LinkConstraintUseFrameOffset; },
+ (s,p,l,v) => { LinkConstraintUseFrameOffset = v; } ),
+ new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints",
+ ConfigurationParameters.numericTrue,
+ (s,cf,p,v) => { LinkConstraintEnableTransMotor = BSParam.NumericBool(cf.GetBoolean(p, BSParam.BoolNumeric(v))); },
+ (s) => { return LinkConstraintEnableTransMotor; },
+ (s,p,l,v) => { LinkConstraintEnableTransMotor = v; } ),
+ new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints",
+ 5.0f,
+ (s,cf,p,v) => { LinkConstraintTransMotorMaxVel = cf.GetFloat(p, v); },
+ (s) => { return LinkConstraintTransMotorMaxVel; },
+ (s,p,l,v) => { LinkConstraintTransMotorMaxVel = v; } ),
+ new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints",
+ 0.1f,
+ (s,cf,p,v) => { LinkConstraintTransMotorMaxForce = cf.GetFloat(p, v); },
+ (s) => { return LinkConstraintTransMotorMaxForce; },
+ (s,p,l,v) => { LinkConstraintTransMotorMaxForce = v; } ),
+ new ParameterDefn("LinkConstraintCFM", "Amount constraint can be violated. 0=no violation, 1=infinite. Default=0.1",
+ 0.1f,
+ (s,cf,p,v) => { LinkConstraintCFM = cf.GetFloat(p, v); },
+ (s) => { return LinkConstraintCFM; },
+ (s,p,l,v) => { LinkConstraintCFM = v; } ),
+ new ParameterDefn("LinkConstraintERP", "Amount constraint is corrected each tick. 0=none, 1=all. Default = 0.2",
+ 0.1f,
+ (s,cf,p,v) => { LinkConstraintERP = cf.GetFloat(p, v); },
+ (s) => { return LinkConstraintERP; },
+ (s,p,l,v) => { LinkConstraintERP = v; } ),
+ new ParameterDefn("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)",
+ 40,
+ (s,cf,p,v) => { LinkConstraintSolverIterations = cf.GetFloat(p, v); },
+ (s) => { return LinkConstraintSolverIterations; },
+ (s,p,l,v) => { LinkConstraintSolverIterations = v; } ),
+
+ new ParameterDefn("LogPhysicsStatisticsFrames", "Frames between outputting detailed phys stats. (0 is off)",
+ 0f,
+ (s,cf,p,v) => { s.UnmanagedParams[0].physicsLoggingFrames = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.UnmanagedParams[0].physicsLoggingFrames; },
+ (s,p,l,v) => { s.UnmanagedParams[0].physicsLoggingFrames = (int)v; } ),
+ };
+
+ // Convert a boolean to our numeric true and false values
+ public static float NumericBool(bool b)
+ {
+ return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse);
+ }
+
+ // Convert numeric true and false values to a boolean
+ public static bool BoolNumeric(float b)
+ {
+ return (b == ConfigurationParameters.numericTrue ? true : false);
+ }
+
+ // Search through the parameter definitions and return the matching
+ // ParameterDefn structure.
+ // Case does not matter as names are compared after converting to lower case.
+ // Returns 'false' if the parameter is not found.
+ internal static bool TryGetParameter(string paramName, out ParameterDefn defn)
+ {
+ bool ret = false;
+ ParameterDefn foundDefn = new ParameterDefn();
+ string pName = paramName.ToLower();
+
+ foreach (ParameterDefn parm in ParameterDefinitions)
+ {
+ if (pName == parm.name.ToLower())
+ {
+ foundDefn = parm;
+ ret = true;
+ break;
+ }
+ }
+ defn = foundDefn;
+ return ret;
+ }
+
+ // Pass through the settable parameters and set the default values
+ internal static void SetParameterDefaultValues(BSScene physicsScene)
+ {
+ foreach (ParameterDefn parm in ParameterDefinitions)
+ {
+ parm.setter(physicsScene, parm.name, PhysParameterEntry.APPLY_TO_NONE, parm.defaultValue);
+ }
+ }
+
+ // Get user set values out of the ini file.
+ internal static void SetParameterConfigurationValues(BSScene physicsScene, IConfig cfg)
+ {
+ foreach (ParameterDefn parm in ParameterDefinitions)
+ {
+ parm.userParam(physicsScene, cfg, parm.name, parm.defaultValue);
+ }
+ }
+
+ internal static PhysParameterEntry[] SettableParameters = new PhysParameterEntry[1];
+
+ // This creates an array in the correct format for returning the list of
+ // parameters. This is used by the 'list' option of the 'physics' command.
+ internal static void BuildParameterTable()
+ {
+ if (SettableParameters.Length < ParameterDefinitions.Length)
+ {
+ List entries = new List();
+ for (int ii = 0; ii < ParameterDefinitions.Length; ii++)
+ {
+ ParameterDefn pd = ParameterDefinitions[ii];
+ entries.Add(new PhysParameterEntry(pd.name, pd.desc));
+ }
+
+ // make the list in alphabetical order for estetic reasons
+ entries.Sort(delegate(PhysParameterEntry ppe1, PhysParameterEntry ppe2)
+ {
+ return ppe1.name.CompareTo(ppe2.name);
+ });
+
+ SettableParameters = entries.ToArray();
+ }
+ }
+
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs
new file mode 100644
index 0000000..4096ef8
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPhysObject.cs
@@ -0,0 +1,345 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OMV = OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+/*
+ * Class to wrap all objects.
+ * The rest of BulletSim doesn't need to keep checking for avatars or prims
+ * unless the difference is significant.
+ *
+ * Variables in the physicsl objects are in three forms:
+ * VariableName: used by the simulator and performs taint operations, etc
+ * RawVariableName: direct reference to the BulletSim storage for the variable value
+ * ForceVariableName: direct reference (store and fetch) to the value in the physics engine.
+ * The last two (and certainly the last one) should be referenced only in taint-time.
+ */
+
+/*
+ * As of 20121221, the following are the call sequences (going down) for different script physical functions:
+ * llApplyImpulse llApplyRotImpulse llSetTorque llSetForce
+ * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce
+ * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse
+ * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v
+ * BS.ApplyCentralForce BS.ApplyTorque
+ */
+
+public abstract class BSPhysObject : PhysicsActor
+{
+ protected BSPhysObject()
+ {
+ }
+ protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
+ {
+ PhysicsScene = parentScene;
+ LocalID = localID;
+ PhysObjectName = name;
+ TypeName = typeName;
+
+ Linkset = BSLinkset.Factory(PhysicsScene, this);
+ LastAssetBuildFailed = false;
+
+ // Default material type
+ Material = MaterialAttributes.Material.Wood;
+
+ CollisionCollection = new CollisionEventUpdate();
+ SubscribedEventsMs = 0;
+ CollidingStep = 0;
+ CollidingGroundStep = 0;
+ }
+
+ // Tell the object to clean up.
+ public virtual void Destroy()
+ {
+ UnRegisterAllPreStepActions();
+ }
+
+ public BSScene PhysicsScene { get; protected set; }
+ // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor
+ public string PhysObjectName { get; protected set; }
+ public string TypeName { get; protected set; }
+
+ public BSLinkset Linkset { get; set; }
+ public BSLinksetInfo LinksetInfo { get; set; }
+
+ // Return the object mass without calculating it or having side effects
+ public abstract float RawMass { get; }
+ // Set the raw mass but also update physical mass properties (inertia, ...)
+ public abstract void UpdatePhysicalMassProperties(float mass);
+
+ // The last value calculated for the prim's inertia
+ public OMV.Vector3 Inertia { get; set; }
+
+ // Reference to the physical body (btCollisionObject) of this object
+ public BulletBody PhysBody;
+ // Reference to the physical shape (btCollisionShape) of this object
+ public BulletShape PhysShape;
+
+ // 'true' if the mesh's underlying asset failed to build.
+ // This will keep us from looping after the first time the build failed.
+ public bool LastAssetBuildFailed { get; set; }
+
+ // The objects base shape information. Null if not a prim type shape.
+ public PrimitiveBaseShape BaseShape { get; protected set; }
+ // Some types of objects have preferred physical representations.
+ // Returns SHAPE_UNKNOWN if there is no preference.
+ public virtual BSPhysicsShapeType PreferredPhysicalShape
+ {
+ get { return BSPhysicsShapeType.SHAPE_UNKNOWN; }
+ }
+
+ // When the physical properties are updated, an EntityProperty holds the update values.
+ // Keep the current and last EntityProperties to enable computation of differences
+ // between the current update and the previous values.
+ public EntityProperties CurrentEntityProperties { get; set; }
+ public EntityProperties LastEntityProperties { get; set; }
+
+ public virtual OMV.Vector3 Scale { get; set; }
+ public abstract bool IsSolid { get; }
+ public abstract bool IsStatic { get; }
+
+ // Materialness
+ public MaterialAttributes.Material Material { get; private set; }
+ public override void SetMaterial(int material)
+ {
+ Material = (MaterialAttributes.Material)material;
+ }
+
+ // Stop all physical motion.
+ public abstract void ZeroMotion(bool inTaintTime);
+ public abstract void ZeroAngularMotion(bool inTaintTime);
+
+ // Step the vehicle simulation for this object. A NOOP if the vehicle was not configured.
+ public virtual void StepVehicle(float timeStep) { }
+
+ // Update the physical location and motion of the object. Called with data from Bullet.
+ public abstract void UpdateProperties(EntityProperties entprop);
+
+ public abstract OMV.Vector3 RawPosition { get; set; }
+ public abstract OMV.Vector3 ForcePosition { get; set; }
+
+ public abstract OMV.Quaternion RawOrientation { get; set; }
+ public abstract OMV.Quaternion ForceOrientation { get; set; }
+
+ // The system is telling us the velocity it wants to move at.
+ // protected OMV.Vector3 m_targetVelocity; // use the definition in PhysicsActor
+ public override OMV.Vector3 TargetVelocity
+ {
+ get { return m_targetVelocity; }
+ set
+ {
+ m_targetVelocity = value;
+ Velocity = value;
+ }
+ }
+ public abstract OMV.Vector3 ForceVelocity { get; set; }
+
+ public abstract OMV.Vector3 ForceRotationalVelocity { get; set; }
+
+ public abstract float ForceBuoyancy { get; set; }
+
+ public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; }
+
+ #region Collisions
+
+ // Requested number of milliseconds between collision events. Zero means disabled.
+ protected int SubscribedEventsMs { get; set; }
+ // Given subscription, the time that a collision may be passed up
+ protected int NextCollisionOkTime { get; set; }
+ // The simulation step that last had a collision
+ protected long CollidingStep { get; set; }
+ // The simulation step that last had a collision with the ground
+ protected long CollidingGroundStep { get; set; }
+ // The collision flags we think are set in Bullet
+ protected CollisionFlags CurrentCollisionFlags { get; set; }
+
+ // The collisions that have been collected this tick
+ protected CollisionEventUpdate CollisionCollection;
+
+ // The simulation step is telling this object about a collision.
+ // Return 'true' if a collision was processed and should be sent up.
+ // Called at taint time from within the Step() function
+ public virtual bool Collide(uint collidingWith, BSPhysObject collidee,
+ OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
+ {
+ bool ret = false;
+
+ // The following lines make IsColliding() and IsCollidingGround() work
+ CollidingStep = PhysicsScene.SimulationStep;
+ if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID)
+ {
+ CollidingGroundStep = PhysicsScene.SimulationStep;
+ }
+
+ // prims in the same linkset cannot collide with each other
+ if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID))
+ {
+ return ret;
+ }
+
+ // if someone has subscribed for collision events....
+ if (SubscribedEvents()) {
+ CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
+ DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}",
+ LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth);
+
+ ret = true;
+ }
+ return ret;
+ }
+
+ // Send the collected collisions into the simulator.
+ // Called at taint time from within the Step() function thus no locking problems
+ // with CollisionCollection and ObjectsWithNoMoreCollisions.
+ // Return 'true' if there were some actual collisions passed up
+ public virtual bool SendCollisions()
+ {
+ bool ret = true;
+ // If the 'no collision' call, force it to happen right now so quick collision_end
+ bool force = (CollisionCollection.Count == 0);
+
+ // throttle the collisions to the number of milliseconds specified in the subscription
+ if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime))
+ {
+ NextCollisionOkTime = PhysicsScene.SimulationNowTime + SubscribedEventsMs;
+
+ // We are called if we previously had collisions. If there are no collisions
+ // this time, send up one last empty event so OpenSim can sense collision end.
+ if (CollisionCollection.Count == 0)
+ {
+ // If I have no collisions this time, remove me from the list of objects with collisions.
+ ret = false;
+ }
+
+ // DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count);
+ base.SendCollisionUpdate(CollisionCollection);
+
+ // The CollisionCollection instance is passed around in the simulator.
+ // Make sure we don't have a handle to that one and that a new one is used for next time.
+ // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here,
+ // a race condition is created for the other users of this instance.
+ CollisionCollection = new CollisionEventUpdate();
+ }
+ return ret;
+ }
+
+ // Subscribe for collision events.
+ // Parameter is the millisecond rate the caller wishes collision events to occur.
+ public override void SubscribeEvents(int ms) {
+ // DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms);
+ SubscribedEventsMs = ms;
+ if (ms > 0)
+ {
+ // make sure first collision happens
+ NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);
+
+ PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate()
+ {
+ if (PhysBody.HasPhysicalBody)
+ CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ });
+ }
+ else
+ {
+ // Subscribing for zero or less is the same as unsubscribing
+ UnSubscribeEvents();
+ }
+ }
+ public override void UnSubscribeEvents() {
+ // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName);
+ SubscribedEventsMs = 0;
+ PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate()
+ {
+ // Make sure there is a body there because sometimes destruction happens in an un-ideal order.
+ if (PhysBody.HasPhysicalBody)
+ CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ });
+ }
+ // Return 'true' if the simulator wants collision events
+ public override bool SubscribedEvents() {
+ return (SubscribedEventsMs > 0);
+ }
+
+ #endregion // Collisions
+
+ #region Per Simulation Step actions
+ // There are some actions that must be performed for a physical object before each simulation step.
+ // These actions are optional so, rather than scanning all the physical objects and asking them
+ // if they have anything to do, a physical object registers for an event call before the step is performed.
+ // This bookkeeping makes it easy to add, remove and clean up after all these registrations.
+ private Dictionary RegisteredActions = new Dictionary();
+ protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn)
+ {
+ string identifier = op + "-" + id.ToString();
+ RegisteredActions[identifier] = actn;
+ PhysicsScene.BeforeStep += actn;
+ DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
+ }
+
+ // Unregister a pre step action. Safe to call if the action has not been registered.
+ protected void UnRegisterPreStepAction(string op, uint id)
+ {
+ string identifier = op + "-" + id.ToString();
+ bool removed = false;
+ if (RegisteredActions.ContainsKey(identifier))
+ {
+ PhysicsScene.BeforeStep -= RegisteredActions[identifier];
+ RegisteredActions.Remove(identifier);
+ removed = true;
+ }
+ DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
+ }
+
+ protected void UnRegisterAllPreStepActions()
+ {
+ foreach (KeyValuePair kvp in RegisteredActions)
+ {
+ PhysicsScene.BeforeStep -= kvp.Value;
+ }
+ RegisteredActions.Clear();
+ DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
+ }
+
+
+ #endregion // Per Simulation Step actions
+
+ // High performance detailed logging routine used by the physical objects.
+ protected void DetailLog(string msg, params Object[] args)
+ {
+ if (PhysicsScene.PhysicsLogging.Enabled)
+ PhysicsScene.DetailLog(msg, args);
+ }
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPlugin.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPlugin.cs
new file mode 100644
index 0000000..75963ee
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPlugin.cs
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+ ///
+ /// Entry for a port of Bullet (http://bulletphysics.org/) to OpenSim.
+ /// This module interfaces to an unmanaged C++ library which makes the
+ /// actual calls into the Bullet physics engine.
+ /// The unmanaged library is found in opensim-libs::trunk/unmanaged/BulletSim/.
+ /// The unmanaged library is compiled and linked statically with Bullet
+ /// to create BulletSim.dll and libBulletSim.so (for both 32 and 64 bit).
+ ///
+public class BSPlugin : IPhysicsPlugin
+{
+ //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+
+ private BSScene _mScene;
+
+ public BSPlugin()
+ {
+ }
+
+ public bool Init()
+ {
+ return true;
+ }
+
+ public PhysicsScene GetScene(String sceneIdentifier)
+ {
+ if (_mScene == null)
+ {
+
+ // If not Windows, loading is performed by the
+ // Mono loader as specified in
+ // "bin/Physics/OpenSim.Region.Physics.BulletSNPlugin.dll.config".
+
+ _mScene = new BSScene(sceneIdentifier);
+ }
+ return (_mScene);
+ }
+
+ public string GetName()
+ {
+ return ("BulletSimN");
+ }
+
+ public void Dispose()
+ {
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
new file mode 100644
index 0000000..a889c24
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
@@ -0,0 +1,1467 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+using System.Xml;
+using log4net;
+using OMV = OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+using OpenSim.Region.Physics.ConvexDecompositionDotNet;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+
+ [Serializable]
+public sealed class BSPrim : BSPhysObject
+{
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly string LogHeader = "[BULLETS PRIM]";
+
+ // _size is what the user passed. Scale is what we pass to the physics engine with the mesh.
+ private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user
+
+ private bool _grabbed;
+ private bool _isSelected;
+ private bool _isVolumeDetect;
+ private OMV.Vector3 _position;
+ private float _mass; // the mass of this object
+ private float _density;
+ private OMV.Vector3 _force;
+ private OMV.Vector3 _velocity;
+ private OMV.Vector3 _torque;
+ private float _collisionScore;
+ private OMV.Vector3 _acceleration;
+ private OMV.Quaternion _orientation;
+ private int _physicsActorType;
+ private bool _isPhysical;
+ private bool _flying;
+ private float _friction;
+ private float _restitution;
+ private bool _setAlwaysRun;
+ private bool _throttleUpdates;
+ private bool _isColliding;
+ private bool _collidingGround;
+ private bool _collidingObj;
+ private bool _floatOnWater;
+ private OMV.Vector3 _rotationalVelocity;
+ private bool _kinematic;
+ private float _buoyancy;
+
+ private BSDynamics _vehicle;
+
+ private OMV.Vector3 _PIDTarget;
+ private bool _usePID;
+ private float _PIDTau;
+ private bool _useHoverPID;
+ private float _PIDHoverHeight;
+ private PIDHoverType _PIDHoverType;
+ private float _PIDHoverTao;
+
+ public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
+ OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
+ : base(parent_scene, localID, primName, "BSPrim")
+ {
+ // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
+ _physicsActorType = (int)ActorTypes.Prim;
+ _position = pos;
+ _size = size;
+ Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
+ _orientation = rotation;
+ _buoyancy = 1f;
+ _velocity = OMV.Vector3.Zero;
+ _rotationalVelocity = OMV.Vector3.Zero;
+ BaseShape = pbs;
+ _isPhysical = pisPhysical;
+ _isVolumeDetect = false;
+
+ // Someday set default attributes based on the material but, for now, we don't know the prim material yet.
+ // MaterialAttributes primMat = BSMaterials.GetAttributes(Material, pisPhysical);
+ _density = PhysicsScene.Params.defaultDensity;
+ _friction = PhysicsScene.Params.defaultFriction;
+ _restitution = PhysicsScene.Params.defaultRestitution;
+
+ _vehicle = new BSDynamics(PhysicsScene, this); // add vehicleness
+
+ _mass = CalculateMass();
+
+ // No body or shape yet
+ PhysBody = new BulletBody(LocalID);
+ PhysShape = new BulletShape();
+
+ DetailLog("{0},BSPrim.constructor,call", LocalID);
+ // do the actual object creation at taint time
+ PhysicsScene.TaintedObject("BSPrim.create", delegate()
+ {
+ CreateGeomAndObject(true);
+
+ CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(PhysBody.ptr);
+ });
+ }
+
+ // called when this prim is being destroyed and we should free all the resources
+ public override void Destroy()
+ {
+ // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID);
+ base.Destroy();
+
+ // Undo any links between me and any other object
+ BSPhysObject parentBefore = Linkset.LinksetRoot;
+ int childrenBefore = Linkset.NumberOfChildren;
+
+ Linkset = Linkset.RemoveMeFromLinkset(this);
+
+ DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}",
+ LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
+
+ // Undo any vehicle properties
+ this.VehicleType = (int)Vehicle.TYPE_NONE;
+
+ PhysicsScene.TaintedObject("BSPrim.destroy", delegate()
+ {
+ DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
+ // If there are physical body and shape, release my use of same.
+ PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null);
+ PhysBody.Clear();
+ PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null);
+ PhysShape.Clear();
+ });
+ }
+
+ // No one uses this property.
+ public override bool Stopped {
+ get { return false; }
+ }
+ public override OMV.Vector3 Size {
+ get { return _size; }
+ set {
+ // We presume the scale and size are the same. If scale must be changed for
+ // the physical shape, that is done when the geometry is built.
+ _size = value;
+ Scale = _size;
+ ForceBodyShapeRebuild(false);
+ }
+ }
+
+ public override PrimitiveBaseShape Shape {
+ set {
+ BaseShape = value;
+ ForceBodyShapeRebuild(false);
+ }
+ }
+ // Whatever the linkset wants is what I want.
+ public override BSPhysicsShapeType PreferredPhysicalShape
+ { get { return Linkset.PreferredPhysicalShape(this); } }
+
+ public override bool ForceBodyShapeRebuild(bool inTaintTime)
+ {
+ LastAssetBuildFailed = false;
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ForceBodyShapeRebuild", delegate()
+ {
+ _mass = CalculateMass(); // changing the shape changes the mass
+ CreateGeomAndObject(true);
+ });
+ return true;
+ }
+ public override bool Grabbed {
+ set { _grabbed = value;
+ }
+ }
+ public override bool Selected {
+ set
+ {
+ if (value != _isSelected)
+ {
+ _isSelected = value;
+ PhysicsScene.TaintedObject("BSPrim.setSelected", delegate()
+ {
+ DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected);
+ SetObjectDynamic(false);
+ });
+ }
+ }
+ }
+ public override void CrossingFailure() { return; }
+
+ // link me to the specified parent
+ public override void link(PhysicsActor obj) {
+ BSPrim parent = obj as BSPrim;
+ if (parent != null)
+ {
+ BSPhysObject parentBefore = Linkset.LinksetRoot;
+ int childrenBefore = Linkset.NumberOfChildren;
+
+ Linkset = parent.Linkset.AddMeToLinkset(this);
+
+ DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
+ LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
+ }
+ return;
+ }
+
+ // delink me from my linkset
+ public override void delink() {
+ // TODO: decide if this parent checking needs to happen at taint time
+ // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
+
+ BSPhysObject parentBefore = Linkset.LinksetRoot;
+ int childrenBefore = Linkset.NumberOfChildren;
+
+ Linkset = Linkset.RemoveMeFromLinkset(this);
+
+ DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ",
+ LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
+ return;
+ }
+
+ // Set motion values to zero.
+ // Do it to the properties so the values get set in the physics engine.
+ // Push the setting of the values to the viewer.
+ // Called at taint time!
+ public override void ZeroMotion(bool inTaintTime)
+ {
+ _velocity = OMV.Vector3.Zero;
+ _acceleration = OMV.Vector3.Zero;
+ _rotationalVelocity = OMV.Vector3.Zero;
+
+ // Zero some other properties in the physics engine
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
+ {
+ if (PhysBody.HasPhysicalBody)
+ BulletSimAPI.ClearAllForces2(PhysBody.ptr);
+ });
+ }
+ public override void ZeroAngularMotion(bool inTaintTime)
+ {
+ _rotationalVelocity = OMV.Vector3.Zero;
+ // Zero some other properties in the physics engine
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
+ {
+ // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity);
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ }
+ });
+ }
+
+ public override void LockAngularMotion(OMV.Vector3 axis)
+ {
+ DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
+ return;
+ }
+
+ public override OMV.Vector3 RawPosition
+ {
+ get { return _position; }
+ set { _position = value; }
+ }
+ public override OMV.Vector3 Position {
+ get {
+ /* NOTE: this refetch is not necessary. The simulator knows about linkset children
+ * and does not fetch this position info for children. Thus this is commented out.
+ // child prims move around based on their parent. Need to get the latest location
+ if (!Linkset.IsRoot(this))
+ _position = Linkset.PositionGet(this);
+ */
+
+ // don't do the GetObjectPosition for root elements because this function is called a zillion times.
+ // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr);
+ return _position;
+ }
+ set {
+ // If the position must be forced into the physics engine, use ForcePosition.
+ // All positions are given in world positions.
+ if (_position == value)
+ {
+ DetailLog("{0},BSPrim.setPosition,taint,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation);
+ return;
+ }
+ _position = value;
+ PositionSanityCheck(false);
+
+ // A linkset might need to know if a component information changed.
+ Linkset.UpdateProperties(this, false);
+
+ PhysicsScene.TaintedObject("BSPrim.setPosition", delegate()
+ {
+ DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
+ ForcePosition = _position;
+ });
+ }
+ }
+ public override OMV.Vector3 ForcePosition {
+ get {
+ _position = BulletSimAPI.GetPosition2(PhysBody.ptr);
+ return _position;
+ }
+ set {
+ _position = value;
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ ActivateIfPhysical(false);
+ }
+ }
+ }
+
+ // Check that the current position is sane and, if not, modify the position to make it so.
+ // Check for being below terrain and being out of bounds.
+ // Returns 'true' of the position was made sane by some action.
+ private bool PositionSanityCheck(bool inTaintTime)
+ {
+ bool ret = false;
+
+ if (!PhysicsScene.TerrainManager.IsWithinKnownTerrain(_position))
+ {
+ // The physical object is out of the known/simulated area.
+ // Upper levels of code will handle the transition to other areas so, for
+ // the time, we just ignore the position.
+ return ret;
+ }
+
+ float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position);
+ OMV.Vector3 upForce = OMV.Vector3.Zero;
+ if (RawPosition.Z < terrainHeight)
+ {
+ DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight);
+ float targetHeight = terrainHeight + (Size.Z / 2f);
+ // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec.
+ upForce.Z = (terrainHeight - RawPosition.Z) * 1f;
+ ret = true;
+ }
+
+ if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
+ {
+ float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position);
+ // TODO: a floating motor so object will bob in the water
+ if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f)
+ {
+ // Upforce proportional to the distance away from the water. Correct the error in 1 sec.
+ upForce.Z = (waterHeight - RawPosition.Z) * 1f;
+ ret = true;
+ }
+ }
+
+ // The above code computes a force to apply to correct any out-of-bounds problems. Apply same.
+ // TODO: This should be intergrated with a geneal physics action mechanism.
+ // TODO: This should be moderated with PID'ness.
+ if (ret)
+ {
+ // Apply upforce and overcome gravity.
+ OMV.Vector3 correctionForce = upForce - PhysicsScene.DefaultGravity;
+ DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce);
+ AddForce(correctionForce, false, inTaintTime);
+ }
+ return ret;
+ }
+
+ // Return the effective mass of the object.
+ // If there are multiple items in the linkset, add them together for the root
+ public override float Mass
+ {
+ get
+ {
+ return Linkset.LinksetMass;
+ // return _mass;
+ }
+ }
+
+ // used when we only want this prim's mass and not the linkset thing
+ public override float RawMass {
+ get { return _mass; }
+ }
+ // Set the physical mass to the passed mass.
+ // Note that this does not change _mass!
+ public override void UpdatePhysicalMassProperties(float physMass)
+ {
+ if (IsStatic)
+ {
+ Inertia = OMV.Vector3.Zero;
+ BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
+ BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ }
+ else
+ {
+ Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
+ BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
+ BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ // center of mass is at the zero of the object
+ // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
+ DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia);
+ }
+ }
+
+ // Is this used?
+ public override OMV.Vector3 CenterOfMass
+ {
+ get { return Linkset.CenterOfMass; }
+ }
+
+ // Is this used?
+ public override OMV.Vector3 GeometricCenter
+ {
+ get { return Linkset.GeometricCenter; }
+ }
+
+ public override OMV.Vector3 Force {
+ get { return _force; }
+ set {
+ _force = value;
+ if (_force != OMV.Vector3.Zero)
+ {
+ // If the force is non-zero, it must be reapplied each tick because
+ // Bullet clears the forces applied last frame.
+ RegisterPreStepAction("BSPrim.setForce", LocalID,
+ delegate(float timeStep)
+ {
+ DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force);
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force);
+ ActivateIfPhysical(false);
+ }
+ }
+ );
+ }
+ else
+ {
+ UnRegisterPreStepAction("BSPrim.setForce", LocalID);
+ }
+ }
+ }
+
+ public override int VehicleType {
+ get {
+ return (int)_vehicle.Type; // if we are a vehicle, return that type
+ }
+ set {
+ Vehicle type = (Vehicle)value;
+
+ PhysicsScene.TaintedObject("setVehicleType", delegate()
+ {
+ // Done at taint time so we're sure the physics engine is not using the variables
+ // Vehicle code changes the parameters for this vehicle type.
+ _vehicle.ProcessTypeChange(type);
+ ActivateIfPhysical(false);
+
+ // If an active vehicle, register the vehicle code to be called before each step
+ if (_vehicle.Type == Vehicle.TYPE_NONE)
+ UnRegisterPreStepAction("BSPrim.Vehicle", LocalID);
+ else
+ RegisterPreStepAction("BSPrim.Vehicle", LocalID, _vehicle.Step);
+ });
+ }
+ }
+ public override void VehicleFloatParam(int param, float value)
+ {
+ PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate()
+ {
+ _vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
+ ActivateIfPhysical(false);
+ });
+ }
+ public override void VehicleVectorParam(int param, OMV.Vector3 value)
+ {
+ PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate()
+ {
+ _vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
+ ActivateIfPhysical(false);
+ });
+ }
+ public override void VehicleRotationParam(int param, OMV.Quaternion rotation)
+ {
+ PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate()
+ {
+ _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
+ ActivateIfPhysical(false);
+ });
+ }
+ public override void VehicleFlags(int param, bool remove)
+ {
+ PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate()
+ {
+ _vehicle.ProcessVehicleFlags(param, remove);
+ });
+ }
+
+ // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
+ public override void SetVolumeDetect(int param) {
+ bool newValue = (param != 0);
+ if (_isVolumeDetect != newValue)
+ {
+ _isVolumeDetect = newValue;
+ PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate()
+ {
+ // DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect);
+ SetObjectDynamic(true);
+ });
+ }
+ return;
+ }
+ public override OMV.Vector3 Velocity {
+ get { return _velocity; }
+ set {
+ _velocity = value;
+ PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate()
+ {
+ // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
+ ForceVelocity = _velocity;
+ });
+ }
+ }
+ public override OMV.Vector3 ForceVelocity {
+ get { return _velocity; }
+ set {
+ PhysicsScene.AssertInTaintTime("BSPrim.ForceVelocity");
+
+ _velocity = value;
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
+ ActivateIfPhysical(false);
+ }
+ }
+ }
+ public override OMV.Vector3 Torque {
+ get { return _torque; }
+ set {
+ _torque = value;
+ if (_torque != OMV.Vector3.Zero)
+ {
+ // If the torque is non-zero, it must be reapplied each tick because
+ // Bullet clears the forces applied last frame.
+ RegisterPreStepAction("BSPrim.setTorque", LocalID,
+ delegate(float timeStep)
+ {
+ if (PhysBody.HasPhysicalBody)
+ AddAngularForce(_torque, false, true);
+ }
+ );
+ }
+ else
+ {
+ UnRegisterPreStepAction("BSPrim.setTorque", LocalID);
+ }
+ // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque);
+ }
+ }
+ public override float CollisionScore {
+ get { return _collisionScore; }
+ set { _collisionScore = value;
+ }
+ }
+ public override OMV.Vector3 Acceleration {
+ get { return _acceleration; }
+ set { _acceleration = value; }
+ }
+ public override OMV.Quaternion RawOrientation
+ {
+ get { return _orientation; }
+ set { _orientation = value; }
+ }
+ public override OMV.Quaternion Orientation {
+ get {
+ /* NOTE: this refetch is not necessary. The simulator knows about linkset children
+ * and does not fetch this position info for children. Thus this is commented out.
+ // Children move around because tied to parent. Get a fresh value.
+ if (!Linkset.IsRoot(this))
+ {
+ _orientation = Linkset.OrientationGet(this);
+ }
+ */
+ return _orientation;
+ }
+ set {
+ if (_orientation == value)
+ return;
+ _orientation = value;
+
+ // A linkset might need to know if a component information changed.
+ Linkset.UpdateProperties(this, false);
+
+ PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr);
+ // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
+ BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ }
+ });
+ }
+ }
+ // Go directly to Bullet to get/set the value.
+ public override OMV.Quaternion ForceOrientation
+ {
+ get
+ {
+ _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr);
+ return _orientation;
+ }
+ set
+ {
+ _orientation = value;
+ BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ }
+ }
+ public override int PhysicsActorType {
+ get { return _physicsActorType; }
+ set { _physicsActorType = value; }
+ }
+ public override bool IsPhysical {
+ get { return _isPhysical; }
+ set {
+ if (_isPhysical != value)
+ {
+ _isPhysical = value;
+ PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate()
+ {
+ // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical);
+ SetObjectDynamic(true);
+ // whether phys-to-static or static-to-phys, the object is not moving.
+ ZeroMotion(true);
+ });
+ }
+ }
+ }
+
+ // An object is static (does not move) if selected or not physical
+ public override bool IsStatic
+ {
+ get { return _isSelected || !IsPhysical; }
+ }
+
+ // An object is solid if it's not phantom and if it's not doing VolumeDetect
+ public override bool IsSolid
+ {
+ get { return !IsPhantom && !_isVolumeDetect; }
+ }
+
+ // Make gravity work if the object is physical and not selected
+ // Called at taint-time!!
+ private void SetObjectDynamic(bool forceRebuild)
+ {
+ // Recreate the physical object if necessary
+ CreateGeomAndObject(forceRebuild);
+ }
+
+ // Convert the simulator's physical properties into settings on BulletSim objects.
+ // There are four flags we're interested in:
+ // IsStatic: Object does not move, otherwise the object has mass and moves
+ // isSolid: other objects bounce off of this object
+ // isVolumeDetect: other objects pass through but can generate collisions
+ // collisionEvents: whether this object returns collision events
+ private void UpdatePhysicalParameters()
+ {
+ // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape);
+
+ // Mangling all the physical properties requires the object not be in the physical world.
+ // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found).
+ BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+
+ // Set up the object physicalness (does gravity and collisions move this object)
+ MakeDynamic(IsStatic);
+
+ // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters)
+ _vehicle.Refresh();
+
+ // Arrange for collision events if the simulator wants them
+ EnableCollisions(SubscribedEvents());
+
+ // Make solid or not (do things bounce off or pass through this object).
+ MakeSolid(IsSolid);
+
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr, _position, _orientation);
+
+ // Rebuild its shape
+ BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
+
+ // Collision filter can be set only when the object is in the world
+ PhysBody.ApplyCollisionMask();
+
+ // Recompute any linkset parameters.
+ // When going from non-physical to physical, this re-enables the constraints that
+ // had been automatically disabled when the mass was set to zero.
+ // For compound based linksets, this enables and disables interactions of the children.
+ Linkset.Refresh(this);
+
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
+ LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape);
+ }
+
+ // "Making dynamic" means changing to and from static.
+ // When static, gravity does not effect the object and it is fixed in space.
+ // When dynamic, the object can fall and be pushed by others.
+ // This is independent of its 'solidness' which controls what passes through
+ // this object and what interacts with it.
+ private void MakeDynamic(bool makeStatic)
+ {
+ if (makeStatic)
+ {
+ // Become a Bullet 'static' object type
+ CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ // Stop all movement
+ ZeroMotion(true);
+
+ // Set various physical properties so other object interact properly
+ MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
+ BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
+ BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
+
+ // Mass is zero which disables a bunch of physics stuff in Bullet
+ UpdatePhysicalMassProperties(0f);
+ // Set collision detection parameters
+ if (BSParam.CcdMotionThreshold > 0f)
+ {
+ BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold);
+ BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
+ }
+
+ // The activation state is 'disabled' so Bullet will not try to act on it.
+ // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION);
+ // Start it out sleeping and physical actions could wake it up.
+ BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING);
+
+ // This collides like a static object
+ PhysBody.collisionType = CollisionType.Static;
+
+ // There can be special things needed for implementing linksets
+ Linkset.MakeStatic(this);
+ }
+ else
+ {
+ // Not a Bullet static object
+ CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+
+ // Set various physical properties so other object interact properly
+ MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
+ BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
+ BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
+
+ // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
+ // Since this can be called multiple times, only zero forces when becoming physical
+ // BulletSimAPI.ClearAllForces2(BSBody.ptr);
+
+ // For good measure, make sure the transform is set through to the motion state
+ BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+
+ // Center of mass is at the center of the object
+ // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
+
+ // A dynamic object has mass
+ UpdatePhysicalMassProperties(RawMass);
+
+ // Set collision detection parameters
+ if (BSParam.CcdMotionThreshold > 0f)
+ {
+ BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold);
+ BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
+ }
+
+ // Various values for simulation limits
+ BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping);
+ BulletSimAPI.SetDeactivationTime2(PhysBody.ptr, BSParam.DeactivationTime);
+ BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold);
+ BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold);
+
+ // This collides like an object.
+ PhysBody.collisionType = CollisionType.Dynamic;
+
+ // Force activation of the object so Bullet will act on it.
+ // Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects.
+ BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG);
+
+ // There might be special things needed for implementing linksets.
+ Linkset.MakeDynamic(this);
+ }
+ }
+
+ // "Making solid" means that other object will not pass through this object.
+ // To make transparent, we create a Bullet ghost object.
+ // Note: This expects to be called from the UpdatePhysicalParameters() routine as
+ // the functions after this one set up the state of a possibly newly created collision body.
+ private void MakeSolid(bool makeSolid)
+ {
+ CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(PhysBody.ptr);
+ if (makeSolid)
+ {
+ // Verify the previous code created the correct shape for this type of thing.
+ if ((bodyType & CollisionObjectTypes.CO_RIGID_BODY) == 0)
+ {
+ m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType);
+ }
+ CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ }
+ else
+ {
+ if ((bodyType & CollisionObjectTypes.CO_GHOST_OBJECT) == 0)
+ {
+ m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType);
+ }
+ CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+
+ // Change collision info from a static object to a ghosty collision object
+ PhysBody.collisionType = CollisionType.VolumeDetect;
+ }
+ }
+
+ // Enable physical actions. Bullet will keep sleeping non-moving physical objects so
+ // they need waking up when parameters are changed.
+ // Called in taint-time!!
+ private void ActivateIfPhysical(bool forceIt)
+ {
+ if (IsPhysical && PhysBody.HasPhysicalBody)
+ BulletSimAPI.Activate2(PhysBody.ptr, forceIt);
+ }
+
+ // Turn on or off the flag controlling whether collision events are returned to the simulator.
+ private void EnableCollisions(bool wantsCollisionEvents)
+ {
+ if (wantsCollisionEvents)
+ {
+ CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ }
+ else
+ {
+ CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ }
+ }
+
+ // prims don't fly
+ public override bool Flying {
+ get { return _flying; }
+ set {
+ _flying = value;
+ }
+ }
+ public override bool SetAlwaysRun {
+ get { return _setAlwaysRun; }
+ set { _setAlwaysRun = value; }
+ }
+ public override bool ThrottleUpdates {
+ get { return _throttleUpdates; }
+ set { _throttleUpdates = value; }
+ }
+ public override bool IsColliding {
+ get { return (CollidingStep == PhysicsScene.SimulationStep); }
+ set { _isColliding = value; }
+ }
+ public override bool CollidingGround {
+ get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
+ set { _collidingGround = value; }
+ }
+ public override bool CollidingObj {
+ get { return _collidingObj; }
+ set { _collidingObj = value; }
+ }
+ public bool IsPhantom {
+ get {
+ // SceneObjectPart removes phantom objects from the physics scene
+ // so, although we could implement touching and such, we never
+ // are invoked as a phantom object
+ return false;
+ }
+ }
+ public override bool FloatOnWater {
+ set {
+ _floatOnWater = value;
+ PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate()
+ {
+ if (_floatOnWater)
+ CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ else
+ CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ });
+ }
+ }
+ public override OMV.Vector3 RotationalVelocity {
+ get {
+ return _rotationalVelocity;
+ }
+ set {
+ _rotationalVelocity = value;
+ // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity);
+ PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
+ {
+ DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
+ ForceRotationalVelocity = _rotationalVelocity;
+ });
+ }
+ }
+ public override OMV.Vector3 ForceRotationalVelocity {
+ get {
+ return _rotationalVelocity;
+ }
+ set {
+ _rotationalVelocity = value;
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ ActivateIfPhysical(false);
+ }
+ }
+ }
+ public override bool Kinematic {
+ get { return _kinematic; }
+ set { _kinematic = value;
+ // m_log.DebugFormat("{0}: Kinematic={1}", LogHeader, _kinematic);
+ }
+ }
+ public override float Buoyancy {
+ get { return _buoyancy; }
+ set {
+ _buoyancy = value;
+ PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate()
+ {
+ ForceBuoyancy = _buoyancy;
+ });
+ }
+ }
+ public override float ForceBuoyancy {
+ get { return _buoyancy; }
+ set {
+ _buoyancy = value;
+ // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
+ // Buoyancy is faked by changing the gravity applied to the object
+ if (PhysBody.HasPhysicalBody)
+ {
+ float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
+ BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
+ ActivateIfPhysical(false);
+ }
+ }
+ }
+
+ // Used for MoveTo
+ public override OMV.Vector3 PIDTarget {
+ set { _PIDTarget = value; }
+ }
+ public override bool PIDActive {
+ set { _usePID = value; }
+ }
+ public override float PIDTau {
+ set { _PIDTau = value; }
+ }
+
+ // Used for llSetHoverHeight and maybe vehicle height
+ // Hover Height will override MoveTo target's Z
+ public override bool PIDHoverActive {
+ set { _useHoverPID = value; }
+ }
+ public override float PIDHoverHeight {
+ set { _PIDHoverHeight = value; }
+ }
+ public override PIDHoverType PIDHoverType {
+ set { _PIDHoverType = value; }
+ }
+ public override float PIDHoverTau {
+ set { _PIDHoverTao = value; }
+ }
+
+ // For RotLookAt
+ public override OMV.Quaternion APIDTarget { set { return; } }
+ public override bool APIDActive { set { return; } }
+ public override float APIDStrength { set { return; } }
+ public override float APIDDamping { set { return; } }
+
+ public override void AddForce(OMV.Vector3 force, bool pushforce) {
+ AddForce(force, pushforce, false);
+ }
+ // Applying a force just adds this to the total force on the object.
+ // This added force will only last the next simulation tick.
+ public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) {
+ // for an object, doesn't matter if force is a pushforce or not
+ if (force.IsFinite())
+ {
+ OMV.Vector3 addForce = force;
+ DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce);
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate()
+ {
+ // Bullet adds this central force to the total force for this tick
+ DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
+ ActivateIfPhysical(false);
+ }
+ });
+ }
+ else
+ {
+ m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
+ return;
+ }
+ }
+
+ public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
+ AddAngularForce(force, pushforce, false);
+ }
+ public void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime)
+ {
+ if (force.IsFinite())
+ {
+ OMV.Vector3 angForce = force;
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddAngularForce", delegate()
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce);
+ ActivateIfPhysical(false);
+ }
+ });
+ }
+ else
+ {
+ m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
+ return;
+ }
+ }
+
+ // A torque impulse.
+ // ApplyTorqueImpulse adds torque directly to the angularVelocity.
+ // AddAngularForce accumulates the force and applied it to the angular velocity all at once.
+ // Computed as: angularVelocity += impulse * inertia;
+ public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime)
+ {
+ OMV.Vector3 applyImpulse = impulse;
+ PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate()
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse);
+ ActivateIfPhysical(false);
+ }
+ });
+ }
+
+ public override void SetMomentum(OMV.Vector3 momentum) {
+ // DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum);
+ }
+ #region Mass Calculation
+
+ private float CalculateMass()
+ {
+ float volume = _size.X * _size.Y * _size.Z; // default
+ float tmp;
+
+ float returnMass = 0;
+ float hollowAmount = (float)BaseShape.ProfileHollow * 2.0e-5f;
+ float hollowVolume = hollowAmount * hollowAmount;
+
+ switch (BaseShape.ProfileShape)
+ {
+ case ProfileShape.Square:
+ // default box
+
+ if (BaseShape.PathCurve == (byte)Extrusion.Straight)
+ {
+ if (hollowAmount > 0.0)
+ {
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Square:
+ case HollowShape.Same:
+ break;
+
+ case HollowShape.Circle:
+
+ hollowVolume *= 0.78539816339f;
+ break;
+
+ case HollowShape.Triangle:
+
+ hollowVolume *= (0.5f * .5f);
+ break;
+
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+
+ else if (BaseShape.PathCurve == (byte)Extrusion.Curve1)
+ {
+ //a tube
+
+ volume *= 0.78539816339e-2f * (float)(200 - BaseShape.PathScaleX);
+ tmp= 1.0f -2.0e-2f * (float)(200 - BaseShape.PathScaleY);
+ volume -= volume*tmp*tmp;
+
+ if (hollowAmount > 0.0)
+ {
+ hollowVolume *= hollowAmount;
+
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Square:
+ case HollowShape.Same:
+ break;
+
+ case HollowShape.Circle:
+ hollowVolume *= 0.78539816339f;;
+ break;
+
+ case HollowShape.Triangle:
+ hollowVolume *= 0.5f * 0.5f;
+ break;
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+
+ break;
+
+ case ProfileShape.Circle:
+
+ if (BaseShape.PathCurve == (byte)Extrusion.Straight)
+ {
+ volume *= 0.78539816339f; // elipse base
+
+ if (hollowAmount > 0.0)
+ {
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Same:
+ case HollowShape.Circle:
+ break;
+
+ case HollowShape.Square:
+ hollowVolume *= 0.5f * 2.5984480504799f;
+ break;
+
+ case HollowShape.Triangle:
+ hollowVolume *= .5f * 1.27323954473516f;
+ break;
+
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+
+ else if (BaseShape.PathCurve == (byte)Extrusion.Curve1)
+ {
+ volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - BaseShape.PathScaleX);
+ tmp = 1.0f - .02f * (float)(200 - BaseShape.PathScaleY);
+ volume *= (1.0f - tmp * tmp);
+
+ if (hollowAmount > 0.0)
+ {
+
+ // calculate the hollow volume by it's shape compared to the prim shape
+ hollowVolume *= hollowAmount;
+
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Same:
+ case HollowShape.Circle:
+ break;
+
+ case HollowShape.Square:
+ hollowVolume *= 0.5f * 2.5984480504799f;
+ break;
+
+ case HollowShape.Triangle:
+ hollowVolume *= .5f * 1.27323954473516f;
+ break;
+
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+ break;
+
+ case ProfileShape.HalfCircle:
+ if (BaseShape.PathCurve == (byte)Extrusion.Curve1)
+ {
+ volume *= 0.52359877559829887307710723054658f;
+ }
+ break;
+
+ case ProfileShape.EquilateralTriangle:
+
+ if (BaseShape.PathCurve == (byte)Extrusion.Straight)
+ {
+ volume *= 0.32475953f;
+
+ if (hollowAmount > 0.0)
+ {
+
+ // calculate the hollow volume by it's shape compared to the prim shape
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Same:
+ case HollowShape.Triangle:
+ hollowVolume *= .25f;
+ break;
+
+ case HollowShape.Square:
+ hollowVolume *= 0.499849f * 3.07920140172638f;
+ break;
+
+ case HollowShape.Circle:
+ // Hollow shape is a perfect cyllinder in respect to the cube's scale
+ // Cyllinder hollow volume calculation
+
+ hollowVolume *= 0.1963495f * 3.07920140172638f;
+ break;
+
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+ else if (BaseShape.PathCurve == (byte)Extrusion.Curve1)
+ {
+ volume *= 0.32475953f;
+ volume *= 0.01f * (float)(200 - BaseShape.PathScaleX);
+ tmp = 1.0f - .02f * (float)(200 - BaseShape.PathScaleY);
+ volume *= (1.0f - tmp * tmp);
+
+ if (hollowAmount > 0.0)
+ {
+
+ hollowVolume *= hollowAmount;
+
+ switch (BaseShape.HollowShape)
+ {
+ case HollowShape.Same:
+ case HollowShape.Triangle:
+ hollowVolume *= .25f;
+ break;
+
+ case HollowShape.Square:
+ hollowVolume *= 0.499849f * 3.07920140172638f;
+ break;
+
+ case HollowShape.Circle:
+
+ hollowVolume *= 0.1963495f * 3.07920140172638f;
+ break;
+
+ default:
+ hollowVolume = 0;
+ break;
+ }
+ volume *= (1.0f - hollowVolume);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+
+
+ float taperX1;
+ float taperY1;
+ float taperX;
+ float taperY;
+ float pathBegin;
+ float pathEnd;
+ float profileBegin;
+ float profileEnd;
+
+ if (BaseShape.PathCurve == (byte)Extrusion.Straight || BaseShape.PathCurve == (byte)Extrusion.Flexible)
+ {
+ taperX1 = BaseShape.PathScaleX * 0.01f;
+ if (taperX1 > 1.0f)
+ taperX1 = 2.0f - taperX1;
+ taperX = 1.0f - taperX1;
+
+ taperY1 = BaseShape.PathScaleY * 0.01f;
+ if (taperY1 > 1.0f)
+ taperY1 = 2.0f - taperY1;
+ taperY = 1.0f - taperY1;
+ }
+ else
+ {
+ taperX = BaseShape.PathTaperX * 0.01f;
+ if (taperX < 0.0f)
+ taperX = -taperX;
+ taperX1 = 1.0f - taperX;
+
+ taperY = BaseShape.PathTaperY * 0.01f;
+ if (taperY < 0.0f)
+ taperY = -taperY;
+ taperY1 = 1.0f - taperY;
+
+ }
+
+
+ volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
+
+ pathBegin = (float)BaseShape.PathBegin * 2.0e-5f;
+ pathEnd = 1.0f - (float)BaseShape.PathEnd * 2.0e-5f;
+ volume *= (pathEnd - pathBegin);
+
+ // this is crude aproximation
+ profileBegin = (float)BaseShape.ProfileBegin * 2.0e-5f;
+ profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f;
+ volume *= (profileEnd - profileBegin);
+
+ returnMass = _density * volume;
+
+ /* Comment out code that computes the mass of the linkset. That is done in the Linkset class.
+ if (IsRootOfLinkset)
+ {
+ foreach (BSPrim prim in _childrenPrims)
+ {
+ returnMass += prim.CalculateMass();
+ }
+ }
+ */
+
+ returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass);
+
+ return returnMass;
+ }// end CalculateMass
+ #endregion Mass Calculation
+
+ // Rebuild the geometry and object.
+ // This is called when the shape changes so we need to recreate the mesh/hull.
+ // Called at taint-time!!!
+ public void CreateGeomAndObject(bool forceRebuild)
+ {
+ // If this prim is part of a linkset, we must remove and restore the physical
+ // links if the body is rebuilt.
+ bool needToRestoreLinkset = false;
+ bool needToRestoreVehicle = false;
+
+ // Create the correct physical representation for this type of object.
+ // Updates PhysBody and PhysShape with the new information.
+ // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary.
+ PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody)
+ {
+ // Called if the current prim body is about to be destroyed.
+ // Remove all the physical dependencies on the old body.
+ // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...)
+ needToRestoreLinkset = Linkset.RemoveBodyDependencies(this);
+ needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this);
+ });
+
+ if (needToRestoreLinkset)
+ {
+ // If physical body dependencies were removed, restore them
+ Linkset.RestoreBodyDependencies(this);
+ }
+ if (needToRestoreVehicle)
+ {
+ // If physical body dependencies were removed, restore them
+ _vehicle.RestoreBodyDependencies(this);
+ }
+
+ // Make sure the properties are set on the new object
+ UpdatePhysicalParameters();
+ return;
+ }
+
+ // The physics engine says that properties have updated. Update same and inform
+ // the world that things have changed.
+ // TODO: do we really need to check for changed? Maybe just copy values and call RequestPhysicsterseUpdate()
+ enum UpdatedProperties {
+ Position = 1 << 0,
+ Rotation = 1 << 1,
+ Velocity = 1 << 2,
+ Acceleration = 1 << 3,
+ RotationalVel = 1 << 4
+ }
+
+ const float ROTATION_TOLERANCE = 0.01f;
+ const float VELOCITY_TOLERANCE = 0.001f;
+ const float POSITION_TOLERANCE = 0.05f;
+ const float ACCELERATION_TOLERANCE = 0.01f;
+ const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f;
+
+ public override void UpdateProperties(EntityProperties entprop)
+ {
+ // Updates only for individual prims and for the root object of a linkset.
+ if (Linkset.IsRoot(this))
+ {
+ // A temporary kludge to suppress the rotational effects introduced on vehicles by Bullet
+ // TODO: handle physics introduced by Bullet with computed vehicle physics.
+ if (_vehicle.IsActive)
+ {
+ entprop.RotationalVelocity = OMV.Vector3.Zero;
+ }
+
+ // Assign directly to the local variables so the normal set action does not happen
+ _position = entprop.Position;
+ _orientation = entprop.Rotation;
+ _velocity = entprop.Velocity;
+ _acceleration = entprop.Acceleration;
+ _rotationalVelocity = entprop.RotationalVelocity;
+
+ // The sanity check can change the velocity and/or position.
+ if (IsPhysical && PositionSanityCheck(true))
+ {
+ entprop.Position = _position;
+ entprop.Velocity = _velocity;
+ }
+
+ OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG
+ DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}",
+ LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity);
+
+ // remember the current and last set values
+ LastEntityProperties = CurrentEntityProperties;
+ CurrentEntityProperties = entprop;
+
+ base.RequestPhysicsterseUpdate();
+ }
+ /*
+ else
+ {
+ // For debugging, report the movement of children
+ DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
+ LocalID, entprop.Position, entprop.Rotation, entprop.Velocity,
+ entprop.Acceleration, entprop.RotationalVelocity);
+ }
+ */
+
+ // The linkset implimentation might want to know about this.
+ Linkset.UpdateProperties(this, true);
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs
new file mode 100644
index 0000000..6bcea3f
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSScene.cs
@@ -0,0 +1,954 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading;
+using OpenSim.Framework;
+using OpenSim.Region.Framework;
+using OpenSim.Region.CoreModules;
+using Logging = OpenSim.Region.CoreModules.Framework.Statistics.Logging;
+using OpenSim.Region.Physics.Manager;
+using Nini.Config;
+using log4net;
+using OpenMetaverse;
+
+// TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim)
+// Based on material, set density and friction
+// More efficient memory usage when passing hull information from BSPrim to BulletSim
+// Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect
+// Implement LockAngularMotion
+// Add PID movement operations. What does ScenePresence.MoveToTarget do?
+// Check terrain size. 128 or 127?
+// Raycast
+//
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public sealed class BSScene : PhysicsScene, IPhysicsParameters
+{
+ private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly string LogHeader = "[BULLETS SCENE]";
+
+ // The name of the region we're working for.
+ public string RegionName { get; private set; }
+
+ public string BulletSimVersion = "?";
+
+ public Dictionary PhysObjects;
+ public BSShapeCollection Shapes;
+
+ // Keeping track of the objects with collisions so we can report begin and end of a collision
+ public HashSet ObjectsWithCollisions = new HashSet();
+ public HashSet ObjectsWithNoMoreCollisions = new HashSet();
+ // Keep track of all the avatars so we can send them a collision event
+ // every tick so OpenSim will update its animation.
+ private HashSet m_avatars = new HashSet();
+
+ // let my minuions use my logger
+ public ILog Logger { get { return m_log; } }
+
+ public IMesher mesher;
+ public uint WorldID { get; private set; }
+ public BulletSim World { get; private set; }
+
+ // All the constraints that have been allocated in this instance.
+ public BSConstraintCollection Constraints { get; private set; }
+
+ // Simulation parameters
+ internal int m_maxSubSteps;
+ internal float m_fixedTimeStep;
+ internal long m_simulationStep = 0;
+ public long SimulationStep { get { return m_simulationStep; } }
+ internal int m_taintsToProcessPerStep;
+ internal float LastTimeStep { get; private set; }
+
+ // Physical objects can register for prestep or poststep events
+ public delegate void PreStepAction(float timeStep);
+ public delegate void PostStepAction(float timeStep);
+ public event PreStepAction BeforeStep;
+ public event PreStepAction AfterStep;
+
+ // A value of the time now so all the collision and update routines do not have to get their own
+ // Set to 'now' just before all the prims and actors are called for collisions and updates
+ public int SimulationNowTime { get; private set; }
+
+ // True if initialized and ready to do simulation steps
+ private bool m_initialized = false;
+
+ // Flag which is true when processing taints.
+ // Not guaranteed to be correct all the time (don't depend on this) but good for debugging.
+ public bool InTaintTime { get; private set; }
+
+ // Pinned memory used to pass step information between managed and unmanaged
+ internal int m_maxCollisionsPerFrame;
+ private List m_collisionArray;
+ //private GCHandle m_collisionArrayPinnedHandle;
+
+ internal int m_maxUpdatesPerFrame;
+ private List m_updateArray;
+ //private GCHandle m_updateArrayPinnedHandle;
+
+
+ public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero
+ public const uint GROUNDPLANE_ID = 1;
+ public const uint CHILDTERRAIN_ID = 2; // Terrain allocated based on our mega-prim childre start here
+
+ public float SimpleWaterLevel { get; set; }
+ public BSTerrainManager TerrainManager { get; private set; }
+
+ public ConfigurationParameters Params
+ {
+ get { return UnmanagedParams[0]; }
+ }
+ public Vector3 DefaultGravity
+ {
+ get { return new Vector3(0f, 0f, Params.gravity); }
+ }
+ // Just the Z value of the gravity
+ public float DefaultGravityZ
+ {
+ get { return Params.gravity; }
+ }
+
+ // When functions in the unmanaged code must be called, it is only
+ // done at a known time just before the simulation step. The taint
+ // system saves all these function calls and executes them in
+ // order before the simulation.
+ public delegate void TaintCallback();
+ private struct TaintCallbackEntry
+ {
+ public String ident;
+ public TaintCallback callback;
+ public TaintCallbackEntry(string i, TaintCallback c)
+ {
+ ident = i;
+ callback = c;
+ }
+ }
+ private Object _taintLock = new Object(); // lock for using the next object
+ private List _taintOperations;
+ private Dictionary _postTaintOperations;
+ private List _postStepOperations;
+
+ // A pointer to an instance if this structure is passed to the C++ code
+ // Used to pass basic configuration values to the unmanaged code.
+ internal ConfigurationParameters[] UnmanagedParams;
+ //GCHandle m_paramsHandle;
+
+ // Handle to the callback used by the unmanaged code to call into the managed code.
+ // Used for debug logging.
+ // Need to store the handle in a persistant variable so it won't be freed.
+ private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
+
+ // Sometimes you just have to log everything.
+ public Logging.LogWriter PhysicsLogging;
+ private bool m_physicsLoggingEnabled;
+ private string m_physicsLoggingDir;
+ private string m_physicsLoggingPrefix;
+ private int m_physicsLoggingFileMinutes;
+ private bool m_physicsLoggingDoFlush;
+ // 'true' of the vehicle code is to log lots of details
+ public bool VehicleLoggingEnabled { get; private set; }
+ public bool VehiclePhysicalLoggingEnabled { get; private set; }
+
+ #region Construction and Initialization
+ public BSScene(string identifier)
+ {
+ m_initialized = false;
+ // we are passed the name of the region we're working for.
+ RegionName = identifier;
+ }
+
+ public override void Initialise(IMesher meshmerizer, IConfigSource config)
+ {
+ mesher = meshmerizer;
+ _taintOperations = new List();
+ _postTaintOperations = new Dictionary();
+ _postStepOperations = new List();
+ PhysObjects = new Dictionary();
+ Shapes = new BSShapeCollection(this);
+
+ // Allocate pinned memory to pass parameters.
+ UnmanagedParams = new ConfigurationParameters[1];
+ //m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);
+
+ // Set default values for physics parameters plus any overrides from the ini file
+ GetInitialParameterValues(config);
+
+ // allocate more pinned memory close to the above in an attempt to get the memory all together
+ m_collisionArray = new List();
+ //m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
+ m_updateArray = new List();
+ //m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);
+
+ // Enable very detailed logging.
+ // By creating an empty logger when not logging, the log message invocation code
+ // can be left in and every call doesn't have to check for null.
+ if (m_physicsLoggingEnabled)
+ {
+ PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes);
+ PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output error messages.
+ }
+ else
+ {
+ PhysicsLogging = new Logging.LogWriter();
+ }
+
+ // If Debug logging level, enable logging from the unmanaged code
+ m_DebugLogCallbackHandle = null;
+ if (m_log.IsDebugEnabled || PhysicsLogging.Enabled)
+ {
+ m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader);
+ if (PhysicsLogging.Enabled)
+ // The handle is saved in a variable to make sure it doesn't get freed after this call
+ m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog);
+ else
+ m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger);
+ }
+
+ // Get the version of the DLL
+ // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
+ // BulletSimVersion = BulletSimAPI.GetVersion();
+ // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion);
+
+ // The bounding box for the simulated world. The origin is 0,0,0 unless we're
+ // a child in a mega-region.
+ // Bullet actually doesn't care about the extents of the simulated
+ // area. It tracks active objects no matter where they are.
+ Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
+
+ // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader);
+
+ World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, UnmanagedParams,
+ m_maxCollisionsPerFrame, ref m_collisionArray,
+ m_maxUpdatesPerFrame,ref m_updateArray,
+ m_DebugLogCallbackHandle));
+
+ Constraints = new BSConstraintCollection(World);
+
+ TerrainManager = new BSTerrainManager(this);
+ TerrainManager.CreateInitialGroundPlaneAndTerrain();
+
+ m_log.WarnFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation);
+
+ InTaintTime = false;
+ m_initialized = true;
+ }
+
+ // All default parameter values are set here. There should be no values set in the
+ // variable definitions.
+ private void GetInitialParameterValues(IConfigSource config)
+ {
+ ConfigurationParameters parms = new ConfigurationParameters();
+ UnmanagedParams[0] = parms;
+
+ BSParam.SetParameterDefaultValues(this);
+
+ if (config != null)
+ {
+ // If there are specifications in the ini file, use those values
+ IConfig pConfig = config.Configs["BulletSim"];
+ if (pConfig != null)
+ {
+ BSParam.SetParameterConfigurationValues(this, pConfig);
+
+ // Very detailed logging for physics debugging
+ m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false);
+ m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", ".");
+ m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-");
+ m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5);
+ m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false);
+ // Very detailed logging for vehicle debugging
+ VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false);
+ VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false);
+
+ // Do any replacements in the parameters
+ m_physicsLoggingPrefix = m_physicsLoggingPrefix.Replace("%REGIONNAME%", RegionName);
+ }
+
+ // The material characteristics.
+ BSMaterials.InitializeFromDefaults(Params);
+ if (pConfig != null)
+ {
+ // Let the user add new and interesting material property values.
+ BSMaterials.InitializefromParameters(pConfig);
+ }
+ }
+ }
+
+ // A helper function that handles a true/false parameter and returns the proper float number encoding
+ float ParamBoolean(IConfig config, string parmName, float deflt)
+ {
+ float ret = deflt;
+ if (config.Contains(parmName))
+ {
+ ret = ConfigurationParameters.numericFalse;
+ if (config.GetBoolean(parmName, false))
+ {
+ ret = ConfigurationParameters.numericTrue;
+ }
+ }
+ return ret;
+ }
+
+ // Called directly from unmanaged code so don't do much
+ private void BulletLogger(string msg)
+ {
+ m_log.Debug("[BULLETS UNMANAGED]:" + msg);
+ }
+
+ // Called directly from unmanaged code so don't do much
+ private void BulletLoggerPhysLog(string msg)
+ {
+ DetailLog("[BULLETS UNMANAGED]:" + msg);
+ }
+
+ public override void Dispose()
+ {
+ // m_log.DebugFormat("{0}: Dispose()", LogHeader);
+
+ // make sure no stepping happens while we're deleting stuff
+ m_initialized = false;
+
+ foreach (KeyValuePair kvp in PhysObjects)
+ {
+ kvp.Value.Destroy();
+ }
+ PhysObjects.Clear();
+
+ // Now that the prims are all cleaned up, there should be no constraints left
+ if (Constraints != null)
+ {
+ Constraints.Dispose();
+ Constraints = null;
+ }
+
+ if (Shapes != null)
+ {
+ Shapes.Dispose();
+ Shapes = null;
+ }
+
+ if (TerrainManager != null)
+ {
+ TerrainManager.ReleaseGroundPlaneAndTerrain();
+ TerrainManager.Dispose();
+ TerrainManager = null;
+ }
+
+ // Anything left in the unmanaged code should be cleaned out
+ BulletSimAPI.Shutdown2(World.ptr);
+
+ // Not logging any more
+ PhysicsLogging.Close();
+ }
+ #endregion // Construction and Initialization
+
+ #region Prim and Avatar addition and removal
+
+ public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
+ {
+ m_log.ErrorFormat("{0}: CALL TO AddAvatar in BSScene. NOT IMPLEMENTED", LogHeader);
+ return null;
+ }
+
+ public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying)
+ {
+ // m_log.DebugFormat("{0}: AddAvatar: {1}", LogHeader, avName);
+
+ if (!m_initialized) return null;
+
+ BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying);
+ lock (PhysObjects) PhysObjects.Add(localID, actor);
+
+ // TODO: Remove kludge someday.
+ // We must generate a collision for avatars whether they collide or not.
+ // This is required by OpenSim to update avatar animations, etc.
+ lock (m_avatars) m_avatars.Add(actor);
+
+ return actor;
+ }
+
+ public override void RemoveAvatar(PhysicsActor actor)
+ {
+ // m_log.DebugFormat("{0}: RemoveAvatar", LogHeader);
+
+ if (!m_initialized) return;
+
+ BSCharacter bsactor = actor as BSCharacter;
+ if (bsactor != null)
+ {
+ try
+ {
+ lock (PhysObjects) PhysObjects.Remove(actor.LocalID);
+ // Remove kludge someday
+ lock (m_avatars) m_avatars.Remove(bsactor);
+ }
+ catch (Exception e)
+ {
+ m_log.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}", LogHeader, e);
+ }
+ bsactor.Destroy();
+ // bsactor.dispose();
+ }
+ }
+
+ public override void RemovePrim(PhysicsActor prim)
+ {
+ if (!m_initialized) return;
+
+ BSPrim bsprim = prim as BSPrim;
+ if (bsprim != null)
+ {
+ DetailLog("{0},RemovePrim,call", bsprim.LocalID);
+ // m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID);
+ try
+ {
+ lock (PhysObjects) PhysObjects.Remove(bsprim.LocalID);
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat("{0}: Attempt to remove prim that is not in physics scene: {1}", LogHeader, e);
+ }
+ bsprim.Destroy();
+ // bsprim.dispose();
+ }
+ else
+ {
+ m_log.ErrorFormat("{0}: Attempt to remove prim that is not a BSPrim type.", LogHeader);
+ }
+ }
+
+ public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
+ Vector3 size, Quaternion rotation, bool isPhysical, uint localID)
+ {
+ // m_log.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);
+
+ if (!m_initialized) return null;
+
+ DetailLog("{0},AddPrimShape,call", localID);
+
+ BSPrim prim = new BSPrim(localID, primName, this, position, size, rotation, pbs, isPhysical);
+ lock (PhysObjects) PhysObjects.Add(localID, prim);
+ return prim;
+ }
+
+ // This is a call from the simulator saying that some physical property has been updated.
+ // The BulletSim driver senses the changing of relevant properties so this taint
+ // information call is not needed.
+ public override void AddPhysicsActorTaint(PhysicsActor prim) { }
+
+ #endregion // Prim and Avatar addition and removal
+
+ #region Simulation
+ // Simulate one timestep
+ public override float Simulate(float timeStep)
+ {
+ // prevent simulation until we've been initialized
+ if (!m_initialized) return 5.0f;
+
+ LastTimeStep = timeStep;
+
+ int updatedEntityCount = 0;
+ //Object updatedEntitiesPtr;
+ int collidersCount = 0;
+ //Object collidersPtr;
+
+ int beforeTime = 0;
+ int simTime = 0;
+
+ // update the prim states while we know the physics engine is not busy
+ int numTaints = _taintOperations.Count;
+
+ InTaintTime = true; // Only used for debugging so locking is not necessary.
+
+ ProcessTaints();
+
+ // Some of the physical objects requre individual, pre-step calls
+ TriggerPreStepEvent(timeStep);
+
+ // the prestep actions might have added taints
+ ProcessTaints();
+
+ InTaintTime = false; // Only used for debugging so locking is not necessary.
+
+ // step the physical world one interval
+ m_simulationStep++;
+ int numSubSteps = 0;
+
+ try
+ {
+ //if (VehicleLoggingEnabled) DumpVehicles(); // DEBUG
+ if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount();
+
+ numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep,
+ out updatedEntityCount, out m_updateArray, out collidersCount, out m_collisionArray);
+
+ if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime);
+ DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}",
+ DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps,
+ updatedEntityCount, collidersCount, ObjectsWithCollisions.Count);
+ }
+ catch (Exception e)
+ {
+ m_log.WarnFormat("{0},PhysicsStep Exception: nTaints={1}, substeps={2}, updates={3}, colliders={4}, e={5}",
+ LogHeader, numTaints, numSubSteps, updatedEntityCount, collidersCount, e);
+ DetailLog("{0},PhysicsStepException,call, nTaints={1}, substeps={2}, updates={3}, colliders={4}",
+ DetailLogZero, numTaints, numSubSteps, updatedEntityCount, collidersCount);
+ updatedEntityCount = 0;
+ collidersCount = 0;
+ }
+
+ // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in.
+
+ // Get a value for 'now' so all the collision and update routines don't have to get their own.
+ SimulationNowTime = Util.EnvironmentTickCount();
+
+ // If there were collisions, process them by sending the event to the prim.
+ // Collisions must be processed before updates.
+ if (collidersCount > 0)
+ {
+ for (int ii = 0; ii < collidersCount; ii++)
+ {
+ uint cA = m_collisionArray[ii].aID;
+ uint cB = m_collisionArray[ii].bID;
+ Vector3 point = new Vector3(m_collisionArray[ii].point.X, m_collisionArray[ii].point.Y,
+ m_collisionArray[ii].point.Z);
+ Vector3 normal = new Vector3(m_collisionArray[ii].normal.X, m_collisionArray[ii].normal.Y,
+ m_collisionArray[ii].normal.Z);
+ SendCollision(cA, cB, point, normal, 0.01f);
+ SendCollision(cB, cA, point, -normal, 0.01f);
+ }
+ }
+
+ // The above SendCollision's batch up the collisions on the objects.
+ // Now push the collisions into the simulator.
+ if (ObjectsWithCollisions.Count > 0)
+ {
+ foreach (BSPhysObject bsp in ObjectsWithCollisions)
+ if (!bsp.SendCollisions())
+ {
+ // If the object is done colliding, see that it's removed from the colliding list
+ ObjectsWithNoMoreCollisions.Add(bsp);
+ }
+ }
+
+ // This is a kludge to get avatar movement updates.
+ // The simulator expects collisions for avatars even if there are have been no collisions.
+ // The event updates avatar animations and stuff.
+ // If you fix avatar animation updates, remove this overhead and let normal collision processing happen.
+ foreach (BSPhysObject bsp in m_avatars)
+ if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice
+ bsp.SendCollisions();
+
+ // Objects that are done colliding are removed from the ObjectsWithCollisions list.
+ // Not done above because it is inside an iteration of ObjectWithCollisions.
+ // This complex collision processing is required to create an empty collision
+ // event call after all collisions have happened on an object. This enables
+ // the simulator to generate the 'collision end' event.
+ if (ObjectsWithNoMoreCollisions.Count > 0)
+ {
+ foreach (BSPhysObject po in ObjectsWithNoMoreCollisions)
+ ObjectsWithCollisions.Remove(po);
+ ObjectsWithNoMoreCollisions.Clear();
+ }
+ // Done with collisions.
+
+ // If any of the objects had updated properties, tell the object it has been changed by the physics engine
+ if (updatedEntityCount > 0)
+ {
+ for (int ii = 0; ii < updatedEntityCount; ii++)
+ {
+
+ BulletXNA.EntityProperties entprop = m_updateArray[ii];
+ BSPhysObject pobj;
+ if (PhysObjects.TryGetValue(entprop.ID, out pobj))
+ {
+ EntityProperties prop = new EntityProperties()
+ {
+ Acceleration = new Vector3(entprop.Acceleration.X, entprop.Acceleration.Y, entprop.Acceleration.Z),
+ ID = entprop.ID,
+ Position = new Vector3(entprop.Position.X,entprop.Position.Y,entprop.Position.Z),
+ Rotation = new Quaternion(entprop.Rotation.X,entprop.Rotation.Y,entprop.Rotation.Z,entprop.Rotation.W),
+ RotationalVelocity = new Vector3(entprop.AngularVelocity.X,entprop.AngularVelocity.Y,entprop.AngularVelocity.Z),
+ Velocity = new Vector3(entprop.Velocity.X,entprop.Velocity.Y,entprop.Velocity.Z)
+ };
+ //m_log.Debug(pobj.Name + ":" + prop.ToString() + "\n");
+ pobj.UpdateProperties(prop);
+ }
+ }
+ }
+
+ TriggerPostStepEvent(timeStep);
+
+ // The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
+ // Only enable this in a limited test world with few objects.
+ // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG
+
+ // The physics engine returns the number of milliseconds it simulated this call.
+ // These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
+ // Multiply by 55 to give a nominal frame rate of 55.
+ return (float)numSubSteps * m_fixedTimeStep * 1000f * 55f;
+ }
+
+ // Something has collided
+ private void SendCollision(uint localID, uint collidingWith, Vector3 collidePoint, Vector3 collideNormal, float penetration)
+ {
+ if (localID <= TerrainManager.HighestTerrainID)
+ {
+ return; // don't send collisions to the terrain
+ }
+
+ BSPhysObject collider;
+ if (!PhysObjects.TryGetValue(localID, out collider))
+ {
+ // If the object that is colliding cannot be found, just ignore the collision.
+ DetailLog("{0},BSScene.SendCollision,colliderNotInObjectList,id={1},with={2}", DetailLogZero, localID, collidingWith);
+ return;
+ }
+
+ // The terrain is not in the physical object list so 'collidee' can be null when Collide() is called.
+ BSPhysObject collidee = null;
+ PhysObjects.TryGetValue(collidingWith, out collidee);
+
+ // DetailLog("{0},BSScene.SendCollision,collide,id={1},with={2}", DetailLogZero, localID, collidingWith);
+
+ if (collider.Collide(collidingWith, collidee, collidePoint, collideNormal, penetration))
+ {
+ // If a collision was posted, remember to send it to the simulator
+ ObjectsWithCollisions.Add(collider);
+ }
+
+ return;
+ }
+
+ #endregion // Simulation
+
+ public override void GetResults() { }
+
+ #region Terrain
+
+ public override void SetTerrain(float[] heightMap) {
+ TerrainManager.SetTerrain(heightMap);
+ }
+
+ public override void SetWaterLevel(float baseheight)
+ {
+ SimpleWaterLevel = baseheight;
+ }
+
+ public override void DeleteTerrain()
+ {
+ // m_log.DebugFormat("{0}: DeleteTerrain()", LogHeader);
+ }
+
+ // Although no one seems to check this, I do support combining.
+ public override bool SupportsCombining()
+ {
+ return TerrainManager.SupportsCombining();
+ }
+ // This call says I am a child to region zero in a mega-region. 'pScene' is that
+ // of region zero, 'offset' is my offset from regions zero's origin, and
+ // 'extents' is the largest XY that is handled in my region.
+ public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
+ {
+ TerrainManager.Combine(pScene, offset, extents);
+ }
+
+ // Unhook all the combining that I know about.
+ public override void UnCombine(PhysicsScene pScene)
+ {
+ TerrainManager.UnCombine(pScene);
+ }
+
+ #endregion // Terrain
+
+ public override Dictionary GetTopColliders()
+ {
+ return new Dictionary();
+ }
+
+ public override bool IsThreaded { get { return false; } }
+
+ #region Taints
+ // The simulation execution order is:
+ // Simulate()
+ // DoOneTimeTaints
+ // TriggerPreStepEvent
+ // DoOneTimeTaints
+ // Step()
+ // ProcessAndForwardCollisions
+ // ProcessAndForwardPropertyUpdates
+ // TriggerPostStepEvent
+
+ // Calls to the PhysicsActors can't directly call into the physics engine
+ // because it might be busy. We delay changes to a known time.
+ // We rely on C#'s closure to save and restore the context for the delegate.
+ public void TaintedObject(String ident, TaintCallback callback)
+ {
+ if (!m_initialized) return;
+
+ lock (_taintLock)
+ {
+ _taintOperations.Add(new TaintCallbackEntry(ident, callback));
+ }
+
+ return;
+ }
+
+ // Sometimes a potentially tainted operation can be used in and out of taint time.
+ // This routine executes the command immediately if in taint-time otherwise it is queued.
+ public void TaintedObject(bool inTaintTime, string ident, TaintCallback callback)
+ {
+ if (inTaintTime)
+ callback();
+ else
+ TaintedObject(ident, callback);
+ }
+
+ private void TriggerPreStepEvent(float timeStep)
+ {
+ PreStepAction actions = BeforeStep;
+ if (actions != null)
+ actions(timeStep);
+
+ }
+
+ private void TriggerPostStepEvent(float timeStep)
+ {
+ PreStepAction actions = AfterStep;
+ if (actions != null)
+ actions(timeStep);
+
+ }
+
+ // When someone tries to change a property on a BSPrim or BSCharacter, the object queues
+ // a callback into itself to do the actual property change. That callback is called
+ // here just before the physics engine is called to step the simulation.
+ public void ProcessTaints()
+ {
+ ProcessRegularTaints();
+ ProcessPostTaintTaints();
+ }
+
+ private void ProcessRegularTaints()
+ {
+ if (_taintOperations.Count > 0) // save allocating new list if there is nothing to process
+ {
+ // swizzle a new list into the list location so we can process what's there
+ List oldList;
+ lock (_taintLock)
+ {
+ oldList = _taintOperations;
+ _taintOperations = new List();
+ }
+
+ foreach (TaintCallbackEntry tcbe in oldList)
+ {
+ try
+ {
+ DetailLog("{0},BSScene.ProcessTaints,doTaint,id={1}", DetailLogZero, tcbe.ident); // DEBUG DEBUG DEBUG
+ tcbe.callback();
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, tcbe.ident, e);
+ }
+ }
+ oldList.Clear();
+ }
+ }
+
+ // Schedule an update to happen after all the regular taints are processed.
+ // Note that new requests for the same operation ("ident") for the same object ("ID")
+ // will replace any previous operation by the same object.
+ public void PostTaintObject(String ident, uint ID, TaintCallback callback)
+ {
+ string uniqueIdent = ident + "-" + ID.ToString();
+ lock (_taintLock)
+ {
+ _postTaintOperations[uniqueIdent] = new TaintCallbackEntry(uniqueIdent, callback);
+ }
+
+ return;
+ }
+
+ // Taints that happen after the normal taint processing but before the simulation step.
+ private void ProcessPostTaintTaints()
+ {
+ if (_postTaintOperations.Count > 0)
+ {
+ Dictionary oldList;
+ lock (_taintLock)
+ {
+ oldList = _postTaintOperations;
+ _postTaintOperations = new Dictionary();
+ }
+
+ foreach (KeyValuePair kvp in oldList)
+ {
+ try
+ {
+ DetailLog("{0},BSScene.ProcessPostTaintTaints,doTaint,id={1}", DetailLogZero, kvp.Key); // DEBUG DEBUG DEBUG
+ kvp.Value.callback();
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat("{0}: ProcessPostTaintTaints: {1}: Exception: {2}", LogHeader, kvp.Key, e);
+ }
+ }
+ oldList.Clear();
+ }
+ }
+
+ // Only used for debugging. Does not change state of anything so locking is not necessary.
+ public bool AssertInTaintTime(string whereFrom)
+ {
+ if (!InTaintTime)
+ {
+ DetailLog("{0},BSScene.AssertInTaintTime,NOT IN TAINT TIME,Region={1},Where={2}", DetailLogZero, RegionName, whereFrom);
+ m_log.ErrorFormat("{0} NOT IN TAINT TIME!! Region={1}, Where={2}", LogHeader, RegionName, whereFrom);
+ Util.PrintCallStack(); // Prints the stack into the DEBUG log file.
+ }
+ return InTaintTime;
+ }
+
+ #endregion // Taints
+
+ #region INI and command line parameter processing
+
+ #region IPhysicsParameters
+ // Get the list of parameters this physics engine supports
+ public PhysParameterEntry[] GetParameterList()
+ {
+ BSParam.BuildParameterTable();
+ return BSParam.SettableParameters;
+ }
+
+ // Set parameter on a specific or all instances.
+ // Return 'false' if not able to set the parameter.
+ // Setting the value in the m_params block will change the value the physics engine
+ // will use the next time since it's pinned and shared memory.
+ // Some of the values require calling into the physics engine to get the new
+ // value activated ('terrainFriction' for instance).
+ public bool SetPhysicsParameter(string parm, float val, uint localID)
+ {
+ bool ret = false;
+ BSParam.ParameterDefn theParam;
+ if (BSParam.TryGetParameter(parm, out theParam))
+ {
+ theParam.setter(this, parm, localID, val);
+ ret = true;
+ }
+ return ret;
+ }
+
+ // update all the localIDs specified
+ // If the local ID is APPLY_TO_NONE, just change the default value
+ // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs
+ // If the localID is a specific object, apply the parameter change to only that object
+ internal delegate void AssignVal(float x);
+ internal void UpdateParameterObject(AssignVal setDefault, string parm, uint localID, float val)
+ {
+ List objectIDs = new List();
+ switch (localID)
+ {
+ case PhysParameterEntry.APPLY_TO_NONE:
+ setDefault(val); // setting only the default value
+ // This will cause a call into the physical world if some operation is specified (SetOnObject).
+ objectIDs.Add(TERRAIN_ID);
+ TaintedUpdateParameter(parm, objectIDs, val);
+ break;
+ case PhysParameterEntry.APPLY_TO_ALL:
+ setDefault(val); // setting ALL also sets the default value
+ lock (PhysObjects) objectIDs = new List(PhysObjects.Keys);
+ TaintedUpdateParameter(parm, objectIDs, val);
+ break;
+ default:
+ // setting only one localID
+ objectIDs.Add(localID);
+ TaintedUpdateParameter(parm, objectIDs, val);
+ break;
+ }
+ }
+
+ // schedule the actual updating of the paramter to when the phys engine is not busy
+ private void TaintedUpdateParameter(string parm, List lIDs, float val)
+ {
+ float xval = val;
+ List xlIDs = lIDs;
+ string xparm = parm;
+ TaintedObject("BSScene.UpdateParameterSet", delegate() {
+ BSParam.ParameterDefn thisParam;
+ if (BSParam.TryGetParameter(xparm, out thisParam))
+ {
+ if (thisParam.onObject != null)
+ {
+ foreach (uint lID in xlIDs)
+ {
+ BSPhysObject theObject = null;
+ PhysObjects.TryGetValue(lID, out theObject);
+ thisParam.onObject(this, theObject, xval);
+ }
+ }
+ }
+ });
+ }
+
+ // Get parameter.
+ // Return 'false' if not able to get the parameter.
+ public bool GetPhysicsParameter(string parm, out float value)
+ {
+ float val = 0f;
+ bool ret = false;
+ BSParam.ParameterDefn theParam;
+ if (BSParam.TryGetParameter(parm, out theParam))
+ {
+ val = theParam.getter(this);
+ ret = true;
+ }
+ value = val;
+ return ret;
+ }
+
+ #endregion IPhysicsParameters
+
+ #endregion Runtime settable parameters
+
+ // Invoke the detailed logger and output something if it's enabled.
+ public void DetailLog(string msg, params Object[] args)
+ {
+ PhysicsLogging.Write(msg, args);
+ // Add the Flush() if debugging crashes. Gets all the messages written out.
+ if (m_physicsLoggingDoFlush) PhysicsLogging.Flush();
+ }
+ // Used to fill in the LocalID when there isn't one. It's the correct number of characters.
+ public const string DetailLogZero = "0000000000";
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs
new file mode 100644
index 0000000..398ece0
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSShapeCollection.cs
@@ -0,0 +1,1015 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OMV = OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+using OpenSim.Region.Physics.ConvexDecompositionDotNet;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public sealed class BSShapeCollection : IDisposable
+{
+ private static string LogHeader = "[BULLETSIM SHAPE COLLECTION]";
+
+ private BSScene PhysicsScene { get; set; }
+
+ private Object m_collectionActivityLock = new Object();
+
+ // Description of a Mesh
+ private struct MeshDesc
+ {
+ public Object ptr;
+ public int referenceCount;
+ public DateTime lastReferenced;
+ public UInt64 shapeKey;
+ }
+
+ // Description of a hull.
+ // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations.
+ private struct HullDesc
+ {
+ public Object ptr;
+ public int referenceCount;
+ public DateTime lastReferenced;
+ public UInt64 shapeKey;
+ }
+
+ // The sharable set of meshes and hulls. Indexed by their shape hash.
+ private Dictionary Meshes = new Dictionary();
+ private Dictionary Hulls = new Dictionary();
+
+ private bool DDetail = false;
+
+ public BSShapeCollection(BSScene physScene)
+ {
+ PhysicsScene = physScene;
+ // Set the next to 'true' for very detailed shape update detailed logging (detailed details?)
+ // While detailed debugging is still active, this is better than commenting out all the
+ // DetailLog statements. When debugging slows down, this and the protected logging
+ // statements can be commented/removed.
+ DDetail = true;
+ }
+
+ public void Dispose()
+ {
+ // TODO!!!!!!!!!
+ }
+
+ // Callbacks called just before either the body or shape is destroyed.
+ // Mostly used for changing bodies out from under Linksets.
+ // Useful for other cases where parameters need saving.
+ // Passing 'null' says no callback.
+ public delegate void ShapeDestructionCallback(BulletShape shape);
+ public delegate void BodyDestructionCallback(BulletBody body);
+
+ // Called to update/change the body and shape for an object.
+ // First checks the shape and updates that if necessary then makes
+ // sure the body is of the right type.
+ // Return 'true' if either the body or the shape changed.
+ // 'shapeCallback' and 'bodyCallback' are, if non-null, functions called just before
+ // the current shape or body is destroyed. This allows the caller to remove any
+ // higher level dependencies on the shape or body. Mostly used for LinkSets to
+ // remove the physical constraints before the body is destroyed.
+ // Called at taint-time!!
+ public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim,
+ ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback)
+ {
+ PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape");
+
+ bool ret = false;
+
+ // This lock could probably be pushed down lower but building shouldn't take long
+ lock (m_collectionActivityLock)
+ {
+ // Do we have the correct geometry for this type of object?
+ // Updates prim.BSShape with information/pointers to shape.
+ // Returns 'true' of BSShape is changed to a new shape.
+ bool newGeom = CreateGeom(forceRebuild, prim, shapeCallback);
+ // If we had to select a new shape geometry for the object,
+ // rebuild the body around it.
+ // Updates prim.BSBody with information/pointers to requested body
+ // Returns 'true' if BSBody was changed.
+ bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World,
+ prim.PhysShape, bodyCallback);
+ ret = newGeom || newBody;
+ }
+ DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}",
+ prim.LocalID, forceRebuild, ret, prim.PhysBody, prim.PhysShape);
+
+ return ret;
+ }
+
+ public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim)
+ {
+ return GetBodyAndShape(forceRebuild, sim, prim, null, null);
+ }
+
+ // Track another user of a body.
+ // We presume the caller has allocated the body.
+ // Bodies only have one user so the body is just put into the world if not already there.
+ public void ReferenceBody(BulletBody body, bool inTaintTime)
+ {
+ lock (m_collectionActivityLock)
+ {
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body);
+ PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate()
+ {
+ if (!BulletSimAPI.IsInWorld2(PhysicsScene.World.ptr, body.ptr))
+ {
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr);
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
+ }
+ });
+ }
+ }
+
+ // Release the usage of a body.
+ // Called when releasing use of a BSBody. BSShape is handled separately.
+ public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback )
+ {
+ if (!body.HasPhysicalBody)
+ return;
+
+ lock (m_collectionActivityLock)
+ {
+ PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate()
+ {
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}",
+ body.ID, body, inTaintTime);
+ // If the caller needs to know the old body is going away, pass the event up.
+ if (bodyCallback != null) bodyCallback(body);
+
+ if (BulletSimAPI.IsInWorld2(PhysicsScene.World.ptr, body.ptr))
+ {
+ BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr);
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
+ }
+
+ // Zero any reference to the shape so it is not freed when the body is deleted.
+ BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, null);
+ BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr);
+ });
+ }
+ }
+
+ // Track the datastructures and use count for a shape.
+ // When creating a hull, this is called first to reference the mesh
+ // and then again to reference the hull.
+ // Meshes and hulls for the same shape have the same hash key.
+ // NOTE that native shapes are not added to the mesh list or removed.
+ // Returns 'true' if this is the initial reference to the shape. Otherwise reused.
+ public bool ReferenceShape(BulletShape shape)
+ {
+ bool ret = false;
+ switch (shape.type)
+ {
+ case BSPhysicsShapeType.SHAPE_MESH:
+ MeshDesc meshDesc;
+ if (Meshes.TryGetValue(shape.shapeKey, out meshDesc))
+ {
+ // There is an existing instance of this mesh.
+ meshDesc.referenceCount++;
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingMesh,key={1},cnt={2}",
+ BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount);
+ }
+ else
+ {
+ // This is a new reference to a mesh
+ meshDesc.ptr = shape.ptr;
+ meshDesc.shapeKey = shape.shapeKey;
+ // We keep a reference to the underlying IMesh data so a hull can be built
+ meshDesc.referenceCount = 1;
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}",
+ BSScene.DetailLogZero, shape.shapeKey.ToString("X"), meshDesc.referenceCount);
+ ret = true;
+ }
+ meshDesc.lastReferenced = System.DateTime.Now;
+ Meshes[shape.shapeKey] = meshDesc;
+ break;
+ case BSPhysicsShapeType.SHAPE_HULL:
+ HullDesc hullDesc;
+ if (Hulls.TryGetValue(shape.shapeKey, out hullDesc))
+ {
+ // There is an existing instance of this hull.
+ hullDesc.referenceCount++;
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,existingHull,key={1},cnt={2}",
+ BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount);
+ }
+ else
+ {
+ // This is a new reference to a hull
+ hullDesc.ptr = shape.ptr;
+ hullDesc.shapeKey = shape.shapeKey;
+ hullDesc.referenceCount = 1;
+ if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
+ BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount);
+ ret = true;
+
+ }
+ hullDesc.lastReferenced = System.DateTime.Now;
+ Hulls[shape.shapeKey] = hullDesc;
+ break;
+ case BSPhysicsShapeType.SHAPE_UNKNOWN:
+ break;
+ default:
+ // Native shapes are not tracked and they don't go into any list
+ break;
+ }
+ return ret;
+ }
+
+ // Release the usage of a shape.
+ public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback)
+ {
+ if (!shape.HasPhysicalShape)
+ return;
+
+ PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate()
+ {
+ if (shape.HasPhysicalShape)
+ {
+ if (shape.isNativeShape)
+ {
+ // Native shapes are not tracked and are released immediately
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}",
+ BSScene.DetailLogZero, shape.ptr.ToString(), inTaintTime);
+ if (shapeCallback != null) shapeCallback(shape);
+ BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr);
+ }
+ else
+ {
+ switch (shape.type)
+ {
+ case BSPhysicsShapeType.SHAPE_HULL:
+ DereferenceHull(shape, shapeCallback);
+ break;
+ case BSPhysicsShapeType.SHAPE_MESH:
+ DereferenceMesh(shape, shapeCallback);
+ break;
+ case BSPhysicsShapeType.SHAPE_COMPOUND:
+ DereferenceCompound(shape, shapeCallback);
+ break;
+ case BSPhysicsShapeType.SHAPE_UNKNOWN:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ });
+ }
+
+ // Count down the reference count for a mesh shape
+ // Called at taint-time.
+ private void DereferenceMesh(BulletShape shape, ShapeDestructionCallback shapeCallback)
+ {
+ MeshDesc meshDesc;
+ if (Meshes.TryGetValue(shape.shapeKey, out meshDesc))
+ {
+ meshDesc.referenceCount--;
+ // TODO: release the Bullet storage
+ if (shapeCallback != null) shapeCallback(shape);
+ meshDesc.lastReferenced = System.DateTime.Now;
+ Meshes[shape.shapeKey] = meshDesc;
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceMesh,shape={1},refCnt={2}",
+ BSScene.DetailLogZero, shape, meshDesc.referenceCount);
+
+ }
+ }
+
+ // Count down the reference count for a hull shape
+ // Called at taint-time.
+ private void DereferenceHull(BulletShape shape, ShapeDestructionCallback shapeCallback)
+ {
+ HullDesc hullDesc;
+ if (Hulls.TryGetValue(shape.shapeKey, out hullDesc))
+ {
+ hullDesc.referenceCount--;
+ // TODO: release the Bullet storage (aging old entries?)
+
+ // Tell upper layers that, if they have dependencies on this shape, this link is going away
+ if (shapeCallback != null) shapeCallback(shape);
+
+ hullDesc.lastReferenced = System.DateTime.Now;
+ Hulls[shape.shapeKey] = hullDesc;
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceHull,shape={1},refCnt={2}",
+ BSScene.DetailLogZero, shape, hullDesc.referenceCount);
+ }
+ }
+
+ // Remove a reference to a compound shape.
+ // Taking a compound shape apart is a little tricky because if you just delete the
+ // physical shape, it will free all the underlying children. We can't do that because
+ // they could be shared. So, this removes each of the children from the compound and
+ // dereferences them separately before destroying the compound collision object itself.
+ // Called at taint-time.
+ private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback)
+ {
+ if (!BulletSimAPI.IsCompound2(shape.ptr))
+ {
+ // Failed the sanity check!!
+ PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
+ LogHeader, shape.type, shape.ptr.ToString());
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}",
+ BSScene.DetailLogZero, shape.type, shape.ptr.ToString());
+ return;
+ }
+
+ int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr);
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren);
+
+ for (int ii = numChildren - 1; ii >= 0; ii--)
+ {
+ Object childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii);
+ DereferenceAnonCollisionShape(childShape);
+ }
+ BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr);
+ }
+
+ // Sometimes we have a pointer to a collision shape but don't know what type it is.
+ // Figure out type and call the correct dereference routine.
+ // Called at taint-time.
+ private void DereferenceAnonCollisionShape(Object cShape)
+ {
+ MeshDesc meshDesc;
+ HullDesc hullDesc;
+
+ BulletShape shapeInfo = new BulletShape(cShape);
+ if (TryGetMeshByPtr(cShape, out meshDesc))
+ {
+ shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH;
+ shapeInfo.shapeKey = meshDesc.shapeKey;
+ }
+ else
+ {
+ if (TryGetHullByPtr(cShape, out hullDesc))
+ {
+ shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL;
+ shapeInfo.shapeKey = hullDesc.shapeKey;
+ }
+ else
+ {
+ if (BulletSimAPI.IsCompound2(cShape))
+ {
+ shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND;
+ }
+ else
+ {
+ if (BulletSimAPI.IsNativeShape2(cShape))
+ {
+ shapeInfo.isNativeShape = true;
+ shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
+ }
+ }
+ }
+ }
+
+ if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo);
+
+ if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN)
+ {
+ DereferenceShape(shapeInfo, true, null);
+ }
+ else
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
+ LogHeader, PhysicsScene.RegionName, cShape.ToString());
+ }
+ }
+
+ // Create the geometry information in Bullet for later use.
+ // The objects needs a hull if it's physical otherwise a mesh is enough.
+ // if 'forceRebuild' is true, the geometry is unconditionally rebuilt. For meshes and hulls,
+ // shared geometries will be used. If the parameters of the existing shape are the same
+ // as this request, the shape is not rebuilt.
+ // Info in prim.BSShape is updated to the new shape.
+ // Returns 'true' if the geometry was rebuilt.
+ // Called at taint-time!
+ private bool CreateGeom(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+ bool ret = false;
+ bool haveShape = false;
+
+ if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE)
+ {
+ // an avatar capsule is close to a native shape (it is not shared)
+ GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE,
+ FixedShapeKey.KEY_CAPSULE, shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape);
+ ret = true;
+ haveShape = true;
+ }
+
+ // Compound shapes are handled special as they are rebuilt from scratch.
+ // This isn't too great a hardship since most of the child shapes will have already been created.
+ if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND)
+ {
+ ret = GetReferenceToCompoundShape(prim, shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, prim.PhysShape);
+ haveShape = true;
+ }
+
+ if (!haveShape)
+ {
+ ret = CreateGeomNonSpecial(forceRebuild, prim, shapeCallback);
+ }
+
+ return ret;
+ }
+
+ // Create a mesh/hull shape or a native shape if 'nativeShapePossible' is 'true'.
+ public bool CreateGeomNonSpecial(bool forceRebuild, BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+ bool ret = false;
+ bool haveShape = false;
+ bool nativeShapePossible = true;
+ PrimitiveBaseShape pbs = prim.BaseShape;
+
+ // If the prim attributes are simple, this could be a simple Bullet native shape
+ if (!haveShape
+ && pbs != null
+ && nativeShapePossible
+ && ((pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim)
+ || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
+ && pbs.ProfileHollow == 0
+ && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
+ && pbs.PathBegin == 0 && pbs.PathEnd == 0
+ && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
+ && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
+ && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) )
+ {
+ // Get the scale of any existing shape so we can see if the new shape is same native type and same size.
+ OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
+ if (prim.PhysShape.HasPhysicalShape)
+ scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr);
+
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}",
+ prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type);
+
+ // It doesn't look like Bullet scales spheres so make sure the scales are all equal
+ if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1)
+ && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z)
+ {
+ haveShape = true;
+ if (forceRebuild
+ || prim.Scale != scaleOfExistingShape
+ || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE
+ )
+ {
+ ret = GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_SPHERE,
+ FixedShapeKey.KEY_SPHERE, shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},shape={2}",
+ prim.LocalID, forceRebuild, prim.PhysShape);
+ }
+ }
+ if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
+ {
+ haveShape = true;
+ if (forceRebuild
+ || prim.Scale != scaleOfExistingShape
+ || prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX
+ )
+ {
+ ret = GetReferenceToNativeShape( prim, BSPhysicsShapeType.SHAPE_BOX,
+ FixedShapeKey.KEY_BOX, shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},shape={2}",
+ prim.LocalID, forceRebuild, prim.PhysShape);
+ }
+ }
+ }
+
+ // If a simple shape is not happening, create a mesh and possibly a hull.
+ if (!haveShape && pbs != null)
+ {
+ ret = CreateGeomMeshOrHull(prim, shapeCallback);
+ }
+
+ return ret;
+ }
+
+ public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+
+ bool ret = false;
+ // Note that if it's a native shape, the check for physical/non-physical is not
+ // made. Native shapes work in either case.
+ if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects)
+ {
+ // Update prim.BSShape to reference a hull of this shape.
+ ret = GetReferenceToHull(prim,shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}",
+ prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X"));
+ }
+ else
+ {
+ ret = GetReferenceToMesh(prim, shapeCallback);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,mesh,shape={1},key={2}",
+ prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X"));
+ }
+ return ret;
+ }
+
+ // Creates a native shape and assignes it to prim.BSShape.
+ // "Native" shapes are never shared. they are created here and destroyed in DereferenceShape().
+ private bool GetReferenceToNativeShape(BSPhysObject prim,
+ BSPhysicsShapeType shapeType, FixedShapeKey shapeKey,
+ ShapeDestructionCallback shapeCallback)
+ {
+ // release any previous shape
+ DereferenceShape(prim.PhysShape, true, shapeCallback);
+
+ BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey);
+
+ // Don't need to do a 'ReferenceShape()' here because native shapes are not shared.
+ if (DDetail) DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1},scale={2}",
+ prim.LocalID, newShape, prim.Scale);
+
+ // native shapes are scaled by Bullet
+ prim.PhysShape = newShape;
+ return true;
+ }
+
+ private BulletShape BuildPhysicalNativeShape(BSPhysObject prim, BSPhysicsShapeType shapeType,
+ FixedShapeKey shapeKey)
+ {
+ BulletShape newShape;
+ // Need to make sure the passed shape information is for the native type.
+ ShapeData nativeShapeData = new ShapeData();
+ nativeShapeData.Type = shapeType;
+ nativeShapeData.ID = prim.LocalID;
+ nativeShapeData.Scale = prim.Scale;
+ nativeShapeData.Size = prim.Scale; // unneeded, I think.
+ nativeShapeData.MeshKey = (ulong)shapeKey;
+ nativeShapeData.HullKey = (ulong)shapeKey;
+
+ if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
+ {
+ // The proper scale has been calculated in the prim.
+ newShape = new BulletShape(
+ BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale)
+ , shapeType);
+ if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
+ }
+ else
+ {
+ // Native shapes are scaled in Bullet so set the scaling to the size
+ newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType);
+ }
+ if (!newShape.HasPhysicalShape)
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
+ LogHeader, prim.LocalID, shapeType);
+ }
+ newShape.shapeKey = (System.UInt64)shapeKey;
+ newShape.isNativeShape = true;
+
+ return newShape;
+ }
+
+ // Builds a mesh shape in the physical world and updates prim.BSShape.
+ // Dereferences previous shape in BSShape and adds a reference for this new shape.
+ // Returns 'true' of a mesh was actually built. Otherwise .
+ // Called at taint-time!
+ private bool GetReferenceToMesh(BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+ BulletShape newShape = new BulletShape();
+
+ float lod;
+ System.UInt64 newMeshKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
+
+ // if this new shape is the same as last time, don't recreate the mesh
+ if (newMeshKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_MESH)
+ return false;
+
+ if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToMesh,create,oldKey={1},newKey={2}",
+ prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X"));
+
+ // Since we're recreating new, get rid of the reference to the previous shape
+ DereferenceShape(prim.PhysShape, true, shapeCallback);
+
+ newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, prim.BaseShape, prim.Size, lod);
+ // Take evasive action if the mesh was not constructed.
+ newShape = VerifyMeshCreated(newShape, prim);
+
+ ReferenceShape(newShape);
+
+ prim.PhysShape = newShape;
+
+ return true; // 'true' means a new shape has been added to this prim
+ }
+
+ private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
+ {
+ IMesh meshData = null;
+ Object meshPtr = null;
+ MeshDesc meshDesc;
+ if (Meshes.TryGetValue(newMeshKey, out meshDesc))
+ {
+ // If the mesh has already been built just use it.
+ meshPtr = meshDesc.ptr;
+ }
+ else
+ {
+ meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false);
+
+ if (meshData != null)
+ {
+ int[] indices = meshData.getIndexListAsInt();
+ List vertices = meshData.getVertexList();
+
+ float[] verticesAsFloats = new float[vertices.Count * 3];
+ int vi = 0;
+ foreach (OMV.Vector3 vv in vertices)
+ {
+ verticesAsFloats[vi++] = vv.X;
+ verticesAsFloats[vi++] = vv.Y;
+ verticesAsFloats[vi++] = vv.Z;
+ }
+
+ // m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
+ // LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count);
+
+ meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr,
+ indices.GetLength(0), indices, vertices.Count, verticesAsFloats);
+ }
+ }
+ BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH);
+ newShape.shapeKey = newMeshKey;
+
+ return newShape;
+ }
+
+ // See that hull shape exists in the physical world and update prim.BSShape.
+ // We could be creating the hull because scale changed or whatever.
+ private bool GetReferenceToHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+ BulletShape newShape;
+
+ float lod;
+ System.UInt64 newHullKey = ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
+
+ // if the hull hasn't changed, don't rebuild it
+ if (newHullKey == prim.PhysShape.shapeKey && prim.PhysShape.type == BSPhysicsShapeType.SHAPE_HULL)
+ return false;
+
+ if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToHull,create,oldKey={1},newKey={2}",
+ prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X"));
+
+ // Remove usage of the previous shape.
+ DereferenceShape(prim.PhysShape, true, shapeCallback);
+
+ newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod);
+ newShape = VerifyMeshCreated(newShape, prim);
+
+ ReferenceShape(newShape);
+
+ prim.PhysShape = newShape;
+ return true; // 'true' means a new shape has been added to this prim
+ }
+
+ List m_hulls;
+ private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
+ {
+
+ Object hullPtr = null;
+ HullDesc hullDesc;
+ if (Hulls.TryGetValue(newHullKey, out hullDesc))
+ {
+ // If the hull shape already is created, just use it.
+ hullPtr = hullDesc.ptr;
+ }
+ else
+ {
+ // Build a new hull in the physical world
+ // Pass true for physicalness as this creates some sort of bounding box which we don't need
+ IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false);
+ if (meshData != null)
+ {
+
+ int[] indices = meshData.getIndexListAsInt();
+ List vertices = meshData.getVertexList();
+
+ //format conversion from IMesh format to DecompDesc format
+ List convIndices = new List();
+ List convVertices = new List();
+ for (int ii = 0; ii < indices.GetLength(0); ii++)
+ {
+ convIndices.Add(indices[ii]);
+ }
+ foreach (OMV.Vector3 vv in vertices)
+ {
+ convVertices.Add(new float3(vv.X, vv.Y, vv.Z));
+ }
+
+ // setup and do convex hull conversion
+ m_hulls = new List();
+ DecompDesc dcomp = new DecompDesc();
+ dcomp.mIndices = convIndices;
+ dcomp.mVertices = convVertices;
+ ConvexBuilder convexBuilder = new ConvexBuilder(HullReturn);
+ // create the hull into the _hulls variable
+ convexBuilder.process(dcomp);
+
+ // Convert the vertices and indices for passing to unmanaged.
+ // The hull information is passed as a large floating point array.
+ // The format is:
+ // convHulls[0] = number of hulls
+ // convHulls[1] = number of vertices in first hull
+ // convHulls[2] = hull centroid X coordinate
+ // convHulls[3] = hull centroid Y coordinate
+ // convHulls[4] = hull centroid Z coordinate
+ // convHulls[5] = first hull vertex X
+ // convHulls[6] = first hull vertex Y
+ // convHulls[7] = first hull vertex Z
+ // convHulls[8] = second hull vertex X
+ // ...
+ // convHulls[n] = number of vertices in second hull
+ // convHulls[n+1] = second hull centroid X coordinate
+ // ...
+ //
+ // TODO: is is very inefficient. Someday change the convex hull generator to return
+ // data structures that do not need to be converted in order to pass to Bullet.
+ // And maybe put the values directly into pinned memory rather than marshaling.
+ int hullCount = m_hulls.Count;
+ int totalVertices = 1; // include one for the count of the hulls
+ foreach (ConvexResult cr in m_hulls)
+ {
+ totalVertices += 4; // add four for the vertex count and centroid
+ totalVertices += cr.HullIndices.Count * 3; // we pass just triangles
+ }
+ float[] convHulls = new float[totalVertices];
+
+ convHulls[0] = (float)hullCount;
+ int jj = 1;
+ foreach (ConvexResult cr in m_hulls)
+ {
+ // copy vertices for index access
+ float3[] verts = new float3[cr.HullVertices.Count];
+ int kk = 0;
+ foreach (float3 ff in cr.HullVertices)
+ {
+ verts[kk++] = ff;
+ }
+
+ // add to the array one hull's worth of data
+ convHulls[jj++] = cr.HullIndices.Count;
+ convHulls[jj++] = 0f; // centroid x,y,z
+ convHulls[jj++] = 0f;
+ convHulls[jj++] = 0f;
+ foreach (int ind in cr.HullIndices)
+ {
+ convHulls[jj++] = verts[ind].x;
+ convHulls[jj++] = verts[ind].y;
+ convHulls[jj++] = verts[ind].z;
+ }
+ }
+ // create the hull data structure in Bullet
+ hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls);
+ }
+ }
+
+ BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL);
+ newShape.shapeKey = newHullKey;
+
+ return newShape;
+ }
+
+ // Callback from convex hull creater with a newly created hull.
+ // Just add it to our collection of hulls for this shape.
+ private void HullReturn(ConvexResult result)
+ {
+ m_hulls.Add(result);
+ return;
+ }
+
+ // Compound shapes are always built from scratch.
+ // This shouldn't be to bad since most of the parts will be meshes that had been built previously.
+ private bool GetReferenceToCompoundShape(BSPhysObject prim, ShapeDestructionCallback shapeCallback)
+ {
+ // Remove reference to the old shape
+ // Don't need to do this as the shape is freed when the new root shape is created below.
+ // DereferenceShape(prim.PhysShape, true, shapeCallback);
+
+ BulletShape cShape = new BulletShape(
+ BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND);
+
+ // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
+ CreateGeomMeshOrHull(prim, shapeCallback);
+ BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity);
+ if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}",
+ prim.LocalID, cShape, prim.PhysShape);
+
+ prim.PhysShape = cShape;
+
+ return true;
+ }
+
+ // Create a hash of all the shape parameters to be used as a key
+ // for this particular shape.
+ private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod)
+ {
+ // level of detail based on size and type of the object
+ float lod = BSParam.MeshLOD;
+ if (pbs.SculptEntry)
+ lod = BSParam.SculptLOD;
+
+ // Mega prims usually get more detail because one can interact with shape approximations at this size.
+ float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z));
+ if (maxAxis > BSParam.MeshMegaPrimThreshold)
+ lod = BSParam.MeshMegaPrimLOD;
+
+ retLod = lod;
+ return pbs.GetMeshKey(size, lod);
+ }
+ // For those who don't want the LOD
+ private System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs)
+ {
+ float lod;
+ return ComputeShapeKey(size, pbs, out lod);
+ }
+
+ // The creation of a mesh or hull can fail if an underlying asset is not available.
+ // There are two cases: 1) the asset is not in the cache and it needs to be fetched;
+ // and 2) the asset cannot be converted (like failed decompression of JPEG2000s).
+ // The first case causes the asset to be fetched. The second case requires
+ // us to not loop forever.
+ // Called after creating a physical mesh or hull. If the physical shape was created,
+ // just return.
+ private BulletShape VerifyMeshCreated(BulletShape newShape, BSPhysObject prim)
+ {
+ // If the shape was successfully created, nothing more to do
+ if (newShape.HasPhysicalShape)
+ return newShape;
+
+ // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset
+ if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero)
+ {
+ prim.LastAssetBuildFailed = true;
+ BSPhysObject xprim = prim;
+ DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lID={1},lastFailed={2}",
+ LogHeader, prim.LocalID, prim.LastAssetBuildFailed);
+ Util.FireAndForget(delegate
+ {
+ RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod;
+ if (assetProvider != null)
+ {
+ BSPhysObject yprim = xprim; // probably not necessary, but, just in case.
+ assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset)
+ {
+ if (!yprim.BaseShape.SculptEntry)
+ return;
+ if (yprim.BaseShape.SculptTexture.ToString() != asset.ID)
+ return;
+
+ yprim.BaseShape.SculptData = asset.Data;
+ // This will cause the prim to see that the filler shape is not the right
+ // one and try again to build the object.
+ // No race condition with the normal shape setting since the rebuild is at taint time.
+ yprim.ForceBodyShapeRebuild(false);
+
+ });
+ }
+ });
+ }
+ else
+ {
+ if (prim.LastAssetBuildFailed)
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}",
+ LogHeader, prim.LocalID, prim.BaseShape.SculptTexture);
+ }
+ }
+
+ // While we figure out the real problem, stick a simple native shape on the object.
+ BulletShape fillinShape =
+ BuildPhysicalNativeShape(prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
+
+ return fillinShape;
+ }
+
+ // Create a body object in Bullet.
+ // Updates prim.BSBody with the information about the new body if one is created.
+ // Returns 'true' if an object was actually created.
+ // Called at taint-time.
+ private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletSim sim, BulletShape shape,
+ BodyDestructionCallback bodyCallback)
+ {
+ bool ret = false;
+
+ // the mesh, hull or native shape must have already been created in Bullet
+ bool mustRebuild = !prim.PhysBody.HasPhysicalBody;
+
+ // If there is an existing body, verify it's of an acceptable type.
+ // If not a solid object, body is a GhostObject. Otherwise a RigidBody.
+ if (!mustRebuild)
+ {
+ CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr);
+ if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY
+ || !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
+ {
+ // If the collisionObject is not the correct type for solidness, rebuild what's there
+ mustRebuild = true;
+ }
+ }
+
+ if (mustRebuild || forceRebuild)
+ {
+ // Free any old body
+ DereferenceBody(prim.PhysBody, true, bodyCallback);
+
+ BulletBody aBody;
+ Object bodyPtr = null;
+ if (prim.IsSolid)
+ {
+ bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr,
+ prim.LocalID, prim.RawPosition, prim.RawOrientation);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString());
+ }
+ else
+ {
+ bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr,
+ prim.LocalID, prim.RawPosition, prim.RawOrientation);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString());
+ }
+ aBody = new BulletBody(prim.LocalID, bodyPtr);
+
+ ReferenceBody(aBody, true);
+
+ prim.PhysBody = aBody;
+
+ ret = true;
+ }
+
+ return ret;
+ }
+
+ private bool TryGetMeshByPtr(Object addr, out MeshDesc outDesc)
+ {
+ bool ret = false;
+ MeshDesc foundDesc = new MeshDesc();
+ foreach (MeshDesc md in Meshes.Values)
+ {
+ if (md.ptr == addr)
+ {
+ foundDesc = md;
+ ret = true;
+ break;
+ }
+
+ }
+ outDesc = foundDesc;
+ return ret;
+ }
+
+ private bool TryGetHullByPtr(Object addr, out HullDesc outDesc)
+ {
+ bool ret = false;
+ HullDesc foundDesc = new HullDesc();
+ foreach (HullDesc hd in Hulls.Values)
+ {
+ if (hd.ptr == addr)
+ {
+ foundDesc = hd;
+ ret = true;
+ break;
+ }
+
+ }
+ outDesc = foundDesc;
+ return ret;
+ }
+
+ private void DetailLog(string msg, params Object[] args)
+ {
+ if (PhysicsScene.PhysicsLogging.Enabled)
+ PhysicsScene.DetailLog(msg, args);
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSShapes.cs
new file mode 100644
index 0000000..8ff0275
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSShapes.cs
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public abstract class BSShape
+{
+ public Object ptr { get; set; }
+ public BSPhysicsShapeType type { get; set; }
+ public System.UInt64 key { get; set; }
+ public int referenceCount { get; set; }
+ public DateTime lastReferenced { get; set; }
+
+ public BSShape()
+ {
+ ptr = null;
+ type = BSPhysicsShapeType.SHAPE_UNKNOWN;
+ key = 0;
+ referenceCount = 0;
+ lastReferenced = DateTime.Now;
+ }
+
+ // Get a reference to a physical shape. Create if it doesn't exist
+ public static BSShape GetShapeReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
+ {
+ BSShape ret = null;
+
+ if (prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE)
+ {
+ // an avatar capsule is close to a native shape (it is not shared)
+ ret = BSShapeNative.GetReference(physicsScene, prim, BSPhysicsShapeType.SHAPE_CAPSULE,
+ FixedShapeKey.KEY_CAPSULE);
+ physicsScene.DetailLog("{0},BSShape.GetShapeReference,avatarCapsule,shape={1}", prim.LocalID, ret);
+ }
+
+ // Compound shapes are handled special as they are rebuilt from scratch.
+ // This isn't too great a hardship since most of the child shapes will already been created.
+ if (ret == null && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_COMPOUND)
+ {
+ // Getting a reference to a compound shape gets you the compound shape with the root prim shape added
+ ret = BSShapeCompound.GetReference(prim);
+ physicsScene.DetailLog("{0},BSShapeCollection.CreateGeom,compoundShape,shape={1}", prim.LocalID, ret);
+ }
+
+ if (ret == null)
+ ret = GetShapeReferenceNonSpecial(physicsScene, forceRebuild, prim);
+
+ return ret;
+ }
+ public static BSShape GetShapeReferenceNonSpecial(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
+ {
+ return null;
+ }
+ public static BSShape GetShapeReferenceNonNative(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
+ {
+ return null;
+ }
+
+ // Release the use of a physical shape.
+ public abstract void Dereference(BSScene physicsScene);
+
+ // All shapes have a static call to get a reference to the physical shape
+ // protected abstract static BSShape GetReference();
+
+ public override string ToString()
+ {
+ StringBuilder buff = new StringBuilder();
+ buff.Append("");
+ return buff.ToString();
+ }
+}
+
+public class BSShapeNull : BSShape
+{
+ public BSShapeNull() : base()
+ {
+ }
+ public static BSShape GetReference() { return new BSShapeNull(); }
+ public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ }
+}
+
+public class BSShapeNative : BSShape
+{
+ private static string LogHeader = "[BULLETSIM SHAPE NATIVE]";
+ public BSShapeNative() : base()
+ {
+ }
+ public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim,
+ BSPhysicsShapeType shapeType, FixedShapeKey shapeKey)
+ {
+ // Native shapes are not shared and are always built anew.
+ return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
+ }
+
+ private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
+ BSPhysicsShapeType shapeType, FixedShapeKey shapeKey)
+ {
+ ShapeData nativeShapeData = new ShapeData();
+ nativeShapeData.Type = shapeType;
+ nativeShapeData.ID = prim.LocalID;
+ nativeShapeData.Scale = prim.Scale;
+ nativeShapeData.Size = prim.Scale;
+ nativeShapeData.MeshKey = (ulong)shapeKey;
+ nativeShapeData.HullKey = (ulong)shapeKey;
+
+
+ if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
+ {
+ ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
+ physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
+ }
+ else
+ {
+ ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData);
+ }
+ if (ptr == null)
+ {
+ physicsScene.Logger.ErrorFormat("{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
+ LogHeader, prim.LocalID, shapeType);
+ }
+ type = shapeType;
+ key = (UInt64)shapeKey;
+ }
+ // Make this reference to the physical shape go away since native shapes are not shared.
+ public override void Dereference(BSScene physicsScene)
+ {
+ // Native shapes are not tracked and are released immediately
+ physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
+ BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
+ ptr = null;
+ // Garbage collection will free up this instance.
+ }
+}
+
+public class BSShapeMesh : BSShape
+{
+ private static string LogHeader = "[BULLETSIM SHAPE MESH]";
+ private static Dictionary Meshes = new Dictionary();
+
+ public BSShapeMesh() : base()
+ {
+ }
+ public static BSShape GetReference() { return new BSShapeNull(); }
+ public override void Dereference(BSScene physicsScene) { }
+}
+
+public class BSShapeHull : BSShape
+{
+ private static string LogHeader = "[BULLETSIM SHAPE HULL]";
+ private static Dictionary Hulls = new Dictionary();
+
+ public BSShapeHull() : base()
+ {
+ }
+ public static BSShape GetReference() { return new BSShapeNull(); }
+ public override void Dereference(BSScene physicsScene) { }
+}
+
+public class BSShapeCompound : BSShape
+{
+ private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]";
+ public BSShapeCompound() : base()
+ {
+ }
+ public static BSShape GetReference(BSPhysObject prim)
+ {
+ return new BSShapeNull();
+ }
+ public override void Dereference(BSScene physicsScene) { }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs
new file mode 100644
index 0000000..252953b
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainHeightmap.cs
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Framework;
+using OpenSim.Region.Framework;
+using OpenSim.Region.CoreModules;
+using OpenSim.Region.Physics.Manager;
+
+using Nini.Config;
+using log4net;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public sealed class BSTerrainHeightmap : BSTerrainPhys
+{
+ static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]";
+
+ BulletHeightMapInfo m_mapInfo = null;
+
+ // Constructor to build a default, flat heightmap terrain.
+ public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize)
+ : base(physicsScene, regionBase, id)
+ {
+ Vector3 minTerrainCoords = new Vector3(0f, 0f, BSTerrainManager.HEIGHT_INITIALIZATION - BSTerrainManager.HEIGHT_EQUAL_FUDGE);
+ Vector3 maxTerrainCoords = new Vector3(regionSize.X, regionSize.Y, BSTerrainManager.HEIGHT_INITIALIZATION);
+ int totalHeights = (int)maxTerrainCoords.X * (int)maxTerrainCoords.Y;
+ float[] initialMap = new float[totalHeights];
+ for (int ii = 0; ii < totalHeights; ii++)
+ {
+ initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
+ }
+ m_mapInfo = new BulletHeightMapInfo(id, initialMap, null);
+ m_mapInfo.minCoords = minTerrainCoords;
+ m_mapInfo.maxCoords = maxTerrainCoords;
+ m_mapInfo.terrainRegionBase = TerrainBase;
+ // Don't have to free any previous since we just got here.
+ BuildHeightmapTerrain();
+ }
+
+ // This minCoords and maxCoords passed in give the size of the terrain (min and max Z
+ // are the high and low points of the heightmap).
+ public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap,
+ Vector3 minCoords, Vector3 maxCoords)
+ : base(physicsScene, regionBase, id)
+ {
+ m_mapInfo = new BulletHeightMapInfo(id, initialMap, null);
+ m_mapInfo.minCoords = minCoords;
+ m_mapInfo.maxCoords = maxCoords;
+ m_mapInfo.minZ = minCoords.Z;
+ m_mapInfo.maxZ = maxCoords.Z;
+ m_mapInfo.terrainRegionBase = TerrainBase;
+
+ // Don't have to free any previous since we just got here.
+ BuildHeightmapTerrain();
+ }
+
+ public override void Dispose()
+ {
+ ReleaseHeightMapTerrain();
+ }
+
+ // Using the information in m_mapInfo, create the physical representation of the heightmap.
+ private void BuildHeightmapTerrain()
+ {
+ m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID,
+ m_mapInfo.minCoords, m_mapInfo.maxCoords,
+ m_mapInfo.heightMap, BSParam.TerrainCollisionMargin);
+
+ // Create the terrain shape from the mapInfo
+ m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr),
+ BSPhysicsShapeType.SHAPE_TERRAIN);
+
+ // The terrain object initial position is at the center of the object
+ Vector3 centerPos;
+ centerPos.X = m_mapInfo.minCoords.X + (m_mapInfo.sizeX / 2f);
+ centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f);
+ centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f + 0.5f);
+
+ m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID,
+ BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr,
+ m_mapInfo.ID, centerPos, Quaternion.Identity));
+
+ // Set current terrain attributes
+ BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction);
+ BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainHitFraction);
+ BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, BSParam.TerrainRestitution);
+ BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+
+ // Return the new terrain to the world of physical objects
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr, centerPos, Quaternion.Identity);
+
+ // redo its bounding box now that it is in the world
+ BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+
+ m_mapInfo.terrainBody.collisionType = CollisionType.Terrain;
+ m_mapInfo.terrainBody.ApplyCollisionMask();
+
+ // Make it so the terrain will not move or be considered for movement.
+ BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION);
+
+ return;
+ }
+
+ // If there is information in m_mapInfo pointing to physical structures, release same.
+ private void ReleaseHeightMapTerrain()
+ {
+ if (m_mapInfo != null)
+ {
+ if (m_mapInfo.terrainBody.HasPhysicalBody)
+ {
+ BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ // Frees both the body and the shape.
+ BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr);
+ }
+ }
+ m_mapInfo = null;
+ }
+
+ // The passed position is relative to the base of the region.
+ public override float GetTerrainHeightAtXYZ(Vector3 pos)
+ {
+ float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
+
+ int mapIndex = (int)pos.Y * (int)m_mapInfo.sizeY + (int)pos.X;
+ try
+ {
+ ret = m_mapInfo.heightMap[mapIndex];
+ }
+ catch
+ {
+ // Sometimes they give us wonky values of X and Y. Give a warning and return something.
+ PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}",
+ LogHeader, m_mapInfo.terrainRegionBase, pos);
+ ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
+ }
+ return ret;
+ }
+
+ // The passed position is relative to the base of the region.
+ public override float GetWaterLevelAtXYZ(Vector3 pos)
+ {
+ return PhysicsScene.SimpleWaterLevel;
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs
new file mode 100644
index 0000000..dfad70e
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainManager.cs
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Framework;
+using OpenSim.Region.Framework;
+using OpenSim.Region.CoreModules;
+using OpenSim.Region.Physics.Manager;
+
+using Nini.Config;
+using log4net;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+
+// The physical implementation of the terrain is wrapped in this class.
+public abstract class BSTerrainPhys : IDisposable
+{
+ public enum TerrainImplementation
+ {
+ Heightmap = 0,
+ Mesh = 1
+ }
+
+ public BSScene PhysicsScene { get; private set; }
+ // Base of the region in world coordinates. Coordinates inside the region are relative to this.
+ public Vector3 TerrainBase { get; private set; }
+ public uint ID { get; private set; }
+
+ public BSTerrainPhys(BSScene physicsScene, Vector3 regionBase, uint id)
+ {
+ PhysicsScene = physicsScene;
+ TerrainBase = regionBase;
+ ID = id;
+ }
+ public abstract void Dispose();
+ public abstract float GetTerrainHeightAtXYZ(Vector3 pos);
+ public abstract float GetWaterLevelAtXYZ(Vector3 pos);
+}
+
+// ==========================================================================================
+public sealed class BSTerrainManager : IDisposable
+{
+ static string LogHeader = "[BULLETSIM TERRAIN MANAGER]";
+
+ // These height values are fractional so the odd values will be
+ // noticable when debugging.
+ public const float HEIGHT_INITIALIZATION = 24.987f;
+ public const float HEIGHT_INITIAL_LASTHEIGHT = 24.876f;
+ public const float HEIGHT_GETHEIGHT_RET = 24.765f;
+ public const float WATER_HEIGHT_GETHEIGHT_RET = 19.998f;
+
+ // If the min and max height are equal, we reduce the min by this
+ // amount to make sure that a bounding box is built for the terrain.
+ public const float HEIGHT_EQUAL_FUDGE = 0.2f;
+
+ // Until the whole simulator is changed to pass us the region size, we rely on constants.
+ public Vector3 DefaultRegionSize = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
+
+ // The scene that I am part of
+ private BSScene PhysicsScene { get; set; }
+
+ // The ground plane created to keep thing from falling to infinity.
+ private BulletBody m_groundPlane;
+
+ // If doing mega-regions, if we're region zero we will be managing multiple
+ // region terrains since region zero does the physics for the whole mega-region.
+ private Dictionary m_terrains;
+
+ // Flags used to know when to recalculate the height.
+ private bool m_terrainModified = false;
+
+ // If we are doing mega-regions, terrains are added from TERRAIN_ID to m_terrainCount.
+ // This is incremented before assigning to new region so it is the last ID allocated.
+ private uint m_terrainCount = BSScene.CHILDTERRAIN_ID - 1;
+ public uint HighestTerrainID { get {return m_terrainCount; } }
+
+ // If doing mega-regions, this holds our offset from region zero of
+ // the mega-regions. "parentScene" points to the PhysicsScene of region zero.
+ private Vector3 m_worldOffset;
+ // If the parent region (region 0), this is the extent of the combined regions
+ // relative to the origin of region zero
+ private Vector3 m_worldMax;
+ private PhysicsScene MegaRegionParentPhysicsScene { get; set; }
+
+ public BSTerrainManager(BSScene physicsScene)
+ {
+ PhysicsScene = physicsScene;
+ m_terrains = new Dictionary();
+
+ // Assume one region of default size
+ m_worldOffset = Vector3.Zero;
+ m_worldMax = new Vector3(DefaultRegionSize);
+ MegaRegionParentPhysicsScene = null;
+ }
+
+ public void Dispose()
+ {
+ ReleaseGroundPlaneAndTerrain();
+ }
+
+ // Create the initial instance of terrain and the underlying ground plane.
+ // This is called from the initialization routine so we presume it is
+ // safe to call Bullet in real time. We hope no one is moving prims around yet.
+ public void CreateInitialGroundPlaneAndTerrain()
+ {
+ // The ground plane is here to catch things that are trying to drop to negative infinity
+ BulletShape groundPlaneShape = new BulletShape(
+ BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f,
+ BSParam.TerrainCollisionMargin),
+ BSPhysicsShapeType.SHAPE_GROUNDPLANE);
+ m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID,
+ BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID,
+ Vector3.Zero, Quaternion.Identity));
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr);
+ BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr);
+ // Ground plane does not move
+ BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION);
+ // Everything collides with the ground plane.
+ m_groundPlane.collisionType = CollisionType.Groundplane;
+ m_groundPlane.ApplyCollisionMask();
+
+ // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
+ BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);
+ m_terrains.Add(Vector3.Zero, initialTerrain);
+ }
+
+ // Release all the terrain structures we might have allocated
+ public void ReleaseGroundPlaneAndTerrain()
+ {
+ if (m_groundPlane.HasPhysicalBody)
+ {
+ if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr))
+ {
+ BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr);
+ }
+ m_groundPlane.Clear();
+ }
+
+ ReleaseTerrain();
+ }
+
+ // Release all the terrain we have allocated
+ public void ReleaseTerrain()
+ {
+ lock (m_terrains)
+ {
+ foreach (KeyValuePair kvp in m_terrains)
+ {
+ kvp.Value.Dispose();
+ }
+ m_terrains.Clear();
+ }
+ }
+
+ // The simulator wants to set a new heightmap for the terrain.
+ public void SetTerrain(float[] heightMap) {
+ float[] localHeightMap = heightMap;
+ // If there are multiple requests for changes to the same terrain between ticks,
+ // only do that last one.
+ PhysicsScene.PostTaintObject("TerrainManager.SetTerrain-"+ m_worldOffset.ToString(), 0, delegate()
+ {
+ if (m_worldOffset != Vector3.Zero && MegaRegionParentPhysicsScene != null)
+ {
+ // If a child of a mega-region, we shouldn't have any terrain allocated for us
+ ReleaseGroundPlaneAndTerrain();
+ // If doing the mega-prim stuff and we are the child of the zero region,
+ // the terrain is added to our parent
+ if (MegaRegionParentPhysicsScene is BSScene)
+ {
+ DetailLog("{0},SetTerrain.ToParent,offset={1},worldMax={2}",
+ BSScene.DetailLogZero, m_worldOffset, m_worldMax);
+ ((BSScene)MegaRegionParentPhysicsScene).TerrainManager.UpdateTerrain(
+ BSScene.CHILDTERRAIN_ID, localHeightMap,
+ m_worldOffset, m_worldOffset + DefaultRegionSize, true);
+ }
+ }
+ else
+ {
+ // If not doing the mega-prim thing, just change the terrain
+ DetailLog("{0},SetTerrain.Existing", BSScene.DetailLogZero);
+
+ UpdateTerrain(BSScene.TERRAIN_ID, localHeightMap,
+ m_worldOffset, m_worldOffset + DefaultRegionSize, true);
+ }
+ });
+ }
+
+ // If called with no mapInfo for the terrain, this will create a new mapInfo and terrain
+ // based on the passed information. The 'id' should be either the terrain id or
+ // BSScene.CHILDTERRAIN_ID. If the latter, a new child terrain ID will be allocated and used.
+ // The latter feature is for creating child terrains for mega-regions.
+ // If called with a mapInfo in m_heightMaps and there is an existing terrain body, a new
+ // terrain shape is created and added to the body.
+ // This call is most often used to update the heightMap and parameters of the terrain.
+ // (The above does suggest that some simplification/refactoring is in order.)
+ // Called during taint-time.
+ private void UpdateTerrain(uint id, float[] heightMap,
+ Vector3 minCoords, Vector3 maxCoords, bool inTaintTime)
+ {
+ DetailLog("{0},BSTerrainManager.UpdateTerrain,call,minC={1},maxC={2},inTaintTime={3}",
+ BSScene.DetailLogZero, minCoords, maxCoords, inTaintTime);
+
+ // Find high and low points of passed heightmap.
+ // The min and max passed in is usually the area objects can be in (maximum
+ // object height, for instance). The terrain wants the bounding box for the
+ // terrain so replace passed min and max Z with the actual terrain min/max Z.
+ float minZ = float.MaxValue;
+ float maxZ = float.MinValue;
+ foreach (float height in heightMap)
+ {
+ if (height < minZ) minZ = height;
+ if (height > maxZ) maxZ = height;
+ }
+ if (minZ == maxZ)
+ {
+ // If min and max are the same, reduce min a little bit so a good bounding box is created.
+ minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE;
+ }
+ minCoords.Z = minZ;
+ maxCoords.Z = maxZ;
+
+ Vector3 terrainRegionBase = new Vector3(minCoords.X, minCoords.Y, 0f);
+
+ lock (m_terrains)
+ {
+ BSTerrainPhys terrainPhys;
+ if (m_terrains.TryGetValue(terrainRegionBase, out terrainPhys))
+ {
+ // There is already a terrain in this spot. Free the old and build the new.
+ DetailLog("{0},UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}",
+ BSScene.DetailLogZero, id, terrainRegionBase, minCoords, minCoords);
+
+ // Remove old terrain from the collection
+ m_terrains.Remove(terrainRegionBase);
+ // Release any physical memory it may be using.
+ terrainPhys.Dispose();
+
+ if (MegaRegionParentPhysicsScene == null)
+ {
+ BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords);
+ m_terrains.Add(terrainRegionBase, newTerrainPhys);
+
+ m_terrainModified = true;
+ }
+ else
+ {
+ // It's possible that Combine() was called after this code was queued.
+ // If we are a child of combined regions, we don't create any terrain for us.
+ DetailLog("{0},BSTerrainManager.UpdateTerrain:AmACombineChild,taint", BSScene.DetailLogZero);
+
+ // Get rid of any terrain that may have been allocated for us.
+ ReleaseGroundPlaneAndTerrain();
+
+ // I hate doing this, but just bail
+ return;
+ }
+ }
+ else
+ {
+ // We don't know about this terrain so either we are creating a new terrain or
+ // our mega-prim child is giving us a new terrain to add to the phys world
+
+ // if this is a child terrain, calculate a unique terrain id
+ uint newTerrainID = id;
+ if (newTerrainID >= BSScene.CHILDTERRAIN_ID)
+ newTerrainID = ++m_terrainCount;
+
+ DetailLog("{0},UpdateTerrain:NewTerrain,taint,newID={1},minCoord={2},maxCoord={3}",
+ BSScene.DetailLogZero, newTerrainID, minCoords, minCoords);
+ BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords);
+ m_terrains.Add(terrainRegionBase, newTerrainPhys);
+
+ m_terrainModified = true;
+ }
+ }
+ }
+
+ // TODO: redo terrain implementation selection to allow other base types than heightMap.
+ private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords)
+ {
+ PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}",
+ LogHeader, PhysicsScene.RegionName, terrainRegionBase,
+ (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
+ BSTerrainPhys newTerrainPhys = null;
+ switch ((int)BSParam.TerrainImplementation)
+ {
+ case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
+ newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id,
+ heightMap, minCoords, maxCoords);
+ break;
+ case (int)BSTerrainPhys.TerrainImplementation.Mesh:
+ newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id,
+ heightMap, minCoords, maxCoords);
+ break;
+ default:
+ PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}",
+ LogHeader,
+ (int)BSParam.TerrainImplementation,
+ BSParam.TerrainImplementation,
+ PhysicsScene.RegionName, terrainRegionBase);
+ break;
+ }
+ return newTerrainPhys;
+ }
+
+ // Return 'true' of this position is somewhere in known physical terrain space
+ public bool IsWithinKnownTerrain(Vector3 pos)
+ {
+ Vector3 terrainBaseXYZ;
+ BSTerrainPhys physTerrain;
+ return GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ);
+ }
+
+ // Given an X and Y, find the height of the terrain.
+ // Since we could be handling multiple terrains for a mega-region,
+ // the base of the region is calcuated assuming all regions are
+ // the same size and that is the default.
+ // Once the heightMapInfo is found, we have all the information to
+ // compute the offset into the array.
+ private float lastHeightTX = 999999f;
+ private float lastHeightTY = 999999f;
+ private float lastHeight = HEIGHT_INITIAL_LASTHEIGHT;
+ public float GetTerrainHeightAtXYZ(Vector3 pos)
+ {
+ float tX = pos.X;
+ float tY = pos.Y;
+ // You'd be surprized at the number of times this routine is called
+ // with the same parameters as last time.
+ if (!m_terrainModified && (lastHeightTX == tX) && (lastHeightTY == tY))
+ return lastHeight;
+ m_terrainModified = false;
+
+ lastHeightTX = tX;
+ lastHeightTY = tY;
+ float ret = HEIGHT_GETHEIGHT_RET;
+
+ Vector3 terrainBaseXYZ;
+ BSTerrainPhys physTerrain;
+ if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ))
+ {
+ ret = physTerrain.GetTerrainHeightAtXYZ(pos - terrainBaseXYZ);
+ }
+ else
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} GetTerrainHeightAtXY: terrain not found: region={1}, x={2}, y={3}",
+ LogHeader, PhysicsScene.RegionName, tX, tY);
+ DetailLog("{0},BSTerrainManager.GetTerrainHeightAtXYZ,terrainNotFound,pos={1},base={2}",
+ BSScene.DetailLogZero, pos, terrainBaseXYZ);
+ }
+ lastHeight = ret;
+ return ret;
+ }
+
+ public float GetWaterLevelAtXYZ(Vector3 pos)
+ {
+ float ret = WATER_HEIGHT_GETHEIGHT_RET;
+
+ Vector3 terrainBaseXYZ;
+ BSTerrainPhys physTerrain;
+ if (GetTerrainPhysicalAtXYZ(pos, out physTerrain, out terrainBaseXYZ))
+ {
+ ret = physTerrain.GetWaterLevelAtXYZ(pos);
+ }
+ else
+ {
+ PhysicsScene.Logger.ErrorFormat("{0} GetWaterHeightAtXY: terrain not found: pos={1}, terrainBase={2}, height={3}",
+ LogHeader, PhysicsScene.RegionName, pos, terrainBaseXYZ, ret);
+ }
+ return ret;
+ }
+
+ // Given an address, return 'true' of there is a description of that terrain and output
+ // the descriptor class and the 'base' fo the addresses therein.
+ private bool GetTerrainPhysicalAtXYZ(Vector3 pos, out BSTerrainPhys outPhysTerrain, out Vector3 outTerrainBase)
+ {
+ int offsetX = ((int)(pos.X / (int)DefaultRegionSize.X)) * (int)DefaultRegionSize.X;
+ int offsetY = ((int)(pos.Y / (int)DefaultRegionSize.Y)) * (int)DefaultRegionSize.Y;
+ Vector3 terrainBaseXYZ = new Vector3(offsetX, offsetY, 0f);
+
+ BSTerrainPhys physTerrain = null;
+ lock (m_terrains)
+ {
+ m_terrains.TryGetValue(terrainBaseXYZ, out physTerrain);
+ }
+ outTerrainBase = terrainBaseXYZ;
+ outPhysTerrain = physTerrain;
+ return (physTerrain != null);
+ }
+
+ // Although no one seems to check this, I do support combining.
+ public bool SupportsCombining()
+ {
+ return true;
+ }
+
+ // This routine is called two ways:
+ // One with 'offset' and 'pScene' zero and null but 'extents' giving the maximum
+ // extent of the combined regions. This is to inform the parent of the size
+ // of the combined regions.
+ // and one with 'offset' as the offset of the child region to the base region,
+ // 'pScene' pointing to the parent and 'extents' of zero. This informs the
+ // child of its relative base and new parent.
+ public void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
+ {
+ m_worldOffset = offset;
+ m_worldMax = extents;
+ MegaRegionParentPhysicsScene = pScene;
+ if (pScene != null)
+ {
+ // We are a child.
+ // We want m_worldMax to be the highest coordinate of our piece of terrain.
+ m_worldMax = offset + DefaultRegionSize;
+ }
+ DetailLog("{0},BSTerrainManager.Combine,offset={1},extents={2},wOffset={3},wMax={4}",
+ BSScene.DetailLogZero, offset, extents, m_worldOffset, m_worldMax);
+ }
+
+ // Unhook all the combining that I know about.
+ public void UnCombine(PhysicsScene pScene)
+ {
+ // Just like ODE, we don't do anything yet.
+ DetailLog("{0},BSTerrainManager.UnCombine", BSScene.DetailLogZero);
+ }
+
+
+ private void DetailLog(string msg, params Object[] args)
+ {
+ PhysicsScene.PhysicsLogging.Write(msg, args);
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainMesh.cs
new file mode 100644
index 0000000..6083dd4
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSTerrainMesh.cs
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Framework;
+using OpenSim.Region.Framework;
+using OpenSim.Region.CoreModules;
+using OpenSim.Region.Physics.Manager;
+
+using Nini.Config;
+using log4net;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+public sealed class BSTerrainMesh : BSTerrainPhys
+{
+ static string LogHeader = "[BULLETSIM TERRAIN MESH]";
+
+ private float[] m_savedHeightMap;
+ int m_sizeX;
+ int m_sizeY;
+
+ BulletShape m_terrainShape;
+ BulletBody m_terrainBody;
+
+ public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize)
+ : base(physicsScene, regionBase, id)
+ {
+ }
+
+ public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id /* parameters for making mesh */)
+ : base(physicsScene, regionBase, id)
+ {
+ }
+
+ // Create terrain mesh from a heightmap.
+ public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap,
+ Vector3 minCoords, Vector3 maxCoords)
+ : base(physicsScene, regionBase, id)
+ {
+ int indicesCount;
+ int[] indices;
+ int verticesCount;
+ float[] vertices;
+
+ m_savedHeightMap = initialMap;
+
+ m_sizeX = (int)(maxCoords.X - minCoords.X);
+ m_sizeY = (int)(maxCoords.Y - minCoords.Y);
+
+ if (!BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene, initialMap,
+ m_sizeX, m_sizeY,
+ (float)m_sizeX, (float)m_sizeY,
+ Vector3.Zero, 1.0f,
+ out indicesCount, out indices, out verticesCount, out vertices))
+ {
+ // DISASTER!!
+ PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap", ID);
+ PhysicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader, TerrainBase);
+ // Something is very messed up and a crash is in our future.
+ return;
+ }
+ PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}",
+ ID, indicesCount, indices.Length, verticesCount, vertices.Length);
+
+ m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr,
+ indicesCount, indices, verticesCount, vertices),
+ BSPhysicsShapeType.SHAPE_MESH);
+ if (!m_terrainShape.HasPhysicalShape)
+ {
+ // DISASTER!!
+ PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape", ID);
+ physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase);
+ // Something is very messed up and a crash is in our future.
+ return;
+ }
+
+ Vector3 pos = regionBase;
+ Quaternion rot = Quaternion.Identity;
+
+ m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot));
+ if (!m_terrainBody.HasPhysicalBody)
+ {
+ // DISASTER!!
+ physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase);
+ // Something is very messed up and a crash is in our future.
+ return;
+ }
+
+ // Set current terrain attributes
+ BulletSimAPI.SetFriction2(m_terrainBody.ptr, BSParam.TerrainFriction);
+ BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, BSParam.TerrainHitFraction);
+ BulletSimAPI.SetRestitution2(m_terrainBody.ptr, BSParam.TerrainRestitution);
+ BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+
+ // Static objects are not very massive.
+ BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero);
+
+ // Put the new terrain to the world of physical objects
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr, pos, rot);
+
+ // Redo its bounding box now that it is in the world
+ BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+
+ m_terrainBody.collisionType = CollisionType.Terrain;
+ m_terrainBody.ApplyCollisionMask();
+
+ // Make it so the terrain will not move or be considered for movement.
+ BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION);
+ }
+
+ public override void Dispose()
+ {
+ if (m_terrainBody.HasPhysicalBody)
+ {
+ BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ // Frees both the body and the shape.
+ BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ }
+ }
+
+ public override float GetTerrainHeightAtXYZ(Vector3 pos)
+ {
+ // For the moment use the saved heightmap to get the terrain height.
+ // TODO: raycast downward to find the true terrain below the position.
+ float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
+
+ int mapIndex = (int)pos.Y * m_sizeY + (int)pos.X;
+ try
+ {
+ ret = m_savedHeightMap[mapIndex];
+ }
+ catch
+ {
+ // Sometimes they give us wonky values of X and Y. Give a warning and return something.
+ PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}",
+ LogHeader, TerrainBase, pos);
+ ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET;
+ }
+ return ret;
+ }
+
+ // The passed position is relative to the base of the region.
+ public override float GetWaterLevelAtXYZ(Vector3 pos)
+ {
+ return PhysicsScene.SimpleWaterLevel;
+ }
+
+ // Convert the passed heightmap to mesh information suitable for CreateMeshShape2().
+ // Return 'true' if successfully created.
+ public static bool ConvertHeightmapToMesh(
+ BSScene physicsScene,
+ float[] heightMap, int sizeX, int sizeY, // parameters of incoming heightmap
+ float extentX, float extentY, // zero based range for output vertices
+ Vector3 extentBase, // base to be added to all vertices
+ float magnification, // number of vertices to create between heightMap coords
+ out int indicesCountO, out int[] indicesO,
+ out int verticesCountO, out float[] verticesO)
+ {
+ bool ret = false;
+
+ int indicesCount = 0;
+ int verticesCount = 0;
+ int[] indices = new int[0];
+ float[] vertices = new float[0];
+
+ // Simple mesh creation which assumes magnification == 1.
+ // TODO: do a more general solution that scales, adds new vertices and smoothes the result.
+
+ // Create an array of vertices that is sizeX+1 by sizeY+1 (note the loop
+ // from zero to <= sizeX). The triangle indices are then generated as two triangles
+ // per heightmap point. There are sizeX by sizeY of these squares. The extra row and
+ // column of vertices are used to complete the triangles of the last row and column
+ // of the heightmap.
+ try
+ {
+ // One vertice per heightmap value plus the vertices off the top and bottom edge.
+ int totalVertices = (sizeX + 1) * (sizeY + 1);
+ vertices = new float[totalVertices * 3];
+ int totalIndices = sizeX * sizeY * 6;
+ indices = new int[totalIndices];
+
+ float magX = (float)sizeX / extentX;
+ float magY = (float)sizeY / extentY;
+ physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}",
+ BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY);
+ float minHeight = float.MaxValue;
+ // Note that sizeX+1 vertices are created since there is land between this and the next region.
+ for (int yy = 0; yy <= sizeY; yy++)
+ {
+ for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we go around sizeX + 1 times
+ {
+ int offset = yy * sizeX + xx;
+ // Extend the height with the height from the last row or column
+ if (yy == sizeY) offset -= sizeX;
+ if (xx == sizeX) offset -= 1;
+ float height = heightMap[offset];
+ minHeight = Math.Min(minHeight, height);
+ vertices[verticesCount + 0] = (float)xx * magX + extentBase.X;
+ vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y;
+ vertices[verticesCount + 2] = height + extentBase.Z;
+ verticesCount += 3;
+ }
+ }
+ verticesCount = verticesCount / 3;
+
+ for (int yy = 0; yy < sizeY; yy++)
+ {
+ for (int xx = 0; xx < sizeX; xx++)
+ {
+ int offset = yy * (sizeX + 1) + xx;
+ // Each vertices is presumed to be the upper left corner of a box of two triangles
+ indices[indicesCount + 0] = offset;
+ indices[indicesCount + 1] = offset + 1;
+ indices[indicesCount + 2] = offset + sizeX + 1; // accounting for the extra column
+ indices[indicesCount + 3] = offset + 1;
+ indices[indicesCount + 4] = offset + sizeX + 2;
+ indices[indicesCount + 5] = offset + sizeX + 1;
+ indicesCount += 6;
+ }
+ }
+
+ ret = true;
+ }
+ catch (Exception e)
+ {
+ physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh. For={1}/{2}, e={3}",
+ LogHeader, physicsScene.RegionName, extentBase, e);
+ }
+
+ indicesCountO = indicesCount;
+ indicesO = indices;
+ verticesCountO = verticesCount;
+ verticesO = vertices;
+
+ return ret;
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs
new file mode 100644
index 0000000..6af59d6
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimAPI.cs
@@ -0,0 +1,1604 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Text;
+using BulletXNA;
+using OpenMetaverse;
+using BulletXNA.LinearMath;
+using BulletXNA.BulletCollision;
+using BulletXNA.BulletDynamics;
+using BulletXNA.BulletCollision.CollisionDispatch;
+using OpenSim.Framework;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin {
+
+// Classes to allow some type checking for the API
+// These hold pointers to allocated objects in the unmanaged space.
+
+
+
+ // Constraint type values as defined by Bullet
+public enum ConstraintType : int
+{
+ POINT2POINT_CONSTRAINT_TYPE = 3,
+ HINGE_CONSTRAINT_TYPE,
+ CONETWIST_CONSTRAINT_TYPE,
+ D6_CONSTRAINT_TYPE,
+ SLIDER_CONSTRAINT_TYPE,
+ CONTACT_CONSTRAINT_TYPE,
+ D6_SPRING_CONSTRAINT_TYPE,
+ MAX_CONSTRAINT_TYPE
+}
+
+
+// ===============================================================================
+[StructLayout(LayoutKind.Sequential)]
+public struct ConvexHull
+{
+ Vector3 Offset;
+ int VertexCount;
+ Vector3[] Vertices;
+}
+public enum BSPhysicsShapeType
+{
+ SHAPE_UNKNOWN = 0,
+ SHAPE_CAPSULE = 1,
+ SHAPE_BOX = 2,
+ SHAPE_CONE = 3,
+ SHAPE_CYLINDER = 4,
+ SHAPE_SPHERE = 5,
+ SHAPE_MESH = 6,
+ SHAPE_HULL = 7,
+ // following defined by BulletSim
+ SHAPE_GROUNDPLANE = 20,
+ SHAPE_TERRAIN = 21,
+ SHAPE_COMPOUND = 22,
+ SHAPE_HEIGHTMAP = 23,
+};
+
+// The native shapes have predefined shape hash keys
+public enum FixedShapeKey : ulong
+{
+ KEY_NONE = 0,
+ KEY_BOX = 1,
+ KEY_SPHERE = 2,
+ KEY_CONE = 3,
+ KEY_CYLINDER = 4,
+ KEY_CAPSULE = 5,
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct ShapeData
+{
+ public uint ID;
+ public BSPhysicsShapeType Type;
+ public Vector3 Position;
+ public Quaternion Rotation;
+ public Vector3 Velocity;
+ public Vector3 Scale;
+ public float Mass;
+ public float Buoyancy;
+ public System.UInt64 HullKey;
+ public System.UInt64 MeshKey;
+ public float Friction;
+ public float Restitution;
+ public float Collidable; // true of things bump into this
+ public float Static; // true if a static object. Otherwise gravity, etc.
+ public float Solid; // true if object cannot be passed through
+ public Vector3 Size;
+
+ // note that bools are passed as floats since bool size changes by language and architecture
+ public const float numericTrue = 1f;
+ public const float numericFalse = 0f;
+}
+[StructLayout(LayoutKind.Sequential)]
+public struct SweepHit
+{
+ public uint ID;
+ public float Fraction;
+ public Vector3 Normal;
+ public Vector3 Point;
+}
+[StructLayout(LayoutKind.Sequential)]
+public struct RaycastHit
+{
+ public uint ID;
+ public float Fraction;
+ public Vector3 Normal;
+}
+[StructLayout(LayoutKind.Sequential)]
+public struct CollisionDesc
+{
+ public uint aID;
+ public uint bID;
+ public Vector3 point;
+ public Vector3 normal;
+}
+[StructLayout(LayoutKind.Sequential)]
+public struct EntityProperties
+{
+ public uint ID;
+ public Vector3 Position;
+ public Quaternion Rotation;
+ public Vector3 Velocity;
+ public Vector3 Acceleration;
+ public Vector3 RotationalVelocity;
+ public override string ToString()
+ {
+ return string.Format("ID:{0}, Pos:<{1:F},{2:F},{3:F}>, Rot:<{4:F},{5:F},{6:F},{7:F}>, LVel:<{8:F},{9:F},{10:F}>, AVel:<{11:F},{12:F},{13:F}>",
+ ID.ToString(),
+ Position.X,Position.Y,Position.Z,
+ Rotation.X,Rotation.Y,Rotation.Z,Rotation.W,
+ Velocity.X,Velocity.Y,Velocity.Z,
+ RotationalVelocity.X,RotationalVelocity.Y,RotationalVelocity.Z
+ );
+ }
+}
+
+// Format of this structure must match the definition in the C++ code
+// NOTE: adding the X causes compile breaks if used. These are unused symbols
+// that can be removed from both here and the unmanaged definition of this structure.
+[StructLayout(LayoutKind.Sequential)]
+public struct ConfigurationParameters
+{
+ public float defaultFriction;
+ public float defaultDensity;
+ public float defaultRestitution;
+ public float collisionMargin;
+ public float gravity;
+
+ public float XlinearDamping;
+ public float XangularDamping;
+ public float XdeactivationTime;
+ public float XlinearSleepingThreshold;
+ public float XangularSleepingThreshold;
+ public float XccdMotionThreshold;
+ public float XccdSweptSphereRadius;
+ public float XcontactProcessingThreshold;
+
+ public float XterrainImplementation;
+ public float XterrainFriction;
+ public float XterrainHitFraction;
+ public float XterrainRestitution;
+ public float XterrainCollisionMargin;
+
+ public float XavatarFriction;
+ public float XavatarStandingFriction;
+ public float XavatarDensity;
+ public float XavatarRestitution;
+ public float XavatarCapsuleWidth;
+ public float XavatarCapsuleDepth;
+ public float XavatarCapsuleHeight;
+ public float XavatarContactProcessingThreshold;
+
+ public float XvehicleAngularDamping;
+
+ public float maxPersistantManifoldPoolSize;
+ public float maxCollisionAlgorithmPoolSize;
+ public float shouldDisableContactPoolDynamicAllocation;
+ public float shouldForceUpdateAllAabbs;
+ public float shouldRandomizeSolverOrder;
+ public float shouldSplitSimulationIslands;
+ public float shouldEnableFrictionCaching;
+ public float numberOfSolverIterations;
+
+ public float XlinksetImplementation;
+ public float XlinkConstraintUseFrameOffset;
+ public float XlinkConstraintEnableTransMotor;
+ public float XlinkConstraintTransMotorMaxVel;
+ public float XlinkConstraintTransMotorMaxForce;
+ public float XlinkConstraintERP;
+ public float XlinkConstraintCFM;
+ public float XlinkConstraintSolverIterations;
+
+ public float physicsLoggingFrames;
+
+ public const float numericTrue = 1f;
+ public const float numericFalse = 0f;
+}
+
+
+// The states a bullet collision object can have
+
+public enum ActivationState : uint
+{
+ UNDEFINED = 0,
+ ACTIVE_TAG = 1,
+ ISLAND_SLEEPING = 2,
+ WANTS_DEACTIVATION = 3,
+ DISABLE_DEACTIVATION = 4,
+ DISABLE_SIMULATION = 5,
+}
+
+public enum CollisionObjectTypes : int
+{
+ CO_COLLISION_OBJECT = 1 << 0,
+ CO_RIGID_BODY = 1 << 1,
+ CO_GHOST_OBJECT = 1 << 2,
+ CO_SOFT_BODY = 1 << 3,
+ CO_HF_FLUID = 1 << 4,
+ CO_USER_TYPE = 1 << 5,
+}
+
+// Values used by Bullet and BulletSim to control object properties.
+// Bullet's "CollisionFlags" has more to do with operations on the
+// object (if collisions happen, if gravity effects it, ...).
+ [Flags]
+public enum CollisionFlags : uint
+{
+ CF_STATIC_OBJECT = 1 << 0,
+ CF_KINEMATIC_OBJECT = 1 << 1,
+ CF_NO_CONTACT_RESPONSE = 1 << 2,
+ CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
+ CF_CHARACTER_OBJECT = 1 << 4,
+ CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
+ CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
+ // Following used by BulletSim to control collisions and updates
+ BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
+ BS_FLOATS_ON_WATER = 1 << 11,
+ BS_VEHICLE_COLLISIONS = 1 << 12,
+ BS_NONE = 0,
+ BS_ALL = 0xFFFFFFFF,
+
+ // These are the collision flags switched depending on physical state.
+ // The other flags are used for other things and should not be fooled with.
+ BS_ACTIVE = CF_STATIC_OBJECT
+ | CF_KINEMATIC_OBJECT
+ | CF_NO_CONTACT_RESPONSE
+};
+
+// Values for collisions groups and masks
+public enum CollisionFilterGroups : uint
+{
+ // Don't use the bit definitions!! Define the use in a
+ // filter/mask definition below. This way collision interactions
+ // are more easily debugged.
+ BNoneGroup = 0,
+ BDefaultGroup = 1 << 0,
+ BStaticGroup = 1 << 1,
+ BKinematicGroup = 1 << 2,
+ BDebrisGroup = 1 << 3,
+ BSensorTrigger = 1 << 4,
+ BCharacterGroup = 1 << 5,
+ BAllGroup = 0xFFFFFFFF,
+ // Filter groups defined by BulletSim
+ BGroundPlaneGroup = 1 << 10,
+ BTerrainGroup = 1 << 11,
+ BRaycastGroup = 1 << 12,
+ BSolidGroup = 1 << 13,
+ // BLinksetGroup = xx // a linkset proper is either static or dynamic
+ BLinksetChildGroup = 1 << 14,
+ // The collsion filters and masked are defined in one place -- don't want them scattered
+ AvatarGroup = BCharacterGroup,
+ AvatarMask = BAllGroup,
+ ObjectGroup = BSolidGroup,
+ ObjectMask = BAllGroup,
+ StaticObjectGroup = BStaticGroup,
+ StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much
+ LinksetGroup = BLinksetChildGroup,
+ LinksetMask = BAllGroup & ~BLinksetChildGroup, // linkset objects don't collide with each other
+ VolumeDetectGroup = BSensorTrigger,
+ VolumeDetectMask = ~BSensorTrigger,
+ TerrainGroup = BTerrainGroup,
+ TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide
+ GroundPlaneGroup = BGroundPlaneGroup,
+ GroundPlaneMask = BAllGroup
+
+};
+
+// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
+// ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
+public enum ConstraintParams : int
+{
+ BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
+ BT_CONSTRAINT_STOP_ERP,
+ BT_CONSTRAINT_CFM,
+ BT_CONSTRAINT_STOP_CFM,
+};
+public enum ConstraintParamAxis : int
+{
+ AXIS_LINEAR_X = 0,
+ AXIS_LINEAR_Y,
+ AXIS_LINEAR_Z,
+ AXIS_ANGULAR_X,
+ AXIS_ANGULAR_Y,
+ AXIS_ANGULAR_Z,
+ AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls
+ AXIS_ANGULAR_ALL,
+ AXIS_ALL
+};
+
+// ===============================================================================
+static class BulletSimAPI {
+ private static int m_collisionsThisFrame;
+ public delegate void DebugLogCallback(string msg);
+ ///
+ ///
+ ///
+ ///
+ ///
+ internal static bool RemoveObjectFromWorld2(object pWorld, object pBody)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body = pBody as RigidBody;
+ world.RemoveRigidBody(body);
+ return true;
+ }
+
+ internal static void SetRestitution2(object pBody, float pRestitution)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetRestitution(pRestitution);
+ }
+
+ internal static void SetMargin2(object pShape, float pMargin)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ shape.SetMargin(pMargin);
+ }
+
+ internal static void SetLocalScaling2(object pShape, Vector3 pScale)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
+ shape.SetLocalScaling(ref vec);
+
+ }
+
+ internal static void SetContactProcessingThreshold2(object pBody, float contactprocessingthreshold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetContactProcessingThreshold(contactprocessingthreshold);
+ }
+
+ internal static void SetCcdMotionThreshold2(object pBody, float pccdMotionThreashold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCcdMotionThreshold(pccdMotionThreashold);
+ }
+
+ internal static void SetCcdSweptSphereRadius2(object pBody, float pCcdSweptSphereRadius)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius);
+ }
+
+ internal static void SetAngularFactorV2(object pBody, Vector3 pAngularFactor)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z));
+ }
+
+ internal static CollisionFlags AddToCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
+ existingcollisionFlags |= pcollisionFlags;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
+ return (CollisionFlags) (uint) existingcollisionFlags;
+ }
+
+ internal static void AddObjectToWorld2(object pWorld, object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
+
+ world.AddRigidBody(body);
+
+ //if (body.GetBroadphaseHandle() != null)
+ // world.UpdateSingleAabb(body);
+ }
+
+ internal static void AddObjectToWorld2(object pWorld, object pBody, Vector3 _position, Quaternion _orientation)
+ {
+ RigidBody body = pBody as RigidBody;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
+
+ world.AddRigidBody(body);
+ IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
+ IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
+ _orientation.W);
+ IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
+ mat._origin = vposition;
+ body.SetWorldTransform(mat);
+ //if (body.GetBroadphaseHandle() != null)
+ // world.UpdateSingleAabb(body);
+ }
+
+ internal static void ForceActivationState2(object pBody, ActivationState pActivationState)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState);
+ }
+
+ internal static void UpdateSingleAabb2(object pWorld, object pBody)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ world.UpdateSingleAabb(body);
+ }
+
+ internal static bool SetCollisionGroupMask2(object pBody, uint pGroup, uint pMask)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
+ body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
+ if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0)
+ return false;
+ return true;
+ }
+
+ internal static void ClearAllForces2(object pBody)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0);
+ body.SetInterpolationLinearVelocity(ref zeroVector);
+ body.SetInterpolationAngularVelocity(ref zeroVector);
+ IndexedMatrix bodytransform = body.GetWorldTransform();
+
+ body.SetInterpolationWorldTransform(ref bodytransform);
+
+ if (body is RigidBody)
+ {
+ RigidBody rigidbody = body as RigidBody;
+ rigidbody.SetLinearVelocity(zeroVector);
+ rigidbody.SetAngularVelocity(zeroVector);
+ rigidbody.ClearForces();
+ }
+ }
+
+ internal static void SetInterpolationAngularVelocity2(object pBody, Vector3 pVector3)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
+ body.SetInterpolationAngularVelocity(ref vec);
+ }
+
+ internal static void SetAngularVelocity2(object pBody, Vector3 pVector3)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
+ body.SetAngularVelocity(ref vec);
+ }
+
+ internal static void ClearForces2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.ClearForces();
+ }
+
+ internal static void SetTranslation2(object pBody, Vector3 _position, Quaternion _orientation)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
+ IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
+ _orientation.W);
+ IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
+ mat._origin = vposition;
+ body.SetWorldTransform(mat);
+
+ }
+
+ internal static Vector3 GetPosition2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin;
+ return new Vector3(pos.X, pos.Y, pos.Z);
+ }
+
+ internal static Vector3 CalculateLocalInertia2(object pShape, float pphysMass)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ IndexedVector3 inertia = IndexedVector3.Zero;
+ shape.CalculateLocalInertia(pphysMass, out inertia);
+ return new Vector3(inertia.X, inertia.Y, inertia.Z);
+ }
+
+ internal static void SetMassProps2(object pBody, float pphysMass, Vector3 plocalInertia)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z);
+ body.SetMassProps(pphysMass, inertia);
+ }
+
+
+ internal static void SetObjectForce2(object pBody, Vector3 _force)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z);
+ body.SetTotalForce(ref force);
+ }
+
+ internal static void SetFriction2(object pBody, float _currentFriction)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetFriction(_currentFriction);
+ }
+
+ internal static void SetLinearVelocity2(object pBody, Vector3 _velocity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z);
+ body.SetLinearVelocity(velocity);
+ }
+
+ internal static void Activate2(object pBody, bool pforceactivation)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.Activate(pforceactivation);
+
+ }
+
+ internal static Quaternion GetOrientation2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation();
+ return new Quaternion(mat.X, mat.Y, mat.Z, mat.W);
+ }
+
+ internal static CollisionFlags RemoveFromCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
+ {
+ RigidBody body = pBody as RigidBody;
+ CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
+ existingcollisionFlags &= ~pcollisionFlags;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
+ return (CollisionFlags)(uint)existingcollisionFlags;
+ }
+
+ internal static void SetGravity2(object pBody, Vector3 pGravity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z);
+ body.SetGravity(gravity);
+ }
+
+ internal static bool DestroyConstraint2(object pBody, object pConstraint)
+ {
+ RigidBody body = pBody as RigidBody;
+ TypedConstraint constraint = pConstraint as TypedConstraint;
+ body.RemoveConstraintRef(constraint);
+ return true;
+ }
+
+ internal static bool SetLinearLimits2(object pConstraint, Vector3 low, Vector3 high)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
+ IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
+ constraint.SetLinearLowerLimit(lowlimit);
+ constraint.SetLinearUpperLimit(highlimit);
+ return true;
+ }
+
+ internal static bool SetAngularLimits2(object pConstraint, Vector3 low, Vector3 high)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
+ IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
+ constraint.SetAngularLowerLimit(lowlimit);
+ constraint.SetAngularUpperLimit(highlimit);
+ return true;
+ }
+
+ internal static void SetConstraintNumSolverIterations2(object pConstraint, float cnt)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetOverrideNumSolverIterations((int)cnt);
+ }
+
+ internal static void CalculateTransforms2(object pConstraint)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.CalculateTransforms();
+ }
+
+ internal static void SetConstraintEnable2(object pConstraint, float p_2)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetEnabled((p_2 == 0) ? false : true);
+ }
+
+
+ //BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+ internal static object Create6DofConstraint2(object pWorld, object pBody1, object pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body1 = pBody1 as RigidBody;
+ RigidBody body2 = pBody2 as RigidBody;
+ IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
+ IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
+ IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
+ frame1._origin = frame1v;
+
+ IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
+ IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
+ IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
+ frame2._origin = frame1v;
+
+ Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2,
+ puseLinearReferenceFrameA);
+ consttr.CalculateTransforms();
+ world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);
+
+ return consttr;
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ internal static object Create6DofConstraintToPoint2(object pWorld, object pBody1, object pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body1 = pBody1 as RigidBody;
+ RigidBody body2 = pBody2 as RigidBody;
+ IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
+ IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
+
+ IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
+ IndexedMatrix mat = IndexedMatrix.Identity;
+ mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
+ frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
+ frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;
+
+ Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
+ consttr.CalculateTransforms();
+ world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);
+
+ return consttr;
+ }
+ //SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot);
+ internal static void SetFrames2(object pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
+ IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
+ IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
+ frame1._origin = frame1v;
+
+ IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
+ IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
+ IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
+ frame2._origin = frame1v;
+ constraint.SetFrames(ref frame1, ref frame2);
+ }
+
+
+
+
+ internal static bool IsInWorld2(object pWorld, object pShapeObj)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ CollisionObject shape = pShapeObj as CollisionObject;
+ return world.IsInWorld(shape);
+ }
+
+ internal static void SetInterpolationLinearVelocity2(object pBody, Vector3 VehicleVelocity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z);
+ body.SetInterpolationLinearVelocity(ref velocity);
+ }
+
+ internal static bool UseFrameOffset2(object pConstraint, float onOff)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetUseFrameOffset((onOff == 0) ? false : true);
+ return true;
+ }
+ //SetBreakingImpulseThreshold2(m_constraint.ptr, threshold);
+ internal static bool SetBreakingImpulseThreshold2(object pConstraint, float threshold)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetBreakingImpulseThreshold(threshold);
+ return true;
+ }
+ //BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
+ internal static void SetAngularDamping2(object pBody, float angularDamping)
+ {
+ RigidBody body = pBody as RigidBody;
+ float lineardamping = body.GetLinearDamping();
+ body.SetDamping(lineardamping, angularDamping);
+
+ }
+
+ internal static void UpdateInertiaTensor2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.UpdateInertiaTensor();
+ }
+
+ internal static void RecalculateCompoundShapeLocalAabb2( object pCompoundShape)
+ {
+
+ CompoundShape shape = pCompoundShape as CompoundShape;
+ shape.RecalculateLocalAabb();
+ }
+
+ //BulletSimAPI.GetCollisionFlags2(PhysBody.ptr)
+ internal static CollisionFlags GetCollisionFlags2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ uint flags = (uint)body.GetCollisionFlags();
+ return (CollisionFlags) flags;
+ }
+
+ internal static void SetDamping2(object pBody, float pLinear, float pAngular)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetDamping(pLinear, pAngular);
+ }
+ //PhysBody.ptr, PhysicsScene.Params.deactivationTime);
+ internal static void SetDeactivationTime2(object pBody, float pDeactivationTime)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetDeactivationTime(pDeactivationTime);
+ }
+ //SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold);
+ internal static void SetSleepingThresholds2(object pBody, float plinearSleepingThreshold, float pangularSleepingThreshold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold);
+ }
+
+ internal static CollisionObjectTypes GetBodyType2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ return (CollisionObjectTypes)(int) body.GetInternalType();
+ }
+
+ //BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum);
+ internal static void ApplyCentralForce2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyCentralForce(ref fSum);
+ }
+ internal static void ApplyCentralImpulse2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyCentralImpulse(ref fSum);
+ }
+ internal static void ApplyTorque2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyTorque(ref fSum);
+ }
+ internal static void ApplyTorqueImpulse2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyTorqueImpulse(ref fSum);
+ }
+
+ internal static void DumpRigidBody2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ internal static void DumpCollisionShape2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ internal static void DestroyObject2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ internal static void Shutdown2(object pWorld)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ world.Cleanup();
+ }
+
+ internal static void DeleteCollisionShape2(object p, object p_2)
+ {
+ //TODO:
+ }
+ //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation);
+
+ internal static object CreateBodyFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+ CollisionWorld world = pWorld as CollisionWorld;
+ IndexedMatrix mat =
+ IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
+ pRawOrientation.Z, pRawOrientation.W));
+ mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+ CollisionShape shape = pShape as CollisionShape;
+ //UpdateSingleAabb2(world, shape);
+ // TODO: Feed Update array into null
+ RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero);
+
+ body.SetUserPointer(pLocalID);
+ return body;
+ }
+
+
+ internal static object CreateBodyWithDefaultMotionState2( object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+
+ IndexedMatrix mat =
+ IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
+ pRawOrientation.Z, pRawOrientation.W));
+ mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+
+ CollisionShape shape = pShape as CollisionShape;
+
+ // TODO: Feed Update array into null
+ RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
+ body.SetWorldTransform(mat);
+ body.SetUserPointer(pLocalID);
+ return body;
+ }
+ //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ internal static void SetCollisionFlags2(object pBody, CollisionFlags collisionFlags)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags);
+ }
+ //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction);
+ internal static void SetHitFraction2(object pBody, float pHitFraction)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetHitFraction(pHitFraction);
+ }
+ //BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
+ internal static object BuildCapsuleShape2(object pWorld, float pRadius, float pHeight, Vector3 pScale)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
+ CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight);
+ capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin);
+ capsuleShapeZ.SetLocalScaling(ref scale);
+
+ return capsuleShapeZ;
+ }
+
+ public static object Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref List collisionArray, int mMaxUpdatesPerFrame, ref List updateArray, object mDebugLogCallbackHandle)
+ {
+ CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();
+
+ p.angularDamping = o[0].XangularDamping;
+ p.defaultFriction = o[0].defaultFriction;
+ p.defaultFriction = o[0].defaultFriction;
+ p.defaultDensity = o[0].defaultDensity;
+ p.defaultRestitution = o[0].defaultRestitution;
+ p.collisionMargin = o[0].collisionMargin;
+ p.gravity = o[0].gravity;
+
+ p.linearDamping = o[0].XlinearDamping;
+ p.angularDamping = o[0].XangularDamping;
+ p.deactivationTime = o[0].XdeactivationTime;
+ p.linearSleepingThreshold = o[0].XlinearSleepingThreshold;
+ p.angularSleepingThreshold = o[0].XangularSleepingThreshold;
+ p.ccdMotionThreshold = o[0].XccdMotionThreshold;
+ p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius;
+ p.contactProcessingThreshold = o[0].XcontactProcessingThreshold;
+
+ p.terrainImplementation = o[0].XterrainImplementation;
+ p.terrainFriction = o[0].XterrainFriction;
+
+ p.terrainHitFraction = o[0].XterrainHitFraction;
+ p.terrainRestitution = o[0].XterrainRestitution;
+ p.terrainCollisionMargin = o[0].XterrainCollisionMargin;
+
+ p.avatarFriction = o[0].XavatarFriction;
+ p.avatarStandingFriction = o[0].XavatarStandingFriction;
+ p.avatarDensity = o[0].XavatarDensity;
+ p.avatarRestitution = o[0].XavatarRestitution;
+ p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth;
+ p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth;
+ p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight;
+ p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold;
+
+ p.vehicleAngularDamping = o[0].XvehicleAngularDamping;
+
+ p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
+ p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
+ p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
+ p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
+ p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
+ p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
+ p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
+ p.numberOfSolverIterations = o[0].numberOfSolverIterations;
+
+ p.linksetImplementation = o[0].XlinksetImplementation;
+ p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset;
+ p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor;
+ p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel;
+ p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce;
+ p.linkConstraintERP = o[0].XlinkConstraintERP;
+ p.linkConstraintCFM = o[0].XlinkConstraintCFM;
+ p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations;
+ p.physicsLoggingFrames = o[0].physicsLoggingFrames;
+ DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();
+
+ DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
+ CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);
+
+
+ if (p.maxPersistantManifoldPoolSize > 0)
+ cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
+ if (p.shouldDisableContactPoolDynamicAllocation !=0)
+ m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
+ //if (p.maxCollisionAlgorithmPoolSize >0 )
+
+ DbvtBroadphase m_broadphase = new DbvtBroadphase();
+ //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
+ //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);
+
+ //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
+ m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());
+
+ SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();
+
+ DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);
+ world.UpdatedObjects = updateArray;
+ world.UpdatedCollisions = collisionArray;
+ world.WorldSettings.Params = p;
+ world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
+ world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
+ if (p.shouldRandomizeSolverOrder != 0)
+ world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;
+
+ world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
+ //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port
+
+ if (p.shouldEnableFrictionCaching != 0)
+ world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;
+
+ if (p.numberOfSolverIterations > 0)
+ world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;
+
+
+ world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
+ world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
+ world.GetSolverInfo().m_globalCfm = 0.0f;
+ world.GetSolverInfo().m_tau = 0.6f;
+ world.GetSolverInfo().m_friction = 0.3f;
+ world.GetSolverInfo().m_maxErrorReduction = 20f;
+ world.GetSolverInfo().m_numIterations = 10;
+ world.GetSolverInfo().m_erp = 0.2f;
+ world.GetSolverInfo().m_erp2 = 0.1f;
+ world.GetSolverInfo().m_sor = 1.0f;
+ world.GetSolverInfo().m_splitImpulse = false;
+ world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
+ world.GetSolverInfo().m_linearSlop = 0.0f;
+ world.GetSolverInfo().m_warmstartingFactor = 0.85f;
+ world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
+ world.SetForceUpdateAllAabbs(true);
+
+
+ world.SetGravity(new IndexedVector3(0,0,p.gravity));
+
+ return world;
+ }
+ //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL
+ internal static bool SetConstraintParam2(object pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis)
+ {
+ Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
+ if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2);
+ }
+ if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5);
+ }
+ if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis);
+ }
+ return true;
+ }
+
+ internal static bool PushUpdate2(object pCollisionObject)
+ {
+ bool ret = false;
+ RigidBody rb = pCollisionObject as RigidBody;
+ if (rb != null)
+ {
+ SimMotionState sms = rb.GetMotionState() as SimMotionState;
+ if (sms != null)
+ {
+ IndexedMatrix wt = IndexedMatrix.Identity;
+ sms.GetWorldTransform(out wt);
+ sms.SetWorldTransform(ref wt, true);
+ ret = true;
+ }
+ }
+ return ret;
+
+ }
+
+ internal static bool IsCompound2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsCompound();
+ }
+ internal static bool IsPloyhedral2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsPolyhedral();
+ }
+ internal static bool IsConvex2d2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConvex2d();
+ }
+ internal static bool IsConvex2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConvex();
+ }
+ internal static bool IsNonMoving2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsNonMoving();
+ }
+ internal static bool IsConcave2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConcave();
+ }
+ internal static bool IsInfinite2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsInfinite();
+ }
+ internal static bool IsNativeShape2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ bool ret;
+ switch (shape.GetShapeType())
+ {
+ case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
+ ret = true;
+ break;
+ default:
+ ret = false;
+ break;
+ }
+ return ret;
+ }
+ //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation
+ internal static object CreateGhostFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+ IndexedMatrix bodyTransform = new IndexedMatrix();
+ bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+ bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W));
+ GhostObject gObj = new PairCachingGhostObject();
+ gObj.SetWorldTransform(bodyTransform);
+ CollisionShape shape = pShape as CollisionShape;
+ gObj.SetCollisionShape(shape);
+ gObj.SetUserPointer(pLocalID);
+ // TODO: Add to Special CollisionObjects!
+ return gObj;
+ }
+
+ public static void SetCollisionShape2(object pWorld, object pObj, object pShape)
+ {
+ var world = pWorld as DiscreteDynamicsWorld;
+ var obj = pObj as CollisionObject;
+ var shape = pShape as CollisionShape;
+ obj.SetCollisionShape(shape);
+
+ }
+ //(PhysicsScene.World.ptr, nativeShapeData)
+ internal static object BuildNativeShape2(object pWorld, ShapeData pShapeData)
+ {
+ var world = pWorld as DiscreteDynamicsWorld;
+ CollisionShape shape = null;
+ switch (pShapeData.Type)
+ {
+ case BSPhysicsShapeType.SHAPE_BOX:
+ shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f));
+ break;
+ case BSPhysicsShapeType.SHAPE_CONE:
+ shape = new ConeShapeZ(0.5f, 1.0f);
+ break;
+ case BSPhysicsShapeType.SHAPE_CYLINDER:
+ shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f));
+ break;
+ case BSPhysicsShapeType.SHAPE_SPHERE:
+ shape = new SphereShape(0.5f);
+ break;
+
+ }
+ if (shape != null)
+ {
+ IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z);
+ shape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ shape.SetLocalScaling(ref scaling);
+
+ }
+ return shape;
+ }
+ //PhysicsScene.World.ptr, false
+ internal static object CreateCompoundShape2(object pWorld, bool enableDynamicAabbTree)
+ {
+ return new CompoundShape(enableDynamicAabbTree);
+ }
+
+ internal static int GetNumberOfCompoundChildren2(object pCompoundShape)
+ {
+ var compoundshape = pCompoundShape as CompoundShape;
+ return compoundshape.GetNumChildShapes();
+ }
+ //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot
+ internal static void AddChildShapeToCompoundShape2(object pCShape, object paddShape, Vector3 displacementPos, Quaternion displacementRot)
+ {
+ IndexedMatrix relativeTransform = new IndexedMatrix();
+ var compoundshape = pCShape as CompoundShape;
+ var addshape = paddShape as CollisionShape;
+
+ relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z);
+ relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W));
+ compoundshape.AddChildShape(ref relativeTransform, addshape);
+
+ }
+
+ internal static object RemoveChildShapeFromCompoundShapeIndex2(object pCShape, int pii)
+ {
+ var compoundshape = pCShape as CompoundShape;
+ CollisionShape ret = null;
+ ret = compoundshape.GetChildShape(pii);
+ compoundshape.RemoveChildShapeByIndex(pii);
+ return ret;
+ }
+
+ internal static object CreateGroundPlaneShape2(uint pLocalId, float pheight, float pcollisionMargin)
+ {
+ StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight );
+ m_planeshape.SetMargin(pcollisionMargin);
+ m_planeshape.SetUserPointer(pLocalId);
+ return m_planeshape;
+ }
+
+ internal static object CreateHingeConstraint2(object pWorld, object pBody1, object ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+ {
+ HingeConstraint constrain = null;
+ var rb1 = pBody1 as RigidBody;
+ var rb2 = ppBody2 as RigidBody;
+ if (rb1 != null && rb2 != null)
+ {
+ IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z);
+ IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
+ IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
+ IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
+ var world = pWorld as DiscreteDynamicsWorld;
+ world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
+ }
+ return constrain;
+ }
+
+ internal static bool ReleaseHeightMapInfo2(object pMapInfo)
+ {
+ if (pMapInfo != null)
+ {
+ BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
+ if (mapinfo.heightMap != null)
+ mapinfo.heightMap = null;
+
+
+ }
+ return true;
+ }
+
+ internal static object CreateHullShape2(object pWorld, int pHullCount, float[] pConvHulls)
+ {
+ CompoundShape compoundshape = new CompoundShape(false);
+ var world = pWorld as DiscreteDynamicsWorld;
+
+
+ compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ int ii = 1;
+
+ for (int i = 0; i < pHullCount; i++)
+ {
+ int vertexCount = (int) pConvHulls[ii];
+
+ IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]);
+ IndexedMatrix childTrans = IndexedMatrix.Identity;
+ childTrans._origin = centroid;
+
+ List virts = new List();
+ int ender = ((ii + 4) + (vertexCount*3));
+ for (int iii = ii + 4; iii < ender; iii+=3)
+ {
+
+ virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2]));
+ }
+ ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount);
+ convexShape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ compoundshape.AddChildShape(ref childTrans, convexShape);
+ ii += (vertexCount*3 + 4);
+ }
+
+
+ return compoundshape;
+ }
+
+ internal static object CreateMeshShape2(object pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
+ {
+ //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);
+
+ for (int iter = 0; iter < pVerticesCount; iter++)
+ {
+ if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
+ if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
+ }
+
+ ObjectArray indicesarr = new ObjectArray(indices);
+ ObjectArray vertices = new ObjectArray(verticesAsFloats);
+ DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
+ var world = pWorld as DiscreteDynamicsWorld;
+ IndexedMesh mesh = new IndexedMesh();
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount/3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indicesarr;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+ BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
+ meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ // world.UpdateSingleAabb(meshShape);
+ return meshShape;
+
+ }
+ public static void DumpRaw(ObjectArrayindices, ObjectArray vertices, int pIndicesCount,int pVerticesCount )
+ {
+
+ String fileName = "objTest3.raw";
+ String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
+ StreamWriter sw = new StreamWriter(completePath);
+ IndexedMesh mesh = new IndexedMesh();
+
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount / 3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indices;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+
+
+
+ for (int i = 0; i < pVerticesCount; i++)
+ {
+
+ string s = vertices[indices[i * 3]].ToString("0.0000");
+ s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
+ s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
+
+ sw.Write(s + "\n");
+ }
+
+ sw.Close();
+ }
+ public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount)
+ {
+
+ String fileName = "objTest6.raw";
+ String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
+ StreamWriter sw = new StreamWriter(completePath);
+ IndexedMesh mesh = new IndexedMesh();
+
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount / 3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indices;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+
+
+ sw.WriteLine("Indices");
+ sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount));
+ for (int iter = 0; iter < indices.Length; iter++)
+ {
+ sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter]));
+ }
+ sw.WriteLine("VerticesFloats");
+ sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount));
+ for (int iter = 0; iter < vertices.Length; iter++)
+ {
+ sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000")));
+ }
+
+ // for (int i = 0; i < pVerticesCount; i++)
+ // {
+ //
+ // string s = vertices[indices[i * 3]].ToString("0.0000");
+ // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
+ // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
+ //
+ // sw.Write(s + "\n");
+ //}
+
+ sw.Close();
+ }
+ //PhysicsScene.World.ptr, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, PhysicsScene.Params.terrainCollisionMargin
+ internal static object CreateHeightMapInfo2(object pWorld, uint pId, Vector3 pminCoords, Vector3 pmaxCoords, float[] pheightMap, float pCollisionMargin)
+ {
+ BulletHeightMapInfo mapInfo = new BulletHeightMapInfo(pId, pheightMap, null);
+ mapInfo.heightMap = null;
+ mapInfo.minCoords = pminCoords;
+ mapInfo.maxCoords = pmaxCoords;
+ mapInfo.sizeX = (int) (pmaxCoords.X - pminCoords.X);
+ mapInfo.sizeY = (int) (pmaxCoords.Y - pminCoords.Y);
+ mapInfo.ID = pId;
+ mapInfo.minZ = pminCoords.Z;
+ mapInfo.maxZ = pmaxCoords.Z;
+ mapInfo.collisionMargin = pCollisionMargin;
+ if (mapInfo.minZ == mapInfo.maxZ)
+ mapInfo.minZ -= 0.2f;
+ mapInfo.heightMap = pheightMap;
+
+ return mapInfo;
+
+ }
+
+ internal static object CreateTerrainShape2(object pMapInfo)
+ {
+ BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
+ const int upAxis = 2;
+ const float scaleFactor = 1.0f;
+ HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)mapinfo.sizeX, (int)mapinfo.sizeY,
+ mapinfo.heightMap, scaleFactor,
+ mapinfo.minZ, mapinfo.maxZ, upAxis,
+ false);
+ terrainShape.SetMargin(mapinfo.collisionMargin + 0.5f);
+ terrainShape.SetUseDiamondSubdivision(true);
+ terrainShape.SetUserPointer(mapinfo.ID);
+ return terrainShape;
+ }
+
+ internal static bool TranslationalLimitMotor2(object pConstraint, float ponOff, float targetVelocity, float maxMotorForce)
+ {
+ TypedConstraint tconstrain = pConstraint as TypedConstraint;
+ bool onOff = ponOff != 0;
+ bool ret = false;
+
+ switch (tconstrain.GetConstraintType())
+ {
+ case TypedConstraintType.D6_CONSTRAINT_TYPE:
+ Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
+ constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff;
+ constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity;
+ constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce;
+ ret = true;
+ break;
+ }
+
+
+ return ret;
+
+ }
+
+ internal static int PhysicsStep2(object pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List updatedEntities, out int collidersCount, out Listcolliders)
+ {
+ int epic = PhysicsStepint2(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities,
+ out collidersCount, out colliders);
+ return epic;
+ }
+
+ private static int PhysicsStepint2(object pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List updatedEntities, out int collidersCount, out List colliders)
+ {
+ int numSimSteps = 0;
+
+
+ //if (updatedEntities is null)
+ // updatedEntities = new List();
+
+ //if (colliders is null)
+ // colliders = new List();
+
+
+ if (pWorld is DiscreteDynamicsWorld)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+
+ numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep);
+ int updates = 0;
+
+ updatedEntityCount = world.UpdatedObjects.Count;
+ updatedEntities = new List(world.UpdatedObjects);
+ updatedEntityCount = updatedEntities.Count;
+ world.UpdatedObjects.Clear();
+
+
+ collidersCount = world.UpdatedCollisions.Count;
+ colliders = new List(world.UpdatedCollisions);
+
+ world.UpdatedCollisions.Clear();
+ m_collisionsThisFrame = 0;
+ int numManifolds = world.GetDispatcher().GetNumManifolds();
+ for (int j = 0; j < numManifolds; j++)
+ {
+ PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j);
+ int numContacts = contactManifold.GetNumContacts();
+ if (numContacts == 0)
+ continue;
+
+ CollisionObject objA = contactManifold.GetBody0() as CollisionObject;
+ CollisionObject objB = contactManifold.GetBody1() as CollisionObject;
+
+ ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0);
+ IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB();
+ IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A
+
+ RecordCollision(world, objA, objB, contactPoint, contactNormal);
+ m_collisionsThisFrame ++;
+ if (m_collisionsThisFrame >= 9999999)
+ break;
+
+
+ }
+
+
+ }
+ else
+ {
+ //if (updatedEntities is null)
+ updatedEntities = new List();
+ updatedEntityCount = 0;
+ //if (colliders is null)
+ colliders = new List();
+ collidersCount = 0;
+ }
+ return numSimSteps;
+ }
+
+ private static void RecordCollision(CollisionWorld world,CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm)
+ {
+
+ IndexedVector3 contactNormal = norm;
+ if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 &&
+ (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0)
+ {
+ return;
+ }
+ uint idA = (uint)objA.GetUserPointer();
+ uint idB = (uint)objB.GetUserPointer();
+ if (idA > idB)
+ {
+ uint temp = idA;
+ idA = idB;
+ idB = temp;
+ contactNormal = -contactNormal;
+ }
+
+ ulong collisionID = ((ulong) idA << 32) | idB;
+
+ BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc()
+ {
+ aID = idA,
+ bID = idB,
+ point = contact,
+ normal = contactNormal
+ };
+ world.UpdatedCollisions.Add(cDesc);
+ m_collisionsThisFrame++;
+
+
+ }
+ private static EntityProperties GetDebugProperties(object pWorld, object pBody)
+ {
+ EntityProperties ent = new EntityProperties();
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body = pBody as RigidBody;
+ IndexedMatrix transform = body.GetWorldTransform();
+ IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity();
+ IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity();
+ IndexedQuaternion rotation = transform.GetRotation();
+ ent.Acceleration = Vector3.Zero;
+ ent.ID = (uint)body.GetUserPointer();
+ ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z);
+ ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W);
+ ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
+ ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);
+ return ent;
+
+
+ }
+
+
+ internal static Vector3 GetLocalScaling2(object pBody)
+ {
+ CollisionShape shape = pBody as CollisionShape;
+ IndexedVector3 scale = shape.GetLocalScaling();
+ return new Vector3(scale.X,scale.Y,scale.Z);
+ }
+
+ internal static bool RayCastGround(object pWorld, Vector3 _RayOrigin, float pRayHeight, object NotMe)
+ {
+ DynamicsWorld world = pWorld as DynamicsWorld;
+ if (world != null)
+ {
+ if (NotMe is CollisionObject || NotMe is RigidBody)
+ {
+ CollisionObject AvoidBody = NotMe as CollisionObject;
+
+ IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z);
+ IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight);
+ using (
+ ClosestNotMeRayResultCallback rayCallback = new ClosestNotMeRayResultCallback(rOrigin,
+ rEnd, AvoidBody)
+ )
+ {
+ world.RayTest(ref rOrigin, ref rEnd, rayCallback);
+ if (rayCallback.HasHit())
+ {
+ IndexedVector3 hitLocation = rayCallback.m_hitPointWorld;
+
+ }
+ return rayCallback.HasHit();
+ }
+ }
+ }
+ return false;
+ }
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs
new file mode 100644
index 0000000..a1ed8d8
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BulletSimData.cs
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OMV = OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSNPlugin
+{
+// Classes to allow some type checking for the API
+// These hold pointers to allocated objects in the unmanaged space.
+
+// The physics engine controller class created at initialization
+public struct BulletSim
+{
+ public BulletSim(uint worldId, BSScene bss, object xx)
+ {
+ ptr = xx;
+ worldID = worldId;
+ physicsScene = bss;
+ }
+ public object ptr;
+ public uint worldID;
+ // The scene is only in here so very low level routines have a handle to print debug/error messages
+ public BSScene physicsScene;
+}
+
+// An allocated Bullet btRigidBody
+public struct BulletBody
+{
+ public BulletBody(uint id) : this(id, null)
+ {
+ }
+ public BulletBody(uint id, object xx)
+ {
+ ID = id;
+ ptr = xx;
+ collisionType = CollisionType.Static;
+ }
+ public object ptr;
+ public uint ID;
+ public CollisionType collisionType;
+
+ public void Clear()
+ {
+ ptr = null;
+ }
+ public bool HasPhysicalBody { get { return ptr != null; } }
+
+ // Apply the specificed collision mask into the physical world
+ public void ApplyCollisionMask()
+ {
+ // Should assert the body has been added to the physical world.
+ // (The collision masks are stored in the collision proxy cache which only exists for
+ // a collision body that is in the world.)
+ BulletSimAPI.SetCollisionGroupMask2(ptr,
+ BulletSimData.CollisionTypeMasks[collisionType].group,
+ BulletSimData.CollisionTypeMasks[collisionType].mask);
+ }
+
+ public override string ToString()
+ {
+ StringBuilder buff = new StringBuilder();
+ buff.Append("");
+ return buff.ToString();
+ }
+}
+
+public struct BulletShape
+{
+ public BulletShape(object xx) : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN)
+ {
+ }
+ public BulletShape(object xx, BSPhysicsShapeType typ)
+ {
+ ptr = xx;
+ type = typ;
+ shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
+ isNativeShape = false;
+ }
+ public object ptr;
+ public BSPhysicsShapeType type;
+ public System.UInt64 shapeKey;
+ public bool isNativeShape;
+
+ public void Clear()
+ {
+ ptr = null;
+ }
+ public bool HasPhysicalShape { get { return ptr != null; } }
+
+ public override string ToString()
+ {
+ StringBuilder buff = new StringBuilder();
+ buff.Append("");
+ return buff.ToString();
+ }
+}
+
+// An allocated Bullet btConstraint
+public struct BulletConstraint
+{
+ public BulletConstraint(object xx)
+ {
+ ptr = xx;
+ }
+ public object ptr;
+
+ public void Clear()
+ {
+ ptr = null;
+ }
+ public bool HasPhysicalConstraint { get { return ptr != null; } }
+}
+
+// An allocated HeightMapThing which holds various heightmap info.
+// Made a class rather than a struct so there would be only one
+// instance of this and C# will pass around pointers rather
+// than making copies.
+public class BulletHeightMapInfo
+{
+ public BulletHeightMapInfo(uint id, float[] hm, object xx) {
+ ID = id;
+ Ptr = xx;
+ heightMap = hm;
+ terrainRegionBase = OMV.Vector3.Zero;
+ minCoords = new OMV.Vector3(100f, 100f, 25f);
+ maxCoords = new OMV.Vector3(101f, 101f, 26f);
+ minZ = maxZ = 0f;
+ sizeX = sizeY = 256f;
+ }
+ public uint ID;
+ public object Ptr;
+ public float[] heightMap;
+ public OMV.Vector3 terrainRegionBase;
+ public OMV.Vector3 minCoords;
+ public OMV.Vector3 maxCoords;
+ public float sizeX, sizeY;
+ public float minZ, maxZ;
+ public BulletShape terrainShape;
+ public BulletBody terrainBody;
+
+ public float collisionMargin { get; set; }
+}
+
+// The general class of collsion object.
+public enum CollisionType
+{
+ Avatar,
+ Groundplane,
+ Terrain,
+ Static,
+ Dynamic,
+ VolumeDetect,
+ // Linkset, // A linkset should be either Static or Dynamic
+ LinksetChild,
+ Unknown
+};
+
+// Hold specification of group and mask collision flags for a CollisionType
+public struct CollisionTypeFilterGroup
+{
+ public CollisionTypeFilterGroup(CollisionType t, uint g, uint m)
+ {
+ type = t;
+ group = g;
+ mask = m;
+ }
+ public CollisionType type;
+ public uint group;
+ public uint mask;
+};
+
+ /* NOTE: old definitions kept for reference. Delete when things are working.
+ // The collsion filters and masked are defined in one place -- don't want them scattered
+ AvatarGroup = BCharacterGroup,
+ AvatarMask = BAllGroup,
+ ObjectGroup = BSolidGroup,
+ ObjectMask = BAllGroup,
+ StaticObjectGroup = BStaticGroup,
+ StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much
+ LinksetGroup = BLinksetGroup,
+ LinksetMask = BAllGroup,
+ LinksetChildGroup = BLinksetChildGroup,
+ LinksetChildMask = BNoneGroup, // Linkset children disappear from the world
+ VolumeDetectGroup = BSensorTrigger,
+ VolumeDetectMask = ~BSensorTrigger,
+ TerrainGroup = BTerrainGroup,
+ TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide
+ GroundPlaneGroup = BGroundPlaneGroup,
+ GroundPlaneMask = BAllGroup
+ */
+
+public static class BulletSimData
+{
+
+// Map of collisionTypes to flags for collision groups and masks.
+// As mentioned above, don't use the CollisionFilterGroups definitions directly in the code
+// but, instead, use references to this dictionary. Finding and debugging
+// collision flag problems will be made easier.
+public static Dictionary CollisionTypeMasks
+ = new Dictionary()
+{
+ { CollisionType.Avatar,
+ new CollisionTypeFilterGroup(CollisionType.Avatar,
+ (uint)CollisionFilterGroups.BCharacterGroup,
+ (uint)CollisionFilterGroups.BAllGroup)
+ },
+ { CollisionType.Groundplane,
+ new CollisionTypeFilterGroup(CollisionType.Groundplane,
+ (uint)CollisionFilterGroups.BGroundPlaneGroup,
+ (uint)CollisionFilterGroups.BAllGroup)
+ },
+ { CollisionType.Terrain,
+ new CollisionTypeFilterGroup(CollisionType.Terrain,
+ (uint)CollisionFilterGroups.BTerrainGroup,
+ (uint)(CollisionFilterGroups.BAllGroup & ~CollisionFilterGroups.BStaticGroup))
+ },
+ { CollisionType.Static,
+ new CollisionTypeFilterGroup(CollisionType.Static,
+ (uint)CollisionFilterGroups.BStaticGroup,
+ (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
+ },
+ { CollisionType.Dynamic,
+ new CollisionTypeFilterGroup(CollisionType.Dynamic,
+ (uint)CollisionFilterGroups.BSolidGroup,
+ (uint)(CollisionFilterGroups.BAllGroup))
+ },
+ { CollisionType.VolumeDetect,
+ new CollisionTypeFilterGroup(CollisionType.VolumeDetect,
+ (uint)CollisionFilterGroups.BSensorTrigger,
+ (uint)(~CollisionFilterGroups.BSensorTrigger))
+ },
+ { CollisionType.LinksetChild,
+ new CollisionTypeFilterGroup(CollisionType.LinksetChild,
+ (uint)CollisionFilterGroups.BTerrainGroup,
+ (uint)(CollisionFilterGroups.BNoneGroup))
+ },
+};
+
+}
+}
--
cgit v1.1
From 93188706073fa23aa037456f5ec2d52605257d89 Mon Sep 17 00:00:00 2001
From: teravus
Date: Sun, 23 Dec 2012 16:17:18 -0500
Subject: * Update BulletSimN terrain implementation to default to Heightfield,
it's less CPU intensive.
---
OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs
index 0bb1674..20c0939 100644
--- a/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSParam.cs
@@ -315,7 +315,7 @@ public static class BSParam
(s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ),
new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
- (float)BSTerrainPhys.TerrainImplementation.Mesh,
+ (float)BSTerrainPhys.TerrainImplementation.Heightmap,
(s,cf,p,v) => { TerrainImplementation = cf.GetFloat(p,v); },
(s) => { return TerrainImplementation; },
(s,p,l,v) => { TerrainImplementation = v; } ),
--
cgit v1.1
From 80cee1b85a646045c02e2bb675056d532ce2fe27 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 24 Dec 2012 08:56:02 -0800
Subject: BulletSim: Fix single physical prim reporting its mass as zero.
Properly return root mass as mass of just the root prim rather than the mass
of the linkset. SOG has the logic to add the masses together to get the
linkset mass. Update TODO list.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 9 +--
OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 20 +++---
.../Physics/BulletSPlugin/BSLinksetCompound.cs | 13 ++--
.../Physics/BulletSPlugin/BSLinksetConstraints.cs | 6 +-
.../Region/Physics/BulletSPlugin/BSPhysObject.cs | 3 +-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 71 ++++++++++++++--------
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 15 ++++-
7 files changed, 83 insertions(+), 54 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 8e059ee..bf0545a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -174,7 +174,7 @@ public sealed class BSCharacter : BSPhysObject
BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
}
- UpdatePhysicalMassProperties(RawMass);
+ UpdatePhysicalMassProperties(RawMass, false);
// Make so capsule does not fall over
BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
@@ -224,7 +224,7 @@ public sealed class BSCharacter : BSPhysObject
if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape)
{
BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
- UpdatePhysicalMassProperties(RawMass);
+ UpdatePhysicalMassProperties(RawMass, true);
// Make sure this change appears as a property update event
BulletSimAPI.PushUpdate2(PhysBody.ptr);
}
@@ -390,7 +390,7 @@ public sealed class BSCharacter : BSPhysObject
public override float RawMass {
get {return _mass; }
}
- public override void UpdatePhysicalMassProperties(float physMass)
+ public override void UpdatePhysicalMassProperties(float physMass, bool inWorld)
{
OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia);
@@ -772,8 +772,9 @@ public sealed class BSCharacter : BSPhysObject
// the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer.
if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero)
{
- stepVelocity = OMV.Vector3.Zero;
_velocityMotor.Enabled = false;
+ stepVelocity = OMV.Vector3.Zero;
+ ZeroMotion(true);
DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 8580928..756faed 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -97,14 +97,7 @@ public abstract class BSLinkset
}
// We keep the prim's mass in the linkset structure since it could be dependent on other prims
- protected float m_mass;
- public float LinksetMass
- {
- get
- {
- return m_mass;
- }
- }
+ public float LinksetMass { get; protected set; }
public virtual bool LinksetIsColliding { get { return false; } }
@@ -128,7 +121,7 @@ public abstract class BSLinkset
PhysicsScene = scene;
LinksetRoot = parent;
m_children = new HashSet();
- m_mass = parent.RawMass;
+ LinksetMass = parent.RawMass;
Rebuilding = false;
}
@@ -143,7 +136,7 @@ public abstract class BSLinkset
// Don't add the root to its own linkset
if (!IsRoot(child))
AddChildToLinkset(child);
- m_mass = ComputeLinksetMass();
+ LinksetMass = ComputeLinksetMass();
}
return this;
}
@@ -162,7 +155,7 @@ public abstract class BSLinkset
return this;
}
RemoveChildFromLinkset(child);
- m_mass = ComputeLinksetMass();
+ LinksetMass = ComputeLinksetMass();
}
// The child is down to a linkset of just itself
@@ -230,7 +223,10 @@ public abstract class BSLinkset
// When physical properties are changed the linkset needs to recalculate
// its internal properties.
// May be called at runtime or taint-time.
- public abstract void Refresh(BSPhysObject requestor);
+ public virtual void Refresh(BSPhysObject requestor)
+ {
+ LinksetMass = ComputeLinksetMass();
+ }
// Flag denoting the linkset is in the process of being rebuilt.
// Used to know not the schedule a rebuild in the middle of a rebuild.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 2a7b72c..d5cbf5f 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -5,7 +5,7 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclat simer.
* * Redistributions in binary form must reproduce the above copyrightD
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
@@ -89,6 +89,8 @@ public sealed class BSLinksetCompound : BSLinkset
// its internal properties.
public override void Refresh(BSPhysObject requestor)
{
+ base.Refresh(requestor);
+
// Something changed so do the rebuilding thing
// ScheduleRebuild();
}
@@ -96,13 +98,13 @@ public sealed class BSLinksetCompound : BSLinkset
// Schedule a refresh to happen after all the other taint processing.
private void ScheduleRebuild(BSPhysObject requestor)
{
- DetailLog("{0},BSLinksetCompound.Refresh,schedulingRefresh,rebuilding={1}",
+ DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1}",
requestor.LocalID, Rebuilding);
// When rebuilding, it is possible to set properties that would normally require a rebuild.
// If already rebuilding, don't request another rebuild.
if (!Rebuilding)
{
- PhysicsScene.PostTaintObject("BSLinksetCompound.Refresh", LinksetRoot.LocalID, delegate()
+ PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate()
{
if (HasAnyChildren)
RecomputeLinksetCompound();
@@ -123,7 +125,6 @@ public sealed class BSLinksetCompound : BSLinkset
if (IsRoot(child))
{
// The root is going dynamic. Make sure mass is properly set.
- m_mass = ComputeLinksetMass();
ScheduleRebuild(LinksetRoot);
}
else
@@ -377,8 +378,8 @@ public sealed class BSLinksetCompound : BSLinkset
});
// With all of the linkset packed into the root prim, it has the mass of everyone.
- float linksetMass = LinksetMass;
- LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
+ LinksetMass = LinksetMass;
+ LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true);
}
finally
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index d95f223..6b592e7 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -46,6 +46,8 @@ public sealed class BSLinksetConstraints : BSLinkset
// refresh will happen once after all the other taints are applied.
public override void Refresh(BSPhysObject requestor)
{
+ base.Refresh(requestor);
+
// Queue to happen after all the other taint processing
PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
{
@@ -279,7 +281,7 @@ public sealed class BSLinksetConstraints : BSLinkset
private void RecomputeLinksetConstraints()
{
float linksetMass = LinksetMass;
- LinksetRoot.UpdatePhysicalMassProperties(linksetMass);
+ LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true);
// DEBUG: see of inter-linkset collisions are causing problems
// BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
@@ -292,7 +294,7 @@ public sealed class BSLinksetConstraints : BSLinkset
// A child in the linkset physically shows the mass of the whole linkset.
// This allows Bullet to apply enough force on the child to move the whole linkset.
// (Also do the mass stuff before recomputing the constraint so mass is not zero.)
- child.UpdatePhysicalMassProperties(linksetMass);
+ child.UpdatePhysicalMassProperties(linksetMass, true);
BSConstraint constrain;
if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain))
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index c76f869..4bed535 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -96,7 +96,8 @@ public abstract class BSPhysObject : PhysicsActor
// Return the object mass without calculating it or having side effects
public abstract float RawMass { get; }
// Set the raw mass but also update physical mass properties (inertia, ...)
- public abstract void UpdatePhysicalMassProperties(float mass);
+ // 'inWorld' true if the object has already been added to the dynamic world.
+ public abstract void UpdatePhysicalMassProperties(float mass, bool inWorld);
// The last value calculated for the prim's inertia
public OMV.Vector3 Inertia { get; set; }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 26b8df5..159f79f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -115,6 +115,8 @@ public sealed class BSPrim : BSPhysObject
PhysBody = new BulletBody(LocalID);
PhysShape = new BulletShape();
+ Linkset.Refresh(this);
+
DetailLog("{0},BSPrim.constructor,call", LocalID);
// do the actual object creation at taint time
PhysicsScene.TaintedObject("BSPrim.create", delegate()
@@ -384,13 +386,13 @@ public sealed class BSPrim : BSPhysObject
}
// Return the effective mass of the object.
- // If there are multiple items in the linkset, add them together for the root
+ // The definition of this call is to return the mass of the prim.
+ // If the simulator cares about the mass of the linkset, it will sum it itself.
public override float Mass
{
get
{
- return Linkset.LinksetMass;
- // return _mass;
+ return _mass;
}
}
@@ -400,22 +402,41 @@ public sealed class BSPrim : BSPhysObject
}
// Set the physical mass to the passed mass.
// Note that this does not change _mass!
- public override void UpdatePhysicalMassProperties(float physMass)
+ public override void UpdatePhysicalMassProperties(float physMass, bool inWorld)
{
- if (IsStatic)
+ if (PhysBody.HasPhysicalBody)
{
- Inertia = OMV.Vector3.Zero;
- BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
- BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
- }
- else
- {
- Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
- BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
- BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
- // center of mass is at the zero of the object
- // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
- DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia);
+ if (IsStatic)
+ {
+ Inertia = OMV.Vector3.Zero;
+ BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
+ BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ }
+ else
+ {
+ if (inWorld)
+ {
+ // Changing interesting properties doesn't change proxy and collision cache
+ // information. The Bullet solution is to re-add the object to the world
+ // after parameters are changed.
+ BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ }
+
+ float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
+ BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
+
+ Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
+ BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
+ BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ // center of mass is at the zero of the object
+ // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
+ DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia);
+
+ if (inWorld)
+ {
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ }
+ }
}
}
@@ -714,7 +735,7 @@ public sealed class BSPrim : BSPhysObject
Linkset.Refresh(this);
DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
- LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape);
+ LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape);
}
// "Making dynamic" means changing to and from static.
@@ -737,7 +758,7 @@ public sealed class BSPrim : BSPhysObject
BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
// Mass is zero which disables a bunch of physics stuff in Bullet
- UpdatePhysicalMassProperties(0f);
+ UpdatePhysicalMassProperties(0f, false);
// Set collision detection parameters
if (BSParam.CcdMotionThreshold > 0f)
{
@@ -777,7 +798,7 @@ public sealed class BSPrim : BSPhysObject
// DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
// A dynamic object has mass
- UpdatePhysicalMassProperties(RawMass);
+ UpdatePhysicalMassProperties(RawMass, false);
// Set collision detection parameters
if (BSParam.CcdMotionThreshold > 0f)
@@ -950,13 +971,9 @@ public sealed class BSPrim : BSPhysObject
set {
_buoyancy = value;
// DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
- // Buoyancy is faked by changing the gravity applied to the object
- if (PhysBody.HasPhysicalBody)
- {
- float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
- BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
- ActivateIfPhysical(false);
- }
+ // Force the recalculation of the various inertia,etc variables in the object
+ UpdatePhysicalMassProperties(_mass, true);
+ ActivateIfPhysical(false);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 9a7e965..0f27d67 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -1,11 +1,17 @@
CURRENT PRIORITIES
=================================================
-Smooth avatar movement with motor
- Should motor update be all at taint-time?
+Smooth avatar movement with motor (DONE)
+ Should motor update be all at taint-time? (Yes, DONE)
+ Fix avatar slowly sliding when standing (zero motion when stopped)
+llApplyImpulse()
+ Compare mass/movement in OS and SL. Calibrate actions.
+llSetBuoyancy()
+Boats float low in the water
Enable vehicle border crossings (at least as poorly as ODE)
Terrain skirts
Avatar created in previous region and not new region when crossing border
Vehicle recreated in new sim at small Z value (offset from root value?) (DONE)
+Add material densities to the material types.
Vehicle movement on terrain smoothness
Vehicle script tuning/debugging
Avanti speed script
@@ -52,6 +58,8 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl
BULLETSIM TODO LIST:
=================================================
+In SL, perfect spheres don't seem to have rolling friction. Add special case.
+Avatar density is WAY off. Compare and calibrate with what's in SL.
Revisit CollisionMargin. Builders notice the 0.04 spacing between prims.
Duplicating a physical prim causes old prim to jump away
Dup a phys prim and the original become unselected and thus interacts w/ selected prim.
@@ -82,6 +90,9 @@ Linkset.Position and Linkset.Orientation requre rewrite to properly return
Implement LockAngularMotion -- implements llSetStatus(ROTATE_AXIS_*, T/F)
Should the different PID factors have non-equal contributions for different
values of Efficiency?
+Selecting and deselecting physical objects causes CPU processing time to jump
+ http://www.youtube.com/watch?v=Hjg57fWg8yI&hd=1
+ put thousand physical objects, select and deselect same. CPU time will be large.
LINKSETS
======================================================
--
cgit v1.1
From 4759a8acee97fa175c078ec72d9b8cf0db96121b Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 24 Dec 2012 20:16:10 -0800
Subject: BulletSim: Default avatar density changed to 3.5 which is WAY closer
to the SL value. Fixed frictin values for physical materials which were just
wrong which caused things that should have slipped to not.
---
OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs | 16 ++++++++--------
OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
index c113a43..92d62ff 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSMaterials.cs
@@ -119,26 +119,26 @@ public static class BSMaterials
Attributes[(int)MaterialAttributes.Material.Light] =
new MaterialAttributes("light",dDensity, dFriction, dRestitution);
Attributes[(int)MaterialAttributes.Material.Avatar] =
- new MaterialAttributes("avatar",60f, 0.2f, 0f);
+ new MaterialAttributes("avatar",3.5f, 0.2f, 0f);
Attributes[(int)MaterialAttributes.Material.Stone + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("stonePhysical",dDensity, 0.8f, 0.4f);
Attributes[(int)MaterialAttributes.Material.Metal + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("metalPhysical",dDensity, 0.8f, 0.4f);
+ new MaterialAttributes("metalPhysical",dDensity, 0.3f, 0.4f);
Attributes[(int)MaterialAttributes.Material.Glass + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("glassPhysical",dDensity, 0.8f, 0.7f);
+ new MaterialAttributes("glassPhysical",dDensity, 0.2f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Wood + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("woodPhysical",dDensity, 0.8f, 0.5f);
+ new MaterialAttributes("woodPhysical",dDensity, 0.6f, 0.5f);
Attributes[(int)MaterialAttributes.Material.Flesh + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("fleshPhysical",dDensity, 0.8f, 0.3f);
+ new MaterialAttributes("fleshPhysical",dDensity, 0.9f, 0.3f);
Attributes[(int)MaterialAttributes.Material.Plastic + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("plasticPhysical",dDensity, 0.8f, 0.7f);
+ new MaterialAttributes("plasticPhysical",dDensity, 0.4f, 0.7f);
Attributes[(int)MaterialAttributes.Material.Rubber + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("rubberPhysical",dDensity, 0.8f, 0.9f);
+ new MaterialAttributes("rubberPhysical",dDensity, 0.9f, 0.9f);
Attributes[(int)MaterialAttributes.Material.Light + (int)MaterialAttributes.Material.NumberOfTypes] =
new MaterialAttributes("lightPhysical",dDensity, dFriction, dRestitution);
Attributes[(int)MaterialAttributes.Material.Avatar + (int)MaterialAttributes.Material.NumberOfTypes] =
- new MaterialAttributes("avatarPhysical",60f, 0.2f, 0f);
+ new MaterialAttributes("avatarPhysical",3.5f, 0.2f, 0f);
}
// Under the [BulletSim] section, one can change the individual material
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 5558ad5..7454718 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -351,7 +351,7 @@ public static class BSParam
(s) => { return AvatarStandingFriction; },
(s,p,l,v) => { AvatarStandingFriction = v; } ),
new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.",
- 60f,
+ 3.5f,
(s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); },
(s) => { return AvatarDensity; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{AvatarDensity=x;}, p, l, v); } ),
--
cgit v1.1
From bbc5a5089f79a4c5543f4a3f1cd4ffaf1de8c07e Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 24 Dec 2012 20:18:06 -0800
Subject: BulletSim: Rename some of the interface structures (BulletWorld, ...)
to get ready for... Start creation of BulletAPITemplate. This defines the
abstract interface functions. Following commits will move over to the new
interface. This will enable switching between the managed and unmanaged
version of Bullet.
---
.../Region/Physics/BulletSPlugin/BSConstraint.cs | 2 +-
.../Physics/BulletSPlugin/BSConstraint6Dof.cs | 4 +-
.../BulletSPlugin/BSConstraintCollection.cs | 4 +-
.../Physics/BulletSPlugin/BSConstraintHinge.cs | 2 +-
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 4 +-
.../Physics/BulletSPlugin/BSShapeCollection.cs | 6 +-
.../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 392 +++++++++++++++++++++
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 4 +-
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 7 +
9 files changed, 412 insertions(+), 13 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
index e77fb50..59584b2 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
@@ -36,7 +36,7 @@ public abstract class BSConstraint : IDisposable
{
private static string LogHeader = "[BULLETSIM CONSTRAINT]";
- protected BulletSim m_world;
+ protected BulletWorld m_world;
protected BulletBody m_body1;
protected BulletBody m_body2;
protected BulletConstraint m_constraint;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
index b073555..b946870 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
@@ -39,7 +39,7 @@ public sealed class BSConstraint6Dof : BSConstraint
public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } }
// Create a btGeneric6DofConstraint
- public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2,
+ public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1, Quaternion frame1rot,
Vector3 frame2, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
@@ -58,7 +58,7 @@ public sealed class BSConstraint6Dof : BSConstraint
obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
}
- public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2,
+ public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
index a9fd826..2aeff25 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintCollection.cs
@@ -41,9 +41,9 @@ public sealed class BSConstraintCollection : IDisposable
delegate bool ConstraintAction(BSConstraint constrain);
private List m_constraints;
- private BulletSim m_world;
+ private BulletWorld m_world;
- public BSConstraintCollection(BulletSim world)
+ public BSConstraintCollection(BulletWorld world)
{
m_world = world;
m_constraints = new List();
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
index ed3ffa7..a5378b9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
@@ -36,7 +36,7 @@ public sealed class BSConstraintHinge : BSConstraint
{
public override ConstraintType Type { get { return ConstraintType.HINGE_CONSTRAINT_TYPE; } }
- public BSConstraintHinge(BulletSim world, BulletBody obj1, BulletBody obj2,
+ public BSConstraintHinge(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotInA, Vector3 pivotInB,
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index e8e0d50..0022e45 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -74,7 +74,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
public IMesher mesher;
public uint WorldID { get; private set; }
- public BulletSim World { get; private set; }
+ public BulletWorld World { get; private set; }
// All the constraints that have been allocated in this instance.
public BSConstraintCollection Constraints { get; private set; }
@@ -242,7 +242,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
// m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader);
- World = new BulletSim(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(),
+ World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(),
m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
m_DebugLogCallbackHandle));
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 939d5e9..65ebcaa 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -98,7 +98,7 @@ public sealed class BSShapeCollection : IDisposable
// higher level dependencies on the shape or body. Mostly used for LinkSets to
// remove the physical constraints before the body is destroyed.
// Called at taint-time!!
- public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim,
+ public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim,
ShapeDestructionCallback shapeCallback, BodyDestructionCallback bodyCallback)
{
PhysicsScene.AssertInTaintTime("BSShapeCollection.GetBodyAndShape");
@@ -126,7 +126,7 @@ public sealed class BSShapeCollection : IDisposable
return ret;
}
- public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim)
+ public bool GetBodyAndShape(bool forceRebuild, BulletWorld sim, BSPhysObject prim)
{
return GetBodyAndShape(forceRebuild, sim, prim, null, null);
}
@@ -918,7 +918,7 @@ public sealed class BSShapeCollection : IDisposable
// Updates prim.BSBody with the information about the new body if one is created.
// Returns 'true' if an object was actually created.
// Called at taint-time.
- private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletSim sim, BulletShape shape,
+ private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BulletShape shape,
BodyDestructionCallback bodyCallback)
{
bool ret = false;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index 7857eaa..afe5bca 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -288,6 +288,398 @@ public enum ConstraintParamAxis : int
AXIS_ALL
};
+public abstract class BulletSimAPITemplate
+{
+// Initialization and simulation
+public abstract BulletWorld Initialize2(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray
+ );
+
+public abstract bool UpdateParameter2(BulletWorld world, uint localID, String parm, float value);
+
+public abstract void SetHeightMap2(BulletWorld world, float[] heightmap);
+
+public abstract void Shutdown2(BulletWorld sim);
+
+public abstract int PhysicsStep2(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount,
+ out IntPtr updatedEntitiesPtr,
+ out int collidersCount,
+ out IntPtr collidersPtr);
+
+public abstract bool PushUpdate2(BulletBody obj);
+
+// =====================================================================================
+// Mesh, hull, shape and body creation helper routines
+public abstract BulletShape CreateMeshShape2(BulletWorld world,
+ int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
+ int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
+
+public abstract BulletShape CreateHullShape2(BulletWorld world,
+ int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
+
+public abstract BulletShape BuildHullShapeFromMesh2(BulletWorld world, BulletShape meshShape);
+
+public abstract BulletShape BuildNativeShape2(BulletWorld world, ShapeData shapeData);
+
+public abstract bool IsNativeShape2(BulletShape shape);
+
+public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
+
+public abstract BulletShape BuildCapsuleShape2(BulletWorld world, float radius, float height, Vector3 scale);
+
+public abstract BulletShape CreateCompoundShape2(BulletWorld sim, bool enableDynamicAabbTree);
+
+public abstract int GetNumberOfCompoundChildren2(BulletShape cShape);
+
+public abstract void AddChildShapeToCompoundShape2(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
+
+public abstract BulletShape GetChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
+
+public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
+
+public abstract void RemoveChildShapeFromCompoundShape2(BulletShape cShape, BulletShape removeShape);
+
+public abstract void RecalculateCompoundShapeLocalAabb2(BulletShape cShape);
+
+public abstract BulletShape DuplicateCollisionShape2(BulletWorld sim, BulletShape srcShape, uint id);
+
+public abstract BulletBody CreateBodyFromShapeAndInfo2(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
+
+public abstract bool DeleteCollisionShape2(BulletWorld world, BulletShape shape);
+
+public abstract int GetBodyType2(BulletBody obj);
+
+public abstract BulletBody CreateBodyFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
+
+public abstract BulletBody CreateBodyWithDefaultMotionState2(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
+
+public abstract BulletBody CreateGhostFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
+
+public abstract IntPtr AllocateBodyInfo2(BulletBody obj);
+
+public abstract void ReleaseBodyInfo2(IntPtr obj);
+
+public abstract void DestroyObject2(BulletWorld sim, BulletBody obj);
+
+// =====================================================================================
+// Terrain creation and helper routines
+public abstract IntPtr CreateHeightMapInfo2(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+public abstract IntPtr FillHeightMapInfo2(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+public abstract bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
+
+public abstract BulletBody CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
+
+public abstract BulletBody CreateTerrainShape2(IntPtr mapInfo);
+
+// =====================================================================================
+// Constraint creation and helper routines
+public abstract BulletConstraint Create6DofConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 frame1loc, Quaternion frame1rot,
+ Vector3 frame2loc, Quaternion frame2rot,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public abstract BulletConstraint Create6DofConstraintToPoint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 joinPoint,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public abstract BulletConstraint CreateHingeConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 pivotinA, Vector3 pivotinB,
+ Vector3 axisInA, Vector3 axisInB,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public abstract void SetConstraintEnable2(BulletConstraint constrain, float numericTrueFalse);
+
+public abstract void SetConstraintNumSolverIterations2(BulletConstraint constrain, float iterations);
+
+public abstract bool SetFrames2(BulletConstraint constrain,
+ Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
+
+public abstract bool SetLinearLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
+
+public abstract bool SetAngularLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
+
+public abstract bool UseFrameOffset2(BulletConstraint constrain, float enable);
+
+public abstract bool TranslationalLimitMotor2(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
+
+public abstract bool SetBreakingImpulseThreshold2(BulletConstraint constrain, float threshold);
+
+public abstract bool CalculateTransforms2(BulletConstraint constrain);
+
+public abstract bool SetConstraintParam2(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
+
+public abstract bool DestroyConstraint2(BulletWorld world, BulletConstraint constrain);
+
+// =====================================================================================
+// btCollisionWorld entries
+public abstract void UpdateSingleAabb2(BulletWorld world, BulletBody obj);
+
+public abstract void UpdateAabbs2(BulletWorld world);
+
+public abstract bool GetForceUpdateAllAabbs2(BulletWorld world);
+
+public abstract void SetForceUpdateAllAabbs2(BulletWorld world, bool force);
+
+// =====================================================================================
+// btDynamicsWorld entries
+public abstract bool AddObjectToWorld2(BulletWorld world, BulletBody obj);
+
+public abstract bool RemoveObjectFromWorld2(BulletWorld world, BulletBody obj);
+
+public abstract bool AddConstraintToWorld2(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
+
+public abstract bool RemoveConstraintFromWorld2(BulletWorld world, BulletConstraint constrain);
+// =====================================================================================
+// btCollisionObject entries
+public abstract Vector3 GetAnisotripicFriction2(BulletConstraint constrain);
+
+public abstract Vector3 SetAnisotripicFriction2(BulletConstraint constrain, Vector3 frict);
+
+public abstract bool HasAnisotripicFriction2(BulletConstraint constrain);
+
+public abstract void SetContactProcessingThreshold2(BulletBody obj, float val);
+
+public abstract float GetContactProcessingThreshold2(BulletBody obj);
+
+public abstract bool IsStaticObject2(BulletBody obj);
+
+public abstract bool IsKinematicObject2(BulletBody obj);
+
+public abstract bool IsStaticOrKinematicObject2(BulletBody obj);
+
+public abstract bool HasContactResponse2(BulletBody obj);
+
+public abstract void SetCollisionShape2(BulletWorld sim, BulletBody obj, BulletBody shape);
+
+public abstract BulletShape GetCollisionShape2(BulletBody obj);
+
+public abstract int GetActivationState2(BulletBody obj);
+
+public abstract void SetActivationState2(BulletBody obj, int state);
+
+public abstract void SetDeactivationTime2(BulletBody obj, float dtime);
+
+public abstract float GetDeactivationTime2(BulletBody obj);
+
+public abstract void ForceActivationState2(BulletBody obj, ActivationState state);
+
+public abstract void Activate2(BulletBody obj, bool forceActivation);
+
+public abstract bool IsActive2(BulletBody obj);
+
+public abstract void SetRestitution2(BulletBody obj, float val);
+
+public abstract float GetRestitution2(BulletBody obj);
+
+public abstract void SetFriction2(BulletBody obj, float val);
+
+public abstract float GetFriction2(BulletBody obj);
+
+ /* Haven't defined the type 'Transform'
+public abstract Transform GetWorldTransform2(BulletBody obj);
+
+public abstract void setWorldTransform2(BulletBody obj, Transform trans);
+ */
+
+public abstract Vector3 GetPosition2(BulletBody obj);
+
+public abstract Quaternion GetOrientation2(BulletBody obj);
+
+public abstract void SetTranslation2(BulletBody obj, Vector3 position, Quaternion rotation);
+
+public abstract IntPtr GetBroadphaseHandle2(BulletBody obj);
+
+public abstract void SetBroadphaseHandle2(BulletBody obj, IntPtr handle);
+
+ /*
+public abstract Transform GetInterpolationWorldTransform2(IntPtr obj);
+
+public abstract void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
+ */
+
+public abstract void SetInterpolationLinearVelocity2(BulletBody obj, Vector3 vel);
+
+public abstract void SetInterpolationAngularVelocity2(BulletBody obj, Vector3 vel);
+
+public abstract void SetInterpolationVelocity2(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
+
+public abstract float GetHitFraction2(BulletBody obj);
+
+public abstract void SetHitFraction2(BulletBody obj, float val);
+
+public abstract CollisionFlags GetCollisionFlags2(BulletBody obj);
+
+public abstract CollisionFlags SetCollisionFlags2(BulletBody obj, CollisionFlags flags);
+
+public abstract CollisionFlags AddToCollisionFlags2(BulletBody obj, CollisionFlags flags);
+
+public abstract CollisionFlags RemoveFromCollisionFlags2(BulletBody obj, CollisionFlags flags);
+
+public abstract float GetCcdMotionThreshold2(BulletBody obj);
+
+public abstract void SetCcdMotionThreshold2(BulletBody obj, float val);
+
+public abstract float GetCcdSweptSphereRadius2(BulletBody obj);
+
+public abstract void SetCcdSweptSphereRadius2(BulletBody obj, float val);
+
+public abstract IntPtr GetUserPointer2(BulletBody obj);
+
+public abstract void SetUserPointer2(BulletBody obj, IntPtr val);
+
+// =====================================================================================
+// btRigidBody entries
+public abstract void ApplyGravity2(BulletBody obj);
+
+public abstract void SetGravity2(BulletBody obj, Vector3 val);
+
+public abstract Vector3 GetGravity2(BulletBody obj);
+
+public abstract void SetDamping2(BulletBody obj, float lin_damping, float ang_damping);
+
+public abstract void SetLinearDamping2(BulletBody obj, float lin_damping);
+
+public abstract void SetAngularDamping2(BulletBody obj, float ang_damping);
+
+public abstract float GetLinearDamping2(BulletBody obj);
+
+public abstract float GetAngularDamping2(BulletBody obj);
+
+public abstract float GetLinearSleepingThreshold2(BulletBody obj);
+
+
+public abstract void ApplyDamping2(BulletBody obj, float timeStep);
+
+public abstract void SetMassProps2(BulletBody obj, float mass, Vector3 inertia);
+
+public abstract Vector3 GetLinearFactor2(BulletBody obj);
+
+public abstract void SetLinearFactor2(BulletBody obj, Vector3 factor);
+
+ /*
+public abstract void SetCenterOfMassTransform2(BulletBody obj, Transform trans);
+ */
+
+public abstract void SetCenterOfMassByPosRot2(BulletBody obj, Vector3 pos, Quaternion rot);
+
+// Add a force to the object as if its mass is one.
+public abstract void ApplyCentralForce2(BulletBody obj, Vector3 force);
+
+// Set the force being applied to the object as if its mass is one.
+public abstract void SetObjectForce2(BulletBody obj, Vector3 force);
+
+public abstract Vector3 GetTotalForce2(BulletBody obj);
+
+public abstract Vector3 GetTotalTorque2(BulletBody obj);
+
+public abstract Vector3 GetInvInertiaDiagLocal2(BulletBody obj);
+
+public abstract void SetInvInertiaDiagLocal2(BulletBody obj, Vector3 inert);
+
+public abstract void SetSleepingThresholds2(BulletBody obj, float lin_threshold, float ang_threshold);
+
+public abstract void ApplyTorque2(BulletBody obj, Vector3 torque);
+
+// Apply force at the given point. Will add torque to the object.
+public abstract void ApplyForce2(BulletBody obj, Vector3 force, Vector3 pos);
+
+// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
+public abstract void ApplyCentralImpulse2(BulletBody obj, Vector3 imp);
+
+// Apply impulse to the object's torque. Force is scaled by object's mass.
+public abstract void ApplyTorqueImpulse2(BulletBody obj, Vector3 imp);
+
+// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
+public abstract void ApplyImpulse2(BulletBody obj, Vector3 imp, Vector3 pos);
+
+public abstract void ClearForces2(BulletBody obj);
+
+public abstract void ClearAllForces2(BulletBody obj);
+
+public abstract void UpdateInertiaTensor2(BulletBody obj);
+
+
+ /*
+public abstract Transform GetCenterOfMassTransform2(BulletBody obj);
+ */
+
+public abstract Vector3 GetLinearVelocity2(BulletBody obj);
+
+public abstract Vector3 GetAngularVelocity2(BulletBody obj);
+
+public abstract void SetLinearVelocity2(BulletBody obj, Vector3 val);
+
+public abstract void SetAngularVelocity2(BulletBody obj, Vector3 angularVelocity);
+
+public abstract Vector3 GetVelocityInLocalPoint2(BulletBody obj, Vector3 pos);
+
+public abstract void Translate2(BulletBody obj, Vector3 trans);
+
+public abstract void UpdateDeactivation2(BulletBody obj, float timeStep);
+
+public abstract bool WantsSleeping2(BulletBody obj);
+
+public abstract void SetAngularFactor2(BulletBody obj, float factor);
+
+public abstract void SetAngularFactorV2(BulletBody obj, Vector3 factor);
+
+public abstract Vector3 GetAngularFactor2(BulletBody obj);
+
+public abstract bool IsInWorld2(BulletBody obj);
+
+public abstract void AddConstraintRef2(BulletBody obj, BulletConstraint constrain);
+
+public abstract void RemoveConstraintRef2(BulletBody obj, BulletConstraint constrain);
+
+public abstract BulletConstraint GetConstraintRef2(BulletBody obj, int index);
+
+public abstract int GetNumConstraintRefs2(BulletBody obj);
+
+public abstract bool SetCollisionGroupMask2(BulletBody body, uint filter, uint mask);
+
+// =====================================================================================
+// btCollisionShape entries
+
+public abstract float GetAngularMotionDisc2(BulletShape shape);
+
+public abstract float GetContactBreakingThreshold2(BulletShape shape, float defaultFactor);
+
+public abstract bool IsPolyhedral2(BulletShape shape);
+
+public abstract bool IsConvex2d2(BulletShape shape);
+
+public abstract bool IsConvex2(BulletShape shape);
+
+public abstract bool IsNonMoving2(BulletShape shape);
+
+public abstract bool IsConcave2(BulletShape shape);
+
+public abstract bool IsCompound2(BulletShape shape);
+
+public abstract bool IsSoftBody2(BulletShape shape);
+
+public abstract bool IsInfinite2(BulletShape shape);
+
+public abstract void SetLocalScaling2(BulletShape shape, Vector3 scale);
+
+public abstract Vector3 GetLocalScaling2(BulletShape shape);
+
+public abstract Vector3 CalculateLocalInertia2(BulletShape shape, float mass);
+
+public abstract int GetShapeType2(BulletShape shape);
+
+public abstract void SetMargin2(BulletShape shape, float val);
+
+public abstract float GetMargin2(BulletShape shape);
+
+};
+
// ===============================================================================
static class BulletSimAPI {
// ===============================================================================
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 662177f..36d38d4 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -35,9 +35,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// These hold pointers to allocated objects in the unmanaged space.
// The physics engine controller class created at initialization
-public struct BulletSim
+public struct BulletWorld
{
- public BulletSim(uint worldId, BSScene bss, IntPtr xx)
+ public BulletWorld(uint worldId, BSScene bss, IntPtr xx)
{
ptr = xx;
worldID = worldId;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 0f27d67..35cb8f3 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -146,6 +146,13 @@ Is there are more efficient method of implementing pre and post step actions?
See http://www.codeproject.com/Articles/29922/Weak-Events-in-C
Physics Arena central pyramid: why is one side permiable?
+Enforce physical parameter min/max:
+ Gravity: [-1, 28]
+ Friction: [0, 255]
+ Density: [1, 22587]
+ Restitution [0, 1]
+ http://wiki.secondlife.com/wiki/Physics_Material_Settings_test
+Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/31796/1.html
INTERNAL IMPROVEMENT/CLEANUP
=================================================
--
cgit v1.1
From e98e223927226602d7a050bbb92ebb2904e81562 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 06:56:36 -0800
Subject: BulletSim: complete applyImpulse function in BSCharacter (like I said
I did last time).
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 25 +++++++++++++++-------
1 file changed, 17 insertions(+), 8 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 9f0d5af..cbc1772 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -683,22 +683,31 @@ public sealed class BSCharacter : BSPhysObject
public override void AddForce(OMV.Vector3 force, bool pushforce) {
if (force.IsFinite())
{
- _force.X += force.X;
- _force.Y += force.Y;
- _force.Z += force.Z;
- // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force);
+ float magnitude = force.Length();
+ if (magnitude > BSParam.MaxAddForceMagnitude)
+ {
+ // Force has a limit
+ force = force / magnitude * BSParam.MaxAddForceMagnitude;
+ }
+
+ OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep;
+ DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce);
+
PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate()
{
- DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force);
+ // Bullet adds this central force to the total force for this tick
+ DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
+ {
+ BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
+ }
});
}
else
{
- m_log.ErrorFormat("{0}: Got a NaN force applied to a Character", LogHeader);
+ m_log.WarnFormat("{0}: Got a NaN force applied to a character. LocalID={1}", LogHeader, LocalID);
+ return;
}
- //m_lastUpdateSent = false;
}
public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
--
cgit v1.1
From f3baed5827853c5041f042ff36cf394b1e45538f Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 06:58:07 -0800
Subject: BulletSim: add physical parameter min/max constants in BSParam. I
just don't like raw numbers scattered around the code.
---
OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 12 ++++++++++++
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 4 ++--
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 9 ---------
OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 1 +
4 files changed, 15 insertions(+), 11 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 7454718..8366cef 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -89,6 +89,18 @@ public static class BSParam
public static float PID_D { get; private set; } // derivative
public static float PID_P { get; private set; } // proportional
+ // Various constants that come from that other virtual world that shall not be named
+ public const float MinGravityZ = -1f;
+ public const float MaxGravityZ = 28f;
+ public const float MinFriction = 0f;
+ public const float MaxFriction = 255f;
+ public const float MinDensity = 0f;
+ public const float MaxDensity = 22587f;
+ public const float MinRestitution = 0f;
+ public const float MaxRestitution = 1f;
+ public const float MaxAddForceMagnitude = 20000f;
+
+ // ===========================================================================
public delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val);
public delegate float ParamGet(BSScene scene);
public delegate void ParamSet(BSScene scene, string paramName, uint localID, float val);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 9013414..c7a81e0 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -1025,10 +1025,10 @@ public sealed class BSPrim : BSPhysObject
if (force.IsFinite())
{
float magnitude = force.Length();
- if (magnitude > 20000f)
+ if (magnitude > BSParam.MaxAddForceMagnitude)
{
// Force has a limit
- force = force / magnitude * 20000f;
+ force = force / magnitude * BSParam.MaxAddForceMagnitude;
}
OMV.Vector3 addForce = force;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index b67c0ed..a5fbf10 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -38,15 +38,6 @@ using Nini.Config;
using log4net;
using OpenMetaverse;
-// TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim)
-// Based on material, set density and friction
-// More efficient memory usage when passing hull information from BSPrim to BulletSim
-// Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect
-// Implement LockAngularMotion
-// Add PID movement operations. What does ScenePresence.MoveToTarget do?
-// Check terrain size. 128 or 127?
-// Raycast
-//
namespace OpenSim.Region.Physics.BulletSPlugin
{
public sealed class BSScene : PhysicsScene, IPhysicsParameters
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 78cc26c..bc6dd7e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -96,6 +96,7 @@ Selecting and deselecting physical objects causes CPU processing time to jump
put thousand physical objects, select and deselect same. CPU time will be large.
Re-implement buoyancy as a separate force on the object rather than diddling gravity.
Register a pre-step event to add the force.
+More efficient memory usage when passing hull information from BSPrim to BulletSim
LINKSETS
======================================================
--
cgit v1.1
From 723099067976dfa71d18182378000df144d618af Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 10:09:31 -0800
Subject: BulletSim: fix odd code that wasn't really recomputing the mass of a
rebuilt linkset. I was burnt by making get/set methods with side effects. I
should know better.
---
OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index d5cbf5f..4e02904 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -98,11 +98,12 @@ public sealed class BSLinksetCompound : BSLinkset
// Schedule a refresh to happen after all the other taint processing.
private void ScheduleRebuild(BSPhysObject requestor)
{
- DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1}",
- requestor.LocalID, Rebuilding);
+ DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2}",
+ requestor.LocalID, Rebuilding, HasAnyChildren);
// When rebuilding, it is possible to set properties that would normally require a rebuild.
// If already rebuilding, don't request another rebuild.
- if (!Rebuilding)
+ // If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding.
+ if (!Rebuilding && HasAnyChildren)
{
PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate()
{
@@ -112,8 +113,7 @@ public sealed class BSLinksetCompound : BSLinkset
}
}
- // The object is going dynamic (physical). Do any setup necessary
- // for a dynamic linkset.
+ // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset.
// Only the state of the passed object can be modified. The rest of the linkset
// has not yet been fully constructed.
// Return 'true' if any properties updated on the passed object.
@@ -124,7 +124,7 @@ public sealed class BSLinksetCompound : BSLinkset
DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
if (IsRoot(child))
{
- // The root is going dynamic. Make sure mass is properly set.
+ // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly.
ScheduleRebuild(LinksetRoot);
}
else
@@ -378,7 +378,7 @@ public sealed class BSLinksetCompound : BSLinkset
});
// With all of the linkset packed into the root prim, it has the mass of everyone.
- LinksetMass = LinksetMass;
+ LinksetMass = ComputeLinksetMass();
LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true);
}
finally
--
cgit v1.1
From e57c0e6731bff376186ecba2530e76b697ab5887 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 13:13:35 -0800
Subject: BulletSim: fix buoyancy so it's properly set by a script when an
object is selected. Update TODO list.
---
.../Physics/BulletSPlugin/BSLinksetCompound.cs | 2 +-
OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs | 4 +--
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 29 +++++++++++++++++++---
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 24 ++++++++++++------
4 files changed, 44 insertions(+), 15 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 4e02904..19ce62b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -5,7 +5,7 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclat simer.
+ * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyrightD
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
index 9e1a9ba..817a5f7 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSMotors.cs
@@ -241,8 +241,8 @@ public class BSVMotor : BSMotor
public override string ToString()
{
- return String.Format("<{0},curr={1},targ={2},decayTS={3},frictTS={4}>",
- UseName, CurrentValue, TargetValue, TargetValueDecayTimeScale, FrictionTimescale);
+ return String.Format("<{0},curr={1},targ={2},lastErr={3},decayTS={4},frictTS={5}>",
+ UseName, CurrentValue, TargetValue, LastError, TargetValueDecayTimeScale, FrictionTimescale);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index c7a81e0..f804a0f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -94,7 +94,7 @@ public sealed class BSPrim : BSPhysObject
_size = size;
Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
_orientation = rotation;
- _buoyancy = 1f;
+ _buoyancy = 0f;
_velocity = OMV.Vector3.Zero;
_rotationalVelocity = OMV.Vector3.Zero;
BaseShape = pbs;
@@ -408,12 +408,15 @@ public sealed class BSPrim : BSPhysObject
{
if (IsStatic)
{
+ BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity);
Inertia = OMV.Vector3.Zero;
BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
}
else
{
+ OMV.Vector3 grav = ComputeGravity();
+
if (inWorld)
{
// Changing interesting properties doesn't change proxy and collision cache
@@ -422,13 +425,16 @@ public sealed class BSPrim : BSPhysObject
BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
}
+ // The computation of mass props requires gravity to be set on the object.
+ BulletSimAPI.SetGravity2(PhysBody.ptr, grav);
+
Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
// center of mass is at the zero of the object
// DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
- DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},inWorld={3}", LocalID, physMass, Inertia, inWorld);
+ DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld);
if (inWorld)
{
@@ -437,13 +443,23 @@ public sealed class BSPrim : BSPhysObject
// Must set gravity after it has been added to the world because, for unknown reasons,
// adding the object resets the object's gravity to world gravity
- OMV.Vector3 grav = PhysicsScene.DefaultGravity * (1f - Buoyancy);
BulletSimAPI.SetGravity2(PhysBody.ptr, grav);
}
}
}
+ // Return what gravity should be set to this very moment
+ private OMV.Vector3 ComputeGravity()
+ {
+ OMV.Vector3 ret = PhysicsScene.DefaultGravity;
+
+ if (!IsStatic)
+ ret *= (1f - Buoyancy);
+
+ return ret;
+ }
+
// Is this used?
public override OMV.Vector3 CenterOfMass
{
@@ -669,7 +685,7 @@ public sealed class BSPrim : BSPhysObject
_isPhysical = value;
PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate()
{
- // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical);
+ DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical);
SetObjectDynamic(true);
// whether phys-to-static or static-to-phys, the object is not moving.
ZeroMotion(true);
@@ -726,6 +742,10 @@ public sealed class BSPrim : BSPhysObject
BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
+ // Replace this when the new AddObjectToWorld function is complete.
+ BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity());
+
// Rebuild its shape
BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
@@ -976,6 +996,7 @@ public sealed class BSPrim : BSPhysObject
_buoyancy = value;
// DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
// Force the recalculation of the various inertia,etc variables in the object
+ DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2}", LocalID, _buoyancy, _mass);
UpdatePhysicalMassProperties(_mass, true);
ActivateIfPhysical(false);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index bc6dd7e..a66508a 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -1,22 +1,21 @@
CURRENT PRIORITIES
=================================================
-Smooth avatar movement with motor (DONE)
- Should motor update be all at taint-time? (Yes, DONE)
- Fix avatar slowly sliding when standing (zero motion when stopped)
-llApplyImpulse()
- Compare mass/movement in OS and SL. Calibrate actions.
-llSetBuoyancy()
-Boats float low in the water
+Redo BulletSimAPI to allow native C# implementation of Bullet option.
+Avatar movement
+ flying into a wall doesn't stop avatar who keeps appearing to move through the obsticle
+ walking up stairs is not calibrated correctly (stairs out of Kepler cabin)
+ avatar capsule rotation completed
Enable vehicle border crossings (at least as poorly as ODE)
Terrain skirts
Avatar created in previous region and not new region when crossing border
Vehicle recreated in new sim at small Z value (offset from root value?) (DONE)
-Add material densities to the material types.
Vehicle movement on terrain smoothness
Vehicle script tuning/debugging
Avanti speed script
Weapon shooter script
limitMotorUp calibration (more down?)
+Boats float low in the water
+Add material densities to the material types.
CRASHES
=================================================
@@ -243,3 +242,12 @@ Should vehicle angular/linear movement friction happen after all the components
What is expected by some vehicles (turning up friction to moderate speed))
Tune terrain/object friction to be closer to SL.
(Resolution: added material type with friction and resolution)
+Smooth avatar movement with motor (DONE)
+ Should motor update be all at taint-time? (Yes, DONE)
+ Fix avatar slowly sliding when standing (zero motion when stopped) (DONE)
+ (Resolution: added BSVMotor for avatar starting and stopping)
+llApplyImpulse()
+ Compare mass/movement in OS and SL. Calibrate actions. (DONE)
+ (Resolution: tested on SL and OS. AddForce scales the force for timestep)
+llSetBuoyancy() (DONE)
+ (Resolution: Bullet resets object gravity when added to world. Moved set gravity)
--
cgit v1.1
From 5afab9bcfe9e163219cf6b4317a8914860e3f969 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 16:03:14 -0800
Subject: Add check to always push terse updates for presences that have new
velocities of zero.
---
OpenSim/Region/Framework/Scenes/ScenePresence.cs | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 58721b0..a60c551 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -2335,9 +2335,14 @@ namespace OpenSim.Region.Framework.Scenes
// storing a requested force instead of an actual traveling velocity
// Throw away duplicate or insignificant updates
- if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
- !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
- !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
+ if (
+ // If the velocity has become zero, send it no matter what.
+ (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
+ // otherwise, if things have changed reasonably, send the update
+ || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
+ || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
+ || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
+
{
SendTerseUpdateToAllClients();
--
cgit v1.1
From 7a5f598399c7373bd146061b478e6d04cb204879 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 16:05:11 -0800
Subject: BulletSim: move logic for IsColliding, CollidingGround and
CollidingObj from individual sub-classes and up to parent BSPhysObject class.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 36 ++++++++-------------
.../Region/Physics/BulletSPlugin/BSPhysObject.cs | 37 +++++++++++++++++++++-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 18 ++---------
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 3 +-
4 files changed, 55 insertions(+), 39 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index cbc1772..3f7b5e1 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -584,18 +584,6 @@ public sealed class BSCharacter : BSPhysObject
get { return _throttleUpdates; }
set { _throttleUpdates = value; }
}
- public override bool IsColliding {
- get { return (CollidingStep == PhysicsScene.SimulationStep); }
- set { _isColliding = value; }
- }
- public override bool CollidingGround {
- get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
- set { CollidingGround = value; }
- }
- public override bool CollidingObj {
- get { return _collidingObj; }
- set { _collidingObj = value; }
- }
public override bool FloatOnWater {
set {
_floatOnWater = value;
@@ -769,22 +757,26 @@ public sealed class BSCharacter : BSPhysObject
OMV.Vector3 stepVelocity = _velocityMotor.Step(PhysicsScene.LastTimeStep);
- // If falling, we keep the world's downward vector no matter what the other axis specify.
- if (!Flying && !IsColliding)
- {
- stepVelocity.Z = entprop.Velocity.Z;
- DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
- }
-
- // If the user has said stop and we've stopped applying velocity correction,
- // the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer.
- if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero)
+ // Check for cases to turn off the motor.
+ if (
+ // If the walking motor is all done, turn it off
+ (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) )
{
ZeroMotion(true);
stepVelocity = OMV.Vector3.Zero;
_velocityMotor.Enabled = false;
DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor);
}
+ else
+ {
+ // If the motor is not being turned off...
+ // If falling, we keep the world's downward vector no matter what the other axis specify.
+ if (!Flying && !IsColliding)
+ {
+ stepVelocity.Z = entprop.Velocity.Z;
+ DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
+ }
+ }
_velocity = stepVelocity;
entprop.Velocity = _velocity;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 4bed535..73b5764 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -182,9 +182,40 @@ public abstract class BSPhysObject : PhysicsActor
protected long CollidingStep { get; set; }
// The simulation step that last had a collision with the ground
protected long CollidingGroundStep { get; set; }
+ // The simulation step that last collided with an object
+ protected long CollidingObjectStep { get; set; }
// The collision flags we think are set in Bullet
protected CollisionFlags CurrentCollisionFlags { get; set; }
+ public override bool IsColliding {
+ get { return (CollidingStep == PhysicsScene.SimulationStep); }
+ set {
+ if (value)
+ CollidingStep = PhysicsScene.SimulationStep;
+ else
+ CollidingStep = 0;
+ }
+ }
+ public override bool CollidingGround {
+ get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
+ set
+ {
+ if (value)
+ CollidingGroundStep = PhysicsScene.SimulationStep;
+ else
+ CollidingGroundStep = 0;
+ }
+ }
+ public override bool CollidingObj {
+ get { return (CollidingObjectStep == PhysicsScene.SimulationStep); }
+ set {
+ if (value)
+ CollidingObjectStep = PhysicsScene.SimulationStep;
+ else
+ CollidingObjectStep = 0;
+ }
+ }
+
// The collisions that have been collected this tick
protected CollisionEventUpdate CollisionCollection;
@@ -196,12 +227,16 @@ public abstract class BSPhysObject : PhysicsActor
{
bool ret = false;
- // The following lines make IsColliding() and IsCollidingGround() work
+ // The following lines make IsColliding(), CollidingGround() and CollidingObj work
CollidingStep = PhysicsScene.SimulationStep;
if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID)
{
CollidingGroundStep = PhysicsScene.SimulationStep;
}
+ else
+ {
+ CollidingObjectStep = PhysicsScene.SimulationStep;
+ }
// prims in the same linkset cannot collide with each other
if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID))
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index f804a0f..06e4ada 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -915,18 +915,6 @@ public sealed class BSPrim : BSPhysObject
get { return _throttleUpdates; }
set { _throttleUpdates = value; }
}
- public override bool IsColliding {
- get { return (CollidingStep == PhysicsScene.SimulationStep); }
- set { _isColliding = value; }
- }
- public override bool CollidingGround {
- get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
- set { _collidingGround = value; }
- }
- public override bool CollidingObj {
- get { return _collidingObj; }
- set { _collidingObj = value; }
- }
public bool IsPhantom {
get {
// SceneObjectPart removes phantom objects from the physics scene
@@ -1006,12 +994,12 @@ public sealed class BSPrim : BSPhysObject
public override OMV.Vector3 PIDTarget {
set { _PIDTarget = value; }
}
- public override bool PIDActive {
- set { _usePID = value; }
- }
public override float PIDTau {
set { _PIDTau = value; }
}
+ public override bool PIDActive {
+ set { _usePID = value; }
+ }
// Used for llSetHoverHeight and maybe vehicle height
// Hover Height will override MoveTo target's Z
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index a66508a..16131cd 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -2,9 +2,10 @@ CURRENT PRIORITIES
=================================================
Redo BulletSimAPI to allow native C# implementation of Bullet option.
Avatar movement
- flying into a wall doesn't stop avatar who keeps appearing to move through the obsticle
+ flying into a wall doesn't stop avatar who keeps appearing to move through the obstacle
walking up stairs is not calibrated correctly (stairs out of Kepler cabin)
avatar capsule rotation completed
+llMoveToTarget
Enable vehicle border crossings (at least as poorly as ODE)
Terrain skirts
Avatar created in previous region and not new region when crossing border
--
cgit v1.1
From c1e7539c77480b839d513dbb7db74aa8f260eba0 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 18:19:25 -0800
Subject: BulletSim: Parameterize nominal frame rate (55) and add parameters to
dynamially turn on/off detailed, unmanaged data dumping of prims and
vehicles.
---
OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 6 ++++++
OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 5 +++++
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 4 ++--
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 11 ++++++++---
4 files changed, 21 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index a8edd23..0bdfbe3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -822,6 +822,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
if (!IsActive) return;
+ if (PhysicsScene.VehiclePhysicalLoggingEnabled)
+ BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr);
+
ForgetKnownVehicleProperties();
MoveLinear(pTimestep);
@@ -836,6 +839,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// for the physics engine to note the changes so an UpdateProperties event will happen.
PushKnownChanged();
+ if (PhysicsScene.VehiclePhysicalLoggingEnabled)
+ BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr);
+
VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}",
Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 8366cef..f8f24bd 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -212,6 +212,11 @@ public static class BSParam
(s,cf,p,v) => { s.m_fixedTimeStep = cf.GetFloat(p, v); },
(s) => { return (float)s.m_fixedTimeStep; },
(s,p,l,v) => { s.m_fixedTimeStep = v; } ),
+ new ParameterDefn("NominalFrameRate", "The base frame rate we claim",
+ 55f,
+ (s,cf,p,v) => { s.NominalFrameRate = cf.GetInt(p, (int)v); },
+ (s) => { return (float)s.NominalFrameRate; },
+ (s,p,l,v) => { s.NominalFrameRate = (int)v; } ),
new ParameterDefn("MaxCollisionsPerFrame", "Max collisions returned at end of each frame",
2048f,
(s,cf,p,v) => { s.m_maxCollisionsPerFrame = cf.GetInt(p, (int)v); },
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 06e4ada..2d429c4 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -758,8 +758,8 @@ public sealed class BSPrim : BSPhysObject
// For compound based linksets, this enables and disables interactions of the children.
Linkset.Refresh(this);
- DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
- LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},cType={6},body={7},shape={8}",
+ LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody.collisionType, PhysBody, PhysShape);
}
// "Making dynamic" means changing to and from static.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index a5fbf10..8edcd20 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -74,6 +74,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
internal int m_maxSubSteps;
internal float m_fixedTimeStep;
internal long m_simulationStep = 0;
+ internal float NominalFrameRate { get; set; }
public long SimulationStep { get { return m_simulationStep; } }
internal int m_taintsToProcessPerStep;
internal float LastTimeStep { get; private set; }
@@ -162,6 +163,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
private string m_physicsLoggingPrefix;
private int m_physicsLoggingFileMinutes;
private bool m_physicsLoggingDoFlush;
+ private bool m_physicsPhysicalDumpEnabled;
// 'true' of the vehicle code is to log lots of details
public bool VehicleLoggingEnabled { get; private set; }
public bool VehiclePhysicalLoggingEnabled { get; private set; }
@@ -272,6 +274,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-");
m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5);
m_physicsLoggingDoFlush = pConfig.GetBoolean("PhysicsLoggingDoFlush", false);
+ m_physicsPhysicalDumpEnabled = pConfig.GetBoolean("PhysicsPhysicalDumpEnabled", false);
// Very detailed logging for vehicle debugging
VehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false);
VehiclePhysicalLoggingEnabled = pConfig.GetBoolean("VehiclePhysicalLoggingEnabled", false);
@@ -488,7 +491,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
// Only enable this in a limited test world with few objects.
- // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG
+ if (m_physicsPhysicalDumpEnabled)
+ BulletSimAPI.DumpAllInfo2(World.ptr);
// step the physical world one interval
m_simulationStep++;
@@ -587,12 +591,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
// Only enable this in a limited test world with few objects.
- // BulletSimAPI.DumpAllInfo2(World.ptr); // DEBUG DEBUG DEBUG
+ if (m_physicsPhysicalDumpEnabled)
+ BulletSimAPI.DumpAllInfo2(World.ptr);
// The physics engine returns the number of milliseconds it simulated this call.
// These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
// Multiply by 55 to give a nominal frame rate of 55.
- return (float)numSubSteps * m_fixedTimeStep * 1000f * 55f;
+ return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate;
}
// Something has collided
--
cgit v1.1
From 422f0fd6ec6e30c5200dbf81875c64223002f9c7 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 22:02:38 -0800
Subject: BulletSim: fix physical object not interacting with static objects.
Another instance of the underlying Bullet doing, ah, helpful things when
items are added to the world.
---
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 33 +++++++++++++++++++-------
1 file changed, 24 insertions(+), 9 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 2d429c4..5f3f0d1 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -438,7 +438,7 @@ public sealed class BSPrim : BSPhysObject
if (inWorld)
{
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ AddObjectToPhysicalWorld();
}
// Must set gravity after it has been added to the world because, for unknown reasons,
@@ -740,18 +740,11 @@ public sealed class BSPrim : BSPhysObject
// Make solid or not (do things bounce off or pass through this object).
MakeSolid(IsSolid);
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
-
- // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
- // Replace this when the new AddObjectToWorld function is complete.
- BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity());
+ AddObjectToPhysicalWorld();
// Rebuild its shape
BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
- // Collision filter can be set only when the object is in the world
- PhysBody.ApplyCollisionMask();
-
// Recompute any linkset parameters.
// When going from non-physical to physical, this re-enables the constraints that
// had been automatically disabled when the mass was set to zero.
@@ -900,6 +893,28 @@ public sealed class BSPrim : BSPhysObject
}
}
+ // Add me to the physical world.
+ // Object MUST NOT already be in the world.
+ // This routine exists because some assorted properties get mangled by adding to the world.
+ internal void AddObjectToPhysicalWorld()
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+
+ // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
+ // Replace this when the new AddObjectToWorld function is complete.
+ BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity());
+
+ // Collision filter can be set only when the object is in the world
+ if (!PhysBody.ApplyCollisionMask())
+ {
+ m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
+ }
+ }
+ }
+
// prims don't fly
public override bool Flying {
get { return _flying; }
--
cgit v1.1
From 1f6aaad0b587f1589afd7a7ca6feb8d2bbba8641 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 27 Dec 2012 22:04:12 -0800
Subject: BulletSim: correct collision mask definition for linkset children.
Remove unused code. Add comments and TODOs.
---
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 1 +
.../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 24 +++++++++----------
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 27 ++++------------------
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 1 +
4 files changed, 18 insertions(+), 35 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 8edcd20..4133107 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -269,6 +269,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
BSParam.SetParameterConfigurationValues(this, pConfig);
// Very detailed logging for physics debugging
+ // TODO: the boolean values can be moved to the normal parameter processing.
m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false);
m_physicsLoggingDir = pConfig.GetString("PhysicsLoggingDir", ".");
m_physicsLoggingPrefix = pConfig.GetString("PhysicsLoggingPrefix", "physics-%REGIONNAME%-");
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index afe5bca..eb4d039 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -250,20 +250,20 @@ public enum CollisionFilterGroups : uint
// filter/mask definition below. This way collision interactions
// are more easily found and debugged.
BNoneGroup = 0,
- BDefaultGroup = 1 << 0,
- BStaticGroup = 1 << 1,
- BKinematicGroup = 1 << 2,
- BDebrisGroup = 1 << 3,
- BSensorTrigger = 1 << 4,
- BCharacterGroup = 1 << 5,
- BAllGroup = 0xFFFFFFFF,
+ BDefaultGroup = 1 << 0, // 0001
+ BStaticGroup = 1 << 1, // 0002
+ BKinematicGroup = 1 << 2, // 0004
+ BDebrisGroup = 1 << 3, // 0008
+ BSensorTrigger = 1 << 4, // 0010
+ BCharacterGroup = 1 << 5, // 0020
+ BAllGroup = 0x000FFFFF,
// Filter groups defined by BulletSim
- BGroundPlaneGroup = 1 << 10,
- BTerrainGroup = 1 << 11,
- BRaycastGroup = 1 << 12,
- BSolidGroup = 1 << 13,
+ BGroundPlaneGroup = 1 << 10, // 0400
+ BTerrainGroup = 1 << 11, // 0800
+ BRaycastGroup = 1 << 12, // 1000
+ BSolidGroup = 1 << 13, // 2000
// BLinksetGroup = xx // a linkset proper is either static or dynamic
- BLinksetChildGroup = 1 << 14,
+ BLinksetChildGroup = 1 << 14, // 4000
};
// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 36d38d4..5ad6746 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -72,12 +72,12 @@ public struct BulletBody
public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } }
// Apply the specificed collision mask into the physical world
- public void ApplyCollisionMask()
+ public bool ApplyCollisionMask()
{
// Should assert the body has been added to the physical world.
// (The collision masks are stored in the collision proxy cache which only exists for
// a collision body that is in the world.)
- BulletSimAPI.SetCollisionGroupMask2(ptr,
+ return BulletSimAPI.SetCollisionGroupMask2(ptr,
BulletSimData.CollisionTypeMasks[collisionType].group,
BulletSimData.CollisionTypeMasks[collisionType].mask);
}
@@ -207,26 +207,6 @@ public struct CollisionTypeFilterGroup
public uint mask;
};
- /* NOTE: old definitions kept for reference. Delete when things are working.
- // The collsion filters and masked are defined in one place -- don't want them scattered
- AvatarGroup = BCharacterGroup,
- AvatarMask = BAllGroup,
- ObjectGroup = BSolidGroup,
- ObjectMask = BAllGroup,
- StaticObjectGroup = BStaticGroup,
- StaticObjectMask = AvatarGroup | ObjectGroup, // static things don't interact with much
- LinksetGroup = BLinksetGroup,
- LinksetMask = BAllGroup,
- LinksetChildGroup = BLinksetChildGroup,
- LinksetChildMask = BNoneGroup, // Linkset children disappear from the world
- VolumeDetectGroup = BSensorTrigger,
- VolumeDetectMask = ~BSensorTrigger,
- TerrainGroup = BTerrainGroup,
- TerrainMask = BAllGroup & ~BStaticGroup, // static objects on the ground don't collide
- GroundPlaneGroup = BGroundPlaneGroup,
- GroundPlaneMask = BAllGroup
- */
-
public static class BulletSimData
{
@@ -269,8 +249,9 @@ public static Dictionary CollisionTypeM
},
{ CollisionType.LinksetChild,
new CollisionTypeFilterGroup(CollisionType.LinksetChild,
- (uint)CollisionFilterGroups.BTerrainGroup,
+ (uint)CollisionFilterGroups.BLinksetChildGroup,
(uint)(CollisionFilterGroups.BNoneGroup))
+ // (uint)(CollisionFilterGroups.BCharacterGroup | CollisionFilterGroups.BSolidGroup))
},
};
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 16131cd..f805836 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -194,6 +194,7 @@ Should taints check for existance or activeness of target?
actually gone when the taint happens. Crashes don't happen because the taint closure
keeps the object from being freed, but that is just an accident.
Possibly have and 'active' flag that is checked by the taint processor?
+Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones)
THREADING
=================================================
--
cgit v1.1
From 70e0a86601ed33113a87189ee53a40e12790c609 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 28 Dec 2012 11:56:07 -0800
Subject: BulletSim: fix problem of avatars appearing to walk through walls by
moving the movement motor to a pre-step action and out of its questionable
previous home in UpdateProperties.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 106 +++++++++++----------
1 file changed, 55 insertions(+), 51 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 3f7b5e1..90936d0 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -91,17 +91,7 @@ public sealed class BSCharacter : BSPhysObject
if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
- // A motor to control the acceleration and deceleration of the avatar movement.
- // _velocityMotor = new BSVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f);
- // _velocityMotor = new BSPIDVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f);
- // Infinite decay and timescale values so motor only changes current to target values.
- _velocityMotor = new BSVMotor("BSCharacter.Velocity",
- 0.2f, // time scale
- BSMotor.Infinite, // decay time scale
- BSMotor.InfiniteVector, // friction timescale
- 1f // efficiency
- );
- _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages.
+ SetupMovementMotor();
_flying = isFlying;
_orientation = OMV.Quaternion.Identity;
@@ -152,13 +142,12 @@ public sealed class BSCharacter : BSPhysObject
ZeroMotion(true);
ForcePosition = _position;
+
// Set the velocity and compute the proper friction
- ForceVelocity = _velocity;
- // Setting the current and target in the motor will cause it to start computing any deceleration.
_velocityMotor.Reset();
- _velocityMotor.SetCurrent(_velocity);
_velocityMotor.SetTarget(_velocity);
- _velocityMotor.Enabled = false;
+ _velocityMotor.SetCurrent(_velocity);
+ ForceVelocity = _velocity;
// This will enable or disable the flying buoyancy of the avatar.
// Needs to be reset especially when an avatar is recreated after crossing a region boundry.
@@ -192,6 +181,48 @@ public sealed class BSCharacter : BSPhysObject
PhysBody.ApplyCollisionMask();
}
+ // The avatar's movement is controlled by this motor that speeds up and slows down
+ // the avatar seeking to reach the motor's target speed.
+ // This motor runs as a prestep action for the avatar so it will keep the avatar
+ // standing as well as moving. Destruction of the avatar will destroy the pre-step action.
+ private void SetupMovementMotor()
+ {
+
+ // Someday, use a PID motor for asymmetric speed up and slow down
+ // _velocityMotor = new BSPIDVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f);
+
+ // Infinite decay and timescale values so motor only changes current to target values.
+ _velocityMotor = new BSVMotor("BSCharacter.Velocity",
+ 0.2f, // time scale
+ BSMotor.Infinite, // decay time scale
+ BSMotor.InfiniteVector, // friction timescale
+ 1f // efficiency
+ );
+ // _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages.
+
+ RegisterPreStepAction("BSCharactor.Movement", LocalID, delegate(float timeStep)
+ {
+ // TODO: Decide if the step parameters should be changed depending on the avatar's
+ // state (flying, colliding, ...). There is code in ODE to do this.
+
+ OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep);
+
+ // If falling, we keep the world's downward vector no matter what the other axis specify.
+ if (!Flying && !IsColliding)
+ {
+ stepVelocity.Z = _velocity.Z;
+ DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}",
+ LocalID, stepVelocity);
+ }
+
+ // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
+ OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass / PhysicsScene.LastTimeStep;
+ DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
+ LocalID, stepVelocity, _velocity, Mass, moveForce);
+ AddForce(moveForce, false, true);
+ });
+ }
+
public override void RequestPhysicsterseUpdate()
{
base.RequestPhysicsterseUpdate();
@@ -668,7 +699,13 @@ public sealed class BSCharacter : BSPhysObject
public override float APIDStrength { set { return; } }
public override float APIDDamping { set { return; } }
- public override void AddForce(OMV.Vector3 force, bool pushforce) {
+ public override void AddForce(OMV.Vector3 force, bool pushforce)
+ {
+ // Since this force is being applied in only one step, make this a force per second.
+ OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep;
+ AddForce(addForce, pushforce, false);
+ }
+ private void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) {
if (force.IsFinite())
{
float magnitude = force.Length();
@@ -678,10 +715,10 @@ public sealed class BSCharacter : BSPhysObject
force = force / magnitude * BSParam.MaxAddForceMagnitude;
}
- OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep;
+ OMV.Vector3 addForce = force;
DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce);
- PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate()
+ PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate()
{
// Bullet adds this central force to the total force for this tick
DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
@@ -750,39 +787,6 @@ public sealed class BSCharacter : BSPhysObject
// Do some sanity checking for the avatar. Make sure it's above ground and inbounds.
PositionSanityCheck(true);
- if (_velocityMotor.Enabled)
- {
- // TODO: Decide if the step parameters should be changed depending on the avatar's
- // state (flying, colliding, ...).
-
- OMV.Vector3 stepVelocity = _velocityMotor.Step(PhysicsScene.LastTimeStep);
-
- // Check for cases to turn off the motor.
- if (
- // If the walking motor is all done, turn it off
- (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) )
- {
- ZeroMotion(true);
- stepVelocity = OMV.Vector3.Zero;
- _velocityMotor.Enabled = false;
- DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor);
- }
- else
- {
- // If the motor is not being turned off...
- // If falling, we keep the world's downward vector no matter what the other axis specify.
- if (!Flying && !IsColliding)
- {
- stepVelocity.Z = entprop.Velocity.Z;
- DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
- }
- }
-
- _velocity = stepVelocity;
- entprop.Velocity = _velocity;
- BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
- }
-
// remember the current and last set values
LastEntityProperties = CurrentEntityProperties;
CurrentEntityProperties = entprop;
--
cgit v1.1
From 7266eeca6efd10852a062cfc802a50c346b7b119 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 28 Dec 2012 12:01:57 -0800
Subject: BulletSim: add 'AvatarAlwaysRunFactor' parameter and use in
setTargetVelocity to implement the 'always run' feature.
---
OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 6 +++---
OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 6 ++++++
2 files changed, 9 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 90936d0..901f976 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -464,15 +464,15 @@ public sealed class BSCharacter : BSPhysObject
{
DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value);
OMV.Vector3 targetVel = value;
+ if (_setAlwaysRun)
+ targetVel *= BSParam.AvatarAlwaysRunFactor;
+
PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate()
{
_velocityMotor.Reset();
_velocityMotor.SetTarget(targetVel);
_velocityMotor.SetCurrent(_velocity);
_velocityMotor.Enabled = true;
-
- // Make sure a property update happens next step so the motor gets incorporated.
- BulletSimAPI.PushUpdate2(PhysBody.ptr);
});
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index f8f24bd..5c8553a 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -68,6 +68,7 @@ public static class BSParam
// Avatar parameters
public static float AvatarFriction { get; private set; }
public static float AvatarStandingFriction { get; private set; }
+ public static float AvatarAlwaysRunFactor { get; private set; }
public static float AvatarDensity { get; private set; }
public static float AvatarRestitution { get; private set; }
public static float AvatarCapsuleWidth { get; private set; }
@@ -367,6 +368,11 @@ public static class BSParam
(s,cf,p,v) => { AvatarStandingFriction = cf.GetFloat(p, v); },
(s) => { return AvatarStandingFriction; },
(s,p,l,v) => { AvatarStandingFriction = v; } ),
+ new ParameterDefn("AvatarAlwaysRunFactor", "Speed multiplier if avatar is set to always run",
+ 1.3f,
+ (s,cf,p,v) => { AvatarAlwaysRunFactor = cf.GetFloat(p, v); },
+ (s) => { return AvatarAlwaysRunFactor; },
+ (s,p,l,v) => { AvatarAlwaysRunFactor = v; } ),
new ParameterDefn("AvatarDensity", "Density of an avatar. Changed on avatar recreation.",
3.5f,
(s,cf,p,v) => { AvatarDensity = cf.GetFloat(p, v); },
--
cgit v1.1
From fdf8732cd712d8a5799a817e61d4c68e204ba9a2 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 28 Dec 2012 16:29:16 -0800
Subject: ScenePresence passes the avatar rotation down to the physics engine.
This will be a no-op for ODE but enables asymmetrical avatars for BulletSim.
---
OpenSim/Region/Framework/Scenes/ScenePresence.cs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index a60c551..0219540 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -560,6 +560,10 @@ namespace OpenSim.Region.Framework.Scenes
set
{
m_bodyRot = value;
+ if (PhysicsActor != null)
+ {
+ PhysicsActor.Orientation = m_bodyRot;
+ }
// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot);
}
}
--
cgit v1.1
From db6c0363f05db8b2a180eff04db9138a378d227f Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 08:03:57 -0800
Subject: BulletSim: tweeking avatar capsule code in an attempt to have
asymmetrical avatar capsule work now that rotation is being passed from the
simulator. Turns out the Bullet capsule is just not very functional: it
doesn't scale properly, the implementation only half does asymmetry and, in
general, is hard to work with. Avatar shape is about what it was before these
changes. Added initial data structures for avatar shape mesh.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 104 ++++++++++++---------
.../Physics/BulletSPlugin/BSShapeCollection.cs | 6 +-
OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 13 +++
.../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 4 +-
4 files changed, 81 insertions(+), 46 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 901f976..9659542 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -66,7 +66,6 @@ public sealed class BSCharacter : BSPhysObject
private float _buoyancy;
// The friction and velocity of the avatar is modified depending on whether walking or not.
- private OMV.Vector3 _appliedVelocity; // the last velocity applied to the avatar
private float _currentFriction; // the friction currently being used (changed by setVelocity).
private BSVMotor _velocityMotor;
@@ -85,27 +84,27 @@ public sealed class BSCharacter : BSPhysObject
_physicsActorType = (int)ActorTypes.Agent;
_position = pos;
- // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
- // replace with the default values.
- _size = size;
- if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
- if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
-
- SetupMovementMotor();
-
_flying = isFlying;
_orientation = OMV.Quaternion.Identity;
_velocity = OMV.Vector3.Zero;
- _appliedVelocity = OMV.Vector3.Zero;
_buoyancy = ComputeBuoyancyFromFlying(isFlying);
_currentFriction = BSParam.AvatarStandingFriction;
_avatarDensity = BSParam.AvatarDensity;
- // The dimensions of the avatar capsule are kept in the scale.
+ // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
+ // replace with the default values.
+ _size = size;
+ if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
+ if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
+
+ // The dimensions of the physical capsule are kept in the scale.
// Physics creates a unit capsule which is scaled by the physics engine.
- ComputeAvatarScale(_size);
+ Scale = ComputeAvatarScale(_size);
// set _avatarVolume and _mass based on capsule size, _density and Scale
ComputeAvatarVolumeAndMass();
+
+ SetupMovementMotor();
+
DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
@@ -217,9 +216,21 @@ public sealed class BSCharacter : BSPhysObject
// 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass / PhysicsScene.LastTimeStep;
- DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
- LocalID, stepVelocity, _velocity, Mass, moveForce);
- AddForce(moveForce, false, true);
+
+ // If moveForce is very small, zero things so we don't keep sending microscopic updates to the user
+ float moveForceMagnitudeSquared = moveForce.LengthSquared();
+ if (moveForceMagnitudeSquared < 0.0001)
+ {
+ DetailLog("{0},BSCharacter.MoveMotor,zeroMovement,stepVel={1},vel={2},mass={3},magSq={4},moveForce={5}",
+ LocalID, stepVelocity, _velocity, Mass, moveForceMagnitudeSquared, moveForce);
+ ForceVelocity = OMV.Vector3.Zero;
+ }
+ else
+ {
+ DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
+ LocalID, stepVelocity, _velocity, Mass, moveForce);
+ AddForce(moveForce, false, true);
+ }
});
}
@@ -238,14 +249,13 @@ public sealed class BSCharacter : BSPhysObject
}
set {
- // When an avatar's size is set, only the height is changed.
_size = value;
// Old versions of ScenePresence passed only the height. If width and/or depth are zero,
// replace with the default values.
if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
- ComputeAvatarScale(_size);
+ Scale = ComputeAvatarScale(_size);
ComputeAvatarVolumeAndMass();
DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
@@ -521,8 +531,6 @@ public sealed class BSCharacter : BSPhysObject
BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
}
}
- // Remember the set velocity so we can suppress the reduction by friction, ...
- _appliedVelocity = value;
BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
BulletSimAPI.Activate2(PhysBody.ptr, true);
@@ -554,11 +562,7 @@ public sealed class BSCharacter : BSPhysObject
// m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation);
PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
{
- if (PhysBody.HasPhysicalBody)
- {
- // _position = BulletSimAPI.GetPosition2(BSBody.ptr);
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
- }
+ ForceOrientation = _orientation;
});
}
}
@@ -573,7 +577,11 @@ public sealed class BSCharacter : BSPhysObject
set
{
_orientation = value;
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ if (PhysBody.HasPhysicalBody)
+ {
+ // _position = BulletSimAPI.GetPosition2(BSBody.ptr);
+ BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ }
}
}
public override int PhysicsActorType {
@@ -716,7 +724,7 @@ public sealed class BSCharacter : BSPhysObject
}
OMV.Vector3 addForce = force;
- DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce);
+ // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce);
PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate()
{
@@ -740,21 +748,31 @@ public sealed class BSCharacter : BSPhysObject
public override void SetMomentum(OMV.Vector3 momentum) {
}
- private void ComputeAvatarScale(OMV.Vector3 size)
+ private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size)
{
- OMV.Vector3 newScale = size;
- // newScale.X = PhysicsScene.Params.avatarCapsuleWidth;
- // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth;
-
- // From the total height, remove the capsule half spheres that are at each end
- // The 1.15f came from ODE. Not sure what this factors in.
- // newScale.Z = (size.Z * 1.15f) - (newScale.X + newScale.Y);
+ OMV.Vector3 newScale;
+
+ // Bullet's capsule total height is the "passed height + radius * 2";
+ // The base capsule is 1 diameter and 2 height (passed radius=0.5, passed height = 1)
+ // The number we pass in for 'scaling' is the multiplier to get that base
+ // shape to be the size desired.
+ // So, when creating the scale for the avatar height, we take the passed height
+ // (size.Z) and remove the caps.
+ // Another oddity of the Bullet capsule implementation is that it presumes the Y
+ // dimension is the radius of the capsule. Even though some of the code allows
+ // for a asymmetrical capsule, other parts of the code presume it is cylindrical.
+
+ // Scale is multiplier of radius with one of "0.5"
+ newScale.X = size.X / 2f;
+ newScale.Y = size.Y / 2f;
// The total scale height is the central cylindar plus the caps on the two ends.
- newScale.Z = size.Z + (Math.Min(size.X, size.Y) * 2f);
+ newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2)) / 2f;
+ // If smaller than the endcaps, just fake like we're almost that small
+ if (newScale.Z < 0)
+ newScale.Z = 0.1f;
- // Convert diameters to radii and height to half height -- the way Bullet expects it.
- Scale = newScale / 2f;
+ return newScale;
}
// set _avatarVolume and _mass based on capsule size, _density and Scale
@@ -762,14 +780,14 @@ public sealed class BSCharacter : BSPhysObject
{
_avatarVolume = (float)(
Math.PI
- * Scale.X
- * Scale.Y // the area of capsule cylinder
- * Scale.Z // times height of capsule cylinder
+ * Size.X / 2f
+ * Size.Y / 2f // the area of capsule cylinder
+ * Size.Z // times height of capsule cylinder
+ 1.33333333f
* Math.PI
- * Scale.X
- * Math.Min(Scale.X, Scale.Y)
- * Scale.Y // plus the volume of the capsule end caps
+ * Size.X / 2f
+ * Math.Min(Size.X, Size.Y) / 2
+ * Size.Y / 2f // plus the volume of the capsule end caps
);
_mass = _avatarDensity * _avatarVolume;
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 65ebcaa..0cc51b0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -420,8 +420,7 @@ public sealed class BSShapeCollection : IDisposable
if (!haveShape && prim.PreferredPhysicalShape == BSPhysicsShapeType.SHAPE_CAPSULE)
{
// an avatar capsule is close to a native shape (it is not shared)
- GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE,
- FixedShapeKey.KEY_CAPSULE, shapeCallback);
+ GetReferenceToNativeShape(prim, BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE, shapeCallback);
if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,avatarCapsule,shape={1}", prim.LocalID, prim.PhysShape);
ret = true;
haveShape = true;
@@ -573,6 +572,9 @@ public sealed class BSShapeCollection : IDisposable
{
// The proper scale has been calculated in the prim.
newShape = new BulletShape(
+ // Bullet's capsule total height is the passed "height + (radius * 2)" so, the base
+ // capsule is radius of 0.5f (1 diameter) and height of two (1.0f + 0.5f * 2)".
+ // This must be taken into account when computing the scaling of the capsule.
BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale)
, shapeType);
if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 96cd55e..c7885c6 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -205,4 +205,17 @@ public class BSShapeCompound : BSShape
}
public override void Dereference(BSScene physicsScene) { }
}
+
+public class BSShapeAvatar : BSShape
+{
+ private static string LogHeader = "[BULLETSIM SHAPE AVATAR]";
+ public BSShapeAvatar() : base()
+ {
+ }
+ public static BSShape GetReference(BSPhysObject prim)
+ {
+ return new BSShapeNull();
+ }
+ public override void Dereference(BSScene physicsScene) { }
+}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index eb4d039..b909b38 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -69,6 +69,7 @@ public enum BSPhysicsShapeType
SHAPE_TERRAIN = 21,
SHAPE_COMPOUND = 22,
SHAPE_HEIGHTMAP = 23,
+ SHAPE_AVATAR = 24,
};
// The native shapes have predefined shape hash keys
@@ -79,7 +80,8 @@ public enum FixedShapeKey : ulong
KEY_SPHERE = 2,
KEY_CONE = 3,
KEY_CYLINDER = 4,
- KEY_CAPSULE = 5,
+ KEY_CAPSULE = 5,
+ KEY_AVATAR = 6,
}
[StructLayout(LayoutKind.Sequential)]
--
cgit v1.1
From 0538096fa3397c52b1171a3ec83dc88489002710 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 08:32:57 -0800
Subject: BulletSim: an 'if' to suppress multiple setting of avatar
orientation. Looks like the viewer bombards the server with avatar
orientation information (we're talking several hundred a second) when the
avatar is being turned or when walking. This change just reduces the number
of 'set' calls into unmanaged code.
---
OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 9659542..e19b5b3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -558,12 +558,16 @@ public sealed class BSCharacter : BSPhysObject
public override OMV.Quaternion Orientation {
get { return _orientation; }
set {
- _orientation = value;
- // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation);
- PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
+ // Orientation is set zillions of times when an avatar is walking. It's like
+ // the viewer doesn't trust us.
+ if (_orientation != value)
{
- ForceOrientation = _orientation;
- });
+ _orientation = value;
+ PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
+ {
+ ForceOrientation = _orientation;
+ });
+ }
}
}
// Go directly to Bullet to get/set the value.
--
cgit v1.1
From 28a8949b9f315e9257a6c51d8872cd99d00fe556 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 10:19:47 -0800
Subject: BulletSim: remove check for small motor movement because, while it
did the right thing for stopping (speed reducing to zero), it prevented
movement from starting (speed increasing from zero). Will revisit when the
generalize PID motor is debugged.
---
OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 7 +++++--
OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index e19b5b3..3b77e49 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -217,6 +217,7 @@ public sealed class BSCharacter : BSPhysObject
// 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass / PhysicsScene.LastTimeStep;
+ /*
// If moveForce is very small, zero things so we don't keep sending microscopic updates to the user
float moveForceMagnitudeSquared = moveForce.LengthSquared();
if (moveForceMagnitudeSquared < 0.0001)
@@ -227,10 +228,12 @@ public sealed class BSCharacter : BSPhysObject
}
else
{
- DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
- LocalID, stepVelocity, _velocity, Mass, moveForce);
AddForce(moveForce, false, true);
}
+ */
+ DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
+ LocalID, stepVelocity, _velocity, Mass, moveForce);
+ AddForce(moveForce, false, true);
});
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index b909b38..b361498 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -80,7 +80,7 @@ public enum FixedShapeKey : ulong
KEY_SPHERE = 2,
KEY_CONE = 3,
KEY_CYLINDER = 4,
- KEY_CAPSULE = 5,
+ KEY_CAPSULE = 5,
KEY_AVATAR = 6,
}
--
cgit v1.1
From 26f364cc5d935c86d94c9b860757e46fd539085a Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 18:30:53 -0800
Subject: Comment out test messages that go directly to the console.
---
.../Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
index ad0b83d..943675e 100644
--- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs
@@ -107,12 +107,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule
public void ScriptRemoved(UUID itemID)
{
- System.Console.WriteLine("TEST Script Removed!");
+ // System.Console.WriteLine("TEST Script Removed!");
}
public void ObjectRemoved(UUID objectID)
{
- System.Console.WriteLine("TEST Obj Removed!");
+ // System.Console.WriteLine("TEST Obj Removed!");
}
}
}
--
cgit v1.1
From 4914d6c0ea02ac0060f2fd7e145119603ecd8e5b Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 18:31:38 -0800
Subject: Resolve Mantis 6480
(http://opensimulator.org/mantis/view.php?id=6480) by reversing the sign on
the recoil computation and adding a [XEngine]RecoilScaleFactor parameter
which defaults to zero. Testing in SL seems to show that there is not a
recoil action there. Or, at least, it is very small. If someone knows how
small, the default for the scale factor should be changed.
---
.../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 837779d..f9b90c5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -96,6 +96,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected float m_ScriptDelayFactor = 1.0f;
protected float m_ScriptDistanceFactor = 1.0f;
protected float m_MinTimerInterval = 0.5f;
+ protected float m_recoilScaleFactor = 0.0f;
protected DateTime m_timer = DateTime.Now;
protected bool m_waitingForScriptAnswer = false;
@@ -146,6 +147,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// there's an smtp config, so load in the snooze time.
EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
}
+ // Rezzing an object with a velocity can create recoil. This feature seems to have been
+ // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
+ // it by this factor. May be zero to turn off recoil all together.
+ m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
}
public override Object InitializeLifetimeService()
@@ -2829,10 +2834,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
PhysicsActor pa = new_group.RootPart.PhysActor;
+ //Recoil.
if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
{
- //Recoil.
- llApplyImpulse(vel * groupmass, 0);
+ Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
+ if (recoil != Vector3.Zero)
+ {
+ llApplyImpulse(recoil, 0);
+ }
}
// Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
});
--
cgit v1.1
From 203588e3c0374505a6aa564d8f7a655d968653d7 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 18:34:46 -0800
Subject: BulletSim: change physical data structures to classes. Add default
instantiations for PhysBody and PhysShape when BSPhysObject is created to
account for them being classes and not structures. Update TODO list.
---
.../Region/Physics/BulletSPlugin/BSLinksetConstraints.cs | 15 +++++++++------
OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 5 +++++
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 5 +----
OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs | 15 ++++++++++-----
OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 4 ++++
5 files changed, 29 insertions(+), 15 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 6b592e7..86c29c7 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -48,12 +48,15 @@ public sealed class BSLinksetConstraints : BSLinkset
{
base.Refresh(requestor);
- // Queue to happen after all the other taint processing
- PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
- {
- if (HasAnyChildren && IsRoot(requestor))
- RecomputeLinksetConstraints();
- });
+ if (HasAnyChildren && IsRoot(requestor))
+ {
+ // Queue to happen after all the other taint processing
+ PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
+ {
+ if (HasAnyChildren && IsRoot(requestor))
+ RecomputeLinksetConstraints();
+ });
+ }
}
// The object is going dynamic (physical). Do any setup necessary
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 73b5764..b093890 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -67,6 +67,11 @@ public abstract class BSPhysObject : PhysicsActor
PhysObjectName = name;
TypeName = typeName;
+ // We don't have any physical representation yet.
+ PhysBody = new BulletBody(localID);
+ PhysShape = new BulletShape();
+
+ // A linkset of just me
Linkset = BSLinkset.Factory(PhysicsScene, this);
LastAssetBuildFailed = false;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 5f3f0d1..2de4717 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -111,10 +111,7 @@ public sealed class BSPrim : BSPhysObject
_mass = CalculateMass();
- // No body or shape yet
- PhysBody = new BulletBody(LocalID);
- PhysShape = new BulletShape();
-
+ // Cause linkset variables to be initialized (like mass)
Linkset.Refresh(this);
DetailLog("{0},BSPrim.constructor,call", LocalID);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 5ad6746..cd5d170 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -35,7 +35,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// These hold pointers to allocated objects in the unmanaged space.
// The physics engine controller class created at initialization
-public struct BulletWorld
+public class BulletWorld
{
public BulletWorld(uint worldId, BSScene bss, IntPtr xx)
{
@@ -50,7 +50,7 @@ public struct BulletWorld
}
// An allocated Bullet btRigidBody
-public struct BulletBody
+public class BulletBody
{
public BulletBody(uint id) : this(id, IntPtr.Zero)
{
@@ -96,9 +96,14 @@ public struct BulletBody
}
}
-public struct BulletShape
+public class BulletShape
{
- public BulletShape(IntPtr xx) : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN)
+ public BulletShape()
+ : this(IntPtr.Zero, BSPhysicsShapeType.SHAPE_UNKNOWN)
+ {
+ }
+ public BulletShape(IntPtr xx)
+ : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN)
{
}
public BulletShape(IntPtr xx, BSPhysicsShapeType typ)
@@ -136,7 +141,7 @@ public struct BulletShape
}
// An allocated Bullet btConstraint
-public struct BulletConstraint
+public class BulletConstraint
{
public BulletConstraint(IntPtr xx)
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index f805836..8ec9871 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -97,6 +97,9 @@ Selecting and deselecting physical objects causes CPU processing time to jump
Re-implement buoyancy as a separate force on the object rather than diddling gravity.
Register a pre-step event to add the force.
More efficient memory usage when passing hull information from BSPrim to BulletSim
+Avatar movement motor check for zero or small movement. Somehow suppress small movements
+ when avatar has stopped and is just standing. Simple test for near zero has
+ the problem of preventing starting up (increase from zero) especially when falling.
LINKSETS
======================================================
@@ -195,6 +198,7 @@ Should taints check for existance or activeness of target?
keeps the object from being freed, but that is just an accident.
Possibly have and 'active' flag that is checked by the taint processor?
Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones)
+Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'?
THREADING
=================================================
--
cgit v1.1
From 48f718f39fcd61501262878a8bcfbd98efed29d2 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 21:43:43 -0800
Subject: BulletSim: first round of conversion from direct BulletSimAPI
interfacing by BulletSim core to using the BulletSimAPITemplate. Physical
object creation and destruction first.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 8 +-
.../Physics/BulletSPlugin/BSLinksetCompound.cs | 6 +-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +-
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 10 +-
.../Physics/BulletSPlugin/BSShapeCollection.cs | 63 +-
OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 7 +-
.../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 7 +-
.../Physics/BulletSPlugin/BSTerrainManager.cs | 8 +-
.../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 8 +-
.../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 947 ++++-----------------
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 7 +-
11 files changed, 234 insertions(+), 839 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 3b77e49..d5ab245 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -210,8 +210,7 @@ public sealed class BSCharacter : BSPhysObject
if (!Flying && !IsColliding)
{
stepVelocity.Z = _velocity.Z;
- DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}",
- LocalID, stepVelocity);
+ // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity);
}
// 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force.
@@ -231,8 +230,7 @@ public sealed class BSCharacter : BSPhysObject
AddForce(moveForce, false, true);
}
*/
- DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}",
- LocalID, stepVelocity, _velocity, Mass, moveForce);
+ // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce);
AddForce(moveForce, false, true);
});
}
@@ -736,7 +734,7 @@ public sealed class BSCharacter : BSPhysObject
PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.AddForce", delegate()
{
// Bullet adds this central force to the total force for this tick
- DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
+ // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
if (PhysBody.HasPhysicalBody)
{
BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 19ce62b..9bb951c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -359,7 +359,7 @@ public sealed class BSLinksetCompound : BSLinkset
PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null);
BulletShape newShape = cPrim.PhysShape;
cPrim.PhysShape = saveShape;
- BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, newShape.ptr, lci.OffsetPos, lci.OffsetRot);
+ PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, lci.OffsetPos, lci.OffsetRot);
}
else
{
@@ -371,7 +371,7 @@ public sealed class BSLinksetCompound : BSLinkset
PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
}
- BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, lci.OffsetPos, lci.OffsetRot);
+ PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
}
}
return false; // 'false' says to move onto the next child in the list
@@ -386,7 +386,7 @@ public sealed class BSLinksetCompound : BSLinkset
Rebuilding = false;
}
- BulletSimAPI.RecalculateCompoundShapeLocalAabb2(LinksetRoot.PhysShape.ptr);
+ PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape);
// DEBUG: see of inter-linkset collisions are causing problems for constraint linksets.
// BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 2de4717..cf09be2 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -845,7 +845,7 @@ public sealed class BSPrim : BSPhysObject
// the functions after this one set up the state of a possibly newly created collision body.
private void MakeSolid(bool makeSolid)
{
- CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(PhysBody.ptr);
+ CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(PhysBody);
if (makeSolid)
{
// Verify the previous code created the correct shape for this type of thing.
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 4133107..bfc9df2 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -50,6 +50,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
public string BulletSimVersion = "?";
+ // The handle to the underlying managed or unmanaged version of Bullet being used.
+ public BulletSimAPITemplate PE;
+
public Dictionary PhysObjects;
public BSShapeCollection Shapes;
@@ -187,12 +190,15 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// Allocate pinned memory to pass parameters.
UnmanagedParams = new ConfigurationParameters[1];
- m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);
// Set default values for physics parameters plus any overrides from the ini file
GetInitialParameterValues(config);
- // allocate more pinned memory close to the above in an attempt to get the memory all together
+ // For the moment, only one version of the interface
+ PE = new BSAPIUnman();
+
+ // Allocate more pinned memory. Do this early to try and get all pinned memory close together.
+ m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);
m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 0cc51b0..e7d8d14 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -174,7 +174,7 @@ public sealed class BSShapeCollection : IDisposable
// Zero any reference to the shape so it is not freed when the body is deleted.
BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero);
- BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, body.ptr);
+ PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
});
}
}
@@ -261,7 +261,7 @@ public sealed class BSShapeCollection : IDisposable
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}",
BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime);
if (shapeCallback != null) shapeCallback(shape);
- BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr);
+ PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
}
else
{
@@ -342,26 +342,26 @@ public sealed class BSShapeCollection : IDisposable
return;
}
- int numChildren = BulletSimAPI.GetNumberOfCompoundChildren2(shape.ptr);
+ int numChildren = PhysicsScene.PE.GetNumberOfCompoundChildren(shape);
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", BSScene.DetailLogZero, shape, numChildren);
for (int ii = numChildren - 1; ii >= 0; ii--)
{
- IntPtr childShape = BulletSimAPI.RemoveChildShapeFromCompoundShapeIndex2(shape.ptr, ii);
+ BulletShape childShape = PhysicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(shape, ii);
DereferenceAnonCollisionShape(childShape);
}
- BulletSimAPI.DeleteCollisionShape2(PhysicsScene.World.ptr, shape.ptr);
+ PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
}
// Sometimes we have a pointer to a collision shape but don't know what type it is.
// Figure out type and call the correct dereference routine.
// Called at taint-time.
- private void DereferenceAnonCollisionShape(IntPtr cShape)
+ private void DereferenceAnonCollisionShape(BulletShape shapeInfo)
{
MeshDesc meshDesc;
HullDesc hullDesc;
- BulletShape shapeInfo = new BulletShape(cShape);
+ IntPtr cShape = shapeInfo.ptr;
if (TryGetMeshByPtr(cShape, out meshDesc))
{
shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH;
@@ -382,7 +382,7 @@ public sealed class BSShapeCollection : IDisposable
}
else
{
- if (BulletSimAPI.IsNativeShape2(cShape))
+ if (PhysicsScene.PE.IsNativeShape(shapeInfo))
{
shapeInfo.isNativeShape = true;
shapeInfo.type = BSPhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
@@ -570,19 +570,15 @@ public sealed class BSShapeCollection : IDisposable
if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
{
- // The proper scale has been calculated in the prim.
- newShape = new BulletShape(
- // Bullet's capsule total height is the passed "height + (radius * 2)" so, the base
- // capsule is radius of 0.5f (1 diameter) and height of two (1.0f + 0.5f * 2)".
- // This must be taken into account when computing the scaling of the capsule.
- BulletSimAPI.BuildCapsuleShape2(PhysicsScene.World.ptr, 1f, 1f, prim.Scale)
- , shapeType);
+
+ newShape = PhysicsScene.PE.BuildCapsuleShape(PhysicsScene.World, 1f, 1f, prim.Scale);
if (DDetail) DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
}
else
{
// Native shapes are scaled in Bullet so set the scaling to the size
- newShape = new BulletShape(BulletSimAPI.BuildNativeShape2(PhysicsScene.World.ptr, nativeShapeData), shapeType);
+ newShape = PhysicsScene.PE.BuildNativeShape(PhysicsScene.World, nativeShapeData);
+
}
if (!newShape.HasPhysicalShape)
{
@@ -629,13 +625,14 @@ public sealed class BSShapeCollection : IDisposable
private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
{
+ BulletShape newShape = new BulletShape();
IMesh meshData = null;
- IntPtr meshPtr = IntPtr.Zero;
+
MeshDesc meshDesc;
if (Meshes.TryGetValue(newMeshKey, out meshDesc))
{
// If the mesh has already been built just use it.
- meshPtr = meshDesc.ptr;
+ newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH);
}
else
{
@@ -658,11 +655,10 @@ public sealed class BSShapeCollection : IDisposable
// m_log.DebugFormat("{0}: BSShapeCollection.CreatePhysicalMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
// LogHeader, prim.LocalID, newMeshKey, indices.Length, vertices.Count);
- meshPtr = BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr,
+ newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World,
indices.GetLength(0), indices, vertices.Count, verticesAsFloats);
}
}
- BulletShape newShape = new BulletShape(meshPtr, BSPhysicsShapeType.SHAPE_MESH);
newShape.shapeKey = newMeshKey;
return newShape;
@@ -700,12 +696,14 @@ public sealed class BSShapeCollection : IDisposable
private BulletShape CreatePhysicalHull(string objName, System.UInt64 newHullKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod)
{
+ BulletShape newShape = new BulletShape();
IntPtr hullPtr = IntPtr.Zero;
+
HullDesc hullDesc;
if (Hulls.TryGetValue(newHullKey, out hullDesc))
{
// If the hull shape already is created, just use it.
- hullPtr = hullDesc.ptr;
+ newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL);
}
else
{
@@ -793,11 +791,10 @@ public sealed class BSShapeCollection : IDisposable
}
}
// create the hull data structure in Bullet
- hullPtr = BulletSimAPI.CreateHullShape2(PhysicsScene.World.ptr, hullCount, convHulls);
+ newShape = PhysicsScene.PE.CreateHullShape(PhysicsScene.World, hullCount, convHulls);
}
}
- BulletShape newShape = new BulletShape(hullPtr, BSPhysicsShapeType.SHAPE_HULL);
newShape.shapeKey = newHullKey;
return newShape;
@@ -819,12 +816,12 @@ public sealed class BSShapeCollection : IDisposable
// Don't need to do this as the shape is freed when the new root shape is created below.
// DereferenceShape(prim.PhysShape, true, shapeCallback);
- BulletShape cShape = new BulletShape(
- BulletSimAPI.CreateCompoundShape2(PhysicsScene.World.ptr, false), BSPhysicsShapeType.SHAPE_COMPOUND);
+
+ BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false);
// Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
CreateGeomMeshOrHull(prim, shapeCallback);
- BulletSimAPI.AddChildShapeToCompoundShape2(cShape.ptr, prim.PhysShape.ptr, OMV.Vector3.Zero, OMV.Quaternion.Identity);
+ PhysicsScene.PE.AddChildShapeToCompoundShape(cShape, prim.PhysShape, OMV.Vector3.Zero, OMV.Quaternion.Identity);
if (DDetail) DetailLog("{0},BSShapeCollection.GetReferenceToCompoundShape,addRootPrim,compShape={1},rootShape={2}",
prim.LocalID, cShape, prim.PhysShape);
@@ -932,7 +929,7 @@ public sealed class BSShapeCollection : IDisposable
// If not a solid object, body is a GhostObject. Otherwise a RigidBody.
if (!mustRebuild)
{
- CollisionObjectTypes bodyType = (CollisionObjectTypes)BulletSimAPI.GetBodyType2(prim.PhysBody.ptr);
+ CollisionObjectTypes bodyType = (CollisionObjectTypes)PhysicsScene.PE.GetBodyType(prim.PhysBody);
if (prim.IsSolid && bodyType != CollisionObjectTypes.CO_RIGID_BODY
|| !prim.IsSolid && bodyType != CollisionObjectTypes.CO_GHOST_OBJECT)
{
@@ -947,20 +944,16 @@ public sealed class BSShapeCollection : IDisposable
DereferenceBody(prim.PhysBody, true, bodyCallback);
BulletBody aBody;
- IntPtr bodyPtr = IntPtr.Zero;
if (prim.IsSolid)
{
- bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr,
- prim.LocalID, prim.RawPosition, prim.RawOrientation);
- if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
+ aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody);
}
else
{
- bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr,
- prim.LocalID, prim.RawPosition, prim.RawOrientation);
- if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
+ aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
+ if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody);
}
- aBody = new BulletBody(prim.LocalID, bodyPtr);
ReferenceBody(aBody, true);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index c7885c6..cdaa869 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -126,7 +126,8 @@ public class BSShapeNative : BSShape
BSPhysicsShapeType shapeType, FixedShapeKey shapeKey)
{
// Native shapes are not shared and are always built anew.
- return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
+ //return new BSShapeNative(physicsScene, prim, shapeType, shapeKey);
+ return null;
}
private BSShapeNative(BSScene physicsScene, BSPhysObject prim,
@@ -141,6 +142,7 @@ public class BSShapeNative : BSShape
nativeShapeData.HullKey = (ulong)shapeKey;
+ /*
if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
{
ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
@@ -157,15 +159,18 @@ public class BSShapeNative : BSShape
}
type = shapeType;
key = (UInt64)shapeKey;
+ */
}
// Make this reference to the physical shape go away since native shapes are not shared.
public override void Dereference(BSScene physicsScene)
{
+ /*
// Native shapes are not tracked and are released immediately
physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
ptr = IntPtr.Zero;
// Garbage collection will free up this instance.
+ */
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index 07a9fd8..a2c085e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -105,9 +105,8 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f);
centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f);
- m_mapInfo.terrainBody = new BulletBody(m_mapInfo.ID,
- BulletSimAPI.CreateBodyWithDefaultMotionState2(m_mapInfo.terrainShape.ptr,
- m_mapInfo.ID, centerPos, Quaternion.Identity));
+ m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape,
+ m_mapInfo.ID, centerPos, Quaternion.Identity);
// Set current terrain attributes
BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction);
@@ -139,7 +138,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
{
BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
// Frees both the body and the shape.
- BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody);
BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index 86ccfbb..d99a50f 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -137,9 +137,9 @@ public sealed class BSTerrainManager : IDisposable
BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f,
BSParam.TerrainCollisionMargin),
BSPhysicsShapeType.SHAPE_GROUNDPLANE);
- m_groundPlane = new BulletBody(BSScene.GROUNDPLANE_ID,
- BulletSimAPI.CreateBodyWithDefaultMotionState2(groundPlaneShape.ptr, BSScene.GROUNDPLANE_ID,
- Vector3.Zero, Quaternion.Identity));
+ m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
+ BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);
+
BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr);
BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr);
// Ground plane does not move
@@ -160,7 +160,7 @@ public sealed class BSTerrainManager : IDisposable
{
if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr))
{
- BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_groundPlane.ptr);
+ PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane);
}
m_groundPlane.Clear();
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
index 061e232..d8c4972 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
@@ -91,9 +91,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}",
ID, indicesCount, indices.Length, verticesCount, vertices.Length);
- m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr,
- indicesCount, indices, verticesCount, vertices),
- BSPhysicsShapeType.SHAPE_MESH);
+ m_terrainShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, indicesCount, indices, verticesCount, vertices);
if (!m_terrainShape.HasPhysicalShape)
{
// DISASTER!!
@@ -106,7 +104,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
Vector3 pos = regionBase;
Quaternion rot = Quaternion.Identity;
- m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot));
+ m_terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_terrainShape, ID, pos, rot);
if (!m_terrainBody.HasPhysicalBody)
{
// DISASTER!!
@@ -143,7 +141,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
{
BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr);
// Frees both the body and the shape.
- BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index b361498..6b76151 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -292,985 +292,376 @@ public enum ConstraintParamAxis : int
public abstract class BulletSimAPITemplate
{
+ /*
// Initialization and simulation
-public abstract BulletWorld Initialize2(Vector3 maxPosition, IntPtr parms,
+public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
int maxCollisions, IntPtr collisionArray,
int maxUpdates, IntPtr updateArray
);
-public abstract bool UpdateParameter2(BulletWorld world, uint localID, String parm, float value);
+public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
-public abstract void SetHeightMap2(BulletWorld world, float[] heightmap);
+public abstract void SetHeightMap(BulletWorld world, float[] heightmap);
-public abstract void Shutdown2(BulletWorld sim);
+public abstract void Shutdown(BulletWorld sim);
-public abstract int PhysicsStep2(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
+public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
out int updatedEntityCount,
out IntPtr updatedEntitiesPtr,
out int collidersCount,
out IntPtr collidersPtr);
-public abstract bool PushUpdate2(BulletBody obj);
+public abstract bool PushUpdate(BulletBody obj);
+ */
// =====================================================================================
// Mesh, hull, shape and body creation helper routines
-public abstract BulletShape CreateMeshShape2(BulletWorld world,
- int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
- int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
+public abstract BulletShape CreateMeshShape(BulletWorld world,
+ int indicesCount, int[] indices,
+ int verticesCount, float[] vertices );
-public abstract BulletShape CreateHullShape2(BulletWorld world,
- int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
+public abstract BulletShape CreateHullShape(BulletWorld world,
+ int hullCount, float[] hulls);
-public abstract BulletShape BuildHullShapeFromMesh2(BulletWorld world, BulletShape meshShape);
+public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
-public abstract BulletShape BuildNativeShape2(BulletWorld world, ShapeData shapeData);
+public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
-public abstract bool IsNativeShape2(BulletShape shape);
+public abstract bool IsNativeShape(BulletShape shape);
public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
-public abstract BulletShape BuildCapsuleShape2(BulletWorld world, float radius, float height, Vector3 scale);
-
-public abstract BulletShape CreateCompoundShape2(BulletWorld sim, bool enableDynamicAabbTree);
-
-public abstract int GetNumberOfCompoundChildren2(BulletShape cShape);
-
-public abstract void AddChildShapeToCompoundShape2(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
-
-public abstract BulletShape GetChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
-
-public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex2(BulletShape cShape, int indx);
-
-public abstract void RemoveChildShapeFromCompoundShape2(BulletShape cShape, BulletShape removeShape);
-
-public abstract void RecalculateCompoundShapeLocalAabb2(BulletShape cShape);
-
-public abstract BulletShape DuplicateCollisionShape2(BulletWorld sim, BulletShape srcShape, uint id);
-
-public abstract BulletBody CreateBodyFromShapeAndInfo2(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
-
-public abstract bool DeleteCollisionShape2(BulletWorld world, BulletShape shape);
-
-public abstract int GetBodyType2(BulletBody obj);
-
-public abstract BulletBody CreateBodyFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract BulletBody CreateBodyWithDefaultMotionState2(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract BulletBody CreateGhostFromShape2(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract IntPtr AllocateBodyInfo2(BulletBody obj);
-
-public abstract void ReleaseBodyInfo2(IntPtr obj);
-
-public abstract void DestroyObject2(BulletWorld sim, BulletBody obj);
-
-// =====================================================================================
-// Terrain creation and helper routines
-public abstract IntPtr CreateHeightMapInfo2(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-public abstract IntPtr FillHeightMapInfo2(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-public abstract bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
-
-public abstract BulletBody CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
-
-public abstract BulletBody CreateTerrainShape2(IntPtr mapInfo);
-
-// =====================================================================================
-// Constraint creation and helper routines
-public abstract BulletConstraint Create6DofConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 frame1loc, Quaternion frame1rot,
- Vector3 frame2loc, Quaternion frame2rot,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract BulletConstraint Create6DofConstraintToPoint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 joinPoint,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract BulletConstraint CreateHingeConstraint2(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 pivotinA, Vector3 pivotinB,
- Vector3 axisInA, Vector3 axisInB,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract void SetConstraintEnable2(BulletConstraint constrain, float numericTrueFalse);
-
-public abstract void SetConstraintNumSolverIterations2(BulletConstraint constrain, float iterations);
-
-public abstract bool SetFrames2(BulletConstraint constrain,
- Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
-
-public abstract bool SetLinearLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public abstract bool SetAngularLimits2(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public abstract bool UseFrameOffset2(BulletConstraint constrain, float enable);
-
-public abstract bool TranslationalLimitMotor2(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
-
-public abstract bool SetBreakingImpulseThreshold2(BulletConstraint constrain, float threshold);
-
-public abstract bool CalculateTransforms2(BulletConstraint constrain);
-
-public abstract bool SetConstraintParam2(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-
-public abstract bool DestroyConstraint2(BulletWorld world, BulletConstraint constrain);
-
-// =====================================================================================
-// btCollisionWorld entries
-public abstract void UpdateSingleAabb2(BulletWorld world, BulletBody obj);
-
-public abstract void UpdateAabbs2(BulletWorld world);
-
-public abstract bool GetForceUpdateAllAabbs2(BulletWorld world);
-
-public abstract void SetForceUpdateAllAabbs2(BulletWorld world, bool force);
-
-// =====================================================================================
-// btDynamicsWorld entries
-public abstract bool AddObjectToWorld2(BulletWorld world, BulletBody obj);
-
-public abstract bool RemoveObjectFromWorld2(BulletWorld world, BulletBody obj);
-
-public abstract bool AddConstraintToWorld2(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
-
-public abstract bool RemoveConstraintFromWorld2(BulletWorld world, BulletConstraint constrain);
-// =====================================================================================
-// btCollisionObject entries
-public abstract Vector3 GetAnisotripicFriction2(BulletConstraint constrain);
-
-public abstract Vector3 SetAnisotripicFriction2(BulletConstraint constrain, Vector3 frict);
-
-public abstract bool HasAnisotripicFriction2(BulletConstraint constrain);
-
-public abstract void SetContactProcessingThreshold2(BulletBody obj, float val);
-
-public abstract float GetContactProcessingThreshold2(BulletBody obj);
-
-public abstract bool IsStaticObject2(BulletBody obj);
-
-public abstract bool IsKinematicObject2(BulletBody obj);
-
-public abstract bool IsStaticOrKinematicObject2(BulletBody obj);
-
-public abstract bool HasContactResponse2(BulletBody obj);
-
-public abstract void SetCollisionShape2(BulletWorld sim, BulletBody obj, BulletBody shape);
-
-public abstract BulletShape GetCollisionShape2(BulletBody obj);
-
-public abstract int GetActivationState2(BulletBody obj);
-
-public abstract void SetActivationState2(BulletBody obj, int state);
-
-public abstract void SetDeactivationTime2(BulletBody obj, float dtime);
-
-public abstract float GetDeactivationTime2(BulletBody obj);
-
-public abstract void ForceActivationState2(BulletBody obj, ActivationState state);
-
-public abstract void Activate2(BulletBody obj, bool forceActivation);
-
-public abstract bool IsActive2(BulletBody obj);
-
-public abstract void SetRestitution2(BulletBody obj, float val);
-
-public abstract float GetRestitution2(BulletBody obj);
-
-public abstract void SetFriction2(BulletBody obj, float val);
-
-public abstract float GetFriction2(BulletBody obj);
-
- /* Haven't defined the type 'Transform'
-public abstract Transform GetWorldTransform2(BulletBody obj);
-
-public abstract void setWorldTransform2(BulletBody obj, Transform trans);
- */
-
-public abstract Vector3 GetPosition2(BulletBody obj);
-
-public abstract Quaternion GetOrientation2(BulletBody obj);
-
-public abstract void SetTranslation2(BulletBody obj, Vector3 position, Quaternion rotation);
-
-public abstract IntPtr GetBroadphaseHandle2(BulletBody obj);
-
-public abstract void SetBroadphaseHandle2(BulletBody obj, IntPtr handle);
-
- /*
-public abstract Transform GetInterpolationWorldTransform2(IntPtr obj);
-
-public abstract void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
- */
-
-public abstract void SetInterpolationLinearVelocity2(BulletBody obj, Vector3 vel);
-
-public abstract void SetInterpolationAngularVelocity2(BulletBody obj, Vector3 vel);
-
-public abstract void SetInterpolationVelocity2(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
-
-public abstract float GetHitFraction2(BulletBody obj);
-
-public abstract void SetHitFraction2(BulletBody obj, float val);
-
-public abstract CollisionFlags GetCollisionFlags2(BulletBody obj);
-
-public abstract CollisionFlags SetCollisionFlags2(BulletBody obj, CollisionFlags flags);
-
-public abstract CollisionFlags AddToCollisionFlags2(BulletBody obj, CollisionFlags flags);
-
-public abstract CollisionFlags RemoveFromCollisionFlags2(BulletBody obj, CollisionFlags flags);
-
-public abstract float GetCcdMotionThreshold2(BulletBody obj);
-
-public abstract void SetCcdMotionThreshold2(BulletBody obj, float val);
-
-public abstract float GetCcdSweptSphereRadius2(BulletBody obj);
-
-public abstract void SetCcdSweptSphereRadius2(BulletBody obj, float val);
-
-public abstract IntPtr GetUserPointer2(BulletBody obj);
-
-public abstract void SetUserPointer2(BulletBody obj, IntPtr val);
-
-// =====================================================================================
-// btRigidBody entries
-public abstract void ApplyGravity2(BulletBody obj);
-
-public abstract void SetGravity2(BulletBody obj, Vector3 val);
-
-public abstract Vector3 GetGravity2(BulletBody obj);
-
-public abstract void SetDamping2(BulletBody obj, float lin_damping, float ang_damping);
-
-public abstract void SetLinearDamping2(BulletBody obj, float lin_damping);
-
-public abstract void SetAngularDamping2(BulletBody obj, float ang_damping);
-
-public abstract float GetLinearDamping2(BulletBody obj);
+public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
-public abstract float GetAngularDamping2(BulletBody obj);
+public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
-public abstract float GetLinearSleepingThreshold2(BulletBody obj);
+public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
+public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
-public abstract void ApplyDamping2(BulletBody obj, float timeStep);
+public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
-public abstract void SetMassProps2(BulletBody obj, float mass, Vector3 inertia);
+public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
-public abstract Vector3 GetLinearFactor2(BulletBody obj);
+public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
-public abstract void SetLinearFactor2(BulletBody obj, Vector3 factor);
+public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
- /*
-public abstract void SetCenterOfMassTransform2(BulletBody obj, Transform trans);
- */
-
-public abstract void SetCenterOfMassByPosRot2(BulletBody obj, Vector3 pos, Quaternion rot);
-
-// Add a force to the object as if its mass is one.
-public abstract void ApplyCentralForce2(BulletBody obj, Vector3 force);
-
-// Set the force being applied to the object as if its mass is one.
-public abstract void SetObjectForce2(BulletBody obj, Vector3 force);
-
-public abstract Vector3 GetTotalForce2(BulletBody obj);
+public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id);
-public abstract Vector3 GetTotalTorque2(BulletBody obj);
+public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
-public abstract Vector3 GetInvInertiaDiagLocal2(BulletBody obj);
+public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
-public abstract void SetInvInertiaDiagLocal2(BulletBody obj, Vector3 inert);
+public abstract int GetBodyType(BulletBody obj);
-public abstract void SetSleepingThresholds2(BulletBody obj, float lin_threshold, float ang_threshold);
+public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-public abstract void ApplyTorque2(BulletBody obj, Vector3 torque);
-
-// Apply force at the given point. Will add torque to the object.
-public abstract void ApplyForce2(BulletBody obj, Vector3 force, Vector3 pos);
-
-// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
-public abstract void ApplyCentralImpulse2(BulletBody obj, Vector3 imp);
-
-// Apply impulse to the object's torque. Force is scaled by object's mass.
-public abstract void ApplyTorqueImpulse2(BulletBody obj, Vector3 imp);
-
-// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
-public abstract void ApplyImpulse2(BulletBody obj, Vector3 imp, Vector3 pos);
+public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-public abstract void ClearForces2(BulletBody obj);
+public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-public abstract void ClearAllForces2(BulletBody obj);
+public abstract IntPtr AllocateBodyInfo(BulletBody obj);
-public abstract void UpdateInertiaTensor2(BulletBody obj);
+public abstract void ReleaseBodyInfo(IntPtr obj);
+public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
/*
-public abstract Transform GetCenterOfMassTransform2(BulletBody obj);
- */
-
-public abstract Vector3 GetLinearVelocity2(BulletBody obj);
-
-public abstract Vector3 GetAngularVelocity2(BulletBody obj);
-
-public abstract void SetLinearVelocity2(BulletBody obj, Vector3 val);
-
-public abstract void SetAngularVelocity2(BulletBody obj, Vector3 angularVelocity);
-
-public abstract Vector3 GetVelocityInLocalPoint2(BulletBody obj, Vector3 pos);
-
-public abstract void Translate2(BulletBody obj, Vector3 trans);
-
-public abstract void UpdateDeactivation2(BulletBody obj, float timeStep);
-
-public abstract bool WantsSleeping2(BulletBody obj);
-
-public abstract void SetAngularFactor2(BulletBody obj, float factor);
-
-public abstract void SetAngularFactorV2(BulletBody obj, Vector3 factor);
-
-public abstract Vector3 GetAngularFactor2(BulletBody obj);
-
-public abstract bool IsInWorld2(BulletBody obj);
-
-public abstract void AddConstraintRef2(BulletBody obj, BulletConstraint constrain);
-
-public abstract void RemoveConstraintRef2(BulletBody obj, BulletConstraint constrain);
-
-public abstract BulletConstraint GetConstraintRef2(BulletBody obj, int index);
-
-public abstract int GetNumConstraintRefs2(BulletBody obj);
-
-public abstract bool SetCollisionGroupMask2(BulletBody body, uint filter, uint mask);
-
-// =====================================================================================
-// btCollisionShape entries
-
-public abstract float GetAngularMotionDisc2(BulletShape shape);
-
-public abstract float GetContactBreakingThreshold2(BulletShape shape, float defaultFactor);
-
-public abstract bool IsPolyhedral2(BulletShape shape);
-
-public abstract bool IsConvex2d2(BulletShape shape);
-
-public abstract bool IsConvex2(BulletShape shape);
-
-public abstract bool IsNonMoving2(BulletShape shape);
-
-public abstract bool IsConcave2(BulletShape shape);
-
-public abstract bool IsCompound2(BulletShape shape);
-
-public abstract bool IsSoftBody2(BulletShape shape);
-
-public abstract bool IsInfinite2(BulletShape shape);
-
-public abstract void SetLocalScaling2(BulletShape shape, Vector3 scale);
-
-public abstract Vector3 GetLocalScaling2(BulletShape shape);
-
-public abstract Vector3 CalculateLocalInertia2(BulletShape shape, float mass);
-
-public abstract int GetShapeType2(BulletShape shape);
-
-public abstract void SetMargin2(BulletShape shape, float val);
-
-public abstract float GetMargin2(BulletShape shape);
-
-};
-
-// ===============================================================================
-static class BulletSimAPI {
-// ===============================================================================
-// Link back to the managed code for outputting log messages
-[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
-
-// ===============================================================================
-// Initialization and simulation
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray,
- DebugLogCallback logRoutine);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Shutdown2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool PushUpdate2(IntPtr obj);
-
-// =====================================================================================
-// Mesh, hull, shape and body creation helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateMeshShape2(IntPtr world,
- int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
- int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHullShape2(IntPtr world,
- int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsNativeShape2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetShapeCollisionMargin(IntPtr shape, float margin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetBodyType2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ReleaseBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
-
// =====================================================================================
// Terrain creation and helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ float[] heightMap, float collisionMargin);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ float[] heightMap, float collisionMargin);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
+public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
+public abstract BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
+public abstract BulletBody CreateTerrainShape(IntPtr mapInfo);
// =====================================================================================
// Constraint creation and helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 frame1loc, Quaternion frame1rot,
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 pivotinA, Vector3 pivotinB,
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
+public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
+public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetFrames2(IntPtr constrain,
+public abstract bool SetFrames(BulletConstraint constrain,
Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
+public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
+public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
+public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool CalculateTransforms2(IntPtr constrain);
+public abstract bool CalculateTransforms(BulletConstraint constrain);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
+public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
+public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
// =====================================================================================
// btCollisionWorld entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
+public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateAabbs2(IntPtr world);
+public abstract void UpdateAabbs(BulletWorld world);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
+public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
+public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
// =====================================================================================
// btDynamicsWorld entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
+public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
+public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
+public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
+public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
// =====================================================================================
// btCollisionObject entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
+public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
+public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool HasAnisotripicFriction2(IntPtr constrain);
+public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
+public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetContactProcessingThreshold2(IntPtr obj);
+public abstract float GetContactProcessingThreshold(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsStaticObject2(IntPtr obj);
+public abstract bool IsStaticObject(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsKinematicObject2(IntPtr obj);
+public abstract bool IsKinematicObject(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
+public abstract bool IsStaticOrKinematicObject(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool HasContactResponse2(IntPtr obj);
+public abstract bool HasContactResponse(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
+public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetCollisionShape2(IntPtr obj);
+public abstract BulletShape GetCollisionShape(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetActivationState2(IntPtr obj);
+public abstract int GetActivationState(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetActivationState2(IntPtr obj, int state);
+public abstract void SetActivationState(BulletBody obj, int state);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
+public abstract void SetDeactivationTime(BulletBody obj, float dtime);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetDeactivationTime2(IntPtr obj);
+public abstract float GetDeactivationTime(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
+public abstract void ForceActivationState(BulletBody obj, ActivationState state);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Activate2(IntPtr obj, bool forceActivation);
+public abstract void Activate(BulletBody obj, bool forceActivation);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsActive2(IntPtr obj);
+public abstract bool IsActive(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetRestitution2(IntPtr obj, float val);
+public abstract void SetRestitution(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetRestitution2(IntPtr obj);
+public abstract float GetRestitution(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetFriction2(IntPtr obj, float val);
+public abstract void SetFriction(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetFriction2(IntPtr obj);
+public abstract float GetFriction(BulletBody obj);
- /* Haven't defined the type 'Transform'
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetWorldTransform2(IntPtr obj);
+public abstract Vector3 GetPosition(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void setWorldTransform2(IntPtr obj, Transform trans);
- */
+public abstract Quaternion GetOrientation(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetPosition2(IntPtr obj);
+public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Quaternion GetOrientation2(IntPtr obj);
+public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
+public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
+public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
+public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
+public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
- */
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
+public abstract float GetHitFraction(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetHitFraction2(IntPtr obj);
+public abstract void SetHitFraction(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHitFraction2(IntPtr obj, float val);
+public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
+public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
+public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
+public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
+public abstract float GetCcdMotionThreshold(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetCcdMotionThreshold2(IntPtr obj);
+public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
+public abstract float GetCcdSweptSphereRadius(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
+public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
+public abstract IntPtr GetUserPointer(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetUserPointer2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
+public abstract void SetUserPointer(BulletBody obj, IntPtr val);
// =====================================================================================
// btRigidBody entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyGravity2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetGravity2(IntPtr obj, Vector3 val);
+public abstract void ApplyGravity(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetGravity2(IntPtr obj);
+public abstract void SetGravity(BulletBody obj, Vector3 val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
+public abstract Vector3 GetGravity(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
+public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
+public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetLinearDamping2(IntPtr obj);
+public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularDamping2(IntPtr obj);
+public abstract float GetLinearDamping(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetLinearSleepingThreshold2(IntPtr obj);
+public abstract float GetAngularDamping(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularSleepingThreshold2(IntPtr obj);
+public abstract float GetLinearSleepingThreshold(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyDamping2(IntPtr obj, float timeStep);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
+public abstract void ApplyDamping(BulletBody obj, float timeStep);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLinearFactor2(IntPtr obj);
+public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
+public abstract Vector3 GetLinearFactor(BulletBody obj);
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
- */
+public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
+public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
// Add a force to the object as if its mass is one.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
+public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
// Set the force being applied to the object as if its mass is one.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
+public abstract void SetObjectForce(BulletBody obj, Vector3 force);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetTotalForce2(IntPtr obj);
+public abstract Vector3 GetTotalForce(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetTotalTorque2(IntPtr obj);
+public abstract Vector3 GetTotalTorque(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
+public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
+public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
+public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
+public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
// Apply force at the given point. Will add torque to the object.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
+public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
+public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
// Apply impulse to the object's torque. Force is scaled by object's mass.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
+public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ClearForces2(IntPtr obj);
+public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ClearAllForces2(IntPtr obj);
+public abstract void ClearForces(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateInertiaTensor2(IntPtr obj);
+public abstract void ClearAllForces(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
-
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
- */
+public abstract void UpdateInertiaTensor(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLinearVelocity2(IntPtr obj);
+public abstract Vector3 GetLinearVelocity(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAngularVelocity2(IntPtr obj);
+public abstract Vector3 GetAngularVelocity(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
+public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
+public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
+public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Translate2(IntPtr obj, Vector3 trans);
+public abstract void Translate(BulletBody obj, Vector3 trans);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
+public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool WantsSleeping2(IntPtr obj);
+public abstract bool WantsSleeping(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularFactor2(IntPtr obj, float factor);
+public abstract void SetAngularFactor(BulletBody obj, float factor);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
+public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAngularFactor2(IntPtr obj);
+public abstract Vector3 GetAngularFactor(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsInWorld2(IntPtr obj);
+public abstract bool IsInWorld(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
+public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
+public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
+public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetNumConstraintRefs2(IntPtr obj);
+public abstract int GetNumConstraintRefs(BulletBody obj);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
+public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
// =====================================================================================
// btCollisionShape entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularMotionDisc2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
+public abstract float GetAngularMotionDisc(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsPolyhedral2(IntPtr shape);
+public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConvex2d2(IntPtr shape);
+public abstract bool IsPolyhedral(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConvex2(IntPtr shape);
+public abstract bool IsConvex2d(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsNonMoving2(IntPtr shape);
+public abstract bool IsConvex(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConcave2(IntPtr shape);
+public abstract bool IsNonMoving(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsCompound2(IntPtr shape);
+public abstract bool IsConcave(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsSoftBody2(IntPtr shape);
+public abstract bool IsCompound(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsInfinite2(IntPtr shape);
+public abstract bool IsSoftBody(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
+public abstract bool IsInfinite(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLocalScaling2(IntPtr shape);
+public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
+public abstract Vector3 GetLocalScaling(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetShapeType2(IntPtr shape);
+public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetMargin2(IntPtr shape, float val);
+public abstract int GetShapeType(BulletShape shape);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetMargin2(IntPtr shape);
-
-// =====================================================================================
-// Debugging
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
+public abstract void SetMargin(BulletShape shape, float val);
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
+public abstract float GetMargin(BulletShape shape);
+ */
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpActivationInfo2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpAllInfo2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpPhysicsStatistics2(IntPtr sim);
-
-}
+};
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 8ec9871..4cb8e6d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -31,6 +31,7 @@ CRASHES
VEHICLES TODO LIST:
=================================================
+Angular motor direction is global coordinates rather than local coordinates
Border crossing with linked vehicle causes crash
Vehicles (Move smoothly)
Add vehicle collisions so IsColliding is properly reported.
@@ -78,7 +79,7 @@ Small physical objects do not interact correctly
Create chain of .5x.5x.1 torui and make all but top physical so to hang.
The chain will fall apart and pairs will dance around on ground
Chains of 1x1x.2 will stay connected but will dance.
- Chains above 2x2x.4 are move stable and get stablier as torui get larger.
+ Chains above 2x2x.4 are more stable and get stablier as torui get larger.
Add PID motor for avatar movement (slow to stop, ...)
setForce should set a constant force. Different than AddImpulse.
Implement raycast.
@@ -100,9 +101,13 @@ More efficient memory usage when passing hull information from BSPrim to BulletS
Avatar movement motor check for zero or small movement. Somehow suppress small movements
when avatar has stopped and is just standing. Simple test for near zero has
the problem of preventing starting up (increase from zero) especially when falling.
+Physical and phantom will drop through the terrain
+
LINKSETS
======================================================
+Offset the center of the linkset to be the geometric center of all the prims
+ Not quite the same as the center-of-gravity
Linksets should allow collisions to individual children
Add LocalID to children shapes in LinksetCompound and create events for individuals
LinksetCompound: when one of the children changes orientation (like tires
--
cgit v1.1
From 9fd0e1b0805ccc97b8e4f19727d98b26fb5fa89d Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 29 Dec 2012 21:44:13 -0800
Subject: BulletSim: add the implementation files for the two versions of
Bullet: unmanaged (C++) and managed (C#).
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 1107 ++++++++++++++++++++
OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 39 +
2 files changed, 1146 insertions(+)
create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
create mode 100755 OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
new file mode 100755
index 0000000..bbfc1f8
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -0,0 +1,1107 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Text;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSPlugin
+{
+public sealed class BSAPIUnman : BulletSimAPITemplate
+{
+ /*
+// Initialization and simulation
+public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray
+ );
+
+public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
+
+public void SetHeightMap(BulletWorld world, float[] heightmap);
+
+public void Shutdown(BulletWorld sim);
+
+public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount,
+ out IntPtr updatedEntitiesPtr,
+ out int collidersCount,
+ out IntPtr collidersPtr);
+
+public bool PushUpdate(BulletBody obj);
+ */
+
+// =====================================================================================
+// Mesh, hull, shape and body creation helper routines
+public override BulletShape CreateMeshShape(BulletWorld world,
+ int indicesCount, int[] indices,
+ int verticesCount, float[] vertices)
+{
+ return new BulletShape(
+ BSAPI.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices),
+ BSPhysicsShapeType.SHAPE_MESH);
+}
+
+public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
+{
+ return new BulletShape(
+ BSAPI.CreateHullShape2(world.ptr, hullCount, hulls),
+ BSPhysicsShapeType.SHAPE_HULL);
+}
+
+public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
+{
+ return new BulletShape(
+ BSAPI.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr),
+ BSPhysicsShapeType.SHAPE_HULL);
+}
+
+public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData)
+{
+ return new BulletShape(
+ BSAPI.BuildNativeShape2(world.ptr, shapeData),
+ shapeData.Type);
+}
+
+public override bool IsNativeShape(BulletShape shape)
+{
+ if (shape.HasPhysicalShape)
+ return BSAPI.IsNativeShape2(shape.ptr);
+ return false;
+}
+
+public override void SetShapeCollisionMargin(BulletShape shape, float margin)
+{
+ if (shape.HasPhysicalShape)
+ BSAPI.SetShapeCollisionMargin2(shape.ptr, margin);
+}
+
+public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
+{
+ return new BulletShape(
+ BSAPI.BuildCapsuleShape2(world.ptr, radius, height, scale),
+ BSPhysicsShapeType.SHAPE_CAPSULE);
+}
+
+public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree)
+{
+ return new BulletShape(
+ BSAPI.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree),
+ BSPhysicsShapeType.SHAPE_COMPOUND);
+
+}
+
+public override int GetNumberOfCompoundChildren(BulletShape shape)
+{
+ if (shape.HasPhysicalShape)
+ return BSAPI.GetNumberOfCompoundChildren2(shape.ptr);
+ return 0;
+}
+
+public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot)
+{
+ BSAPI.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot);
+}
+
+public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+{
+ return new BulletShape(BSAPI.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+}
+
+public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+{
+ return new BulletShape(BSAPI.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+}
+
+public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape)
+{
+ BSAPI.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr);
+}
+
+public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape)
+{
+ BSAPI.RecalculateCompoundShapeLocalAabb2(cShape.ptr);
+}
+
+public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id)
+{
+ return new BulletShape(BSAPI.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type);
+}
+
+public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo)
+{
+ return new BulletBody(id, BSAPI.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo));
+}
+
+public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
+{
+ return BSAPI.DeleteCollisionShape2(world.ptr, shape.ptr);
+}
+
+public override int GetBodyType(BulletBody obj)
+{
+ return BSAPI.GetBodyType2(obj.ptr);
+}
+
+public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+}
+
+public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPI.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot));
+}
+
+public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+}
+
+public override IntPtr AllocateBodyInfo(BulletBody obj)
+{
+ return BSAPI.AllocateBodyInfo2(obj.ptr);
+}
+
+public override void ReleaseBodyInfo(IntPtr obj)
+{
+ BSAPI.ReleaseBodyInfo2(obj);
+}
+
+public override void DestroyObject(BulletWorld sim, BulletBody obj)
+{
+ BSAPI.DestroyObject2(sim.ptr, obj.ptr);
+}
+
+ /*
+// =====================================================================================
+// Terrain creation and helper routines
+public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
+
+public override BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin);
+
+public override BulletBody CreateTerrainShape(IntPtr mapInfo);
+
+// =====================================================================================
+// Constraint creation and helper routines
+public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 frame1loc, Quaternion frame1rot,
+ Vector3 frame2loc, Quaternion frame2rot,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 joinPoint,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 pivotinA, Vector3 pivotinB,
+ Vector3 axisInA, Vector3 axisInB,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
+
+public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
+
+public override bool SetFrames(BulletConstraint constrain,
+ Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
+
+public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
+
+public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
+
+public override bool UseFrameOffset(BulletConstraint constrain, float enable);
+
+public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
+
+public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
+
+public override bool CalculateTransforms(BulletConstraint constrain);
+
+public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
+
+public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
+
+// =====================================================================================
+// btCollisionWorld entries
+public override void UpdateSingleAabb(BulletWorld world, BulletBody obj);
+
+public override void UpdateAabbs(BulletWorld world);
+
+public override bool GetForceUpdateAllAabbs(BulletWorld world);
+
+public override void SetForceUpdateAllAabbs(BulletWorld world, bool force);
+
+// =====================================================================================
+// btDynamicsWorld entries
+public override bool AddObjectToWorld(BulletWorld world, BulletBody obj);
+
+public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
+
+public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
+
+public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
+// =====================================================================================
+// btCollisionObject entries
+public override Vector3 GetAnisotripicFriction(BulletConstraint constrain);
+
+public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
+
+public override bool HasAnisotripicFriction(BulletConstraint constrain);
+
+public override void SetContactProcessingThreshold(BulletBody obj, float val);
+
+public override float GetContactProcessingThreshold(BulletBody obj);
+
+public override bool IsStaticObject(BulletBody obj);
+
+public override bool IsKinematicObject(BulletBody obj);
+
+public override bool IsStaticOrKinematicObject(BulletBody obj);
+
+public override bool HasContactResponse(BulletBody obj);
+
+public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape);
+
+public override BulletShape GetCollisionShape(BulletBody obj);
+
+public override int GetActivationState(BulletBody obj);
+
+public override void SetActivationState(BulletBody obj, int state);
+
+public override void SetDeactivationTime(BulletBody obj, float dtime);
+
+public override float GetDeactivationTime(BulletBody obj);
+
+public override void ForceActivationState(BulletBody obj, ActivationState state);
+
+public override void Activate(BulletBody obj, bool forceActivation);
+
+public override bool IsActive(BulletBody obj);
+
+public override void SetRestitution(BulletBody obj, float val);
+
+public override float GetRestitution(BulletBody obj);
+
+public override void SetFriction(BulletBody obj, float val);
+
+public override float GetFriction(BulletBody obj);
+
+public override Vector3 GetPosition(BulletBody obj);
+
+public override Quaternion GetOrientation(BulletBody obj);
+
+public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
+
+public override IntPtr GetBroadphaseHandle(BulletBody obj);
+
+public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
+
+public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
+
+public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
+
+public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
+
+public override float GetHitFraction(BulletBody obj);
+
+public override void SetHitFraction(BulletBody obj, float val);
+
+public override CollisionFlags GetCollisionFlags(BulletBody obj);
+
+public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
+
+public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
+
+public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
+
+public override float GetCcdMotionThreshold(BulletBody obj);
+
+public override void SetCcdMotionThreshold(BulletBody obj, float val);
+
+public override float GetCcdSweptSphereRadius(BulletBody obj);
+
+public override void SetCcdSweptSphereRadius(BulletBody obj, float val);
+
+public override IntPtr GetUserPointer(BulletBody obj);
+
+public override void SetUserPointer(BulletBody obj, IntPtr val);
+
+// =====================================================================================
+// btRigidBody entries
+public override void ApplyGravity(BulletBody obj);
+
+public override void SetGravity(BulletBody obj, Vector3 val);
+
+public override Vector3 GetGravity(BulletBody obj);
+
+public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
+
+public override void SetLinearDamping(BulletBody obj, float lin_damping);
+
+public override void SetAngularDamping(BulletBody obj, float ang_damping);
+
+public override float GetLinearDamping(BulletBody obj);
+
+public override float GetAngularDamping(BulletBody obj);
+
+public override float GetLinearSleepingThreshold(BulletBody obj);
+
+
+public override void ApplyDamping(BulletBody obj, float timeStep);
+
+public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
+
+public override Vector3 GetLinearFactor(BulletBody obj);
+
+public override void SetLinearFactor(BulletBody obj, Vector3 factor);
+
+public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
+
+// Add a force to the object as if its mass is one.
+public override void ApplyCentralForce(BulletBody obj, Vector3 force);
+
+// Set the force being applied to the object as if its mass is one.
+public override void SetObjectForce(BulletBody obj, Vector3 force);
+
+public override Vector3 GetTotalForce(BulletBody obj);
+
+public override Vector3 GetTotalTorque(BulletBody obj);
+
+public override Vector3 GetInvInertiaDiagLocal(BulletBody obj);
+
+public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
+
+public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
+
+public override void ApplyTorque(BulletBody obj, Vector3 torque);
+
+// Apply force at the given point. Will add torque to the object.
+public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
+
+// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
+public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
+
+// Apply impulse to the object's torque. Force is scaled by object's mass.
+public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
+
+// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
+public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
+
+public override void ClearForces(BulletBody obj);
+
+public override void ClearAllForces(BulletBody obj);
+
+public override void UpdateInertiaTensor(BulletBody obj);
+
+public override Vector3 GetLinearVelocity(BulletBody obj);
+
+public override Vector3 GetAngularVelocity(BulletBody obj);
+
+public override void SetLinearVelocity(BulletBody obj, Vector3 val);
+
+public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
+
+public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
+
+public override void Translate(BulletBody obj, Vector3 trans);
+
+public override void UpdateDeactivation(BulletBody obj, float timeStep);
+
+public override bool WantsSleeping(BulletBody obj);
+
+public override void SetAngularFactor(BulletBody obj, float factor);
+
+public override void SetAngularFactorV(BulletBody obj, Vector3 factor);
+
+public override Vector3 GetAngularFactor(BulletBody obj);
+
+public override bool IsInWorld(BulletBody obj);
+
+public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
+
+public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
+
+public override BulletConstraint GetConstraintRef(BulletBody obj, int index);
+
+public override int GetNumConstraintRefs(BulletBody obj);
+
+public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
+
+// =====================================================================================
+// btCollisionShape entries
+
+public override float GetAngularMotionDisc(BulletShape shape);
+
+public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
+
+public override bool IsPolyhedral(BulletShape shape);
+
+public override bool IsConvex2d(BulletShape shape);
+
+public override bool IsConvex(BulletShape shape);
+
+public override bool IsNonMoving(BulletShape shape);
+
+public override bool IsConcave(BulletShape shape);
+
+public override bool IsCompound(BulletShape shape);
+
+public override bool IsSoftBody(BulletShape shape);
+
+public override bool IsInfinite(BulletShape shape);
+
+public override void SetLocalScaling(BulletShape shape, Vector3 scale);
+
+public override Vector3 GetLocalScaling(BulletShape shape);
+
+public override Vector3 CalculateLocalInertia(BulletShape shape, float mass);
+
+public override int GetShapeType(BulletShape shape);
+
+public override void SetMargin(BulletShape shape, float val);
+
+public override float GetMargin(BulletShape shape);
+ */
+
+static class BSAPI
+{
+// =====================================================================================
+// Mesh, hull, shape and body creation helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateMeshShape2(IntPtr world,
+ int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
+ int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHullShape2(IntPtr world,
+ int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsNativeShape2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetBodyType2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ReleaseBodyInfo2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
+
+}
+}
+
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+static class BulletSimAPI {
+// ===============================================================================
+// Link back to the managed code for outputting log messages
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
+
+// ===============================================================================
+// Initialization and simulation
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray,
+ DebugLogCallback logRoutine);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Shutdown2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount,
+ out IntPtr updatedEntitiesPtr,
+ out int collidersCount,
+ out IntPtr collidersPtr);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool PushUpdate2(IntPtr obj);
+
+// =====================================================================================
+// Terrain creation and helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
+
+// =====================================================================================
+// Constraint creation and helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 frame1loc, Quaternion frame1rot,
+ Vector3 frame2loc, Quaternion frame2rot,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 joinPoint,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 pivotinA, Vector3 pivotinB,
+ Vector3 axisInA, Vector3 axisInB,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetFrames2(IntPtr constrain,
+ Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool CalculateTransforms2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
+
+// =====================================================================================
+// btCollisionWorld entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateAabbs2(IntPtr world);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
+
+// =====================================================================================
+// btDynamicsWorld entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
+// =====================================================================================
+// btCollisionObject entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool HasAnisotripicFriction2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetContactProcessingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsStaticObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsKinematicObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool HasContactResponse2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetCollisionShape2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetActivationState2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetActivationState2(IntPtr obj, int state);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetDeactivationTime2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Activate2(IntPtr obj, bool forceActivation);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsActive2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetRestitution2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetRestitution2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetFriction2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetFriction2(IntPtr obj);
+
+ /* Haven't defined the type 'Transform'
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetWorldTransform2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void setWorldTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetPosition2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Quaternion GetOrientation2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetHitFraction2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetHitFraction2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetCcdMotionThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetUserPointer2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
+
+// =====================================================================================
+// btRigidBody entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyGravity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetGravity2(IntPtr obj, Vector3 val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetGravity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetLinearDamping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularDamping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetLinearSleepingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularSleepingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyDamping2(IntPtr obj, float timeStep);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLinearFactor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
+
+// Add a force to the object as if its mass is one.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
+
+// Set the force being applied to the object as if its mass is one.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetTotalForce2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetTotalTorque2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
+
+// Apply force at the given point. Will add torque to the object.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
+
+// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
+
+// Apply impulse to the object's torque. Force is scaled by object's mass.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
+
+// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ClearForces2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ClearAllForces2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateInertiaTensor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLinearVelocity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAngularVelocity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Translate2(IntPtr obj, Vector3 trans);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool WantsSleeping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularFactor2(IntPtr obj, float factor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAngularFactor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsInWorld2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetNumConstraintRefs2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
+
+// =====================================================================================
+// btCollisionShape entries
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularMotionDisc2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsPolyhedral2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConvex2d2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConvex2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsNonMoving2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConcave2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsCompound2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsSoftBody2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsInfinite2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLocalScaling2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetShapeType2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetMargin2(IntPtr shape, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetMargin2(IntPtr shape);
+
+// =====================================================================================
+// Debugging
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpActivationInfo2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpAllInfo2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpPhysicsStatistics2(IntPtr sim);
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
new file mode 100755
index 0000000..a56a817
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenSim.Region.Physics.BulletSPlugin
+{
+ /*
+public sealed class BSAPIXNA : BulletSimAPITemplate
+{
+}
+ */
+}
--
cgit v1.1
From 9218748321519ed04da5cdffa1f29e69030171b5 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sun, 30 Dec 2012 10:21:47 -0800
Subject: BulletSim: another round of conversion: dynamics world and collision
object functions.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 2425 +++++++++++---------
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 46 +-
.../Region/Physics/BulletSPlugin/BSConstraint.cs | 17 +-
.../Physics/BulletSPlugin/BSConstraint6Dof.cs | 30 +-
.../Physics/BulletSPlugin/BSConstraintHinge.cs | 10 +-
OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 10 +-
.../Physics/BulletSPlugin/BSLinksetCompound.cs | 12 +-
OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 8 +-
.../Region/Physics/BulletSPlugin/BSPhysObject.cs | 4 +-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 74 +-
.../Physics/BulletSPlugin/BSShapeCollection.cs | 6 +-
.../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 23 +-
.../Physics/BulletSPlugin/BSTerrainManager.cs | 13 +-
.../Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 16 +-
.../Region/Physics/BulletSPlugin/BulletSimAPI.cs | 8 +-
15 files changed, 1454 insertions(+), 1248 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index bbfc1f8..9a8a2e8 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -1,1107 +1,1318 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyrightD
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Text;
-
-using OpenMetaverse;
-
-namespace OpenSim.Region.Physics.BulletSPlugin
-{
-public sealed class BSAPIUnman : BulletSimAPITemplate
-{
- /*
-// Initialization and simulation
-public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray
- );
-
-public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
-
-public void SetHeightMap(BulletWorld world, float[] heightmap);
-
-public void Shutdown(BulletWorld sim);
-
-public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
-
-public bool PushUpdate(BulletBody obj);
- */
-
-// =====================================================================================
-// Mesh, hull, shape and body creation helper routines
-public override BulletShape CreateMeshShape(BulletWorld world,
- int indicesCount, int[] indices,
- int verticesCount, float[] vertices)
-{
- return new BulletShape(
- BSAPI.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices),
- BSPhysicsShapeType.SHAPE_MESH);
-}
-
-public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
-{
- return new BulletShape(
- BSAPI.CreateHullShape2(world.ptr, hullCount, hulls),
- BSPhysicsShapeType.SHAPE_HULL);
-}
-
-public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
-{
- return new BulletShape(
- BSAPI.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr),
- BSPhysicsShapeType.SHAPE_HULL);
-}
-
-public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData)
-{
- return new BulletShape(
- BSAPI.BuildNativeShape2(world.ptr, shapeData),
- shapeData.Type);
-}
-
-public override bool IsNativeShape(BulletShape shape)
-{
- if (shape.HasPhysicalShape)
- return BSAPI.IsNativeShape2(shape.ptr);
- return false;
-}
-
-public override void SetShapeCollisionMargin(BulletShape shape, float margin)
-{
- if (shape.HasPhysicalShape)
- BSAPI.SetShapeCollisionMargin2(shape.ptr, margin);
-}
-
-public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
-{
- return new BulletShape(
- BSAPI.BuildCapsuleShape2(world.ptr, radius, height, scale),
- BSPhysicsShapeType.SHAPE_CAPSULE);
-}
-
-public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree)
-{
- return new BulletShape(
- BSAPI.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree),
- BSPhysicsShapeType.SHAPE_COMPOUND);
-
-}
-
-public override int GetNumberOfCompoundChildren(BulletShape shape)
-{
- if (shape.HasPhysicalShape)
- return BSAPI.GetNumberOfCompoundChildren2(shape.ptr);
- return 0;
-}
-
-public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot)
-{
- BSAPI.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot);
-}
-
-public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
-{
- return new BulletShape(BSAPI.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
-}
-
-public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
-{
- return new BulletShape(BSAPI.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
-}
-
-public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape)
-{
- BSAPI.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr);
-}
-
-public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape)
-{
- BSAPI.RecalculateCompoundShapeLocalAabb2(cShape.ptr);
-}
-
-public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id)
-{
- return new BulletShape(BSAPI.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type);
-}
-
-public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo)
-{
- return new BulletBody(id, BSAPI.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo));
-}
-
-public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
-{
- return BSAPI.DeleteCollisionShape2(world.ptr, shape.ptr);
-}
-
-public override int GetBodyType(BulletBody obj)
-{
- return BSAPI.GetBodyType2(obj.ptr);
-}
-
-public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
-{
- return new BulletBody(id, BSAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot));
-}
-
-public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
-{
- return new BulletBody(id, BSAPI.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot));
-}
-
-public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
-{
- return new BulletBody(id, BSAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot));
-}
-
-public override IntPtr AllocateBodyInfo(BulletBody obj)
-{
- return BSAPI.AllocateBodyInfo2(obj.ptr);
-}
-
-public override void ReleaseBodyInfo(IntPtr obj)
-{
- BSAPI.ReleaseBodyInfo2(obj);
-}
-
-public override void DestroyObject(BulletWorld sim, BulletBody obj)
-{
- BSAPI.DestroyObject2(sim.ptr, obj.ptr);
-}
-
- /*
-// =====================================================================================
-// Terrain creation and helper routines
-public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
-
-public override BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-
-public override BulletBody CreateTerrainShape(IntPtr mapInfo);
-
-// =====================================================================================
-// Constraint creation and helper routines
-public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 frame1loc, Quaternion frame1rot,
- Vector3 frame2loc, Quaternion frame2rot,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 joinPoint,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 pivotinA, Vector3 pivotinB,
- Vector3 axisInA, Vector3 axisInB,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
-
-public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
-
-public override bool SetFrames(BulletConstraint constrain,
- Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
-
-public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public override bool UseFrameOffset(BulletConstraint constrain, float enable);
-
-public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
-
-public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
-
-public override bool CalculateTransforms(BulletConstraint constrain);
-
-public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-
-public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
-
-// =====================================================================================
-// btCollisionWorld entries
-public override void UpdateSingleAabb(BulletWorld world, BulletBody obj);
-
-public override void UpdateAabbs(BulletWorld world);
-
-public override bool GetForceUpdateAllAabbs(BulletWorld world);
-
-public override void SetForceUpdateAllAabbs(BulletWorld world, bool force);
-
-// =====================================================================================
-// btDynamicsWorld entries
-public override bool AddObjectToWorld(BulletWorld world, BulletBody obj);
-
-public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
-
-public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
-
-public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
-// =====================================================================================
-// btCollisionObject entries
-public override Vector3 GetAnisotripicFriction(BulletConstraint constrain);
-
-public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
-
-public override bool HasAnisotripicFriction(BulletConstraint constrain);
-
-public override void SetContactProcessingThreshold(BulletBody obj, float val);
-
-public override float GetContactProcessingThreshold(BulletBody obj);
-
-public override bool IsStaticObject(BulletBody obj);
-
-public override bool IsKinematicObject(BulletBody obj);
-
-public override bool IsStaticOrKinematicObject(BulletBody obj);
-
-public override bool HasContactResponse(BulletBody obj);
-
-public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape);
-
-public override BulletShape GetCollisionShape(BulletBody obj);
-
-public override int GetActivationState(BulletBody obj);
-
-public override void SetActivationState(BulletBody obj, int state);
-
-public override void SetDeactivationTime(BulletBody obj, float dtime);
-
-public override float GetDeactivationTime(BulletBody obj);
-
-public override void ForceActivationState(BulletBody obj, ActivationState state);
-
-public override void Activate(BulletBody obj, bool forceActivation);
-
-public override bool IsActive(BulletBody obj);
-
-public override void SetRestitution(BulletBody obj, float val);
-
-public override float GetRestitution(BulletBody obj);
-
-public override void SetFriction(BulletBody obj, float val);
-
-public override float GetFriction(BulletBody obj);
-
-public override Vector3 GetPosition(BulletBody obj);
-
-public override Quaternion GetOrientation(BulletBody obj);
-
-public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
-
-public override IntPtr GetBroadphaseHandle(BulletBody obj);
-
-public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
-
-public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
-
-public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
-
-public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
-
-public override float GetHitFraction(BulletBody obj);
-
-public override void SetHitFraction(BulletBody obj, float val);
-
-public override CollisionFlags GetCollisionFlags(BulletBody obj);
-
-public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public override float GetCcdMotionThreshold(BulletBody obj);
-
-public override void SetCcdMotionThreshold(BulletBody obj, float val);
-
-public override float GetCcdSweptSphereRadius(BulletBody obj);
-
-public override void SetCcdSweptSphereRadius(BulletBody obj, float val);
-
-public override IntPtr GetUserPointer(BulletBody obj);
-
-public override void SetUserPointer(BulletBody obj, IntPtr val);
-
-// =====================================================================================
-// btRigidBody entries
-public override void ApplyGravity(BulletBody obj);
-
-public override void SetGravity(BulletBody obj, Vector3 val);
-
-public override Vector3 GetGravity(BulletBody obj);
-
-public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
-
-public override void SetLinearDamping(BulletBody obj, float lin_damping);
-
-public override void SetAngularDamping(BulletBody obj, float ang_damping);
-
-public override float GetLinearDamping(BulletBody obj);
-
-public override float GetAngularDamping(BulletBody obj);
-
-public override float GetLinearSleepingThreshold(BulletBody obj);
-
-
-public override void ApplyDamping(BulletBody obj, float timeStep);
-
-public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
-
-public override Vector3 GetLinearFactor(BulletBody obj);
-
-public override void SetLinearFactor(BulletBody obj, Vector3 factor);
-
-public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
-
-// Add a force to the object as if its mass is one.
-public override void ApplyCentralForce(BulletBody obj, Vector3 force);
-
-// Set the force being applied to the object as if its mass is one.
-public override void SetObjectForce(BulletBody obj, Vector3 force);
-
-public override Vector3 GetTotalForce(BulletBody obj);
-
-public override Vector3 GetTotalTorque(BulletBody obj);
-
-public override Vector3 GetInvInertiaDiagLocal(BulletBody obj);
-
-public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
-
-public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
-
-public override void ApplyTorque(BulletBody obj, Vector3 torque);
-
-// Apply force at the given point. Will add torque to the object.
-public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
-
-// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
-public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
-
-// Apply impulse to the object's torque. Force is scaled by object's mass.
-public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
-
-// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
-public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
-
-public override void ClearForces(BulletBody obj);
-
-public override void ClearAllForces(BulletBody obj);
-
-public override void UpdateInertiaTensor(BulletBody obj);
-
-public override Vector3 GetLinearVelocity(BulletBody obj);
-
-public override Vector3 GetAngularVelocity(BulletBody obj);
-
-public override void SetLinearVelocity(BulletBody obj, Vector3 val);
-
-public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
-
-public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
-
-public override void Translate(BulletBody obj, Vector3 trans);
-
-public override void UpdateDeactivation(BulletBody obj, float timeStep);
-
-public override bool WantsSleeping(BulletBody obj);
-
-public override void SetAngularFactor(BulletBody obj, float factor);
-
-public override void SetAngularFactorV(BulletBody obj, Vector3 factor);
-
-public override Vector3 GetAngularFactor(BulletBody obj);
-
-public override bool IsInWorld(BulletBody obj);
-
-public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
-
-public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
-
-public override BulletConstraint GetConstraintRef(BulletBody obj, int index);
-
-public override int GetNumConstraintRefs(BulletBody obj);
-
-public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
-
-// =====================================================================================
-// btCollisionShape entries
-
-public override float GetAngularMotionDisc(BulletShape shape);
-
-public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
-
-public override bool IsPolyhedral(BulletShape shape);
-
-public override bool IsConvex2d(BulletShape shape);
-
-public override bool IsConvex(BulletShape shape);
-
-public override bool IsNonMoving(BulletShape shape);
-
-public override bool IsConcave(BulletShape shape);
-
-public override bool IsCompound(BulletShape shape);
-
-public override bool IsSoftBody(BulletShape shape);
-
-public override bool IsInfinite(BulletShape shape);
-
-public override void SetLocalScaling(BulletShape shape, Vector3 scale);
-
-public override Vector3 GetLocalScaling(BulletShape shape);
-
-public override Vector3 CalculateLocalInertia(BulletShape shape, float mass);
-
-public override int GetShapeType(BulletShape shape);
-
-public override void SetMargin(BulletShape shape, float val);
-
-public override float GetMargin(BulletShape shape);
- */
-
-static class BSAPI
-{
-// =====================================================================================
-// Mesh, hull, shape and body creation helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateMeshShape2(IntPtr world,
- int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
- int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHullShape2(IntPtr world,
- int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsNativeShape2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetBodyType2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ReleaseBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
-
-}
-}
-
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-static class BulletSimAPI {
-// ===============================================================================
-// Link back to the managed code for outputting log messages
-[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
-
-// ===============================================================================
-// Initialization and simulation
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray,
- DebugLogCallback logRoutine);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Shutdown2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool PushUpdate2(IntPtr obj);
-
-// =====================================================================================
-// Terrain creation and helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
-
-// =====================================================================================
-// Constraint creation and helper routines
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
- Vector3 frame1loc, Quaternion frame1rot,
- Vector3 frame2loc, Quaternion frame2rot,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
- Vector3 joinPoint,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
- Vector3 pivotinA, Vector3 pivotinB,
- Vector3 axisInA, Vector3 axisInB,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetFrames2(IntPtr constrain,
- Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool CalculateTransforms2(IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
-
-// =====================================================================================
-// btCollisionWorld entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateAabbs2(IntPtr world);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
-
-// =====================================================================================
-// btDynamicsWorld entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
-// =====================================================================================
-// btCollisionObject entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool HasAnisotripicFriction2(IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetContactProcessingThreshold2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsStaticObject2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsKinematicObject2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool HasContactResponse2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetCollisionShape2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetActivationState2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetActivationState2(IntPtr obj, int state);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetDeactivationTime2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Activate2(IntPtr obj, bool forceActivation);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsActive2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetRestitution2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetRestitution2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetFriction2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetFriction2(IntPtr obj);
-
- /* Haven't defined the type 'Transform'
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetWorldTransform2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void setWorldTransform2(IntPtr obj, Transform trans);
- */
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetPosition2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Quaternion GetOrientation2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
-
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
- */
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetHitFraction2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHitFraction2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetCcdMotionThreshold2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetUserPointer2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
-
-// =====================================================================================
-// btRigidBody entries
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyGravity2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetGravity2(IntPtr obj, Vector3 val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetGravity2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetLinearDamping2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularDamping2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetLinearSleepingThreshold2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularSleepingThreshold2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyDamping2(IntPtr obj, float timeStep);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLinearFactor2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
-
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
- */
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
-
-// Add a force to the object as if its mass is one.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
-
-// Set the force being applied to the object as if its mass is one.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetTotalForce2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetTotalTorque2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
-
-// Apply force at the given point. Will add torque to the object.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
-
-// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
-
-// Apply impulse to the object's torque. Force is scaled by object's mass.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
-
-// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ClearForces2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ClearAllForces2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateInertiaTensor2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
-
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
- */
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLinearVelocity2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAngularVelocity2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Translate2(IntPtr obj, Vector3 trans);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool WantsSleeping2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularFactor2(IntPtr obj, float factor);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetAngularFactor2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsInWorld2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetNumConstraintRefs2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
-
-// =====================================================================================
-// btCollisionShape entries
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetAngularMotionDisc2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsPolyhedral2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConvex2d2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConvex2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsNonMoving2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsConcave2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsCompound2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsSoftBody2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool IsInfinite2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 GetLocalScaling2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int GetShapeType2(IntPtr shape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetMargin2(IntPtr shape, float val);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern float GetMargin2(IntPtr shape);
-
-// =====================================================================================
-// Debugging
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpActivationInfo2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpAllInfo2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void DumpPhysicsStatistics2(IntPtr sim);
-
-}
-}
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Text;
+
+using OpenMetaverse;
+
+namespace OpenSim.Region.Physics.BulletSPlugin
+{
+public sealed class BSAPIUnman : BulletSimAPITemplate
+{
+ /*
+// Initialization and simulation
+public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray
+ );
+
+public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
+
+public void SetHeightMap(BulletWorld world, float[] heightmap);
+
+public void Shutdown(BulletWorld sim);
+
+public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount,
+ out IntPtr updatedEntitiesPtr,
+ out int collidersCount,
+ out IntPtr collidersPtr);
+
+public bool PushUpdate(BulletBody obj);
+ */
+
+// =====================================================================================
+// Mesh, hull, shape and body creation helper routines
+public override BulletShape CreateMeshShape(BulletWorld world,
+ int indicesCount, int[] indices,
+ int verticesCount, float[] vertices)
+{
+ return new BulletShape(
+ BSAPICPP.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices),
+ BSPhysicsShapeType.SHAPE_MESH);
+}
+
+public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
+{
+ return new BulletShape(
+ BSAPICPP.CreateHullShape2(world.ptr, hullCount, hulls),
+ BSPhysicsShapeType.SHAPE_HULL);
+}
+
+public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
+{
+ return new BulletShape(
+ BSAPICPP.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr),
+ BSPhysicsShapeType.SHAPE_HULL);
+}
+
+public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData)
+{
+ return new BulletShape(
+ BSAPICPP.BuildNativeShape2(world.ptr, shapeData),
+ shapeData.Type);
+}
+
+public override bool IsNativeShape(BulletShape shape)
+{
+ if (shape.HasPhysicalShape)
+ return BSAPICPP.IsNativeShape2(shape.ptr);
+ return false;
+}
+
+public override void SetShapeCollisionMargin(BulletShape shape, float margin)
+{
+ if (shape.HasPhysicalShape)
+ BSAPICPP.SetShapeCollisionMargin2(shape.ptr, margin);
+}
+
+public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
+{
+ return new BulletShape(
+ BSAPICPP.BuildCapsuleShape2(world.ptr, radius, height, scale),
+ BSPhysicsShapeType.SHAPE_CAPSULE);
+}
+
+public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree)
+{
+ return new BulletShape(
+ BSAPICPP.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree),
+ BSPhysicsShapeType.SHAPE_COMPOUND);
+
+}
+
+public override int GetNumberOfCompoundChildren(BulletShape shape)
+{
+ if (shape.HasPhysicalShape)
+ return BSAPICPP.GetNumberOfCompoundChildren2(shape.ptr);
+ return 0;
+}
+
+public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot)
+{
+ BSAPICPP.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot);
+}
+
+public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+{
+ return new BulletShape(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+}
+
+public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+{
+ return new BulletShape(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+}
+
+public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape)
+{
+ BSAPICPP.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr);
+}
+
+public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape)
+{
+ BSAPICPP.RecalculateCompoundShapeLocalAabb2(cShape.ptr);
+}
+
+public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id)
+{
+ return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type);
+}
+
+public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo)
+{
+ return new BulletBody(id, BSAPICPP.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo));
+}
+
+public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
+{
+ return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr);
+}
+
+public override int GetBodyType(BulletBody obj)
+{
+ return BSAPICPP.GetBodyType2(obj.ptr);
+}
+
+public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPICPP.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+}
+
+public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot));
+}
+
+public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+{
+ return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+}
+
+public override IntPtr AllocateBodyInfo(BulletBody obj)
+{
+ return BSAPICPP.AllocateBodyInfo2(obj.ptr);
+}
+
+public override void ReleaseBodyInfo(IntPtr obj)
+{
+ BSAPICPP.ReleaseBodyInfo2(obj);
+}
+
+public override void DestroyObject(BulletWorld sim, BulletBody obj)
+{
+ BSAPICPP.DestroyObject2(sim.ptr, obj.ptr);
+}
+
+// =====================================================================================
+// Terrain creation and helper routines
+public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ float[] heightMap, float collisionMargin)
+{
+ return BSAPICPP.CreateHeightMapInfo2(sim.ptr, id, minCoords, maxCoords, heightMap, collisionMargin);
+}
+
+public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ float[] heightMap, float collisionMargin)
+{
+ return BSAPICPP.FillHeightMapInfo2(sim.ptr, mapInfo, id, minCoords, maxCoords, heightMap, collisionMargin);
+}
+
+public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo)
+{
+ return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo);
+}
+
+public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
+{
+ return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
+}
+
+public override BulletShape CreateTerrainShape(IntPtr mapInfo)
+{
+ return new BulletShape(BSAPICPP.CreateTerrainShape2(mapInfo), BSPhysicsShapeType.SHAPE_TERRAIN);
+}
+
+// =====================================================================================
+// Constraint creation and helper routines
+public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 frame1loc, Quaternion frame1rot,
+ Vector3 frame2loc, Quaternion frame2rot,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+{
+ return new BulletConstraint(BSAPICPP.Create6DofConstraint2(world.ptr, obj1.ptr, obj2.ptr, frame1loc, frame1rot,
+ frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+}
+
+public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 joinPoint,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+{
+ return new BulletConstraint(BSAPICPP.Create6DofConstraintToPoint2(world.ptr, obj1.ptr, obj2.ptr,
+ joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+}
+
+public override BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
+ Vector3 pivotinA, Vector3 pivotinB,
+ Vector3 axisInA, Vector3 axisInB,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+{
+ return new BulletConstraint(BSAPICPP.CreateHingeConstraint2(world.ptr, obj1.ptr, obj2.ptr,
+ pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+}
+
+public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
+{
+ BSAPICPP.SetConstraintEnable2(constrain.ptr, numericTrueFalse);
+}
+
+public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations)
+{
+ BSAPICPP.SetConstraintNumSolverIterations2(constrain.ptr, iterations);
+}
+
+public override bool SetFrames(BulletConstraint constrain,
+ Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
+{
+ return BSAPICPP.SetFrames2(constrain.ptr, frameA, frameArot, frameB, frameBrot);
+}
+
+public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
+{
+ return BSAPICPP.SetLinearLimits2(constrain.ptr, low, hi);
+}
+
+public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
+{
+ return BSAPICPP.SetAngularLimits2(constrain.ptr, low, hi);
+}
+
+public override bool UseFrameOffset(BulletConstraint constrain, float enable)
+{
+ return BSAPICPP.UseFrameOffset2(constrain.ptr, enable);
+}
+
+public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce)
+{
+ return BSAPICPP.TranslationalLimitMotor2(constrain.ptr, enable, targetVel, maxMotorForce);
+}
+
+public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold)
+{
+ return BSAPICPP.SetBreakingImpulseThreshold2(constrain.ptr, threshold);
+}
+
+public override bool CalculateTransforms(BulletConstraint constrain)
+{
+ return BSAPICPP.CalculateTransforms2(constrain.ptr);
+}
+
+public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis)
+{
+ return BSAPICPP.SetConstraintParam2(constrain.ptr, paramIndex, value, axis);
+}
+
+public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain)
+{
+ return BSAPICPP.DestroyConstraint2(world.ptr, constrain.ptr);
+}
+
+// =====================================================================================
+// btCollisionWorld entries
+public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
+{
+ BSAPICPP.UpdateSingleAabb2(world.ptr, obj.ptr);
+}
+
+public override void UpdateAabbs(BulletWorld world)
+{
+ BSAPICPP.UpdateAabbs2(world.ptr);
+}
+
+public override bool GetForceUpdateAllAabbs(BulletWorld world)
+{
+ return BSAPICPP.GetForceUpdateAllAabbs2(world.ptr);
+}
+
+public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
+{
+ BSAPICPP.SetForceUpdateAllAabbs2(world.ptr, force);
+}
+
+// =====================================================================================
+// btDynamicsWorld entries
+public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
+{
+ return BSAPICPP.AddObjectToWorld2(world.ptr, obj.ptr);
+}
+
+public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
+{
+ return BSAPICPP.RemoveObjectFromWorld2(world.ptr, obj.ptr);
+}
+
+public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
+{
+ return BSAPICPP.AddConstraintToWorld2(world.ptr, constrain.ptr, disableCollisionsBetweenLinkedObjects);
+}
+
+public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
+{
+ return BSAPICPP.RemoveConstraintFromWorld2(world.ptr, constrain.ptr);
+}
+// =====================================================================================
+// btCollisionObject entries
+public override Vector3 GetAnisotripicFriction(BulletConstraint constrain)
+{
+ return BSAPICPP.GetAnisotripicFriction2(constrain.ptr);
+}
+
+public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict)
+{
+ return BSAPICPP.SetAnisotripicFriction2(constrain.ptr, frict);
+}
+
+public override bool HasAnisotripicFriction(BulletConstraint constrain)
+{
+ return BSAPICPP.HasAnisotripicFriction2(constrain.ptr);
+}
+
+public override void SetContactProcessingThreshold(BulletBody obj, float val)
+{
+ BSAPICPP.SetContactProcessingThreshold2(obj.ptr, val);
+}
+
+public override float GetContactProcessingThreshold(BulletBody obj)
+{
+ return BSAPICPP.GetContactProcessingThreshold2(obj.ptr);
+}
+
+public override bool IsStaticObject(BulletBody obj)
+{
+ return BSAPICPP.IsStaticObject2(obj.ptr);
+}
+
+public override bool IsKinematicObject(BulletBody obj)
+{
+ return BSAPICPP.IsKinematicObject2(obj.ptr);
+}
+
+public override bool IsStaticOrKinematicObject(BulletBody obj)
+{
+ return BSAPICPP.IsStaticOrKinematicObject2(obj.ptr);
+}
+
+public override bool HasContactResponse(BulletBody obj)
+{
+ return BSAPICPP.HasContactResponse2(obj.ptr);
+}
+
+public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape)
+{
+ BSAPICPP.SetCollisionShape2(sim.ptr, obj.ptr, shape.ptr);
+}
+
+public override BulletShape GetCollisionShape(BulletBody obj)
+{
+ return new BulletShape(BSAPICPP.GetCollisionShape2(obj.ptr));
+}
+
+public override int GetActivationState(BulletBody obj)
+{
+ return BSAPICPP.GetActivationState2(obj.ptr);
+}
+
+public override void SetActivationState(BulletBody obj, int state)
+{
+ BSAPICPP.SetActivationState2(obj.ptr, state);
+}
+
+public override void SetDeactivationTime(BulletBody obj, float dtime)
+{
+ BSAPICPP.SetDeactivationTime2(obj.ptr, dtime);
+}
+
+public override float GetDeactivationTime(BulletBody obj)
+{
+ return BSAPICPP.GetDeactivationTime2(obj.ptr);
+}
+
+public override void ForceActivationState(BulletBody obj, ActivationState state)
+{
+ BSAPICPP.ForceActivationState2(obj.ptr, state);
+}
+
+public override void Activate(BulletBody obj, bool forceActivation)
+{
+ BSAPICPP.Activate2(obj.ptr, forceActivation);
+}
+
+public override bool IsActive(BulletBody obj)
+{
+ return BSAPICPP.IsActive2(obj.ptr);
+}
+
+public override void SetRestitution(BulletBody obj, float val)
+{
+ BSAPICPP.SetRestitution2(obj.ptr, val);
+}
+
+public override float GetRestitution(BulletBody obj)
+{
+ return BSAPICPP.GetRestitution2(obj.ptr);
+}
+
+public override void SetFriction(BulletBody obj, float val)
+{
+ BSAPICPP.SetFriction2(obj.ptr, val);
+}
+
+public override float GetFriction(BulletBody obj)
+{
+ return BSAPICPP.GetFriction2(obj.ptr);
+}
+
+public override Vector3 GetPosition(BulletBody obj)
+{
+ return BSAPICPP.GetPosition2(obj.ptr);
+}
+
+public override Quaternion GetOrientation(BulletBody obj)
+{
+ return BSAPICPP.GetOrientation2(obj.ptr);
+}
+
+public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation)
+{
+ BSAPICPP.SetTranslation2(obj.ptr, position, rotation);
+}
+
+public override IntPtr GetBroadphaseHandle(BulletBody obj)
+{
+ return BSAPICPP.GetBroadphaseHandle2(obj.ptr);
+}
+
+public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
+{
+ BSAPICPP.SetUserPointer2(obj.ptr, handle);
+}
+
+public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
+{
+ BSAPICPP.SetInterpolationLinearVelocity2(obj.ptr, vel);
+}
+
+public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel)
+{
+ BSAPICPP.SetInterpolationAngularVelocity2(obj.ptr, vel);
+}
+
+public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel)
+{
+ BSAPICPP.SetInterpolationVelocity2(obj.ptr, linearVel, angularVel);
+}
+
+public override float GetHitFraction(BulletBody obj)
+{
+ return BSAPICPP.GetHitFraction2(obj.ptr);
+}
+
+public override void SetHitFraction(BulletBody obj, float val)
+{
+ BSAPICPP.SetHitFraction2(obj.ptr, val);
+}
+
+public override CollisionFlags GetCollisionFlags(BulletBody obj)
+{
+ return BSAPICPP.GetCollisionFlags2(obj.ptr);
+}
+
+public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags)
+{
+ return BSAPICPP.SetCollisionFlags2(obj.ptr, flags);
+}
+
+public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags)
+{
+ return BSAPICPP.AddToCollisionFlags2(obj.ptr, flags);
+}
+
+public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags)
+{
+ return BSAPICPP.RemoveFromCollisionFlags2(obj.ptr, flags);
+}
+
+public override float GetCcdMotionThreshold(BulletBody obj)
+{
+ return BSAPICPP.GetCcdMotionThreshold2(obj.ptr);
+}
+
+
+public override void SetCcdMotionThreshold(BulletBody obj, float val)
+{
+ BSAPICPP.SetCcdMotionThreshold2(obj.ptr, val);
+}
+
+public override float GetCcdSweptSphereRadius(BulletBody obj)
+{
+ return BSAPICPP.GetCcdSweptSphereRadius2(obj.ptr);
+}
+
+public override void SetCcdSweptSphereRadius(BulletBody obj, float val)
+{
+ BSAPICPP.SetCcdSweptSphereRadius2(obj.ptr, val);
+}
+
+public override IntPtr GetUserPointer(BulletBody obj)
+{
+ return BSAPICPP.GetUserPointer2(obj.ptr);
+}
+
+public override void SetUserPointer(BulletBody obj, IntPtr val)
+{
+ BSAPICPP.SetUserPointer2(obj.ptr, val);
+}
+
+ /*
+// =====================================================================================
+// btRigidBody entries
+public override void ApplyGravity(BulletBody obj);
+
+public override void SetGravity(BulletBody obj, Vector3 val);
+
+public override Vector3 GetGravity(BulletBody obj);
+
+public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
+
+public override void SetLinearDamping(BulletBody obj, float lin_damping);
+
+public override void SetAngularDamping(BulletBody obj, float ang_damping);
+
+public override float GetLinearDamping(BulletBody obj);
+
+public override float GetAngularDamping(BulletBody obj);
+
+public override float GetLinearSleepingThreshold(BulletBody obj);
+
+
+public override void ApplyDamping(BulletBody obj, float timeStep);
+
+public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
+
+public override Vector3 GetLinearFactor(BulletBody obj);
+
+public override void SetLinearFactor(BulletBody obj, Vector3 factor);
+
+public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
+
+// Add a force to the object as if its mass is one.
+public override void ApplyCentralForce(BulletBody obj, Vector3 force);
+
+// Set the force being applied to the object as if its mass is one.
+public override void SetObjectForce(BulletBody obj, Vector3 force);
+
+public override Vector3 GetTotalForce(BulletBody obj);
+
+public override Vector3 GetTotalTorque(BulletBody obj);
+
+public override Vector3 GetInvInertiaDiagLocal(BulletBody obj);
+
+public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
+
+public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
+
+public override void ApplyTorque(BulletBody obj, Vector3 torque);
+
+// Apply force at the given point. Will add torque to the object.
+public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
+
+// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
+public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
+
+// Apply impulse to the object's torque. Force is scaled by object's mass.
+public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
+
+// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
+public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
+
+public override void ClearForces(BulletBody obj);
+
+public override void ClearAllForces(BulletBody obj);
+
+public override void UpdateInertiaTensor(BulletBody obj);
+
+public override Vector3 GetLinearVelocity(BulletBody obj);
+
+public override Vector3 GetAngularVelocity(BulletBody obj);
+
+public override void SetLinearVelocity(BulletBody obj, Vector3 val);
+
+public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
+
+public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
+
+public override void Translate(BulletBody obj, Vector3 trans);
+
+public override void UpdateDeactivation(BulletBody obj, float timeStep);
+
+public override bool WantsSleeping(BulletBody obj);
+
+public override void SetAngularFactor(BulletBody obj, float factor);
+
+public override void SetAngularFactorV(BulletBody obj, Vector3 factor);
+
+public override Vector3 GetAngularFactor(BulletBody obj);
+
+public override bool IsInWorld(BulletBody obj);
+
+public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
+
+public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
+
+public override BulletConstraint GetConstraintRef(BulletBody obj, int index);
+
+public override int GetNumConstraintRefs(BulletBody obj);
+
+public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
+
+// =====================================================================================
+// btCollisionShape entries
+
+public override float GetAngularMotionDisc(BulletShape shape);
+
+public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
+
+public override bool IsPolyhedral(BulletShape shape);
+
+public override bool IsConvex2d(BulletShape shape);
+
+public override bool IsConvex(BulletShape shape);
+
+public override bool IsNonMoving(BulletShape shape);
+
+public override bool IsConcave(BulletShape shape);
+
+public override bool IsCompound(BulletShape shape);
+
+public override bool IsSoftBody(BulletShape shape);
+
+public override bool IsInfinite(BulletShape shape);
+
+public override void SetLocalScaling(BulletShape shape, Vector3 scale);
+
+public override Vector3 GetLocalScaling(BulletShape shape);
+
+public override Vector3 CalculateLocalInertia(BulletShape shape, float mass);
+
+public override int GetShapeType(BulletShape shape);
+
+public override void SetMargin(BulletShape shape, float val);
+
+public override float GetMargin(BulletShape shape);
+ */
+
+static class BSAPICPP
+{
+// =====================================================================================
+// Mesh, hull, shape and body creation helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateMeshShape2(IntPtr world,
+ int indicesCount, [MarshalAs(UnmanagedType.LPArray)] int[] indices,
+ int verticesCount, [MarshalAs(UnmanagedType.LPArray)] float[] vertices );
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHullShape2(IntPtr world,
+ int hullCount, [MarshalAs(UnmanagedType.LPArray)] float[] hulls);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildHullShapeFromMesh2(IntPtr world, IntPtr meshShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildNativeShape2(IntPtr world, ShapeData shapeData);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsNativeShape2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetShapeCollisionMargin2(IntPtr shape, float margin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr BuildCapsuleShape2(IntPtr world, float radius, float height, Vector3 scale);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateCompoundShape2(IntPtr sim, bool enableDynamicAabbTree);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetNumberOfCompoundChildren2(IntPtr cShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void AddChildShapeToCompoundShape2(IntPtr cShape, IntPtr addShape, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr RemoveChildShapeFromCompoundShapeIndex2(IntPtr cShape, int indx);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RemoveChildShapeFromCompoundShape2(IntPtr cShape, IntPtr removeShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetBodyType2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ReleaseBodyInfo2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
+
+// =====================================================================================
+// Terrain creation and helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
+
+// =====================================================================================
+// Constraint creation and helper routines
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Create6DofConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 frame1loc, Quaternion frame1rot,
+ Vector3 frame2loc, Quaternion frame2rot,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Create6DofConstraintToPoint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 joinPoint,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr CreateHingeConstraint2(IntPtr world, IntPtr obj1, IntPtr obj2,
+ Vector3 pivotinA, Vector3 pivotinB,
+ Vector3 axisInA, Vector3 axisInB,
+ bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetConstraintEnable2(IntPtr constrain, float numericTrueFalse);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetConstraintNumSolverIterations2(IntPtr constrain, float iterations);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetFrames2(IntPtr constrain,
+ Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool CalculateTransforms2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetConstraintParam2(IntPtr constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool DestroyConstraint2(IntPtr world, IntPtr constrain);
+
+// =====================================================================================
+// btCollisionWorld entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateSingleAabb2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateAabbs2(IntPtr world);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool GetForceUpdateAllAabbs2(IntPtr world);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetForceUpdateAllAabbs2(IntPtr world, bool force);
+
+// =====================================================================================
+// btDynamicsWorld entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool AddObjectToWorld2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool RemoveObjectFromWorld2(IntPtr world, IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool AddConstraintToWorld2(IntPtr world, IntPtr constrain, bool disableCollisionsBetweenLinkedObjects);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool RemoveConstraintFromWorld2(IntPtr world, IntPtr constrain);
+// =====================================================================================
+// btCollisionObject entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAnisotripicFriction2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 SetAnisotripicFriction2(IntPtr constrain, Vector3 frict);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool HasAnisotripicFriction2(IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetContactProcessingThreshold2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetContactProcessingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsStaticObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsKinematicObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsStaticOrKinematicObject2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool HasContactResponse2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCollisionShape2(IntPtr sim, IntPtr obj, IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetCollisionShape2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetActivationState2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetActivationState2(IntPtr obj, int state);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetDeactivationTime2(IntPtr obj, float dtime);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetDeactivationTime2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ForceActivationState2(IntPtr obj, ActivationState state);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Activate2(IntPtr obj, bool forceActivation);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsActive2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetRestitution2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetRestitution2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetFriction2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetFriction2(IntPtr obj);
+
+ /* Haven't defined the type 'Transform'
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetWorldTransform2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void setWorldTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetPosition2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Quaternion GetOrientation2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetTranslation2(IntPtr obj, Vector3 position, Quaternion rotation);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetBroadphaseHandle2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetBroadphaseHandle2(IntPtr obj, IntPtr handle);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetInterpolationWorldTransform2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationWorldTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationLinearVelocity2(IntPtr obj, Vector3 vel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationAngularVelocity2(IntPtr obj, Vector3 vel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInterpolationVelocity2(IntPtr obj, Vector3 linearVel, Vector3 angularVel);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetHitFraction2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetHitFraction2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags GetCollisionFlags2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags SetCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags AddToCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern CollisionFlags RemoveFromCollisionFlags2(IntPtr obj, CollisionFlags flags);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetCcdMotionThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCcdMotionThreshold2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetCcdSweptSphereRadius2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCcdSweptSphereRadius2(IntPtr obj, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetUserPointer2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetUserPointer2(IntPtr obj, IntPtr val);
+
+}
+}
+
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+// ===============================================================================
+static class BulletSimAPI {
+// ===============================================================================
+// Link back to the managed code for outputting log messages
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
+
+// ===============================================================================
+// Initialization and simulation
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray,
+ DebugLogCallback logRoutine);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Shutdown2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount,
+ out IntPtr updatedEntitiesPtr,
+ out int collidersCount,
+ out IntPtr collidersPtr);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool PushUpdate2(IntPtr obj);
+
+// =====================================================================================
+// btRigidBody entries
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyGravity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetGravity2(IntPtr obj, Vector3 val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetGravity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetDamping2(IntPtr obj, float lin_damping, float ang_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearDamping2(IntPtr obj, float lin_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularDamping2(IntPtr obj, float ang_damping);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetLinearDamping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularDamping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetLinearSleepingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularSleepingThreshold2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyDamping2(IntPtr obj, float timeStep);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetMassProps2(IntPtr obj, float mass, Vector3 inertia);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLinearFactor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearFactor2(IntPtr obj, Vector3 factor);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCenterOfMassTransform2(IntPtr obj, Transform trans);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetCenterOfMassByPosRot2(IntPtr obj, Vector3 pos, Quaternion rot);
+
+// Add a force to the object as if its mass is one.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyCentralForce2(IntPtr obj, Vector3 force);
+
+// Set the force being applied to the object as if its mass is one.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetObjectForce2(IntPtr obj, Vector3 force);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetTotalForce2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetTotalTorque2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetInvInertiaDiagLocal2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetInvInertiaDiagLocal2(IntPtr obj, Vector3 inert);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetSleepingThresholds2(IntPtr obj, float lin_threshold, float ang_threshold);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyTorque2(IntPtr obj, Vector3 torque);
+
+// Apply force at the given point. Will add torque to the object.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyForce2(IntPtr obj, Vector3 force, Vector3 pos);
+
+// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyCentralImpulse2(IntPtr obj, Vector3 imp);
+
+// Apply impulse to the object's torque. Force is scaled by object's mass.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyTorqueImpulse2(IntPtr obj, Vector3 imp);
+
+// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ApplyImpulse2(IntPtr obj, Vector3 imp, Vector3 pos);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ClearForces2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void ClearAllForces2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateInertiaTensor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetCenterOfMassPosition2(IntPtr obj);
+
+ /*
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Transform GetCenterOfMassTransform2(IntPtr obj);
+ */
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLinearVelocity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAngularVelocity2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLinearVelocity2(IntPtr obj, Vector3 val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularVelocity2(IntPtr obj, Vector3 angularVelocity);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetVelocityInLocalPoint2(IntPtr obj, Vector3 pos);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Translate2(IntPtr obj, Vector3 trans);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void UpdateDeactivation2(IntPtr obj, float timeStep);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool WantsSleeping2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularFactor2(IntPtr obj, float factor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetAngularFactorV2(IntPtr obj, Vector3 factor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetAngularFactor2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsInWorld2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void AddConstraintRef2(IntPtr obj, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void RemoveConstraintRef2(IntPtr obj, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr GetConstraintRef2(IntPtr obj, int index);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetNumConstraintRefs2(IntPtr obj);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool SetCollisionGroupMask2(IntPtr body, uint filter, uint mask);
+
+// =====================================================================================
+// btCollisionShape entries
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetAngularMotionDisc2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetContactBreakingThreshold2(IntPtr shape, float defaultFactor);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsPolyhedral2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConvex2d2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConvex2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsNonMoving2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsConcave2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsCompound2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsSoftBody2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool IsInfinite2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetLocalScaling2(IntPtr shape, Vector3 scale);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 GetLocalScaling2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern Vector3 CalculateLocalInertia2(IntPtr shape, float mass);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int GetShapeType2(IntPtr shape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetMargin2(IntPtr shape, float val);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern float GetMargin2(IntPtr shape);
+
+// =====================================================================================
+// Debugging
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpRigidBody2(IntPtr sim, IntPtr collisionObject);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpCollisionShape2(IntPtr sim, IntPtr collisionShape);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpMapInfo2(IntPtr sim, IntPtr manInfo);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpConstraint2(IntPtr sim, IntPtr constrain);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpActivationInfo2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpAllInfo2(IntPtr sim);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void DumpPhysicsStatistics2(IntPtr sim);
+
+}
+}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index d5ab245..328164b 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -137,7 +137,7 @@ public sealed class BSCharacter : BSPhysObject
private void SetPhysicalProperties()
{
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
ZeroMotion(true);
ForcePosition = _position;
@@ -152,14 +152,14 @@ public sealed class BSCharacter : BSPhysObject
// Needs to be reset especially when an avatar is recreated after crossing a region boundry.
Flying = _flying;
- BulletSimAPI.SetRestitution2(PhysBody.ptr, BSParam.AvatarRestitution);
+ PhysicsScene.PE.SetRestitution(PhysBody, BSParam.AvatarRestitution);
BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin);
BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
- BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold);
+ PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
if (BSParam.CcdMotionThreshold > 0f)
{
- BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold);
- BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
+ PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
+ PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
}
UpdatePhysicalMassProperties(RawMass, false);
@@ -167,13 +167,13 @@ public sealed class BSCharacter : BSPhysObject
// Make so capsule does not fall over
BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
- BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT);
+ PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT);
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
- // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG);
- BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_DEACTIVATION);
- BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
+ // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
+ PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION);
+ PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
// Do this after the object has been added to the world
PhysBody.collisionType = CollisionType.Avatar;
@@ -320,7 +320,7 @@ public sealed class BSCharacter : BSPhysObject
{
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
+ PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero);
BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
// The next also get rid of applied linear force but the linear velocity is untouched.
BulletSimAPI.ClearForces2(PhysBody.ptr);
@@ -350,19 +350,19 @@ public sealed class BSCharacter : BSPhysObject
{
DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
});
}
}
public override OMV.Vector3 ForcePosition {
get {
- _position = BulletSimAPI.GetPosition2(PhysBody.ptr);
+ _position = PhysicsScene.PE.GetPosition(PhysBody);
return _position;
}
set {
_position = value;
PositionSanityCheck();
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
}
}
@@ -418,7 +418,7 @@ public sealed class BSCharacter : BSPhysObject
{
DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
});
ret = true;
}
@@ -520,7 +520,7 @@ public sealed class BSCharacter : BSPhysObject
{
_currentFriction = BSParam.AvatarStandingFriction;
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
+ PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
}
}
else
@@ -529,12 +529,12 @@ public sealed class BSCharacter : BSPhysObject
{
_currentFriction = BSParam.AvatarFriction;
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
+ PhysicsScene.PE.SetFriction(PhysBody, _currentFriction);
}
}
BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
- BulletSimAPI.Activate2(PhysBody.ptr, true);
+ PhysicsScene.PE.Activate(PhysBody, true);
}
}
public override OMV.Vector3 Torque {
@@ -576,7 +576,7 @@ public sealed class BSCharacter : BSPhysObject
{
get
{
- _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr);
+ _orientation = PhysicsScene.PE.GetOrientation(PhysBody);
return _orientation;
}
set
@@ -584,8 +584,8 @@ public sealed class BSCharacter : BSPhysObject
_orientation = value;
if (PhysBody.HasPhysicalBody)
{
- // _position = BulletSimAPI.GetPosition2(BSBody.ptr);
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ // _position = PhysicsScene.PE.GetPosition(BSBody);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
}
}
}
@@ -636,9 +636,9 @@ public sealed class BSCharacter : BSPhysObject
if (PhysBody.HasPhysicalBody)
{
if (_floatOnWater)
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
else
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
}
});
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
index 59584b2..c9c7c2e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
@@ -37,6 +37,7 @@ public abstract class BSConstraint : IDisposable
private static string LogHeader = "[BULLETSIM CONSTRAINT]";
protected BulletWorld m_world;
+ protected BSScene PhysicsScene;
protected BulletBody m_body1;
protected BulletBody m_body2;
protected BulletConstraint m_constraint;
@@ -48,8 +49,10 @@ public abstract class BSConstraint : IDisposable
public abstract ConstraintType Type { get; }
public bool IsEnabled { get { return m_enabled; } }
- public BSConstraint()
+ public BSConstraint(BulletWorld world)
{
+ m_world = world;
+ PhysicsScene = m_world.physicsScene;
}
public virtual void Dispose()
@@ -59,7 +62,7 @@ public abstract class BSConstraint : IDisposable
m_enabled = false;
if (m_constraint.HasPhysicalConstraint)
{
- bool success = BulletSimAPI.DestroyConstraint2(m_world.ptr, m_constraint.ptr);
+ bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint);
m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}",
BSScene.DetailLogZero,
m_body1.ID, m_body1.ptr.ToString("X"),
@@ -74,7 +77,7 @@ public abstract class BSConstraint : IDisposable
{
bool ret = false;
if (m_enabled)
- ret = BulletSimAPI.SetLinearLimits2(m_constraint.ptr, low, high);
+ ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high);
return ret;
}
@@ -82,7 +85,7 @@ public abstract class BSConstraint : IDisposable
{
bool ret = false;
if (m_enabled)
- ret = BulletSimAPI.SetAngularLimits2(m_constraint.ptr, low, high);
+ ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high);
return ret;
}
@@ -91,7 +94,7 @@ public abstract class BSConstraint : IDisposable
bool ret = false;
if (m_enabled)
{
- BulletSimAPI.SetConstraintNumSolverIterations2(m_constraint.ptr, cnt);
+ PhysicsScene.PE.SetConstraintNumSolverIterations(m_constraint, cnt);
ret = true;
}
return ret;
@@ -103,7 +106,7 @@ public abstract class BSConstraint : IDisposable
if (m_enabled)
{
// Recompute the internal transforms
- BulletSimAPI.CalculateTransforms2(m_constraint.ptr);
+ PhysicsScene.PE.CalculateTransforms(m_constraint);
ret = true;
}
return ret;
@@ -122,7 +125,7 @@ public abstract class BSConstraint : IDisposable
// Setting an object's mass to zero (making it static like when it's selected)
// automatically disables the constraints.
// If the link is enabled, be sure to set the constraint itself to enabled.
- BulletSimAPI.SetConstraintEnable2(m_constraint.ptr, BSParam.NumericBool(true));
+ PhysicsScene.PE.SetConstraintEnable(m_constraint, BSParam.NumericBool(true));
}
else
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
index b946870..aee93c9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
@@ -43,15 +43,14 @@ public sealed class BSConstraint6Dof : BSConstraint
Vector3 frame1, Quaternion frame1rot,
Vector3 frame2, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+ : base(world)
{
- m_world = world;
m_body1 = obj1;
m_body2 = obj2;
- m_constraint = new BulletConstraint(
- BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,
+ m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2,
frame1, frame1rot,
frame2, frame2rot,
- useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+ useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
m_enabled = true;
world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
BSScene.DetailLogZero, world.worldID,
@@ -61,8 +60,8 @@ public sealed class BSConstraint6Dof : BSConstraint
public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+ : base(world)
{
- m_world = world;
m_body1 = obj1;
m_body2 = obj2;
if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody)
@@ -76,11 +75,10 @@ public sealed class BSConstraint6Dof : BSConstraint
}
else
{
- m_constraint = new BulletConstraint(
- BulletSimAPI.Create6DofConstraintToPoint2(m_world.ptr, m_body1.ptr, m_body2.ptr,
+ m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2,
joinPoint,
- useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
- world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
+ useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
+ PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"),
obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
if (!m_constraint.HasPhysicalConstraint)
@@ -101,7 +99,7 @@ public sealed class BSConstraint6Dof : BSConstraint
bool ret = false;
if (m_enabled)
{
- BulletSimAPI.SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot);
+ PhysicsScene.PE.SetFrames(m_constraint, frameA, frameArot, frameB, frameBrot);
ret = true;
}
return ret;
@@ -112,9 +110,9 @@ public sealed class BSConstraint6Dof : BSConstraint
bool ret = false;
if (m_enabled)
{
- BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
- BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
- BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
+ PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
+ PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
+ PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
ret = true;
}
return ret;
@@ -125,7 +123,7 @@ public sealed class BSConstraint6Dof : BSConstraint
bool ret = false;
float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
if (m_enabled)
- ret = BulletSimAPI.UseFrameOffset2(m_constraint.ptr, onOff);
+ ret = PhysicsScene.PE.UseFrameOffset(m_constraint, onOff);
return ret;
}
@@ -135,7 +133,7 @@ public sealed class BSConstraint6Dof : BSConstraint
float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
if (m_enabled)
{
- ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.ptr, onOff, targetVelocity, maxMotorForce);
+ ret = PhysicsScene.PE.TranslationalLimitMotor(m_constraint, onOff, targetVelocity, maxMotorForce);
m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}",
BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce);
}
@@ -146,7 +144,7 @@ public sealed class BSConstraint6Dof : BSConstraint
{
bool ret = false;
if (m_enabled)
- ret = BulletSimAPI.SetBreakingImpulseThreshold2(m_constraint.ptr, threshold);
+ ret = PhysicsScene.PE.SetBreakingImpulseThreshold(m_constraint, threshold);
return ret;
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
index a5378b9..7714a03 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraintHinge.cs
@@ -40,15 +40,13 @@ public sealed class BSConstraintHinge : BSConstraint
Vector3 pivotInA, Vector3 pivotInB,
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
+ : base(world)
{
- m_world = world;
m_body1 = obj1;
m_body2 = obj2;
- m_constraint = new BulletConstraint(
- BulletSimAPI.CreateHingeConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,
- pivotInA, pivotInB,
- axisInA, axisInB,
- useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+ m_constraint = PhysicsScene.PE.CreateHingeConstraint(world, obj1, obj2,
+ pivotInA, pivotInB, axisInA, axisInB,
+ useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
m_enabled = true;
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 0bdfbe3..5d70ef7 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -558,7 +558,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// Friction affects are handled by this vehicle code
float friction = 0f;
- BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, friction);
+ PhysicsScene.PE.SetFriction(Prim.PhysBody, friction);
// Moderate angular movement introduced by Bullet.
// TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
@@ -567,7 +567,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
// Vehicles report collision events so we know when it's on the ground
- BulletSimAPI.AddToCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS);
+ PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass);
BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia);
@@ -581,7 +581,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
}
else
{
- BulletSimAPI.RemoveFromCollisionFlags2(Prim.PhysBody.ptr, CollisionFlags.BS_VEHICLE_COLLISIONS);
+ PhysicsScene.PE.RemoveFromCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
}
}
@@ -651,7 +651,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
if ((m_knownChanged & m_knownChangedVelocity) != 0)
{
Prim.ForceVelocity = m_knownVelocity;
- BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity);
+ PhysicsScene.PE.SetInterpolationLinearVelocity(Prim.PhysBody, VehicleVelocity);
}
if ((m_knownChanged & m_knownChangedForce) != 0)
@@ -661,7 +661,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
Prim.ForceRotationalVelocity = m_knownRotationalVelocity;
// Fake out Bullet by making it think the velocity is the same as last time.
- BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, m_knownRotationalVelocity);
+ PhysicsScene.PE.SetInterpolationAngularVelocity(Prim.PhysBody, m_knownRotationalVelocity);
}
if ((m_knownChanged & m_knownChangedRotationalForce) != 0)
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 9bb951c..3c99ca7 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -131,10 +131,10 @@ public sealed class BSLinksetCompound : BSLinkset
{
// The origional prims are removed from the world as the shape of the root compound
// shape takes over.
- BulletSimAPI.AddToCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
- BulletSimAPI.ForceActivationState2(child.PhysBody.ptr, ActivationState.DISABLE_SIMULATION);
+ PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION);
// We don't want collisions from the old linkset children.
- BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
child.PhysBody.collisionType = CollisionType.LinksetChild;
@@ -159,12 +159,12 @@ public sealed class BSLinksetCompound : BSLinkset
else
{
// The non-physical children can come back to life.
- BulletSimAPI.RemoveFromCollisionFlags2(child.PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
child.PhysBody.collisionType = CollisionType.LinksetChild;
// Don't force activation so setting of DISABLE_SIMULATION can stay if used.
- BulletSimAPI.Activate2(child.PhysBody.ptr, false);
+ PhysicsScene.PE.Activate(child.PhysBody, false);
ret = true;
}
return ret;
@@ -371,7 +371,7 @@ public sealed class BSLinksetCompound : BSLinkset
PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}",
LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape);
}
- PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
+ PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, lci.OffsetPos, lci.OffsetRot);
}
}
return false; // 'false' says to move onto the next child in the list
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index 5c8553a..c6c2946 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -300,7 +300,7 @@ public static class BSParam
(s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
(s) => { return DeactivationTime; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{DeactivationTime=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.PhysBody.ptr, v); } ),
+ (s,o,v) => { s.PE.SetDeactivationTime(o.PhysBody, v); } ),
new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
0.8f,
(s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
@@ -318,19 +318,19 @@ public static class BSParam
(s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
(s) => { return CcdMotionThreshold; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdMotionThreshold=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.PhysBody.ptr, v); } ),
+ (s,o,v) => { s.PE.SetCcdMotionThreshold(o.PhysBody, v); } ),
new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
0f,
(s,cf,p,v) => { CcdSweptSphereRadius = cf.GetFloat(p, v); },
(s) => { return CcdSweptSphereRadius; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{CcdSweptSphereRadius=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetCcdSweptSphereRadius2(o.PhysBody.ptr, v); } ),
+ (s,o,v) => { s.PE.SetCcdSweptSphereRadius(o.PhysBody, v); } ),
new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
0.1f,
(s,cf,p,v) => { ContactProcessingThreshold = cf.GetFloat(p, v); },
(s) => { return ContactProcessingThreshold; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{ContactProcessingThreshold=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ),
+ (s,o,v) => { s.PE.SetContactProcessingThreshold(o.PhysBody, v); } ),
new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
(float)BSTerrainPhys.TerrainImplementation.Mesh,
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index b093890..e7cb3e0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -308,7 +308,7 @@ public abstract class BSPhysObject : PhysicsActor
PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate()
{
if (PhysBody.HasPhysicalBody)
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
});
}
else
@@ -324,7 +324,7 @@ public abstract class BSPhysObject : PhysicsActor
{
// Make sure there is a body there because sometimes destruction happens in an un-ideal order.
if (PhysBody.HasPhysicalBody)
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
});
}
// Return 'true' if the simulator wants collision events
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index cf09be2..613606f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -120,7 +120,7 @@ public sealed class BSPrim : BSPhysObject
{
CreateGeomAndObject(true);
- CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(PhysBody.ptr);
+ CurrentCollisionFlags = PhysicsScene.PE.GetCollisionFlags(PhysBody);
});
}
@@ -265,7 +265,7 @@ public sealed class BSPrim : BSPhysObject
// DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity);
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity);
BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
}
});
@@ -318,14 +318,14 @@ public sealed class BSPrim : BSPhysObject
}
public override OMV.Vector3 ForcePosition {
get {
- _position = BulletSimAPI.GetPosition2(PhysBody.ptr);
+ _position = PhysicsScene.PE.GetPosition(PhysBody);
return _position;
}
set {
_position = value;
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
ActivateIfPhysical(false);
}
}
@@ -419,7 +419,7 @@ public sealed class BSPrim : BSPhysObject
// Changing interesting properties doesn't change proxy and collision cache
// information. The Bullet solution is to re-add the object to the world
// after parameters are changed.
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
}
// The computation of mass props requires gravity to be set on the object.
@@ -649,9 +649,9 @@ public sealed class BSPrim : BSPhysObject
{
if (PhysBody.HasPhysicalBody)
{
- // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr);
+ // _position = PhysicsScene.PE.GetObjectPosition(PhysicsScene.World, BSBody);
// DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
}
});
}
@@ -661,13 +661,13 @@ public sealed class BSPrim : BSPhysObject
{
get
{
- _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr);
+ _orientation = PhysicsScene.PE.GetOrientation(PhysBody);
return _orientation;
}
set
{
_orientation = value;
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
}
}
public override int PhysicsActorType {
@@ -723,7 +723,7 @@ public sealed class BSPrim : BSPhysObject
// Mangling all the physical properties requires the object not be in the physical world.
// This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found).
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, PhysBody);
// Set up the object physicalness (does gravity and collisions move this object)
MakeDynamic(IsStatic);
@@ -740,7 +740,7 @@ public sealed class BSPrim : BSPhysObject
AddObjectToPhysicalWorld();
// Rebuild its shape
- BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
// Recompute any linkset parameters.
// When going from non-physical to physical, this re-enables the constraints that
@@ -762,28 +762,28 @@ public sealed class BSPrim : BSPhysObject
if (makeStatic)
{
// Become a Bullet 'static' object type
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
// Stop all movement
ZeroMotion(true);
// Set various physical properties so other object interact properly
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
- BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
- BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
+ PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction);
+ PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution);
// Mass is zero which disables a bunch of physics stuff in Bullet
UpdatePhysicalMassProperties(0f, false);
// Set collision detection parameters
if (BSParam.CcdMotionThreshold > 0f)
{
- BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold);
- BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
+ PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
+ PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
}
// The activation state is 'disabled' so Bullet will not try to act on it.
- // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION);
+ // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_SIMULATION);
// Start it out sleeping and physical actions could wake it up.
- BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING);
+ PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ISLAND_SLEEPING);
// This collides like a static object
PhysBody.collisionType = CollisionType.Static;
@@ -794,22 +794,22 @@ public sealed class BSPrim : BSPhysObject
else
{
// Not a Bullet static object
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT);
// Set various physical properties so other object interact properly
MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
- BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
- BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
+ PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction);
+ PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution);
// per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
// Since this can be called multiple times, only zero forces when becoming physical
- // BulletSimAPI.ClearAllForces2(BSBody.ptr);
+ // PhysicsScene.PE.ClearAllForces(BSBody);
// For good measure, make sure the transform is set through to the motion state
- BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
+ PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
// Center of mass is at the center of the object
- // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
+ // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody, _position, _orientation);
// A dynamic object has mass
UpdatePhysicalMassProperties(RawMass, false);
@@ -817,22 +817,22 @@ public sealed class BSPrim : BSPhysObject
// Set collision detection parameters
if (BSParam.CcdMotionThreshold > 0f)
{
- BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold);
- BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius);
+ PhysicsScene.PE.SetCcdMotionThreshold(PhysBody, BSParam.CcdMotionThreshold);
+ PhysicsScene.PE.SetCcdSweptSphereRadius(PhysBody, BSParam.CcdSweptSphereRadius);
}
// Various values for simulation limits
BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping);
- BulletSimAPI.SetDeactivationTime2(PhysBody.ptr, BSParam.DeactivationTime);
+ PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime);
BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold);
- BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold);
+ PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
// This collides like an object.
PhysBody.collisionType = CollisionType.Dynamic;
// Force activation of the object so Bullet will act on it.
// Must do the ForceActivationState2() to overcome the DISABLE_SIMULATION from static objects.
- BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ACTIVE_TAG);
+ PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
// There might be special things needed for implementing linksets.
Linkset.MakeDynamic(this);
@@ -853,7 +853,7 @@ public sealed class BSPrim : BSPhysObject
{
m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for solidity. id={1}, type={2}", LogHeader, LocalID, bodyType);
}
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
}
else
{
@@ -861,7 +861,7 @@ public sealed class BSPrim : BSPhysObject
{
m_log.ErrorFormat("{0} MakeSolid: physical body of wrong type for non-solidness. id={1}, type={2}", LogHeader, LocalID, bodyType);
}
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
// Change collision info from a static object to a ghosty collision object
PhysBody.collisionType = CollisionType.VolumeDetect;
@@ -874,7 +874,7 @@ public sealed class BSPrim : BSPhysObject
private void ActivateIfPhysical(bool forceIt)
{
if (IsPhysical && PhysBody.HasPhysicalBody)
- BulletSimAPI.Activate2(PhysBody.ptr, forceIt);
+ PhysicsScene.PE.Activate(PhysBody, forceIt);
}
// Turn on or off the flag controlling whether collision events are returned to the simulator.
@@ -882,11 +882,11 @@ public sealed class BSPrim : BSPhysObject
{
if (wantsCollisionEvents)
{
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
}
else
{
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
}
}
@@ -897,7 +897,7 @@ public sealed class BSPrim : BSPhysObject
{
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
// TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
// Replace this when the new AddObjectToWorld function is complete.
@@ -941,9 +941,9 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate()
{
if (_floatOnWater)
- CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
else
- CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
+ CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_FLOATS_ON_WATER);
});
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index e7d8d14..6f819d8 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -143,7 +143,7 @@ public sealed class BSShapeCollection : IDisposable
{
if (!BulletSimAPI.IsInWorld2(body.ptr))
{
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, body.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body);
if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
}
});
@@ -168,12 +168,12 @@ public sealed class BSShapeCollection : IDisposable
if (BulletSimAPI.IsInWorld2(body.ptr))
{
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body);
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
}
// Zero any reference to the shape so it is not freed when the body is deleted.
- BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero);
+ PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape());
PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
});
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index a2c085e..01966c0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -91,13 +91,12 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
// Using the information in m_mapInfo, create the physical representation of the heightmap.
private void BuildHeightmapTerrain()
{
- m_mapInfo.Ptr = BulletSimAPI.CreateHeightMapInfo2(PhysicsScene.World.ptr, m_mapInfo.ID,
+ m_mapInfo.Ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID,
m_mapInfo.minCoords, m_mapInfo.maxCoords,
m_mapInfo.heightMap, BSParam.TerrainCollisionMargin);
// Create the terrain shape from the mapInfo
- m_mapInfo.terrainShape = new BulletShape(BulletSimAPI.CreateTerrainShape2(m_mapInfo.Ptr),
- BSPhysicsShapeType.SHAPE_TERRAIN);
+ m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.Ptr);
// The terrain object initial position is at the center of the object
Vector3 centerPos;
@@ -109,22 +108,22 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
m_mapInfo.ID, centerPos, Quaternion.Identity);
// Set current terrain attributes
- BulletSimAPI.SetFriction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainFriction);
- BulletSimAPI.SetHitFraction2(m_mapInfo.terrainBody.ptr, BSParam.TerrainHitFraction);
- BulletSimAPI.SetRestitution2(m_mapInfo.terrainBody.ptr, BSParam.TerrainRestitution);
- BulletSimAPI.SetCollisionFlags2(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction);
+ PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction);
+ PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution);
+ PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT);
// Return the new terrain to the world of physical objects
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody);
// redo its bounding box now that it is in the world
- BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody);
m_mapInfo.terrainBody.collisionType = CollisionType.Terrain;
m_mapInfo.terrainBody.ApplyCollisionMask();
// Make it so the terrain will not move or be considered for movement.
- BulletSimAPI.ForceActivationState2(m_mapInfo.terrainBody.ptr, ActivationState.DISABLE_SIMULATION);
+ PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION);
return;
}
@@ -136,10 +135,10 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
{
if (m_mapInfo.terrainBody.HasPhysicalBody)
{
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody);
// Frees both the body and the shape.
PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody);
- BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr);
+ PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.Ptr);
}
}
m_mapInfo = null;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index d99a50f..590c687 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -133,17 +133,14 @@ public sealed class BSTerrainManager : IDisposable
public void CreateInitialGroundPlaneAndTerrain()
{
// The ground plane is here to catch things that are trying to drop to negative infinity
- BulletShape groundPlaneShape = new BulletShape(
- BulletSimAPI.CreateGroundPlaneShape2(BSScene.GROUNDPLANE_ID, 1f,
- BSParam.TerrainCollisionMargin),
- BSPhysicsShapeType.SHAPE_GROUNDPLANE);
+ BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);
m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr);
- BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_groundPlane.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane);
+ PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane);
// Ground plane does not move
- BulletSimAPI.ForceActivationState2(m_groundPlane.ptr, ActivationState.DISABLE_SIMULATION);
+ PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
// Everything collides with the ground plane.
m_groundPlane.collisionType = CollisionType.Groundplane;
m_groundPlane.ApplyCollisionMask();
@@ -158,7 +155,7 @@ public sealed class BSTerrainManager : IDisposable
{
if (m_groundPlane.HasPhysicalBody)
{
- if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_groundPlane.ptr))
+ if (PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_groundPlane))
{
PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_groundPlane);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
index d8c4972..2f55fc3 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
@@ -114,32 +114,32 @@ public sealed class BSTerrainMesh : BSTerrainPhys
}
// Set current terrain attributes
- BulletSimAPI.SetFriction2(m_terrainBody.ptr, BSParam.TerrainFriction);
- BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, BSParam.TerrainHitFraction);
- BulletSimAPI.SetRestitution2(m_terrainBody.ptr, BSParam.TerrainRestitution);
- BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ PhysicsScene.PE.SetFriction(m_terrainBody, BSParam.TerrainFriction);
+ PhysicsScene.PE.SetHitFraction(m_terrainBody, BSParam.TerrainHitFraction);
+ PhysicsScene.PE.SetRestitution(m_terrainBody, BSParam.TerrainRestitution);
+ PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);
// Static objects are not very massive.
BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero);
// Put the new terrain to the world of physical objects
- BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody);
// Redo its bounding box now that it is in the world
- BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody);
m_terrainBody.collisionType = CollisionType.Terrain;
m_terrainBody.ApplyCollisionMask();
// Make it so the terrain will not move or be considered for movement.
- BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION);
+ PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION);
}
public override void Dispose()
{
if (m_terrainBody.HasPhysicalBody)
{
- BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr);
+ PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_terrainBody);
// Frees both the body and the shape.
PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_terrainBody);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index 6b76151..b119f22 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -367,7 +367,6 @@ public abstract void ReleaseBodyInfo(IntPtr obj);
public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
- /*
// =====================================================================================
// Terrain creation and helper routines
public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
@@ -378,9 +377,9 @@ public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint i
public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
-public abstract BulletBody CreateGroundPlaneShape(uint id, float height, float collisionMargin);
+public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-public abstract BulletBody CreateTerrainShape(IntPtr mapInfo);
+public abstract BulletShape CreateTerrainShape(IntPtr mapInfo);
// =====================================================================================
// Constraint creation and helper routines
@@ -460,7 +459,7 @@ public abstract bool IsStaticOrKinematicObject(BulletBody obj);
public abstract bool HasContactResponse(BulletBody obj);
-public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletBody shape);
+public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
public abstract BulletShape GetCollisionShape(BulletBody obj);
@@ -526,6 +525,7 @@ public abstract IntPtr GetUserPointer(BulletBody obj);
public abstract void SetUserPointer(BulletBody obj, IntPtr val);
+ /*
// =====================================================================================
// btRigidBody entries
public abstract void ApplyGravity(BulletBody obj);
--
cgit v1.1
From 5379d6d112a8027c8f0f62ba77303e8b69e24332 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sun, 30 Dec 2012 10:37:37 -0800
Subject: BulletSim: remove all the debug printing of pointer formatting
(.ToString(X)) and replace it with a method on BulletBody, BulletShape, ...
---
.../Region/Physics/BulletSPlugin/BSConstraint.cs | 4 +--
.../Physics/BulletSPlugin/BSConstraint6Dof.cs | 10 +++----
.../Physics/BulletSPlugin/BSLinksetCompound.cs | 6 ++---
.../Physics/BulletSPlugin/BSLinksetConstraints.cs | 16 +++++------
.../Physics/BulletSPlugin/BSShapeCollection.cs | 8 +++---
OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 8 +++++-
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 31 ++++++++++++++++++++--
7 files changed, 58 insertions(+), 25 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
index c9c7c2e..b813974 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs
@@ -65,8 +65,8 @@ public abstract class BSConstraint : IDisposable
bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint);
m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}",
BSScene.DetailLogZero,
- m_body1.ID, m_body1.ptr.ToString("X"),
- m_body2.ID, m_body2.ptr.ToString("X"),
+ m_body1.ID, m_body1.AddrString,
+ m_body2.ID, m_body2.AddrString,
success);
m_constraint.Clear();
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
index aee93c9..ecb1b32 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs
@@ -54,7 +54,7 @@ public sealed class BSConstraint6Dof : BSConstraint
m_enabled = true;
world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
BSScene.DetailLogZero, world.worldID,
- obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
+ obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
}
public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
@@ -68,9 +68,9 @@ public sealed class BSConstraint6Dof : BSConstraint
{
world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
BSScene.DetailLogZero, world.worldID,
- obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
+ obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
- LogHeader, world.worldID, obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
+ LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
m_enabled = false;
}
else
@@ -79,8 +79,8 @@ public sealed class BSConstraint6Dof : BSConstraint
joinPoint,
useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
- BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString("X"),
- obj1.ID, obj1.ptr.ToString("X"), obj2.ID, obj2.ptr.ToString("X"));
+ BSScene.DetailLogZero, world.worldID, m_constraint.AddrString,
+ obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
if (!m_constraint.HasPhysicalConstraint)
{
world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}",
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 3c99ca7..143c60c 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -196,7 +196,7 @@ public sealed class BSLinksetCompound : BSLinkset
bool ret = false;
DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}",
- child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), IsRoot(child));
+ child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, IsRoot(child));
if (!IsRoot(child))
{
@@ -280,8 +280,8 @@ public sealed class BSLinksetCompound : BSLinkset
{
DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
child.LocalID,
- LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"),
- child.LocalID, child.PhysBody.ptr.ToString("X"));
+ LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString,
+ child.LocalID, child.PhysBody.AddrString);
// Cause the child's body to be rebuilt and thus restored to normal operation
RecomputeChildWorldPosition(child, false);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 86c29c7..629bc72 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -98,7 +98,7 @@ public sealed class BSLinksetConstraints : BSLinkset
bool ret = false;
DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
- child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"));
+ child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);
lock (m_linksetActivityLock)
{
@@ -147,8 +147,8 @@ public sealed class BSLinksetConstraints : BSLinkset
DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
childx.LocalID,
- rootx.LocalID, rootx.PhysBody.ptr.ToString("X"),
- childx.LocalID, childx.PhysBody.ptr.ToString("X"));
+ rootx.LocalID, rootx.PhysBody.AddrString,
+ childx.LocalID, childx.PhysBody.AddrString);
PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate()
{
@@ -187,8 +187,8 @@ public sealed class BSLinksetConstraints : BSLinkset
DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
rootPrim.LocalID,
- rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"),
- childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X"),
+ rootPrim.LocalID, rootPrim.PhysBody.AddrString,
+ childPrim.LocalID, childPrim.PhysBody.AddrString,
rootPrim.Position, childPrim.Position, midPoint);
// create a constraint that allows no freedom of movement between the two objects
@@ -252,8 +252,8 @@ public sealed class BSLinksetConstraints : BSLinkset
bool ret = false;
DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
rootPrim.LocalID,
- rootPrim.LocalID, rootPrim.PhysBody.ptr.ToString("X"),
- childPrim.LocalID, childPrim.PhysBody.ptr.ToString("X"));
+ rootPrim.LocalID, rootPrim.PhysBody.AddrString,
+ childPrim.LocalID, childPrim.PhysBody.AddrString);
// Find the constraint for this link and get rid of it from the overall collection and from my list
if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
@@ -290,7 +290,7 @@ public sealed class BSLinksetConstraints : BSLinkset
// BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
// (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
- LinksetRoot.LocalID, LinksetRoot.PhysBody.ptr.ToString("X"), linksetMass);
+ LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass);
foreach (BSPhysObject child in m_children)
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 6f819d8..d59e455 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -259,7 +259,7 @@ public sealed class BSShapeCollection : IDisposable
{
// Native shapes are not tracked and are released immediately
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}",
- BSScene.DetailLogZero, shape.ptr.ToString("X"), inTaintTime);
+ BSScene.DetailLogZero, shape.AddrString, inTaintTime);
if (shapeCallback != null) shapeCallback(shape);
PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
}
@@ -336,9 +336,9 @@ public sealed class BSShapeCollection : IDisposable
{
// Failed the sanity check!!
PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
- LogHeader, shape.type, shape.ptr.ToString("X"));
+ LogHeader, shape.type, shape.AddrString);
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}",
- BSScene.DetailLogZero, shape.type, shape.ptr.ToString("X"));
+ BSScene.DetailLogZero, shape.type, shape.AddrString);
return;
}
@@ -400,7 +400,7 @@ public sealed class BSShapeCollection : IDisposable
else
{
PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
- LogHeader, PhysicsScene.RegionName, cShape.ToString("X"));
+ LogHeader, PhysicsScene.RegionName, shapeInfo.AddrString);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index cdaa869..423e700 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -91,11 +91,17 @@ public abstract class BSShape
// All shapes have a static call to get a reference to the physical shape
// protected abstract static BSShape GetReference();
+ // Returns a string for debugging that uniquily identifies the memory used by this instance
+ public string AddrString
+ {
+ get { return ptr.ToString("X"); }
+ }
+
public override string ToString()
{
StringBuilder buff = new StringBuilder();
buff.Append("");
@@ -124,11 +133,20 @@ public class BulletShape
}
public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } }
+ // Used for log messages for a unique display of the memory/object allocated to this instance
+ public string AddrString
+ {
+ get
+ {
+ return ptr.ToString("X");
+ }
+ }
+
public override string ToString()
{
StringBuilder buff = new StringBuilder();
buff.Append("
0f)
{
@@ -165,19 +165,19 @@ public sealed class BSCharacter : BSPhysObject
UpdatePhysicalMassProperties(RawMass, false);
// Make so capsule does not fall over
- BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
+ PhysicsScene.PE.SetAngularFactorV(PhysBody, OMV.Vector3.Zero);
PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.CF_CHARACTER_OBJECT);
PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
- // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
+ // PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.ACTIVE_TAG);
PhysicsScene.PE.ForceActivationState(PhysBody, ActivationState.DISABLE_DEACTIVATION);
PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, PhysBody);
// Do this after the object has been added to the world
PhysBody.collisionType = CollisionType.Avatar;
- PhysBody.ApplyCollisionMask();
+ PhysBody.ApplyCollisionMask(PhysicsScene);
}
// The avatar's movement is controlled by this motor that speeds up and slows down
@@ -265,10 +265,10 @@ public sealed class BSCharacter : BSPhysObject
{
if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape)
{
- BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
+ PhysicsScene.PE.SetLocalScaling(PhysShape, Scale);
UpdatePhysicalMassProperties(RawMass, true);
// Make sure this change appears as a property update event
- BulletSimAPI.PushUpdate2(PhysBody.ptr);
+ PhysicsScene.PE.PushUpdate(PhysBody);
}
});
@@ -309,7 +309,7 @@ public sealed class BSCharacter : BSPhysObject
PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
{
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.ClearAllForces2(PhysBody.ptr);
+ PhysicsScene.PE.ClearAllForces(PhysBody);
});
}
public override void ZeroAngularMotion(bool inTaintTime)
@@ -321,9 +321,9 @@ public sealed class BSCharacter : BSPhysObject
if (PhysBody.HasPhysicalBody)
{
PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, OMV.Vector3.Zero);
- BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
+ PhysicsScene.PE.SetAngularVelocity(PhysBody, OMV.Vector3.Zero);
// The next also get rid of applied linear force but the linear velocity is untouched.
- BulletSimAPI.ClearForces2(PhysBody.ptr);
+ PhysicsScene.PE.ClearForces(PhysBody);
}
});
}
@@ -339,7 +339,7 @@ public sealed class BSCharacter : BSPhysObject
public override OMV.Vector3 Position {
get {
// Don't refetch the position because this function is called a zillion times
- // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID);
+ // _position = PhysicsScene.PE.GetObjectPosition(Scene.World, LocalID);
return _position;
}
set {
@@ -433,8 +433,8 @@ public sealed class BSCharacter : BSPhysObject
}
public override void UpdatePhysicalMassProperties(float physMass, bool inWorld)
{
- OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
- BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia);
+ OMV.Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
+ PhysicsScene.PE.SetMassProps(PhysBody, physMass, localInertia);
}
public override OMV.Vector3 Force {
@@ -446,7 +446,7 @@ public sealed class BSCharacter : BSPhysObject
{
DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force);
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
+ PhysicsScene.PE.SetObjectForce(PhysBody, _force);
});
}
}
@@ -533,7 +533,7 @@ public sealed class BSCharacter : BSPhysObject
}
}
- BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
+ PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
PhysicsScene.PE.Activate(PhysBody, true);
}
}
@@ -676,7 +676,7 @@ public sealed class BSCharacter : BSPhysObject
// Buoyancy is faked by changing the gravity applied to the object
float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
+ PhysicsScene.PE.SetGravity(PhysBody, new OMV.Vector3(0f, 0f, grav));
}
}
@@ -737,7 +737,7 @@ public sealed class BSCharacter : BSPhysObject
// DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce);
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
+ PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce);
}
});
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index 5d70ef7..e4e3edc 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -564,17 +564,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// TODO: possibly set AngularFactor and LinearFactor for the type of vehicle.
// Maybe compute linear and angular factor and damping from params.
float angularDamping = BSParam.VehicleAngularDamping;
- BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
+ PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping);
// Vehicles report collision events so we know when it's on the ground
PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS);
- Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(Prim.PhysShape.ptr, m_vehicleMass);
- BulletSimAPI.SetMassProps2(Prim.PhysBody.ptr, m_vehicleMass, localInertia);
- BulletSimAPI.UpdateInertiaTensor2(Prim.PhysBody.ptr);
+ Vector3 localInertia = PhysicsScene.PE.CalculateLocalInertia(Prim.PhysShape, m_vehicleMass);
+ PhysicsScene.PE.SetMassProps(Prim.PhysBody, m_vehicleMass, localInertia);
+ PhysicsScene.PE.UpdateInertiaTensor(Prim.PhysBody);
Vector3 grav = PhysicsScene.DefaultGravity * (1f - Prim.Buoyancy);
- BulletSimAPI.SetGravity2(Prim.PhysBody.ptr, grav);
+ PhysicsScene.PE.SetGravity(Prim.PhysBody, grav);
VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4}",
Prim.LocalID, m_vehicleMass, friction, localInertia, angularDamping);
@@ -669,7 +669,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// If we set one of the values (ie, the physics engine didn't do it) we must force
// an UpdateProperties event to send the changes up to the simulator.
- BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr);
+ PhysicsScene.PE.PushUpdate(Prim.PhysBody);
}
m_knownChanged = 0;
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 143c60c..bd03d31 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -387,11 +387,6 @@ public sealed class BSLinksetCompound : BSLinkset
}
PhysicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape);
-
- // DEBUG: see of inter-linkset collisions are causing problems for constraint linksets.
- // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
- // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
-
}
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
index 629bc72..d0b2a56 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
@@ -259,7 +259,7 @@ public sealed class BSLinksetConstraints : BSLinkset
if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
{
// Make the child refresh its location
- BulletSimAPI.PushUpdate2(childPrim.PhysBody.ptr);
+ PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
ret = true;
}
@@ -286,9 +286,6 @@ public sealed class BSLinksetConstraints : BSLinkset
float linksetMass = LinksetMass;
LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true);
- // DEBUG: see of inter-linkset collisions are causing problems
- // BulletSimAPI.SetCollisionFilterMask2(LinksetRoot.BSBody.ptr,
- // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass);
@@ -307,11 +304,7 @@ public sealed class BSLinksetConstraints : BSLinkset
}
constrain.RecomputeConstraintVariables(linksetMass);
- // DEBUG: see of inter-linkset collisions are causing problems
- // BulletSimAPI.SetCollisionFilterMask2(child.BSBody.ptr,
- // (uint)CollisionFilterGroups.LinksetFilter, (uint)CollisionFilterGroups.LinksetMask);
-
- // BulletSimAPI.DumpConstraint2(PhysicsScene.World.ptr, constrain.Constraint.ptr); // DEBUG DEBUG
+ // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
index c6c2946..339722e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs
@@ -280,7 +280,7 @@ public static class BSParam
(s,cf,p,v) => { s.UnmanagedParams[0].gravity = cf.GetFloat(p, v); },
(s) => { return s.UnmanagedParams[0].gravity; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{s.UnmanagedParams[0].gravity=x;}, p, PhysParameterEntry.APPLY_TO_NONE, v); },
- (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ),
+ (s,o,v) => { s.PE.SetGravity(o.PhysBody, new Vector3(0f,0f,v)); } ),
new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
@@ -288,13 +288,13 @@ public static class BSParam
(s,cf,p,v) => { LinearDamping = cf.GetFloat(p, v); },
(s) => { return LinearDamping; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearDamping=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, v, AngularDamping); } ),
+ (s,o,v) => { s.PE.SetDamping(o.PhysBody, v, AngularDamping); } ),
new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
0f,
(s,cf,p,v) => { AngularDamping = cf.GetFloat(p, v); },
(s) => { return AngularDamping; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularDamping=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetDamping2(o.PhysBody.ptr, LinearDamping, v); } ),
+ (s,o,v) => { s.PE.SetDamping(o.PhysBody, LinearDamping, v); } ),
new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
0.2f,
(s,cf,p,v) => { DeactivationTime = cf.GetFloat(p, v); },
@@ -306,13 +306,13 @@ public static class BSParam
(s,cf,p,v) => { LinearSleepingThreshold = cf.GetFloat(p, v); },
(s) => { return LinearSleepingThreshold; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{LinearSleepingThreshold=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ),
+ (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
1.0f,
(s,cf,p,v) => { AngularSleepingThreshold = cf.GetFloat(p, v); },
(s) => { return AngularSleepingThreshold; },
(s,p,l,v) => { s.UpdateParameterObject((x)=>{AngularSleepingThreshold=x;}, p, l, v); },
- (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.PhysBody.ptr, v, v); } ),
+ (s,o,v) => { s.PE.SetSleepingThresholds(o.PhysBody, v, v); } ),
new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
0f, // set to zero to disable
(s,cf,p,v) => { CcdMotionThreshold = cf.GetFloat(p, v); },
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 613606f..064ce3c 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -253,7 +253,7 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
{
if (PhysBody.HasPhysicalBody)
- BulletSimAPI.ClearAllForces2(PhysBody.ptr);
+ PhysicsScene.PE.ClearAllForces(PhysBody);
});
}
public override void ZeroAngularMotion(bool inTaintTime)
@@ -266,7 +266,7 @@ public sealed class BSPrim : BSPhysObject
if (PhysBody.HasPhysicalBody)
{
PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity);
- BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity);
}
});
}
@@ -292,7 +292,7 @@ public sealed class BSPrim : BSPhysObject
*/
// don't do the GetObjectPosition for root elements because this function is called a zillion times.
- // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr);
+ // _position = PhysicsScene.PE.GetObjectPosition2(PhysicsScene.World, BSBody);
return _position;
}
set {
@@ -405,10 +405,10 @@ public sealed class BSPrim : BSPhysObject
{
if (IsStatic)
{
- BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity);
+ PhysicsScene.PE.SetGravity(PhysBody, PhysicsScene.DefaultGravity);
Inertia = OMV.Vector3.Zero;
- BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
- BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ PhysicsScene.PE.SetMassProps(PhysBody, 0f, Inertia);
+ PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
}
else
{
@@ -423,14 +423,14 @@ public sealed class BSPrim : BSPhysObject
}
// The computation of mass props requires gravity to be set on the object.
- BulletSimAPI.SetGravity2(PhysBody.ptr, grav);
+ PhysicsScene.PE.SetGravity(PhysBody, grav);
- Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
- BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
- BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
+ Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass);
+ PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia);
+ PhysicsScene.PE.UpdateInertiaTensor(PhysBody);
// center of mass is at the zero of the object
- // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
+ // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation);
DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld);
if (inWorld)
@@ -440,7 +440,7 @@ public sealed class BSPrim : BSPhysObject
// Must set gravity after it has been added to the world because, for unknown reasons,
// adding the object resets the object's gravity to world gravity
- BulletSimAPI.SetGravity2(PhysBody.ptr, grav);
+ PhysicsScene.PE.SetGravity(PhysBody, grav);
}
}
@@ -483,7 +483,7 @@ public sealed class BSPrim : BSPhysObject
DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force);
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, _force);
+ PhysicsScene.PE.ApplyCentralForce(PhysBody, _force);
ActivateIfPhysical(false);
}
}
@@ -583,7 +583,7 @@ public sealed class BSPrim : BSPhysObject
_velocity = value;
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
+ PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity);
ActivateIfPhysical(false);
}
}
@@ -809,7 +809,7 @@ public sealed class BSPrim : BSPhysObject
PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation);
// Center of mass is at the center of the object
- // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody, _position, _orientation);
+ // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation);
// A dynamic object has mass
UpdatePhysicalMassProperties(RawMass, false);
@@ -822,9 +822,9 @@ public sealed class BSPrim : BSPhysObject
}
// Various values for simulation limits
- BulletSimAPI.SetDamping2(PhysBody.ptr, BSParam.LinearDamping, BSParam.AngularDamping);
+ PhysicsScene.PE.SetDamping(PhysBody, BSParam.LinearDamping, BSParam.AngularDamping);
PhysicsScene.PE.SetDeactivationTime(PhysBody, BSParam.DeactivationTime);
- BulletSimAPI.SetSleepingThresholds2(PhysBody.ptr, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold);
+ PhysicsScene.PE.SetSleepingThresholds(PhysBody, BSParam.LinearSleepingThreshold, BSParam.AngularSleepingThreshold);
PhysicsScene.PE.SetContactProcessingThreshold(PhysBody, BSParam.ContactProcessingThreshold);
// This collides like an object.
@@ -901,10 +901,10 @@ public sealed class BSPrim : BSPhysObject
// TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
// Replace this when the new AddObjectToWorld function is complete.
- BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity());
+ PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
// Collision filter can be set only when the object is in the world
- if (!PhysBody.ApplyCollisionMask())
+ if (!PhysBody.ApplyCollisionMask(PhysicsScene))
{
m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
@@ -969,7 +969,7 @@ public sealed class BSPrim : BSPhysObject
_rotationalVelocity = value;
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
+ PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity);
ActivateIfPhysical(false);
}
}
@@ -1061,7 +1061,7 @@ public sealed class BSPrim : BSPhysObject
DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, addForce);
+ PhysicsScene.PE.ApplyCentralForce(PhysBody, addForce);
ActivateIfPhysical(false);
}
});
@@ -1085,7 +1085,7 @@ public sealed class BSPrim : BSPhysObject
{
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.ApplyTorque2(PhysBody.ptr, angForce);
+ PhysicsScene.PE.ApplyTorque(PhysBody, angForce);
ActivateIfPhysical(false);
}
});
@@ -1108,7 +1108,7 @@ public sealed class BSPrim : BSPhysObject
{
if (PhysBody.HasPhysicalBody)
{
- BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse);
+ PhysicsScene.PE.ApplyTorqueImpulse(PhysBody, applyImpulse);
ActivateIfPhysical(false);
}
});
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index bfc9df2..28c6680 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -51,7 +51,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
public string BulletSimVersion = "?";
// The handle to the underlying managed or unmanaged version of Bullet being used.
- public BulletSimAPITemplate PE;
+ public BSAPITemplate PE;
public Dictionary PhysObjects;
public BSShapeCollection Shapes;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index d59e455..cd77581 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -141,7 +141,7 @@ public sealed class BSShapeCollection : IDisposable
if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body);
PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate()
{
- if (!BulletSimAPI.IsInWorld2(body.ptr))
+ if (!PhysicsScene.PE.IsInWorld(body))
{
PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body);
if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
@@ -166,7 +166,7 @@ public sealed class BSShapeCollection : IDisposable
// If the caller needs to know the old body is going away, pass the event up.
if (bodyCallback != null) bodyCallback(body);
- if (BulletSimAPI.IsInWorld2(body.ptr))
+ if (PhysicsScene.PE.IsInWorld(body))
{
PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body);
if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
@@ -332,7 +332,7 @@ public sealed class BSShapeCollection : IDisposable
// Called at taint-time.
private void DereferenceCompound(BulletShape shape, ShapeDestructionCallback shapeCallback)
{
- if (!BulletSimAPI.IsCompound2(shape.ptr))
+ if (!PhysicsScene.PE.IsCompound(shape))
{
// Failed the sanity check!!
PhysicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
@@ -376,7 +376,7 @@ public sealed class BSShapeCollection : IDisposable
}
else
{
- if (BulletSimAPI.IsCompound2(cShape))
+ if (PhysicsScene.PE.IsCompound(shapeInfo))
{
shapeInfo.type = BSPhysicsShapeType.SHAPE_COMPOUND;
}
@@ -467,7 +467,7 @@ public sealed class BSShapeCollection : IDisposable
// Get the scale of any existing shape so we can see if the new shape is same native type and same size.
OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
if (prim.PhysShape.HasPhysicalShape)
- scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr);
+ scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape);
if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}",
prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 423e700..c75eb9b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -151,12 +151,12 @@ public class BSShapeNative : BSShape
/*
if (shapeType == BSPhysicsShapeType.SHAPE_CAPSULE)
{
- ptr = BulletSimAPI.BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
+ ptr = PhysicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale);
physicsScene.DetailLog("{0},BSShapeCollection.BuiletPhysicalNativeShape,capsule,scale={1}", prim.LocalID, prim.Scale);
}
else
{
- ptr = BulletSimAPI.BuildNativeShape2(physicsScene.World.ptr, nativeShapeData);
+ ptr = PhysicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData);
}
if (ptr == IntPtr.Zero)
{
@@ -173,7 +173,7 @@ public class BSShapeNative : BSShape
/*
// Native shapes are not tracked and are released immediately
physicsScene.DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
- BulletSimAPI.DeleteCollisionShape2(physicsScene.World.ptr, ptr);
+ PhysicsScene.PE.DeleteCollisionShape(physicsScene.World, this);
ptr = IntPtr.Zero;
// Garbage collection will free up this instance.
*/
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index 01966c0..cc28344 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -120,7 +120,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody);
m_mapInfo.terrainBody.collisionType = CollisionType.Terrain;
- m_mapInfo.terrainBody.ApplyCollisionMask();
+ m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene);
// Make it so the terrain will not move or be considered for movement.
PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
index 590c687..2e9db39 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs
@@ -143,7 +143,7 @@ public sealed class BSTerrainManager : IDisposable
PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
// Everything collides with the ground plane.
m_groundPlane.collisionType = CollisionType.Groundplane;
- m_groundPlane.ApplyCollisionMask();
+ m_groundPlane.ApplyCollisionMask(PhysicsScene);
// Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
index 2f55fc3..1d55ce3 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs
@@ -120,7 +120,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
PhysicsScene.PE.SetCollisionFlags(m_terrainBody, CollisionFlags.CF_STATIC_OBJECT);
// Static objects are not very massive.
- BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero);
+ PhysicsScene.PE.SetMassProps(m_terrainBody, 0f, Vector3.Zero);
// Put the new terrain to the world of physical objects
PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_terrainBody);
@@ -129,7 +129,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys
PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_terrainBody);
m_terrainBody.collisionType = CollisionType.Terrain;
- m_terrainBody.ApplyCollisionMask();
+ m_terrainBody.ApplyCollisionMask(PhysicsScene);
// Make it so the terrain will not move or be considered for movement.
PhysicsScene.PE.ForceActivationState(m_terrainBody, ActivationState.DISABLE_SIMULATION);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
deleted file mode 100644
index b119f22..0000000
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ /dev/null
@@ -1,667 +0,0 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyrightD
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Text;
-using OpenMetaverse;
-
-namespace OpenSim.Region.Physics.BulletSPlugin {
-
- // Constraint type values as defined by Bullet
-public enum ConstraintType : int
-{
- POINT2POINT_CONSTRAINT_TYPE = 3,
- HINGE_CONSTRAINT_TYPE,
- CONETWIST_CONSTRAINT_TYPE,
- D6_CONSTRAINT_TYPE,
- SLIDER_CONSTRAINT_TYPE,
- CONTACT_CONSTRAINT_TYPE,
- D6_SPRING_CONSTRAINT_TYPE,
- MAX_CONSTRAINT_TYPE
-}
-
-// ===============================================================================
-[StructLayout(LayoutKind.Sequential)]
-public struct ConvexHull
-{
- Vector3 Offset;
- int VertexCount;
- Vector3[] Vertices;
-}
-public enum BSPhysicsShapeType
-{
- SHAPE_UNKNOWN = 0,
- SHAPE_CAPSULE = 1,
- SHAPE_BOX = 2,
- SHAPE_CONE = 3,
- SHAPE_CYLINDER = 4,
- SHAPE_SPHERE = 5,
- SHAPE_MESH = 6,
- SHAPE_HULL = 7,
- // following defined by BulletSim
- SHAPE_GROUNDPLANE = 20,
- SHAPE_TERRAIN = 21,
- SHAPE_COMPOUND = 22,
- SHAPE_HEIGHTMAP = 23,
- SHAPE_AVATAR = 24,
-};
-
-// The native shapes have predefined shape hash keys
-public enum FixedShapeKey : ulong
-{
- KEY_NONE = 0,
- KEY_BOX = 1,
- KEY_SPHERE = 2,
- KEY_CONE = 3,
- KEY_CYLINDER = 4,
- KEY_CAPSULE = 5,
- KEY_AVATAR = 6,
-}
-
-[StructLayout(LayoutKind.Sequential)]
-public struct ShapeData
-{
- public uint ID;
- public BSPhysicsShapeType Type;
- public Vector3 Position;
- public Quaternion Rotation;
- public Vector3 Velocity;
- public Vector3 Scale;
- public float Mass;
- public float Buoyancy;
- public System.UInt64 HullKey;
- public System.UInt64 MeshKey;
- public float Friction;
- public float Restitution;
- public float Collidable; // true of things bump into this
- public float Static; // true if a static object. Otherwise gravity, etc.
- public float Solid; // true if object cannot be passed through
- public Vector3 Size;
-
- // note that bools are passed as floats since bool size changes by language and architecture
- public const float numericTrue = 1f;
- public const float numericFalse = 0f;
-}
-[StructLayout(LayoutKind.Sequential)]
-public struct SweepHit
-{
- public uint ID;
- public float Fraction;
- public Vector3 Normal;
- public Vector3 Point;
-}
-[StructLayout(LayoutKind.Sequential)]
-public struct RaycastHit
-{
- public uint ID;
- public float Fraction;
- public Vector3 Normal;
-}
-[StructLayout(LayoutKind.Sequential)]
-public struct CollisionDesc
-{
- public uint aID;
- public uint bID;
- public Vector3 point;
- public Vector3 normal;
-}
-[StructLayout(LayoutKind.Sequential)]
-public struct EntityProperties
-{
- public uint ID;
- public Vector3 Position;
- public Quaternion Rotation;
- public Vector3 Velocity;
- public Vector3 Acceleration;
- public Vector3 RotationalVelocity;
-}
-
-// Format of this structure must match the definition in the C++ code
-// NOTE: adding the X causes compile breaks if used. These are unused symbols
-// that can be removed from both here and the unmanaged definition of this structure.
-[StructLayout(LayoutKind.Sequential)]
-public struct ConfigurationParameters
-{
- public float defaultFriction;
- public float defaultDensity;
- public float defaultRestitution;
- public float collisionMargin;
- public float gravity;
-
- public float XlinearDamping;
- public float XangularDamping;
- public float XdeactivationTime;
- public float XlinearSleepingThreshold;
- public float XangularSleepingThreshold;
- public float XccdMotionThreshold;
- public float XccdSweptSphereRadius;
- public float XcontactProcessingThreshold;
-
- public float XterrainImplementation;
- public float XterrainFriction;
- public float XterrainHitFraction;
- public float XterrainRestitution;
- public float XterrainCollisionMargin;
-
- public float XavatarFriction;
- public float XavatarStandingFriction;
- public float XavatarDensity;
- public float XavatarRestitution;
- public float XavatarCapsuleWidth;
- public float XavatarCapsuleDepth;
- public float XavatarCapsuleHeight;
- public float XavatarContactProcessingThreshold;
-
- public float XvehicleAngularDamping;
-
- public float maxPersistantManifoldPoolSize;
- public float maxCollisionAlgorithmPoolSize;
- public float shouldDisableContactPoolDynamicAllocation;
- public float shouldForceUpdateAllAabbs;
- public float shouldRandomizeSolverOrder;
- public float shouldSplitSimulationIslands;
- public float shouldEnableFrictionCaching;
- public float numberOfSolverIterations;
-
- public float XlinksetImplementation;
- public float XlinkConstraintUseFrameOffset;
- public float XlinkConstraintEnableTransMotor;
- public float XlinkConstraintTransMotorMaxVel;
- public float XlinkConstraintTransMotorMaxForce;
- public float XlinkConstraintERP;
- public float XlinkConstraintCFM;
- public float XlinkConstraintSolverIterations;
-
- public float physicsLoggingFrames;
-
- public const float numericTrue = 1f;
- public const float numericFalse = 0f;
-}
-
-
-// The states a bullet collision object can have
-public enum ActivationState : uint
-{
- ACTIVE_TAG = 1,
- ISLAND_SLEEPING,
- WANTS_DEACTIVATION,
- DISABLE_DEACTIVATION,
- DISABLE_SIMULATION,
-}
-
-public enum CollisionObjectTypes : int
-{
- CO_COLLISION_OBJECT = 1 << 0,
- CO_RIGID_BODY = 1 << 1,
- CO_GHOST_OBJECT = 1 << 2,
- CO_SOFT_BODY = 1 << 3,
- CO_HF_FLUID = 1 << 4,
- CO_USER_TYPE = 1 << 5,
-}
-
-// Values used by Bullet and BulletSim to control object properties.
-// Bullet's "CollisionFlags" has more to do with operations on the
-// object (if collisions happen, if gravity effects it, ...).
-public enum CollisionFlags : uint
-{
- CF_STATIC_OBJECT = 1 << 0,
- CF_KINEMATIC_OBJECT = 1 << 1,
- CF_NO_CONTACT_RESPONSE = 1 << 2,
- CF_CUSTOM_MATERIAL_CALLBACK = 1 << 3,
- CF_CHARACTER_OBJECT = 1 << 4,
- CF_DISABLE_VISUALIZE_OBJECT = 1 << 5,
- CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
- // Following used by BulletSim to control collisions and updates
- BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
- BS_FLOATS_ON_WATER = 1 << 11,
- BS_VEHICLE_COLLISIONS = 1 << 12,
- BS_NONE = 0,
- BS_ALL = 0xFFFFFFFF
-};
-
-// Values f collisions groups and masks
-public enum CollisionFilterGroups : uint
-{
- // Don't use the bit definitions!! Define the use in a
- // filter/mask definition below. This way collision interactions
- // are more easily found and debugged.
- BNoneGroup = 0,
- BDefaultGroup = 1 << 0, // 0001
- BStaticGroup = 1 << 1, // 0002
- BKinematicGroup = 1 << 2, // 0004
- BDebrisGroup = 1 << 3, // 0008
- BSensorTrigger = 1 << 4, // 0010
- BCharacterGroup = 1 << 5, // 0020
- BAllGroup = 0x000FFFFF,
- // Filter groups defined by BulletSim
- BGroundPlaneGroup = 1 << 10, // 0400
- BTerrainGroup = 1 << 11, // 0800
- BRaycastGroup = 1 << 12, // 1000
- BSolidGroup = 1 << 13, // 2000
- // BLinksetGroup = xx // a linkset proper is either static or dynamic
- BLinksetChildGroup = 1 << 14, // 4000
-};
-
-// CFM controls the 'hardness' of the constraint. 0=fixed, 0..1=violatable. Default=0
-// ERP controls amount of correction per tick. Usable range=0.1..0.8. Default=0.2.
-public enum ConstraintParams : int
-{
- BT_CONSTRAINT_ERP = 1, // this one is not used in Bullet as of 20120730
- BT_CONSTRAINT_STOP_ERP,
- BT_CONSTRAINT_CFM,
- BT_CONSTRAINT_STOP_CFM,
-};
-public enum ConstraintParamAxis : int
-{
- AXIS_LINEAR_X = 0,
- AXIS_LINEAR_Y,
- AXIS_LINEAR_Z,
- AXIS_ANGULAR_X,
- AXIS_ANGULAR_Y,
- AXIS_ANGULAR_Z,
- AXIS_LINEAR_ALL = 20, // these last three added by BulletSim so we don't have to do zillions of calls
- AXIS_ANGULAR_ALL,
- AXIS_ALL
-};
-
-public abstract class BulletSimAPITemplate
-{
- /*
-// Initialization and simulation
-public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray
- );
-
-public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
-
-public abstract void SetHeightMap(BulletWorld world, float[] heightmap);
-
-public abstract void Shutdown(BulletWorld sim);
-
-public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
-
-public abstract bool PushUpdate(BulletBody obj);
- */
-
-// =====================================================================================
-// Mesh, hull, shape and body creation helper routines
-public abstract BulletShape CreateMeshShape(BulletWorld world,
- int indicesCount, int[] indices,
- int verticesCount, float[] vertices );
-
-public abstract BulletShape CreateHullShape(BulletWorld world,
- int hullCount, float[] hulls);
-
-public abstract BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape);
-
-public abstract BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData);
-
-public abstract bool IsNativeShape(BulletShape shape);
-
-public abstract void SetShapeCollisionMargin(BulletShape shape, float margin);
-
-public abstract BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale);
-
-public abstract BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree);
-
-public abstract int GetNumberOfCompoundChildren(BulletShape cShape);
-
-public abstract void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot);
-
-public abstract BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
-
-public abstract BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx);
-
-public abstract void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape);
-
-public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
-
-public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id);
-
-public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
-
-public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
-
-public abstract int GetBodyType(BulletBody obj);
-
-public abstract BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-
-public abstract IntPtr AllocateBodyInfo(BulletBody obj);
-
-public abstract void ReleaseBodyInfo(IntPtr obj);
-
-public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
-
-// =====================================================================================
-// Terrain creation and helper routines
-public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin);
-
-public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin);
-
-public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
-
-public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-
-public abstract BulletShape CreateTerrainShape(IntPtr mapInfo);
-
-// =====================================================================================
-// Constraint creation and helper routines
-public abstract BulletConstraint Create6DofConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 frame1loc, Quaternion frame1rot,
- Vector3 frame2loc, Quaternion frame2rot,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract BulletConstraint Create6DofConstraintToPoint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 joinPoint,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract BulletConstraint CreateHingeConstraint(BulletWorld world, BulletBody obj1, BulletBody obj2,
- Vector3 pivotinA, Vector3 pivotinB,
- Vector3 axisInA, Vector3 axisInB,
- bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies);
-
-public abstract void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse);
-
-public abstract void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations);
-
-public abstract bool SetFrames(BulletConstraint constrain,
- Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot);
-
-public abstract bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public abstract bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi);
-
-public abstract bool UseFrameOffset(BulletConstraint constrain, float enable);
-
-public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce);
-
-public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
-
-public abstract bool CalculateTransforms(BulletConstraint constrain);
-
-public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-
-public abstract bool DestroyConstraint(BulletWorld world, BulletConstraint constrain);
-
-// =====================================================================================
-// btCollisionWorld entries
-public abstract void UpdateSingleAabb(BulletWorld world, BulletBody obj);
-
-public abstract void UpdateAabbs(BulletWorld world);
-
-public abstract bool GetForceUpdateAllAabbs(BulletWorld world);
-
-public abstract void SetForceUpdateAllAabbs(BulletWorld world, bool force);
-
-// =====================================================================================
-// btDynamicsWorld entries
-public abstract bool AddObjectToWorld(BulletWorld world, BulletBody obj);
-
-public abstract bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj);
-
-public abstract bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects);
-
-public abstract bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain);
-// =====================================================================================
-// btCollisionObject entries
-public abstract Vector3 GetAnisotripicFriction(BulletConstraint constrain);
-
-public abstract Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict);
-
-public abstract bool HasAnisotripicFriction(BulletConstraint constrain);
-
-public abstract void SetContactProcessingThreshold(BulletBody obj, float val);
-
-public abstract float GetContactProcessingThreshold(BulletBody obj);
-
-public abstract bool IsStaticObject(BulletBody obj);
-
-public abstract bool IsKinematicObject(BulletBody obj);
-
-public abstract bool IsStaticOrKinematicObject(BulletBody obj);
-
-public abstract bool HasContactResponse(BulletBody obj);
-
-public abstract void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape);
-
-public abstract BulletShape GetCollisionShape(BulletBody obj);
-
-public abstract int GetActivationState(BulletBody obj);
-
-public abstract void SetActivationState(BulletBody obj, int state);
-
-public abstract void SetDeactivationTime(BulletBody obj, float dtime);
-
-public abstract float GetDeactivationTime(BulletBody obj);
-
-public abstract void ForceActivationState(BulletBody obj, ActivationState state);
-
-public abstract void Activate(BulletBody obj, bool forceActivation);
-
-public abstract bool IsActive(BulletBody obj);
-
-public abstract void SetRestitution(BulletBody obj, float val);
-
-public abstract float GetRestitution(BulletBody obj);
-
-public abstract void SetFriction(BulletBody obj, float val);
-
-public abstract float GetFriction(BulletBody obj);
-
-public abstract Vector3 GetPosition(BulletBody obj);
-
-public abstract Quaternion GetOrientation(BulletBody obj);
-
-public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
-
-public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
-
-public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
-
-public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
-
-public abstract void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel);
-
-public abstract void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel);
-
-public abstract float GetHitFraction(BulletBody obj);
-
-public abstract void SetHitFraction(BulletBody obj, float val);
-
-public abstract CollisionFlags GetCollisionFlags(BulletBody obj);
-
-public abstract CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public abstract CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public abstract CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags);
-
-public abstract float GetCcdMotionThreshold(BulletBody obj);
-
-public abstract void SetCcdMotionThreshold(BulletBody obj, float val);
-
-public abstract float GetCcdSweptSphereRadius(BulletBody obj);
-
-public abstract void SetCcdSweptSphereRadius(BulletBody obj, float val);
-
-public abstract IntPtr GetUserPointer(BulletBody obj);
-
-public abstract void SetUserPointer(BulletBody obj, IntPtr val);
-
- /*
-// =====================================================================================
-// btRigidBody entries
-public abstract void ApplyGravity(BulletBody obj);
-
-public abstract void SetGravity(BulletBody obj, Vector3 val);
-
-public abstract Vector3 GetGravity(BulletBody obj);
-
-public abstract void SetDamping(BulletBody obj, float lin_damping, float ang_damping);
-
-public abstract void SetLinearDamping(BulletBody obj, float lin_damping);
-
-public abstract void SetAngularDamping(BulletBody obj, float ang_damping);
-
-public abstract float GetLinearDamping(BulletBody obj);
-
-public abstract float GetAngularDamping(BulletBody obj);
-
-public abstract float GetLinearSleepingThreshold(BulletBody obj);
-
-
-public abstract void ApplyDamping(BulletBody obj, float timeStep);
-
-public abstract void SetMassProps(BulletBody obj, float mass, Vector3 inertia);
-
-public abstract Vector3 GetLinearFactor(BulletBody obj);
-
-public abstract void SetLinearFactor(BulletBody obj, Vector3 factor);
-
-public abstract void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot);
-
-// Add a force to the object as if its mass is one.
-public abstract void ApplyCentralForce(BulletBody obj, Vector3 force);
-
-// Set the force being applied to the object as if its mass is one.
-public abstract void SetObjectForce(BulletBody obj, Vector3 force);
-
-public abstract Vector3 GetTotalForce(BulletBody obj);
-
-public abstract Vector3 GetTotalTorque(BulletBody obj);
-
-public abstract Vector3 GetInvInertiaDiagLocal(BulletBody obj);
-
-public abstract void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert);
-
-public abstract void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold);
-
-public abstract void ApplyTorque(BulletBody obj, Vector3 torque);
-
-// Apply force at the given point. Will add torque to the object.
-public abstract void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos);
-
-// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
-public abstract void ApplyCentralImpulse(BulletBody obj, Vector3 imp);
-
-// Apply impulse to the object's torque. Force is scaled by object's mass.
-public abstract void ApplyTorqueImpulse(BulletBody obj, Vector3 imp);
-
-// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
-public abstract void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos);
-
-public abstract void ClearForces(BulletBody obj);
-
-public abstract void ClearAllForces(BulletBody obj);
-
-public abstract void UpdateInertiaTensor(BulletBody obj);
-
-public abstract Vector3 GetLinearVelocity(BulletBody obj);
-
-public abstract Vector3 GetAngularVelocity(BulletBody obj);
-
-public abstract void SetLinearVelocity(BulletBody obj, Vector3 val);
-
-public abstract void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity);
-
-public abstract Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos);
-
-public abstract void Translate(BulletBody obj, Vector3 trans);
-
-public abstract void UpdateDeactivation(BulletBody obj, float timeStep);
-
-public abstract bool WantsSleeping(BulletBody obj);
-
-public abstract void SetAngularFactor(BulletBody obj, float factor);
-
-public abstract void SetAngularFactorV(BulletBody obj, Vector3 factor);
-
-public abstract Vector3 GetAngularFactor(BulletBody obj);
-
-public abstract bool IsInWorld(BulletBody obj);
-
-public abstract void AddConstraintRef(BulletBody obj, BulletConstraint constrain);
-
-public abstract void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain);
-
-public abstract BulletConstraint GetConstraintRef(BulletBody obj, int index);
-
-public abstract int GetNumConstraintRefs(BulletBody obj);
-
-public abstract bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask);
-
-// =====================================================================================
-// btCollisionShape entries
-
-public abstract float GetAngularMotionDisc(BulletShape shape);
-
-public abstract float GetContactBreakingThreshold(BulletShape shape, float defaultFactor);
-
-public abstract bool IsPolyhedral(BulletShape shape);
-
-public abstract bool IsConvex2d(BulletShape shape);
-
-public abstract bool IsConvex(BulletShape shape);
-
-public abstract bool IsNonMoving(BulletShape shape);
-
-public abstract bool IsConcave(BulletShape shape);
-
-public abstract bool IsCompound(BulletShape shape);
-
-public abstract bool IsSoftBody(BulletShape shape);
-
-public abstract bool IsInfinite(BulletShape shape);
-
-public abstract void SetLocalScaling(BulletShape shape, Vector3 scale);
-
-public abstract Vector3 GetLocalScaling(BulletShape shape);
-
-public abstract Vector3 CalculateLocalInertia(BulletShape shape, float mass);
-
-public abstract int GetShapeType(BulletShape shape);
-
-public abstract void SetMargin(BulletShape shape, float val);
-
-public abstract float GetMargin(BulletShape shape);
- */
-
-};
-}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index c10d75e..a040928 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -72,12 +72,12 @@ public class BulletBody
public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } }
// Apply the specificed collision mask into the physical world
- public bool ApplyCollisionMask()
+ public bool ApplyCollisionMask(BSScene physicsScene)
{
// Should assert the body has been added to the physical world.
// (The collision masks are stored in the collision proxy cache which only exists for
// a collision body that is in the world.)
- return BulletSimAPI.SetCollisionGroupMask2(ptr,
+ return physicsScene.PE.SetCollisionGroupMask(this,
BulletSimData.CollisionTypeMasks[collisionType].group,
BulletSimData.CollisionTypeMasks[collisionType].mask);
}
--
cgit v1.1
From 3d0fc708647ceb734385f90e2f22be9774e2171e Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 31 Dec 2012 16:22:45 -0800
Subject: BulletSim: complete movement of BulletSimAPI functions to
BSAPITemplate. Update BulletSim DLLs and SOs with simplier step function
interface.
---
OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs | 4 -
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 217 +++++++++++++++------
OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 78 ++++----
.../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 43 ++--
OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 4 +-
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 127 ++++++------
.../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 12 +-
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 8 +-
.../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 10 +-
.../Region/Physics/Manager/PhysicsPluginManager.cs | 2 +-
10 files changed, 311 insertions(+), 194 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
index 9c4ba30..aadb5b2 100644
--- a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
@@ -111,10 +111,6 @@ public sealed class BSPrim : BSPhysObject
_mass = CalculateMass();
- // No body or shape yet
- PhysBody = new BulletBody(LocalID);
- PhysShape = new BulletShape();
-
Linkset.Refresh(this);
DetailLog("{0},BSPrim.constructor,call", LocalID);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 6e68053..0355b94 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Generic;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
@@ -36,31 +37,102 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
public sealed class BSAPIUnman : BSAPITemplate
{
- /*
+
+// We pin the memory passed between the managed and unmanaged code.
+GCHandle m_paramsHandle;
+private GCHandle m_collisionArrayPinnedHandle;
+private GCHandle m_updateArrayPinnedHandle;
+
+// Handle to the callback used by the unmanaged code to call into the managed code.
+// Used for debug logging.
+// Need to store the handle in a persistant variable so it won't be freed.
+private BSAPICPP.DebugLogCallback m_DebugLogCallbackHandle;
+
+private BSScene PhysicsScene { get; set; }
+
+public override string BulletEngineName { get { return "BulletUnmanaged"; } }
+public override string BulletEngineVersion { get; protected set; }
+
+public BSAPIUnman(string paramName, BSScene physScene)
+{
+ PhysicsScene = physScene;
+ // Do something fancy with the paramName to get the right DLL implementation
+ // like "Bullet-2.80-OpenCL-Intel" loading the version for Intel based OpenCL implementation, etc.
+}
+
// Initialization and simulation
-public BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray
- );
+public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
+ int maxCollisions, ref CollisionDesc[] collisionArray,
+ int maxUpdates, ref EntityProperties[] updateArray
+ )
+{
+ // Pin down the memory that will be used to pass object collisions and updates back from unmanaged code
+ m_paramsHandle = GCHandle.Alloc(parms, GCHandleType.Pinned);
+ m_collisionArrayPinnedHandle = GCHandle.Alloc(collisionArray, GCHandleType.Pinned);
+ m_updateArrayPinnedHandle = GCHandle.Alloc(updateArray, GCHandleType.Pinned);
-public bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
+ // If Debug logging level, enable logging from the unmanaged code
+ m_DebugLogCallbackHandle = null;
+ if (BSScene.m_log.IsDebugEnabled || PhysicsScene.PhysicsLogging.Enabled)
+ {
+ BSScene.m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", BSScene.LogHeader);
+ if (PhysicsScene.PhysicsLogging.Enabled)
+ // The handle is saved in a variable to make sure it doesn't get freed after this call
+ m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLoggerPhysLog);
+ else
+ m_DebugLogCallbackHandle = new BSAPICPP.DebugLogCallback(BulletLogger);
+ }
-public void SetHeightMap(BulletWorld world, float[] heightmap);
+ // Get the version of the DLL
+ // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
+ // BulletEngineVersion = BulletSimAPI.GetVersion2();
+ BulletEngineVersion = "";
+
+ // Call the unmanaged code with the buffers and other information
+ return new BulletWorld(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
+ maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
+ maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
+ m_DebugLogCallbackHandle));
-public void Shutdown(BulletWorld sim);
+}
-public int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
+// Called directly from unmanaged code so don't do much
+private void BulletLogger(string msg)
+{
+ BSScene.m_log.Debug("[BULLETS UNMANAGED]:" + msg);
+}
+
+// Called directly from unmanaged code so don't do much
+private void BulletLoggerPhysLog(string msg)
+{
+ PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg);
+}
+
+ /*
+public void SetHeightMap(BulletWorld world, float[] heightmap);
*/
+public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount, out int collidersCount)
+{
+ return BSAPICPP.PhysicsStep2(world.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
+}
+
+public override void Shutdown(BulletWorld sim)
+{
+ BSAPICPP.Shutdown2(sim.ptr);
+}
+
public override bool PushUpdate(BulletBody obj)
{
return BSAPICPP.PushUpdate2(obj.ptr);
}
+public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
+{
+ return BSAPICPP.UpdateParameter2(world.ptr, localID, parm, value);
+}
+
// =====================================================================================
// Mesh, hull, shape and body creation helper routines
public override BulletShape CreateMeshShape(BulletWorld world,
@@ -893,11 +965,81 @@ public override float GetMargin(BulletShape shape)
return BSAPICPP.GetMargin2(shape.ptr);
}
+// =====================================================================================
+// Debugging
+public override void DumpRigidBody(BulletWorld sim, BulletBody collisionObject)
+{
+ BSAPICPP.DumpRigidBody2(sim.ptr, collisionObject.ptr);
+}
+
+public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape)
+{
+ BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr);
+}
+
+public override void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo)
+{
+ BSAPICPP.DumpMapInfo2(sim.ptr, mapInfo.ptr);
+}
+
+public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain)
+{
+ BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr);
+}
+
+public override void DumpActivationInfo(BulletWorld sim)
+{
+ BSAPICPP.DumpActivationInfo2(sim.ptr);
+}
+
+public override void DumpAllInfo(BulletWorld sim)
+{
+ BSAPICPP.DumpAllInfo2(sim.ptr);
+}
+
+public override void DumpPhysicsStatistics(BulletWorld sim)
+{
+ BSAPICPP.DumpPhysicsStatistics2(sim.ptr);
+}
+
+
+// =====================================================================================
+// =====================================================================================
+// =====================================================================================
+// =====================================================================================
+// =====================================================================================
+// The actual interface to the unmanaged code
static class BSAPICPP
{
+// ===============================================================================
+// Link back to the managed code for outputting log messages
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
+
+// ===============================================================================
+// Initialization and simulation
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
+ int maxCollisions, IntPtr collisionArray,
+ int maxUpdates, IntPtr updateArray,
+ DebugLogCallback logRoutine);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
+ out int updatedEntityCount, out int collidersCount);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern void Shutdown2(IntPtr sim);
+
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool PushUpdate2(IntPtr obj);
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
+
// =====================================================================================
// Mesh, hull, shape and body creation helper routines
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -1431,52 +1573,6 @@ public static extern void SetMargin2(IntPtr shape, float val);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern float GetMargin2(IntPtr shape);
-}
-}
-
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-// ===============================================================================
-static class BulletSimAPI {
-// ===============================================================================
-// Link back to the managed code for outputting log messages
-[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg);
-
-// ===============================================================================
-// Initialization and simulation
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray,
- DebugLogCallback logRoutine);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool UpdateParameter2(IntPtr world, uint localID, String parm, float value);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void Shutdown2(IntPtr sim);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
-
// =====================================================================================
// Debugging
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -1501,4 +1597,7 @@ public static extern void DumpAllInfo2(IntPtr sim);
public static extern void DumpPhysicsStatistics2(IntPtr sim);
}
+
+}
+
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index a56a817..8ed791e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyrightD
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace OpenSim.Region.Physics.BulletSPlugin
-{
- /*
-public sealed class BSAPIXNA : BulletSimAPITemplate
-{
-}
- */
-}
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyrightD
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenSim.Region.Physics.BulletSPlugin
+{
+ /*
+public sealed class BSAPIXNA : BSAPITemplate
+{
+}
+ */
+}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index fbf362d..64a886b 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -292,26 +292,27 @@ public enum ConstraintParamAxis : int
public abstract class BSAPITemplate
{
- /*
+// Returns the name of the underlying Bullet engine
+public abstract string BulletEngineName { get; }
+public abstract string BulletEngineVersion { get; protected set;}
+
// Initialization and simulation
-public abstract BulletWorld Initialize(Vector3 maxPosition, IntPtr parms,
- int maxCollisions, IntPtr collisionArray,
- int maxUpdates, IntPtr updateArray
+public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParameters parms,
+ int maxCollisions, ref CollisionDesc[] collisionArray,
+ int maxUpdates, ref EntityProperties[] updateArray
);
-public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
-
+ /*
public abstract void SetHeightMap(BulletWorld world, float[] heightmap);
-public abstract void Shutdown(BulletWorld sim);
-
+ */
public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
- out int updatedEntityCount,
- out IntPtr updatedEntitiesPtr,
- out int collidersCount,
- out IntPtr collidersPtr);
+ out int updatedEntityCount, out int collidersCount);
+
+public abstract bool UpdateParameter(BulletWorld world, uint localID, String parm, float value);
+
+public abstract void Shutdown(BulletWorld sim);
- */
public abstract bool PushUpdate(BulletBody obj);
// =====================================================================================
@@ -660,5 +661,21 @@ public abstract void SetMargin(BulletShape shape, float val);
public abstract float GetMargin(BulletShape shape);
+// =====================================================================================
+// Debugging
+public abstract void DumpRigidBody(BulletWorld sim, BulletBody collisionObject);
+
+public abstract void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape);
+
+public abstract void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo);
+
+public abstract void DumpConstraint(BulletWorld sim, BulletConstraint constrain);
+
+public abstract void DumpActivationInfo(BulletWorld sim);
+
+public abstract void DumpAllInfo(BulletWorld sim);
+
+public abstract void DumpPhysicsStatistics(BulletWorld sim);
+
};
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index e4e3edc..13c2539 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -823,7 +823,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
if (!IsActive) return;
if (PhysicsScene.VehiclePhysicalLoggingEnabled)
- BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr);
+ PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
ForgetKnownVehicleProperties();
@@ -840,7 +840,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
PushKnownChanged();
if (PhysicsScene.VehiclePhysicalLoggingEnabled)
- BulletSimAPI.DumpRigidBody2(PhysicsScene.World.ptr, Prim.PhysBody.ptr);
+ PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody);
VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}",
Prim.LocalID, VehiclePosition, Prim.Force, VehicleVelocity, VehicleRotationalVelocity);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 28c6680..258b72f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Generic;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@@ -42,8 +43,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
public sealed class BSScene : PhysicsScene, IPhysicsParameters
{
- private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
- private static readonly string LogHeader = "[BULLETS SCENE]";
+ internal static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ internal static readonly string LogHeader = "[BULLETS SCENE]";
// The name of the region we're working for.
public string RegionName { get; private set; }
@@ -51,6 +52,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
public string BulletSimVersion = "?";
// The handle to the underlying managed or unmanaged version of Bullet being used.
+ public string BulletEngineName { get; private set; }
public BSAPITemplate PE;
public Dictionary PhysObjects;
@@ -102,11 +104,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// Pinned memory used to pass step information between managed and unmanaged
internal int m_maxCollisionsPerFrame;
internal CollisionDesc[] m_collisionArray;
- internal GCHandle m_collisionArrayPinnedHandle;
internal int m_maxUpdatesPerFrame;
internal EntityProperties[] m_updateArray;
- internal GCHandle m_updateArrayPinnedHandle;
public const uint TERRAIN_ID = 0; // OpenSim senses terrain with a localID of zero
public const uint GROUNDPLANE_ID = 1;
@@ -152,12 +152,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// A pointer to an instance if this structure is passed to the C++ code
// Used to pass basic configuration values to the unmanaged code.
internal ConfigurationParameters[] UnmanagedParams;
- GCHandle m_paramsHandle;
-
- // Handle to the callback used by the unmanaged code to call into the managed code.
- // Used for debug logging.
- // Need to store the handle in a persistant variable so it won't be freed.
- private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
// Sometimes you just have to log everything.
public Logging.LogWriter PhysicsLogging;
@@ -194,15 +188,8 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// Set default values for physics parameters plus any overrides from the ini file
GetInitialParameterValues(config);
- // For the moment, only one version of the interface
- PE = new BSAPIUnman();
-
- // Allocate more pinned memory. Do this early to try and get all pinned memory close together.
- m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);
- m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
- m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
- m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
- m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);
+ // Get the connection to the physics engine (could be native or one of many DLLs)
+ PE = SelectUnderlyingBulletEngine(BulletEngineName);
// Enable very detailed logging.
// By creating an empty logger when not logging, the log message invocation code
@@ -217,22 +204,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
PhysicsLogging = new Logging.LogWriter();
}
- // If Debug logging level, enable logging from the unmanaged code
- m_DebugLogCallbackHandle = null;
- if (m_log.IsDebugEnabled || PhysicsLogging.Enabled)
- {
- m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader);
- if (PhysicsLogging.Enabled)
- // The handle is saved in a variable to make sure it doesn't get freed after this call
- m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog);
- else
- m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger);
- }
-
- // Get the version of the DLL
- // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
- // BulletSimVersion = BulletSimAPI.GetVersion();
- // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion);
+ // Allocate memory for returning of the updates and collisions from the physics engine
+ m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
+ m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];
// The bounding box for the simulated world. The origin is 0,0,0 unless we're
// a child in a mega-region.
@@ -240,11 +214,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// area. It tracks active objects no matter where they are.
Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);
- // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader);
- World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, m_paramsHandle.AddrOfPinnedObject(),
- m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
- m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
- m_DebugLogCallbackHandle));
+ World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray);
Constraints = new BSConstraintCollection(World);
@@ -274,6 +244,9 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
{
BSParam.SetParameterConfigurationValues(this, pConfig);
+ // There are two Bullet implementations to choose from
+ BulletEngineName = pConfig.GetString("BulletEngine", "BulletUnmanaged");
+
// Very detailed logging for physics debugging
// TODO: the boolean values can be moved to the normal parameter processing.
m_physicsLoggingEnabled = pConfig.GetBoolean("PhysicsLoggingEnabled", false);
@@ -315,16 +288,41 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
return ret;
}
- // Called directly from unmanaged code so don't do much
- private void BulletLogger(string msg)
+ // Select the connection to the actual Bullet implementation.
+ // The main engine selection is the engineName up to the first hypen.
+ // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name
+ // is passed to the engine to do its special selection, etc.
+ private BSAPITemplate SelectUnderlyingBulletEngine(string engineName)
{
- m_log.Debug("[BULLETS UNMANAGED]:" + msg);
- }
+ // For the moment, do a simple switch statement.
+ // Someday do fancyness with looking up the interfaces in the assembly.
+ BSAPITemplate ret = null;
- // Called directly from unmanaged code so don't do much
- private void BulletLoggerPhysLog(string msg)
- {
- DetailLog("[BULLETS UNMANAGED]:" + msg);
+ string selectionName = engineName.ToLower();
+ int hyphenIndex = engineName.IndexOf("-");
+ if (hyphenIndex > 0)
+ selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1);
+
+ switch (selectionName)
+ {
+ case "bulletunmanaged":
+ ret = new BSAPIUnman(engineName, this);
+ break;
+ case "bulletxna":
+ // ret = new BSAPIXNA(engineName, this);
+ break;
+ }
+
+ if (ret == null)
+ {
+ m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader);
+ }
+ else
+ {
+ m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion);
+ }
+
+ return ret;
}
public override void Dispose()
@@ -361,7 +359,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
}
// Anything left in the unmanaged code should be cleaned out
- BulletSimAPI.Shutdown2(World.ptr);
+ PE.Shutdown(World);
// Not logging any more
PhysicsLogging.Close();
@@ -474,9 +472,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
LastTimeStep = timeStep;
int updatedEntityCount = 0;
- IntPtr updatedEntitiesPtr;
int collidersCount = 0;
- IntPtr collidersPtr;
int beforeTime = 0;
int simTime = 0;
@@ -492,6 +488,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
TriggerPreStepEvent(timeStep);
// the prestep actions might have added taints
+ numTaints += _taintOperations.Count;
ProcessTaints();
InTaintTime = false; // Only used for debugging so locking is not necessary.
@@ -499,23 +496,25 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
// Only enable this in a limited test world with few objects.
if (m_physicsPhysicalDumpEnabled)
- BulletSimAPI.DumpAllInfo2(World.ptr);
+ PE.DumpAllInfo(World);
// step the physical world one interval
m_simulationStep++;
int numSubSteps = 0;
-
try
{
- if (PhysicsLogging.Enabled) beforeTime = Util.EnvironmentTickCount();
+ if (PhysicsLogging.Enabled)
+ beforeTime = Util.EnvironmentTickCount();
- numSubSteps = BulletSimAPI.PhysicsStep2(World.ptr, timeStep, m_maxSubSteps, m_fixedTimeStep,
- out updatedEntityCount, out updatedEntitiesPtr, out collidersCount, out collidersPtr);
+ numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount);
- if (PhysicsLogging.Enabled) simTime = Util.EnvironmentTickCountSubtract(beforeTime);
- DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}",
- DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps,
- updatedEntityCount, collidersCount, ObjectsWithCollisions.Count);
+ if (PhysicsLogging.Enabled)
+ {
+ simTime = Util.EnvironmentTickCountSubtract(beforeTime);
+ DetailLog("{0},Simulate,call, frame={1}, nTaints={2}, simTime={3}, substeps={4}, updates={5}, colliders={6}, objWColl={7}",
+ DetailLogZero, m_simulationStep, numTaints, simTime, numSubSteps,
+ updatedEntityCount, collidersCount, ObjectsWithCollisions.Count);
+ }
}
catch (Exception e)
{
@@ -527,8 +526,6 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
collidersCount = 0;
}
- // Don't have to use the pointers passed back since we know it is the same pinned memory we passed in.
-
// Get a value for 'now' so all the collision and update routines don't have to get their own.
SimulationNowTime = Util.EnvironmentTickCount();
@@ -570,7 +567,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// Objects that are done colliding are removed from the ObjectsWithCollisions list.
// Not done above because it is inside an iteration of ObjectWithCollisions.
// This complex collision processing is required to create an empty collision
- // event call after all collisions have happened on an object. This enables
+ // event call after all real collisions have happened on an object. This enables
// the simulator to generate the 'collision end' event.
if (ObjectsWithNoMoreCollisions.Count > 0)
{
@@ -599,11 +596,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
// The following causes the unmanaged code to output ALL the values found in ALL the objects in the world.
// Only enable this in a limited test world with few objects.
if (m_physicsPhysicalDumpEnabled)
- BulletSimAPI.DumpAllInfo2(World.ptr);
+ PE.DumpAllInfo(World);
// The physics engine returns the number of milliseconds it simulated this call.
// These are summed and normalized to one second and divided by 1000 to give the reported physics FPS.
- // Multiply by 55 to give a nominal frame rate of 55.
+ // Multiply by a fixed nominal frame rate to give a rate similar to the simulator (usually 55).
return (float)numSubSteps * m_fixedTimeStep * 1000f * NominalFrameRate;
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index cc28344..0802b3a 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -44,7 +44,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
{
static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]";
- BulletHeightMapInfo m_mapInfo = null;
+ BulletHMapInfo m_mapInfo = null;
// Constructor to build a default, flat heightmap terrain.
public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize)
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
{
initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
}
- m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero);
+ m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero);
m_mapInfo.minCoords = minTerrainCoords;
m_mapInfo.maxCoords = maxTerrainCoords;
m_mapInfo.terrainRegionBase = TerrainBase;
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
Vector3 minCoords, Vector3 maxCoords)
: base(physicsScene, regionBase, id)
{
- m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero);
+ m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero);
m_mapInfo.minCoords = minCoords;
m_mapInfo.maxCoords = maxCoords;
m_mapInfo.minZ = minCoords.Z;
@@ -91,12 +91,12 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
// Using the information in m_mapInfo, create the physical representation of the heightmap.
private void BuildHeightmapTerrain()
{
- m_mapInfo.Ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID,
+ m_mapInfo.ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID,
m_mapInfo.minCoords, m_mapInfo.maxCoords,
m_mapInfo.heightMap, BSParam.TerrainCollisionMargin);
// Create the terrain shape from the mapInfo
- m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.Ptr);
+ m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.ptr);
// The terrain object initial position is at the center of the object
Vector3 centerPos;
@@ -138,7 +138,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody);
// Frees both the body and the shape.
PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody);
- PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.Ptr);
+ PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.ptr);
}
}
m_mapInfo = null;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index a040928..c8f4602 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -187,11 +187,11 @@ public class BulletConstraint
// Made a class rather than a struct so there would be only one
// instance of this and C# will pass around pointers rather
// than making copies.
-public class BulletHeightMapInfo
+public class BulletHMapInfo
{
- public BulletHeightMapInfo(uint id, float[] hm, IntPtr xx) {
+ public BulletHMapInfo(uint id, float[] hm, IntPtr xx) {
ID = id;
- Ptr = xx;
+ ptr = xx;
heightMap = hm;
terrainRegionBase = OMV.Vector3.Zero;
minCoords = new OMV.Vector3(100f, 100f, 25f);
@@ -200,7 +200,7 @@ public class BulletHeightMapInfo
sizeX = sizeY = 256f;
}
public uint ID;
- public IntPtr Ptr;
+ public IntPtr ptr;
public float[] heightMap;
public OMV.Vector3 terrainRegionBase;
public OMV.Vector3 minCoords;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index 4cb8e6d..a8a4ff5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -61,7 +61,8 @@ Incorporate inter-relationship of angular corrections. For instance, angularDefl
BULLETSIM TODO LIST:
=================================================
-Avatar density is WAY off. Compare and calibrate with what's in SL.
+Implement an avatar mesh shape. The Bullet capsule is way too limited.
+ Consider just hand creating a vertex/index array in a new BSShapeAvatar.
Revisit CollisionMargin. Builders notice the 0.04 spacing between prims.
Duplicating a physical prim causes old prim to jump away
Dup a phys prim and the original become unselected and thus interacts w/ selected prim.
@@ -170,6 +171,9 @@ Avatar attachments have no mass? http://forums-archive.secondlife.com/54/f0/3179
INTERNAL IMPROVEMENT/CLEANUP
=================================================
+Create the physical wrapper classes (BulletBody, BulletShape) by methods on
+ BSAPITemplate and make their actual implementation Bullet engine specific.
+ For the short term, just call the existing functions in ShapeCollection.
Consider moving prim/character body and shape destruction in destroy()
to postTimeTime rather than protecting all the potential sets that
might have been queued up.
@@ -204,6 +208,8 @@ Should taints check for existance or activeness of target?
Possibly have and 'active' flag that is checked by the taint processor?
Parameters for physics logging should be moved from BSScene to BSParam (at least boolean ones)
Can some of the physical wrapper classes (BulletBody, BulletWorld, BulletShape) be 'sealed'?
+There are TOO MANY interfaces from BulletSim core to Bullet itself
+ Think of something to eliminate one or more of the layers
THREADING
=================================================
@@ -262,3 +268,5 @@ llApplyImpulse()
(Resolution: tested on SL and OS. AddForce scales the force for timestep)
llSetBuoyancy() (DONE)
(Resolution: Bullet resets object gravity when added to world. Moved set gravity)
+Avatar density is WAY off. Compare and calibrate with what's in SL. (DONE)
+ (Resolution: set default density to 3.5 (from 60) which is closer to SL)
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index 8587a2b..8ccfda5 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -30,7 +30,7 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Nini.Config;
-using log4net;
+using log4net;
using OpenSim.Framework;
namespace OpenSim.Region.Physics.Manager
--
cgit v1.1
From 9396ccc078516023d63b5a86b3262ff97a1e97fb Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 31 Dec 2012 16:54:39 -0800
Subject: BulletSim: eliminate the use of the unmanaged HeightMapInfo
structure. Remove all related calls from the unmanaged and BSAPITemplate
interfaces. Update DLLs and SOs to include the version without HeightMapInfo
structures.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 26 +++++++++-------------
.../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 18 ++-------------
.../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 14 +++++-------
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 4 +---
4 files changed, 20 insertions(+), 42 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 0355b94..cf37e56 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -108,10 +108,6 @@ private void BulletLoggerPhysLog(string msg)
PhysicsScene.DetailLog("[BULLETS UNMANAGED]:" + msg);
}
- /*
-public void SetHeightMap(BulletWorld world, float[] heightmap);
-
- */
public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
out int updatedEntityCount, out int collidersCount)
{
@@ -277,6 +273,7 @@ public override void DestroyObject(BulletWorld sim, BulletBody obj)
// =====================================================================================
// Terrain creation and helper routines
+ /*
public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
float[] heightMap, float collisionMargin)
{
@@ -293,15 +290,18 @@ public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo)
{
return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo);
}
+ */
public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
{
return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
}
-public override BulletShape CreateTerrainShape(IntPtr mapInfo)
+public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
+ float scaleFactor, float collisionMargin)
{
- return new BulletShape(BSAPICPP.CreateTerrainShape2(mapInfo), BSPhysicsShapeType.SHAPE_TERRAIN);
+ return new BulletShape(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
+ BSPhysicsShapeType.SHAPE_TERRAIN);
}
// =====================================================================================
@@ -977,11 +977,6 @@ public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionSh
BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr);
}
-public override void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo)
-{
- BSAPICPP.DumpMapInfo2(sim.ptr, mapInfo.ptr);
-}
-
public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain)
{
BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr);
@@ -1025,9 +1020,6 @@ public static extern IntPtr Initialize2(Vector3 maxPosition, IntPtr parms,
DebugLogCallback logRoutine);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void SetHeightMap2(IntPtr world, float[] heightmap);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern int PhysicsStep2(IntPtr world, float timeStep, int maxSubSteps, float fixedTimeStep,
out int updatedEntityCount, out int collidersCount);
@@ -1119,6 +1111,7 @@ public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
// =====================================================================================
// Terrain creation and helper routines
+ /*
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
[MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
@@ -1129,12 +1122,15 @@ public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
+ */
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateTerrainShape2(IntPtr mapInfo);
+public static extern IntPtr CreateTerrainShape2(uint id, Vector3 size, float minHeight, float maxHeight,
+ [MarshalAs(UnmanagedType.LPArray)] float[] heightMap,
+ float scaleFactor, float collisionMargin);
// =====================================================================================
// Constraint creation and helper routines
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index 64a886b..a618a21 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -302,10 +302,6 @@ public abstract BulletWorld Initialize(Vector3 maxPosition, ConfigurationParamet
int maxUpdates, ref EntityProperties[] updateArray
);
- /*
-public abstract void SetHeightMap(BulletWorld world, float[] heightmap);
-
- */
public abstract int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
out int updatedEntityCount, out int collidersCount);
@@ -369,18 +365,10 @@ public abstract void ReleaseBodyInfo(IntPtr obj);
public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
// =====================================================================================
-// Terrain creation and helper routines
-public abstract IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin);
-
-public abstract IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin);
-
-public abstract bool ReleaseHeightMapInfo(IntPtr heightMapInfo);
-
public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-public abstract BulletShape CreateTerrainShape(IntPtr mapInfo);
+public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
+ float scaleFactor, float collisionMargin);
// =====================================================================================
// Constraint creation and helper routines
@@ -667,8 +655,6 @@ public abstract void DumpRigidBody(BulletWorld sim, BulletBody collisionObject);
public abstract void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape);
-public abstract void DumpMapInfo(BulletWorld sim, BulletHMapInfo mapInfo);
-
public abstract void DumpConstraint(BulletWorld sim, BulletConstraint constrain);
public abstract void DumpActivationInfo(BulletWorld sim);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
index 0802b3a..114c0aa 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs
@@ -58,7 +58,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
{
initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION;
}
- m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero);
+ m_mapInfo = new BulletHMapInfo(id, initialMap);
m_mapInfo.minCoords = minTerrainCoords;
m_mapInfo.maxCoords = maxTerrainCoords;
m_mapInfo.terrainRegionBase = TerrainBase;
@@ -72,7 +72,7 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
Vector3 minCoords, Vector3 maxCoords)
: base(physicsScene, regionBase, id)
{
- m_mapInfo = new BulletHMapInfo(id, initialMap, IntPtr.Zero);
+ m_mapInfo = new BulletHMapInfo(id, initialMap);
m_mapInfo.minCoords = minCoords;
m_mapInfo.maxCoords = maxCoords;
m_mapInfo.minZ = minCoords.Z;
@@ -91,12 +91,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
// Using the information in m_mapInfo, create the physical representation of the heightmap.
private void BuildHeightmapTerrain()
{
- m_mapInfo.ptr = PhysicsScene.PE.CreateHeightMapInfo(PhysicsScene.World, m_mapInfo.ID,
- m_mapInfo.minCoords, m_mapInfo.maxCoords,
- m_mapInfo.heightMap, BSParam.TerrainCollisionMargin);
-
// Create the terrain shape from the mapInfo
- m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape(m_mapInfo.ptr);
+ m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID,
+ new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ,
+ m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin);
+
// The terrain object initial position is at the center of the object
Vector3 centerPos;
@@ -138,7 +137,6 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys
PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody);
// Frees both the body and the shape.
PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody);
- PhysicsScene.PE.ReleaseHeightMapInfo(m_mapInfo.ptr);
}
}
m_mapInfo = null;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index c8f4602..681d21e 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -189,9 +189,8 @@ public class BulletConstraint
// than making copies.
public class BulletHMapInfo
{
- public BulletHMapInfo(uint id, float[] hm, IntPtr xx) {
+ public BulletHMapInfo(uint id, float[] hm) {
ID = id;
- ptr = xx;
heightMap = hm;
terrainRegionBase = OMV.Vector3.Zero;
minCoords = new OMV.Vector3(100f, 100f, 25f);
@@ -200,7 +199,6 @@ public class BulletHMapInfo
sizeX = sizeY = 256f;
}
public uint ID;
- public IntPtr ptr;
public float[] heightMap;
public OMV.Vector3 terrainRegionBase;
public OMV.Vector3 minCoords;
--
cgit v1.1
From 6988b5ceaf6387198f0d23769adefdf572757c4a Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 31 Dec 2012 17:06:47 -0800
Subject: BulletSim: remove rigid body contruction functions from BSAPITemplate
that relied on prebuilt construction info structures.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 56 ----------------------
.../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 5 --
2 files changed, 61 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index cf37e56..a06f6d0 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -226,11 +226,6 @@ public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape
return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type);
}
-public override BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo)
-{
- return new BulletBody(id, BSAPICPP.CreateBodyFromShapeAndInfo2(sim.ptr, shape.ptr, id, constructionInfo));
-}
-
public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
{
return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr);
@@ -256,16 +251,6 @@ public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape sha
return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot));
}
-public override IntPtr AllocateBodyInfo(BulletBody obj)
-{
- return BSAPICPP.AllocateBodyInfo2(obj.ptr);
-}
-
-public override void ReleaseBodyInfo(IntPtr obj)
-{
- BSAPICPP.ReleaseBodyInfo2(obj);
-}
-
public override void DestroyObject(BulletWorld sim, BulletBody obj)
{
BSAPICPP.DestroyObject2(sim.ptr, obj.ptr);
@@ -273,25 +258,6 @@ public override void DestroyObject(BulletWorld sim, BulletBody obj)
// =====================================================================================
// Terrain creation and helper routines
- /*
-public override IntPtr CreateHeightMapInfo(BulletWorld sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin)
-{
- return BSAPICPP.CreateHeightMapInfo2(sim.ptr, id, minCoords, maxCoords, heightMap, collisionMargin);
-}
-
-public override IntPtr FillHeightMapInfo(BulletWorld sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- float[] heightMap, float collisionMargin)
-{
- return BSAPICPP.FillHeightMapInfo2(sim.ptr, mapInfo, id, minCoords, maxCoords, heightMap, collisionMargin);
-}
-
-public override bool ReleaseHeightMapInfo(IntPtr heightMapInfo)
-{
- return BSAPICPP.ReleaseHeightMapInfo2(heightMapInfo);
-}
- */
-
public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
{
return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
@@ -1083,9 +1049,6 @@ public static extern void RecalculateCompoundShapeLocalAabb2(IntPtr cShape);
public static extern IntPtr DuplicateCollisionShape2(IntPtr sim, IntPtr srcShape, uint id);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateBodyFromShapeAndInfo2(IntPtr sim, IntPtr shape, uint id, IntPtr constructionInfo);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool DeleteCollisionShape2(IntPtr world, IntPtr shape);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -1101,29 +1064,10 @@ public static extern IntPtr CreateBodyWithDefaultMotionState2(IntPtr shape, uint
public static extern IntPtr CreateGhostFromShape2(IntPtr sim, IntPtr shape, uint id, Vector3 pos, Quaternion rot);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr AllocateBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern void ReleaseBodyInfo2(IntPtr obj);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void DestroyObject2(IntPtr sim, IntPtr obj);
// =====================================================================================
// Terrain creation and helper routines
- /*
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr CreateHeightMapInfo2(IntPtr sim, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern IntPtr FillHeightMapInfo2(IntPtr sim, IntPtr mapInfo, uint id, Vector3 minCoords, Vector3 maxCoords,
- [MarshalAs(UnmanagedType.LPArray)] float[] heightMap, float collisionMargin);
-
-[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
-public static extern bool ReleaseHeightMapInfo2(IntPtr heightMapInfo);
- */
-
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr CreateGroundPlaneShape2(uint id, float height, float collisionMargin);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index a618a21..6e67c7a 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -346,7 +346,6 @@ public abstract void RecalculateCompoundShapeLocalAabb(BulletShape cShape);
public abstract BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id);
-public abstract BulletBody CreateBodyFromShapeAndInfo(BulletWorld sim, BulletShape shape, uint id, IntPtr constructionInfo);
public abstract bool DeleteCollisionShape(BulletWorld world, BulletShape shape);
@@ -358,10 +357,6 @@ public abstract BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, u
public abstract BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot);
-public abstract IntPtr AllocateBodyInfo(BulletBody obj);
-
-public abstract void ReleaseBodyInfo(IntPtr obj);
-
public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
// =====================================================================================
--
cgit v1.1
From db3b6e892133c096f2c4244a0902b4f9f1a87371 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Mon, 31 Dec 2012 19:56:32 -0800
Subject: BulletSim: remove unused unmanaged memory reference functions from
BSAPITemplate.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 2 ++
OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index a06f6d0..3975776 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -524,6 +524,7 @@ public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion
BSAPICPP.SetTranslation2(obj.ptr, position, rotation);
}
+ /*
public override IntPtr GetBroadphaseHandle(BulletBody obj)
{
return BSAPICPP.GetBroadphaseHandle2(obj.ptr);
@@ -533,6 +534,7 @@ public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
{
BSAPICPP.SetUserPointer2(obj.ptr, handle);
}
+ */
public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
{
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index 6e67c7a..699f055 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -475,9 +475,9 @@ public abstract Quaternion GetOrientation(BulletBody obj);
public abstract void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation);
-public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
+// public abstract IntPtr GetBroadphaseHandle(BulletBody obj);
-public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
+// public abstract void SetBroadphaseHandle(BulletBody obj, IntPtr handle);
public abstract void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel);
--
cgit v1.1
From bc9a7ba0d6c0f7ad90a270c93acbb9b5c5f08645 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 1 Jan 2013 23:57:20 +0000
Subject: minor: Assign names to the different SmartThreadPools for debugging
purposes.
A different approach to the patch in http://opensimulator.org/mantis/view.php?id=6462
that doesn't involve further forking of SmartThreadPool
---
OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 1 +
1 file changed, 1 insertion(+)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index f38d17d..79cec04 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1487,6 +1487,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
startInfo.StartSuspended = true;
m_ThreadPool = new SmartThreadPool(startInfo);
+ m_ThreadPool.Name = "XEngine";
}
//
--
cgit v1.1
From 04132d3af4c8f44639ea842091f86274513e2dfd Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Tue, 1 Jan 2013 09:30:49 -0800
Subject: BulletSim: subclass Bullet[World|Body|Shape|Constraint] for unmanaged
to have pointers and managed to have objects. Initial paste of XNA code.
Commented out.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 654 +++++++---
OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 1278 +++++++++++++++++++-
.../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 2 +-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 37 +-
.../Physics/BulletSPlugin/BSShapeCollection.cs | 27 +-
.../Region/Physics/BulletSPlugin/BulletSimData.cs | 86 +-
6 files changed, 1806 insertions(+), 278 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 3975776..2c0cb43 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -38,6 +38,91 @@ namespace OpenSim.Region.Physics.BulletSPlugin
public sealed class BSAPIUnman : BSAPITemplate
{
+private sealed class BulletWorldUnman : BulletWorld
+{
+ public IntPtr ptr;
+ public BulletWorldUnman(uint id, BSScene physScene, IntPtr xx)
+ : base(id, physScene)
+ {
+ ptr = xx;
+ }
+}
+
+private sealed class BulletBodyUnman : BulletBody
+{
+ public IntPtr ptr;
+ public BulletBodyUnman(uint id, IntPtr xx)
+ : base(id)
+ {
+ ptr = xx;
+ }
+ public override bool HasPhysicalBody
+ {
+ get { return ptr != IntPtr.Zero; }
+ }
+ public override void Clear()
+ {
+ ptr = IntPtr.Zero;
+ }
+ public override string AddrString
+ {
+ get { return ptr.ToString("X"); }
+ }
+}
+
+private sealed class BulletShapeUnman : BulletShape
+{
+ public IntPtr ptr;
+ public BulletShapeUnman(IntPtr xx, BSPhysicsShapeType typ)
+ : base()
+ {
+ ptr = xx;
+ type = typ;
+ }
+ public override bool HasPhysicalShape
+ {
+ get { return ptr != IntPtr.Zero; }
+ }
+ public override void Clear()
+ {
+ ptr = IntPtr.Zero;
+ }
+ public override BulletShape Clone()
+ {
+ return new BulletShapeUnman(ptr, type);
+ }
+ public override bool ReferenceSame(BulletShape other)
+ {
+ BulletShapeUnman otheru = other as BulletShapeUnman;
+ return (otheru != null) && (this.ptr == otheru.ptr);
+
+ }
+ public override string AddrString
+ {
+ get { return ptr.ToString("X"); }
+ }
+}
+private sealed class BulletConstraintUnman : BulletConstraint
+{
+ public BulletConstraintUnman(IntPtr xx) : base()
+ {
+ ptr = xx;
+ }
+ public IntPtr ptr;
+
+ public override void Clear()
+ {
+ ptr = IntPtr.Zero;
+ }
+ public override bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
+
+ // Used for log messages for a unique display of the memory/object allocated to this instance
+ public override string AddrString
+ {
+ get { return ptr.ToString("X"); }
+ }
+}
+
// We pin the memory passed between the managed and unmanaged code.
GCHandle m_paramsHandle;
private GCHandle m_collisionArrayPinnedHandle;
@@ -89,7 +174,7 @@ public override BulletWorld Initialize(Vector3 maxPosition, ConfigurationParamet
BulletEngineVersion = "";
// Call the unmanaged code with the buffers and other information
- return new BulletWorld(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
+ return new BulletWorldUnman(0, PhysicsScene, BSAPICPP.Initialize2(maxPosition, m_paramsHandle.AddrOfPinnedObject(),
maxCollisions, m_collisionArrayPinnedHandle.AddrOfPinnedObject(),
maxUpdates, m_updateArrayPinnedHandle.AddrOfPinnedObject(),
m_DebugLogCallbackHandle));
@@ -111,22 +196,26 @@ private void BulletLoggerPhysLog(string msg)
public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSteps, float fixedTimeStep,
out int updatedEntityCount, out int collidersCount)
{
- return BSAPICPP.PhysicsStep2(world.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return BSAPICPP.PhysicsStep2(worldu.ptr, timeStep, maxSubSteps, fixedTimeStep, out updatedEntityCount, out collidersCount);
}
-public override void Shutdown(BulletWorld sim)
+public override void Shutdown(BulletWorld world)
{
- BSAPICPP.Shutdown2(sim.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.Shutdown2(worldu.ptr);
}
public override bool PushUpdate(BulletBody obj)
{
- return BSAPICPP.PushUpdate2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.PushUpdate2(bodyu.ptr);
}
public override bool UpdateParameter(BulletWorld world, uint localID, String parm, float value)
{
- return BSAPICPP.UpdateParameter2(world.ptr, localID, parm, value);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return BSAPICPP.UpdateParameter2(worldu.ptr, localID, parm, value);
}
// =====================================================================================
@@ -135,138 +224,165 @@ public override BulletShape CreateMeshShape(BulletWorld world,
int indicesCount, int[] indices,
int verticesCount, float[] vertices)
{
- return new BulletShape(
- BSAPICPP.CreateMeshShape2(world.ptr, indicesCount, indices, verticesCount, vertices),
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return new BulletShapeUnman(
+ BSAPICPP.CreateMeshShape2(worldu.ptr, indicesCount, indices, verticesCount, vertices),
BSPhysicsShapeType.SHAPE_MESH);
}
public override BulletShape CreateHullShape(BulletWorld world, int hullCount, float[] hulls)
{
- return new BulletShape(
- BSAPICPP.CreateHullShape2(world.ptr, hullCount, hulls),
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return new BulletShapeUnman(
+ BSAPICPP.CreateHullShape2(worldu.ptr, hullCount, hulls),
BSPhysicsShapeType.SHAPE_HULL);
}
public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape)
{
- return new BulletShape(
- BSAPICPP.BuildHullShapeFromMesh2(world.ptr, meshShape.ptr),
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman shapeu = meshShape as BulletShapeUnman;
+ return new BulletShapeUnman(
+ BSAPICPP.BuildHullShapeFromMesh2(worldu.ptr, shapeu.ptr),
BSPhysicsShapeType.SHAPE_HULL);
}
-public override BulletShape BuildNativeShape( BulletWorld world, ShapeData shapeData)
+public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData)
{
- return new BulletShape(
- BSAPICPP.BuildNativeShape2(world.ptr, shapeData),
- shapeData.Type);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type);
}
public override bool IsNativeShape(BulletShape shape)
{
- if (shape.HasPhysicalShape)
- return BSAPICPP.IsNativeShape2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ if (shapeu != null && shapeu.HasPhysicalShape)
+ return BSAPICPP.IsNativeShape2(shapeu.ptr);
return false;
}
public override void SetShapeCollisionMargin(BulletShape shape, float margin)
{
- if (shape.HasPhysicalShape)
- BSAPICPP.SetShapeCollisionMargin2(shape.ptr, margin);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ if (shapeu != null && shapeu.HasPhysicalShape)
+ BSAPICPP.SetShapeCollisionMargin2(shapeu.ptr, margin);
}
public override BulletShape BuildCapsuleShape(BulletWorld world, float radius, float height, Vector3 scale)
{
- return new BulletShape(
- BSAPICPP.BuildCapsuleShape2(world.ptr, radius, height, scale),
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return new BulletShapeUnman(
+ BSAPICPP.BuildCapsuleShape2(worldu.ptr, radius, height, scale),
BSPhysicsShapeType.SHAPE_CAPSULE);
}
-public override BulletShape CreateCompoundShape(BulletWorld sim, bool enableDynamicAabbTree)
+public override BulletShape CreateCompoundShape(BulletWorld world, bool enableDynamicAabbTree)
{
- return new BulletShape(
- BSAPICPP.CreateCompoundShape2(sim.ptr, enableDynamicAabbTree),
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return new BulletShapeUnman(
+ BSAPICPP.CreateCompoundShape2(worldu.ptr, enableDynamicAabbTree),
BSPhysicsShapeType.SHAPE_COMPOUND);
}
public override int GetNumberOfCompoundChildren(BulletShape shape)
{
- if (shape.HasPhysicalShape)
- return BSAPICPP.GetNumberOfCompoundChildren2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ if (shapeu != null && shapeu.HasPhysicalShape)
+ return BSAPICPP.GetNumberOfCompoundChildren2(shapeu.ptr);
return 0;
}
-public override void AddChildShapeToCompoundShape(BulletShape cShape, BulletShape addShape, Vector3 pos, Quaternion rot)
+public override void AddChildShapeToCompoundShape(BulletShape shape, BulletShape addShape, Vector3 pos, Quaternion rot)
{
- BSAPICPP.AddChildShapeToCompoundShape2(cShape.ptr, addShape.ptr, pos, rot);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ BulletShapeUnman addShapeu = addShape as BulletShapeUnman;
+ BSAPICPP.AddChildShapeToCompoundShape2(shapeu.ptr, addShapeu.ptr, pos, rot);
}
-public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+public override BulletShape GetChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
{
- return new BulletShape(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return new BulletShapeUnman(BSAPICPP.GetChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
}
-public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape cShape, int indx)
+public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape shape, int indx)
{
- return new BulletShape(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(cShape.ptr, indx));
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return new BulletShapeUnman(BSAPICPP.RemoveChildShapeFromCompoundShapeIndex2(shapeu.ptr, indx), BSPhysicsShapeType.SHAPE_UNKNOWN);
}
-public override void RemoveChildShapeFromCompoundShape(BulletShape cShape, BulletShape removeShape)
+public override void RemoveChildShapeFromCompoundShape(BulletShape shape, BulletShape removeShape)
{
- BSAPICPP.RemoveChildShapeFromCompoundShape2(cShape.ptr, removeShape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ BulletShapeUnman removeShapeu = removeShape as BulletShapeUnman;
+ BSAPICPP.RemoveChildShapeFromCompoundShape2(shapeu.ptr, removeShapeu.ptr);
}
-public override void RecalculateCompoundShapeLocalAabb(BulletShape cShape)
+public override void RecalculateCompoundShapeLocalAabb(BulletShape shape)
{
- BSAPICPP.RecalculateCompoundShapeLocalAabb2(cShape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ BSAPICPP.RecalculateCompoundShapeLocalAabb2(shapeu.ptr);
}
-public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id)
+public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletShape srcShape, uint id)
{
- return new BulletShape(BSAPICPP.DuplicateCollisionShape2(sim.ptr, srcShape.ptr, id), srcShape.type);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman srcShapeu = srcShape as BulletShapeUnman;
+ return new BulletShapeUnman(BSAPICPP.DuplicateCollisionShape2(worldu.ptr, srcShapeu.ptr, id), srcShape.type);
}
public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
{
- return BSAPICPP.DeleteCollisionShape2(world.ptr, shape.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
}
public override int GetBodyType(BulletBody obj)
{
- return BSAPICPP.GetBodyType2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetBodyType2(bodyu.ptr);
}
-public override BulletBody CreateBodyFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
{
- return new BulletBody(id, BSAPICPP.CreateBodyFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return new BulletBodyUnman(id, BSAPICPP.CreateBodyFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
}
public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, uint id, Vector3 pos, Quaternion rot)
{
- return new BulletBody(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shape.ptr, id, pos, rot));
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return new BulletBodyUnman(id, BSAPICPP.CreateBodyWithDefaultMotionState2(shapeu.ptr, id, pos, rot));
}
-public override BulletBody CreateGhostFromShape(BulletWorld sim, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
+public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
{
- return new BulletBody(id, BSAPICPP.CreateGhostFromShape2(sim.ptr, shape.ptr, id, pos, rot));
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
}
-public override void DestroyObject(BulletWorld sim, BulletBody obj)
+public override void DestroyObject(BulletWorld world, BulletBody obj)
{
- BSAPICPP.DestroyObject2(sim.ptr, obj.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.DestroyObject2(worldu.ptr, bodyu.ptr);
}
// =====================================================================================
// Terrain creation and helper routines
public override BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin)
{
- return new BulletShape(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
+ return new BulletShapeUnman(BSAPICPP.CreateGroundPlaneShape2(id, height, collisionMargin), BSPhysicsShapeType.SHAPE_GROUNDPLANE);
}
public override BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
float scaleFactor, float collisionMargin)
{
- return new BulletShape(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
+ return new BulletShapeUnman(BSAPICPP.CreateTerrainShape2(id, size, minHeight, maxHeight, heightMap, scaleFactor, collisionMargin),
BSPhysicsShapeType.SHAPE_TERRAIN);
}
@@ -277,7 +393,10 @@ public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletB
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- return new BulletConstraint(BSAPICPP.Create6DofConstraint2(world.ptr, obj1.ptr, obj2.ptr, frame1loc, frame1rot,
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
+ BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
+ return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
frame2loc, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
@@ -285,7 +404,10 @@ public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- return new BulletConstraint(BSAPICPP.Create6DofConstraintToPoint2(world.ptr, obj1.ptr, obj2.ptr,
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
+ BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
+ return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
joinPoint, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
@@ -294,560 +416,687 @@ public override BulletConstraint CreateHingeConstraint(BulletWorld world, Bullet
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- return new BulletConstraint(BSAPICPP.CreateHingeConstraint2(world.ptr, obj1.ptr, obj2.ptr,
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
+ BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
+ return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
pivotinA, pivotinB, axisInA, axisInB, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
}
public override void SetConstraintEnable(BulletConstraint constrain, float numericTrueFalse)
{
- BSAPICPP.SetConstraintEnable2(constrain.ptr, numericTrueFalse);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ BSAPICPP.SetConstraintEnable2(constrainu.ptr, numericTrueFalse);
}
public override void SetConstraintNumSolverIterations(BulletConstraint constrain, float iterations)
{
- BSAPICPP.SetConstraintNumSolverIterations2(constrain.ptr, iterations);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ BSAPICPP.SetConstraintNumSolverIterations2(constrainu.ptr, iterations);
}
public override bool SetFrames(BulletConstraint constrain,
Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
{
- return BSAPICPP.SetFrames2(constrain.ptr, frameA, frameArot, frameB, frameBrot);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetFrames2(constrainu.ptr, frameA, frameArot, frameB, frameBrot);
}
public override bool SetLinearLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
{
- return BSAPICPP.SetLinearLimits2(constrain.ptr, low, hi);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetLinearLimits2(constrainu.ptr, low, hi);
}
public override bool SetAngularLimits(BulletConstraint constrain, Vector3 low, Vector3 hi)
{
- return BSAPICPP.SetAngularLimits2(constrain.ptr, low, hi);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetAngularLimits2(constrainu.ptr, low, hi);
}
public override bool UseFrameOffset(BulletConstraint constrain, float enable)
{
- return BSAPICPP.UseFrameOffset2(constrain.ptr, enable);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.UseFrameOffset2(constrainu.ptr, enable);
}
public override bool TranslationalLimitMotor(BulletConstraint constrain, float enable, float targetVel, float maxMotorForce)
{
- return BSAPICPP.TranslationalLimitMotor2(constrain.ptr, enable, targetVel, maxMotorForce);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.TranslationalLimitMotor2(constrainu.ptr, enable, targetVel, maxMotorForce);
}
public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold)
{
- return BSAPICPP.SetBreakingImpulseThreshold2(constrain.ptr, threshold);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
}
public override bool CalculateTransforms(BulletConstraint constrain)
{
- return BSAPICPP.CalculateTransforms2(constrain.ptr);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.CalculateTransforms2(constrainu.ptr);
}
public override bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis)
{
- return BSAPICPP.SetConstraintParam2(constrain.ptr, paramIndex, value, axis);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetConstraintParam2(constrainu.ptr, paramIndex, value, axis);
}
public override bool DestroyConstraint(BulletWorld world, BulletConstraint constrain)
{
- return BSAPICPP.DestroyConstraint2(world.ptr, constrain.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.DestroyConstraint2(worldu.ptr, constrainu.ptr);
}
// =====================================================================================
// btCollisionWorld entries
public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
-{
- BSAPICPP.UpdateSingleAabb2(world.ptr, obj.ptr);
+{
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr);
}
public override void UpdateAabbs(BulletWorld world)
{
- BSAPICPP.UpdateAabbs2(world.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.UpdateAabbs2(worldu.ptr);
}
public override bool GetForceUpdateAllAabbs(BulletWorld world)
{
- return BSAPICPP.GetForceUpdateAllAabbs2(world.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr);
}
public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
{
- BSAPICPP.SetForceUpdateAllAabbs2(world.ptr, force);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force);
}
// =====================================================================================
// btDynamicsWorld entries
public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
{
- return BSAPICPP.AddObjectToWorld2(world.ptr, obj.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
}
public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
{
- return BSAPICPP.RemoveObjectFromWorld2(world.ptr, obj.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr);
}
public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
{
- return BSAPICPP.AddConstraintToWorld2(world.ptr, constrain.ptr, disableCollisionsBetweenLinkedObjects);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects);
}
public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
{
- return BSAPICPP.RemoveConstraintFromWorld2(world.ptr, constrain.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr);
}
// =====================================================================================
// btCollisionObject entries
public override Vector3 GetAnisotripicFriction(BulletConstraint constrain)
{
- return BSAPICPP.GetAnisotripicFriction2(constrain.ptr);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.GetAnisotripicFriction2(constrainu.ptr);
}
public override Vector3 SetAnisotripicFriction(BulletConstraint constrain, Vector3 frict)
{
- return BSAPICPP.SetAnisotripicFriction2(constrain.ptr, frict);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.SetAnisotripicFriction2(constrainu.ptr, frict);
}
public override bool HasAnisotripicFriction(BulletConstraint constrain)
{
- return BSAPICPP.HasAnisotripicFriction2(constrain.ptr);
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ return BSAPICPP.HasAnisotripicFriction2(constrainu.ptr);
}
public override void SetContactProcessingThreshold(BulletBody obj, float val)
{
- BSAPICPP.SetContactProcessingThreshold2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetContactProcessingThreshold2(bodyu.ptr, val);
}
public override float GetContactProcessingThreshold(BulletBody obj)
{
- return BSAPICPP.GetContactProcessingThreshold2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetContactProcessingThreshold2(bodyu.ptr);
}
public override bool IsStaticObject(BulletBody obj)
{
- return BSAPICPP.IsStaticObject2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.IsStaticObject2(bodyu.ptr);
}
public override bool IsKinematicObject(BulletBody obj)
{
- return BSAPICPP.IsKinematicObject2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.IsKinematicObject2(bodyu.ptr);
}
public override bool IsStaticOrKinematicObject(BulletBody obj)
{
- return BSAPICPP.IsStaticOrKinematicObject2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.IsStaticOrKinematicObject2(bodyu.ptr);
}
public override bool HasContactResponse(BulletBody obj)
{
- return BSAPICPP.HasContactResponse2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.HasContactResponse2(bodyu.ptr);
}
-public override void SetCollisionShape(BulletWorld sim, BulletBody obj, BulletShape shape)
+public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape)
{
- BSAPICPP.SetCollisionShape2(sim.ptr, obj.ptr, shape.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ if (worldu != null && bodyu != null)
+ {
+ // Special case to allow the caller to zero out the reference to any physical shape
+ if (shapeu != null)
+ BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
+ else
+ BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
+ }
}
public override BulletShape GetCollisionShape(BulletBody obj)
{
- return new BulletShape(BSAPICPP.GetCollisionShape2(obj.ptr));
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return new BulletShapeUnman(BSAPICPP.GetCollisionShape2(bodyu.ptr), BSPhysicsShapeType.SHAPE_UNKNOWN);
}
public override int GetActivationState(BulletBody obj)
{
- return BSAPICPP.GetActivationState2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetActivationState2(bodyu.ptr);
}
public override void SetActivationState(BulletBody obj, int state)
{
- BSAPICPP.SetActivationState2(obj.ptr, state);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetActivationState2(bodyu.ptr, state);
}
public override void SetDeactivationTime(BulletBody obj, float dtime)
{
- BSAPICPP.SetDeactivationTime2(obj.ptr, dtime);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetDeactivationTime2(bodyu.ptr, dtime);
}
public override float GetDeactivationTime(BulletBody obj)
{
- return BSAPICPP.GetDeactivationTime2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetDeactivationTime2(bodyu.ptr);
}
public override void ForceActivationState(BulletBody obj, ActivationState state)
{
- BSAPICPP.ForceActivationState2(obj.ptr, state);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ForceActivationState2(bodyu.ptr, state);
}
public override void Activate(BulletBody obj, bool forceActivation)
{
- BSAPICPP.Activate2(obj.ptr, forceActivation);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.Activate2(bodyu.ptr, forceActivation);
}
public override bool IsActive(BulletBody obj)
{
- return BSAPICPP.IsActive2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.IsActive2(bodyu.ptr);
}
public override void SetRestitution(BulletBody obj, float val)
{
- BSAPICPP.SetRestitution2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetRestitution2(bodyu.ptr, val);
}
public override float GetRestitution(BulletBody obj)
{
- return BSAPICPP.GetRestitution2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetRestitution2(bodyu.ptr);
}
public override void SetFriction(BulletBody obj, float val)
{
- BSAPICPP.SetFriction2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetFriction2(bodyu.ptr, val);
}
public override float GetFriction(BulletBody obj)
{
- return BSAPICPP.GetFriction2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetFriction2(bodyu.ptr);
}
public override Vector3 GetPosition(BulletBody obj)
{
- return BSAPICPP.GetPosition2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetPosition2(bodyu.ptr);
}
public override Quaternion GetOrientation(BulletBody obj)
{
- return BSAPICPP.GetOrientation2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetOrientation2(bodyu.ptr);
}
public override void SetTranslation(BulletBody obj, Vector3 position, Quaternion rotation)
{
- BSAPICPP.SetTranslation2(obj.ptr, position, rotation);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetTranslation2(bodyu.ptr, position, rotation);
}
/*
public override IntPtr GetBroadphaseHandle(BulletBody obj)
{
- return BSAPICPP.GetBroadphaseHandle2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetBroadphaseHandle2(bodyu.ptr);
}
public override void SetBroadphaseHandle(BulletBody obj, IntPtr handle)
{
- BSAPICPP.SetUserPointer2(obj.ptr, handle);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetUserPointer2(bodyu.ptr, handle);
}
*/
public override void SetInterpolationLinearVelocity(BulletBody obj, Vector3 vel)
{
- BSAPICPP.SetInterpolationLinearVelocity2(obj.ptr, vel);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetInterpolationLinearVelocity2(bodyu.ptr, vel);
}
public override void SetInterpolationAngularVelocity(BulletBody obj, Vector3 vel)
{
- BSAPICPP.SetInterpolationAngularVelocity2(obj.ptr, vel);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetInterpolationAngularVelocity2(bodyu.ptr, vel);
}
public override void SetInterpolationVelocity(BulletBody obj, Vector3 linearVel, Vector3 angularVel)
{
- BSAPICPP.SetInterpolationVelocity2(obj.ptr, linearVel, angularVel);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetInterpolationVelocity2(bodyu.ptr, linearVel, angularVel);
}
public override float GetHitFraction(BulletBody obj)
{
- return BSAPICPP.GetHitFraction2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetHitFraction2(bodyu.ptr);
}
public override void SetHitFraction(BulletBody obj, float val)
{
- BSAPICPP.SetHitFraction2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetHitFraction2(bodyu.ptr, val);
}
public override CollisionFlags GetCollisionFlags(BulletBody obj)
{
- return BSAPICPP.GetCollisionFlags2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetCollisionFlags2(bodyu.ptr);
}
public override CollisionFlags SetCollisionFlags(BulletBody obj, CollisionFlags flags)
{
- return BSAPICPP.SetCollisionFlags2(obj.ptr, flags);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.SetCollisionFlags2(bodyu.ptr, flags);
}
public override CollisionFlags AddToCollisionFlags(BulletBody obj, CollisionFlags flags)
{
- return BSAPICPP.AddToCollisionFlags2(obj.ptr, flags);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.AddToCollisionFlags2(bodyu.ptr, flags);
}
public override CollisionFlags RemoveFromCollisionFlags(BulletBody obj, CollisionFlags flags)
{
- return BSAPICPP.RemoveFromCollisionFlags2(obj.ptr, flags);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.RemoveFromCollisionFlags2(bodyu.ptr, flags);
}
public override float GetCcdMotionThreshold(BulletBody obj)
{
- return BSAPICPP.GetCcdMotionThreshold2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetCcdMotionThreshold2(bodyu.ptr);
}
public override void SetCcdMotionThreshold(BulletBody obj, float val)
{
- BSAPICPP.SetCcdMotionThreshold2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetCcdMotionThreshold2(bodyu.ptr, val);
}
public override float GetCcdSweptSphereRadius(BulletBody obj)
{
- return BSAPICPP.GetCcdSweptSphereRadius2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetCcdSweptSphereRadius2(bodyu.ptr);
}
public override void SetCcdSweptSphereRadius(BulletBody obj, float val)
{
- BSAPICPP.SetCcdSweptSphereRadius2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetCcdSweptSphereRadius2(bodyu.ptr, val);
}
public override IntPtr GetUserPointer(BulletBody obj)
{
- return BSAPICPP.GetUserPointer2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetUserPointer2(bodyu.ptr);
}
public override void SetUserPointer(BulletBody obj, IntPtr val)
{
- BSAPICPP.SetUserPointer2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetUserPointer2(bodyu.ptr, val);
}
// =====================================================================================
// btRigidBody entries
public override void ApplyGravity(BulletBody obj)
{
- BSAPICPP.ApplyGravity2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyGravity2(bodyu.ptr);
}
public override void SetGravity(BulletBody obj, Vector3 val)
{
- BSAPICPP.SetGravity2(obj.ptr, val);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetGravity2(bodyu.ptr, val);
}
public override Vector3 GetGravity(BulletBody obj)
{
- return BSAPICPP.GetGravity2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetGravity2(bodyu.ptr);
}
public override void SetDamping(BulletBody obj, float lin_damping, float ang_damping)
{
- BSAPICPP.SetDamping2(obj.ptr, lin_damping, ang_damping);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetDamping2(bodyu.ptr, lin_damping, ang_damping);
}
public override void SetLinearDamping(BulletBody obj, float lin_damping)
{
- BSAPICPP.SetLinearDamping2(obj.ptr, lin_damping);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetLinearDamping2(bodyu.ptr, lin_damping);
}
public override void SetAngularDamping(BulletBody obj, float ang_damping)
{
- BSAPICPP.SetAngularDamping2(obj.ptr, ang_damping);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetAngularDamping2(bodyu.ptr, ang_damping);
}
public override float GetLinearDamping(BulletBody obj)
{
- return BSAPICPP.GetLinearDamping2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetLinearDamping2(bodyu.ptr);
}
public override float GetAngularDamping(BulletBody obj)
{
- return BSAPICPP.GetAngularDamping2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetAngularDamping2(bodyu.ptr);
}
public override float GetLinearSleepingThreshold(BulletBody obj)
{
- return BSAPICPP.GetLinearSleepingThreshold2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetLinearSleepingThreshold2(bodyu.ptr);
}
public override void ApplyDamping(BulletBody obj, float timeStep)
{
- BSAPICPP.ApplyDamping2(obj.ptr, timeStep);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyDamping2(bodyu.ptr, timeStep);
}
public override void SetMassProps(BulletBody obj, float mass, Vector3 inertia)
{
- BSAPICPP.SetMassProps2(obj.ptr, mass, inertia);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetMassProps2(bodyu.ptr, mass, inertia);
}
public override Vector3 GetLinearFactor(BulletBody obj)
{
- return BSAPICPP.GetLinearFactor2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetLinearFactor2(bodyu.ptr);
}
public override void SetLinearFactor(BulletBody obj, Vector3 factor)
{
- BSAPICPP.SetLinearFactor2(obj.ptr, factor);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetLinearFactor2(bodyu.ptr, factor);
}
public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot)
{
- BSAPICPP.SetCenterOfMassByPosRot2(obj.ptr, pos, rot);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetCenterOfMassByPosRot2(bodyu.ptr, pos, rot);
}
// Add a force to the object as if its mass is one.
public override void ApplyCentralForce(BulletBody obj, Vector3 force)
{
- BSAPICPP.ApplyCentralForce2(obj.ptr, force);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyCentralForce2(bodyu.ptr, force);
}
// Set the force being applied to the object as if its mass is one.
public override void SetObjectForce(BulletBody obj, Vector3 force)
{
- BSAPICPP.SetObjectForce2(obj.ptr, force);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetObjectForce2(bodyu.ptr, force);
}
public override Vector3 GetTotalForce(BulletBody obj)
{
- return BSAPICPP.GetTotalForce2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetTotalForce2(bodyu.ptr);
}
public override Vector3 GetTotalTorque(BulletBody obj)
{
- return BSAPICPP.GetTotalTorque2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetTotalTorque2(bodyu.ptr);
}
public override Vector3 GetInvInertiaDiagLocal(BulletBody obj)
{
- return BSAPICPP.GetInvInertiaDiagLocal2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetInvInertiaDiagLocal2(bodyu.ptr);
}
public override void SetInvInertiaDiagLocal(BulletBody obj, Vector3 inert)
{
- BSAPICPP.SetInvInertiaDiagLocal2(obj.ptr, inert);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetInvInertiaDiagLocal2(bodyu.ptr, inert);
}
public override void SetSleepingThresholds(BulletBody obj, float lin_threshold, float ang_threshold)
{
- BSAPICPP.SetSleepingThresholds2(obj.ptr, lin_threshold, ang_threshold);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetSleepingThresholds2(bodyu.ptr, lin_threshold, ang_threshold);
}
public override void ApplyTorque(BulletBody obj, Vector3 torque)
{
- BSAPICPP.ApplyTorque2(obj.ptr, torque);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyTorque2(bodyu.ptr, torque);
}
// Apply force at the given point. Will add torque to the object.
public override void ApplyForce(BulletBody obj, Vector3 force, Vector3 pos)
{
- BSAPICPP.ApplyForce2(obj.ptr, force, pos);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyForce2(bodyu.ptr, force, pos);
}
// Apply impulse to the object. Same as "ApplycentralForce" but force scaled by object's mass.
public override void ApplyCentralImpulse(BulletBody obj, Vector3 imp)
{
- BSAPICPP.ApplyCentralImpulse2(obj.ptr, imp);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyCentralImpulse2(bodyu.ptr, imp);
}
// Apply impulse to the object's torque. Force is scaled by object's mass.
public override void ApplyTorqueImpulse(BulletBody obj, Vector3 imp)
{
- BSAPICPP.ApplyTorqueImpulse2(obj.ptr, imp);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyTorqueImpulse2(bodyu.ptr, imp);
}
// Apply impulse at the point given. For is scaled by object's mass and effects both linear and angular forces.
public override void ApplyImpulse(BulletBody obj, Vector3 imp, Vector3 pos)
{
- BSAPICPP.ApplyImpulse2(obj.ptr, imp, pos);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ApplyImpulse2(bodyu.ptr, imp, pos);
}
public override void ClearForces(BulletBody obj)
{
- BSAPICPP.ClearForces2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ClearForces2(bodyu.ptr);
}
public override void ClearAllForces(BulletBody obj)
{
- BSAPICPP.ClearAllForces2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.ClearAllForces2(bodyu.ptr);
}
public override void UpdateInertiaTensor(BulletBody obj)
{
- BSAPICPP.UpdateInertiaTensor2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.UpdateInertiaTensor2(bodyu.ptr);
}
public override Vector3 GetLinearVelocity(BulletBody obj)
{
- return BSAPICPP.GetLinearVelocity2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetLinearVelocity2(bodyu.ptr);
}
public override Vector3 GetAngularVelocity(BulletBody obj)
{
- return BSAPICPP.GetAngularVelocity2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetAngularVelocity2(bodyu.ptr);
}
public override void SetLinearVelocity(BulletBody obj, Vector3 vel)
{
- BSAPICPP.SetLinearVelocity2(obj.ptr, vel);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetLinearVelocity2(bodyu.ptr, vel);
}
public override void SetAngularVelocity(BulletBody obj, Vector3 angularVelocity)
{
- BSAPICPP.SetAngularVelocity2(obj.ptr, angularVelocity);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetAngularVelocity2(bodyu.ptr, angularVelocity);
}
public override Vector3 GetVelocityInLocalPoint(BulletBody obj, Vector3 pos)
{
- return BSAPICPP.GetVelocityInLocalPoint2(obj.ptr, pos);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetVelocityInLocalPoint2(bodyu.ptr, pos);
}
public override void Translate(BulletBody obj, Vector3 trans)
{
- BSAPICPP.Translate2(obj.ptr, trans);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.Translate2(bodyu.ptr, trans);
}
public override void UpdateDeactivation(BulletBody obj, float timeStep)
{
- BSAPICPP.UpdateDeactivation2(obj.ptr, timeStep);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.UpdateDeactivation2(bodyu.ptr, timeStep);
}
public override bool WantsSleeping(BulletBody obj)
{
- return BSAPICPP.WantsSleeping2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.WantsSleeping2(bodyu.ptr);
}
public override void SetAngularFactor(BulletBody obj, float factor)
{
- BSAPICPP.SetAngularFactor2(obj.ptr, factor);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetAngularFactor2(bodyu.ptr, factor);
}
public override void SetAngularFactorV(BulletBody obj, Vector3 factor)
{
- BSAPICPP.SetAngularFactorV2(obj.ptr, factor);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BSAPICPP.SetAngularFactorV2(bodyu.ptr, factor);
}
public override Vector3 GetAngularFactor(BulletBody obj)
{
- return BSAPICPP.GetAngularFactor2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetAngularFactor2(bodyu.ptr);
}
public override bool IsInWorld(BulletBody obj)
{
- return BSAPICPP.IsInWorld2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.IsInWorld2(bodyu.ptr);
}
public override void AddConstraintRef(BulletBody obj, BulletConstraint constrain)
{
- BSAPICPP.AddConstraintRef2(obj.ptr, constrain.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ BSAPICPP.AddConstraintRef2(bodyu.ptr, constrainu.ptr);
}
public override void RemoveConstraintRef(BulletBody obj, BulletConstraint constrain)
{
- BSAPICPP.RemoveConstraintRef2(obj.ptr, constrain.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ BSAPICPP.RemoveConstraintRef2(bodyu.ptr, constrainu.ptr);
}
public override BulletConstraint GetConstraintRef(BulletBody obj, int index)
{
- return new BulletConstraint(BSAPICPP.GetConstraintRef2(obj.ptr, index));
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return new BulletConstraintUnman(BSAPICPP.GetConstraintRef2(bodyu.ptr, index));
}
public override int GetNumConstraintRefs(BulletBody obj)
{
- return BSAPICPP.GetNumConstraintRefs2(obj.ptr);
+ BulletBodyUnman bodyu = obj as BulletBodyUnman;
+ return BSAPICPP.GetNumConstraintRefs2(bodyu.ptr);
}
public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint mask)
{
- return BSAPICPP.SetCollisionGroupMask2(body.ptr, filter, mask);
+ BulletBodyUnman bodyu = body as BulletBodyUnman;
+ return BSAPICPP.SetCollisionGroupMask2(bodyu.ptr, filter, mask);
}
// =====================================================================================
@@ -855,114 +1104,139 @@ public override bool SetCollisionGroupMask(BulletBody body, uint filter, uint ma
public override float GetAngularMotionDisc(BulletShape shape)
{
- return BSAPICPP.GetAngularMotionDisc2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.GetAngularMotionDisc2(shapeu.ptr);
}
public override float GetContactBreakingThreshold(BulletShape shape, float defaultFactor)
{
- return BSAPICPP.GetContactBreakingThreshold2(shape.ptr, defaultFactor);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.GetContactBreakingThreshold2(shapeu.ptr, defaultFactor);
}
public override bool IsPolyhedral(BulletShape shape)
{
- return BSAPICPP.IsPolyhedral2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsPolyhedral2(shapeu.ptr);
}
public override bool IsConvex2d(BulletShape shape)
{
- return BSAPICPP.IsConvex2d2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsConvex2d2(shapeu.ptr);
}
public override bool IsConvex(BulletShape shape)
{
- return BSAPICPP.IsConvex2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsConvex2(shapeu.ptr);
}
public override bool IsNonMoving(BulletShape shape)
{
- return BSAPICPP.IsNonMoving2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsNonMoving2(shapeu.ptr);
}
public override bool IsConcave(BulletShape shape)
{
- return BSAPICPP.IsConcave2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsConcave2(shapeu.ptr);
}
public override bool IsCompound(BulletShape shape)
{
- return BSAPICPP.IsCompound2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsCompound2(shapeu.ptr);
}
public override bool IsSoftBody(BulletShape shape)
{
- return BSAPICPP.IsSoftBody2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsSoftBody2(shapeu.ptr);
}
public override bool IsInfinite(BulletShape shape)
{
- return BSAPICPP.IsInfinite2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.IsInfinite2(shapeu.ptr);
}
public override void SetLocalScaling(BulletShape shape, Vector3 scale)
{
- BSAPICPP.SetLocalScaling2(shape.ptr, scale);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ BSAPICPP.SetLocalScaling2(shapeu.ptr, scale);
}
public override Vector3 GetLocalScaling(BulletShape shape)
{
- return BSAPICPP.GetLocalScaling2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.GetLocalScaling2(shapeu.ptr);
}
public override Vector3 CalculateLocalInertia(BulletShape shape, float mass)
{
- return BSAPICPP.CalculateLocalInertia2(shape.ptr, mass);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.CalculateLocalInertia2(shapeu.ptr, mass);
}
public override int GetShapeType(BulletShape shape)
{
- return BSAPICPP.GetShapeType2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.GetShapeType2(shapeu.ptr);
}
public override void SetMargin(BulletShape shape, float val)
{
- BSAPICPP.SetMargin2(shape.ptr, val);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ BSAPICPP.SetMargin2(shapeu.ptr, val);
}
public override float GetMargin(BulletShape shape)
{
- return BSAPICPP.GetMargin2(shape.ptr);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ return BSAPICPP.GetMargin2(shapeu.ptr);
}
// =====================================================================================
// Debugging
-public override void DumpRigidBody(BulletWorld sim, BulletBody collisionObject)
+public override void DumpRigidBody(BulletWorld world, BulletBody collisionObject)
{
- BSAPICPP.DumpRigidBody2(sim.ptr, collisionObject.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletBodyUnman bodyu = collisionObject as BulletBodyUnman;
+ BSAPICPP.DumpRigidBody2(worldu.ptr, bodyu.ptr);
}
-public override void DumpCollisionShape(BulletWorld sim, BulletShape collisionShape)
+public override void DumpCollisionShape(BulletWorld world, BulletShape collisionShape)
{
- BSAPICPP.DumpCollisionShape2(sim.ptr, collisionShape.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletShapeUnman shapeu = collisionShape as BulletShapeUnman;
+ BSAPICPP.DumpCollisionShape2(worldu.ptr, shapeu.ptr);
}
-public override void DumpConstraint(BulletWorld sim, BulletConstraint constrain)
+public override void DumpConstraint(BulletWorld world, BulletConstraint constrain)
{
- BSAPICPP.DumpConstraint2(sim.ptr, constrain.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+ BSAPICPP.DumpConstraint2(worldu.ptr, constrainu.ptr);
}
-public override void DumpActivationInfo(BulletWorld sim)
+public override void DumpActivationInfo(BulletWorld world)
{
- BSAPICPP.DumpActivationInfo2(sim.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.DumpActivationInfo2(worldu.ptr);
}
-public override void DumpAllInfo(BulletWorld sim)
+public override void DumpAllInfo(BulletWorld world)
{
- BSAPICPP.DumpAllInfo2(sim.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.DumpAllInfo2(worldu.ptr);
}
-public override void DumpPhysicsStatistics(BulletWorld sim)
+public override void DumpPhysicsStatistics(BulletWorld world)
{
- BSAPICPP.DumpPhysicsStatistics2(sim.ptr);
+ BulletWorldUnman worldu = world as BulletWorldUnman;
+ BSAPICPP.DumpPhysicsStatistics2(worldu.ptr);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index 8ed791e..f70ad30 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -29,11 +29,1287 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
+using BulletXNA;
+using BulletXNA.LinearMath;
+using BulletXNA.BulletCollision;
+using BulletXNA.BulletDynamics;
+using BulletXNA.BulletCollision.CollisionDispatch;
+
+using OpenMetaverse;
+
namespace OpenSim.Region.Physics.BulletSPlugin
{
/*
public sealed class BSAPIXNA : BSAPITemplate
{
+ private static int m_collisionsThisFrame;
+ private BSScene PhysicsScene { get; set; }
+
+ public override string BulletEngineName { get { return "BulletXNA"; } }
+ public override string BulletEngineVersion { get; protected set; }
+
+ public BSAPIXNA(string paramName, BSScene physScene)
+ {
+ PhysicsScene = physScene;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override bool RemoveObjectFromWorld2(object pWorld, object pBody)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body = pBody as RigidBody;
+ world.RemoveRigidBody(body);
+ return true;
+ }
+
+ public override void SetRestitution2(object pBody, float pRestitution)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetRestitution(pRestitution);
+ }
+
+ public override void SetMargin2(object pShape, float pMargin)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ shape.SetMargin(pMargin);
+ }
+
+ public override void SetLocalScaling2(object pShape, Vector3 pScale)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
+ shape.SetLocalScaling(ref vec);
+
+ }
+
+ public override void SetContactProcessingThreshold2(object pBody, float contactprocessingthreshold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetContactProcessingThreshold(contactprocessingthreshold);
+ }
+
+ public override void SetCcdMotionThreshold2(object pBody, float pccdMotionThreashold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCcdMotionThreshold(pccdMotionThreashold);
+ }
+
+ public override void SetCcdSweptSphereRadius2(object pBody, float pCcdSweptSphereRadius)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius);
+ }
+
+ public override void SetAngularFactorV2(object pBody, Vector3 pAngularFactor)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z));
+ }
+
+ public override CollisionFlags AddToCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
+ existingcollisionFlags |= pcollisionFlags;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
+ return (CollisionFlags) (uint) existingcollisionFlags;
+ }
+
+ public override void AddObjectToWorld2(object pWorld, object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
+
+ world.AddRigidBody(body);
+
+ //if (body.GetBroadphaseHandle() != null)
+ // world.UpdateSingleAabb(body);
+ }
+
+ public override void AddObjectToWorld2(object pWorld, object pBody, Vector3 _position, Quaternion _orientation)
+ {
+ RigidBody body = pBody as RigidBody;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ //if (!(body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE && body.GetCollisionShape().GetShapeType() == BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE))
+
+ world.AddRigidBody(body);
+ IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
+ IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
+ _orientation.W);
+ IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
+ mat._origin = vposition;
+ body.SetWorldTransform(mat);
+ //if (body.GetBroadphaseHandle() != null)
+ // world.UpdateSingleAabb(body);
+ }
+
+ public override void ForceActivationState2(object pBody, ActivationState pActivationState)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState);
+ }
+
+ public override void UpdateSingleAabb2(object pWorld, object pBody)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ world.UpdateSingleAabb(body);
+ }
+
+ public override bool SetCollisionGroupMask2(object pBody, uint pGroup, uint pMask)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
+ body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup;
+ if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0)
+ return false;
+ return true;
+ }
+
+ public override void ClearAllForces2(object pBody)
+ {
+ CollisionObject body = pBody as CollisionObject;
+ IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0);
+ body.SetInterpolationLinearVelocity(ref zeroVector);
+ body.SetInterpolationAngularVelocity(ref zeroVector);
+ IndexedMatrix bodytransform = body.GetWorldTransform();
+
+ body.SetInterpolationWorldTransform(ref bodytransform);
+
+ if (body is RigidBody)
+ {
+ RigidBody rigidbody = body as RigidBody;
+ rigidbody.SetLinearVelocity(zeroVector);
+ rigidbody.SetAngularVelocity(zeroVector);
+ rigidbody.ClearForces();
+ }
+ }
+
+ public override void SetInterpolationAngularVelocity2(object pBody, Vector3 pVector3)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
+ body.SetInterpolationAngularVelocity(ref vec);
+ }
+
+ public override void SetAngularVelocity2(object pBody, Vector3 pVector3)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z);
+ body.SetAngularVelocity(ref vec);
+ }
+
+ public override void ClearForces2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.ClearForces();
+ }
+
+ public override void SetTranslation2(object pBody, Vector3 _position, Quaternion _orientation)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z);
+ IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z,
+ _orientation.W);
+ IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion);
+ mat._origin = vposition;
+ body.SetWorldTransform(mat);
+
+ }
+
+ public override Vector3 GetPosition2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin;
+ return new Vector3(pos.X, pos.Y, pos.Z);
+ }
+
+ public override Vector3 CalculateLocalInertia2(object pShape, float pphysMass)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ IndexedVector3 inertia = IndexedVector3.Zero;
+ shape.CalculateLocalInertia(pphysMass, out inertia);
+ return new Vector3(inertia.X, inertia.Y, inertia.Z);
+ }
+
+ public override void SetMassProps2(object pBody, float pphysMass, Vector3 plocalInertia)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z);
+ body.SetMassProps(pphysMass, inertia);
+ }
+
+
+ public override void SetObjectForce2(object pBody, Vector3 _force)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z);
+ body.SetTotalForce(ref force);
+ }
+
+ public override void SetFriction2(object pBody, float _currentFriction)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetFriction(_currentFriction);
+ }
+
+ public override void SetLinearVelocity2(object pBody, Vector3 _velocity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z);
+ body.SetLinearVelocity(velocity);
+ }
+
+ public override void Activate2(object pBody, bool pforceactivation)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.Activate(pforceactivation);
+
+ }
+
+ public override Quaternion GetOrientation2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation();
+ return new Quaternion(mat.X, mat.Y, mat.Z, mat.W);
+ }
+
+ public override CollisionFlags RemoveFromCollisionFlags2(object pBody, CollisionFlags pcollisionFlags)
+ {
+ RigidBody body = pBody as RigidBody;
+ CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags();
+ existingcollisionFlags &= ~pcollisionFlags;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags);
+ return (CollisionFlags)(uint)existingcollisionFlags;
+ }
+
+ public override void SetGravity2(object pBody, Vector3 pGravity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z);
+ body.SetGravity(gravity);
+ }
+
+ public override bool DestroyConstraint2(object pBody, object pConstraint)
+ {
+ RigidBody body = pBody as RigidBody;
+ TypedConstraint constraint = pConstraint as TypedConstraint;
+ body.RemoveConstraintRef(constraint);
+ return true;
+ }
+
+ public override bool SetLinearLimits2(object pConstraint, Vector3 low, Vector3 high)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
+ IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
+ constraint.SetLinearLowerLimit(lowlimit);
+ constraint.SetLinearUpperLimit(highlimit);
+ return true;
+ }
+
+ public override bool SetAngularLimits2(object pConstraint, Vector3 low, Vector3 high)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z);
+ IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z);
+ constraint.SetAngularLowerLimit(lowlimit);
+ constraint.SetAngularUpperLimit(highlimit);
+ return true;
+ }
+
+ public override void SetConstraintNumSolverIterations2(object pConstraint, float cnt)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetOverrideNumSolverIterations((int)cnt);
+ }
+
+ public override void CalculateTransforms2(object pConstraint)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.CalculateTransforms();
+ }
+
+ public override void SetConstraintEnable2(object pConstraint, float p_2)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetEnabled((p_2 == 0) ? false : true);
+ }
+
+
+ //BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr,frame1, frame1rot,frame2, frame2rot,useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies));
+ public override object Create6DofConstraint2(object pWorld, object pBody1, object pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body1 = pBody1 as RigidBody;
+ RigidBody body2 = pBody2 as RigidBody;
+ IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
+ IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
+ IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
+ frame1._origin = frame1v;
+
+ IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
+ IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
+ IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
+ frame2._origin = frame1v;
+
+ Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2,
+ puseLinearReferenceFrameA);
+ consttr.CalculateTransforms();
+ world.AddConstraint(consttr,pdisableCollisionsBetweenLinkedBodies);
+
+ return consttr;
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override object Create6DofConstraintToPoint2(object pWorld, object pBody1, object pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body1 = pBody1 as RigidBody;
+ RigidBody body2 = pBody2 as RigidBody;
+ IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
+ IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0));
+
+ IndexedVector3 joinPoint = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
+ IndexedMatrix mat = IndexedMatrix.Identity;
+ mat._origin = new IndexedVector3(pjoinPoint.X, pjoinPoint.Y, pjoinPoint.Z);
+ frame1._origin = body1.GetWorldTransform().Inverse()*joinPoint;
+ frame2._origin = body2.GetWorldTransform().Inverse()*joinPoint;
+
+ Generic6DofConstraint consttr = new Generic6DofConstraint(body1, body2, ref frame1, ref frame2, puseLinearReferenceFrameA);
+ consttr.CalculateTransforms();
+ world.AddConstraint(consttr, pdisableCollisionsBetweenLinkedBodies);
+
+ return consttr;
+ }
+ //SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot);
+ public override void SetFrames2(object pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z);
+ IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W);
+ IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot);
+ frame1._origin = frame1v;
+
+ IndexedVector3 frame2v = new IndexedVector3(pframe2.X, pframe2.Y, pframe2.Z);
+ IndexedQuaternion frame2rot = new IndexedQuaternion(pframe2rot.X, pframe2rot.Y, pframe2rot.Z, pframe2rot.W);
+ IndexedMatrix frame2 = IndexedMatrix.CreateFromQuaternion(frame2rot);
+ frame2._origin = frame1v;
+ constraint.SetFrames(ref frame1, ref frame2);
+ }
+
+
+
+
+ public override bool IsInWorld2(object pWorld, object pShapeObj)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ CollisionObject shape = pShapeObj as CollisionObject;
+ return world.IsInWorld(shape);
+ }
+
+ public override void SetInterpolationLinearVelocity2(object pBody, Vector3 VehicleVelocity)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z);
+ body.SetInterpolationLinearVelocity(ref velocity);
+ }
+
+ public override bool UseFrameOffset2(object pConstraint, float onOff)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetUseFrameOffset((onOff == 0) ? false : true);
+ return true;
+ }
+ //SetBreakingImpulseThreshold2(m_constraint.ptr, threshold);
+ public override bool SetBreakingImpulseThreshold2(object pConstraint, float threshold)
+ {
+ Generic6DofConstraint constraint = pConstraint as Generic6DofConstraint;
+ constraint.SetBreakingImpulseThreshold(threshold);
+ return true;
+ }
+ //BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, angularDamping);
+ public override void SetAngularDamping2(object pBody, float angularDamping)
+ {
+ RigidBody body = pBody as RigidBody;
+ float lineardamping = body.GetLinearDamping();
+ body.SetDamping(lineardamping, angularDamping);
+
+ }
+
+ public override void UpdateInertiaTensor2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.UpdateInertiaTensor();
+ }
+
+ public override void RecalculateCompoundShapeLocalAabb2( object pCompoundShape)
+ {
+
+ CompoundShape shape = pCompoundShape as CompoundShape;
+ shape.RecalculateLocalAabb();
+ }
+
+ //BulletSimAPI.GetCollisionFlags2(PhysBody.ptr)
+ public override CollisionFlags GetCollisionFlags2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ uint flags = (uint)body.GetCollisionFlags();
+ return (CollisionFlags) flags;
+ }
+
+ public override void SetDamping2(object pBody, float pLinear, float pAngular)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetDamping(pLinear, pAngular);
+ }
+ //PhysBody.ptr, PhysicsScene.Params.deactivationTime);
+ public override void SetDeactivationTime2(object pBody, float pDeactivationTime)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetDeactivationTime(pDeactivationTime);
+ }
+ //SetSleepingThresholds2(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold);
+ public override void SetSleepingThresholds2(object pBody, float plinearSleepingThreshold, float pangularSleepingThreshold)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold);
+ }
+
+ public override CollisionObjectTypes GetBodyType2(object pBody)
+ {
+ RigidBody body = pBody as RigidBody;
+ return (CollisionObjectTypes)(int) body.GetInternalType();
+ }
+
+ //BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum);
+ public override void ApplyCentralForce2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyCentralForce(ref fSum);
+ }
+ public override void ApplyCentralImpulse2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyCentralImpulse(ref fSum);
+ }
+ public override void ApplyTorque2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyTorque(ref fSum);
+ }
+ public override void ApplyTorqueImpulse2(object pBody, Vector3 pfSum)
+ {
+ RigidBody body = pBody as RigidBody;
+ IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z);
+ body.ApplyTorqueImpulse(ref fSum);
+ }
+
+ public override void DumpRigidBody2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ public override void DumpCollisionShape2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ public override void DestroyObject2(object p, object p_2)
+ {
+ //TODO:
+ }
+
+ public override void Shutdown2(object pWorld)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ world.Cleanup();
+ }
+
+ public override void DeleteCollisionShape2(object p, object p_2)
+ {
+ //TODO:
+ }
+ //(sim.ptr, shape.ptr, prim.LocalID, prim.RawPosition, prim.RawOrientation);
+
+ public override object CreateBodyFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+ CollisionWorld world = pWorld as CollisionWorld;
+ IndexedMatrix mat =
+ IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
+ pRawOrientation.Z, pRawOrientation.W));
+ mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+ CollisionShape shape = pShape as CollisionShape;
+ //UpdateSingleAabb2(world, shape);
+ // TODO: Feed Update array into null
+ RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero);
+
+ body.SetUserPointer(pLocalID);
+ return body;
+ }
+
+
+ public override object CreateBodyWithDefaultMotionState2( object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+
+ IndexedMatrix mat =
+ IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
+ pRawOrientation.Z, pRawOrientation.W));
+ mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+
+ CollisionShape shape = pShape as CollisionShape;
+
+ // TODO: Feed Update array into null
+ RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
+ body.SetWorldTransform(mat);
+ body.SetUserPointer(pLocalID);
+ return body;
+ }
+ //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
+ public override void SetCollisionFlags2(object pBody, CollisionFlags collisionFlags)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags);
+ }
+ //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction);
+ public override void SetHitFraction2(object pBody, float pHitFraction)
+ {
+ RigidBody body = pBody as RigidBody;
+ body.SetHitFraction(pHitFraction);
+ }
+ //BuildCapsuleShape2(physicsScene.World.ptr, 1f, 1f, prim.Scale);
+ public override object BuildCapsuleShape2(object pWorld, float pRadius, float pHeight, Vector3 pScale)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z);
+ CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight);
+ capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin);
+ capsuleShapeZ.SetLocalScaling(ref scale);
+
+ return capsuleShapeZ;
+ }
+
+ public static object Initialize2(Vector3 worldExtent, ConfigurationParameters[] o, int mMaxCollisionsPerFrame, ref List collisionArray, int mMaxUpdatesPerFrame, ref List updateArray, object mDebugLogCallbackHandle)
+ {
+ CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();
+
+ p.angularDamping = o[0].XangularDamping;
+ p.defaultFriction = o[0].defaultFriction;
+ p.defaultFriction = o[0].defaultFriction;
+ p.defaultDensity = o[0].defaultDensity;
+ p.defaultRestitution = o[0].defaultRestitution;
+ p.collisionMargin = o[0].collisionMargin;
+ p.gravity = o[0].gravity;
+
+ p.linearDamping = o[0].XlinearDamping;
+ p.angularDamping = o[0].XangularDamping;
+ p.deactivationTime = o[0].XdeactivationTime;
+ p.linearSleepingThreshold = o[0].XlinearSleepingThreshold;
+ p.angularSleepingThreshold = o[0].XangularSleepingThreshold;
+ p.ccdMotionThreshold = o[0].XccdMotionThreshold;
+ p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius;
+ p.contactProcessingThreshold = o[0].XcontactProcessingThreshold;
+
+ p.terrainImplementation = o[0].XterrainImplementation;
+ p.terrainFriction = o[0].XterrainFriction;
+
+ p.terrainHitFraction = o[0].XterrainHitFraction;
+ p.terrainRestitution = o[0].XterrainRestitution;
+ p.terrainCollisionMargin = o[0].XterrainCollisionMargin;
+
+ p.avatarFriction = o[0].XavatarFriction;
+ p.avatarStandingFriction = o[0].XavatarStandingFriction;
+ p.avatarDensity = o[0].XavatarDensity;
+ p.avatarRestitution = o[0].XavatarRestitution;
+ p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth;
+ p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth;
+ p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight;
+ p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold;
+
+ p.vehicleAngularDamping = o[0].XvehicleAngularDamping;
+
+ p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
+ p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
+ p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
+ p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
+ p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
+ p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
+ p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
+ p.numberOfSolverIterations = o[0].numberOfSolverIterations;
+
+ p.linksetImplementation = o[0].XlinksetImplementation;
+ p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset;
+ p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor;
+ p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel;
+ p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce;
+ p.linkConstraintERP = o[0].XlinkConstraintERP;
+ p.linkConstraintCFM = o[0].XlinkConstraintCFM;
+ p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations;
+ p.physicsLoggingFrames = o[0].physicsLoggingFrames;
+ DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();
+
+ DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
+ CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);
+
+
+ if (p.maxPersistantManifoldPoolSize > 0)
+ cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
+ if (p.shouldDisableContactPoolDynamicAllocation !=0)
+ m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
+ //if (p.maxCollisionAlgorithmPoolSize >0 )
+
+ DbvtBroadphase m_broadphase = new DbvtBroadphase();
+ //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
+ //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);
+
+ //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
+ m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());
+
+ SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();
+
+ DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);
+ world.UpdatedObjects = updateArray;
+ world.UpdatedCollisions = collisionArray;
+ world.WorldSettings.Params = p;
+ world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
+ world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
+ if (p.shouldRandomizeSolverOrder != 0)
+ world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;
+
+ world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
+ //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port
+
+ if (p.shouldEnableFrictionCaching != 0)
+ world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;
+
+ if (p.numberOfSolverIterations > 0)
+ world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;
+
+
+ world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
+ world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
+ world.GetSolverInfo().m_globalCfm = 0.0f;
+ world.GetSolverInfo().m_tau = 0.6f;
+ world.GetSolverInfo().m_friction = 0.3f;
+ world.GetSolverInfo().m_maxErrorReduction = 20f;
+ world.GetSolverInfo().m_numIterations = 10;
+ world.GetSolverInfo().m_erp = 0.2f;
+ world.GetSolverInfo().m_erp2 = 0.1f;
+ world.GetSolverInfo().m_sor = 1.0f;
+ world.GetSolverInfo().m_splitImpulse = false;
+ world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
+ world.GetSolverInfo().m_linearSlop = 0.0f;
+ world.GetSolverInfo().m_warmstartingFactor = 0.85f;
+ world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
+ world.SetForceUpdateAllAabbs(true);
+
+
+ world.SetGravity(new IndexedVector3(0,0,p.gravity));
+
+ return world;
+ }
+ //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL
+ public override bool SetConstraintParam2(object pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis)
+ {
+ Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
+ if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 1);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 2);
+ }
+ if (axis == ConstraintParamAxis.AXIS_ANGULAR_ALL || axis == ConstraintParamAxis.AXIS_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 3);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 4);
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, 5);
+ }
+ if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL)
+ {
+ constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams)(int)paramIndex, paramvalue, (int)axis);
+ }
+ return true;
+ }
+
+ public override bool PushUpdate2(object pCollisionObject)
+ {
+ bool ret = false;
+ RigidBody rb = pCollisionObject as RigidBody;
+ if (rb != null)
+ {
+ SimMotionState sms = rb.GetMotionState() as SimMotionState;
+ if (sms != null)
+ {
+ IndexedMatrix wt = IndexedMatrix.Identity;
+ sms.GetWorldTransform(out wt);
+ sms.SetWorldTransform(ref wt, true);
+ ret = true;
+ }
+ }
+ return ret;
+
+ }
+
+ public override bool IsCompound2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsCompound();
+ }
+ public override bool IsPloyhedral2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsPolyhedral();
+ }
+ public override bool IsConvex2d2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConvex2d();
+ }
+ public override bool IsConvex2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConvex();
+ }
+ public override bool IsNonMoving2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsNonMoving();
+ }
+ public override bool IsConcave2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsConcave();
+ }
+ public override bool IsInfinite2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ return shape.IsInfinite();
+ }
+ public override bool IsNativeShape2(object pShape)
+ {
+ CollisionShape shape = pShape as CollisionShape;
+ bool ret;
+ switch (shape.GetShapeType())
+ {
+ case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
+ case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
+ ret = true;
+ break;
+ default:
+ ret = false;
+ break;
+ }
+ return ret;
+ }
+ //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation
+ public override object CreateGhostFromShape2(object pWorld, object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
+ {
+ IndexedMatrix bodyTransform = new IndexedMatrix();
+ bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);
+ bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W));
+ GhostObject gObj = new PairCachingGhostObject();
+ gObj.SetWorldTransform(bodyTransform);
+ CollisionShape shape = pShape as CollisionShape;
+ gObj.SetCollisionShape(shape);
+ gObj.SetUserPointer(pLocalID);
+ // TODO: Add to Special CollisionObjects!
+ return gObj;
+ }
+
+ public static void SetCollisionShape2(object pWorld, object pObj, object pShape)
+ {
+ var world = pWorld as DiscreteDynamicsWorld;
+ var obj = pObj as CollisionObject;
+ var shape = pShape as CollisionShape;
+ obj.SetCollisionShape(shape);
+
+ }
+ //(PhysicsScene.World.ptr, nativeShapeData)
+ public override object BuildNativeShape2(object pWorld, ShapeData pShapeData)
+ {
+ var world = pWorld as DiscreteDynamicsWorld;
+ CollisionShape shape = null;
+ switch (pShapeData.Type)
+ {
+ case BSPhysicsShapeType.SHAPE_BOX:
+ shape = new BoxShape(new IndexedVector3(0.5f,0.5f,0.5f));
+ break;
+ case BSPhysicsShapeType.SHAPE_CONE:
+ shape = new ConeShapeZ(0.5f, 1.0f);
+ break;
+ case BSPhysicsShapeType.SHAPE_CYLINDER:
+ shape = new CylinderShapeZ(new IndexedVector3(0.5f, 0.5f, 0.5f));
+ break;
+ case BSPhysicsShapeType.SHAPE_SPHERE:
+ shape = new SphereShape(0.5f);
+ break;
+
+ }
+ if (shape != null)
+ {
+ IndexedVector3 scaling = new IndexedVector3(pShapeData.Scale.X, pShapeData.Scale.Y, pShapeData.Scale.Z);
+ shape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ shape.SetLocalScaling(ref scaling);
+
+ }
+ return shape;
+ }
+ //PhysicsScene.World.ptr, false
+ public override object CreateCompoundShape2(object pWorld, bool enableDynamicAabbTree)
+ {
+ return new CompoundShape(enableDynamicAabbTree);
+ }
+
+ public override int GetNumberOfCompoundChildren2(object pCompoundShape)
+ {
+ var compoundshape = pCompoundShape as CompoundShape;
+ return compoundshape.GetNumChildShapes();
+ }
+ //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot
+ public override void AddChildShapeToCompoundShape2(object pCShape, object paddShape, Vector3 displacementPos, Quaternion displacementRot)
+ {
+ IndexedMatrix relativeTransform = new IndexedMatrix();
+ var compoundshape = pCShape as CompoundShape;
+ var addshape = paddShape as CollisionShape;
+
+ relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z);
+ relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W));
+ compoundshape.AddChildShape(ref relativeTransform, addshape);
+
+ }
+
+ public override object RemoveChildShapeFromCompoundShapeIndex2(object pCShape, int pii)
+ {
+ var compoundshape = pCShape as CompoundShape;
+ CollisionShape ret = null;
+ ret = compoundshape.GetChildShape(pii);
+ compoundshape.RemoveChildShapeByIndex(pii);
+ return ret;
+ }
+
+ public override object CreateGroundPlaneShape2(uint pLocalId, float pheight, float pcollisionMargin)
+ {
+ StaticPlaneShape m_planeshape = new StaticPlaneShape(new IndexedVector3(0,0,1),(int)pheight );
+ m_planeshape.SetMargin(pcollisionMargin);
+ m_planeshape.SetUserPointer(pLocalId);
+ return m_planeshape;
+ }
+
+ public override object CreateHingeConstraint2(object pWorld, object pBody1, object ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies)
+ {
+ HingeConstraint constrain = null;
+ var rb1 = pBody1 as RigidBody;
+ var rb2 = ppBody2 as RigidBody;
+ if (rb1 != null && rb2 != null)
+ {
+ IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z);
+ IndexedVector3 pivotInB = new IndexedVector3(ppivotInB.X, ppivotInB.Y, ppivotInB.Z);
+ IndexedVector3 axisInA = new IndexedVector3(paxisInA.X, paxisInA.Y, paxisInA.Z);
+ IndexedVector3 axisInB = new IndexedVector3(paxisInB.X, paxisInB.Y, paxisInB.Z);
+ var world = pWorld as DiscreteDynamicsWorld;
+ world.AddConstraint(constrain, pdisableCollisionsBetweenLinkedBodies);
+ }
+ return constrain;
+ }
+
+ public override bool ReleaseHeightMapInfo2(object pMapInfo)
+ {
+ if (pMapInfo != null)
+ {
+ BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
+ if (mapinfo.heightMap != null)
+ mapinfo.heightMap = null;
+
+
+ }
+ return true;
+ }
+
+ public override object CreateHullShape2(object pWorld, int pHullCount, float[] pConvHulls)
+ {
+ CompoundShape compoundshape = new CompoundShape(false);
+ var world = pWorld as DiscreteDynamicsWorld;
+
+
+ compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ int ii = 1;
+
+ for (int i = 0; i < pHullCount; i++)
+ {
+ int vertexCount = (int) pConvHulls[ii];
+
+ IndexedVector3 centroid = new IndexedVector3(pConvHulls[ii + 1], pConvHulls[ii + 2], pConvHulls[ii + 3]);
+ IndexedMatrix childTrans = IndexedMatrix.Identity;
+ childTrans._origin = centroid;
+
+ List virts = new List();
+ int ender = ((ii + 4) + (vertexCount*3));
+ for (int iii = ii + 4; iii < ender; iii+=3)
+ {
+
+ virts.Add(new IndexedVector3(pConvHulls[iii], pConvHulls[iii + 1], pConvHulls[iii +2]));
+ }
+ ConvexHullShape convexShape = new ConvexHullShape(virts, vertexCount);
+ convexShape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ compoundshape.AddChildShape(ref childTrans, convexShape);
+ ii += (vertexCount*3 + 4);
+ }
+
+
+ return compoundshape;
+ }
+
+ public override object CreateMeshShape2(object pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats)
+ {
+ //DumpRaw(indices,verticesAsFloats,pIndicesCount,pVerticesCount);
+
+ for (int iter = 0; iter < pVerticesCount; iter++)
+ {
+ if (verticesAsFloats[iter] > 0 && verticesAsFloats[iter] < 0.0001) verticesAsFloats[iter] = 0;
+ if (verticesAsFloats[iter] < 0 && verticesAsFloats[iter] > -0.0001) verticesAsFloats[iter] = 0;
+ }
+
+ ObjectArray indicesarr = new ObjectArray(indices);
+ ObjectArray vertices = new ObjectArray(verticesAsFloats);
+ DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount);
+ var world = pWorld as DiscreteDynamicsWorld;
+ IndexedMesh mesh = new IndexedMesh();
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount/3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indicesarr;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+ BvhTriangleMeshShape meshShape = new BvhTriangleMeshShape(tribuilder, true,true);
+ meshShape.SetMargin(world.WorldSettings.Params.collisionMargin);
+ // world.UpdateSingleAabb(meshShape);
+ return meshShape;
+
+ }
+ public static void DumpRaw(ObjectArrayindices, ObjectArray vertices, int pIndicesCount,int pVerticesCount )
+ {
+
+ String fileName = "objTest3.raw";
+ String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
+ StreamWriter sw = new StreamWriter(completePath);
+ IndexedMesh mesh = new IndexedMesh();
+
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount / 3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indices;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+
+
+
+ for (int i = 0; i < pVerticesCount; i++)
+ {
+
+ string s = vertices[indices[i * 3]].ToString("0.0000");
+ s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
+ s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
+
+ sw.Write(s + "\n");
+ }
+
+ sw.Close();
+ }
+ public static void DumpRaw(int[] indices, float[] vertices, int pIndicesCount, int pVerticesCount)
+ {
+
+ String fileName = "objTest6.raw";
+ String completePath = System.IO.Path.Combine(Util.configDir(), fileName);
+ StreamWriter sw = new StreamWriter(completePath);
+ IndexedMesh mesh = new IndexedMesh();
+
+ mesh.m_indexType = PHY_ScalarType.PHY_INTEGER;
+ mesh.m_numTriangles = pIndicesCount / 3;
+ mesh.m_numVertices = pVerticesCount;
+ mesh.m_triangleIndexBase = indices;
+ mesh.m_vertexBase = vertices;
+ mesh.m_vertexStride = 3;
+ mesh.m_vertexType = PHY_ScalarType.PHY_FLOAT;
+ mesh.m_triangleIndexStride = 3;
+
+ TriangleIndexVertexArray tribuilder = new TriangleIndexVertexArray();
+ tribuilder.AddIndexedMesh(mesh, PHY_ScalarType.PHY_INTEGER);
+
+
+ sw.WriteLine("Indices");
+ sw.WriteLine(string.Format("int[] indices = new int[{0}];",pIndicesCount));
+ for (int iter = 0; iter < indices.Length; iter++)
+ {
+ sw.WriteLine(string.Format("indices[{0}]={1};",iter,indices[iter]));
+ }
+ sw.WriteLine("VerticesFloats");
+ sw.WriteLine(string.Format("float[] vertices = new float[{0}];", pVerticesCount));
+ for (int iter = 0; iter < vertices.Length; iter++)
+ {
+ sw.WriteLine(string.Format("Vertices[{0}]={1};", iter, vertices[iter].ToString("0.0000")));
+ }
+
+ // for (int i = 0; i < pVerticesCount; i++)
+ // {
+ //
+ // string s = vertices[indices[i * 3]].ToString("0.0000");
+ // s += " " + vertices[indices[i * 3 + 1]].ToString("0.0000");
+ // s += " " + vertices[indices[i * 3 + 2]].ToString("0.0000");
+ //
+ // sw.Write(s + "\n");
+ //}
+
+ sw.Close();
+ }
+ //PhysicsScene.World.ptr, m_mapInfo.ID, m_mapInfo.minCoords, m_mapInfo.maxCoords, m_mapInfo.heightMap, PhysicsScene.Params.terrainCollisionMargin
+ public override object CreateHeightMapInfo2(object pWorld, uint pId, Vector3 pminCoords, Vector3 pmaxCoords, float[] pheightMap, float pCollisionMargin)
+ {
+ BulletHeightMapInfo mapInfo = new BulletHeightMapInfo(pId, pheightMap, null);
+ mapInfo.heightMap = null;
+ mapInfo.minCoords = pminCoords;
+ mapInfo.maxCoords = pmaxCoords;
+ mapInfo.sizeX = (int) (pmaxCoords.X - pminCoords.X);
+ mapInfo.sizeY = (int) (pmaxCoords.Y - pminCoords.Y);
+ mapInfo.ID = pId;
+ mapInfo.minZ = pminCoords.Z;
+ mapInfo.maxZ = pmaxCoords.Z;
+ mapInfo.collisionMargin = pCollisionMargin;
+ if (mapInfo.minZ == mapInfo.maxZ)
+ mapInfo.minZ -= 0.2f;
+ mapInfo.heightMap = pheightMap;
+
+ return mapInfo;
+
+ }
+
+ public override object CreateTerrainShape2(object pMapInfo)
+ {
+ BulletHeightMapInfo mapinfo = pMapInfo as BulletHeightMapInfo;
+ const int upAxis = 2;
+ const float scaleFactor = 1.0f;
+ HeightfieldTerrainShape terrainShape = new HeightfieldTerrainShape((int)mapinfo.sizeX, (int)mapinfo.sizeY,
+ mapinfo.heightMap, scaleFactor,
+ mapinfo.minZ, mapinfo.maxZ, upAxis,
+ false);
+ terrainShape.SetMargin(mapinfo.collisionMargin + 0.5f);
+ terrainShape.SetUseDiamondSubdivision(true);
+ terrainShape.SetUserPointer(mapinfo.ID);
+ return terrainShape;
+ }
+
+ public override bool TranslationalLimitMotor2(object pConstraint, float ponOff, float targetVelocity, float maxMotorForce)
+ {
+ TypedConstraint tconstrain = pConstraint as TypedConstraint;
+ bool onOff = ponOff != 0;
+ bool ret = false;
+
+ switch (tconstrain.GetConstraintType())
+ {
+ case TypedConstraintType.D6_CONSTRAINT_TYPE:
+ Generic6DofConstraint constrain = pConstraint as Generic6DofConstraint;
+ constrain.GetTranslationalLimitMotor().m_enableMotor[0] = onOff;
+ constrain.GetTranslationalLimitMotor().m_targetVelocity[0] = targetVelocity;
+ constrain.GetTranslationalLimitMotor().m_maxMotorForce[0] = maxMotorForce;
+ ret = true;
+ break;
+ }
+
+
+ return ret;
+
+ }
+
+ public override int PhysicsStep2(object pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List updatedEntities, out int collidersCount, out Listcolliders)
+ {
+ int epic = PhysicsStepint2(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities,
+ out collidersCount, out colliders);
+ return epic;
+ }
+
+ private static int PhysicsStepint2(object pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List updatedEntities, out int collidersCount, out List colliders)
+ {
+ int numSimSteps = 0;
+
+
+ //if (updatedEntities is null)
+ // updatedEntities = new List();
+
+ //if (colliders is null)
+ // colliders = new List();
+
+
+ if (pWorld is DiscreteDynamicsWorld)
+ {
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+
+ numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep);
+ int updates = 0;
+
+ updatedEntityCount = world.UpdatedObjects.Count;
+ updatedEntities = new List(world.UpdatedObjects);
+ updatedEntityCount = updatedEntities.Count;
+ world.UpdatedObjects.Clear();
+
+
+ collidersCount = world.UpdatedCollisions.Count;
+ colliders = new List(world.UpdatedCollisions);
+
+ world.UpdatedCollisions.Clear();
+ m_collisionsThisFrame = 0;
+ int numManifolds = world.GetDispatcher().GetNumManifolds();
+ for (int j = 0; j < numManifolds; j++)
+ {
+ PersistentManifold contactManifold = world.GetDispatcher().GetManifoldByIndexInternal(j);
+ int numContacts = contactManifold.GetNumContacts();
+ if (numContacts == 0)
+ continue;
+
+ CollisionObject objA = contactManifold.GetBody0() as CollisionObject;
+ CollisionObject objB = contactManifold.GetBody1() as CollisionObject;
+
+ ManifoldPoint manifoldPoint = contactManifold.GetContactPoint(0);
+ IndexedVector3 contactPoint = manifoldPoint.GetPositionWorldOnB();
+ IndexedVector3 contactNormal = -manifoldPoint.m_normalWorldOnB; // make relative to A
+
+ RecordCollision(world, objA, objB, contactPoint, contactNormal);
+ m_collisionsThisFrame ++;
+ if (m_collisionsThisFrame >= 9999999)
+ break;
+
+
+ }
+
+
+ }
+ else
+ {
+ //if (updatedEntities is null)
+ updatedEntities = new List();
+ updatedEntityCount = 0;
+ //if (colliders is null)
+ colliders = new List();
+ collidersCount = 0;
+ }
+ return numSimSteps;
+ }
+
+ private static void RecordCollision(CollisionWorld world,CollisionObject objA, CollisionObject objB, IndexedVector3 contact, IndexedVector3 norm)
+ {
+
+ IndexedVector3 contactNormal = norm;
+ if ((objA.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0 &&
+ (objB.GetCollisionFlags() & BulletXNA.BulletCollision.CollisionFlags.BS_WANTS_COLLISIONS) == 0)
+ {
+ return;
+ }
+ uint idA = (uint)objA.GetUserPointer();
+ uint idB = (uint)objB.GetUserPointer();
+ if (idA > idB)
+ {
+ uint temp = idA;
+ idA = idB;
+ idB = temp;
+ contactNormal = -contactNormal;
+ }
+
+ ulong collisionID = ((ulong) idA << 32) | idB;
+
+ BulletXNA.CollisionDesc cDesc = new BulletXNA.CollisionDesc()
+ {
+ aID = idA,
+ bID = idB,
+ point = contact,
+ normal = contactNormal
+ };
+ world.UpdatedCollisions.Add(cDesc);
+ m_collisionsThisFrame++;
+
+
+ }
+ private static EntityProperties GetDebugProperties(object pWorld, object pBody)
+ {
+ EntityProperties ent = new EntityProperties();
+ DiscreteDynamicsWorld world = pWorld as DiscreteDynamicsWorld;
+ RigidBody body = pBody as RigidBody;
+ IndexedMatrix transform = body.GetWorldTransform();
+ IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity();
+ IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity();
+ IndexedQuaternion rotation = transform.GetRotation();
+ ent.Acceleration = Vector3.Zero;
+ ent.ID = (uint)body.GetUserPointer();
+ ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z);
+ ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W);
+ ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
+ ent.RotationalVelocity = new Vector3(AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);
+ return ent;
+ }
+
+ public override Vector3 GetLocalScaling2(object pBody)
+ {
+ CollisionShape shape = pBody as CollisionShape;
+ IndexedVector3 scale = shape.GetLocalScaling();
+ return new Vector3(scale.X,scale.Y,scale.Z);
+ }
+
+ public override bool RayCastGround(object pWorld, Vector3 _RayOrigin, float pRayHeight, object NotMe)
+ {
+ DynamicsWorld world = pWorld as DynamicsWorld;
+ if (world != null)
+ {
+ if (NotMe is CollisionObject || NotMe is RigidBody)
+ {
+ CollisionObject AvoidBody = NotMe as CollisionObject;
+
+ IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z);
+ IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight);
+ using (
+ ClosestNotMeRayResultCallback rayCallback = new ClosestNotMeRayResultCallback(rOrigin,
+ rEnd, AvoidBody)
+ )
+ {
+ world.RayTest(ref rOrigin, ref rEnd, rayCallback);
+ if (rayCallback.HasHit())
+ {
+ IndexedVector3 hitLocation = rayCallback.m_hitPointWorld;
+
+ }
+ return rayCallback.HasHit();
+ }
+ }
+ }
+ return false;
+ }
}
- */
+*/
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
index 699f055..2350f59 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -362,7 +362,7 @@ public abstract void DestroyObject(BulletWorld sim, BulletBody obj);
// =====================================================================================
public abstract BulletShape CreateGroundPlaneShape(uint id, float height, float collisionMargin);
-public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
+public abstract BulletShape CreateTerrainShape(uint id, Vector3 size, float minHeight, float maxHeight, float[] heightMap,
float scaleFactor, float collisionMargin);
// =====================================================================================
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 064ce3c..cb8108d 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -300,7 +300,7 @@ public sealed class BSPrim : BSPhysObject
// All positions are given in world positions.
if (_position == value)
{
- DetailLog("{0},BSPrim.setPosition,taint,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation);
+ DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation);
return;
}
_position = value;
@@ -894,21 +894,26 @@ public sealed class BSPrim : BSPhysObject
// Object MUST NOT already be in the world.
// This routine exists because some assorted properties get mangled by adding to the world.
internal void AddObjectToPhysicalWorld()
- {
- if (PhysBody.HasPhysicalBody)
- {
- PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
-
- // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
- // Replace this when the new AddObjectToWorld function is complete.
- PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
-
- // Collision filter can be set only when the object is in the world
- if (!PhysBody.ApplyCollisionMask(PhysicsScene))
- {
- m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
- DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
- }
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
+
+ // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
+ // Replace this when the new AddObjectToWorld function is complete.
+ PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
+
+ // Collision filter can be set only when the object is in the world
+ if (!PhysBody.ApplyCollisionMask(PhysicsScene))
+ {
+ m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
+ }
+ }
+ else
+ {
+ m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index cd77581..2b652f5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -45,7 +45,7 @@ public sealed class BSShapeCollection : IDisposable
// Description of a Mesh
private struct MeshDesc
{
- public IntPtr ptr;
+ public BulletShape shape;
public int referenceCount;
public DateTime lastReferenced;
public UInt64 shapeKey;
@@ -55,7 +55,7 @@ public sealed class BSShapeCollection : IDisposable
// Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations.
private struct HullDesc
{
- public IntPtr ptr;
+ public BulletShape shape;
public int referenceCount;
public DateTime lastReferenced;
public UInt64 shapeKey;
@@ -173,7 +173,7 @@ public sealed class BSShapeCollection : IDisposable
}
// Zero any reference to the shape so it is not freed when the body is deleted.
- PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape());
+ PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null);
PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
});
}
@@ -202,7 +202,7 @@ public sealed class BSShapeCollection : IDisposable
else
{
// This is a new reference to a mesh
- meshDesc.ptr = shape.ptr;
+ meshDesc.shape = shape.Clone();
meshDesc.shapeKey = shape.shapeKey;
// We keep a reference to the underlying IMesh data so a hull can be built
meshDesc.referenceCount = 1;
@@ -225,7 +225,7 @@ public sealed class BSShapeCollection : IDisposable
else
{
// This is a new reference to a hull
- hullDesc.ptr = shape.ptr;
+ hullDesc.shape = shape.Clone();
hullDesc.shapeKey = shape.shapeKey;
hullDesc.referenceCount = 1;
if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
@@ -361,15 +361,14 @@ public sealed class BSShapeCollection : IDisposable
MeshDesc meshDesc;
HullDesc hullDesc;
- IntPtr cShape = shapeInfo.ptr;
- if (TryGetMeshByPtr(cShape, out meshDesc))
+ if (TryGetMeshByPtr(shapeInfo, out meshDesc))
{
shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH;
shapeInfo.shapeKey = meshDesc.shapeKey;
}
else
{
- if (TryGetHullByPtr(cShape, out hullDesc))
+ if (TryGetHullByPtr(shapeInfo, out hullDesc))
{
shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL;
shapeInfo.shapeKey = hullDesc.shapeKey;
@@ -632,7 +631,7 @@ public sealed class BSShapeCollection : IDisposable
if (Meshes.TryGetValue(newMeshKey, out meshDesc))
{
// If the mesh has already been built just use it.
- newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH);
+ newShape = meshDesc.shape.Clone();
}
else
{
@@ -703,7 +702,7 @@ public sealed class BSShapeCollection : IDisposable
if (Hulls.TryGetValue(newHullKey, out hullDesc))
{
// If the hull shape already is created, just use it.
- newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL);
+ newShape = hullDesc.shape.Clone();
}
else
{
@@ -965,13 +964,13 @@ public sealed class BSShapeCollection : IDisposable
return ret;
}
- private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc)
+ private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc)
{
bool ret = false;
MeshDesc foundDesc = new MeshDesc();
foreach (MeshDesc md in Meshes.Values)
{
- if (md.ptr == addr)
+ if (md.shape.ReferenceSame(shape))
{
foundDesc = md;
ret = true;
@@ -983,13 +982,13 @@ public sealed class BSShapeCollection : IDisposable
return ret;
}
- private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc)
+ private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc)
{
bool ret = false;
HullDesc foundDesc = new HullDesc();
foreach (HullDesc hd in Hulls.Values)
{
- if (hd.ptr == addr)
+ if (hd.shape.ReferenceSame(shape))
{
foundDesc = hd;
ret = true;
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
index 681d21e..662dd68 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimData.cs
@@ -33,17 +33,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
// Classes to allow some type checking for the API
// These hold pointers to allocated objects in the unmanaged space.
+// These classes are subclassed by the various physical implementations of
+// objects. In particular, there is a version for physical instances in
+// unmanaged memory ("unman") and one for in managed memory ("XNA").
+
+// Currently, the instances of these classes are a reference to a
+// physical representation and this has no releationship to other
+// instances. Someday, refarb the usage of these classes so each instance
+// refers to a particular physical instance and this class controls reference
+// counts and such. This should be done along with adding BSShapes.
-// The physics engine controller class created at initialization
public class BulletWorld
{
- public BulletWorld(uint worldId, BSScene bss, IntPtr xx)
+ public BulletWorld(uint worldId, BSScene bss)
{
- ptr = xx;
worldID = worldId;
physicsScene = bss;
}
- public IntPtr ptr;
public uint worldID;
// The scene is only in here so very low level routines have a handle to print debug/error messages
public BSScene physicsScene;
@@ -52,27 +58,19 @@ public class BulletWorld
// An allocated Bullet btRigidBody
public class BulletBody
{
- public BulletBody(uint id) : this(id, IntPtr.Zero)
- {
- }
- public BulletBody(uint id, IntPtr xx)
+ public BulletBody(uint id)
{
ID = id;
- ptr = xx;
collisionType = CollisionType.Static;
}
- public IntPtr ptr;
public uint ID;
public CollisionType collisionType;
- public void Clear()
- {
- ptr = IntPtr.Zero;
- }
- public bool HasPhysicalBody { get { return ptr != IntPtr.Zero; } }
+ public virtual void Clear() { }
+ public virtual bool HasPhysicalBody { get { return false; } }
// Apply the specificed collision mask into the physical world
- public bool ApplyCollisionMask(BSScene physicsScene)
+ public virtual bool ApplyCollisionMask(BSScene physicsScene)
{
// Should assert the body has been added to the physical world.
// (The collision masks are stored in the collision proxy cache which only exists for
@@ -83,12 +81,9 @@ public class BulletBody
}
// Used for log messages for a unique display of the memory/object allocated to this instance
- public string AddrString
+ public virtual string AddrString
{
- get
- {
- return ptr.ToString("X");
- }
+ get { return "unknown"; }
}
public override string ToString()
@@ -108,38 +103,26 @@ public class BulletBody
public class BulletShape
{
public BulletShape()
- : this(IntPtr.Zero, BSPhysicsShapeType.SHAPE_UNKNOWN)
- {
- }
- public BulletShape(IntPtr xx)
- : this(xx, BSPhysicsShapeType.SHAPE_UNKNOWN)
{
- }
- public BulletShape(IntPtr xx, BSPhysicsShapeType typ)
- {
- ptr = xx;
- type = typ;
+ type = BSPhysicsShapeType.SHAPE_UNKNOWN;
shapeKey = (System.UInt64)FixedShapeKey.KEY_NONE;
isNativeShape = false;
}
- public IntPtr ptr;
public BSPhysicsShapeType type;
public System.UInt64 shapeKey;
public bool isNativeShape;
- public void Clear()
- {
- ptr = IntPtr.Zero;
- }
- public bool HasPhysicalShape { get { return ptr != IntPtr.Zero; } }
+ public virtual void Clear() { }
+ public virtual bool HasPhysicalShape { get { return false; } }
+ // Make another reference to this physical object.
+ public virtual BulletShape Clone() { return new BulletShape(); }
+ // Return 'true' if this and other refer to the same physical object
+ public virtual bool ReferenceSame(BulletShape xx) { return false; }
// Used for log messages for a unique display of the memory/object allocated to this instance
- public string AddrString
+ public virtual string AddrString
{
- get
- {
- return ptr.ToString("X");
- }
+ get { return "unknown"; }
}
public override string ToString()
@@ -161,25 +144,16 @@ public class BulletShape
// An allocated Bullet btConstraint
public class BulletConstraint
{
- public BulletConstraint(IntPtr xx)
- {
- ptr = xx;
- }
- public IntPtr ptr;
-
- public void Clear()
+ public BulletConstraint()
{
- ptr = IntPtr.Zero;
}
- public bool HasPhysicalConstraint { get { return ptr != IntPtr.Zero; } }
+ public virtual void Clear() { }
+ public virtual bool HasPhysicalConstraint { get { return false; } }
// Used for log messages for a unique display of the memory/object allocated to this instance
- public string AddrString
+ public virtual string AddrString
{
- get
- {
- return ptr.ToString("X");
- }
+ get { return "unknown"; }
}
}
--
cgit v1.1
From 0662d109c2954c7be5f5e9400b1f4afdeab2c298 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Tue, 1 Jan 2013 09:32:21 -0800
Subject: BulletSim: fix line endings.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 64 +++++++++++-----------
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 40 +++++++-------
2 files changed, 52 insertions(+), 52 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 2c0cb43..9d8f60d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -55,10 +55,10 @@ private sealed class BulletBodyUnman : BulletBody
: base(id)
{
ptr = xx;
- }
- public override bool HasPhysicalBody
- {
- get { return ptr != IntPtr.Zero; }
+ }
+ public override bool HasPhysicalBody
+ {
+ get { return ptr != IntPtr.Zero; }
}
public override void Clear()
{
@@ -79,10 +79,10 @@ private sealed class BulletShapeUnman : BulletShape
ptr = xx;
type = typ;
}
- public override bool HasPhysicalShape
- {
- get { return ptr != IntPtr.Zero; }
- }
+ public override bool HasPhysicalShape
+ {
+ get { return ptr != IntPtr.Zero; }
+ }
public override void Clear()
{
ptr = IntPtr.Zero;
@@ -202,7 +202,7 @@ public override int PhysicsStep(BulletWorld world, float timeStep, int maxSubSte
public override void Shutdown(BulletWorld world)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BSAPICPP.Shutdown2(worldu.ptr);
}
@@ -249,7 +249,7 @@ public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShap
public override BulletShape BuildNativeShape(BulletWorld world, ShapeData shapeData)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
return new BulletShapeUnman(BSAPICPP.BuildNativeShape2(worldu.ptr, shapeData), shapeData.Type);
}
@@ -334,7 +334,7 @@ public override BulletShape DuplicateCollisionShape(BulletWorld world, BulletSha
public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletShapeUnman shapeu = shape as BulletShapeUnman;
return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
}
@@ -360,7 +360,7 @@ public override BulletBody CreateBodyWithDefaultMotionState(BulletShape shape, u
public override BulletBody CreateGhostFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletShapeUnman shapeu = shape as BulletShapeUnman;
return new BulletBodyUnman(id, BSAPICPP.CreateGhostFromShape2(worldu.ptr, shapeu.ptr, id, pos, rot));
}
@@ -393,7 +393,7 @@ public override BulletConstraint Create6DofConstraint(BulletWorld world, BulletB
Vector3 frame2loc, Quaternion frame2rot,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.Create6DofConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr, frame1loc, frame1rot,
@@ -404,7 +404,7 @@ public override BulletConstraint Create6DofConstraintToPoint(BulletWorld world,
Vector3 joinPoint,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.Create6DofConstraintToPoint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
@@ -416,7 +416,7 @@ public override BulletConstraint CreateHingeConstraint(BulletWorld world, Bullet
Vector3 axisInA, Vector3 axisInB,
bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu1 = obj1 as BulletBodyUnman;
BulletBodyUnman bodyu2 = obj2 as BulletBodyUnman;
return new BulletConstraintUnman(BSAPICPP.CreateHingeConstraint2(worldu.ptr, bodyu1.ptr, bodyu2.ptr,
@@ -494,7 +494,7 @@ public override bool DestroyConstraint(BulletWorld world, BulletConstraint const
// =====================================================================================
// btCollisionWorld entries
public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
-{
+{
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu = obj as BulletBodyUnman;
BSAPICPP.UpdateSingleAabb2(worldu.ptr, bodyu.ptr);
@@ -502,19 +502,19 @@ public override void UpdateSingleAabb(BulletWorld world, BulletBody obj)
public override void UpdateAabbs(BulletWorld world)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BSAPICPP.UpdateAabbs2(worldu.ptr);
}
public override bool GetForceUpdateAllAabbs(BulletWorld world)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
return BSAPICPP.GetForceUpdateAllAabbs2(worldu.ptr);
}
public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BSAPICPP.SetForceUpdateAllAabbs2(worldu.ptr, force);
}
@@ -522,28 +522,28 @@ public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
// btDynamicsWorld entries
public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu = obj as BulletBodyUnman;
return BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
}
public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu = obj as BulletBodyUnman;
return BSAPICPP.RemoveObjectFromWorld2(worldu.ptr, bodyu.ptr);
}
public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.AddConstraintToWorld2(worldu.ptr, constrainu.ptr, disableCollisionsBetweenLinkedObjects);
}
public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.RemoveConstraintFromWorld2(worldu.ptr, constrainu.ptr);
}
@@ -605,16 +605,16 @@ public override bool HasContactResponse(BulletBody obj)
public override void SetCollisionShape(BulletWorld world, BulletBody obj, BulletShape shape)
{
- BulletWorldUnman worldu = world as BulletWorldUnman;
+ BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu = obj as BulletBodyUnman;
- BulletShapeUnman shapeu = shape as BulletShapeUnman;
- if (worldu != null && bodyu != null)
- {
- // Special case to allow the caller to zero out the reference to any physical shape
- if (shapeu != null)
- BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
- else
- BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
+ BulletShapeUnman shapeu = shape as BulletShapeUnman;
+ if (worldu != null && bodyu != null)
+ {
+ // Special case to allow the caller to zero out the reference to any physical shape
+ if (shapeu != null)
+ BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, shapeu.ptr);
+ else
+ BSAPICPP.SetCollisionShape2(worldu.ptr, bodyu.ptr, IntPtr.Zero);
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index cb8108d..d4e2e87 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -894,26 +894,26 @@ public sealed class BSPrim : BSPhysObject
// Object MUST NOT already be in the world.
// This routine exists because some assorted properties get mangled by adding to the world.
internal void AddObjectToPhysicalWorld()
- {
- if (PhysBody.HasPhysicalBody)
- {
- PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
-
- // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
- // Replace this when the new AddObjectToWorld function is complete.
- PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
-
- // Collision filter can be set only when the object is in the world
- if (!PhysBody.ApplyCollisionMask(PhysicsScene))
- {
- m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
- DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
- }
- }
- else
- {
- m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
- DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
+ {
+ if (PhysBody.HasPhysicalBody)
+ {
+ PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody);
+
+ // TODO: Fix this. Total kludge because adding object to world resets its gravity to default.
+ // Replace this when the new AddObjectToWorld function is complete.
+ PhysicsScene.PE.SetGravity(PhysBody, ComputeGravity());
+
+ // Collision filter can be set only when the object is in the world
+ if (!PhysBody.ApplyCollisionMask(PhysicsScene))
+ {
+ m_log.ErrorFormat("{0} Failed setting object collision mask: id={1}", LogHeader, LocalID);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,failedSetMaskGroup,cType={1}", LocalID, PhysBody.collisionType);
+ }
+ }
+ else
+ {
+ m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID);
+ DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType);
}
}
--
cgit v1.1
From 9d840fd2ee5c3e6c6f788e8145f06701e9ea2724 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Tue, 1 Jan 2013 16:49:38 -0800
Subject: BulletSim: move over and port the interface for BulletXNA. Copied
BulletSNPlugin.BulletSimAPI to a new BulletSPlugin.BSAPIXNA.cs and then
modifyed the latter to comply with the BSAPITemplate definition. Not totally
debugged but the code is all there for an INI variable to select either
unmanaged C++ Bullet or the C# version of Bullet.
---
OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 22 +-
OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 889 ++++++++++++++-------
.../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 6 +-
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 11 -
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 2 +-
.../Physics/BulletSPlugin/BSShapeCollection.cs | 4 +-
.../Physics/BulletSPlugin/BSTerrainHeightmap.cs | 4 +-
7 files changed, 623 insertions(+), 315 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 9d8f60d..83e12ba 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -339,10 +339,10 @@ public override bool DeleteCollisionShape(BulletWorld world, BulletShape shape)
return BSAPICPP.DeleteCollisionShape2(worldu.ptr, shapeu.ptr);
}
-public override int GetBodyType(BulletBody obj)
+public override CollisionObjectTypes GetBodyType(BulletBody obj)
{
BulletBodyUnman bodyu = obj as BulletBodyUnman;
- return BSAPICPP.GetBodyType2(bodyu.ptr);
+ return (CollisionObjectTypes)BSAPICPP.GetBodyType2(bodyu.ptr);
}
public override BulletBody CreateBodyFromShape(BulletWorld world, BulletShape shape, uint id, Vector3 pos, Quaternion rot)
@@ -522,9 +522,22 @@ public override void SetForceUpdateAllAabbs(BulletWorld world, bool force)
// btDynamicsWorld entries
public override bool AddObjectToWorld(BulletWorld world, BulletBody obj)
{
+ // Bullet resets several variables when an object is added to the world.
+ // Gravity is reset to world default depending on the static/dynamic
+ // type. Of course, the collision flags in the broadphase proxy are initialized to default.
BulletWorldUnman worldu = world as BulletWorldUnman;
BulletBodyUnman bodyu = obj as BulletBodyUnman;
- return BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
+
+ Vector3 origGrav = BSAPICPP.GetGravity2(bodyu.ptr);
+
+ bool ret = BSAPICPP.AddObjectToWorld2(worldu.ptr, bodyu.ptr);
+
+ if (ret)
+ {
+ BSAPICPP.SetGravity2(bodyu.ptr, origGrav);
+ obj.ApplyCollisionMask(world.physicsScene);
+ }
+ return ret;
}
public override bool RemoveObjectFromWorld(BulletWorld world, BulletBody obj)
@@ -1061,7 +1074,7 @@ public override Vector3 GetAngularFactor(BulletBody obj)
return BSAPICPP.GetAngularFactor2(bodyu.ptr);
}
-public override bool IsInWorld(BulletBody obj)
+public override bool IsInWorld(BulletWorld world, BulletBody obj)
{
BulletBodyUnman bodyu = obj as BulletBodyUnman;
return BSAPICPP.IsInWorld2(bodyu.ptr);
@@ -1239,7 +1252,6 @@ public override void DumpPhysicsStatistics(BulletWorld world)
BSAPICPP.DumpPhysicsStatistics2(worldu.ptr);
}
-
// =====================================================================================
// =====================================================================================
// =====================================================================================
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
index f70ad30..aea10ee 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -26,22 +26,110 @@
*/
using System;
using System.Collections.Generic;
-using System.Linq;
+using System.IO;
using System.Text;
+using OpenSim.Framework;
+
+using OpenMetaverse;
+
using BulletXNA;
using BulletXNA.LinearMath;
using BulletXNA.BulletCollision;
using BulletXNA.BulletDynamics;
using BulletXNA.BulletCollision.CollisionDispatch;
-using OpenMetaverse;
-
namespace OpenSim.Region.Physics.BulletSPlugin
{
- /*
public sealed class BSAPIXNA : BSAPITemplate
{
+private sealed class BulletWorldXNA : BulletWorld
+{
+ public DiscreteDynamicsWorld world;
+ public BulletWorldXNA(uint id, BSScene physScene, DiscreteDynamicsWorld xx)
+ : base(id, physScene)
+ {
+ world = xx;
+ }
+}
+
+private sealed class BulletBodyXNA : BulletBody
+{
+ public CollisionObject body;
+ public RigidBody rigidBody { get { return RigidBody.Upcast(body); } }
+
+ public BulletBodyXNA(uint id, CollisionObject xx)
+ : base(id)
+ {
+ body = xx;
+ }
+ public override bool HasPhysicalBody
+ {
+ get { return body != null; }
+ }
+ public override void Clear()
+ {
+ body = null;
+ }
+ public override string AddrString
+ {
+ get { return "XNARigidBody"; }
+ }
+}
+
+private sealed class BulletShapeXNA : BulletShape
+{
+ public CollisionShape shape;
+ public BulletShapeXNA(CollisionShape xx, BSPhysicsShapeType typ)
+ : base()
+ {
+ shape = xx;
+ type = typ;
+ }
+ public override bool HasPhysicalShape
+ {
+ get { return shape != null; }
+ }
+ public override void Clear()
+ {
+ shape = null;
+ }
+ public override BulletShape Clone()
+ {
+ return new BulletShapeXNA(shape, type);
+ }
+ public override bool ReferenceSame(BulletShape other)
+ {
+ BulletShapeXNA otheru = other as BulletShapeXNA;
+ return (otheru != null) && (this.shape == otheru.shape);
+
+ }
+ public override string AddrString
+ {
+ get { return "XNACollisionShape"; }
+ }
+}
+private sealed class BulletConstraintXNA : BulletConstraint
+{
+ public TypedConstraint constrain;
+ public BulletConstraintXNA(TypedConstraint xx) : base()
+ {
+ constrain = xx;
+ }
+
+ public override void Clear()
+ {
+ constrain = null;
+ }
+ public override bool HasPhysicalConstraint { get { return constrain != null; } }
+
+ // Used for log messages for a unique display of the memory/object allocated to this instance
+ public override string AddrString
+ {
+ get { return "XNAConstraint"; }
+ }
+}
+
private static int m_collisionsThisFrame;
private BSScene PhysicsScene { get; set; }
@@ -58,112 +146,135 @@ public sealed class BSAPIXNA : BSAPITemplate
///