Quaternion interpolate(float t, Quaternion a, Quaternion b) { float w = acos(dotQuaternion(normQuaternion(a), normQuaternion(b))); float s = sin(w); return addQuaternion(scaleQuaternion(sin((1.0f - t) * w) / s, a), scaleQuaternion(sin(t * w) / s, b)); }
KartUpdateMessage::KartUpdateMessage() : Message(Message::MT_KART_INFO) { World *world = World::getWorld(); unsigned int num_karts = world->getNumKarts(); // Send the number of karts and for each kart the compressed // control structure (3 ints) and xyz,hpr (4 floats: quaternion: allocate(getCharLength()+ num_karts*(KartControl::getLength() + getVec3Length() +getQuaternionLength()) ); addChar(num_karts); for(unsigned int i=0; i<num_karts; i++) { const Kart* kart = world->getKart(i); const KartControl& kc=kart->getControls(); kc.serialise(this); addVec3(kart->getXYZ()); addQuaternion(kart->getRotation()); } // for i } // KartUpdateMessage
void drawContext::eventHandler(int event, float x, float y) { int width = _width, height = _height; if(_retina){ // x,y for retina are still the same as for non-retina width /= 2; height /= 2; } _current.set(_scale, _translate, _right, _left, _bottom, _top, width, height, x, y); double xx[3] = {1.,0.,0.}; double yy[3] = {0.,1.,0.}; double q[4]; switch(event){ case 0: // finger(s) press the screen // in this case x and y represent the start point _start.set(_scale, _translate, _right, _left, _bottom, _top, width, height, x, y); _previous.set(_scale, _translate, _right, _left, _bottom, _top, width, height, x, y); break; case 1: // finger move (translate) // in this case x and y represent the current point _translate[0] += (_current.wnr[0] - _previous.wnr[0]); _translate[1] += (_current.wnr[1] - _previous.wnr[1]); _translate[2] = 0.; break; case 2: // fingers move (scale) // in this case we don't care about previous and current position, x // represent the scale _scale[0] = _scale[1] = _scale[2] = x; _start.recenter(_scale, _translate); break; case 3: // fingers move (rotate) addQuaternion((2. * _previous.win[0] - width) / width, (height - 2. * _previous.win[1]) / height, (2. * _current.win[0] - width) / width, (height - 2. * _current.win[1]) / height); break; case 4: // release the finger(s) // Do nothing ? break; case 5: // X view axis_to_quat(xx, M_PI/2, q); setQuaternion(q[0], q[1], q[2], q[3]); break; case 6: // Y view axis_to_quat(yy, M_PI/2, q); setQuaternion(q[0], q[1], q[2], q[3]); break; case 7: // Z view setQuaternion(0., 0., 0., 1.); break; default: // all other reset the position setQuaternion(0., 0., 0., 1.); for(int i = 0; i < 3; i++){ _translate[i] = 0.; _scale[i] = 1.; } break; } _previous.set(_scale, _translate, _right, _left, _bottom, _top, width, height, x, y); }