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

CmdTrans.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: CmdTrans.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.43 $       $Date: 2019/01/17 21:20:58 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Command objects for transforming the current scene.
00020  *
00021  ***************************************************************************/
00022 
00023 #include <math.h>
00024 #include "CmdTrans.h"
00025 
00027 void CmdRotMat::create_text(void) {
00028   *cmdText << "rotmat " << (byOrTo == CmdRotMat::BY ? "by " : "to ");
00029   for (int i=0; i<3; i++) *cmdText << " " 
00030       << rotMat.mat[4*i] << " " << rotMat.mat[4*i+1] <<" " 
00031       << rotMat.mat[4*i+2] << " ";
00032   *cmdText << ends;
00033 }
00034 
00035 CmdRotMat::CmdRotMat(const Matrix4& m, int by_or_to)
00036 : Command(Command::ROTMAT) {
00037    byOrTo = by_or_to;
00038    rotMat = m;
00039 }
00040 
00041 
00043 
00044 void CmdRotate::create_text(void) {
00045   *cmdText << "rotate " << axis;
00046   *cmdText << ( byOrTo == CmdRotate::BY ? " by " : " to ");
00047   *cmdText << deg;
00048   if(steps > 0)
00049     *cmdText << " " << (deg / ((float)steps));
00050   *cmdText << ends;
00051 }
00052 
00053 // first constructor: a single rotation, no smooth transition
00054 CmdRotate::CmdRotate(float a, char ax, int by_or_to)
00055   : Command(Command::ROTATE) {
00056 
00057   steps = (-1);
00058 
00059   // make sure the axis specified is a legal one ...
00060   if(ax >= 'x' && ax <= 'z') {
00061     byOrTo = by_or_to;
00062     axis = ax;
00063     deg = a;
00064   } else {
00065     // if not legal, just do no rotation.
00066     byOrTo = CmdRotate::BY;
00067     axis = 'y';
00068     deg = 0.0;
00069   }
00070 }
00071 
00072 // second constructor: a smooth rotation in given increments ...
00073 // only useful for "by" rotations.  If "to" is given to this constructor,
00074 // a single-step rotation is done.
00075 CmdRotate::CmdRotate(float a, char ax, int by_or_to, float inc)
00076   : Command(Command::ROTATE) {
00077 
00078   // make sure the axis specified is a legal one ...
00079   if(ax >= 'x' && ax <= 'z' && inc != 0) {
00080     byOrTo = by_or_to;
00081     axis =  ax;
00082   
00083     // determine by how much to rotate, and number of steps to use.  If we
00084     // are doing 'to' rotation, just do it in one big step.
00085     if(byOrTo == CmdRotate::TO) {
00086       steps = (-1);
00087       deg = a;
00088     } else {
00089       steps = (int)(fabs(a / inc) + 0.5);
00090 
00091       // make sure there is at least one step
00092       if(steps < 1) {
00093         steps = (-1);
00094         deg = a;
00095       } else {
00096         deg = (float) (a < 0.0 ? - fabs(inc) : fabs(inc));
00097       }
00098     }
00099 
00100   } else {
00101     // if not legal, just do no rotation.
00102     byOrTo = CmdRotate::BY;
00103     axis = 'y';
00104     deg = 0.0;
00105     steps = (-1);
00106   }
00107 }
00108 
00109 
00111 void CmdTranslate::create_text(void) {
00112   *cmdText << "translate ";
00113   *cmdText << (byOrTo == CmdTranslate::BY ? "by " : "to ");
00114   *cmdText << x << " " << y << " " << z << ends;
00115 }
00116 
00117 CmdTranslate::CmdTranslate(float nx,float ny, float nz, int by_or_to)
00118   : Command(Command::TRANSLATE) {
00119   x = nx;  y = ny;  z = nz;
00120   byOrTo = by_or_to;
00121 }
00122 
00123 
00125 void CmdScale::create_text(void) {
00126   *cmdText << "scale ";
00127   *cmdText << ( byOrTo == CmdScale::BY ? "by " : "to ");
00128   *cmdText << s;
00129   *cmdText << ends;
00130 }
00131 
00132 CmdScale::CmdScale(float ns, int by_or_to)
00133   : Command(Command::SCALE) {
00134   s = ns;
00135   byOrTo = by_or_to;
00136 }
00137 
00138 
00140 void CmdRockOn::create_text(void) {
00141   *cmdText << "rock " << axis << " by " << deg;
00142   if(steps >= 0)
00143     *cmdText << " " << steps;
00144   *cmdText << ends;
00145 }
00146 
00147 CmdRockOn::CmdRockOn(float a, char ax, int nsteps)
00148   : Command(Command::ROCKON) {
00149   deg = a;
00150   axis = ((ax >= 'x' && ax <= 'z') ? ax : 'y');
00151   steps = nsteps;
00152 }
00153 
00154 
00156 void CmdRockOff::create_text(void) {
00157   *cmdText << "rock off" << ends;
00158 }
00159 
00160 CmdRockOff::CmdRockOff() 
00161 : Command(Command::ROCKOFF) { }

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