gpt4 book ai didi

c# - WPF AxisAngleRotation3D 与 XNA CreateFromAxisAngle

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:39 27 4
gpt4 key购买 nike

我对 3D 很笨,就像我的问题可能是:

我在 WPF 中制作了一个“查看器”程序,可以在屏幕上呈现内容,以及可以旋转的内容。我用它来轮换适合我的口味:

代码:WPF

Transform3DGroup tg = new Transform3DGroup();
tg.Children.Add(new ScaleTransform3D(sx, sy, 1));
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), rx)));
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), ry)));
tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), rz)));
tg.Children.Add(new TranslateTransform3D(x, y, z));
darabka.Transform = tg;
TeljesModell.Children.Add(darabka);

我决定在 XNA 中编写这个程序,因为它似乎更快一些,但我无法让它工作。

尝试过这种方式(代码,XNA):

Pozició = Matrix.CreateScale(sx, sy, 1f);                          //méretezés
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitX, rx); //forgatás
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitY, ry);
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitZ, rz);
Pozició *= Matrix.CreateTranslation(x, y, z); //középpont

我什至也尝试了 CreateFromYawPitchRoll、CreateRotationX(YZ),但运气不好,屏幕上绘制的内容总是以不同的方式旋转。所以我想我问过这里的大脑他们是否知道我要在这两种技术之间放入什么数学

提前致谢。

编辑:我在其他要求我提供详细信息的论坛上尝试过。我也在这里复制/粘贴它们XNA 代码如下:

主要

...
protected override void LoadContent()
{
t3 = new Airplane(); //this is a "zone" object, having zone regions and zone objects in it. all of them together give the zone itself as a static object, where player walks in
Kamera.Példány.Pozició = new Vector3(1362, 627, -757); //starting pozition in the zone - this is camera position so the player's starting pozition. (camera is FPS)
...
}
...
protected override void Update(GameTime gameTime)
{
...
Kameramozgatása(); //kamera mozgatását vezérlő billentyűk
//this moves the FPS camera around
}
...
protected override void Draw(GameTime gameTime)
{
...
ÁltalánosGrafikaiObjektumok.Effect.View = Kamera.Példány.Idenézünk; //camera views this
ÁltalánosGrafikaiObjektumok.Effect.Projection = projectionMatrix; //... and camera views FROM is set in Kameramozgatása()
...
t3.Rajzolj(); //draw zone object
...
}

区域对象

constructor: set the effect and device to the same as main, set the Pozició (a matrix containing the current position and rotations) to origo
...
public virtual Alapmodel Inicializálás(float x, float y, float z, float rx, float ry, float rz, float sx, float sy)
{
//this initializer starts when the coordinates are from a file and not set with Pozició = Matrix....., so we are to convert. this runs only one time. overrides set the vertex positions and textures
VertexDeclaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);
Pozició = Matrix.CreateScale(sx, sy, 1f); //méretezés
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitX, rx); //forgatás
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitY, ry);
Pozició *= Matrix.CreateFromAxisAngle(Vector3.UnitZ, rz);
Pozició *= Matrix.CreateTranslation(x, y, z); //középpont
//we set the starting position - nowhere else we do it, from here only the main loop can modify this,... could.. but does not. this is zone, and has only static objects - never moving
}
public void Rajzolj()
{
//this draws the object (what can be a zone or a static object in it)
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
foreach (Elem elem in Elemek)
{
//végigmegyünk az elemeken
effect.Texture = elem.Textúra;

//pozicionálás
effect.World = Pozició; //we take the initialized position

effect.CommitChanges(); //this is needed. if you do not use this, the textures will be screwed up
device.VertexDeclaration = VertexDeclaration;
device.DrawUserIndexedPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, Poziciók, 0, Poziciók.Length, elem.Indexek, 0, elem.Indexek.Length / 3);
}
pass.End();
}
}

就是这样。我仍然猜测这是一些转换而不是绘图代码。其他地方的位置都没有改变。我猜想矩阵就像 WPFs 堆叠变换一样——我的问题是我不知道在两者之间转换的数学。 WPF 代码完美运行,区域中的模型显示良好。 XNA 代码在某种程度上是错误的,因为 Inicializálás() 从 x、y、z 等进行了错误的转换。在里面。在这方面我确实需要帮助。

提前致谢。

最佳答案

我建议不要以这种方式以角度方式存储您的方向...

但有时您的问题可以在 xna 版本中解决,只需先应用 Z 旋转,然后 X,然后 Y。

关于c# - WPF AxisAngleRotation3D 与 XNA CreateFromAxisAngle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345007/

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