B2.GearJoint: Difference between revisions
From GiderosMobile
No edit summary |
No edit summary |
||
| Line 6: | Line 6: | ||
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 /> | ||
<br /> | <br /> | ||
=== Examples === | |||
'''Gear joint combining revolute and prismatic joints'''<br/> | |||
<source lang="lua">--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)</source> | |||
{|- | {|- | ||
| style="width: 50%;"| | | style="width: 50%;"| | ||
Revision as of 09:44, 23 August 2018
Supported platforms: android, ios, mac, pc
Available since: Gideros 2011.6
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)
Methodsb2.GearJoint:getRatio - returns the gear ratio |
EventsConstants |