2011-04-19 4 views
1

OK 얘들 아, 바운더리 포지셔닝에 대한 XNA 문제가 있습니다. 나는 각각의 위치가 정확히 동일하다는 것을 맹세한다 - 나는 심지어 디버거로 확인했지만 그럼에도 불구하고 두 개가 서로 다른 방향으로 나타난다. 이 권리를 얻기 위해 요인을 곱하여 수동으로 조정할 수 있지만 왜이 효과가 나타 납니까?XNA 바운딩 구형과 같은 위치에있는 오브젝트가 다르게 표시됩니다.

경계의 영역 :

protected BoundingSphere CalculateBoundingSphere() 
    { 
     BoundingSphere mergedSphere = new BoundingSphere(); 
     BoundingSphere[] boundingSpheres; 
     int index = 0; 
     int meshCount = Model.Meshes.Count; 

     boundingSpheres = new BoundingSphere[meshCount]; 
     foreach (ModelMesh mesh in Model.Meshes) 
     { 
      boundingSpheres[index++] = mesh.BoundingSphere; 
     } 

     mergedSphere = boundingSpheres[0]; 
     if ((Model.Meshes.Count) > 1) 
     { 
      index = 1; 
      do 
      { 
       mergedSphere = BoundingSphere.CreateMerged(mergedSphere, 
        boundingSpheres[index]); 
       index++; 
      } while (index < Model.Meshes.Count); 
     } 

     mergedSphere.Center = Position; 
     return mergedSphere; 
    } 

    internal void DrawBoundingSphere(Matrix view, Matrix projection, 
GameObject boundingSphereModel) 
    { 
     Matrix scaleMatrix = Matrix.CreateScale(BoundingSphere.Radius); 
     Matrix translateMatrix = 
      Matrix.CreateTranslation(BoundingSphere.Center);//BoundingSphere.Center CHANGED THISSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 

     Matrix worldMatrix = scaleMatrix * translateMatrix; 

     foreach (ModelMesh mesh in boundingSphereModel.Model.Meshes) 
     { 
      foreach (BasicEffect effect in mesh.Effects) 
      { 
       effect.World = worldMatrix; 
       effect.View = view; 
       effect.Projection = projection; 
      } 
      mesh.Draw(); 
     } 
    } 
} 

개체 무승부 :

class Asteroid : GameObject 
{ 
    public bool Destroyed { get; set; } 
    Vector3 m_Rotations; 
    public int rotDir; 

    public Asteroid(int rot) 
     : base() 
    { 
     Destroyed = false; 
     rotDir = rot; 


    } 

    public void LoadContent(ContentManager content, string modelName) 
    { 
     Model = content.Load<Model>(modelName); 
     Position = Vector3.Down; 
    } 
    public void update(GameTime gameTime)//for making asteroid spin 
    { 
     switch (rotDir) 
     { 
      case 0: m_Rotations.Z += (float)gameTime.ElapsedGameTime.TotalSeconds; 
       break; 
      case 1: m_Rotations.X += (float)gameTime.ElapsedGameTime.TotalSeconds; 
       break; 
      case 2 :m_Rotations.Z += (float)gameTime.ElapsedGameTime.TotalSeconds; 
       break; 


     } 
    } 
    public void Draw(Matrix view, Matrix projection) 
    { 
     BoundingSphere = CalculateBoundingSphere(); 

     //Vector3 pos = BoundingSphere.Center; 

     Matrix[] transforms = new Matrix[Model.Bones.Count]; 
     Model.CopyAbsoluteBoneTransformsTo(transforms); 
     Matrix translateMatrix = Matrix.CreateTranslation(Position);//POSITION 
     Matrix worldMatrix = Matrix.Identity; 
     worldMatrix *= Matrix.CreateRotationX(m_Rotations.X);//making asteroid spin 
     worldMatrix *= Matrix.CreateRotationY(m_Rotations.Y);//making asteroid spin 
     worldMatrix *= Matrix.CreateRotationZ(m_Rotations.Z);//making asteroid spin 
     worldMatrix *= translateMatrix; 

     //Matrix worldMatrix = translateMatrix; 

     if (!Destroyed) 
     { 
      foreach (ModelMesh mesh in Model.Meshes) 
      { 
       foreach (BasicEffect effect in mesh.Effects) 
       { 
        effect.World = 
         worldMatrix* transforms[mesh.ParentBone.Index]; //MAKE THIS ROTATE 
        effect.View = view ; 
        effect.Projection = projection; 


        effect.EnableDefaultLighting(); 
        effect.PreferPerPixelLighting = true; 
       } 
       mesh.Draw(); 
      } 
     } 

답변

0

너무 많이 생각하지 않고 Matrix worldMatrix = scaleMatrix * translateMatrix; 뒤로, 그렇지 여기 코드는?

Matrix worldMatrix = translateMatrix * scaleMatrix;이 아니어야합니까?

0

jv42 규칙 말 : SRT : 스케일링 - 회전 - 번역

관련 문제