Difference between revisions of "R3d.Body:createFixture"

From GiderosMobile
 
Line 5: Line 5:
 
Creates a new fixture.
 
Creates a new fixture.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
(fixture) = r3d.Body:createFixture(shape,transform,mass)
+
(fixture) = r3d.Body:createFixture(shape[,transform,mass])
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
 
'''shape''': (r3d.Shape) the r3d shape of the fixture (one of '''[[R3d.Shape]]''')<br/>
 
'''shape''': (r3d.Shape) the r3d shape of the fixture (one of '''[[R3d.Shape]]''')<br/>
'''transform''': (matrix) the initial position and orientation of the fixture relative to the body<br/>
+
'''transform''': (matrix) the initial position and orientation of the fixture relative to the body, '''optional default = 0,0,0'''<br/>
'''mass''': (number) the mass of the fixture<br/>
+
'''mass''': (number) the mass of the fixture, '''optional default = 1 kg'''<br/>
  
 
=== Example ===
 
=== Example ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local shipobj = loadObj("3d/ship", "ship.obj")
+
-- mesh
shipobj.shape1 = r3d.SphereShape.new(8)
+
local mesh = D3.Cube.new(params.sizex, params.sizey, params.sizez, Sprite.CULL_NONE)
local shipvp = Viewport.new()
+
mesh:setCullMode(params.cullmode)
shipvp:setContent(shipobj)
+
mesh:mapTexture(params.tex, params.texw, params.texh)
shipvp:setPosition(0, shipheight * 8, 0) -- ship start position
+
mesh:updateMode( D3.Mesh.MODE_LIGHTING | D3.Mesh.MODE_SHADOW )
shipvp.body = world:createBody(shipvp:getMatrix())
+
-- put it in a viewport so we can matrix it
local m1 = Matrix.new()
+
local viewport = Viewport.new()
m1:setPosition(0, 0, -6) -- position shape1 in front of the ship
+
viewport:setContent(mesh)
local fixture = shipvp.body:createFixture(shipobj.shape1, m1, 100) -- shape, transform, mass
+
-- 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
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
{{R3d.Body}}
 
{{R3d.Body}}

Latest revision as of 08:51, 18 December 2025

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