ExtendedPhysics

From OpenSimulator

Jump to: navigation, search

Contents

ExtendedPhysics

ExtendedPhysics is an OpenSimulator module that adds LSL functions and constants that provide physics engine extension functions.

The module is designed so to work with any physics engine but, at the moment, only BulletSim implements these functions. These functions can be called when using any physics engine but nothing will change.

The OpenSimulator default configuration has ExtendedPhysics disabled. To enable ExtendedPhysics, add the following to any of the configuration INI files:

    [ExtendedPhysics]
    Enabled = true

Informational Functions

This request returns the type of the physics engine. This function returns the same as osGetPhysicsEngineType which is a string identifying the type of the physics engine.

The BulletSim physics engine returns the string "BulletSim".

The function osGetPhysicsEngineName returns a string that has additional information than just the type. For instance, version numbers or types of accelerators being used.

    string physType = physGetEngineType();
    string morePhysType = osGetPhysicsEngineName();
    llOwnerSay(0, "Physics engine type = " + physType);
    llOwnerSay(0, "Physics engine type again = " + morePhysType);

Disable Deactivation Function

Disable physics deactivation on the containing physical object.

The Bullet physics engine saves CPU cycles by only checking "active" physical objects. Physical objects start out active and are deactivated when their linear or angular velocity falls below some threshold. For instance, if a scene has 100 physical balls that are dropped and roll around, the physics engine has to test each of the 100 balls multiple times a second to compute their movement. As some of the balls slow down and stop moving, the balls are stopped and "deactivated" and thus the physics engine doesn't need to check the stopped physical object any more.

Physical objects are re-activated when another physical object bumps into them but otherwise, they stay still.

This deactivation is usually a great CPU saver but there are cases where it causes objects with small movements or movements that are effected by non-physical objects. A ball on a tilting surface, for instance.

This function disables deactivation -- setting "true" means the object will never be deactivated.

    physDisableDeactivation(TRUE);

Axis Lock Functions

These requests effect the movement of a physical object around its various axis.

The effect of these requests is to create a constraint on one or more of the axis of the physics object.

The constraints are given as a list of parameters. Some of the functions take no parameters and some take two. Multiple constraints can be set in one request and they are processed from left to right.

For instance, the following request constrains a physical object to only move along its local Z axis with no rotation:

    physAxisLock(PHYS_AXIS_LOCK_ANGULAR, PHYS_AXIS_LOCK_LINEAR_Y, PHYS_AXIS_LOCK_LINEAR_X);

There are code that clear all of the settings -- PHYS_AXIS_UNLOCK unlocks all the linear and angular constraints, for instance.

Code Description
PHYS_AXIS_LOCK_LINEAR Lock all linear motion. No parameters.
PHYS_AXIS_LOCK_LINEAR_X Lock all linear motion along the local X axis. No parameters.
PHYS_AXIS_LIMIT_LINEAR_X Limit linear motion along the local X axis. Two parameters giving low and high relative X position.
PHYS_AXIS_LOCK_LINEAR_Y Lock all linear motion along the local Y axis. No parameters.
PHYS_AXIS_LIMIT_LINEAR_Y Limit linear motion along the local Y axis. Two parameters giving low and high relative Y position.
PHYS_AXIS_LOCK_LINEAR_Z Lock all linear motion along the local Z axis. No parameters.
PHYS_AXIS_LIMIT_LINEAR_Z Limit linear motion along the local Y axis. Two parameters giving low and high relative Z position.
PHYS_AXIS_LOCK_ANGULAR Lock all angular motion. No parameters.
PHYS_AXIS_LOCK_ANGULAR_X Lock all angular motion around the local X axis. No parameters.
PHYS_AXIS_LIMIT_ANGULAR_X Limit angular motion around the local X axis. Two parameters giving low and high values in radians.
PHYS_AXIS_LOCK_ANGULAR_Y Lock all angular motion around the local Y axis. No parameters.
PHYS_AXIS_LIMIT_ANGULAR_Y Limit angular motion around the local Y axis. Two parameters giving low and high values in radians.
PHYS_AXIS_LOCK_ANGULAR_Z Lock all angular motion around the local Z axis. No parameters.
PHYS_AXIS_LIMIT_ANGULAR_Z Limit angular motion around the local Z axis. Two parameters giving low and high values in radians.
PHYS_AXIS_UNLOCK_LINEAR Unlock all linear motion constraints
PHYS_AXIS_UNLOCK_LINEAR_X Unlock any linear motion constraint on the X axis
PHYS_AXIS_UNLOCK_LINEAR_Y Unlock any linear motion constraint on the Y axis
PHYS_AXIS_UNLOCK_LINEAR_Z Unlock any linear motion constraint on the Z axis
PHYS_AXIS_UNLOCK_ANGULAR Unlock all angular motion constraints
PHYS_AXIS_UNLOCK_ANGULAR_X Unlock any angular motion constraints around the X axis
PHYS_AXIS_UNLOCK_ANGULAR_Y Unlock any angular motion constraints around the Y axis
PHYS_AXIS_UNLOCK_ANGULAR_Z Unlock any angular motion constraints around the Z axis
PHYS_AXIS_UNLOCK Unlock all linear and angular constraints

