Code Monkey home page Code Monkey logo

Comments (5)

Genbox avatar Genbox commented on June 4, 2024

TOI sweeps the shape along a path to the point of collision. Distance.ComputeDistance() is used by TOI and faster than TOI if you only need the point of collision and normal.

from velcrophysics.

benblo avatar benblo commented on June 4, 2024

Hey, thanks for your answer! Not sure I understand though, how would I get the distance considering I'm doing a sweep? As I understand it CalculateTimeOfImpact iterates a bunch of times along the sweep, while ComputeDistance only takes transforms.
Currently this is what I'm doing:

TimeOfImpact.CalculateTimeOfImpact(out _output, input);

#region compute the contact point at TOI
// FIXME: this is super redundant and inefficient as CalculateTimeOfImpact() already does all this!

if (_output.State == TOIOutputState.Touching ||
    (_output.State == TOIOutputState.Overlapped && _overlapPolicy == ShapeCastOverlapPolicy.Accept)) // NOTE: not sure ComputeDistance() returns something valid in this case...
{
	Sweep sweepA = input.SweepA;
	Sweep sweepB = input.SweepB;
	sweepA.Normalize();
	sweepB.Normalize();
	TransformF xfA, xfB;
	sweepA.GetTransform(out xfA, _output.T);
	sweepB.GetTransform(out xfB, _output.T);

	distanceInput.ProxyA = input.ProxyA;
	distanceInput.ProxyB = input.ProxyB;
	distanceInput.TransformA = xfA;
	distanceInput.TransformB = xfB;
	distanceInput.UseRadii = false;

	DistanceOutput distance;
	SimplexCache cache;
	Distance.ComputeDistance(out distance, out cache, distanceInput);
	_contactPoint = distance.PointA;
}
else
{
	_contactPoint = new Vector2();
}

#endregion

... thoughts?

from velcrophysics.

Genbox avatar Genbox commented on June 4, 2024

Right, now I understand.

The internals try to limit the size of input/output structs and caches such that more of it will fit in the CPU cache. On most systems it is much faster to just run a single iteration of the distance function rather than storing a lot of (mostly) unused values filling up the cache.

It does not store the original value of the distance function in the cache or output as it is not needed for the engine itself. However, you can try and store the original values from the distance function in TOIOutput if you want to omit that one distance call.

from velcrophysics.

benblo avatar benblo commented on June 4, 2024

OK, that's what I thought, that it could just be added to TOIOutput, but I haven't studied the loop closely enough that I felt sure where exactly to do that.
Do you think adding more data to TOIOutput would have a negative impact on cache performances for the general case? I don't have a good grasp on how heavily CalculateTimeOfImpact is used by the engine itself... not even sure it matters for my game as I mostly use the engine for collision detection, not real physics (no non-kinematic bodies, forces etc).

from velcrophysics.

Genbox avatar Genbox commented on June 4, 2024

Honestly, it probably wouldn't. However, if we take that approach everywhere it would have a big impact.

This engine was built many years ago and both computers & compilers have changed a lot since. Nowadays I have to use Intel VTune Amplifier to get the real numbers as pipelining, prefetching, cache coherence etc. all have a huge impact on tight loops. For the most part, a simple profiler is enough though.

from velcrophysics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.