00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "bodies.h"
00011
00012
00013 Body::Body(int id, float qu, Body::BodyType type, float *shift, float *rotation)
00014 {
00015 deviceID = id;
00016 quality = qu;
00017 deviceType = type;
00018
00019 this->SetRotation(rotation);
00020 this->SetShift(shift);
00021 }
00022 Body::~Body()
00023 {}
00024 void Body::Scale(float num)
00025 {
00026 vector3 vct;
00027 vct.x = vct.y =vct.z = num;
00028 tMatrix.Scale(vct);
00029 }
00030 void Body::SetMatrix(MATRIX & matr)
00031 {
00032 tMatrix = matr;
00033 }
00034 void Body::Identity()
00035 {
00036 MATRIX identity;
00037 tMatrix = identity;
00038 }
00039 void Body::SetShift(float *shift)
00040 {
00041 if (shift != NULL)
00042 {
00043 vector3 vct;
00044 vct.x = shift[0];
00045 vct.y = shift[1];
00046 vct.z = shift[2];
00047 tMatrix.Translate(vct);
00048 }
00049 }
00050 void Body::SetRotation(float *rotation)
00051 {
00052 if (rotation != NULL)
00053 {
00054 tMatrix._m11 = rotation[0]; tMatrix._m12 = rotation[3]; tMatrix._m13 = rotation[6];
00055 tMatrix._m21 = rotation[1]; tMatrix._m22 = rotation[4]; tMatrix._m23 = rotation[7];
00056 tMatrix._m31 = rotation[2]; tMatrix._m32 = rotation[5]; tMatrix._m33 = rotation[8];
00057 }
00058 }
00059 int Body::GetID()
00060 {
00061 return deviceID;
00062 }
00063 Body::BodyType Body::GetType()
00064 {
00065 return deviceType;
00066 }
00067 vector3 Body::GetShift()
00068 {
00069 return tMatrix.ExtractTranslation();
00070 }
00071 MATRIX Body::GetRotation()
00072 {
00073 return tMatrix.ExtractRotation();
00074 }
00075 MATRIX Body::Matrix()
00076 {
00077 return tMatrix;
00078 }
00079 float Body::GetQuality()
00080 {
00081 return quality;
00082 }
00083 int Body::Button(int num)
00084 {
00085 return -10;
00086 }
00087 int Body::ButonsNumber()
00088 {
00089 return 0;
00090 }
00091 int Body::ControlsNuber()
00092 {
00093 return 0;
00094 }
00095 float Body::Control(int num)
00096 {
00097 return -10.0;
00098 }
00099 int Body::LeftHand()
00100 {
00101 return -10;
00102 }
00103 int Body::FingersNum()
00104 {
00105 return 0;
00106 }
00107 Finger * Body::GetFinger(int num)
00108 {
00109 return NULL;
00110 }
00111 BodyGlove::BodyGlove(int id, float qu, int numFingers, bool lHand, float *shift, float *rotation)
00112 : Body(id, qu, Body::BGL, shift, rotation)
00113 {
00114 this->leftHand = lHand;
00115 this->fingerCount = numFingers;
00116 this->fingers = new Finger[fingerCount];
00117 }
00118 BodyGlove::~BodyGlove()
00119 {
00120 delete [] fingers;
00121 }
00122 void BodyGlove::addFinger(int pos, Finger finger)
00123 {
00124 if ((0 <= pos) && (pos < fingerCount)) fingers[pos] = finger;
00125 }
00126 int BodyGlove::LeftHand()
00127 {
00128 return (this->leftHand ? 1 : 0);
00129 }
00130 int BodyGlove::FingersNum()
00131 {
00132 return fingerCount;
00133 }
00134 Finger * BodyGlove::GetFinger(int num)
00135 {
00136 if ((0 <= num) && (num < fingerCount)) return &(fingers[num]);
00137 else return NULL;
00138 }
00139 ButtonDevice::ButtonDevice(Body::BodyType type, int id, float qu, int buttons, float *shift, float *rotation)
00140 : Body(id, qu, type, shift, rotation)
00141 {
00142 this->buttons = buttons;
00143 }
00144 ButtonDevice::~ButtonDevice()
00145 {}
00146 int ButtonDevice::ButonsNumber()
00147 {
00148 return 8;
00149 }
00150 int ButtonDevice::Button(int num)
00151 {
00152 int res = 0x01;
00153 if (0<=num && num < 8)
00154 {
00155 res = res << num;
00156 if (0 != (res & buttons)) return 1;
00157 else return 0;
00158 }
00159 else return -10;
00160 }
00161 FlyStick1::FlyStick1(int id, float qu, int buttons, float *shift, float * rotation)
00162 : ButtonDevice(Body::B6DF,id,qu,buttons,shift,rotation)
00163 {}
00164 FlyStick1::~FlyStick1()
00165 {}
00166 Measurer::Measurer(int id, float qu, int buttons, float *shift, float * rotation)
00167 :ButtonDevice(Body::B6DMT,id,qu,buttons,shift,rotation)
00168 {}
00169 Measurer::~Measurer()
00170 {}
00171 FlyStick2::FlyStick2(int id, float qu, int buttons, int controls, float * shift, float * rotation)
00172 : Body(id, qu, Body::B6DF2, shift, rotation)
00173 {
00174 buttonsCount = buttons;
00175 int arrsize = buttons / 32 + 1;
00176 controlCount = controls;
00177 this->buttArray = new int[arrsize];
00178 this->ctrlArray = new float[controls];
00179 }
00180 FlyStick2::~FlyStick2()
00181 {
00182 delete [] buttArray;
00183 delete [] ctrlArray;
00184 }
00185 void FlyStick2::addButtons(int pos, int config)
00186 {
00187 if ((0 <= pos) && (pos < buttonsCount ))
00188 {
00189 buttArray[pos] = config;
00190 }
00191 }
00192 void FlyStick2::addControls(int pos, float value)
00193 {
00194 if ((0 <= pos) && (pos < controlCount ))
00195 {
00196 ctrlArray[pos] = value;
00197 }
00198 }
00199 int FlyStick2::ButonsNumber()
00200 {
00201 return buttonsCount;
00202 }
00203 int FlyStick2::ControlsNuber()
00204 {
00205 return controlCount;
00206 }
00207 float FlyStick2::Control(int num)
00208 {
00209 if ((0 <= num) && (num < controlCount)) return ctrlArray[num];
00210 else return -10.0;
00211 }
00212 int FlyStick2::Button(int num)
00213 {
00214 if ((0 <= num) && (num < buttonsCount))
00215 {
00216 int index = num / 32;
00217 int shift = num % 32;
00218 int mask = 0x01;
00219 mask = mask << shift;
00220 if ( 0 != (mask & buttArray[index])) return 1;
00221 else return 0;
00222 }
00223 else return - 10;
00224 }
00225 int Body::ButtonsMask32()
00226 {
00227 return 0x00;
00228 }
00229 int ButtonDevice::ButtonsMask32()
00230 {
00231 return this->buttons;
00232 }
00233 int FlyStick2::ButtonsMask32()
00234 {
00235 return this->buttArray[0];
00236 }