Comments (5)
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.
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.
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.
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.
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)
- Serializable templates HOT 1
- BodyTemplate.GravityScale is ignored HOT 1
- Problem with sliding HOT 8
- Can't run HelloWorld project on VS 2017 HOT 2
- MVP Sandbox HOT 1
- Requires XNA, no mention of that on the description or front page HOT 1
- TextureConverter.DetectVertices() throws InvalidOperationException on blank textures HOT 1
- Documentation or tutorials needed HOT 3
- VelcroPhysics and Unity HOT 1
- Upgrading from Farseer -- what do you think of Aether? HOT 2
- Importing SVG HOT 3
- NuGet not available HOT 12
- Setting contact.Enabled = false not having effect HOT 4
- Weird collisions on edges in rectangles HOT 1
- Invert Y axis HOT 1
- Question: Documentation and/or Forum HOT 1
- Updating NuGet Package HOT 1
- Is is still active?
- Possible license breach? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from velcrophysics.