XNA 天空盒的傻瓜版实现方法
额
天空是必不可少的.
所以说,一种傻瓜实现方法
1、下载大地无敌做好拆好UV的天空盒.X模型!
点此下载
或201003182308011327.rar
2、解压加入到Content里!
3、写代码把它画出来!
model变量请读入Skybox.X模型
texture是你画的贴图~当然也可以用大地无敌画的sky1.png!
Model model;
Texture2D texture;
在Draw函数这样写!
GraphicsDevice.RenderState.DepthBufferEnable = false;//禁用深度测试,避免挡住后面的物体!
GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
Matrix[] skytransforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(skytransforms);
foreach (ModelMesh mesh in model.Meshes)
{
// This is where the mesh orientation is set, as well as our camera and projection.
foreach (BasicEffect effect in mesh.Effects)
{
effect.TextureEnabled = true;
effect.Texture = texture;
effect.AmbientLightColor = new Vector3(1, 1, 1);//仅开启环境光
effect.World = skytransforms[mesh.ParentBone.Index]
* Matrix.CreateScale(2000.0f)
* rotationMatrix
* Matrix.CreateTranslation(赋予相机位置);
effect.View = 赋予相机的观察矩阵;
effect.Projection = 赋予相机的投影矩阵;
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
要自己画贴图,这里有天空盒模型的UV图,在框框里画就可以了!
只用单幅贴图,貌似贴图空间浪费比较大,但使用一个贴图很好绘画!,不容易画得衔接不上!
效果图
Comments
Hi,非常感谢你的资源~
大地无敌 于 3/23/2010 10:15:24 PM 回复客气客气~~
Comments were from migrated old data. I am too lazy so you can't add new comments yet. Sorry!