Plane.cs 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho
  4. {
  5. [StructLayout(LayoutKind.Sequential)]
  6. public struct Plane
  7. {
  8. /// <summary>
  9. /// Plane normal.
  10. /// </summary>
  11. public Vector3 Normal;
  12. /// <summary>
  13. /// Plane absolute normal.
  14. /// </summary>
  15. public Vector3 AbsNormal;
  16. /// <summary>
  17. /// Plane constant.
  18. /// </summary>
  19. public float D;
  20. /// <summary>
  21. /// Construct from a normal vector and a point on the plane.
  22. /// </summary>
  23. public Plane(Vector3 normal, Vector3 point)
  24. {
  25. Normal = Vector3.Normalize(normal);
  26. AbsNormal = new Vector3(Math.Abs(Normal.X), Math.Abs(Normal.Y), Math.Abs(Normal.Z));
  27. D = - Vector3.Dot(Normal, point);
  28. }
  29. /// <summary>
  30. /// Construct from a 4-dimensional vector, where the w coordinate is the plane parameter.
  31. /// </summary>
  32. public Plane(Vector4 plane)
  33. {
  34. Normal = new Vector3(plane.X, plane.Y, plane.Z);
  35. AbsNormal = new Vector3(Math.Abs(plane.X), Math.Abs(plane.Y), Math.Abs(plane.Z));
  36. D = plane.W;
  37. }
  38. }
  39. }