Sign in to follow this  

Mesh.Intersect not outputting expected values

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using C# for a 3D graphics class. I am trying to "walk" on a mesh. I am using the position of my character to find out where he "should" be if the user goes towards a mesh object. I am only doing Y directing right now. However, I send in a position of the user. Then it seems Mesh.Intersect asks for a direction, but seems to only check from the origin TO the direction. I would assume it goes to infinity. It says it intersects, then, using "intersectionPoint = rayOrigin + (rayDirection * intersectInformation.Distance)" I get a position where the intersection occurred. However, the X and Z values change in the intersectionPoint from the origin even though the origin and direction only differ in the Y direction. Below is the code that is relevant. From World Class
        private Vector3 GetNewMeshPosition(Vector3 position)
        {
            Vector3 retVal = position;
            Vector3 tempPosition;

            for (int i = 0; i < m_tunnelNodes.Count; i++)
            {
                if (m_tunnelNodesDraw[i])
                {
                    tempPosition = m_tunnelNodes[i].BoundFloor(position);
                    retVal = tempPosition;
                }
            }

            return retVal;
        }
From mesh class
        public Vector3 BoundFloor(Vector3 position)
        {
            Vector3 retVal = position;
            Matrix inverseTransforms = m_device.Transform.World;

            IntersectInformation info;
            Vector3 from = position;
            Vector3 to = from;

            to.TransformCoordinate(inverseTransforms);
            from.TransformCoordinate(inverseTransforms);

            from.Y = from.Y + 10;
            to.Y = to.Y - 90;


            if (m_mesh.Intersect(from, to, out info))
            {
                //intersectionPoint = rayOrigin + (rayDirection * intersectInformation.Distance);
                retVal = Vector3.Add(from, (Vector3.Multiply(to, info.Dist)));
            }

            retVal.TransformCoordinate(transforms);

            return retVal;
        }

Share this post


Link to post
Share on other sites
Hey, it is not "from + (to * dist)", it is "from + (dir * dist)", where dir is (to - from). So you do something like

retVal = Vector3.Add (from, (Vector3.Multiply (Vector3.Subtract(to, from), info.Dist)));

Share this post


Link to post
Share on other sites
I didnt say that. I just thought you used the name "to" because its the endpoint. I dont know how the C# SDK works so you'd better read it. But probably its actually the endpoint because its what the C++ SDK usually asks for.

Share this post


Link to post
Share on other sites

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this