Jump to content
  • Advertisement
Sign in to follow this  
sanosuke001

Mesh.Intersect not outputting expected values

This topic is 4081 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)
                {
                    tempPosition = m_tunnelNodes.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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!