Example #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;
        }
Example #2
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);
        }