GetEntityXForm

From OxeyeWiki

Jump to: navigation, search

physics:getEntityXForm(entityId)

Fetches the 2D matrix that defines the entity's current position and rotation in world space.

Parameter Expected Type Description
enitityId An integer The entity's body identifier.
Returns

Returns six values. First the centerX and centerY, which is the entity's current center position in world space (measured in meters). Then four values that build up the rotation matrix: x1, y1, x2, y2.

You can use these six values to determine any point on the shape. For example, say that you have x and y, which are points relative to the entity's centrum position. To calculate where x and y are right now, you do:

local formX, formY, formCX1, formCY1, formCX2, formCY2 = physics:getEntityXForm(player.body)
local newX = formCX1 * x + formCX2 * y
local newY = formCY1 * x + formCY2 * y

x, y = newX + formX, newY + formY
Daisymoon Physics Lib


Example


   local formX, formY, formCX1, formCY1, formCX2, formCY2 = physics:getEntityXForm(player.body)
   local newX = formCX1 * x + formCX2 * y
   local newY = formCY1 * x + formCY2 * y

   x, y = newX + formX, newY + formY
   video.renderSpriteState(player.sprite, x / physResolution, y / physResolution)

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox