x40*_*000 8 c# translation matrix slimdx
好的,这应该是一个简单的矩阵问题,但我对矩阵的理解有些局限.这是场景:我有一个1px乘1px的精灵,我希望按比例缩放x和y(每边不同的数量),然后我想将该精灵旋转一定角度,然后我希望能够精确定位整个事物(从左上角或中心,对我没有任何影响).
到目前为止,我的代码模糊地接近,但是根据我传入的角度,它往往会偏离一些随机数量.
我认为这样做会:
Point center = new Point( 50, 50 );
float width = 60;
float height = 100;
float angle = 0.5;
Vector3 axis = new Vector3( center.X, center.Y, 0 );
axis.Normalize();
Matrix m = Matrix.Scaling( width, height, 0 ) *
Matrix.RotationAxis( axis, angle ) *
Matrix.Translation( center.X, center.Y, 0 );
Run Code Online (Sandbox Code Playgroud)
但它倾向于缩小旋转线的缩小比例,尽管我认为它的定位是正确的.
我也试过这个:
Matrix m = Matrix.Transformation2D( new Vector2( center.X, center.Y ), 0f,
new Vector2( width, height ), new Vector2( center.X, center.Y ),
angle, Vector2.Zero );
Run Code Online (Sandbox Code Playgroud)
线看起来完全正确,具有完全正确的尺寸和形状,但我根本无法正确定位.如果我在上面的调用结束时使用翻译向量,或者如果我使用Sprite.Draw设置位置,则无法正常工作.
这一切都在SlimDX中.我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
32736 次 |
| 最近记录: |