// This task gets the position of mouse each frame, and rotates the neck based // on it. void World::turn_head() { // Check to make sure the mouse is readable PT(MouseWatcher) mouseWatcherPtr = DCAST(MouseWatcher, m_windowFrameworkPtr->get_mouse().node()); if(mouseWatcherPtr->has_mouse()) { // get the mouse position as a Vec2. The values for each axis are from -1 to // 1. The top-left is (-1,-1), the bottom right is (1,1) const LPoint2f& mpos = mouseWatcherPtr->get_mouse(); // Here we multiply the values to get the amount of degrees to turn // Restrain is used to make sure the values returned by getMouse are in the // valid range. If this particular model were to turn more than this, // significant tearing would be visible m_eveNeckNp.set_p(restrain(mpos.get_x()) * 50); m_eveNeckNp.set_h(restrain(mpos.get_y()) * 20); } }
char getHexChar(int n) { restrain(n, 0, 15); if (n < 10) return static_cast<char>('0' + n); else return static_cast<char>('a' + n - 10); }