generated mass is the same as density passed in

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

generated mass is the same as density passed in

Post by zell2002 »

is this correct ?
how does box2d calculate mass?

here is my world :

Code: Select all

	Meter = 64
	love.physics.setMeter(Meter)
	--World = love.physics.newWorld(0, 0, true)
	World = love.physics.newWorld(0, 9.81 * Meter, true)
so a meter is 64px for me

then i create a shape :

Code: Select all

Width = Meter/2
Height = Meter * 2
local shape = love.physics.newRectangleShape(Width, Height)
local fixture = love.physics.newFixture(myBody, shape, Density)	
i calculate density as :
d = mass / volume
so i did this :

Code: Select all

Density = 60 / (Width * Height) * Meter -- (to scale back up?)
I created a rectangle to roughly represent an average human, so 2 meter in height, half meter in width, and weighting roughly 60kg

so i run this, it builds my rectangle guy, and Density prints at : 0.9375
but when I check the mass of my newly created shape, it returns : 0.9375 using myBody:getMass()
but using : shape:computerMass(Density) returns "60"

Code: Select all

print("compute mass : ", shape:computeMass(Density))
print("getMass : ", myBody:getMass())
output :
compute mass : 60
getMass : 0, 0, 0.9385, 1360 (x,y, mass, inertia)
am i missing something here? shouldnt the mass of the body reflect the computeMass() or does box2d not actually calculate this ?
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: generated mass is the same as density passed in

Post by Azhukar »

I ran your code and it prints 0.9375 in both cases.

Code: Select all

function love.load()
	Meter = 64
	love.physics.setMeter(Meter)
	World = love.physics.newWorld(0, 9.81 * Meter, true)
	Width = Meter/2
	Height = Meter * 2
	Density = 60 / (Width * Height) * Meter -- (to scale back up?) 
	local myBody = love.physics.newBody(World,0,0,"dynamic")
	local shape = love.physics.newRectangleShape(Width, Height)
	local fixture = love.physics.newFixture(myBody, shape, Density)  
	print("compute mass : ", shape:computeMass(Density))
	print("getMass : ",myBody:getMass())
end

Code: Select all

compute mass :  0       0       0.9375  1360
getMass :       0.9375
I thought about it some more and realized your human is 1 square meter, meaning if you want him to weigh 60 kilos you have to set density to 60.
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: generated mass is the same as density passed in

Post by zell2002 »

ah, i think i misread the computemass() output before as it is behaving the same for me now

but yeah, if you print Density it is also 0.9375
which isn't correct

when i change it to :
Width = Meter * 2
Height = Meter * 2
Density = 1

the outputs are :
Density : 1
Mass : 4

*edit, just seen your extra response
weight isnt the same density though...?
zell2002
Citizen
Posts: 75
Joined: Sun Feb 23, 2014 9:22 pm

Re: generated mass is the same as density passed in

Post by zell2002 »

ah i see what you mean
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: generated mass is the same as density passed in

Post by s-ol »

Well, a 2x0.5m human has an area (or "2d volume") of 1, so density has the same value as mass in this case (60kg and 60kg / sqm).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 214 guests