0

나는 총알 물리학 세계에서 물체를 선택하려고 노력하고있다. 그러나 내가 선택할 수있는 것처럼 보이는 것은 바닥/지상 평면이다! Vuforia SDK를 사용 중이며 ImageTargets 데모 코드가 변경되었습니다. 나는 3D 세계에 내 터치 스크린 점을 프로젝트에 다음 코드를 사용했다 : 내 물리학의 세계에서 레이 검사를 할 때Augmented Reality + Bullet Physics - rayTest/Ray picking의 문제

void projectTouchPointsForBullet(QCAR::Vec2F point, QCAR::Vec3F &lineStart, QCAR::Vec3F &lineEnd, QCAR::Matrix44F &modelViewMatrix) 
{ 

QCAR::Vec4F normalisedVector((2 * point.data[0]/screenWidth - 1), 
     (2 * (screenHeight-point.data[1])/screenHeight - 1), 
     -1, 
     1); 
QCAR::Matrix44F modelViewProjection; 
SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]); 
QCAR::Matrix44F inversedMatrix = SampleMath::Matrix44FInverse(modelViewProjection); 

QCAR::Vec4F near_point = SampleMath::Vec4FTransform(normalisedVector,inversedMatrix); 

near_point.data[3] = 1.0/near_point.data[3]; 
near_point = QCAR::Vec4F(near_point.data[0]*near_point.data[3], near_point.data[1]*near_point.data[3], near_point.data[2]*near_point.data[3], 1); 

normalisedVector.data[2] = 1.0;//z coordinate now 1 
QCAR::Vec4F far_point = SampleMath::Vec4FTransform(normalisedVector, inversedMatrix); 

far_point.data[3] = 1.0/far_point.data[3]; 
far_point = QCAR::Vec4F(far_point.data[0]*far_point.data[3], far_point.data[1]*far_point.data[3], far_point.data[2]*far_point.data[3], 1); 

lineStart = QCAR::Vec3F(near_point.data[0],near_point.data[1],near_point.data[2]); 
lineEnd = QCAR::Vec3F(far_point.data[0],far_point.data[1],far_point.data[2]); 
} 

하는 난 단지 접지면을 치는 것 같다! 여기에 선 테스트 전화 코드입니다 :

QCAR::Vec3F intersection, lineStart; 
    projectTouchPointsForBullet(QCAR::Vec2F(touch1.tapX, touch1.tapY), lineStart, lineEnd,inverseProjMatrix, modelViewMatrix); 
    btVector3 btRayFrom = btVector3(lineEnd.data[0], lineEnd.data[1], lineEnd.data[2]); 
    btVector3 btRayTo = btVector3(lineStart.data[0], lineStart.data[1], lineStart.data[2]); 

    btCollisionWorld::ClosestRayResultCallback rayCallback(btRayFrom,btRayTo); 
    dynamicsWorld->rayTest(btRayFrom, btRayTo, rayCallback); 
    if(rayCallback.hasHit()) 
    { 
     char* pPhysicsData = reinterpret_cast<char*>(rayCallback.m_collisionObject->getUserPointer());//my bodies have char* messages attached to them to determine what has been touched 
     btRigidBody* pBody = btRigidBody::upcast(rayCallback.m_collisionObject); 
     if (pBody && pPhysicsData) 
     { 
      LOG("handleTouches:: notifyOnTouchEvent from physics world!!!"); 
      notifyOnTouchEvent(env, obj,0,0, pPhysicsData); 
     } 

    } 

나는 적어도 내 터치가 제대로 세계로 투사되는 알고, 내가 주로 그래서이 접지면을 칠 구속하고 하향식 (top-down)을 찾고 있어요 알고는, 그러나 나는 지상 비행기에 물건이 누워있어, 나는 그들을 만질 수 없을 것 같습니다! 모든 포인터를 크게 주시면 감사하겠습니다 :)

답변

0

내가 왜 객체를 만질 수 없었는지 알았어. 객체를 그릴 때 객체를 스케일링하고 있기 때문에 이전에 같은 값으로 뷰 매트릭스를 스케일해야했다. 나는 3 차원의 세계로 내 터치 점을 예상 (EDIT 나는 또한 btRayFrom 및 btRayTo 입력 cooordinates, 그것은 수정되었습니다 반전했다) :

//top of code 
int kObjectScale = 100.0f 
.... 
... 
//inside touch handler method 
SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,&modelViewMatrix.data[0]); 
    projectTouchPointsForBullet(QCAR::Vec2F(touch1.tapX, touch1.tapY), lineStart, lineEnd,inverseProjMatrix, modelViewMatrix); 
    btVector3 btRayFrom = btVector3(lineStart.data[0], lineStart.data[1], lineStart.data[2]); 
    btVector3 btRayTo = btVector3(lineEnd.data[0], lineEnd.data[1], lineEnd.data[2]); 

내 터치가 제대로 이제 예상된다 :)

관련 문제