Esempio n. 1
0
        /// <summary>
        /// Call this in a GameplayScreen Update function implementation
        /// Pass in the actor that the camera should follow behind
        /// </summary>
        /// <param name="actor"></param>
        public void followBehind(Actor actor)
        {
            Vector3 camPos = new Vector3(0f, 120.0f, 120.0f);
            camPos = (Vector3.Transform(camPos, Matrix.CreateFromQuaternion(actor.quat)));
            camPos += actor.position;
            m_kCameraPosition = camPos;
            Vector3 camUp = new Vector3(0, 1, 0);
            camUp = Vector3.Transform(camUp, Matrix.CreateFromQuaternion(actor.quat));

            cameraMatrix = Matrix.CreateLookAt(camPos, actor.position, camUp);

            facing = actor.position - camPos;
        }
Esempio n. 2
0
        public void ManualCameraRotation(float rotation, Actor actor)
        {
            //Vector3 camPos = new Vector3(0f, 120.0f, 120.0f);
            //camPos = (Vector3.Transform(camPos, Matrix.CreateFromQuaternion(actor.quat)));

            //Vector3 camPos = new Vector3((float)Math.Cos(rotation) * 60f, 50.0f, (float)Math.Sin(rotation) * 60f);

            Vector3 camPos = new Vector3(0f, 120.0f, 120.0f);
            camPos = Vector3.Transform(camPos, Matrix.CreateRotationY(rotation));

            camPos += actor.position;
            m_kCameraPosition = camPos;
            Vector3 camUp = new Vector3(0, 1, 0);

            cameraMatrix = Matrix.CreateLookAt(camPos, actor.position, camUp);

            facing = actor.position - camPos;
        }
        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;
        }
Esempio n. 4
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;
        }