Skip to content

Conversation

Kreblc3428
Copy link

PR Details

Related Issue

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x ] My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@Kreblc3428
Copy link
Author

@dotnet-policy-service agree

Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice contribution. Is this not somewhat similar to RayIntersectsPlane() method? That method expects a ray, and this one two points on a line (that could also be used to create a ray), but it is essentially the same thing, no?

Anyway, just left some comments.

/// <param name="point">When the method completes, contains the point of intersection,
/// or <see cref="Vector3.Zero"/> if there was no intersection.</param>
/// <returns>Whether the two objects intersected.</returns>
public static bool LinePlaneIntersection(Plane plane, Vector3 pt1, Vector3 pt2, out Vector3 point)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other methods in this CollisionHelper class uses names such as vertex1, point, etc. Maybe there could be more descriptive names for arguments pt1 and pt2? Something like point1, point2, intersection, or something along those lines.


float denominator = Vector3.Dot(N, V);

if (denominator == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Floating point comparison against zero is usually a bad idea because of precission issues. Better to use relational operators and/or compare against an epsilon value. Look at how it is done in ClosestPointPointTriangle():

float d1 = Vector3.Dot(ab, ap);
float d2 = Vector3.Dot(ac, ap);

if (d1 <= 0.0f && d2 <= 0.0f)
{
    result = vertex1; //Barycentric coordinates (1,0,0)
    return;
}


float t = -(Vector3.Dot(N, S) + D) /denominator;

point = S + (t * (V));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a minor nitpick.

I know this may come from mathematical formulas where variables are named S, t, N, or V. But in code it helps immensely (specially when debugging or reading the code) to have more descriptive names.

Also, if you have variables that only store the value of some other and are never modified (like float D = -plane.D), why not use -plane.D directly?

Make code style adjustments from feedback.
@Kreblc3428
Copy link
Author

Nice contribution. Is this not somewhat similar to RayIntersectsPlane() method? That method expects a ray, and this one two points on a line (that could also be used to create a ray), but it is essentially the same thing, no?

Anyway, just left some comments.

Ok I think I made the changes you wanted, thanks.

Copy link
Contributor

@Ethereal77 Ethereal77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. LGTM

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

Successfully merging this pull request may close these issues.

2 participants