/source/blender/editors/transform/transform_convert_cursor.c

https://github.com/eliemichel/OpenMeshEffectForBlender · C · 136 lines · 80 code · 25 blank · 31 comment · 8 complexity · acbac0d52ae301eeca3827717d7a59e9 MD5 · raw file

  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software Foundation,
  14. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. *
  16. * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  17. * All rights reserved.
  18. */
  19. /** \file
  20. * \ingroup edtransform
  21. */
  22. #include "DNA_space_types.h"
  23. #include "MEM_guardedalloc.h"
  24. #include "BLI_math.h"
  25. #include "BKE_context.h"
  26. #include "BKE_report.h"
  27. #include "BKE_scene.h"
  28. #include "transform.h"
  29. #include "transform_convert.h"
  30. /* -------------------------------------------------------------------- */
  31. /** \name Cursor Transform Creation
  32. *
  33. * Instead of transforming the selection, move the 2D/3D cursor.
  34. *
  35. * \{ */
  36. void createTransCursor_image(TransInfo *t)
  37. {
  38. TransData *td;
  39. SpaceImage *sima = t->area->spacedata.first;
  40. float *cursor_location = sima->cursor;
  41. {
  42. BLI_assert(t->data_container_len == 1);
  43. TransDataContainer *tc = t->data_container;
  44. tc->data_len = 1;
  45. td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
  46. td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
  47. }
  48. td->flag = TD_SELECTED;
  49. /* UV coords are scaled by aspects (see UVsToTransData). This also applies for the Cursor in the
  50. * UV Editor which also means that for display and when the cursor coords are flushed
  51. * (recalcData_cursor_image), these are converted each time. */
  52. cursor_location[0] = cursor_location[0] * t->aspect[0];
  53. cursor_location[1] = cursor_location[1] * t->aspect[1];
  54. copy_v3_v3(td->center, cursor_location);
  55. td->ob = NULL;
  56. unit_m3(td->mtx);
  57. unit_m3(td->axismtx);
  58. pseudoinverse_m3_m3(td->smtx, td->mtx, PSEUDOINVERSE_EPSILON);
  59. td->loc = cursor_location;
  60. copy_v3_v3(td->iloc, cursor_location);
  61. }
  62. void createTransCursor_view3d(TransInfo *t)
  63. {
  64. TransData *td;
  65. Scene *scene = t->scene;
  66. if (ID_IS_LINKED(scene)) {
  67. BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
  68. return;
  69. }
  70. View3DCursor *cursor = &scene->cursor;
  71. {
  72. BLI_assert(t->data_container_len == 1);
  73. TransDataContainer *tc = t->data_container;
  74. tc->data_len = 1;
  75. td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
  76. td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
  77. }
  78. td->flag = TD_SELECTED;
  79. copy_v3_v3(td->center, cursor->location);
  80. td->ob = NULL;
  81. unit_m3(td->mtx);
  82. BKE_scene_cursor_rot_to_mat3(cursor, td->axismtx);
  83. normalize_m3(td->axismtx);
  84. pseudoinverse_m3_m3(td->smtx, td->mtx, PSEUDOINVERSE_EPSILON);
  85. td->loc = cursor->location;
  86. copy_v3_v3(td->iloc, cursor->location);
  87. if (cursor->rotation_mode > 0) {
  88. td->ext->rot = cursor->rotation_euler;
  89. td->ext->rotAxis = NULL;
  90. td->ext->rotAngle = NULL;
  91. td->ext->quat = NULL;
  92. copy_v3_v3(td->ext->irot, cursor->rotation_euler);
  93. }
  94. else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
  95. td->ext->rot = NULL;
  96. td->ext->rotAxis = cursor->rotation_axis;
  97. td->ext->rotAngle = &cursor->rotation_angle;
  98. td->ext->quat = NULL;
  99. td->ext->irotAngle = cursor->rotation_angle;
  100. copy_v3_v3(td->ext->irotAxis, cursor->rotation_axis);
  101. }
  102. else {
  103. td->ext->rot = NULL;
  104. td->ext->rotAxis = NULL;
  105. td->ext->rotAngle = NULL;
  106. td->ext->quat = cursor->rotation_quaternion;
  107. copy_qt_qt(td->ext->iquat, cursor->rotation_quaternion);
  108. }
  109. td->ext->rotOrder = cursor->rotation_mode;
  110. }
  111. /** \} */