00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00054 CmdRotate::CmdRotate(float a, char ax, int by_or_to)
00055 : Command(Command::ROTATE) {
00056
00057 steps = (-1);
00058
00059
00060 if(ax >= 'x' && ax <= 'z') {
00061 byOrTo = by_or_to;
00062 axis = ax;
00063 deg = a;
00064 } else {
00065
00066 byOrTo = CmdRotate::BY;
00067 axis = 'y';
00068 deg = 0.0;
00069 }
00070 }
00071
00072
00073
00074
00075 CmdRotate::CmdRotate(float a, char ax, int by_or_to, float inc)
00076 : Command(Command::ROTATE) {
00077
00078
00079 if(ax >= 'x' && ax <= 'z' && inc != 0) {
00080 byOrTo = by_or_to;
00081 axis = ax;
00082
00083
00084
00085 if(byOrTo == CmdRotate::TO) {
00086 steps = (-1);
00087 deg = a;
00088 } else {
00089 steps = (int)(fabs(a / inc) + 0.5);
00090
00091
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
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) { }