Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jul 2011
Offline Last Active Oct 07 2015 06:31 PM

#5230026 Circle embedded in line-- fastest vector to unembed

Posted by on 20 May 2015 - 06:21 AM

♬♬ Every cycle's sacred... every cycle's good... every cycle's wanted, in my neighborhood... ♬


However, I don't need it PERFECTLY normalized... I just need it pretty close to one.  I wonder what tricks I can do by multiplying my vectors by huge numbers, so they approach infinity, and then divide them by eachother.  That might work for my resolution.

#5228243 Collision/Unembedding/Pushing... and a seemingly impossible case

Posted by on 10 May 2015 - 11:15 AM

Hi all,


I asked a few questions about Box2D a few days ago, and learned a whole lot about how that system works.  As a result of that, for fun and optimization, I'm trying to roll a stripped down system of my own for kicks, learning, and edification... with one enhancement that seems "impossible" in a simultaneous physics simulation.


Impossible is usually a result of looking at things from the wrong perspective!  Show me the other angle!


I want to develop a process where the density of an object, and the object's ability to display another object are two seperate variables.  Every physics simulation I've run into represents their object something like this:

       Point        mPosition;
       Point        mMoveDirection;
       float        mDensity;

For the purposes of gameplay elements, I want to represent an object like this:

     Point        mPosition;
     Point        mMoveDirection;
     float        mStrength;
     float        mWeight;

Let's further say that:


if ObjectA.mStrength<=ObjectB.mWeight, then ObjectA cannot displace object B.

else if ObjectA.mStrength>=ObjectB.mWeight*10, then ObjectA pushes object B at normal "collision seperation."

else (ObjectA pushes ObjectB at an interpolation between 0*CollisionSeperation and 1*CollisionSeperation).


With those rules in mind, consider a simulation where ObjectA and ObjectB are both in motion, and they end up overlapped after their mMoveDirection has been applied.


The following rules come into play:



I've managed to make the whole simulation work with every condition except the very last one.  It's a problem! 


There's two circles that are overlapping, but are NOT allowed to displace eachother.


Can anyone think of how one would resolve this situation?  If one circle is at rest, it's pretty simple, you treat it like one of the conditions where one cannot move the other.  But if both circles are in motion, then their unembed essentially should hold them in place relative to each other-- while still granting them the ability to slide and jostle around eachother as they both push but cannot advance.


(Note that conditions 1 and 2 are really the same as condition 3, just with the midpoint position weighted properly... the equation to get that is incredibly fiddly and I still haven't come up with one that works, but I think it exists)


* * *


I can solve "condition impossible" by making the simulation non-simultaneous-- moving each object one by one, and unembedding it and it alone, and then moving on to the next object.  The speed hit from this is horrible, not to mention you get unfair situations because whoever is higher in the list gets primacy!  So I'm looking for a way to make it simultaneous.


Any ideas?

#5227947 Box-- Absorbing impulse after collide

Posted by on 08 May 2015 - 07:45 AM

Hi Alex,


I wish I had but more upvotes to give.  That does the correct modification of the velocity.  However, if I'm not mistaken, the strength is not related to the weight at all?  I.E. if I set the strength to .1, then it's .1 push-power against everything.


Can you suggest a way I can make that related to the weight of the other object?  My first inclination is to intercept the solver's constructor and set the "strength" explicity by just comparing it to the density of the other object and setting it anywhere from 0 to 1.0f depending.


Does that sound right to you?


The system I intend  to set up is something like this:


if (strengthA<=weightB || weightB==0) {A cannot move B at all}

else if (strengthA>weightB*10) {A pushes B without any hindrance, sort of like Box2D normal behavior}

else {A pushes B at a linear interpolation depending on it's placement between weightB and weightB*10}


* * *


Edit: I've been fiddling around with the code a bit, trying to make this happen... I'm running into an issue in that during the push, strengthA is related to strengthB... whereas what I'm looking for is for strengthA to be related to weightB.


I made a quickie function:

float32 ResolveStrength(float pushStr, float pushedWeight)
	if (pushStr<=pushedWeight) return .00001f;// Should be zero actually!
	if (pushStr>=pushedWeight*10) return 1.0f;

	float aMax=(pushedWeight*10)-pushedWeight;
	return (pushStr)/aMax;

And I use that like so in b2ContactSolver's constructor:

vc->strengthA = ResolveStrength(fixtureA->GetStrength(),fixtureB->GetWeight());
vc->strengthB = ResolveStrength(fixtureB->GetStrength(),fixtureA->GetWeight());

(I added a weight component to fixtures, to seperate it from density-- for the purposes of my initial test, everything has a density of 1 so that it's not a factor)

So when I do this, I set up:


CircleA, weight = 1.0, strength=11.0

CircleB, weight = 10.0, strength = 10.0


...and it works exactly as expected, with the pushing circle barely budging CircleB.


BUT!  If I decide CircleB is going to be a weak guy, and give it a low strength, then suddenly circle A has more power to move it.  So those attributes are still related to eachother, albeit with finer control.


But picture this situation:

A horde of Chasers are set up.  Each chaser has weight 10, strength 1.  This prevents the chasers from pushing much (including eachother, so they aren't just batting eachother out of the way constantly) but meanwhile the player character has to have at least strength 11 to push back at all.


There's probably an on-the-fly modification I could do to inv_mass to make this all come together--but for simplicity, is it possible to just divorce out the relationship between strengthA and strengthB when deciding how much the players seperate?

#4939336 Converting a bitmap image to a meshed approximation

Posted by on 11 May 2012 - 10:20 AM

Taby, you might be a God Among Men.

I will look this over this weekend and see if I can make use of it. Needless to say, if I can make it do what I need, you will go on the credit's list for my project!

If think after incorporating your project, I can reduce the triangles myself and come up with an acceptable solution.

Stay tuned!