Jump to content

  • Log In with Google      Sign In   
  • Create Account


h4tt3n

Member Since 02 Apr 2008
Offline Last Active Yesterday, 03:14 PM
*****

#5144448 Separating axis Theorem rotation issue

Posted by h4tt3n on 04 April 2014 - 03:30 PM

Hi Aardvajk. I don't actually calculate the distance, since it is not needed. If you want the distance, you need to solve the Pythagorean theorem, which means calling square root. It's getting late here in Europe so I won't go into a lengthy explanation on SAT, but here are some links you might find useful:

 

http://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf

 
Cheers,
Mike



#5144278 Separating axis Theorem rotation issue

Posted by h4tt3n on 04 April 2014 - 01:23 AM

@nicky95

 

It's hard to tell exactly what goes wrong without seeing any code.

 

@CJThomas

 

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"

 

Cheers,

Mike




#5123321 Jittering due to gravity and restitution

Posted by h4tt3n on 13 January 2014 - 11:52 AM

The damping you mention seems wrong. It should always apply force along some axis (along the constraint or normal to intersection), not just remove a fraction of all movement per game loop.

 

The folowing equation will compute the exact force to make your object align with the floor and come to rest in one step:

 

correction force = - ( object mass / timestep^2 ) * overlap distance along axis * coefficient - ( object mass / timestep ) * velocity along axis * coefficient

 

If you are dealing with impulses or velocities then the equation should be:

 

Correction impulse = - ( object mass / timestep ) * overlap distance along axis * coefficient - velocity along axis * coefficient

 

The coefficient is just a number between 0 and 1 determining how soft / rigid you want it to behave. Setting the coefficients to 1 will do the job in 1 loop, but may also introduce instability if there are several objects interacting at one time. Setting them between 0.5 and 0.05 should work just fine.

 

Cheers,

Mike




#5118623 Alchemy System, what would make alchemy fun?

Posted by h4tt3n on 21 December 2013 - 02:57 PM

Make it procedural. In ohter words, don't make a number of pre-defined recipies, but instead let the properties of the potion emerge from some pre-defined laws. THis way, not even the game designer himself knows what might happen in every case. This is essentially what makes physics-based games so rewarding, and why they have such a high degree of re-playability. So instead of pre-coding a limited number of recipies, you need to pre-code a limited number of laws or rules from which an infinite number of recipies will emerge.

 

Cheers,

Mike




#5066519 physics force problem

Posted by h4tt3n on 31 May 2013 - 02:51 PM

Hello Lomateron,

 

I've been working on the exact same problem, but I haven't solved it entirely yet. I've attached a small windows .exe + full source for a small program that propagates forces trough a chain of interconnected particles. It displays far more rigid behaviour than any iterative solver I know of. My method of doing this is very similar to yours, it seems :-)

The only problem is that it's position based, and does not take velocity and acceleration into consideration. Still working on that...

 

Cheers,

Mike

Attached Files




#5012122 billiard/pool balls

Posted by h4tt3n on 18 December 2012 - 12:07 PM

Hi there,

There ae already a few tutorials covering this topic. Here are a few good ones found by googling "pool physics"
I've implemented some of these myself, and it works just fine!

http://www.gamasutra.com/view/feature/3168/physics_on_the_back_of_a_cocktail_.php
http://archive.ncsa.illinois.edu/Classes/MATH198/townsend/math.html
http://www.real-world-physics-problems.com/physics-of-billiards.html

Cheers,
Mike


#5005227 Learning Soft Body

Posted by h4tt3n on 29 November 2012 - 02:37 AM

Hi there,

A good place to start is to make a loop of particles connected with springs. Then calculate the rest-area (or "2d volume") using the equation found here, and save it.

For each program loop, calculate the current area and calculate a pressure force, which could look like this:

Fpressure = stiffnes * (area - rest area)

Which is essentially just Hooke's law of elasticity in another form. Then, for each spring, apply a perpendicular pressure force to the particles in each end of the spring.

Integrate with time using your favourite algorithm and repeat. This will make the loop of springs into a neat little water balloon :-)

Cheers,
Mike


#4991783 Problem getting correct orbits of planets

Posted by h4tt3n on 19 October 2012 - 08:28 AM

