[Bf-blender-cvs] [f8b19d1] wiggly-widgets: Logic for light position operator.
Antony Riakiotakis
noreply at git.blender.org
Fri Oct 3 19:51:38 CEST 2014
Commit: f8b19d1d6e6f2873d92ed336d6a1e0780ea47b2f
Author: Antony Riakiotakis
Date: Fri Oct 3 19:51:26 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBf8b19d1d6e6f2873d92ed336d6a1e0780ea47b2f
Logic for light position operator.
===================================================================
M source/blender/editors/interface/interface_generic_widgets.c
===================================================================
diff --git a/source/blender/editors/interface/interface_generic_widgets.c b/source/blender/editors/interface/interface_generic_widgets.c
index 055c6f5..7d08254 100644
--- a/source/blender/editors/interface/interface_generic_widgets.c
+++ b/source/blender/editors/interface/interface_generic_widgets.c
@@ -29,6 +29,7 @@
#include "WM_types.h"
+#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_lamp_types.h"
#include "DNA_object_types.h"
@@ -41,6 +42,7 @@
#include "BLI_math.h"
#include "BKE_context.h"
+#include "BKE_object.h"
#include "ED_view3d.h"
@@ -61,6 +63,7 @@
typedef struct LampPositionData {
int pos[2];
float quat[4];
+ float lvec[3];
} LampPositionData;
/* Modal Operator init */
@@ -73,6 +76,9 @@ static int lamp_position_invoke(bContext *C, wmOperator *op, const wmEvent *even
copy_v2_v2_int(data->pos, event->mval);
mat4_to_quat(data->quat, ob->obmat);
+ copy_v3_v3(data->lvec, ob->obmat[2]);
+ negate_v3(data->lvec);
+ normalize_v3(data->lvec);
WM_event_add_modal_handler(C, op);
@@ -82,11 +88,39 @@ static int lamp_position_invoke(bContext *C, wmOperator *op, const wmEvent *even
/* Repeat operator */
static int lamp_position_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
+
+ LampPositionData *data = op->customdata;
+
switch (event->type) {
case MOUSEMOVE:
{
Object *ob = CTX_data_active_object(C);
- Lamp *la = ob->data;
+
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ float world_pos[3];
+
+ view3d_operator_needs_opengl(C);
+ if (ED_view3d_autodist(scene, ar, v3d, event->mval, world_pos, true, NULL)) {
+ float axis[3];
+ sub_v3_v3(world_pos, ob->obmat[3]);
+ normalize_v3(world_pos);
+
+ cross_v3_v3v3(axis, data->lvec, world_pos);
+ if (normalize_v3(axis) > 0.001) {
+ float mat[4][4];
+ float quat[4], qfinal[4];
+
+ /* transform the initial rotation quaternion to the new position and set the matrix to the lamp */
+ axis_angle_to_quat(quat, axis, saacos(dot_v3v3(axis, data->lvec)));
+ mul_qt_qtqt(qfinal, quat, data->quat);
+ quat_to_mat4(mat, qfinal);
+ copy_v3_v3(mat[3], ob->obmat[3]);
+
+ BKE_object_apply_mat4(ob, mat, true, true);
+ }
+ }
break;
}
@@ -125,7 +159,7 @@ void UI_OT_lamp_position(struct wmOperatorType *ot)
/* properties */
}
-int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, int active)
+int WIDGET_lamp_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *UNUSED(widget), int active)
{
if (event->type == LEFTMOUSE && event->val == KM_PRESS && active == 1) {
More information about the Bf-blender-cvs
mailing list