void Object_Picking_Test::RunTest(float mX, float mY) { CameraPtr ptr = scene->GetActiveCamera(); Camera * cam = ptr.Get(); cam->CalcPickingRay(mX, mY); using namespace DirectX; for (unsigned int i = 0; i < pickable.size(); i++) { SceneObj obj = pickable[i]; StaticEntity * ent = obj.obj.Get(); XMFLOAT4X4 mat = ent->GetWorldMatrix(); XMMATRIX world = XMLoadFloat4x4((XMFLOAT4X4*)&mat); world = XMMatrixTranspose(world); XMVECTOR det = XMMatrixDeterminant(world); XMMATRIX invWorld = XMMatrixInverse(&det, world); Vector3 org = cam->GetPosition(); Vector3 dir = cam->GetPickingRayDirection(); XMVECTOR orgInv = XMVector3TransformCoord(XMLoadFloat3((XMFLOAT3*)&org), invWorld); XMVECTOR dirInv = XMVector3TransformNormal(XMLoadFloat3((XMFLOAT3*)&dir), invWorld); dirInv = XMVector3Normalize(dirInv); XMStoreFloat3((XMFLOAT3*)&org, orgInv); XMStoreFloat3((XMFLOAT3*)&dir, dirInv); AABB bbox = ent->GetAABB(); /*XMVECTOR max = XMLoadFloat3((XMFLOAT3*)&bbox.max); XMVECTOR min = XMLoadFloat3((XMFLOAT3*)&bbox.min); max = XMVector3TransformCoord(max, world); min = XMVector3TransformCoord(min, world); XMStoreFloat3((XMFLOAT3*)&bbox.max, max); XMStoreFloat3((XMFLOAT3*)&bbox.min, min);*/ if (bbox.RayIntersact(org, dir)) { obj.bbox.Get()->SetVisible(!obj.bbox.Get()->IsVisible()); } } }