Simple buoyancy.

scratchyrice

26-03-2009 23:07:05

How would i go about getting simple buoyancy to work? I understand that to get the force required to keep an object buoyant, I need to times the fluid density, But the displacement volume, By the gravitational acceleration. However, Obviously simply using Actor::AddForce with the result of that equation does not work. How do i calculate drag etc etc, So it does not pop out of the water/Bounce of the water surface. Ive spent 8 non stop hours trying to get even the simplest of buoyant effects working, But i just cant. I always get the same result, The object hits the water, Slows down, And shoot's flying back out. I cant get it to calmly rise to the water surface. Any help will be much appreciated.

Cheers

Scratchy

betajaen

26-03-2009 23:57:44

I had a little go at it when I learned about fluids at University the other month. What about a second trigger above the water line to cancel out the momentum?

And I had some good results with this, perhaps it will help with you.

// Calculate anti-gravity, reverse the linear velocity and then make it slowly rise upwards.
float y = (9.81f * actor->getMass()) // counteract gravity
+ (-actor->getLinearVelocity().y * actor->getMass()) // counteract vertical velocity
+ ((10.0f - actor->getGlobalPosition().y) * actor->getMass()); // Add some force to move it to the top

// Add the force.
actor->addForce(Real3(0, y, 0), Enums::ForceMode_Force, true);

scratchyrice

27-03-2009 17:45:08

Thanks dude. After working on it for about 2 hours, Using your code as a base, Ive got some very convincing buoyancy working. Your code alone would have worked, however, Im using hydrax, And so the wave height is always changing, So i had to add quite alot for it to look realistic.

Thanks a lot anyway

Cheers

Scratchy

betajaen

27-03-2009 18:20:25

I'm glad to help. Any chance you can post a copy for us mortals?

scratchyrice

27-03-2009 21:20:00

Sure. I will just neat'n up the code.

Cheers

Scratchy

scratchyrice

28-03-2009 17:42:56

Here, I made a new post. I hope its useful.
http://www.ogre3d.org/addonforums/viewtopic.php?f=6&t=9639

Cheers

Scratchy

scratchyrice

29-03-2009 16:06:56

Ok, I have a simple math question. In the equation F = 0.5 C ρA V2 , What does ρA mean? Im trying to calculate the drag force's in water. I understand the equation apart from ρA. I was thinking maybe i just multiplied ρ + A together, But i tried that, And it produces an insane force, Which simply cannot be right. So what does a little symbol, Infront of a large variable letter mean in mathematics?

Cheers

Scratchy

nargil

29-03-2009 16:15:31

ρ (is readed rho) - means density

scratchyrice

29-03-2009 16:42:33

ρ (is readed rho) - means density
It said that on the page i got the equation from, But I'm simply not sure about how to convert it to programming code. Is it rho * A? Or rho/A? Maybe rho^A. I do wish mathematicians, Would make it clearer. I mean is it really so hard to put an extra x or * between vars? lol - Just a thought. I tried the equation using rho*A, And that cannot be right, As the object's spring off the water asif its a trampoline.

Cheers

Scratchy

nargil

29-03-2009 16:48:18

*

scratchyrice

29-03-2009 16:50:30

Ah ok cheers. As i said, That does not seem to work still.
Am i even arranging the equation correctly? This is how i have it in my code:
_force = 0.5 * coefficent * shapearea * (actorVelocityY^2);

