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