src/ldObjectMath.cpp

changeset 944
1a6f1997fcbe
parent 869
7184f3bae695
child 945
c310073e4f22
equal deleted inserted replaced
943:af81220741d9 944:1a6f1997fcbe
39 sinangle = sin (angle); 39 sinangle = sin (angle);
40 40
41 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 41 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2
42 Matrix transform ( 42 Matrix transform (
43 { 43 {
44 (l* l * (1 - cosangle)) + cosangle, 44 (l * l * (1 - cosangle)) + cosangle,
45 (m* l * (1 - cosangle)) - (n* sinangle), 45 (m * l * (1 - cosangle)) - (n * sinangle),
46 (n* l * (1 - cosangle)) + (m* sinangle), 46 (n * l * (1 - cosangle)) + (m * sinangle),
47 47
48 (l* m * (1 - cosangle)) + (n* sinangle), 48 (l * m * (1 - cosangle)) + (n * sinangle),
49 (m* m * (1 - cosangle)) + cosangle, 49 (m * m * (1 - cosangle)) + cosangle,
50 (n* m * (1 - cosangle)) - (l* sinangle), 50 (n * m * (1 - cosangle)) - (l * sinangle),
51 51
52 (l* n * (1 - cosangle)) - (m* sinangle), 52 (l * n * (1 - cosangle)) - (m * sinangle),
53 (m* n * (1 - cosangle)) + (l* sinangle), 53 (m * n * (1 - cosangle)) + (l * sinangle),
54 (n* n * (1 - cosangle)) + cosangle 54 (n * n * (1 - cosangle)) + cosangle
55 }); 55 });
56 56
57 // Apply the above matrix to everything 57 // Apply the above matrix to everything
58 for (LDObjectPtr obj : objects) 58 for (LDObject* obj : objects)
59 { 59 {
60 if (obj->numVertices()) 60 if (obj->numVertices())
61 { 61 {
62 for (int i = 0; i < obj->numVertices(); ++i) 62 for (int i = 0; i < obj->numVertices(); ++i)
63 { 63 {
66 obj->setVertex (i, v); 66 obj->setVertex (i, v);
67 } 67 }
68 } 68 }
69 elif (obj->hasMatrix()) 69 elif (obj->hasMatrix())
70 { 70 {
71 LDMatrixObjectPtr mo = obj.dynamicCast<LDMatrixObject>(); 71 LDMatrixObjectPtr mo = dynamic_cast<LDMatrixObject*> (obj);
72 72
73 // Transform the position 73 // Transform the position
74 Vertex v = mo->position(); 74 Vertex v = mo->position();
75 RotateVertex (v, rotpoint, transform); 75 RotateVertex (v, rotpoint, transform);
76 mo->setPosition (v); 76 mo->setPosition (v);
78 // Transform the matrix 78 // Transform the matrix
79 mo->setTransform (transform * mo->transform()); 79 mo->setTransform (transform * mo->transform());
80 } 80 }
81 elif (obj->type() == OBJ_Vertex) 81 elif (obj->type() == OBJ_Vertex)
82 { 82 {
83 LDVertexPtr vert = obj.staticCast<LDVertex>(); 83 LDVertexPtr vert = static_cast<LDVertex*> (obj);
84 Vertex v = vert->pos; 84 Vertex v = vert->pos;
85 RotateVertex (v, rotpoint, transform); 85 RotateVertex (v, rotpoint, transform);
86 vert->pos = v; 86 vert->pos = v;
87 } 87 }
88 } 88 }

mercurial