Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeaturePair.value not set correctly? #6

Closed
huweiATgithub opened this issue Jan 20, 2021 · 2 comments
Closed

FeaturePair.value not set correctly? #6

huweiATgithub opened this issue Jan 20, 2021 · 2 comments

Comments

@huweiATgithub
Copy link

Hi Erin, Thank you for your great illustrative code, it is very good for learning rigid body dynamics.

From Arbiter::Update,

Contact* cNew = newContacts + i;
int k = -1;
for (int j = 0; j < numContacts; ++j)
{
Contact* cOld = contacts + j;
if (cNew->feature.value == cOld->feature.value)
{
k = j;
break;
}
}

I think FeaturePair.value is used to distinguish contacts. While in Collide.cpp where contacts are computed, the only place to set value is in ClipVertex's constructor which set value=0.
struct ClipVertex
{
ClipVertex() { fp.value = 0; }
Vec2 v;
FeaturePair fp;
};

Does it seem like this value is not correctly assigned for its purpose?

Thank you.

@bit-hack
Copy link

I have been doing some work on Box2D-Lite and your ticket caught my attention.

It also looked to me that fp.value is only ever set to 0 but thats not the case.
If you look at the definition of FeaturePair we can see that its actually a union type so setting inEdge1, etc will also affect value. This seems like just a way to speed up comparisons between all of these char members using type punning.

union FeaturePair
{
  struct Edges
  {
    char inEdge1;
    char outEdge1;
    char inEdge2;
    char outEdge2;
  } e;
  int value;
};

@huweiATgithub
Copy link
Author

Oh, I see. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants