void Player::Shoot() { Shot* shot = NULL; for (auto i : m_shots) { if (i->m_timeRemaining <= 0) { shot = i; break; } } if (shot && (m_spinRate > 0)) { // Reset the shot shot->m_timeRemaining = shot->m_timeTotal; // Get orientation of player Vec3f orient = Vec3f(0,1,0); Quatf rot = m_pShip->GetRot(); if (rot.getAngle() != 0) { orient.rotate(rot.getAxis(), rot.getAngle()); } // Apply impulse to cull shot btVector3 impulse = btVector3(orient.x,orient.y,orient.z); impulse = impulse * 55 * (m_spinRate / c_maxSpinRate); shot->m_pPhysicsData->m_pBtRigidBody->applyImpulse(impulse,btVector3(0,0,0)); // Play sound #if CI_AUDIO ci::audio::Output::play(m_sfx_shoot); #elif AL_AUDIO m_pSfxShoot->Play(); #endif } }
void Puppeteer::update(SKELETON::SKELETON& skeleton) { if ( skeleton.joints[XN_SKEL_LEFT_SHOULDER].confidence == 0 || skeleton.joints[XN_SKEL_RIGHT_SHOULDER].confidence == 0 ) { return; } // ----------------------------legs Vec3f &lHip = skeleton.joints[XN_SKEL_LEFT_HIP].position; Vec3f &rHip = skeleton.joints[XN_SKEL_RIGHT_HIP].position; Vec3f &lKnee = skeleton.joints[XN_SKEL_LEFT_KNEE].position; Vec3f &rKnee = skeleton.joints[XN_SKEL_RIGHT_KNEE].position; float legLenL = lKnee.distance(lHip); float legLegR = rKnee.distance(rHip); float legPosL = arduinoUnit * math<float>::clamp(1.0f - (lHip.y - lKnee.y + legLenL * .25f) / (legLenL * 1.25f), 0.0f, 1.0f); float legPosR = arduinoUnit * math<float>::clamp(1.0f - (rHip.y - rKnee.y + legLegR * .25f) / (legLegR * 1.25f), 0.0f, 1.0f); legPosL = CHECK_DELTA(legPosL, lastLegPosL); legPosR = CHECK_DELTA(legPosR, lastLegPosR); lastLegPosL = legPosL; lastLegPosR = legLegR; // ----------------------------hands shoulderL = skeleton.joints[XN_SKEL_LEFT_SHOULDER].position; shoulderR = skeleton.joints[XN_SKEL_RIGHT_SHOULDER].position; // calculate length for both left and right arms based on skeleton size armLenL = shoulderL.distance(skeleton.joints[XN_SKEL_LEFT_ELBOW].position) + skeleton.joints[XN_SKEL_LEFT_ELBOW].position.distance(skeleton.joints[XN_SKEL_LEFT_HAND].position); armLenR = shoulderR.distance(skeleton.joints[XN_SKEL_RIGHT_ELBOW].position) + skeleton.joints[XN_SKEL_RIGHT_ELBOW].position.distance(skeleton.joints[XN_SKEL_RIGHT_HAND].position); // get the 3 axis aligned to the body axisHoriz = (skeleton.joints[XN_SKEL_LEFT_SHOULDER].position - skeleton.joints[XN_SKEL_RIGHT_SHOULDER].position).normalized(); axisVert = (skeleton.joints[XN_SKEL_NECK].position - skeleton.joints[XN_SKEL_TORSO].position).normalized(); normal = axisHoriz.cross(axisVert).normalized(); Vec3f v1 = Vec3f(0, 0, -1).normalized(); Vec3f v2 = normal; // align rectangular region to z-axis Quatf q = Quatf( v1.cross(v2).normalized(), -acos(v1.dot(v2)) ); Matrix33<float> m1 = Matrix33<float>::createRotation(q.getAxis(), q.getAngle()); // normal aligned with z-axis but rectangular region is rotated around the z-axis, we need to undo this rotation Vec3f p = m1.transformVec(axisVert); float theta = atan2(p.y, p.x); Matrix33<float> m2 = Matrix33<float>::createRotation(Vec3f::zAxis(), -theta + M_PI / 2.0f); normalizationMatrix = m2 * m1; handL = normalizationMatrix.transformVec(skeleton.joints[XN_SKEL_LEFT_HAND].position - shoulderL); if (handL.x > 0) handL.x = 0; handR = normalizationMatrix.transformVec(skeleton.joints[XN_SKEL_RIGHT_HAND].position - shoulderR); if (handR.x < 0) handR.x = 0; // ----------------------------send to arduino if (cinder::app::App::get()->getElapsedSeconds() - lastUpdateTime >= updateInterval) { lastUpdateTime = cinder::app::App::get()->getElapsedSeconds(); Vec3f handPosL = Vec3f( arduinoUnit * math<float>::clamp((handL.x / armLenL) * -1.0f, 0.0f, 1.0f), arduinoUnit * math<float>::clamp((handL.y + armLenL) / (armLenL * 2.0f), 0.0f, 1.0f), arduinoUnit * math<float>::clamp((handL.z / armLenL) * -1.0f, 0.0f, 1.0f) ); Vec3f handPosR = Vec3f( arduinoUnit * math<float>::clamp((handR.x / armLenR), 0.0f, 1.0f), arduinoUnit * math<float>::clamp((handR.y + armLenR) / (armLenR * 2.0f), 0.0f, 1.0f), arduinoUnit * math<float>::clamp((handR.z / armLenR) * -1.0f, 0.0f, 1.0f) ); handPosL.x = CHECK_DELTA(handPosL.x, lastHandPosL.x); handPosL.y = CHECK_DELTA(handPosL.y, lastHandPosL.y); handPosL.z = CHECK_DELTA(handPosL.z, lastHandPosL.z); handPosR.x = CHECK_DELTA(handPosR.x, lastHandPosR.x); handPosR.y = CHECK_DELTA(handPosR.y, lastHandPosR.y); handPosR.z = CHECK_DELTA(handPosR.z, lastHandPosR.z); if (Constants::Debug::USE_ARDUINO) { if (UserTracker::getInstance()->activeUserId == mUserTracked) { if (mUserTracked == 0 && ++mUserNoneFrames > 500) { // reset every 500 frames if there's no active user mUserNoneFrames = 0; // arduino->sendMessage("k|"); } else { // send normal message std::ostringstream message; message << round(handPosL.x) << "," << round(handPosL.y) << "," << round(handPosL.z) << "," << round(handPosR.x) << "," << round(handPosR.y) << "," << round(handPosR.z) << "," << round(legPosL) << "," << round(legPosR) << "|"; arduino->sendMessage(message.str()); // std::cout << message.str() << std::endl; } } else { mUserTracked = UserTracker::getInstance()->activeUserId; mUserNoneFrames = 0; // arduino->sendMessage("k|"); } } lastHandPosL.x = handPosL.x; lastHandPosL.y = handPosL.y; lastHandPosL.z = handPosL.z; lastHandPosR.x = handPosR.x; lastHandPosR.y = handPosR.y; lastHandPosR.z = handPosR.z; } }