For instance, constraining movement along the X axis, not allowing any movement on the Z axis, and limiting rotation around the Y axis would be accomplished with:

    physLockAxis(PHYS_AXIS_LIMIT_LINEAR_X, 0, 5.5, PHYS_AXIS_LOCK_LINEAR_Z, PHYS_LIMIT_ANGULAR_Y, -0.785, 0.785);

Linkset Manipulation Functions

        PHYS_LINKSET_TYPE_CONSTRAINT  = 0;
        PHYS_LINKSET_TYPE_COMPOUND    = 1;
        PHYS_LINKSET_TYPE_MANUAL      = 2;

        public int physSetLinksetType(int linksetType)

        int lsType = physGetLinksetType();

        PHYS_LINK_TYPE_FIXED  = 1234;
        PHYS_LINK_TYPE_HINGE  = 4;
        PHYS_LINK_TYPE_SPRING = 9;
        PHYS_LINK_TYPE_6DOF   = 6;
        PHYS_LINK_TYPE_SLIDER = 7;

        physChangeLinkType(int linkNum, int lType)

        physGetLinkType(int linkNum)

        physChangeLinkFixed(int linkNum)

        PHYS_PARAM_FRAMEINA_LOC           = 14401;
        PHYS_PARAM_FRAMEINA_ROT           = 14402;
        PHYS_PARAM_FRAMEINB_LOC           = 14403;
        PHYS_PARAM_FRAMEINB_ROT           = 14404;
        PHYS_PARAM_LINEAR_LIMIT_LOW       = 14405;
        PHYS_PARAM_LINEAR_LIMIT_HIGH      = 14406;
        PHYS_PARAM_ANGULAR_LIMIT_LOW      = 14407;
        PHYS_PARAM_ANGULAR_LIMIT_HIGH     = 14408;
        PHYS_PARAM_USE_FRAME_OFFSET       = 14409;
        PHYS_PARAM_ENABLE_TRANSMOTOR      = 14410;
        PHYS_PARAM_TRANSMOTOR_MAXVEL      = 14411;
        PHYS_PARAM_TRANSMOTOR_MAXFORCE    = 14412;
        PHYS_PARAM_CFM                    = 14413;
        PHYS_PARAM_ERP                    = 14414;
        PHYS_PARAM_SOLVER_ITERATIONS      = 14415;
        PHYS_PARAM_SPRING_AXIS_ENABLE     = 14416;
        PHYS_PARAM_SPRING_DAMPING         = 14417;
        PHYS_PARAM_SPRING_STIFFNESS       = 14418;
        PHYS_PARAM_LINK_TYPE              = 14419;
        PHYS_PARAM_USE_LINEAR_FRAMEA      = 14420;
        PHYS_PARAM_SPRING_EQUILIBRIUM_POINT = 14421;

        PHYS_AXIS_ALL = -1;
        PHYS_AXIS_LINEAR_ALL = -2;
        PHYS_AXIS_ANGULAR_ALL = -3;
        PHYS_AXIS_LINEAR_X  = 0;
        PHYS_AXIS_LINEAR_Y  = 1;
        PHYS_AXIS_LINEAR_Z  = 2;
        PHYS_AXIS_ANGULAR_X = 3;
        PHYS_AXIS_ANGULAR_Y = 4;
        PHYS_AXIS_ANGULAR_Z = 5;

        physChangeLinkParams(params ....)
Personal tools
General
About This Wiki