src/gui_editactions.cpp

changeset 268
778eed342ee4
parent 266
12e7302f14e9
child 269
2d71227f35cb
equal deleted inserted replaced
267:95fde37e1f00 268:778eed342ee4
169 continue; 169 continue;
170 } 170 }
171 171
172 // Create the replacement primitive. 172 // Create the replacement primitive.
173 LDSubfile* prim = new LDSubfile; 173 LDSubfile* prim = new LDSubfile;
174 memcpy (&prim->pos, &rad->pos, sizeof rad->pos); // inherit position 174 prim->setPosition (rad->position ()); // inherit position
175 memcpy (&prim->transform, &rad->transform, sizeof rad->transform); // inherit matrix 175 prim->setTransform (rad->transform ()); // inherit matrix
176 prim->setColor (rad->color ()); // inherit color 176 prim->setColor (rad->color ()); // inherit color
177 prim->fileName = name; 177 prim->fileName = name;
178 prim->fileInfo = file; 178 prim->fileInfo = file;
179 179
180 // Replace the radial with the primitive. 180 // Replace the radial with the primitive.
433 } 433 }
434 434
435 // ============================================================================= 435 // =============================================================================
436 static void doRotate (const short l, const short m, const short n) { 436 static void doRotate (const short l, const short m, const short n) {
437 vector<LDObject*> sel = g_win->sel (); 437 vector<LDObject*> sel = g_win->sel ();
438 vertex origin;
439 vector<vertex*> queue; 438 vector<vertex*> queue;
439 const vertex rotpoint = rotPoint (sel);
440 const double angle = (pi * currentGrid ().confs[Grid::Angle]->value) / 180; 440 const double angle = (pi * currentGrid ().confs[Grid::Angle]->value) / 180;
441 441
442 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2 442 // ref: http://en.wikipedia.org/wiki/Transformation_matrix#Rotation_2
443 const double cosangle = cos (angle), 443 const double cosangle = cos (angle),
444 sinangle = sin (angle); 444 sinangle = sin (angle);
455 (l * n * (1 - cosangle)) - (m * sinangle), 455 (l * n * (1 - cosangle)) - (m * sinangle),
456 (m * n * (1 - cosangle)) + (l * sinangle), 456 (m * n * (1 - cosangle)) + (l * sinangle),
457 (n * n * (1 - cosangle)) + cosangle 457 (n * n * (1 - cosangle)) + cosangle
458 }); 458 });
459 459
460 origin = rotPoint (sel); 460 // Apply the above matrix to everything - first, mark down
461 461 // which vertices to transform
462 // Apply the above matrix to everything
463 for (LDObject* obj : sel) { 462 for (LDObject* obj : sel) {
464 if (obj->vertices ()) 463 if (obj->vertices ())
465 for (short i = 0; i < obj->vertices (); ++i) 464 for (short i = 0; i < obj->vertices (); ++i)
466 queue << &obj->coords[i]; 465 queue << &obj->coords[i];
467 else if (obj->hasMatrix ()) { 466 else if (obj->hasMatrix ()) {
468 LDMatrixObject* mobj = static_cast<LDSubfile*> (obj); 467 LDMatrixObject* mo = static_cast<LDSubfile*> (obj);
469 468 queue << const_cast<vertex*> (&mo->position ()); // TEMPORARY HACK
470 queue << &mobj->pos; 469 mo->setTransform (mo->transform () * transform);
471 mobj->transform = mobj->transform * transform;
472 } else if (obj->getType () == LDObject::Vertex) 470 } else if (obj->getType () == LDObject::Vertex)
473 queue << &static_cast<LDVertex*> (obj)->pos; 471 queue << &static_cast<LDVertex*> (obj)->pos;
474 472
475 g_win->R ()->compileObject (obj); 473 g_win->R ()->compileObject (obj);
476 } 474 }
477 475
476 // Now do the actual transformations
478 for (vertex* v : queue) { 477 for (vertex* v : queue) {
479 v->move (-origin); 478 v->move (-rotpoint);
480 v->transform (transform, g_origin); 479 v->transform (transform, g_origin);
481 v->move (origin); 480 v->move (rotpoint);
482 } 481 }
483 482
484 g_win->refresh (); 483 g_win->refresh ();
485 } 484 }
486 485

mercurial