00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "P_PinchTool.h"
00013 #include "Matrix4.h"
00014 #include "utilities.h"
00015
00016 PinchTool::PinchTool(int id, VMDApp *vmdapp, Displayable *disp)
00017 : Tool(id, vmdapp, disp) {
00018 int i;
00019 for(i=0;i<3;i++) offset[i]=0;
00020 tugging=0;
00021 springscale = 1.0;
00022 }
00023
00024 void PinchTool::do_event() {
00025 float zero[3] = {0,0,0};
00026
00027 if (istugging()) {
00028 if (!tugging) {
00029 if(!target(TARGET_TUG, tugged_pos, 0)) {
00030
00031 tugging = 0;
00032 return;
00033 }
00034 tugging = 1;
00035
00036 vec_sub(offset, Tool::position(), tugged_pos);
00037 start_tug();
00038 }
00039 target(TARGET_TUG, tugged_pos, 1);
00040
00041 float offset_tugged_pos[3];
00042 vec_add(offset_tugged_pos,offset,tugged_pos);
00043
00044
00045
00046 const Matrix4 *o = orientation();
00047 float zaxis[] = {1,0,0};
00048 float orientaxis[3];
00049 o->multpoint3d(zaxis, orientaxis);
00050 setplaneconstraint(50, offset_tugged_pos, orientaxis);
00051 sendforce();
00052
00053
00054 float diff[3];
00055 vec_sub(diff, Tool::position(), offset_tugged_pos);
00056 vec_scale(diff,40000 * forcescale*springscale,diff);
00057 float res[3];
00058 vec_scale(res, dot_prod(diff, orientaxis), orientaxis);
00059 tug(res);
00060 }
00061 else if (tugging) {
00062 tug(zero);
00063 let_go();
00064 tugging = 0;
00065 forceoff();
00066 offset[0]=offset[1]=offset[2]=0;
00067 }
00068 }