首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请教一下这个图像里顶点进行旋转的原理是如何样的呢

2012-03-23 
请问一下这个图像里顶点进行旋转的原理是怎么样的呢?RT,这个是工程代码的一部分,输入参数x,y,w,h,centerX,

请问一下这个图像里顶点进行旋转的原理是怎么样的呢?
RT,这个是工程代码的一部分,输入参数x,y,w,h,centerX,centerX应该分别是坐标点的x,y,宽高和中点坐标,

C/C++ code
void Rotate(x,y,w,h,centerX,centerX ....){                 short vertices[] =         {            x ,    y,            x + w, y,            x + w, y + h,            x,     y,            x + w, y + h,            x,     y + h        };        if(rotation != 0)        {            TransformVertices(vertices, -centerX, -centerY);            RotateVertices(vertices, rotation);            TransformVertices(vertices, centerX, centerY);        }}void TransformVertices(short* vertices, int x, int y){    for(int i = 0; i < 12; i+=2)    {        vertices[i] += x;        vertices[i+1] += y;    }}void RotateVertices(short* vertices, float rotation){    //x1 = x*cosA - y*sinA    //y1 = x*sinA + y*cosA    double _A = DEGREES_TO_RADIANS(rotation);    double sinA = sin(_A);    double cosA = cos(_A);    for(int i = 0; i < 12; i+=2)    {        GLshort x = vertices[i];        GLshort y = vertices[i + 1];        vertices[i] = x * cosA - y * sinA;        vertices[i+1] = x * sinA + y * cosA;    }}


我没看懂为什么要这样计算旋转,但是我之所以要修改它是因为当角度不是90,180,270和360这样的特殊角度时候 会有误差,所以 求指教更好的旋转方法

[解决办法]
几何计算啊

热点排行