Am i missing ('s? Im not too good at converting mathematical equation's to code, As you can no doubt tell.

Cheers

Scratchy

betajaen

29-03-2009 17:00:35

Where you getting your equations from?

I can't remember dealing with coefficients with buoyancy, I thought it was simpler than that.

[Edit]

Looking at drag forces on the internet. "V" is volume, not velocity.

scratchyrice

29-03-2009 17:04:08

Well the trouble is, That if i apply the real "scientificly correct" equation of:
_forcey = _currentSubmergedVolume * (waterDensity * -_myPhysicsSystem->getGravity().y);

I also require the "scientificly correct" equation of fluid drag, Which is here http://en.wikipedia.org/wiki/Drag_equation#cite_note-1

Im super close to simply using the method that me and you created, Which you saw on the video, But adding some sort of fake density calculation, For partly submerged actors etc. But its annoying the hell out of me, That it would seem that science itself is wrong.

Cheers

Scratchy

betajaen

29-03-2009 17:12:21

I think your using the wrong equations here. If you want bouyancy with based on lower density objects to rise and higher ones to fall then, calculating the bouyancy force should be enough;

float bouyancyForceY = densityFluid * volumeSubmerged * 9.81f;

See; http://hyperphysics.phy-astr.gsu.edu/Hb ... y5.html#c1

scratchyrice

29-03-2009 17:43:29

Thanks, But the equation i was already using _forcey = _currentSubmergedVolume * (1000 * -_myPhysicsSystem->getGravity().y), Is exactly the same thing. And as i said, If i only use that code, The objects rocket out of the water, And i assume its because of no drag calculations. Here is the code im using for the force
_currentSubmergedVolume = (-_distanceFromWave) / _currentActor->getBoundingBoxAverage();
if (_currentSubmergedVolume > 1)
_currentSubmergedVolume = 1;
_forcey = 1000 * _currentSubmergedVolume * -_myPhysicsSystem->getGravity().y;
_currentActor->_getPhysXActor()->addForce(Ogre::Vector3(0, _forcey, 0) , NxForceMode::NX_FORCE, true);


Using that, The objects seem to jump out of the water. It all looks genuine, Until that happens, And the illusion of buoyancy is completely broken. I can create a quick video on youtube of the problem, If this helps. Yes the submerged volume calculation, Is a bit primitive, But it should work for any fairly even shapes. Also its nice and fast.

Cheers

Scratchy

scratchyrice

29-03-2009 17:45:55

BTW, Im using 98.10 as my gravity setting, As i have to scale everything to 1cm = 1unit, Due to hydrax's weird scaleing. I did set the gravity down to 9.81, But it does the exact same thing, only in "slow motion"

Cheers

Scratchy

nargil

29-03-2009 17:59:21

I'm confused. The gravity is ~9.8 m/s^2 for earth. If 1 unit = 1 cm, then your gravity should be 980 units, not 98, shouldn't it ?
You should also consider to scale the volume: since it's x*y*z and each of those dimensions is 100 times larger you need to scale it by 0.01*0.01*0.01.

BTW: I use hydrax with a metric system. Needs some tweaking, but I think it's better than worrying about the physics all the time in a non-metric system.

betajaen

29-03-2009 18:10:24

If your working in cm's then, you should multiply everything by a 100.

The easiest way is like has been said is to work in seconds-kilograms-metres, but have a "super parent node" that is scaled by a factor of 0.01

scratchyrice

29-03-2009 18:55:47

then your gravity should be 980 units
My bad, It is set to 980, or -980.

Sounds like i need to convert to a metre system.

I use hydrax with a metric system. Needs some tweaking, but I think it's better than worrying about the physics all the time in a non-metric system.
This is slightly confusing. I thought cm's, Were a unit of the metric system?

Anyway, I will convert to 1 metre = 1 unit, But before i start the conversion process. Could one of you confirm that the best scale, Is 1 metre per ogre unit?

Cheers

Scratchy

betajaen

29-03-2009 19:11:08

Centimetres are fractions of metres, but they aren't a "whole" unit.

NxOgre uses the metre-second-kilogram system; where 1 Ogre unit is 1 metre. I've been using it and encouraging others to use since day one, and have had no problems.

nargil

29-03-2009 19:29:13

thought cm's, Were a unit of the metric system? ;) You know what I meant.

scratchyrice

19-04-2009 18:17:41

Ok i have now converted my engine to use 1m per unit, But i still get the same result with the buoyancy. It goes into the water, And shoots out, just like before. I think it must be the lack of fluid drag. Imagine you dropped an object into an empty space, But it did the same as it does in water, Minus the drag of the liquid, The object would shoot out as it has nothing whatsoever working against it (other than the relatively weak force of gravity.). Its the same reason object flying through air (also a fluid), has a terminal velocity, Only the drag force is alot lot less in air due to its very low density. As a test, I have a 1mx1mx1m box, With a mass of 500KG's (So half of the same volume of water, So will buoy), With this i get the "shooting" effect.

Cheers

Scratchy

betajaen

19-04-2009 19:07:16

What if you increase the linear damping of the body whilst it's in the water, that would simulate drag, and reduce the shooting out effect. Perhaps you could also reduce fair chunk of the velocity of body when it hits the water as well.

scratchyrice

20-04-2009 17:33:44

Thanks, With a bit of work, That seems to work quite well. Im almost there, But im having problems with fixed joints. For some reason "setGlobalAnchor" does not seem to work. No matter what value i put in, The anchor is always in the centre of the parent object (test boat), But i need to move the anchor outwards to the sides of the boat.

Any help much appreciated.

Cheers

Scratchy