Hinge

This function creates a new hinge joint.

Syntax

Parameters

Example

angle=45

window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-4)

local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

parent = Model:Box()
parent:SetColor(0.0,0.0,1.0)

child = Model:Box()
child:SetColor(1.0,0.0,0.0)
child:SetShape(Shape:Box())
child:SetMass(1)
child:SetPosition(2,0,0)

joint = Joint:Hinge(0,0,0, 0,0,1, child, parent)
joint:EnableLimits()
joint:SetLimits(-45,45)
joint:EnableMotor()

while true do
if window:Closed() or window:KeyDown(Key.Escape) then return false end

if window:KeyDown(Key.Up) then angle=angle+1.0 end
if window:KeyDown(Key.Down) then angle=angle-1.0 end
joint:SetAngle(angle)

if window:KeyHit(Key.Space) then
if joint:MotorEnabled()==false then
joint:EnableMotor()
else
joint:DisableMotor()
end
end

Time:Update()
world:Update()
world:Render()

context:SetBlendMode(Blend.Alpha)
context:DrawText("Target angle: "..angle,0,0)
context:DrawText("Current angle: "..joint:GetAngle(),0,20)
if joint:MotorEnabled() then
context:DrawText("Motor enabled: 1",0,40)
else
context:DrawText("Motor enabled: 0",0,40)
end
context:SetBlendMode(Blend.Solid)

context:Sync()
end