2014-05-18 7 views
0

안녕하세요 저는 XNA 4.0에서 개미에 대해 약간의 RPG를 작성하고 있습니다. LoadModel 클래스를 fbx 모델로드로 만들고 경계 영역을 작성했습니다. 모델 메쉬를 병합하여 만든 모델에 하나의 일반적인 경계 구가 있습니다. 이제 게임에서 내 영역을 나타내는 추가 구형 모델을 만들었습니다. 메쉬 이름이 "BoundingSphere"인지 확인하고 메쉬를 추가 할 때 BoundingSphere를 bs 배열에 추가합니다. 지금 내가 그 학사를 업데이트하는 방법을 지금 해달라고 ... 내 코드 시도 :BoundingSphere 업데이트

private void buildBoundingSphere() 
    { 

     BoundingSphere sphere = new BoundingSphere(Vector3.Zero, 0); 
     List<BoundingSphere> spheres = new List<BoundingSphere>(); 
     foreach (ModelMesh mesh in Model.Meshes) 
     { 
      if (mesh.Name.Contains("BoundingSphere")) 
      { 
       BoundingSphere transformed = mesh.BoundingSphere.Transform(modelTransforms[mesh.ParentBone.Index]) 
      spheres.Add(transformed); 
      sphere = BoundingSphere.CreateMerged(sphere, transformed); 

      } 
     } 


     this.boundingSphere = sphere; 
     this.spheres = spheres.ToArray(); 
    } 

을 지금 BoundingSphere 배열이 얻을/세트 :

public BoundingSphere[] spheres 
    { 

     get 
     { 
      // No need for rotation, as this is a sphere 
      List<BoundingSphere> spheres = new List<BoundingSphere>(); 
      foreach (ModelMesh mesh in Model.Meshes) 
      { 
       Matrix worldTransform = Matrix.CreateScale(Scale)* Matrix.CreateTranslation(Position); 

       if (mesh.Name.Contains("BoundingSphere")) { 

       BoundingSphere transformed = mesh.BoundingSphere.Transform(worldTransform); 
       spheres.Add(transformed); 
       } 
      } 

      return spheres.ToArray(); 
     } 
     set{} 
    } 

내가 모델의 2 구를 가지고 있고, 모두 그들도 같은 장소에있다. 힌트를 제공해서 감사합니다.

답변

0

세터는 비어 있습니다. 자동 생성 설정 도구를 사용하는 경우 set{} 대신 을 사용하십시오. 따라서 buildBoundingSphere()에서하는 모든 작업이 손실 된 것으로 보입니다. 먼저 확인하십시오.

또 다른 사소한 문제는 경계 구형 누산기가 원점의 한 점으로 시작한다는 것입니다. 이것은 근원이 최종 구체 안에 있다고 가정하는데, 이는 일반적으로 사실이 아닙니다. 첫 번째 구체를 알고 나면 실제로 시작 영역을 생성해야합니다.

이 스 니펫에서 더 이상 내용을 알 수 없습니다. getter에있는 모든 영역을 변형하려고한다면 객체의 현재 변환에 의한 것입니까? Scale과 Position은 구를 변형하는 메쉬에 의존하지 않는 것처럼 보이므로 worldTransform 행렬의 생성은 루프 외부로 이동할 수 있습니다.