2012-11-26 19 views
2

我想知道下面使用的方法是在繪製屏幕之前確定模型位置的正確方法。 因爲當我想創建一個複製我的模型的地板。我發現自己面臨着「Z戰鬥」問題^^。在xna項目中配置模型/紋理位置的最佳方法是什麼

非常感謝你

代碼示例ST位置上我的模型繪製前:

model_Position.X = (float) 1.0; 
model_Position.Z = (float) 3.0; 
model_Position.Y = (float) 5.0; 

// Draw the model. A model can have multiple meshes, so loop. 
foreach (ModelMesh mesh in model_ground_land1.Meshes) 
{ 
    // This is where the mesh orientation is set, as well 
    // as our camera and projection. 
    foreach (BasicEffect effect in mesh.Effects) 
    { 
     effect.EnableDefaultLighting(); 
     effect.World = transforms[mesh.ParentBone.Index] * 
    Matrix.CreateRotationY(model_Rotation) * Matrix.CreateTranslation(model_Position); 
     effect.View = View; 
     effect.Projection = Projection; 
    } 
    // Draw the mesh, using the effects set above. 
    mesh.Draw(); 
} 

回答

0

據我所看到的,你的方法是用於定位模型是正確的。在Z戰鬥問題中,當兩個3D面在同一平面上相互重疊時,會出現這種情況。正如你所說你「複製你的模型」,這聽起來像是這個問題,而不是模型定位本身。要解決戰鬥,您可以在繪製模型的第二個副本之前將某個非零值設置爲GraphicsDevice.RasterizerState.DepthBias。從documentation

「多邊形具有高的z偏壓值出現在同一個 低值多邊形的前面,而不需要分揀繪製順序。例如, 多邊形爲1的值顯示在前面。的值爲 0的多邊形。「

+0

thanksss man ;-)!你的權利 –

相關問題