public Vector3 testCollision(Actor ball)
        {
            //the normalized direction that the actor should be pushed away
            Vector3 pushAwayDir = Vector3.Zero;

            for (int i = 0; i < TVIndices.Count; i++)
            {
                MeshDataExtractor.TriangleVertexIndices currentTVI = TVIndices[i];

                /*
                 * Vector3[] currentTriangle = { Vector3.Zero, Vector3.Zero, Vector3.Zero };
                 * currentTriangle[0] = new Vector3(verticies[currentTVI.I0].X, verticies[currentTVI.I0].Y, verticies[currentTVI.I0].Z);
                 * currentTriangle[1] = new Vector3(verticies[currentTVI.I1].X, verticies[currentTVI.I1].Y, verticies[currentTVI.I1].Z);
                 * currentTriangle[2] = new Vector3(verticies[currentTVI.I2].X, verticies[currentTVI.I2].Y, verticies[currentTVI.I2].Z);
                 * currentTriangle[0] = Vector3.Transform(currentTriangle[0], worldTransform);
                 * currentTriangle[1] = Vector3.Transform(currentTriangle[1], worldTransform);
                 * currentTriangle[2] = Vector3.Transform(currentTriangle[2], worldTransform);
                 *
                 */
                /*
                 * Vector3 v0 = verticies[currentTVI.I0];
                 * Vector3 v1 = verticies[currentTVI.I1];
                 * Vector3 v2 = verticies[currentTVI.I2];
                 * v0 *= m_scale;
                 * v1 *= m_scale;
                 * v2 *= m_scale;
                 * Vector3[] currentTriangle = {  v0, v1, v2 };
                 */

                Vector3[] currentTriangle = { Vector3.Transform(verticies[currentTVI.I0], worldTransform),
                                              Vector3.Transform(verticies[currentTVI.I1], worldTransform),
                                              Vector3.Transform(verticies[currentTVI.I2], worldTransform) };

                if (IntersectHelper.sphereTriangleIntersect(ball.WorldBoundSphere, currentTriangle))
                {
                    //Console.WriteLine("HIT " + i);
                    pushAwayDir += getTriangleNormal(currentTriangle);
                    //return true;
                }
            }

            if (pushAwayDir != Vector3.Zero)
            {
                pushAwayDir.Normalize();
            }
            else
            {
                //Console.WriteLine("MISS");
            }
            return(pushAwayDir);
            //return false;
        }
Beispiel #2
0
        public bool testCollision(Actor ball)
        {
            //temp
            Vector3[] tempTriangle = { Vector3.Transform(verticies[0], worldTransform),
                                       Vector3.Transform(verticies[1], worldTransform),
                                       Vector3.Transform(verticies[2], worldTransform) };

            //for (int i = 0; i < 1; i++) {
            for (int i = 0; i < TVIndices.Count; i++)
            {
                MeshDataExtractor.TriangleVertexIndices currentTVI = TVIndices[i];
                Vector3[] currentTriangle = { Vector3.Transform(verticies[currentTVI.I0], worldTransform),
                                              Vector3.Transform(verticies[currentTVI.I1], worldTransform),
                                              Vector3.Transform(verticies[currentTVI.I2], worldTransform) };
                if (IntersectHelper.sphereTriangleIntersect(ball.WorldBoundSphere, currentTriangle))
                {
                    Console.WriteLine("HIT");
                    return(true);
                }
            }
            Console.WriteLine("MISS");
            return(false);
        }