You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to make my own, it doesn't work fully, what if the object is translated.
std::shared_ptr<item> Pick(float mouseX,float mouseY)
{
// Right Hand conversion
float pointX = (((2.0f * (float)mouseX) / (float)wi) - 1.0f) * -1.0f;
float pointY = (((2.0f * (float)mouseY) / (float)he) - 1.0f);
Vector3 origin = Vector3(pointX, pointY, 0);
Vector3 farx = Vector3(pointX, pointY, 1);
for (auto& m : models)
{
DirectXTK::BoundingSphere b = m->get_bounding_sphere(); // uses DirectXTK
SimpleMath::Matrix worldMatrix = m->world; // how to use this?
auto m1 = m_view * m_proj;
Matrix m2;
m1.Invert(m2);
// Now transform the ray origin and the ray direction from view space to world space.
auto rayOrigin = XMVector3TransformCoord(origin, m2);
auto rayend = XMVector3TransformCoord(farx, m2);
// Normalize the ray direction.
auto rayDirection = XMVector3Normalize(rayend - rayOrigin);
float radius = 0;
bool intersect = b.Intersects(rayOrigin, rayDirection, radius);
if (intersect == true)
return m;
}
return nullptr;
}
The text was updated successfully, but these errors were encountered:
It would help to have a picking method.
I'm trying to make my own, it doesn't work fully, what if the object is translated.
The text was updated successfully, but these errors were encountered: