void System::ROTATE_FRAGMENT(double degree_amount, VECTOR direction,int Gr, VECTOR center){ /** \param[in] degree_amount The magnitude of rotation, in degrees \param[in] direction The vector definining the axis of rotation. The magnitude of this vector does not matter. \param[in] Gr The ID (not index!) of the group/fragment to be rotated \param[in] center The vector defining the center of the rotating coordinate system Simplest manipulation Rotates the fragment with the fragment ID "int Gr" on amount of "double amount" around the axis given by "VECTOR direction" around the given center */ int v = get_fragment_index_by_fragment_id(Gr); VECTOR dir; dir = center - Fragments[v].Group_RB.rb_cm; double amount = dir.length(); // Translate the fragment's center of mass to the "center" point TRANSLATE_FRAGMENT(amount, dir,Gr); // Rotate the fragment around new center of mass ROTATE_FRAGMENT(degree_amount, direction, Gr); // Translate the fragment's center of mass back to the original position TRANSLATE_FRAGMENT(-amount, dir,Gr); }
/* -------------------------------------------------------------------------------------------------- - check collision with stairs -------------------------------------------------------------------------------------------------- */ bool PlanesPhysicHandler::ColisionWithStair(const AABB & actorBB, const VECTOR &Speed, VECTOR &ModifiedSpeed) { float moveX = Speed.x; float moveZ = Speed.z; // calculate norm of speed VECTOR speedNorm = Speed.unit(); float startX = (actorBB.P.x+actorBB.E.x)/2.0f; float startZ = (actorBB.P.z+actorBB.E.z)/2.0f; std::vector<StairPlane>::const_iterator it = _stairs.begin(); std::vector<StairPlane>::const_iterator end = _stairs.end(); // for each stairs for(int i=0; it != end; ++it, ++i) { // project point to plane and check if we cross it float DotProduct=speedNorm.dot(it->Normal); // Determine If Ray Parallel To Plane if (abs(DotProduct) > 0.000001f) { // Find Distance To Collision Point float l2=(it->Normal.dot(it->C1-VECTOR(startX, actorBB.P.y, startZ)))/DotProduct; // Test If Collision Behind Start or after end if (l2 > 0 && l2 < Speed.length()) { float collionsX = startX + (speedNorm.x * l2); float collionsZ = startZ + (speedNorm.z * l2); if((collionsX >= it->minX) && (collionsX <= it->maxX)) { if((collionsZ >= it->minZ) && (collionsZ <= it->maxZ)) { VECTOR spmY(Speed.x, 0, Speed.z); VECTOR Vt(it->Normal.dot(spmY)*it->Normal); VECTOR Vn(spmY - Vt); ModifiedSpeed = Vn; return true; } } } } } return false; }