/* clear rotation of object */ static void object_clear_rot(Object *ob) { /* clear rotations that aren't locked */ if (ob->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) { if (ob->protectflag & OB_LOCK_ROT4D) { /* perform clamping on a component by component basis */ if (ob->rotmode == ROT_MODE_AXISANGLE) { if ((ob->protectflag & OB_LOCK_ROTW) == 0) ob->rotAngle= ob->drotAngle= 0.0f; if ((ob->protectflag & OB_LOCK_ROTX) == 0) ob->rotAxis[0]= ob->drotAxis[0]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTY) == 0) ob->rotAxis[1]= ob->drotAxis[1]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTZ) == 0) ob->rotAxis[2]= ob->drotAxis[2]= 0.0f; /* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */ if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2])) ob->rotAxis[1] = 1.0f; if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2])) ob->drotAxis[1]= 1.0f; } else if (ob->rotmode == ROT_MODE_QUAT) { if ((ob->protectflag & OB_LOCK_ROTW) == 0) ob->quat[0]= ob->dquat[0]= 1.0f; if ((ob->protectflag & OB_LOCK_ROTX) == 0) ob->quat[1]= ob->dquat[1]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTY) == 0) ob->quat[2]= ob->dquat[2]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTZ) == 0) ob->quat[3]= ob->dquat[3]= 0.0f; // TODO: does this quat need normalising now? } else { /* the flag may have been set for the other modes, so just ignore the extra flag... */ if ((ob->protectflag & OB_LOCK_ROTX) == 0) ob->rot[0]= ob->drot[0]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTY) == 0) ob->rot[1]= ob->drot[1]= 0.0f; if ((ob->protectflag & OB_LOCK_ROTZ) == 0) ob->rot[2]= ob->drot[2]= 0.0f; } } else { /* perform clamping using euler form (3-components) */ // FIXME: deltas are not handled for these cases yet... float eul[3], oldeul[3], quat1[4] = {0}; if (ob->rotmode == ROT_MODE_QUAT) { copy_qt_qt(quat1, ob->quat); quat_to_eul(oldeul, ob->quat); } else if (ob->rotmode == ROT_MODE_AXISANGLE) { axis_angle_to_eulO(oldeul, EULER_ORDER_DEFAULT, ob->rotAxis, ob->rotAngle); } else { copy_v3_v3(oldeul, ob->rot); } eul[0]= eul[1]= eul[2]= 0.0f; if (ob->protectflag & OB_LOCK_ROTX) eul[0]= oldeul[0]; if (ob->protectflag & OB_LOCK_ROTY) eul[1]= oldeul[1]; if (ob->protectflag & OB_LOCK_ROTZ) eul[2]= oldeul[2]; if (ob->rotmode == ROT_MODE_QUAT) { eul_to_quat(ob->quat, eul); /* quaternions flip w sign to accumulate rotations correctly */ if ((quat1[0]<0.0f && ob->quat[0]>0.0f) || (quat1[0]>0.0f && ob->quat[0]<0.0f)) { mul_qt_fl(ob->quat, -1.0f); } } else if (ob->rotmode == ROT_MODE_AXISANGLE) { eulO_to_axis_angle(ob->rotAxis, &ob->rotAngle,eul, EULER_ORDER_DEFAULT); } else { copy_v3_v3(ob->rot, eul); } } } // Duplicated in source/blender/editors/armature/editarmature.c else { if (ob->rotmode == ROT_MODE_QUAT) { unit_qt(ob->quat); unit_qt(ob->dquat); } else if (ob->rotmode == ROT_MODE_AXISANGLE) { unit_axis_angle(ob->rotAxis, &ob->rotAngle); unit_axis_angle(ob->drotAxis, &ob->drotAngle); } else { zero_v3(ob->rot); zero_v3(ob->drot); } } }
static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event) { Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); // Object *obedit= CTX_data_edit_object(C); View3D *v3d= CTX_wm_view3d(C); // BoundBox *bb; Object *ob= OBACT; TransformProperties *tfp= v3d->properties_storage; switch(event) { case B_REDR: ED_area_tag_redraw(CTX_wm_area(C)); return; /* no notifier! */ case B_OBJECTPANEL: DAG_id_tag_update(&ob->id, OB_RECALC_OB); break; case B_OBJECTPANELMEDIAN: if(ob) { v3d_editvertex_buts(NULL, v3d, ob, 1.0); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } break; /* note; this case also used for parbone */ case B_OBJECTPANELPARENT: if(ob) { if(ob->id.lib || test_parent_loop(ob->parent, ob) ) ob->parent= NULL; else { DAG_scene_sort(bmain, scene); DAG_id_tag_update(&ob->id, OB_RECALC_OB); } } break; case B_ARMATUREPANEL3: // rotate button on channel { bPoseChannel *pchan; float eul[3]; pchan= get_active_posechannel(ob); if (!pchan) return; /* make a copy to eul[3], to allow TAB on buttons to work */ eul[0]= (float)M_PI*tfp->ob_eul[0]/180.0f; eul[1]= (float)M_PI*tfp->ob_eul[1]/180.0f; eul[2]= (float)M_PI*tfp->ob_eul[2]/180.0f; if (pchan->rotmode == ROT_MODE_AXISANGLE) { float quat[4]; /* convert to axis-angle, passing through quats */ eul_to_quat( quat,eul); quat_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,quat); } else if (pchan->rotmode == ROT_MODE_QUAT) eul_to_quat( pchan->quat,eul); else copy_v3_v3(pchan->eul, eul); } /* no break, pass on */ case B_ARMATUREPANEL2: { ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } break; case B_TRANSFORMSPACEADD: { char names[sizeof(((TransformOrientation *)NULL)->name)]= ""; BIF_createTransformOrientation(C, NULL, names, 1, 0); break; } case B_TRANSFORMSPACECLEAR: BIF_clearTransformOrientation(C); break; #if 0 // XXX case B_WEIGHT0_0: wpaint->weight = 0.0f; break; case B_WEIGHT1_4: wpaint->weight = 0.25f; break; case B_WEIGHT1_2: wpaint->weight = 0.5f; break; case B_WEIGHT3_4: wpaint->weight = 0.75f; break; case B_WEIGHT1_0: wpaint->weight = 1.0f; break; case B_OPA1_8: wpaint->a = 0.125f; break; case B_OPA1_4: wpaint->a = 0.25f; break; case B_OPA1_2: wpaint->a = 0.5f; break; case B_OPA3_4: wpaint->a = 0.75f; break; case B_OPA1_0: wpaint->a = 1.0f; break; #endif case B_CLR_WPAINT: // if(!multires_level1_test()) { { bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->actdef-1); if(defGroup) { Mesh *me= ob->data; int a; for(a=0; a<me->totvert; a++) ED_vgroup_vert_remove (ob, defGroup, a); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } } break; case B_RV3D_LOCKED: case B_RV3D_BOXVIEW: case B_RV3D_BOXCLIP: { ScrArea *sa= CTX_wm_area(C); ARegion *ar= sa->regionbase.last; RegionView3D *rv3d; short viewlock; ar= ar->prev; rv3d= ar->regiondata; viewlock= rv3d->viewlock; if((viewlock & RV3D_LOCKED)==0) viewlock= 0; else if((viewlock & RV3D_BOXVIEW)==0) viewlock &= ~RV3D_BOXCLIP; for(; ar; ar= ar->prev) { if(ar->alignment==RGN_ALIGN_QSPLIT) { rv3d= ar->regiondata; rv3d->viewlock= viewlock; } } if(rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_copy(sa, sa->regionbase.last); ED_area_tag_redraw(sa); } break; } /* default for now */ WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, ob); }