i have a peice of code that renders a 3D image, say a cube. I require 3 cubes in in different locations, this is done using instancing and i am able to render the cube in 3 different locations. However, i now need to pick any of the 3 cubes. I am pretty new to DirectX(11) and searches online did not yeild any answers. So how i pick an object when i only have a single set of vertices(triangle) used for the render?
1 Answer
Picking is not generally performed by the GPU so the use of instancing shouldn't matter.
Your CPU-side code presumably knew where the cubes where in order to put their transforms into the instance buffer. Hence it can do a ray-AABB test by transforming the picking ray into the space of the cube in the cube's local space.
Happily, the local space for the cube's AABB is just the unit AABB. You need only transform the picking ray by the inverse of the transform matrix you used for each cube's instance in the instance buffer.
-
\$\begingroup\$ ok, i went through the code again and this is how the code looks ` instance_buffer[0].instanceMatrix = vector<float,4>(x,y,z,1.0f); ` This line alone is enough to create an instance of the cube in the new location. So i dont see how i can get any information to perform the picking from this \$\endgroup\$ Jan 21, 2016 at 0:36
-
\$\begingroup\$ @introVertice: your
x
,y
, andz
are the locations of the cube. Assuming that you have no scaling, you know that your cube is a unit cube at that location. Now take your picking ray and do a collision check against the ray and the AABB at that location. \$\endgroup\$ Jan 21, 2016 at 0:49