No. F = ma. a = F/m, and the force is defined as F = G m1m2/r^2, so a = F/m = G m/r^2. This is correct. Gravitational acceleration is independent of the "receiving" object's mass.


Yes, you are completely right - But only if you pick the right mass, and I suspect this is where the error lies. Bugs are often harder to find in optimized, compacted code, and that's why I recommend using the original Newtonian force based equation. Also, for the acceleration based calculation to work you need two equations, one for each body. A1 = G m2/r^2 and A2 = G m1/r^2. Otherwise your simulation will not conserve momentum. Sorry if my first post was a bit unclear, I was in a bit of a hurry when writing it.

Cheers,
Mike


#4968802 Getting an object to roll/slide

Posted by h4tt3n on 12 August 2012 - 01:32 PM

Hello Boov,

I've attached a small physics doodle with windows .exe file and source code that implements ball-to-wall and ball-to-ball collision with static and dynamic friction. It's written in FreeBASIC. All the equations you're looking for are in there, but I don't know how easy they are to read. Ask if you have questions.

Warning: playing with the attached doodle is really addctive :-)

Cheers,
Mike

Attached Files




#4952725 Rope/cloth simulation problems

Posted by h4tt3n on 25 June 2012 - 12:05 PM

Hi there,

Seeing that noone has bothered to reply, I'd like to give you a little advise: If a constraint needs 500 iterations to produce good result, I'd ditch it right away. The Jacobsen method works, but it's a bit dated. In stead take a step back and have a second go at the spring method. As far as I can see, the reason it kept blowing up is because the model you used has no damping. The damped Hooke's law of elasticity spring looks like this:

f = -kx - dv

where f = force, k = spring stiffnes coefficient, x = displacement, d = damping coefficient, and v = velocity along distance vector.

v is calculated by taking the dot product of the velocity difference vector (node 2 velocity - node 1 velocity) and the normalized distance vector.

If you apply the damping and tweak the coefficients, you'lle see much calmer movement and no simulation blow up.

Have fun experimenting!

Cheers,
Mike


#4949554 Numerical integration methods

Posted by h4tt3n on 15 June 2012 - 09:36 AM

David Whysong's higher order symplectic integration algorithms are truly excellent. I've completely left Runge-Kutta and all the similar, large integrators for these. They come with fourth, sixth, and eighth order accuracy!

Source code as text:
http://read.pudn.com...ectic.cpp__.htm

source code download:
http://www.google.dk...P3iMU0-hryo2iuw

There's a paper too, but I can't find a link.

When I don't need the high accuracy, I use plane old symplectic Euler:

v(n+1) = v(n) + a(n) * dt
x(n+1) = x(n) + v(n+1) * dt

I've stopped using the velocity verlet, because it handles differences in velocity very poorly.

Cheers,
Mike


#4938622 Help with making a gravity well.

Posted by h4tt3n on 09 May 2012 - 04:08 AM

Another thing worth mentioning is that a real, physically accurate gravity field cannot "catch" stray objects and make them spiral into itself. This is only possible if you add some sort of friction that dampens motion over time. Would you like to see some simple code samples (100-200 lines) of gravitational interaction?

Cheers,
Mike


#4923510 how 2d fluid is implemented?

Posted by h4tt3n on 19 March 2012 - 09:01 PM

Hi there, here are some good articles on SPH:

http://www.cs.clemson.edu/~bpelfre/sph_tutorial.pdf
http://image.diku.dk/projects/media/kelager.06.pdf

Cheers,
Mike


#4890627 Calculating and applying forces

Posted by h4tt3n on 05 December 2011 - 12:52 AM

You almost got it. The below scheme is simpe, effective and widely used. It's called the symplectic Euler integration algorithm.

calculate forces

acceleration = force / mass
velocity += acceleration * dt
position += velocity * dt

reset forces and start all over


#4885665 Jumpy raycast-vehicle

Posted by h4tt3n on 19 November 2011 - 12:13 PM

You're welcome, always glad to help. :-)

The abs() does seem a little strange to me though, and if it only works with it, I think there may be a bug hiding somewhere else in your code. Have you tried this:

SuspensionForce = -SuspensionStiffness *  (RestLength - Compression) - ExtendDamping * Ship.GetLinearVelocity().y;

Notice there are two signs you can change independently of each other, suspension force and damping force. Good bug huntin'

Cheers,
Mike




PARTNERS