Jump to content



Why does RayIntersect return wrong values?

  • You cannot reply to this topic
1 reply to this topic

#1 plusnoir   Members   -  Reputation: 102

Like
0Likes
Like

Posted 09 February 2012 - 05:56 AM

I'm trying to implement Object picking. My BasicModel.cs has a function:

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


I create the Ray in my Camera.cs:

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


And finally in game1.cs I check for Intersection in every BasicModel and write "Intersects" to Console:

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


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.
Any advice is welcome,
noir

Ad:

#2 plusnoir   Members   -  Reputation: 102

Like
0Likes
Like

Posted 10 February 2012 - 01:56 PM

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.






We are working on generating results for this topic
PARTNERS