• 13
• 16
• 27
• 9
• 9

# Mesh.Intersect not outputting expected values

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

## 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.TransformCoordinate(transforms);

return retVal;
}


anyone?

##### 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 on other sites
ahh, ok. well when mesh.intersect asks for dir, they mean endpoint of a line. thanks, i'll go try that.