Jump to content
Leadwerks Community

Recommended Posts

Posted

Sets the damping value of a physics body. Damping slows the velocity and omega each frame by a small amount.

Example:

window = Window:Create("Linear Damping Example",0,0,800,600,Window.Titlebar+Window.Center)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:SetPosition(0,10,-6)
camera:SetRotation(45,0,0)
light = DirectionalLight:Create()
light:SetRotation(35,35,0)

ground = Model:Box(50,1,50)
ground:SetPosition(0,-0.5,0)
ground:SetColor(0,1,0)
shape = Shape:Box(0,0,0, 0,0,0, 50,1,50)
ground:SetShape(shape)
shape:Release()

box = {}
for i = 1, 3 do 
	box[i] = Model:Box()
	box[i]:SetColor(1-0.5*(i-1),-0.5*(i-1),.5) 
	shape = Shape:ConvexHull(box[i]:GetSurface(0))
	box[i]:SetShape(shape)
	box[i]:SetPosition(-8+i*4,1,0)
	box[i]:SetMass(1)
	box[i]:SetDamping(1-0.5*(i-1),1.0)
end
	
while window:KeyHit(Key.Escape)==false do
	if window:Closed() then break end
	
	if window:KeyHit(Key.Space) then
		for i = 1, 3 do 
			box[i]:AddForce(0,0,1000,true)
		end
	end

	Time:Update()
	world:Update()
	world:Render()
	
	context:SetBlendMode(Blend.Alpha)
	context:DrawText("Linear Damping (from left to right): 1, 0.5, 0",2,2)
	context:DrawText("Press SPACE to apply the same force to all boxes!",2,22)
	context:DrawText("The higher the damping-value, the faster the box stops.",2,42)
	context:SetBlendMode(Blend.Solid)
	context:Sync(true)

end

 

LinearDamping.jpg

  • Thanks 1
  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...