Difference between revisions of "B2.createGearJointDef"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<languages />
 
<languages />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2|b2]]<br/>
+
'''Class:''' [[Special:MyLanguage/b2|b2]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Creates and returns a gear joint definition table.<br />
+
Creates and returns a gear joint definition table.
(Please refer to [[b2.World:createJoint]] function for more information about all the information needed to create a gear joint).<br />
+
 
<br /></translate>
+
(Please refer to [[b2.World:createJoint]] function for more information about all the information needed to create a gear joint).
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(table) = b2.createGearJointDef(bodyA,bodyB,joint1,joint2,ratio)
 
(table) = b2.createGearJointDef(bodyA,bodyB,joint1,joint2,ratio)
</source>
+
</syntaxhighlight>
=== <translate>Parameters</translate> ===
+
 
'''bodyA''': (b2.Body) <translate>the first attached body</translate> <br/>
+
=== Parameters ===
'''bodyB''': (b2.Body) <translate>the second attached body</translate> <br/>
+
'''bodyA''': (b2.Body) the first attached body <br/>
'''joint1''': (b2.Joint) <translate>the first revolute/prismatic joint attached to the gear joint</translate> <br/>
+
'''bodyB''': (b2.Body) the second attached body <br/>
'''joint2''': (b2.Joint) <translate>the second revolute/prismatic joint attached to the gear joint</translate> <br/>
+
'''joint1''': (b2.Joint) the first revolute/prismatic joint attached to the gear joint <br/>
'''ratio''': (number, default = 1) <translate>the gear ratio</translate> <br/>
+
'''joint2''': (b2.Joint) the second revolute/prismatic joint attached to the gear joint <br/>
=== <translate>Return values</translate> ===
+
'''ratio''': (number, default = 1) the gear ratio <br/>
'''<translate>Returns</translate>''' (table) <translate>A new gear joint definition table</translate><br/>
+
 
=== <translate>Examples</translate> ===
+
=== Return values ===
'''Gear joint combining revolute and prismatic joints'''<br/>
+
'''Returns''' (table) A new gear joint definition table<br/>
<source lang="lua">--create empty box2d body for joint
+
 
 +
=== Examples ===
 +
'''Gear joint combining revolute and prismatic joints'''
 +
<syntaxhighlight lang="lua">
 +
--create empty box2d body for joint
 
local ground = world:createBody({})
 
local ground = world:createBody({})
  
Line 32: Line 36:
 
revoluteJoint:enableMotor(true)
 
revoluteJoint:enableMotor(true)
  
--axisx, axisy values usually between 0 and 1
+
--axisx, axisy values usually between 0 and 1
 
--note that ground should be passed as first parameter here
 
--note that ground should be passed as first parameter here
 
local jointDef = b2.createPrismaticJointDef(ground, body2, 350, 100, 0.3, 1)
 
local jointDef = b2.createPrismaticJointDef(ground, body2, 350, 100, 0.3, 1)
Line 39: Line 43:
 
prismaticJoint:setMaxMotorForce(1)
 
prismaticJoint:setMaxMotorForce(1)
 
prismaticJoint:enableMotor(true)
 
prismaticJoint:enableMotor(true)
 
  
 
--create gear joint using two already created joints
 
--create gear joint using two already created joints
 
local jointDef = b2.createGearJointDef(body1, body2, revoluteJoint, prismaticJoint, 1)
 
local jointDef = b2.createGearJointDef(body1, body2, revoluteJoint, prismaticJoint, 1)
local gearJoint = world:createJoint(jointDef)</source>
+
local gearJoint = world:createJoint(jointDef)
 +
</syntaxhighlight>
 +
 
 +
{{B2}}

Latest revision as of 14:27, 13 July 2023


Available since: Gideros 2011.6
Class: b2

Description

Creates and returns a gear joint definition table.

(Please refer to b2.World:createJoint function for more information about all the information needed to create a gear joint).

(table) = b2.createGearJointDef(bodyA,bodyB,joint1,joint2,ratio)

Parameters

bodyA: (b2.Body) the first attached body
bodyB: (b2.Body) the second attached body
joint1: (b2.Joint) the first revolute/prismatic joint attached to the gear joint
joint2: (b2.Joint) the second revolute/prismatic joint attached to the gear joint
ratio: (number, default = 1) the gear ratio

Return values

Returns (table) A new gear joint definition table

Examples

Gear joint combining revolute and prismatic joints

--create empty box2d body for joint
local ground = world:createBody({})

--create revolute joint
--note that ground should be passed as first parameter here
local jointDef = b2.createRevoluteJointDef(ground, body1, 300, 300)
local revoluteJoint = world:createJoint(jointDef)
--set motor
revoluteJoint:setMaxMotorTorque(1)
revoluteJoint:enableMotor(true)

--axisx, axisy values usually between 0 and 1
--note that ground should be passed as first parameter here
local jointDef = b2.createPrismaticJointDef(ground, body2, 350, 100, 0.3, 1)
local prismaticJoint = world:createJoint(jointDef)
--set motor
prismaticJoint:setMaxMotorForce(1)
prismaticJoint:enableMotor(true)

--create gear joint using two already created joints
local jointDef = b2.createGearJointDef(body1, body2, revoluteJoint, prismaticJoint, 1)
local gearJoint = world:createJoint(jointDef)





LiquidFun