Triangle Intersection: Unterschied zwischen den Versionen

Aus Das Sopra Wiki
Florian (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Florian (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 6: Zeile 6:


<source lang="csharp">
<source lang="csharp">
/// <summary>
/// Reads the mesh data (vertices and indices) of a ModelMeshPart and provides a method to intersect a ray with the triangles of the mesh.
/// </summary>
public sealed class MeshTriangleData
public sealed class MeshTriangleData
{
{
  /// <summary>
  /// Stores the vertices of the mesh.
  /// </summary>
   private Vector3[] vertices;
   private Vector3[] vertices;


  /// <summary>
  /// Stores the indices of the mesh if they have a size of sixteen bits.
  /// </summary>
   private ushort[] indicesShort;
   private ushort[] indicesShort;
  /// <summary>
  /// Stores the indices of the mesh if they have a size of thirtytwo bits.
  /// </summary>
   private uint[] indicesInt;
   private uint[] indicesInt;
  /// <summary>
  /// Indicates if the mesh uses thirtytwo bit indices (true) or sixteen bit indices (false).
  /// </summary>
   private bool use32BitIndices = false;
   private bool use32BitIndices = false;


  /// <summary>
  /// Creates a new MeshTriangleData object for the ModelMeshPart-Index of the mesh.
  /// </summary>
  /// <param name="mesh">The mesh of the model.</param>
  /// <param name="modelMeshPartIndex">The index of the mesh part of the mesh.</param>
  /// <param name="absoluteBoneTransforms">The absolute bone transforms of the model to which the mesh belongs.</param>
   public MeshTriangleData(ModelMesh mesh, int modelMeshPartIndex, ref Matrix[] absoluteBoneTransforms)
   public MeshTriangleData(ModelMesh mesh, int modelMeshPartIndex, ref Matrix[] absoluteBoneTransforms)
   {
   {
Zeile 43: Zeile 64:
   }
   }


  /// <summary>
  /// Calculates a bounding box around the triangle mesh.
  /// </summary>
  /// <param name="boundingBox">The bounding box for the triangle mesh.</param>
   public void CalculateBoundingBox(out BoundingBox boundingBox)
   public void CalculateBoundingBox(out BoundingBox boundingBox)
   {
   {
Zeile 48: Zeile 73:
   }
   }


  /// <summary>
  /// Calculates a bounding sphere around the triangle mesh.
  /// </summary>
  /// <param name="boundingSphere">The bounding shpere for the triangle mesh.</param>
   public void CalculateBoundingSphere(out BoundingSphere boundingSphere)
   public void CalculateBoundingSphere(out BoundingSphere boundingSphere)
   {
   {
Zeile 53: Zeile 82:
   }
   }


  /// <summary>
  /// Checks wether the current triangle mesh intersects a ray in the object space of the corresponding model.
  /// </summary>
  /// <param name="objectRay">The ray to check intersection with. CAUTION: The ray must be in the object space of the model to which the triangle mesh belongs!</param>
  /// <param name="result">Distance at which the ray intersects the triangle mesh, or <c>null</c> if there is no intersection.</param>
   public void Intersects(ref Ray objectRay, out float? result)
   public void Intersects(ref Ray objectRay, out float? result)
   {
   {