Difference between revisions of "Category:Physics Engine/Bodies"
| Line 1: | Line 1: | ||
| − | A body holds the physical properties (mass, position, rotation, velocity, etc.) of an object. | + | A body holds the physical properties (mass, position, rotation, velocity, etc.) of an object. It does not have a [[#Shape|shape]] until you attach one (or more) to it. |
| + | Its type is TI.cpBody. | ||
| + | |||
| + | |||
| + | ===== Body ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | body = physics.Body(mass, inertia) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | mass | ||
| + | | '''in''' number | ||
| + | | Mass of the body | ||
| + | |- | ||
| + | | inertia | ||
| + | | '''in''' number | ||
| + | | The inertia of the body | ||
| + | |- | ||
| + | | body | ||
| + | | '''out''' physics.Body | ||
| + | | A new Body with the supplied mass and inertia | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns a new Body with the given mass and moment of inertia. | ||
| + | |||
| + | Use the [[#inertia|provided helper functions]] to compute the moment of inertia. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== activate ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:activate() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Activates a sleeping body. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of this routine. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== angle ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | angle = physics.Body:angle() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | angle | ||
| + | | '''out''' number | ||
| + | | The angle of the Body in radians | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the angle in radians of the orientation of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== angVel ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | avel = physics.Body:angVel() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | avel | ||
| + | | '''out''' number | ||
| + | | The angular velocity of the Body in radians per unit time | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the angular velocity of the body in radians per unit time. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== applyForce ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:applyForce(forceVect, rOffset) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | forceVect | ||
| + | | '''in''' physics.Vect | ||
| + | | A force vector | ||
| + | |- | ||
| + | | rOffset | ||
| + | | '''in''' physics.Vect | ||
| + | | Vector offset of the force relative to the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Apply force [[#vector|vector]] on ''self'' at a relative offset from the center of gravity. | ||
| + | |||
| + | Introducted in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== applyImpulse ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:applyImpulse(impulseVect, rOffset) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | impulseVect | ||
| + | | '''in''' physics.Vect | ||
| + | | Impulse force on the Body | ||
| + | |- | ||
| + | | rOffset | ||
| + | | '''in''' physics.Vect | ||
| + | | Vector offset of the force relative to the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Apply the impulse [[#vector|vector]] to ''self'' at a relative offset from the center of gravity. | ||
| + | |||
| + | Introducted in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== data ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | obj = physics.Body:data() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | obj | ||
| + | | '''out''' Lua object | ||
| + | | An object previously set on the Body by the programmer | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the contents of the programmer data field of the Body. | ||
| + | |||
| + | Introducted in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== force ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | fvec = physics.Body:force() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | fvec | ||
| + | | '''out''' physics.Vect | ||
| + | | The force vector on the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the force [[#vector|vector]] on the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== isRogue ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | bool = physics.Body:isRogue() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | bool | ||
| + | | '''out''' boolean | ||
| + | | True if the Body is a rogue Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns true if the Body is a rogue Body, never having been added to the simulation [[#Space|Space]]. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of rogue bodies. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== isSleeping ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | bool = physics.Body:isSleeping() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | bool | ||
| + | | '''out''' boolean | ||
| + | | True if the Body is sleeping | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns true if the body is sleeping. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of sleeping bodies. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== local2World ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | wvec = physics.Body:local2World(lvec) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | lvec | ||
| + | | '''in''' physics.Vect | ||
| + | | A vector relative to the position of the Body | ||
| + | |- | ||
| + | | wvec | ||
| + | | '''out''' physics.Vect | ||
| + | | A vector in world coordinates | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Converts ''lvec'' from body-relative coordinates to world coordinates. Returns the converted [[#vector|vector]]. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== kineticEnergy ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | ke = physics.Body:kineticEnergy() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | ke | ||
| + | | '''out''' number | ||
| + | | The total kinetic energy of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the kinetic energy of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== mass ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | m = physics.Body:mass() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | m | ||
| + | | '''out''' number | ||
| + | | The mass of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the mass of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== moment ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | m = physics.Body:moment() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | m | ||
| + | | '''out''' number | ||
| + | | The moment of inertia of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the moment of inertia of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== pos ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | p = physics.Body:pos() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | p | ||
| + | | '''out''' physics.Vect | ||
| + | | The position of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the [[#vector|vector]] position of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== resetForces ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:resetForces() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Zero both the force and torque accumulated on ''self''. | ||
| + | |||
| + | Introducted in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== rot ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | rvec = physics.Body:rot() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | rvec | ||
| + | | '''out''' physics.Vect | ||
| + | | The unit vector orientation of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the [[#vector|vector]] orientation of the body. This is a unit vector cached from the last calculated angle of the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setAngle ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setAngle(angle) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | angle | ||
| + | | '''in''' number | ||
| + | | The angle of rotation in radians of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the angle of rotation in radians of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setAngVel ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setAngVel(vel) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vel | ||
| + | | '''in''' number | ||
| + | | The angular velocity in radians per unit time of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the angular velocity of the body. The angular velocity is in radians per unit time. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setData ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setData(value) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | value | ||
| + | | '''in''' object | ||
| + | | A programmer-supplied Lua object | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Sets the programmer data field of the Body. The programmer can store any Lua object in this field. This is a handy place to store a reference to a simulation object. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setForce ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setForce(vector) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vector | ||
| + | | '''in''' physics.Vect | ||
| + | | The vector of force on the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the force [[#vector|vector]] on the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setMass ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setMass(mass) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | mass | ||
| + | | '''in''' number | ||
| + | | The mass of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the mass of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setMoment ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setMoment(moment) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | moment | ||
| + | | '''in''' number | ||
| + | | The moment of inertia of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the moment of inertia of the body. | ||
| + | |||
| + | Use the [[#inertia|provided helper functions]] to compute the moment of inertia. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setPos ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setPos(vector) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vector | ||
| + | | '''in''' physics.Vect | ||
| + | | The position of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the position of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setPositionFunc ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setPositionFunc(func) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | func | ||
| + | | '''in''' function(body, dt) | ||
| + | | A callback function that updates the position of the Body on each time step | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Sets the position function of the body. The position function must be a function that accepts a Body and a time step value and at some point calls body:updatePosition to update the position of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#ddffdd;" | ||
| + | |- | ||
| + | | <span style="color:#00AA00">'''TIP''':</span> '''Example'''<hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | -- TODO This is a lame example | ||
| + | |||
| + | function samplePositionFunc(body, dt) | ||
| + | -- What goes here? | ||
| + | body:updatePosition(dt) | ||
| + | end | ||
| + | |||
| + | body:setPositionFunc(samplePositionFunc) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setTorque ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setTorque(torque) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | torque | ||
| + | | '''in''' number | ||
| + | | The torque of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the torque on the body. Torque is a numeric magnitude. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setVel ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setVel(vector) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vector | ||
| + | | '''in''' physics.Vect | ||
| + | | The velocity vector of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the velocity of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setVelocityFunc ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setVelocityFunc(func) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | func | ||
| + | | '''in''' function(body, grav, damping, dt) | ||
| + | | A callback function that updates the velocity of the Body on each time step | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity [[#vector|vector]], a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#ddffdd;" | ||
| + | |- | ||
| + | | <span style="color:#00AA00">'''TIP''':</span> '''Example'''<hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | function sampleVelocityFunc(body, gravity, damping, dt) | ||
| + | local pos = body:pos() | ||
| + | local sqdist = pos:lengthsq() | ||
| + | local g = pos:mult(-GravityStrength / (sqdist * math.sqrt(sqdist))) | ||
| + | body:updateVelocity(g, damping, dt) | ||
| + | end | ||
| + | |||
| + | body:setVelocityFunc(sampleVelocityFunc) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setVLimit ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setVLimit(limit) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | limit | ||
| + | | '''in''' number | ||
| + | | The maximum speed of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Sets the limit for the maximum speed of the body. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== setWLimit ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:setWLimit(limit) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | limit | ||
| + | | '''in''' number | ||
| + | | The maximum angular velocity of the Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the limit of the angular velocity of the body. Angular velocity is in radians per unit time. | ||
| + | |||
| + | Returns the Body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== sleep ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:sleep() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Puts the body to sleep. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of sleeping bodies. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#FFFFCE;" | ||
| + | |- | ||
| + | | <span style="color:#AAAA00">'''NOTE''':</span> '''NOTES'''<hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | The body must be added to a [[#Space|Space]] before it can be put to sleep. | ||
| + | |||
| + | Calling this function within a query or callback is not allowed. | ||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== sleepWithGroup ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | self = physics.Body:sleepWithGroup( [group] ) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | group | ||
| + | | '''in''' physics.Body | ||
| + | | A sleeping body. If this parameter is not supplied, a new group is created | ||
| + | |- | ||
| + | | self | ||
| + | | '''out''' physics.Body | ||
| + | | The input Body is returned as the output | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Puts the Body to sleep and adds it to a group of other sleeping bodies. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of this routine. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#FFFFCE;" | ||
| + | |- | ||
| + | | <span style="color:#AAAA00">'''NOTE''':</span> '''NOTE'''<hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | The body must be added to a [[#Space|Space]] before it can be put to sleep. | ||
| + | |||
| + | Calling this function within a query or callback is not allowed. | ||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | This routine will raise an exception if ''group'' is not sleeping. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== torque ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | t = physics.Body:torque() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | torque | ||
| + | | '''out''' number | ||
| + | | The torque on the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the torque on the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== updatePosition ===== | ||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | physics.Body:updatePosition(dt) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | dt | ||
| + | | '''in''' number | ||
| + | | The time interval in seconds | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the position of the body using Euler integration. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of this routine. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== updateVelocity ===== | ||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | physics.Body:updateVelocity(grav, damp, dt) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | grav | ||
| + | | '''in''' physics.Vect | ||
| + | | The force of gravity | ||
| + | |- | ||
| + | | damp | ||
| + | | '''in''' physics.Vect | ||
| + | | The damping factor | ||
| + | |- | ||
| + | | dt | ||
| + | | '''in''' physics.Vect | ||
| + | | The time interval in seconds | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Updates the velocity of the body using Euler integration. | ||
| + | {| width="100%" style="padding: 20px; margin-left:20px; border:solid; border-color:#aaa; border-width:0px; text-align:left; background-color:#D8E4F1;" | ||
| + | |- | ||
| + | | <span style="color:#0000AA">'''INFO'''</span><hr> | ||
| + | |- | ||
| + | |||
| + | <div style="white-space: pre"> | ||
| + | |||
| + | See [[http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/]] for an explanation of this routine. | ||
| + | |||
| + | </div> | ||
| + | |} | ||
| + | <br/> | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== vel ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | vvel = physics.Body:vel() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vvel | ||
| + | | '''out''' physics.Vect | ||
| + | | The velocity of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the [[#vector|vector]] velocity of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== vLimit ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | vmax = physics.Body:vLimit() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | vmax | ||
| + | | '''out''' number | ||
| + | | The maximum speed of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the speed limit of the body. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== wLimit ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | wmax = physics.Body:wLimit() | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | wmax | ||
| + | | '''out''' number | ||
| + | | The maximum angular velocity of the Body in radians per unit time | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Returns the angular velocity limit of the body. The angular velocity is in radians per unit time. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
| + | ---- | ||
| + | ===== world2Local ===== | ||
| + | |||
| + | |||
| + | <!-- code start--> | ||
| + | <pre style="margin-left:20px; font-size:1.4em; background-color:#fdfdfd"> | ||
| + | lvec = physics.Body:world2Local(wvec) | ||
| + | </pre><!-- code end--> | ||
| + | |||
| + | |||
| + | <!-- table start --> | ||
| + | {| border=1 width="100%" cellspacing="0" cellpadding="4" style="border-color:#eee" class="wikitable" | ||
| + | <!-- header row start --> | ||
| + | ! Parameter !! Type !! Description | ||
| + | <!-- header row end --> | ||
| + | |- | ||
| + | | self | ||
| + | | '''in''' physics.Body | ||
| + | | The input Body | ||
| + | |- | ||
| + | | wvec | ||
| + | | '''in''' physics.Vect | ||
| + | | A vector in world coordinates | ||
| + | |- | ||
| + | | lvec | ||
| + | | '''out''' physics.Vect | ||
| + | | A vector relative to the position of the Body | ||
| + | |}<!-- table end --> | ||
| + | |||
| + | <br/> | ||
| + | Converts ''wvec'' from world coordinates to body-relative coordinates. Returns the converted [[#vector|vector]]. | ||
| + | |||
| + | Introduced in platform.apiLevel = '2.0' | ||
| + | |||
[[Category:Physics_Engine]] | [[Category:Physics_Engine]] | ||
Revision as of 08:42, 18 July 2012
A body holds the physical properties (mass, position, rotation, velocity, etc.) of an object. It does not have a shape until you attach one (or more) to it. Its type is TI.cpBody.
Contents
- 1 Body
- 2 activate
- 3 angle
- 4 angVel
- 5 applyForce
- 6 applyImpulse
- 7 data
- 8 force
- 9 isRogue
- 10 isSleeping
- 11 local2World
- 12 kineticEnergy
- 13 mass
- 14 moment
- 15 pos
- 16 resetForces
- 17 rot
- 18 setAngle
- 19 setAngVel
- 20 setData
- 21 setForce
- 22 setMass
- 23 setMoment
- 24 setPos
- 25 setPositionFunc
- 26 setTorque
- 27 setVel
- 28 setVelocityFunc
- 29 setVLimit
- 30 setWLimit
- 31 sleep
- 32 sleepWithGroup
- 33 torque
- 34 updatePosition
- 35 updateVelocity
- 36 vel
- 37 vLimit
- 38 wLimit
- 39 world2Local
Body
body = physics.Body(mass, inertia)
| Parameter | Type | Description |
|---|---|---|
| mass | in number | Mass of the body |
| inertia | in number | The inertia of the body |
| body | out physics.Body | A new Body with the supplied mass and inertia |
Returns a new Body with the given mass and moment of inertia.
Use the provided helper functions to compute the moment of inertia.
Introduced in platform.apiLevel = '2.0'
activate
self = physics.Body:activate()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| self | out physics.Body | The input Body is returned as the output |
Activates a sleeping body.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
| INFO |
Introduced in platform.apiLevel = '2.0'
angle
angle = physics.Body:angle()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| angle | out number | The angle of the Body in radians |
Returns the angle in radians of the orientation of the body.
Introduced in platform.apiLevel = '2.0'
angVel
avel = physics.Body:angVel()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| avel | out number | The angular velocity of the Body in radians per unit time |
Returns the angular velocity of the body in radians per unit time.
Introduced in platform.apiLevel = '2.0'
applyForce
self = physics.Body:applyForce(forceVect, rOffset)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| forceVect | in physics.Vect | A force vector |
| rOffset | in physics.Vect | Vector offset of the force relative to the Body |
| self | out physics.Body | The input Body is returned as the output |
Apply force vector on self at a relative offset from the center of gravity.
Introducted in platform.apiLevel = '2.0'
applyImpulse
self = physics.Body:applyImpulse(impulseVect, rOffset)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| impulseVect | in physics.Vect | Impulse force on the Body |
| rOffset | in physics.Vect | Vector offset of the force relative to the Body |
| self | out physics.Body | The input Body is returned as the output |
Apply the impulse vector to self at a relative offset from the center of gravity.
Introducted in platform.apiLevel = '2.0'
data
obj = physics.Body:data()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| obj | out Lua object | An object previously set on the Body by the programmer |
Returns the contents of the programmer data field of the Body.
Introducted in platform.apiLevel = '2.0'
force
fvec = physics.Body:force()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| fvec | out physics.Vect | The force vector on the Body |
Returns the force vector on the body.
Introduced in platform.apiLevel = '2.0'
isRogue
bool = physics.Body:isRogue()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| bool | out boolean | True if the Body is a rogue Body |
Returns true if the Body is a rogue Body, never having been added to the simulation Space.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of rogue bodies.
| INFO |
Introduced in platform.apiLevel = '2.0'
isSleeping
bool = physics.Body:isSleeping()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| bool | out boolean | True if the Body is sleeping |
Returns true if the body is sleeping.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of sleeping bodies.
| INFO |
Introduced in platform.apiLevel = '2.0'
local2World
wvec = physics.Body:local2World(lvec)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| lvec | in physics.Vect | A vector relative to the position of the Body |
| wvec | out physics.Vect | A vector in world coordinates |
Converts lvec from body-relative coordinates to world coordinates. Returns the converted vector.
Introduced in platform.apiLevel = '2.0'
kineticEnergy
ke = physics.Body:kineticEnergy()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| ke | out number | The total kinetic energy of the Body |
Returns the kinetic energy of the body.
Introduced in platform.apiLevel = '2.0'
mass
m = physics.Body:mass()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| m | out number | The mass of the Body |
Returns the mass of the body.
Introduced in platform.apiLevel = '2.0'
moment
m = physics.Body:moment()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| m | out number | The moment of inertia of the Body |
Returns the moment of inertia of the body.
Introduced in platform.apiLevel = '2.0'
pos
p = physics.Body:pos()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| p | out physics.Vect | The position of the Body |
Returns the vector position of the body.
Introduced in platform.apiLevel = '2.0'
resetForces
self = physics.Body:resetForces()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| self | out physics.Body | The input Body is returned as the output |
Zero both the force and torque accumulated on self.
Introducted in platform.apiLevel = '2.0'
rot
rvec = physics.Body:rot()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| rvec | out physics.Vect | The unit vector orientation of the Body |
Returns the vector orientation of the body. This is a unit vector cached from the last calculated angle of the Body.
Introduced in platform.apiLevel = '2.0'
setAngle
self = physics.Body:setAngle(angle)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| angle | in number | The angle of rotation in radians of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the angle of rotation in radians of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setAngVel
self = physics.Body:setAngVel(vel)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vel | in number | The angular velocity in radians per unit time of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the angular velocity of the body. The angular velocity is in radians per unit time.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setData
self = physics.Body:setData(value)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| value | in object | A programmer-supplied Lua object |
| self | out physics.Body | The input Body is returned as the output |
Sets the programmer data field of the Body. The programmer can store any Lua object in this field. This is a handy place to store a reference to a simulation object.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setForce
self = physics.Body:setForce(vector)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vector | in physics.Vect | The vector of force on the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the force vector on the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setMass
self = physics.Body:setMass(mass)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| mass | in number | The mass of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the mass of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setMoment
self = physics.Body:setMoment(moment)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| moment | in number | The moment of inertia of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the moment of inertia of the body.
Use the provided helper functions to compute the moment of inertia.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setPos
self = physics.Body:setPos(vector)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vector | in physics.Vect | The position of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the position of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setPositionFunc
self = physics.Body:setPositionFunc(func)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| func | in function(body, dt) | A callback function that updates the position of the Body on each time step |
| self | out physics.Body | The input Body is returned as the output |
Sets the position function of the body. The position function must be a function that accepts a Body and a time step value and at some point calls body:updatePosition to update the position of the body.
Returns the Body.
-- TODO This is a lame example function samplePositionFunc(body, dt) -- What goes here? body:updatePosition(dt) end body:setPositionFunc(samplePositionFunc)
| TIP: Example |
Introduced in platform.apiLevel = '2.0'
setTorque
self = physics.Body:setTorque(torque)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| torque | in number | The torque of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the torque on the body. Torque is a numeric magnitude.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setVel
self = physics.Body:setVel(vector)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vector | in physics.Vect | The velocity vector of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the velocity of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setVelocityFunc
self = physics.Body:setVelocityFunc(func)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| func | in function(body, grav, damping, dt) | A callback function that updates the velocity of the Body on each time step |
| self | out physics.Body | The input Body is returned as the output |
Sets the velocity function of the body. The velocity function must be a function that accepts a Body, a gravity vector, a numeric damping factor, and a time step value. The function should call body:updateVelocity to adjust the velocity of the body.
Returns the Body.
function sampleVelocityFunc(body, gravity, damping, dt) local pos = body:pos() local sqdist = pos:lengthsq() local g = pos:mult(-GravityStrength / (sqdist * math.sqrt(sqdist))) body:updateVelocity(g, damping, dt) end body:setVelocityFunc(sampleVelocityFunc)
| TIP: Example |
Introduced in platform.apiLevel = '2.0'
setVLimit
self = physics.Body:setVLimit(limit)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| limit | in number | The maximum speed of the Body |
| self | out physics.Body | The input Body is returned as the output |
Sets the limit for the maximum speed of the body.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
setWLimit
self = physics.Body:setWLimit(limit)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| limit | in number | The maximum angular velocity of the Body |
| self | out physics.Body | The input Body is returned as the output |
Updates the limit of the angular velocity of the body. Angular velocity is in radians per unit time.
Returns the Body.
Introduced in platform.apiLevel = '2.0'
sleep
self = physics.Body:sleep()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| self | out physics.Body | The input Body is returned as the output |
Puts the body to sleep.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of sleeping bodies.
| INFO |
The body must be added to a Space before it can be put to sleep.
Calling this function within a query or callback is not allowed.
| NOTE: NOTES |
Introduced in platform.apiLevel = '2.0'
sleepWithGroup
self = physics.Body:sleepWithGroup( [group] )
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| group | in physics.Body | A sleeping body. If this parameter is not supplied, a new group is created |
| self | out physics.Body | The input Body is returned as the output |
Puts the Body to sleep and adds it to a group of other sleeping bodies.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
| INFO |
The body must be added to a Space before it can be put to sleep.
Calling this function within a query or callback is not allowed.
| NOTE: NOTE |
This routine will raise an exception if group is not sleeping.
Introduced in platform.apiLevel = '2.0'
torque
t = physics.Body:torque()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| torque | out number | The torque on the Body |
Returns the torque on the body.
Introduced in platform.apiLevel = '2.0'
updatePosition
physics.Body:updatePosition(dt)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| dt | in number | The time interval in seconds |
Updates the position of the body using Euler integration.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
| INFO |
Introduced in platform.apiLevel = '2.0'
updateVelocity
physics.Body:updateVelocity(grav, damp, dt)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| grav | in physics.Vect | The force of gravity |
| damp | in physics.Vect | The damping factor |
| dt | in physics.Vect | The time interval in seconds |
Updates the velocity of the body using Euler integration.
See [http://files.slembcke.net/chipmunk/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/] for an explanation of this routine.
| INFO |
Introduced in platform.apiLevel = '2.0'
vel
vvel = physics.Body:vel()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vvel | out physics.Vect | The velocity of the Body |
Returns the vector velocity of the body.
Introduced in platform.apiLevel = '2.0'
vLimit
vmax = physics.Body:vLimit()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| vmax | out number | The maximum speed of the Body |
Returns the speed limit of the body.
Introduced in platform.apiLevel = '2.0'
wLimit
wmax = physics.Body:wLimit()
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| wmax | out number | The maximum angular velocity of the Body in radians per unit time |
Returns the angular velocity limit of the body. The angular velocity is in radians per unit time.
Introduced in platform.apiLevel = '2.0'
world2Local
lvec = physics.Body:world2Local(wvec)
| Parameter | Type | Description |
|---|---|---|
| self | in physics.Body | The input Body |
| wvec | in physics.Vect | A vector in world coordinates |
| lvec | out physics.Vect | A vector relative to the position of the Body |
Converts wvec from world coordinates to body-relative coordinates. Returns the converted vector.
Introduced in platform.apiLevel = '2.0'
This category currently contains no pages or media.