Difference between revisions of "B2.GearJoint"

From GiderosMobile
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<!-- GIDEROSOBJ:b2.GearJoint -->
 
<!-- GIDEROSOBJ:b2.GearJoint -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/b2.Joint|b2.Joint]]<br/>
+
'''Inherits from:''' [[b2.Joint]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
A gear joint is used to connect two joints together. Either joint can be a revolute or prismatic joint. You specify a gear ratio to bind the motions together: coordinate1  ratio * coordinate2 = constant The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.<br />
+
A gear joint is used to connect two joints together. Either joint can be a revolute or prismatic joint. You specify a gear ratio to bind the motions together: coordinate1  ratio * coordinate2 = constant The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.
<br /></translate>
+
 
=== <translate>Examples</translate> ===
+
=== Examples ===
'''Gear joint combining revolute and prismatic joints'''<br/>
+
'''Gear joint combining revolute and prismatic joints'''
<source lang="lua">--create empty box2d body for joint
+
<syntaxhighlight lang="lua">
 +
--create empty box2d body for joint
 
local ground = world:createBody({})
 
local ground = world:createBody({})
  
Line 21: Line 22:
 
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 28: Line 29:
 
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>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/b2.GearJoint:getRatio|b2.GearJoint:getRatio]] ''<translate>returns the gear ratio</translate>''<br/><!-- GIDEROSMTD:b2.GearJoint:getRatio -->
+
[[b2.GearJoint:getRatio]] ''returns the gear ratio''<br/><!--GIDEROSMTD:b2.GearJoint:getRatio() returns the gear ratio-->
[[Special:MyLanguage/b2.GearJoint:setRatio|b2.GearJoint:setRatio]] ''<translate>sets the gear ratio</translate>''<br/><!-- GIDEROSMTD:b2.GearJoint:setRatio -->
+
[[b2.GearJoint:setRatio]] ''sets the gear ratio''<br/><!--GIDEROSMTD:b2.GearJoint:setRatio(ratio) sets the gear ratio-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
 +
 +
----
 +
*'''[[B2.Joint]]'''
 +
*'''[[LiquidFun]]'''

Latest revision as of 02:55, 1 December 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: b2.Joint

Description

A gear joint is used to connect two joints together. Either joint can be a revolute or prismatic joint. You specify a gear ratio to bind the motions together: coordinate1 ratio * coordinate2 = constant The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length.

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)

Methods

b2.GearJoint:getRatio returns the gear ratio
b2.GearJoint:setRatio sets the gear ratio

Events

Constants