Difference between revisions of "LlGetCenterOfMass"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func=llGetCenterOfMass
|sort=GetCenterOfMass
|func_id=183|func_sleep=0.0|func_energy=10.0
|func_id=183|func_sleep=0.0|func_energy=10.0
|func=llGetCenterOfMass|return_type=vector
|return_type=vector
|func_footnote
|func_desc
|func_desc
|return_text=that is the prim's global center of mass
|Return_text=position of the object's center of mass in [[Viewer coordinate frames#Region|region coordinates]].
|spec
|func_footnote=If called from a child prim, the child's center of mass is returned instead (but still in region coordinates).
|caveats
|spec=
The Center Of Mass for a prim is only computed when an object is physical. When a value is computed it is cached as a prim attribute. If the object is non-physical and there is a cached value, that is the value returned, otherwise [[llGetPos]]() is returned (this value is not cached).
|caveats=* Works in '''physical objects only'''.
** The value is stored as a prim property and will only change when Center Of Mass is computed.
** If called from within a non-physical object it will return the stored {{HoverText|COM|Center Of Mass}} value or in the absence of a stored COM value it will return [[llGetPos]]().
*** It will not compute or recompute the COM if the object is non-physical.
*** The stored value can only be updated when the object is physical. Neither moving or changing the objects shape will update, invalidate or remove the stored COM value when it is non-physical.
|constants
|constants
|examples
|examples=
<source lang="lsl2">
//  this example script will not check for physical status
//  you'll usually need it though to get a correct vector
 
default
{
    state_entry()
    {
        vector massCenter = llGetCenterOfMass();
        integer link = llGetLinkNumber();
 
        if (link == 0 || link == 1) llSay(PUBLIC_CHANNEL,
            "The center of the mass of the object is " + (string)massCenter);
 
        else if (1 < link) llSay(PUBLIC_CHANNEL,
            "The center of the mass of link no. " + (string)link + " is " + (string)massCenter);
 
        //  this script was just a test, remove it again
        string thisScript = llGetScriptName();
        llRemoveInventory(thisScript);
    }
}
</source>
|helpers
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetPos]]|}}
{{LSL DefineRow||[[llGetGeometricCenter]]|}}
{{LSL DefineRow||[[llGetGeometricCenter]]|}}
|also_events
|also_events
Line 19: Line 50:
|negative_index
|negative_index
|cat1=Physics
|cat1=Physics
|cat2
|cat2=Prim
|cat3
|cat3=Object
|cat4
|cat4
}}
}}

Latest revision as of 00:44, 22 January 2015

Summary

Function: vector llGetCenterOfMass( );
0.0 Forced Delay
10.0 Energy

Returns the vector position of the object's center of mass in region coordinates.

If called from a child prim, the child's center of mass is returned instead (but still in region coordinates).

Specification

The Center Of Mass for a prim is only computed when an object is physical. When a value is computed it is cached as a prim attribute. If the object is non-physical and there is a cached value, that is the value returned, otherwise llGetPos() is returned (this value is not cached).

Caveats

  • Works in physical objects only.
    • The value is stored as a prim property and will only change when Center Of Mass is computed.
    • If called from within a non-physical object it will return the stored COM value or in the absence of a stored COM value it will return llGetPos().
      • It will not compute or recompute the COM if the object is non-physical.
      • The stored value can only be updated when the object is physical. Neither moving or changing the objects shape will update, invalidate or remove the stored COM value when it is non-physical.

Examples

//  this example script will not check for physical status
//  you'll usually need it though to get a correct vector

default
{
    state_entry()
    {
        vector massCenter = llGetCenterOfMass();
        integer link = llGetLinkNumber();

        if (link == 0 || link == 1) llSay(PUBLIC_CHANNEL,
            "The center of the mass of the object is " + (string)massCenter);

        else if (1 < link) llSay(PUBLIC_CHANNEL,
            "The center of the mass of link no. " + (string)link + " is " + (string)massCenter);

        //  this script was just a test, remove it again
        string thisScript = llGetScriptName();
        llRemoveInventory(thisScript);
    }
}

See Also

Functions

•  llGetPos
•  llGetGeometricCenter

Deep Notes

Signature

function vector llGetCenterOfMass();