/* MMDAgent_str2rot: get rotation from string */ bool MMDAgent_str2rot(const char *str, btQuaternion *rot) { float vec[3]; if (MMDAgent_str2fvec(str, vec, 3) == false) return false; rot->setEulerZYX(MMDFILES_RAD(vec[2]), MMDFILES_RAD(vec[1]), MMDFILES_RAD(vec[0])); return true; }
/* PMDObject::updateModelRootRotation: update model rotation of root bone */ bool PMDObject::updateModelRootRotation(float fps) { btQuaternion tmpRot; PMDBone *b; bool ret = false; btQuaternion r; float diff; float maxStep; if (m_isEnable == false) return false; m_isRotating = false; /* get root bone */ b = m_pmd.getRootBone(); /* target rotation is m_offsetRot */ /* turn rotation of root bone closer to m_offsetRot */ b->getCurrentRotation(&r); if (m_offsetRot != r) { /* difference calculation */ r = r - m_offsetRot; diff = r.length(); if (diff > PMDOBJECT_MINSPINDIFF) { if (m_spinSpeed >= 0.0f && fps != 0.0f) { /* max turn speed */ maxStep = MMDFILES_RAD(m_spinSpeed) / fps; if (diff > maxStep) { b->getCurrentRotation(&tmpRot); tmpRot = tmpRot.slerp(m_offsetRot, maxStep / diff); b->setCurrentRotation(&tmpRot); m_isRotating = true; } else { b->setCurrentRotation(&m_offsetRot); ret = true; } } else { /* current * 0.95 + target * 0.05 */ b->getCurrentRotation(&tmpRot); tmpRot = tmpRot.slerp(m_offsetRot, 1.0f - PMDOBJECT_SPINSPEEDRATE); b->setCurrentRotation(&tmpRot); m_isRotating = true; } } else { /* set target offset directory if small difference */ b->setCurrentRotation(&m_offsetRot); ret = true; } b->update(); } return ret; }
/* Render::applyProjectionMatirx: update projection matrix */ void Render::applyProjectionMatrix() { double y = RENDER_VIEWPOINTFRUSTUMNEAR * tan(MMDFILES_RAD(m_currentFovy) * 0.5); double x = y * m_width / m_height; glFrustum(-x, x, -y, y, RENDER_VIEWPOINTFRUSTUMNEAR, RENDER_VIEWPOINTFRUSTUMFAR); }
/* Render::updateRotationFromAngle: update rotation quaternion from angle */ void Render::updateRotationFromAngle() { m_rot = btQuaternion(btVector3(0, 0, 1), MMDFILES_RAD(m_angle.z())) * btQuaternion(btVector3(1, 0, 0), MMDFILES_RAD(m_angle.x())) * btQuaternion(btVector3(0, 1, 0), MMDFILES_RAD(m_angle.y())); }