【发布时间】:2012-11-26 17:35:48
【问题描述】:
我想知道在 XNA 中是否可以无限次重复地面模型。例如在这个示例中 http://create.msdn.com/en-US/education/catalog/sample/chasecamera ?
【问题讨论】:
我想知道在 XNA 中是否可以无限次重复地面模型。例如在这个示例中 http://create.msdn.com/en-US/education/catalog/sample/chasecamera ?
【问题讨论】:
简单的答案是否定的。如果您尝试绘制无限数量的多边形,不仅您的内存会耗尽并且您的程序崩溃,而且硬件将花费无限的时间来渲染场景。
为了解决这个问题,游戏开发者使用天空盒和无法到达的地形等技巧让玩家认为世界是无限的。因此,如果您想要一个具有重复地面纹理的有限世界,只需在网格中多次绘制地面纹理,然后放置一个覆盖地面外边缘的天空盒。
如果你真的想要一个无限的世界,你可以做一个让天空盒和地面随你移动的技巧。所以只需将地面和天空盒的速度设置为正在移动的精灵的速度。
【讨论】:
像这样!这是我的定制样品。您可以从具有不同纹理的矩阵索引中重复模型
//Draw a ground land
private void draw_groundLand1(int[,,] MatriceWorldCube,Vector3 position_model_origin)
{
int hauteur = MatriceWorldCube.GetLength(0);
int largeur = MatriceWorldCube.GetLength(1);
int longueur = MatriceWorldCube.GetLength(2);
Vector3 pos_reference = position_model_origin;
for (int epaisseur = 0; epaisseur < hauteur; epaisseur++)
{
for (int collone = 0; collone < largeur; collone++)
{
for (int ligne = 0; ligne < longueur ; ligne++)
{
//Vérifie si l'index de la matrice comporte bien un matériaux a placer
if (MatriceWorldCube[epaisseur, collone, ligne] != 0)
{
// Copy any parent transforms.
Matrix[] transforms = new Matrix[model_ground_land1.Bones.Count];
model_ground_land1.CopyAbsoluteBoneTransformsTo(transforms);
// 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(cubeGroundLand1_modelRotation) * Matrix.CreateTranslation(position_model_origin);
effect.View = View;
effect.Projection = Projection;
//Applique la texture en fonction du type de matière définit dans l'indice de la matrice
switch (MatriceWorldCube[epaisseur, collone, ligne])
{
case 1:
effect.Texture = text_ground_land1;
break;
case 2:
effect.Texture = text_ground_land2;
break;
default:
break;
}
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
}
position_model_origin.X = (float)(ligne+1);
}
position_model_origin.X = pos_reference.X;
position_model_origin.Z = (float)(collone+1);
}
position_model_origin.Z = pos_reference.Z;
position_model_origin.Y = (float)(epaisseur+1);
}
position_model_origin.Y = pos_reference.Y;
position_model_origin = pos_reference;
}
【讨论】: