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 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: P_JoystickTool.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.40 $ $Date: 2019/01/17 21:21:00 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * This is Paul's new Tracker code -- pgrayson@ks.uiuc.edu 00019 * 00020 * 00021 ***************************************************************************/ 00022 00023 #include "P_JoystickTool.h" 00024 00025 JoystickTool::JoystickTool(int id, VMDApp *vmdapp, Displayable *disp) 00026 : Tool(id, vmdapp, disp) { 00027 constrained=0; 00028 } 00029 00030 void JoystickTool::do_event() { 00031 int i; 00032 00033 if(!constrained && isgrabbing()) { 00034 if(!target(TARGET_GRAB, pos, 0)) { 00035 // constrained=-1; return; 00036 } 00037 constrained=1; 00038 for(i=0;i<dimension();i++) { 00039 pos[i]=Tool::position()[i]; 00040 constraint[i]=pos[i]; 00041 } 00042 setconstraint(100,constraint); 00043 sendforce(); 00044 } 00045 else if(constrained && !isgrabbing()) { 00046 let_go(); 00047 constrained=0; 00048 forceoff(); 00049 } 00050 00051 if(constrained == 1) { 00052 for(i=0;i<dimension();i++) 00053 pos[i] += 0.1f * (Tool::position()[i]-constraint[i]); 00054 } 00055 else { 00056 for(i=0;i<dimension();i++) 00057 pos[i] = Tool::position()[i]; 00058 } 00059 } 00060 00061 const float *JoystickTool::position() const { 00062 if(constrained) return pos; 00063 else return Tool::position(); 00064 } 00065