我很愚蠢到3D,就像我的問題可能是:WPF AxisAngleRotation3D與XNA CreateFromAxisAngle
我做了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)過,但沒有運氣的東西drawed在屏幕上總是不同的旋轉。所以我猜我會問這裏的大腦如果他們知道什麼數學我要把兩種技術之間。
在此先感謝。
編輯:我在其他論壇詢問過我的細節。我複製/他們在這裏貼過 的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();
}
}
就是這樣。我仍然認爲這是一些轉換,而不是繪圖代碼。沒有其他地方改變了立場。我猜想,矩陣就像WPF堆棧變換 - 我的問題是,我不知道兩者之間的數學轉換。 WPF代碼完美地工作,該區域中的模型顯示出良好。 XNA代碼不知何故,因爲Inicializálás()從x,y,z等轉換錯誤。在裏面。在這我需要幫助。
在此先感謝。
忘記添加:XNA 3.1 - 但我猜在這種情況下,它不是一個biggy – 2010-12-03 11:21:25