Ejemplo n.º 1
0
        public void Update()
        {
            Ray   pickRay   = MathExtra.CalculateCursorRay(AIGame.camera.ProjectionMatrix, AIGame.camera.ViewMatrix);
            float rayLength = 0f;

            for (int i = 0; i < triangle.Length; i++)
            {
                Tri thisTri = triangle[i];
                if (MathExtra.Intersects(pickRay, thisTri.p1, thisTri.p3, thisTri.p2, thisTri.normal, false, true, out rayLength))
                {
                    Vector3 rayTarget = pickRay.Position + pickRay.Direction * rayLength;
                    groundCursorPosition.X =
                        rayTarget.X / (
                            //heightMap.Size * (heightMap.GridSpacing - 1)) *
                            //(((float)heightMap.Size * ((float)heightMap.GridSpacing - 1)) /
                            Settings.TERRAIN_TEXTURE_SIZE);
                    groundCursorPosition.Y = rayTarget.Y;
                    groundCursorPosition.Z =
                        rayTarget.Z / (
                            // heightMap.Size * (heightMap.GridSpacing - 1)) *
                            //(((float)heightMap.Size * ((float)heightMap.GridSpacing - 1)) /
                            Settings.TERRAIN_TEXTURE_SIZE);
                }
            }
            lastGroundCursorPos = groundCursorPosition;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initiate movement of the model to target position.
 /// </summary>
 /// <param name="target">Target position.</param>
 public virtual void MoveTo(Vector3 target)
 {
     target = NormalizeEndPosition(MathExtra.VectorOnXZAxis(target));
     // if target is same as position, do not move and rotate, if we move it will rotate character 180 degrees
     if (MathExtra.VectorOnXZAxis(_position) == target)
     {
         return;
     }
     _endPosition = target;
     TurnToTarget(target);
     _isMovingPrevStatus = _isMoving;
     _isMoving           = true;
 }
Ejemplo n.º 3
0
        public Vector3?IsIntersected(Ray ray)
        {
            float rayLength = 0f;

            for (int i = 0; i < triangle.Length; i++)
            {
                Tri thisTri = triangle[i];
                if (MathExtra.Intersects(ray, thisTri.p1, thisTri.p3, thisTri.p2, thisTri.normal, false, true, out rayLength))
                {
                    Vector3 rayTarget = ray.Position + ray.Direction * rayLength;
                    return(rayTarget);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private void SetUpCollision(int indiceID, int tID, int x, int y)
        {
            triangle[tID]        = new Tri();
            triangle[tID].p1     = vertices[x + y * heightMap.Size].Position;
            triangle[tID].p2     = vertices[x + (y + 1) * heightMap.Size].Position;
            triangle[tID].p3     = vertices[(x + 1) + y * heightMap.Size].Position;
            triangle[tID].normal = MathExtra.GetNormal(triangle[tID].p1, triangle[tID].p2, triangle[tID].p3);
            triangle[tID].id     = indiceID / 6 - 1;

            triangle[tID + 1]        = new Tri();
            triangle[tID + 1].p1     = vertices[(x + 1) + y * heightMap.Size].Position;
            triangle[tID + 1].p2     = vertices[x + (y + 1) * heightMap.Size].Position;
            triangle[tID + 1].p3     = vertices[(x + 1) + (y + 1) * heightMap.Size].Position;
            triangle[tID + 1].normal = MathExtra.GetNormal(triangle[tID + 1].p1, triangle[tID + 1].p2, triangle[tID + 1].p3);
            triangle[tID + 1].id     = indiceID / 6;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initiate movement of the model to target position.
        /// </summary>
        /// <param name="x">Target X value.</param>
        /// <param name="z">Target Z value.</param>
        public virtual void MoveTo(float x, float z)
        {
            Vector3 target = MathExtra.VectorOnXZAxis(new Vector3(x, 0, z));

            MoveTo(target);
        }