2010-12-03 6 views
2

내 질문이있을 수 있습니다처럼 3D 꽤 바보입니다 : WPF AxisAngleRotation3D 대 XNA CreateFromAxisAngle

나는 화면에 물건을 렌더링 WPF에서 "뷰어"프로그램을 만들어,뿐만 아니라 무엇을 회전 할 수있다. 그 조금 더 빠른 것 같다 있기 때문에 그러나 나는 그것을 만들 수 없습니다, WPF 내가 XNA에서이 프로그램을하기로 결정

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); 

:

코드 : 내 취향 작동하는 무슨 회전이 사용 작업. 심지어 CreateFromYawPitchRoll이 CreateRotationX (YZ)가 너무하지만, 행운 않고, 물건이 화면은 항상 다르게 회전 한에 drawed 시도

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 

:

이 방법 (코드, XNA를) 시도. 그래서 나는 그들이 두뇌 사이에 끼워 넣어야 할 것이 무엇인지 .

미리 감사드립니다.

편집 : 자세한 내용을 묻는 다른 포럼에서 시도했습니다. 나도 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 코드가 완벽하게 작동하면 영역의 모델이 잘 보입니다. Inicializálás()가 x, y, z 등에서 잘못된 변환을하기 때문에 XNA 코드가 잘못되었습니다. 그 안에. 이것에서 나는 도움이 필요하다.

미리 감사드립니다.

+0

추가하는 것을 잊었 : XNA 3.1 -하지만이 경우에는 그것은 큰 것 같지 않아 –

답변

1

CreateWorld도 사용할 수 있지만 크기 조정이 없으므로이 단계별로 해결하기로했습니다. 먼저 origo로 놓은 다음 크기를 조정 한 다음 크기를 변경 한 다음 크기 조정 및 회전하여 포즈를 취합니다.

학위를 소지 한 경우 학위 대신 라디안을 사용해야합니다. MathHelper.ToRadians()를 사용하면됩니다.

WPF에서 왔지만 여기에서 회전 각도가 작동하고 있지만 여기서 각도가 작동하지 않는 경우 라디안으로 계산하기 전에 각도를 360/512로 곱하십시오. 이 예제를 주석에서 볼 수 있습니다. 모든 rx, ry 및 rz에 사용해야합니다.

 Pozició = Matrix.CreateTranslation(Vector3.Zero);      //alappozíció az origó 
     if (sx != 1 || sy != 1) Pozició *= Matrix.CreateScale(sx, sy, 1f); //méretezés 
     if (rx != 0 || ry != 0 || rz != 0) Pozició *= Matrix.CreateFromYawPitchRoll(
           MathHelper.ToRadians(rx)      //WPFből: MathHelper.ToRadians(rx * 360f/512f) 
           , MathHelper.ToRadians(ry) 
           , MathHelper.ToRadians(rz) 
          ); 
     if (x != 0 || y != 0 || z != 0) Pozició *= Matrix.CreateTranslation(x, y, z);       //középpont 

* 360/512 또는 더 나은 것으로 보이는 형식을 더 빨리 줄 수있는 경우 의견을 말하십시오.

1
내가 각도 방식으로 그런 식으로 당신의 방향을 저장에 대해 조언을

...

그러나 문제는 XNA 버전에서 해결 될 수있는 시간은 간단히, 다음, 첫 번째 Y를 X를 Z 회전을 적용하여이있다

+0

시도했지만 나에게 도움이되지 못했습니다. 나는 회전의 순서라고 생각하지 않습니다. 왜냐하면 CreateFromYawPitchRoll을 한번 시도해 볼 때 모든 회전이 동시에 이루어지기 때문입니다. 이것이 내가 XNA의 입력과 WPF의 입력 사이에서 어떤 변환이라고 생각하는 이유입니다. –

+0

rx, ry 및 rz에서 벗어나서 행렬 또는 쿼터니언에 방향을 저장하면 문제/솔루션이 크게 단순화 될 것이라고 확신하고 싶습니다. 하지만이 논평 섹션의 글자 수 제한이 허용하고 귀하의 질문에 대한 직접적인 대답이 아니므로 그렇게하지 않을 것입니다. 붙어 있어야하는 경우 대체 오리엔테이션 표현을 고려하십시오. –

+0

XNA 코드 샘플의 "pozició"는 행렬 유형입니다. 이제 파일의 다른 소스에서 좌표 및 회전 (스케일링)을 변환합니다. –