Simple rotation problem

Started by
4 comments, last by Horn 19 years, 6 months ago
The problem I'm having is when I rotate a model, it gets squished along the Y-Axis. The way my camera is setup I have it up 5 along the Y-Axis, looking at the origin, and the 'up' of is -1 Z.


//Init

PParams.Windowed = true;
PParams.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
PParams.EnableAutoDepthStencil = true;
PParams.AutoDepthStencilFormat = D3D.DepthFormat.D16;

D3Device = new D3D.Device(0, D3D.DeviceType.Hardware, 
this, 
D3D.CreateFlags.SoftwareVertexProcessing,
PParams);

D3Device.Transform.View = Matrix.LookAtLH(
new Vector3(0.0f, 5.0f, 0.0f), 
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 0.0f, -1.0f));

D3Device.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 4),
 this.Width / this.Height,
 1.0f, 100.0f);


//Drawing
Mat = Matrix.RotationY(Direction);
Device.Transform.World = Mat;
Model.Draw();


Advertisement
I don't think it's a problem with the way the camera is set up.

Other stuff that may be wrong:
Are you doing any scaling or translating anywhere? The order in which you do matrix stuff is very important, otherwise weird things (like squishing) can happen.

Are you making sure the rotation is in Radians? That can mess stuff up too, but won't cause squishing.
Nope. Thats all I do with the matrix stack. The Model.Draw() simply uses a Direct3D.Mesh and draws it.
Could you please maybe do this for me.
Create a method/function called rotate and do

void RotateMesh(){
D3DXMatrixRotationY(...);
Direct3d.pDevice->SetTransform(...);
}
and then call it within your

BeginScene();
EndScene();
The problem goes away if I set my aspect ratio to 1 (in the Matrix.LookAt function) and the window size to square (ex 600x600). So it appears that I'm having a problem with the aspect ratio of the model.

I played with the managed tutorial #6 (the model loading one) and setup the camera so that it was at 0,0,-5 instead of 0,3,-5 and theres the same problem.
I solved the problem. When I was dividing 4 by 3 I was using integers (which would produce 1). I changed it to 4.0f / 3.0f and it works fine.

This topic is closed to new replies.

Advertisement