posts | comments
28Mar

Поворот площини за допомогою миші

No comments
« Математичне завдання прямій на площині   |   Вектори в просторі Однорідні координати Матриці перетворень »


inline void set(vec_float xx, vec_float yy)

{

x = xx;

у = yy;

}

inline vec operator + (vec t) // складання

{

return vec(x + t.x, у + t.y);

}

inline vec operator - (vec t) // віднімання

{

return vec(x - t.x, у - t.y);

}

inline vec operator * (vec_float t) // твір на число

{

return vec(x * t, у * t);

}

inline vec_float operator * (vec t) // скалярний твір

{

return x * t.x + у * t.y;

}

inline vec_float operator ^ (vec t) // довжина результату векторного твору з урахуванням напряму

{

return x * t.y - у * t.x;

}

inline vec_float length() // довжина вектора

{

return sqrt(x * x + у * у);

}

inline vec unit() // нормалізація вектора

{

vec_float l = length();

if (l == 0.0f) return vec(0.0f, 0.0f);

return vec(x / l, у / l);

}

inline bool zero() // визначає чи нульовий вектор

{

return (x == 0.0f) && (у == 0.0f);

}

inline bool equals(vec t) // перевіряє вектора на точний збіг

{

return (x == t.x) && (у == t.y);

}

};

Тепер створимо клас, який відповідає за поворот:

Rotation::Rotation()

{

CurrentMatrix[0]= 1;

CurrentMatrix[1]= 0;

CurrentMatrix[2]= 0;

CurrentMatrix[3]= 1;

}

void Rotation::InitRotation(int x, int у)

{

old_mouse.set(x, у);

old_mouse = old_mouse.unit();

}

void Rotation::Rotate(int x, int у)

{

vec new_mouse(x, у);

vec_float sina, cosa;

new_mouse = new_mouse.unit();

sina = new_mouse ^ old_mouse;

cosa = new_mouse * old_mouse;

Matrix Rot;

SetRotationMatrixbySinCos(sina, cosa, Rot);


Tags: , , , , , , , ,

2D теорія


Схожі записи

Categories: 2D теорія

Saturday, March 28th, 2009 at 09:15 and is filed under 2D теорія. You can follow any responses to this entry through the feed. Both comments and pings are currently closed.