2013-05-04 5 views
0

업 벡터를 사용하여 메쉬의 충돌 벡터를 가져 오려고합니다.C# Direct X 9.0c - 메쉬 교차점

나는 위치와 업 벡터를 가지고 ..이 부스와 내가 할 경우

public Vector3 SetPlayerToGround(Matrix Object, Matrix Player, Mesh GroundObject) 
     { 

      Vector3 IntersectVector = new Vector3(0, 0, 0); 

      if (GroundObject != null) 
      { 
       Vector3 Player_UP = new Vector3(Player.M12, Player.M22, Player.M32); 
       Vector3 PlayerPos = new Vector3(Player.M14, Player.M24, Player.M34); 
       Vector3 PlayerPos_Far = PlayerPos - Player_UP ; 

       gameengine.m_Device.Transform.World = Object; 


       IntersectInformation closestIntersection; 



       if (GroundObject.Intersect(PlayerPos, PlayerPos_Far, out closestIntersection)) 
       { 
        IntersectVector = Player_UP + (PlayerPos_Far * closestIntersection.Dist); 

       } 
      } 

      return IntersectVector; 
     } 

그럼 지금까지 벡터를 계산

Vector3 PlayerPos_Far = PlayerPos + Player_UP; 
그는 항상 아무것도 교차합니다

... 을 그러나 내가 교차시키고 자하는 객체는 항상 "위치 -UpVector"아래에있다.

그래서 나는 생각한다.

01 내가 교차하지 못할 이유 23,516,
Vector3 PlayerPos_Far = PlayerPos - Player_UP ; 

rigth입니까? 여기

Image of a Scene where i need the Intersect

는 선수이며 그가 선박에 있습니다 :

여기에 더 나은 설명이다. 플레이어는 세상을 플레이어 주위로 움직이기 때문에 항상 0,0,0에 있습니다. 플레이어를 앞으로 앞으로 움직이면 플레이어 위치 벡터는 다른 모든 물체의 위치 만 가져옵니다. 하지만 플레이어는 인터 섹트와는 아무런 관련이 없습니다.하지만 우주선 자체는 그렇습니다. 나는 위치 0,0,0과 방향으로 upvector를 사용하여 배와 지상의 intersectctor를 얻는다. 당신은 위치에 의해 정의 된 선을 제공해야 나는 그가 늘 선박의 내 번역 매트릭스를 사용하여 생각하고 뭔가를 tryed

Vector3 com = ship.position - gamemanager.player.position; 
        Matrix world; 
        world = Matrix.Identity * Matrix.Scaling(0.001f, 0.001f, 0.001f) * Matrix.Translation(com); 
        m_Device.Transform.World = world; 

...

답변

0

: 선박의 매트릭스 (Matrix 객체)입니다 및 방향. 두 점을 지정할 필요가 없습니다. 따라서 PlayerPos_Far 대신 -PLAYER_UP을 전달하십시오.

또한 Intersect 메서드는 변환에 신경 쓰지 않습니다. 광선을 미리 변환해야합니다. 광선의 위치와 방향을 반전 된 월드 행렬 (세계 공간에서 모델의 공간으로 변환)으로 변환하면됩니다.

Vector3 rayStart = PlayerPos; 
Vector3 rayDir = -PLAYER_UP; 
Matrix world; //the ship's world matrix 
world = Matrix.Invert(matrix); 
rayStart = Vector3.TransformCoordinate(rayStart, world); //you may need to add an out parameter 
rayDir = Vector3.TransformNormal(rayDir, world); 
GroundObject.Intersect(rayStart, rayDir, ... 
+0

글쎄, 나는 방향으로 player_up 만 가져 가야한다는 것을 의미합니다. if (GroundObject.Intersect (PlayerPos, Player_UP, out nearestIntersection))). 하지만 난 pretranformation을 unterstand .. 내게 예제를 줄 수 있습니까? – ZeraTFK

+0

수정 된 답변보기 –

+0

고마워요, 작동합니다! Intersect 후에는 일반 오브젝트 Matrix로 IntersectVector를 다시 변환해야합니다. IntersectVector = Vector3.TransformCoordinate (IntersectVector, Object); – ZeraTFK