Jump to content

  • Log In with Google      Sign In   
  • Create Account

EvilWeebl

Member Since 17 Aug 2009
Offline Last Active Feb 08 2014 11:56 AM

#4796626 [XNA] ray picking and model scaling problems

Posted by EvilWeebl on 10 April 2011 - 05:06 AM

Not to worry, after sitting down and fiddling with it the entire morning I finally cracked it! I still cant believe the windows triangle picking example doesn't take into account the user wanting to scale or rotate on object.

Anyway, for anybody experiencing this problem in the future this is how I went about it:

  • Inversing the ray by an objects world matrix that includes scaling(possibly also rotation) messes it up when it comes to doing a quick test against a bounding sphere. To overcome this create a new ray called boundingSphereRay or something and then transform it by the inverse of the objects translation matrix only.
  • The bounding sphere must then be transformed with uniform scaling, I found the 'TransformBoundingSphere' function in the picking sample(not the triangle picking sample) very useful for this. Although make sure that the center position of the sphere is set to vector.zero to account for the rays inverse. Just to note I found it a good idea to add a translate boolean parameter to the function, false to have the returned sphere at vector.zero and true to translate the sphere to the objects position for use with the bounding frustum test.
  • Finally you inverse your original ray by the objects world matrix(scaling and all) and test against the triangles.

Hopes this helps anybody in need and feel free to post if struggling.


PARTNERS