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

cmd_trans.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 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_trans.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.26 $       $Date: 2019/01/17 21:21:03 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for transformation control
00019  ***************************************************************************/
00020 
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <ctype.h>
00024 #include <math.h>
00025 #include <tcl.h>
00026 
00027 #if defined(ARCH_AIX4)
00028 #include <strings.h>
00029 #endif
00030 
00031 #include "config.h"
00032 #include "utilities.h"
00033 #include "VMDApp.h"
00034 
00035 int text_cmd_rotmat(ClientData cd, Tcl_Interp *, int argc,
00036                             const char *argv[]) {
00037 
00038   VMDApp *app = (VMDApp *)cd;
00039 
00040    // XXX This is crappy, it should take a list or matrix as third argument
00041    if (argc != 11) {
00042       return TCL_ERROR;
00043    }
00044    int rotBy = !strcasecmp(argv[1], "by");
00045    
00046    float tmp[16];
00047    memset(tmp, 0, sizeof(tmp));
00048    for (int i=0; i<9; i++) {
00049       tmp[i+i/3] = (float) atof(argv[i+2]);
00050    }
00051    tmp[15] = 1.0;
00052    int retval = rotBy ? app->scene_rotate_by(tmp)
00053                       : app->scene_rotate_to(tmp); 
00054    if (retval)
00055      return TCL_OK;
00056    return TCL_ERROR;
00057 }
00058 
00059 int text_cmd_rotate(ClientData cd, Tcl_Interp *interp, int argc,
00060                             const char *argv[]) {
00061 
00062   VMDApp *app = (VMDApp *)cd;
00063 
00064   if(argc == 2 && !strupncmp(argv[1],"stop",CMDLEN)) {
00065     if (app->scene_stoprotation())
00066       return TCL_OK; 
00067 
00068   } else if(argc >= 4 && argc <= 5) {
00069     char axis = (char)(tolower(*(argv[1])));
00070     int rotby = !strupcmp(argv[2],"by");
00071     float deg = (float) atof(argv[3]);
00072     float incr = (argc == 5 ? (float)atof(argv[4]) : 0);
00073     int retval = rotby ? app->scene_rotate_by(deg, axis, incr)
00074                        : app->scene_rotate_to(deg, axis);
00075     if (retval)
00076       return TCL_OK;
00077   }      
00078   Tcl_AppendResult(interp, "rotate usage:\n",
00079     "rotate stop -- stop current rotation\n", 
00080     "rotate [x | y | z] by <angle> -- rotate in one step\n", 
00081     "rotate [x | y | z] by <angle> <increment> -- smooth transition\n", 
00082     NULL);  // XXX Fix me!  Need rotate to commands
00083   
00084   return TCL_ERROR;
00085 }
00086 
00087 int text_cmd_translate(ClientData cd, Tcl_Interp *interp, int argc,
00088                             const char *argv[]) {
00089 
00090   VMDApp *app = (VMDApp *)cd;
00091   if(argc == 5) {
00092     int trby=!strupcmp(argv[1],"by");
00093     float x, y, z;
00094     x = (float) atof(argv[2]);
00095     y = (float) atof(argv[3]);
00096     z = (float) atof(argv[4]);
00097     int retval = trby ? app->scene_translate_by(x, y, z)
00098                       : app->scene_translate_to(x, y, z);
00099     if (retval)
00100       return TCL_OK;
00101   }
00102 
00103   Tcl_AppendResult(interp, "translate usage:\n",
00104     "translate [by | to] <x> <y> <z> -- move viewpoint by/to given vector\n",
00105     NULL); 
00106   return TCL_ERROR;
00107 }
00108 
00109 int text_cmd_scale(ClientData cd, Tcl_Interp *interp, int argc,
00110                             const char *argv[]) {
00111 
00112   VMDApp *app = (VMDApp *)cd;
00113 
00114   if(argc == 3) {
00115     int scby = !strupcmp(argv[1],"by");
00116     float s = (float) atof(argv[2]);
00117     int retval = scby ? app->scene_scale_by(s)
00118                       : app->scene_scale_to(s);
00119 
00120     if (retval)
00121       return TCL_OK;
00122   }
00123 
00124   Tcl_AppendResult(interp, "scale usage:\n",
00125                    "scale [by | to] <scalefactor>", NULL); 
00126   return TCL_ERROR;
00127 }
00128     
00129 int text_cmd_rock(ClientData cd, Tcl_Interp *interp, int argc,
00130                             const char *argv[]) {
00131 
00132   VMDApp *app = (VMDApp *)cd;
00133 
00134   if (argc == 2) {
00135     if (!strupncmp(argv[1],"off",CMDLEN)) {
00136       app->scene_rockoff();
00137       return TCL_OK;
00138     } else if (!strupncmp(argv[1],"on",CMDLEN)) {
00139       Tcl_AppendResult(interp, "Totally, dude.", NULL); 
00140       return TCL_OK;
00141     }
00142   }
00143 
00144   if(argc >= 4 && argc <= 5) {
00145     char axis = (char)(tolower(argv[1][0]));
00146     float deg = (float) atof(argv[3]);
00147     int steps = (argc == 5 ? atoi(argv[4]) : -1);
00148     if (app->scene_rock(axis, deg, steps))
00149       return TCL_OK;
00150   }
00151   Tcl_AppendResult(interp, "rock usage:\n",
00152     "rock off -- stop continuous rotation of the scene\n", 
00153     "rock [x | y | z] by <increment> [steps] -- spin the scene\n",
00154     "     about the given axis by the given increment.  Optionally\n",
00155     "     specify the number of steps before reversing direction.",
00156     NULL); 
00157   return TCL_ERROR;
00158 }
00159 

Generated on Fri Nov 8 02:43:59 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002