gpt4 book ai didi

c# - xna 3d bullet bath 和 draw 方法出了问题

转载 作者:行者123 更新时间:2023-11-30 12:16:13 25 4
gpt4 key购买 nike

我正在设计一个 3D 游戏,在这个游戏中,我在宇宙飞船后面安装了一个摄像头,可以四处移动。我在游戏中也添加了一些小行星,我想添加子弹。我用四元数来控制宇宙飞船的路径和它后面的相机。然而,当我在子弹上使用相同的四元数(特定的旋转以便我可以计算子弹的路径)时,我得到了一个非常有趣的效果并且路径完全错误。关于为什么会发生这种情况的任何想法?

public void Update(GameTime gameTime)

{
lazerRotation = spaceship.spaceShipRotation;

Vector3 rotVector = Vector3.Transform(new Vector3(0, 0, -1), lazerRotation);


Position += rotVector* 10 * (float)gameTime.ElapsedGameTime.TotalSeconds;
//

}
//spaceShipRotation = Quaternion.Identity;
//Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), leftRightRot) * Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRot);
//spaceShipRotation *= additionalRot;
//Vector3 addVector = Vector3.Transform(new Vector3(0, 0, -1), spaceShipRotation);
// futurePosition += addVector * movement * velocity;


public void Draw(Matrix view, Matrix projection)
{


// //Quaternion xaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), spaceship.leftrightrot);
// //Quaternion yaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), spaceship.updownrot);
// //Quaternion rot = xaxis * yaxis;
//Matrix x = Matrix.CreateRotationX(spaceship.leftrightrot);
//Matrix y = Matrix.CreateRotationY(spaceship.updownrot);
//Matrix rot = x * y;

Matrix[] transforms = new Matrix[Model.Bones.Count];
Model.CopyAbsoluteBoneTransformsTo(transforms);
Matrix worldMatrix = Matrix.CreateFromQuaternion(lazerRotation) * Matrix.CreateTranslation(Position);



foreach (ModelMesh mesh in Model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{


effect.World = worldMatrix * transforms[mesh.ParentBone.Index]; //position
effect.View = view; //camera
effect.Projection = projection; //2d to 3d

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

请记住,我的宇宙飞船是子弹对象的一个​​场,这就是我获得宇宙飞船的方式。旋转四元数。提前致谢。

最佳答案

您应该连接 effect.World 矩阵,与您当前执行的顺序相反。这不应该影响对象的形状,但会解决其他问题。应该是这样的:

effect.World = transforms[mesh.ParentBone.Index] * worldMatrix;

XNA 是一个行主要框架,串联是从左到右。您的代码(从右到左)是您为 OpenGL 这一列主要框架编写的代码。

关于c# - xna 3d bullet bath 和 draw 方法出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5836111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com