00001 /** \file wiiheadtrack.h 00002 * 00003 * The header of the Wiiheadtrack-class. Read the documentation for more 00004 * information. 00005 * 00006 * \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de) 00007 * \author Christian Rohrbeck (c.rohrbec@stud.uni-heidelberg.de) 00008 * \version 1.0 00009 * \date 2010-09-06 00010 */ 00011 00012 #ifndef WIIHT_H 00013 #define WIIHT_H 00014 00015 #include <iostream> 00016 #include <math.h> 00017 #include <GL/glut.h> 00018 #include "wiiuse.h" 00019 00020 /** \brief These values are used for the position of the virtual camera. 00021 * \see Wiiheadtrack::setCameraPos(WiihtCamPos) 00022 */ 00023 enum WiihtCamPos 00024 { 00025 WIIHT_BELOW, /**< below the monitor*/ 00026 WIIHT_ABOVE /**< above the monitor*/ 00027 }; 00028 00029 /** \brief These values are used for the mode of Wiiheadtrack. 00030 * \see Wiiheadtrack::Wiiheadtrack(WiihtMode, unsigned int) 00031 */ 00032 enum WiihtMode 00033 { 00034 WIIHT_MODE_OBJECT, /**< object-mode*/ 00035 WIIHT_MODE_ROOM /**< room-mode*/ 00036 }; 00037 00038 /** \class Wiiheadtrack 00039 * \brief C++-class for using the Nintento Wii Remote (Wiimote) in combination 00040 * with IR-LEDs attached to the user's head as a headtracking-system in 00041 * graphic libraries. 00042 * 00043 * \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de) 00044 * \author Christian Rohrbeck (c.rohrbec@stud.uni-heidelberg.de) 00045 * \version 0.1 00046 * \date 2010-09-06 00047 */ 00048 class Wiiheadtrack 00049 { 00050 public: 00051 00052 /** \brief Constructor of the Wiiheadtrack-class. 00053 * 00054 * \param noWiimotes The number of Wiimotes you want to connect. 00055 * \param mode There are two modes, you can Wiiheadtrack use 00056 * with: 00057 * \li Object-mode: The virtual camera moves on the surface of a 00058 * imaginary sphere, looking at the object in its center. 00059 * \li Room-mode: The virtual camera moves on a plane, simulating 00060 * the user watching through the monitor as a window 00061 * into a "room" behind it. 00062 * 00063 * \return A Wiiheadtrack-object. 00064 * \see <a href="modes.html">The two modes</a> 00065 */ 00066 Wiiheadtrack(WiihtMode mode, unsigned int noWiimotes); 00067 00068 00069 /** \brief Deconstructor of the Wiiheadtrack-class. 00070 */ 00071 ~Wiiheadtrack(); 00072 00073 00074 /** \brief Computes the current position (plane or spherical) of the 00075 * user depending on the mode in 3 dimensions. 00076 * 00077 * The results are are saved in a private array. For getting 00078 * access to the results, use the getPos()- or getPosRel()-function. 00079 * 00080 * \see getPos() 00081 * \see getPosRel() 00082 * \see <a href="position.html">Computation of the position</a> 00083 * 00084 */ 00085 void computePos(); 00086 00087 00088 /** \brief Sets up the connection to the Wiimote. 00089 * 00090 * After searching for available Wiimotes, the function tries 00091 * to connect to them. It also sets the default position for 00092 * the "camera" (::WIIHT_BELOW) and enables the IR-tracking. You can 00093 * set the time it tries connect with the help of 00094 * setScanTime(unsigned int). 00095 */ 00096 void connect(); 00097 00098 00099 /** \brief Enable Wiiheadtrack. 00100 * 00101 * After connecting to a Wiimote, Wiiheadtrack is enabled by default. 00102 */ 00103 void enable(); 00104 00105 00106 /** \brief Disable Wiiheadtrack. 00107 * 00108 * Calling computePos() will not change the position anymore. 00109 */ 00110 void disable(); 00111 00112 00113 /** \brief Because some systems invert the y-value of the current position, 00114 * this function allows to invert the y-Axis position. 00115 */ 00116 void invertY(); 00117 00118 00119 /** \brief Indicates, if Wiiheadtrack is connected to one or more Wiimote(s). 00120 */ 00121 bool isConnected(); 00122 00123 00124 /** \brief Indicates, if Wiiheadtrack is enabled. 00125 */ 00126 bool isEnabled(); 00127 00128 00129 /** \brief Prints several information about the current status of the 00130 * Wiiheadtracker on cammand-line. 00131 * 00132 * It prints: Wiiheadtrack::connected, Wiiheadtrack::mode, 00133 * Wiiheadtrack::eyeDist, Wiiheadtrack::posDist, 00134 * Wiiheadtrack::sensitivity, Wiiheadtrack::eyeL, Wiiheadtrack::eyeC, 00135 * Wiiheadtrack::eyeR, Wiiheadtrack::eyeZ, Wiiheadtrack::phi, 00136 * Wiiheadtrack::theta, Wiiheadtrack::pos, Wiiheadtrack::posRel. 00137 */ 00138 void printStatus(); 00139 00140 00141 /** \brief This function is used for getting the eye-distance 00142 * eyeDist[2]. 00143 * 00144 * \return A pointer to the 2-dimensional array saving the 00145 * eye-distance. 00146 * \see <a href="sensitivity.html">The Sensitivity</a> 00147 */ 00148 float* getEyeDist(); 00149 00150 00151 /** \brief This function is used for getting the position-distance 00152 * posDist[2]. 00153 * 00154 * \return A pointer to the 2-dimensional array saving the 00155 * position-distance. 00156 * \see <a href="sensitivity.html">The Sensitivity</a> 00157 */ 00158 float* getPosDist(); 00159 00160 00161 /** \brief This function is used for accessing the current position 00162 * (plane or spherical) of the user depending on the mode. 00163 * 00164 * The position previously must be computed by computePos(). 00165 * 00166 * \return A pointer to the 3-dimensional array saving the current 00167 * position. 00168 * \see computePos() 00169 * \see <a href="position.html">Computation of the position</a> 00170 */ 00171 float* getPos(); 00172 00173 00174 /** \brief This function is used for accessing the current relative 00175 * position (plane or spherical) of the user depending on the 00176 * mode. 00177 * 00178 * The position previously must be computed by computePos(). 00179 * 00180 * \return A pointer to the 3-dimensional array saving the current 00181 * relative position. 00182 * \see computePos() 00183 * \see <a href="position.html">Computation of the position</a> 00184 */ 00185 float* getPosRel(); 00186 00187 00188 /** \brief Get the sensitivity of Wiiheadtrack. 00189 * 00190 * \return The (x/y-)sensitivity of the Wiiheadtrack. 00191 * \see setSensitivity(float) 00192 * \see <a href="sensitivity.html">Sensitivity</a> 00193 */ 00194 float getSensitivity(); 00195 00196 00197 /** \brief Set the position of the camera -- above or below the monitor. 00198 * 00199 * \param pos A ::WiihtCamPos-value. 00200 */ 00201 void setCameraPos(WiihtCamPos pos); 00202 00203 00204 /** \brief Set the "normal" an the smallest distance between the 00205 * eyes/user an the camera. 00206 * 00207 * The distances are used for configuring the sensitivity in 00208 * z-direction. 00209 * 00210 * \param distCenter The "normal" distance between the eye/user and the 00211 * camera. Must be greater than distNear and greater than 00212 * 0. 00213 * \param distNear The smallest distance between the eye/user and the 00214 * camera. Must be greater than 0. 00215 * \see setPosDist(float, float) 00216 * \see <a href="sensitivity.html">The Sensitivity</a> 00217 */ 00218 void setEyeDist(float distCenter, float distNear); 00219 00220 00221 /** \brief Set the time (seconds) the program tries to connect to the 00222 * wiimote. (Default: 5 seconds) 00223 * 00224 * \param time The time in seconds. 00225 */ 00226 void setScanTime(unsigned int time); 00227 00228 00229 /** \brief Set the sensitivity of Wiiheadtrack. (Default: 60.0 (object-mode), 00230 * 1.0 (room-mode)) 00231 * 00232 * The sensitivity describes, how intense the camera moves 00233 * depending on the head-movement. 00234 * 00235 * \param sensitivity The new sensitivity. Must be greater 0. 00236 */ 00237 void setSensitivity(float sensitivity); 00238 00239 00240 /** \brief Set the "normal" an the smallest distance between the 00241 * (virtual) position an the (virtual) camera-center. 00242 * 00243 * The distances are used for configuring the sensitivity in 00244 * z-direction. 00245 * 00246 * \param distCenter The "normal" distance between the camera and 00247 * the center. Must be greater than distNear and 00248 * greater than 0. 00249 * \param distNear The smallest distance between the camera and 00250 * the center. Must be greater than or equal to 0 00251 * \see setEyeDist(float, float); 00252 * \see <a href="sensitivity.html">The Sensitivity</a> 00253 */ 00254 void setPosDist(float distCenter, float distNear); 00255 00256 00257 private: 00258 00259 WiihtMode mode; /**< The mode you want to use the Wiiheadtrack. \see Wiiheadtrack(WiihtMode, unsigned int)*/ 00260 wiimote** wiimotes; /**< Array of the Wiimotes.*/ 00261 bool connected; /**< Indicates, if Wiiheadtrack is connected to one or more Wiimote(s)*/ 00262 bool enabled; /**< Indicates, if Wiiheadtracking is enabled.*/ 00263 int invY; /**< Some systems invert the y-Value. This variable helps to fix this error. Inverted=-1, not inverted=1. \see invertY() */ 00264 00265 unsigned int noWiimotes; /**< Number of Wiimotes you want to connect. Default: 1*/ 00266 unsigned int foundWiimotes; /**< Number of Wiimotes found by scanning in the connect()-function.*/ 00267 unsigned int connectedWiimotes; /**< Number of Wiimotes connected with in the connect()-function.*/ 00268 unsigned int scanTime; /**< Time (seconds) Wiiheadtrack searches for Wiimotes in the connect()-function.*/ 00269 00270 float eyeDist[2]; /**< Distance between the eye/user and the camera: "normal" distance (eyeDist[0]), nearest position to the camera (eyeDist[1]). \see setEyeDist(float, float) \see <a href="sensitivity.html">Sensitivity</a>*/ 00271 float posDist[2]; /**< Distance between the "normal" virtual position an the nearest virtual position. \see setPosDist(float, float) \see <a href="sensitivity.html">Sensitivity</a>*/ 00272 float posDistPar[2]; /**< Parameters \f$m\f$ and \f$d\f$ of the linear function \f$f(x) = m \cdot x + d\f$ for mapping the eye-distance to the position-distance. \see computePosDistPar() \see <a href="sensitivity.html">Sensitivity</a>*/ 00273 00274 float eyeL[2]; /**< 2-dimensional position of the user's left eye on the imaginary screen seen by the camera.*/ 00275 float eyeR[2]; /**< 2-dimensional position of the user's right eye on the imaginary screen seen by the camera.*/ 00276 float eyeC[2]; /**< 2-dimensional position of the point between the user's eyes on the imaginary screen seen by the camera.*/ 00277 float eyeZ; /**< Distance between the Wiimote-camera and the user's eyes.*/ 00278 float pos[3]; /**< Position computed by computePos(), depending on the mode.*/ 00279 float posRel[3]; /**< Change of pos[3] since the last call of computePos() (relative Position).*/ 00280 00281 const int wiimoteCamNo; /**< Indicates, which of the connected Wiimotes is used as the camera. Default: 1.*/ 00282 float sensitivity; /**< A factor which declares, how intense the movement (left/right, up/down) of the user moves the virtual camera. \see setSensitivity(float) \see <a href="sensitivity.html">Sensitivity</a>*/ 00283 float phi, theta, radius; /**< Values for calculating the spherical coordinates of the virtual camera/position.*/ 00284 00285 00286 /** \brief Detects the position of the user on the imaginary screen 00287 * seen by the "camera". 00288 * 00289 * After detecting the position of the left (eyeL) and the 00290 * right (eyeR) eye, the function calculates the point 00291 * between the eyes. It also detects the z-value of the 00292 * position of the users eyes seen by the Wiimote-camera. 00293 * 00294 * \see <a href="position.html">Computation of the position</a> 00295 */ 00296 void computeEyePos(); 00297 00298 00299 /** \brief Transforms the position of the user detected by 00300 * computeEyePos() to a virtual position on a plane, 00301 * regarding the sensitivity. Used in room-mode. 00302 * 00303 * \see <a href="position.html">Computation of the position</a> 00304 */ 00305 void computePlanePos(); 00306 00307 00308 /** \brief Computes the parameters \f$m\f$ and \f$d\f$ of the linear 00309 * function \f$f(x) = m \cdot x + d\f$ for mapping the 00310 * eye-distance to the position-distance. 00311 * 00312 * \see <a href="sensitivity.html">The Sensitivity</a> 00313 * 00314 */ 00315 void computePosDistPar(); 00316 00317 00318 /** \brief Maps the position of the user detected by 00319 * computeEyePos() to a virtual position on a sphere, 00320 * regarding the sensitivity. Used in object-mode. 00321 * 00322 * \see <a href="position.html">Computation of the position</a> 00323 */ 00324 void computeSpherePos(); 00325 }; 00326 00327 #endif /* WIIHT_H */ 00328