aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs334
1 files changed, 319 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index c88a5c2..9695fcf 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -34,6 +34,7 @@ using OMV = OpenMetaverse;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.Physics.Manager; 35using OpenSim.Region.Physics.Manager;
36using OpenSim.Region.Physics.ConvexDecompositionDotNet; 36using OpenSim.Region.Physics.ConvexDecompositionDotNet;
37using OpenSim.Region.OptionalModules.Scripting; // for ExtendedPhysics
37 38
38namespace OpenSim.Region.Physics.BulletSPlugin 39namespace OpenSim.Region.Physics.BulletSPlugin
39{ 40{
@@ -285,23 +286,21 @@ public class BSPrim : BSPhysObject
285 { 286 {
286 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); 287 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
287 288
288 // "1" means free, "0" means locked 289 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR, 0f, 0f);
289 OMV.Vector3 locking = LockedAxisFree; 290 if (axis.X != 1)
290 if (axis.X != 1) locking.X = 0f;
291 if (axis.Y != 1) locking.Y = 0f;
292 if (axis.Z != 1) locking.Z = 0f;
293 LockedAngularAxis = locking;
294
295 EnableActor(LockedAngularAxis != LockedAxisFree, LockedAxisActorName, delegate()
296 { 291 {
297 return new BSActorLockAxis(PhysScene, this, LockedAxisActorName); 292 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_X, 0f, 0f);
298 }); 293 }
299 294 if (axis.Y != 1)
300 // Update parameters so the new actor's Refresh() action is called at the right time.
301 PhysScene.TaintedObject(LocalID, "BSPrim.LockAngularMotion", delegate()
302 { 295 {
303 UpdatePhysicalParameters(); 296 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Y, 0f, 0f);
304 }); 297 }
298 if (axis.Z != 1)
299 {
300 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Z, 0f, 0f);
301 }
302
303 InitializeAxisActor();
305 304
306 return; 305 return;
307 } 306 }
@@ -533,6 +532,12 @@ public class BSPrim : BSPhysObject
533 { 532 {
534 return new BSActorSetForce(PhysScene, this, SetForceActorName); 533 return new BSActorSetForce(PhysScene, this, SetForceActorName);
535 }); 534 });
535
536 // Call update so actor Refresh() is called to start things off
537 PhysScene.TaintedObject(LocalID, "BSPrim.setForce", delegate()
538 {
539 UpdatePhysicalParameters();
540 });
536 } 541 }
537 } 542 }
538 543
@@ -766,6 +771,12 @@ public class BSPrim : BSPhysObject
766 return new BSActorSetTorque(PhysScene, this, SetTorqueActorName); 771 return new BSActorSetTorque(PhysScene, this, SetTorqueActorName);
767 }); 772 });
768 DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, RawTorque); 773 DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, RawTorque);
774
775 // Call update so actor Refresh() is called to start things off
776 PhysScene.TaintedObject(LocalID, "BSPrim.setTorque", delegate()
777 {
778 UpdatePhysicalParameters();
779 });
769 } 780 }
770 } 781 }
771 public override OMV.Vector3 Acceleration { 782 public override OMV.Vector3 Acceleration {
@@ -1138,6 +1149,12 @@ public class BSPrim : BSPhysObject
1138 { 1149 {
1139 return new BSActorMoveToTarget(PhysScene, this, MoveToTargetActorName); 1150 return new BSActorMoveToTarget(PhysScene, this, MoveToTargetActorName);
1140 }); 1151 });
1152
1153 // Call update so actor Refresh() is called to start things off
1154 PhysScene.TaintedObject(LocalID, "BSPrim.PIDActive", delegate()
1155 {
1156 UpdatePhysicalParameters();
1157 });
1141 } 1158 }
1142 } 1159 }
1143 1160
@@ -1164,6 +1181,12 @@ public class BSPrim : BSPhysObject
1164 { 1181 {
1165 return new BSActorHover(PhysScene, this, HoverActorName); 1182 return new BSActorHover(PhysScene, this, HoverActorName);
1166 }); 1183 });
1184
1185 // Call update so actor Refresh() is called to start things off
1186 PhysScene.TaintedObject(LocalID, "BSPrim.PIDHoverActive", delegate()
1187 {
1188 UpdatePhysicalParameters();
1189 });
1167 } 1190 }
1168 } 1191 }
1169 1192
@@ -1601,12 +1624,293 @@ public class BSPrim : BSPhysObject
1601 object ret = null; 1624 object ret = null;
1602 switch (pFunct) 1625 switch (pFunct)
1603 { 1626 {
1627 case ExtendedPhysics.PhysFunctAxisLockLimits:
1628 ret = SetAxisLockLimitsExtension(pParams);
1629 break;
1604 default: 1630 default:
1605 ret = base.Extension(pFunct, pParams); 1631 ret = base.Extension(pFunct, pParams);
1606 break; 1632 break;
1607 } 1633 }
1608 return ret; 1634 return ret;
1609 } 1635 }
1636
1637 private void InitializeAxisActor()
1638 {
1639 EnableActor(LockedAngularAxis != LockedAxisFree || LockedLinearAxis != LockedAxisFree,
1640 LockedAxisActorName, delegate()
1641 {
1642 return new BSActorLockAxis(PhysScene, this, LockedAxisActorName);
1643 });
1644
1645 // Update parameters so the new actor's Refresh() action is called at the right time.
1646 PhysScene.TaintedObject(LocalID, "BSPrim.LockAxis", delegate()
1647 {
1648 UpdatePhysicalParameters();
1649 });
1650 }
1651
1652 // Passed an array of an array of parameters, set the axis locking.
1653 // This expects an int (PHYS_AXIS_*) followed by none or two limit floats
1654 // followed by another int and floats, etc.
1655 private object SetAxisLockLimitsExtension(object[] pParams)
1656 {
1657 DetailLog("{0} SetAxisLockLimitsExtension. parmlen={1}", LocalID, pParams.GetLength(0));
1658 object ret = null;
1659 try
1660 {
1661 if (pParams.GetLength(0) > 1)
1662 {
1663 int index = 2;
1664 while (index < pParams.GetLength(0))
1665 {
1666 var funct = pParams[index];
1667 DetailLog("{0} SetAxisLockLimitsExtension. op={1}, index={2}", LocalID, funct, index);
1668 if (funct is Int32 || funct is Int64)
1669 {
1670 switch ((int)funct)
1671 {
1672 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR:
1673 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR, 0f, 0f);
1674 index += 1;
1675 break;
1676 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_X:
1677 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_X, 0f, 0f);
1678 index += 1;
1679 break;
1680 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_X:
1681 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_X, (float)pParams[index + 1], (float)pParams[index + 2]);
1682 index += 3;
1683 break;
1684 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Y:
1685 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Y, 0f, 0f);
1686 index += 1;
1687 break;
1688 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Y:
1689 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Y, (float)pParams[index + 1], (float)pParams[index + 2]);
1690 index += 3;
1691 break;
1692 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Z:
1693 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Z, 0f, 0f);
1694 index += 1;
1695 break;
1696 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Z:
1697 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Z, (float)pParams[index + 1], (float)pParams[index + 2]);
1698 index += 3;
1699 break;
1700 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR:
1701 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR, 0f, 0f);
1702 index += 1;
1703 break;
1704 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_X:
1705 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_X, 0f, 0f);
1706 index += 1;
1707 break;
1708 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_X:
1709 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_X, (float)pParams[index + 1], (float)pParams[index + 2]);
1710 index += 3;
1711 break;
1712 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Y:
1713 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Y, 0f, 0f);
1714 index += 1;
1715 break;
1716 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Y:
1717 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Y, (float)pParams[index + 1], (float)pParams[index + 2]);
1718 index += 3;
1719 break;
1720 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Z:
1721 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Z, 0f, 0f);
1722 index += 1;
1723 break;
1724 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Z:
1725 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Z, (float)pParams[index + 1], (float)pParams[index + 2]);
1726 index += 3;
1727 break;
1728 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR:
1729 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR, 0f, 0f);
1730 index += 1;
1731 break;
1732 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_X:
1733 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_X, 0f, 0f);
1734 index += 1;
1735 break;
1736 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Y:
1737 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Y, 0f, 0f);
1738 index += 1;
1739 break;
1740 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Z:
1741 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Z, 0f, 0f);
1742 index += 1;
1743 break;
1744 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR:
1745 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR, 0f, 0f);
1746 index += 1;
1747 break;
1748 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_X:
1749 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_X, 0f, 0f);
1750 index += 1;
1751 break;
1752 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Y:
1753 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Y, 0f, 0f);
1754 index += 1;
1755 break;
1756 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Z:
1757 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Z, 0f, 0f);
1758 index += 1;
1759 break;
1760 case ExtendedPhysics.PHYS_AXIS_UNLOCK:
1761 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK, 0f, 0f);
1762 index += 1;
1763 break;
1764 default:
1765 m_log.WarnFormat("{0} SetSxisLockLimitsExtension. Unknown op={1}", LogHeader, funct);
1766 index += 1;
1767 break;
1768 }
1769 }
1770 }
1771 InitializeAxisActor();
1772 ret = (object)index;
1773 }
1774 }
1775 catch (Exception e)
1776 {
1777 m_log.WarnFormat("{0} SetSxisLockLimitsExtension exception in object {1}: {2}", LogHeader, this.Name, e);
1778 ret = null;
1779 }
1780 return ret; // not implemented yet
1781 }
1782
1783 // Set the locking parameters.
1784 // If an axis is locked, the limits for the axis are set to zero,
1785 // If the axis is being constrained, the high and low value are passed and set.
1786 // When done here, LockedXXXAxis flags are set and LockedXXXAxixLow/High are set to the range.
1787 protected void ApplyAxisLimits(int funct, float low, float high)
1788 {
1789 DetailLog("{0} ApplyAxisLimits. op={1}, low={2}, high={3}", LocalID, funct, low, high);
1790 float linearMax = 23000f;
1791 float angularMax = (float)Math.PI;
1792
1793 switch ((int)funct)
1794 {
1795 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR:
1796 this.LockedLinearAxis = new OMV.Vector3(LockedAxis, LockedAxis, LockedAxis);
1797 this.LockedLinearAxisLow = OMV.Vector3.Zero;
1798 this.LockedLinearAxisHigh = OMV.Vector3.Zero;
1799 break;
1800 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_X:
1801 this.LockedLinearAxis.X = LockedAxis;
1802 this.LockedLinearAxisLow.X = 0f;
1803 this.LockedLinearAxisHigh.X = 0f;
1804 break;
1805 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_X:
1806 this.LockedLinearAxis.X = LockedAxis;
1807 this.LockedLinearAxisLow.X = Util.Clip(low, -linearMax, linearMax);
1808 this.LockedLinearAxisHigh.X = Util.Clip(high, -linearMax, linearMax);
1809 break;
1810 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Y:
1811 this.LockedLinearAxis.Y = LockedAxis;
1812 this.LockedLinearAxisLow.Y = 0f;
1813 this.LockedLinearAxisHigh.Y = 0f;
1814 break;
1815 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Y:
1816 this.LockedLinearAxis.Y = LockedAxis;
1817 this.LockedLinearAxisLow.Y = Util.Clip(low, -linearMax, linearMax);
1818 this.LockedLinearAxisHigh.Y = Util.Clip(high, -linearMax, linearMax);
1819 break;
1820 case ExtendedPhysics.PHYS_AXIS_LOCK_LINEAR_Z:
1821 this.LockedLinearAxis.Z = LockedAxis;
1822 this.LockedLinearAxisLow.Z = 0f;
1823 this.LockedLinearAxisHigh.Z = 0f;
1824 break;
1825 case ExtendedPhysics.PHYS_AXIS_LIMIT_LINEAR_Z:
1826 this.LockedLinearAxis.Z = LockedAxis;
1827 this.LockedLinearAxisLow.Z = Util.Clip(low, -linearMax, linearMax);
1828 this.LockedLinearAxisHigh.Z = Util.Clip(high, -linearMax, linearMax);
1829 break;
1830 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR:
1831 this.LockedAngularAxis = new OMV.Vector3(LockedAxis, LockedAxis, LockedAxis);
1832 this.LockedAngularAxisLow = OMV.Vector3.Zero;
1833 this.LockedAngularAxisHigh = OMV.Vector3.Zero;
1834 break;
1835 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_X:
1836 this.LockedAngularAxis.X = LockedAxis;
1837 this.LockedAngularAxisLow.X = 0;
1838 this.LockedAngularAxisHigh.X = 0;
1839 break;
1840 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_X:
1841 this.LockedAngularAxis.X = LockedAxis;
1842 this.LockedAngularAxisLow.X = Util.Clip(low, -angularMax, angularMax);
1843 this.LockedAngularAxisHigh.X = Util.Clip(high, -angularMax, angularMax);
1844 break;
1845 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Y:
1846 this.LockedAngularAxis.Y = LockedAxis;
1847 this.LockedAngularAxisLow.Y = 0;
1848 this.LockedAngularAxisHigh.Y = 0;
1849 break;
1850 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Y:
1851 this.LockedAngularAxis.Y = LockedAxis;
1852 this.LockedAngularAxisLow.Y = Util.Clip(low, -angularMax, angularMax);
1853 this.LockedAngularAxisHigh.Y = Util.Clip(high, -angularMax, angularMax);
1854 break;
1855 case ExtendedPhysics.PHYS_AXIS_LOCK_ANGULAR_Z:
1856 this.LockedAngularAxis.Z = LockedAxis;
1857 this.LockedAngularAxisLow.Z = 0;
1858 this.LockedAngularAxisHigh.Z = 0;
1859 break;
1860 case ExtendedPhysics.PHYS_AXIS_LIMIT_ANGULAR_Z:
1861 this.LockedAngularAxis.Z = LockedAxis;
1862 this.LockedAngularAxisLow.Z = Util.Clip(low, -angularMax, angularMax);
1863 this.LockedAngularAxisHigh.Z = Util.Clip(high, -angularMax, angularMax);
1864 break;
1865 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR:
1866 this.LockedLinearAxis = LockedAxisFree;
1867 this.LockedLinearAxisLow = new OMV.Vector3(-linearMax, -linearMax, -linearMax);
1868 this.LockedLinearAxisHigh = new OMV.Vector3(linearMax, linearMax, linearMax);
1869 break;
1870 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_X:
1871 this.LockedLinearAxis.X = FreeAxis;
1872 this.LockedLinearAxisLow.X = -linearMax;
1873 this.LockedLinearAxisHigh.X = linearMax;
1874 break;
1875 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Y:
1876 this.LockedLinearAxis.Y = FreeAxis;
1877 this.LockedLinearAxisLow.Y = -linearMax;
1878 this.LockedLinearAxisHigh.Y = linearMax;
1879 break;
1880 case ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR_Z:
1881 this.LockedLinearAxis.Z = FreeAxis;
1882 this.LockedLinearAxisLow.Z = -linearMax;
1883 this.LockedLinearAxisHigh.Z = linearMax;
1884 break;
1885 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR:
1886 this.LockedAngularAxis = LockedAxisFree;
1887 this.LockedAngularAxisLow = new OMV.Vector3(-angularMax, -angularMax, -angularMax);
1888 this.LockedAngularAxisHigh = new OMV.Vector3(angularMax, angularMax, angularMax);
1889 break;
1890 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_X:
1891 this.LockedAngularAxis.X = FreeAxis;
1892 this.LockedAngularAxisLow.X = -angularMax;
1893 this.LockedAngularAxisHigh.X = angularMax;
1894 break;
1895 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Y:
1896 this.LockedAngularAxis.Y = FreeAxis;
1897 this.LockedAngularAxisLow.Y = -angularMax;
1898 this.LockedAngularAxisHigh.Y = angularMax;
1899 break;
1900 case ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR_Z:
1901 this.LockedAngularAxis.Z = FreeAxis;
1902 this.LockedAngularAxisLow.Z = -angularMax;
1903 this.LockedAngularAxisHigh.Z = angularMax;
1904 break;
1905 case ExtendedPhysics.PHYS_AXIS_UNLOCK:
1906 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_LINEAR, 0f, 0f);
1907 ApplyAxisLimits(ExtendedPhysics.PHYS_AXIS_UNLOCK_ANGULAR, 0f, 0f);
1908 break;
1909 default:
1910 break;
1911 }
1912 return;
1913 }
1610 #endregion // Extension 1914 #endregion // Extension
1611 1915
1612 // The physics engine says that properties have updated. Update same and inform 1916 // The physics engine says that properties have updated. Update same and inform