Jump to content
  • Advertisement
Sign in to follow this  
plusnoir

Why does RayIntersect return wrong values?

This topic is 2501 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

[color=#333333]I'm trying to implement Object picking. My BasicModel.cs has a function:

[color="#333333"]
public bool CheckRayIntersection(Ray ray)
{
//Where aabb is the BasicModel's BoundingBox
if (ray.Intersects(aabb) != null)
{ return true; }
else
{
[color="#333333"] return false;
}
}


[color=#333333]I create the Ray in my Camera.cs:

[color=#333333]public Ray GetMouseRay(Vector2 mousePosition, Viewport viewport)
{
Vector3 near = new Vector3(mousePosition, 0);
Vector3 far = new Vector3(mousePosition, 1);
[color=#333333] near = viewport.Unproject(near, projection, view, Matrix.Identity);
far = viewport.Unproject(far, projection, view, Matrix.Identity);
[color=#333333] return new Ray(near, Vector3.Normalize(far - near));
}


[color=#333333]And finally in game1.cs I check for Intersection in every BasicModel and write "Intersects" to Console:

[color=#333333]foreach(BasicModel model in assetManager._modelsOnscreen)
{
if(model.CheckRayIntersection(camera.GetMouseRay(mouseLocation,viewport)))
{
winForm.ConsoleWrite = "intersects";
}
}


[color=#333333]Somehow it always returns true for intersection with offset (to the right) to the actual Boundingbox. I also don't have any clue how I could visualize the problem or step through it. Actually the Boundingbox is drawn correctly as seen here, so I don't think that aabb causes the problem.
[color=#333333]

Any advice is welcome,
[color=#333333]

noir

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Fugured out, the offset is caused by the viewport being drawn into a PictureBox in a WinForm. Still don't know how to fix it.

Share this post


Link to post
Figured out, the offset is caused by the viewport being drawn into a PictureBox in a WinForm. Still don't know how to fix it.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!