本系列文章由 net_assassin 整理编写,转载请注明出处。
http://blog.csdn.net/net_assassin/article/category/1100363
作者:net_assassin 邮箱: net_assassin@hotmail.com 期待着与志同道合的朋友们相互交流
这一章我们学习使用Direct3D矩阵及一个极为方便D3DX助手函数来旋转、缩放及平移精灵。
2D变换
ID3DXSprite可以处理变换矩阵是它的迷人之处。
介绍完成这些功能的变换函数:
D3DXMATRIX *D3DXMatrixTransformation2D(
D3DXMATRIX *pOut,
CONST D3DXVECTOR2 *pScalingCenter,
FLOAT pScalingRotation,
CONST D3DXVECTOR2 *pScaling,
CONST D3DXVECTOR2 *pRotationCenter,
FLOAT Rotation,
CONST D3DXVECTOR2 *pTranslation
);
这个函数生成一个实际上通过引用来传递的矩阵(第一个参数),然后填满矩阵值返回给用户。
在得到这个矩阵之后,我们就可以告诉精灵对象(ID3DXSprite)依据它来作为当前的变换:
spriteobj->SetTransform(&mat); //假设得到的矩阵是mat。
Rotate_Scale_Demo程序(绘制简单精灵):
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 );
}
Rotate_Animate_Demo(绘制动画精灵,使用Sprite_Animate()):
分享到:
相关推荐
这资源是与博文中讲解内容配套的源代码。3D模型渲染部分
directx11 游戏编程入门 PDF
DirectX 10 3D游戏编程入门.pdf
DirectX+10+3D游戏编程入门
很好的directx游戏编程入门教程,特别适用于初学者。下下来看看吧!
DirectX游戏编程,PDF文档,方便大家学习
游戏编程入门 directx C++ 课件 代码 第二2课游戏编程入门 directx C++ 课件 代码 第二2课游戏编程入门 directx C++ 课件 代码 第二2课
最新英文版DirectX11,与DirectX9差别较大,C++语言描述, 适合新手入门及已入门查阅。
DirectX.11游戏编程入门
DirectX游戏开发入门.pdf
DirectX 10 3D游戏编程入门.pdf
DirectX3d 游戏编程入门 3D红龙 DirectX3d 游戏编程入门 3D红龙
DirectX11游戏编程入门(中文版)(word+pdf)
这是Jim Adams的《Programming Role Playing Games with DirectX》第二版的中文版的第二部分。一共两部分。
《游戏编程入门(原书第3版)》涵盖了使用DirectX编写代码创建2D和3D游戏所需的所有技能,而读者只需基本掌握C++语言即可学会游戏的每个元素都按部就班地在书中讲授——从学习如何创建简单的Windows程序,到使用关键的...
游戏编程入门 directx C++ 课件 代码 第二2课游戏编程入门 directx C++ 课件 代码 第二2课
本书首先介绍Windows和DirectX编程,然后快速介绍游戏编程的工具箱,包括使用C++和DirectX开发游戏所需的所有基础知识。读者将学习到把思想转化为现实所需的技术,比如2D、3D图形的绘制、背景卷动、处理游戏输入、...
DirectX游戏入门书籍,想要学习的小伙伴快来下载吧