Slider

static Joint* Slider(float posx, float posy, float posz, float pinx, float piny, float pinz, Entity* child, Entity* parent=NULL)

Syntax

Parameters

Returns

Returns a new joint.

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:SetGravityMode(true)
child:SetRotation(0,0,15)
child:Move(2,0,0)

joint = Joint:Slider(0,0,0, Math:Cos(15.0),Math:Sin(15.0),0, child, parent)
joint:EnableLimits()
joint:SetLimits(-5,1)
joint:EnableMotor()

jointpos=1

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

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

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 position: "..jointpos,0,0)
context:DrawText("Current position: "..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