3D mouse picking

I have converted the 3D model of the Formula One car to my own VertexPositionNormalColor format. I want to create a few variants of the car with different colors so I needed a way to select vertices and give them a color. A simple editor would suit my needs so I started writing a tool for it. This (old) question on StackExchange helped me a lot: Get 3D mouse position.

This snippet reads the mouse and creates a Ray:

The ray is still in object space, so it needs to be rotated so it matches the 3D object I want to manipulate. This snippet rotates the ray so it matches the 3D object:

Now the ray matches the 3D object, so a triangle intersection on the faces of the mesh does the trick!

Note: the triangle-hitlocation function is not my own, I had it stored on my harddrive (I knew it would come handy some day!) Unfortunately I don’t know the author.

 

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *