Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

P_PinchTool.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 // Tool subclass implementing a function similar to TugTool 
00009 // except that the force is only applied in the direction
00010 // the tool is oriented.
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()) {  // Tugging is enabled...
00028     if (!tugging) {   // but we're not tugging yet
00029       if(!target(TARGET_TUG, tugged_pos, 0)) {
00030         // Didn't pick anything, so return
00031         tugging = 0;
00032         return;
00033       }
00034       tugging = 1;
00035       // We're starting the force field, so set the offset
00036       vec_sub(offset, Tool::position(), tugged_pos);
00037       start_tug();
00038     }
00039     target(TARGET_TUG, tugged_pos, 1);
00040     // Apply the force field...
00041     float offset_tugged_pos[3]; // offset+tugged_pos
00042     vec_add(offset_tugged_pos,offset,tugged_pos);
00043 
00044     // set a plane constraint corresponding to the force the TugTool would
00045     // apply, but dotted into the orientation of the controller.
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     // and send the proper force to UIVR for display and possible export
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) { // Tugging has been disabled, so turn it off.
00062     tug(zero);
00063     let_go();
00064     tugging = 0;
00065     forceoff();
00066     offset[0]=offset[1]=offset[2]=0;
00067   }
00068 }

Generated on Thu Mar 28 02:43:56 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002