C# 地图旋转(天空盒)XNA
我有一个控件中包含xna的窗口窗体,现在我在屏幕的一个区域中有两个模型。问题是我需要同时旋转两个模型,我可以旋转一个对象,其中一个是坦克,另一个是渲染在盒子中的天空盒(风景)C# 地图旋转(天空盒)XNA,c#,winforms,3d,xna,skybox,C#,Winforms,3d,Xna,Skybox,我有一个控件中包含xna的窗口窗体,现在我在屏幕的一个区域中有两个模型。问题是我需要同时旋转两个模型,我可以旋转一个对象,其中一个是坦克,另一个是渲染在盒子中的天空盒(风景) orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f), MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2)); 坦
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
坦克移动时使用串口提供的数据,串口是实时的,坦克可以完美地移动,但我无法旋转地图
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
(地面应随油箱移动)
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
我使用以下代码渲染风景:
private void SkyBoxRender()
{
RasterizerState originalRasterizerState = GraphicsDevice.RasterizerState;
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;
aspectRatio = GraphicsDevice.Viewport.AspectRatio;
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f), MathHelper.ToRadians(TiempoReal.rollPitch[1]), MathHelper.ToRadians(TiempoReal.rollPitch[0]));
cameraPositionSkyBox = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
foreach (EffectPass pass in skyBoxEffect.CurrentTechnique.Passes)
{
pass.Apply();
foreach (ModelMesh mesh in skyBox.Meshes)
{
foreach (ModelMeshPart part in mesh.MeshParts)
{
part.Effect = skyBoxEffect;
part.Effect.Parameters["World"].SetValue(Matrix.CreateScale(50.0f) * Matrix.CreateTranslation(cameraPositionSkyBox));
part.Effect.Parameters["View"].SetValue(view);
part.Effect.Parameters["Projection"].SetValue(Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f));
part.Effect.Parameters["SkyBoxTexture"].SetValue(skyBoxTexture);
part.Effect.Parameters["CameraPosition"].SetValue(cameraPositionSkyBox);
}
mesh.Draw();
}
}
GraphicsDevice.RasterizerState = originalRasterizerState;
}
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
我认为问题出在行部分。Effect.Parameters[“World”]。SetValue。。。。。
我不知道该放什么来让地图用所有的轴旋转
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
我使用以下代码旋转油箱:
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
如果你看第二行,你会注意到我用角度来旋转油箱(它必须是这样…),有什么想法或建议吗
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
更新:
如何解决
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
在SkyBoxRender方法中,我添加了以下内容:
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
orientacionCamara = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(0.0f), MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
然后,我使用以下命令在地图中移动相机:
part.Effect.Parameters[“View”].SetValue(矩阵.CreateLookAt(yourCameraPosition)*orientacionCamara)
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
现在,以与模型相同的角度同时移动摄影机,我旋转模型,而不是此时的摄影机
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
private void BeginRender3D()
{
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
Matrix[] transforms = new Matrix[modelo.Bones.Count];
modelo.CopyAbsoluteBoneTransformsTo(transforms);
**orientacion** = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f), MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2);
foreach (ModelMesh mesh in modelo.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = transforms[mesh.ParentBone.Index] * **orientacion**; //* orientacion
effect.View = Matrix.CreateLookAt(camaraPosicion, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
}
mesh.Draw();
}
fps++;
}
我希望它能对任何人都有帮助,谢谢大家的建议。你可以通过将SkyboxeEffect中的世界参数乘以“orientation”来旋转地图。但是,您必须确保它围绕油箱位置旋转,将整条管线更改为:
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
part.Effect.Parameters[“World”].SetValue(矩阵.CreateScale(50.0f)*矩阵.createtranslation(TankPosition)*方向*矩阵.createtranslation(cameraPositionSkyBox-TankPosition))代码>
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
假设“坦克位置”是你坦克的位置
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
我不确定你想达到什么目的,但是如果你想模拟在坦克周围旋转摄像机,我会通过设置
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
view=matrix.CreatePerspectiveFieldOfView()
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));
请在此处阅读:对不起,我没有看到任何大写字母,也许我的键盘配置可能会对您造成问题?谢谢你的建议,我是新来的。这不是答案,而是建议。不再发展。我建议转到Unity,它目前正蓬勃发展,开箱即用,可以处理游戏的许多方面,例如skybox。感谢您的建议,我知道xna已经不再开发,但我必须使用窗口窗体,最简单的方法是尝试从xna集成一个控件渲染。。。unity支持windows窗体吗?或者我必须重新考虑我的计划?提前谢谢。这似乎是可能的。快速谷歌搜索确认非常感谢你的朋友,你给了我光明,现在我更新了答案
orientacion = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(-85.0f),
MathHelper.ToRadians(floatAngle1), MathHelper.ToRadians(floatAngle2));