R3d.Body:createFixture

From GiderosMobile
Revision as of 08:51, 18 December 2025 by MoKaLux (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Available since: Gideros 2019.10
Class: R3d.Body

Description

Creates a new fixture.

(fixture) = r3d.Body:createFixture(shape[,transform,mass])

Parameters

shape: (r3d.Shape) the r3d shape of the fixture (one of R3d.Shape)
transform: (matrix) the initial position and orientation of the fixture relative to the body, optional default = 0,0,0
mass: (number) the mass of the fixture, optional default = 1 kg

Example

-- mesh
local mesh = D3.Cube.new(params.sizex, params.sizey, params.sizez, Sprite.CULL_NONE)
mesh:setCullMode(params.cullmode)
mesh:mapTexture(params.tex, params.texw, params.texh)
mesh:updateMode( D3.Mesh.MODE_LIGHTING | D3.Mesh.MODE_SHADOW )
-- put it in a viewport so we can matrix it
local viewport = Viewport.new()
viewport:setContent(mesh)
-- transform
local matrix = viewport:getMatrix()
matrix:setPosition(params.posx, params.posy, params.posz)
matrix:setRotationX(params.rotx)
matrix:setRotationY(params.roty)
matrix:setRotationZ(params.rotz)
viewport:setMatrix(matrix)
-- r3d body
viewport.body = world:createBody(matrix)
viewport.body:setType(params.type)
viewport.body.id = "cube"
local shape = r3d.BoxShape.new(params.sizex, params.sizey, params.sizez)
local transform = Matrix.new()
transform:setY(-params.sizey/2)
transform:setRotation(params.rotx)
transform:setRotationY(params.roty)
transform:setRotationZ(params.rotz)
local fixture = viewport.body:createFixture(shape, transform, 1) -- shape, transform, mass