Note that there are some explanatory texts on larger screens.

plurals
  1. PO3d bounding Box border xna
    primarykey
    data
    text
    <p>So, I'm trying to develop a 3d table tennis game, and I'm having problems when it comes to colliding the ball with the table. I have a bounding sphere for the ball and bounding box for the table, but the intersection isn't that accurate, and I'm guessing that the bounding box is incorrect since colliding the ball with the racket is good. </p> <p>I'm trying to display the bounding box so that it would be easier to see where the error is, but I cant seem to implement the tutorials I've found with my code, or just don't know how. And, I'm I right in creating an AABB since my table isn't moving? If anyone could help, it would be greatly appreciated, or if anyone could suggest a better way to collide a ball with a box (if there is) thanks. I've pasted my bounding box detection, and the collision between the sphere and box. If more code is needed I'll post it. Thanks</p> <pre><code>private bool Ball_Table(Model model1, Matrix world1) { for (int meshIndex1 = 0; meshIndex1 &lt; model1.Meshes.Count; meshIndex1++) { BoundingSphere sphere1 = model1.Meshes[meshIndex1].BoundingSphere; sphere1 = sphere1.Transform(world1); if(table_box.Intersects(sphere1)) return true; } return false; } </code></pre> <p>.</p> <pre><code>protected BoundingBox UpdateBoundingBox(Model model, Matrix worldTransform) { // Initialize minimum and maximum corners of the bounding box to max and min values Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue); // For each mesh of the model foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { // Vertex buffer parameters int vertexStride = meshPart.VertexBuffer.VertexDeclaration.VertexStride; int vertexBufferSize = meshPart.NumVertices * vertexStride; // Get vertex data as float float[] vertexData = new float[vertexBufferSize / sizeof(float)]; meshPart.VertexBuffer.GetData&lt;float&gt;(vertexData); // Iterate through vertices (possibly) growing bounding box, all calculations are done in world space for (int i = 0; i &lt; vertexBufferSize / sizeof(float); i += vertexStride / sizeof(float)) { Vector3 transformedPosition = Vector3.Transform(new Vector3(vertexData[i], vertexData[i + 1], vertexData[i + 2]), worldTransform); min = Vector3.Min(min, transformedPosition); max = Vector3.Max(max, transformedPosition); } } } // Create and return bounding box table_box = new BoundingBox(min, max); return table_box; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload