关于D3DXMatrixTransformation2D函数的问题,请大家帮忙看一下,谢谢

wht525097920 2011-10-07 03:39:55
void Sprite_Transform_Draw(LPDIRECT3DTEXTURE9 image, int x, int y, int width, int height,
int frame, int columns, float rotation, float scaling, D3DCOLOR color)
{
//create a scale vector
D3DXVECTOR2 scale( scaling, scaling );

//create a translate vector
D3DXVECTOR2 trans( x, y );

//set center by dividing width and height by two
D3DXVECTOR2 center( (float)( width * scaling )/2, (float)( height * scaling )/2);

//create 2D transformation matrix
D3DXMATRIX mat;
D3DXMatrixTransformation2D( &mat, NULL, 0, &scale, ¢er, rotation, &trans );

//tell sprite object to use the transform
spriteobj->SetTransform( &mat );

//calculate frame location in source image
int fx = (frame % columns) * width;
int fy = (frame / columns) * height;
RECT srcRect = {fx, fy, fx + width, fy + height};

//draw the sprite frame
spriteobj->Draw( image, &srcRect, NULL, NULL, color );
}
这段代码使一个物体旋转伸缩,但是物体缩放时是以物体左上角的左边为中心缩放的,请问一下能不能是它按照物体的中心为中心点进行缩放。
...全文
196 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wht525097920 2011-10-07
  • 打赏
  • 举报
回复
我现在还是direct初学者,楼上的那个函数还不会用,如果可以的话还是想先用D3DXMatrixTransformation2D把问题解决掉。
顺便说一下我刚有研究了一下,把D3DXMatrixTransformation2D中的第二个设置缩放中心点的参数给出后,再把旋转关掉就可以成功了,可把缩放和旋转一起运作里面的物体就又会满屏幕乱窜,麻烦大家再帮帮忙,谢谢
星羽 2011-10-07
  • 打赏
  • 举报
回复
或者
你制定缩放中心看

D3DXMatrixTransformation2D( &mat, ¢er, 0, &scale, ¢er, rotation, &trans );
星羽 2011-10-07
  • 打赏
  • 举报
回复
用这个函数
D3DXMatrixAffineTransformation2D
wht525097920 2011-10-07
  • 打赏
  • 举报
回复
是的,但是好像不是简单的给个坐标就行的,搞不好会把其他的给弄乱
lirunfa 2011-10-07
  • 打赏
  • 举报
回复
第二个参数是缩放的中心?

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