Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Convex Hulls - volume/mass calculation?

Author
Message
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2017 11:29
I hope the 3D physics engine gets a working debug option soon, as it would have solved a problem for me straight away, which was that I hadn't got the object's origin at the centre of mass, so it behaved very strangely.

Talking of convex hulls, I would like to be able to obtain the volume of a convex hull shape to help set an appropriate relative mass of an object / sub object. It doesn't appear that the shape is accessible for this?

janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 22nd Mar 2017 11:58
If I understand you right, you may want to look into CalculateSpritePhysicsCOM()

Also if you don't need the actual volume of the sprite and you don't change the mass after the creation of the physics body, the mass of it does have a direct relation to the volume
So instead of going this way of calculation the mass, you could just set the mass relative to the mass before changing it, maybe ?

Using AGKv2 Tier1
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Mar 2017 12:50 Edited at: 22nd Mar 2017 12:55
I haven't dealt with 3D in agk, but can you pull a list of verts? Here's my thought. Each poly would form the base of a triangular pyramid, where the pyramid's apex is at the center of your object (and all other pyramids' apex is at the same point). Calculate the volume for each pyramid; which is the area of the polygon (triangular surface on your convex hull) time's 1/3 the height of the pyramid (distance from the surface of the poly to that inner apex point).
V = 1/3(AH)

Something like:


This is just rough pseudo-code. Don't even know if my theory would work.

Distance from point to a plane



I thought he wanted 3D, not sprites?


If he's after 3D, I did just find this (after coming up with my own idea):


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 22nd Mar 2017 15:14
Quote: "Talking of convex hulls, I would like to be able to obtain the volume of a convex hull shape to help set an appropriate relative mass of an object / sub object. It doesn't appear that the shape is accessible for this?"


Here is a link to the C++ code used by the Bullet physics engine to calculate the volume of a convex hull and also compute the center of mass.
You would need to convert to AGK.

http://melax.github.io/volint.html

I am not sure why you need to do this. Are you making a compound object?
The coffee is lovely dark and deep,and I have code to write before I sleep.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2017 22:42
No, I'm disassembling sub objects which were auto generated by AppGameKit during loadObjectWithChildren()
In this case they are cubic, so I could just count the cubes and assign a mass to each section based on the number of cubes, but it got me thinking about how to assign mass to abstract objects based on their convex hull size, as it seems to be logical in a 3D physics environment.

If the shapes were available as accessible geometry, then this would be a starting point.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 23rd Mar 2017 00:13
Oh, I just realised that you asked for 3D Physics

Using AGKv2 Tier1

Login to post a reply

Server time is: 2024-11-24 18:35:07
Your offset time is: 2024-11-24 18:35:07