void Matrix4x3::setupParentToLocal(const Vector3& pos, const EulerAngles& orient) { RotationMatrix orientMatrix; orientMatrix.setup(orient); setupParentToLocal(pos,orientMatrix); }
/// \param angles The orientation (unit) vector that you want to reflect /// \return Euler angles that are reflected about the slope of the plane. EulerAngles Plane::reflectOrientation(const EulerAngles& angles) const { EulerAngles out; Vector3 look, up, right; RotationMatrix rotMat; // get look and up vector from euler angles rotMat.setup(angles); look = rotMat.objectToInertial(Vector3(0.0f,0.0f,1.0f)); up = rotMat.objectToInertial(Vector3(0.0f,1.0f,0.0f)); // reflect the look and up vectors over the plane look = reflectOrientation(look); up = -reflectOrientation(up); // calculate right vector right = Vector3::crossProduct( up, look); right.normalize(); // create a rotation matrix from right, up, and look rotMat.m11 = right.x; rotMat.m12 = right.y; rotMat.m13 = right.z; rotMat.m21 = up.x; rotMat.m22 = up.y; rotMat.m23 = up.z; rotMat.m31 = look.x; rotMat.m32 = look.y; rotMat.m33 = look.z; // calculate new euler angles from the matrix out.fromRotationMatrix(rotMat); return out; }
// Resets camera to behind target object void TetherCamera::reset() { Vector3 target; float targetHeading; assert(m_objects); // object manager doesn't exist GameObject* obj = m_objects->getObjectPointer(m_targetObjectID); assert(obj); // object to follow doesn't exist targetHeading = obj->getOrientation().heading; target = obj->getPosition(); target.y += 3.0f; cameraOrient.set(targetHeading, 0.0f,0.0f); RotationMatrix cameraMatrix; cameraMatrix.setup(cameraOrient); Vector3 bOffset(0.0f,0.0f, -maxDist); Vector3 iOffset = cameraMatrix.objectToInertial(bOffset); cameraPos = target + iOffset; }
void BulletObject::updateRay() { EulerAngles lookEuler = getOrientation(); lookEuler.bank = 0.0f; RotationMatrix look; look.setup(lookEuler); m_bulletRay = look.objectToInertial(Vector3(0.0f,0.0f,m_range)); }
/// \param pos Specifies the position of the local space within the /// parent space. /// \param orient Specifies the orientation of the local space within /// the parent space as an Euler angle triplet. void Matrix4x3::setupParentToLocal(const Vector3 &pos, const EulerAngles &orient) { // Create a rotation matrix. RotationMatrix orientMatrix; orientMatrix.setup(orient); // Setup the 4x3 matrix. setupParentToLocal(pos, orientMatrix); }
/// \param pos Specifies the position of the local space within the /// parent space. /// \param orient Specifies the orientation of the local space within /// the parent space as an Euler angle triplet. void Matrix4x3::setupLocalToParent(const Vector3 &pos, const EulerAngles &orient) { // Create a rotation matrix. RotationMatrix orientMatrix; orientMatrix.setup(orient); // Setup the 4x3 matrix. Note: if we were really concerned with // speed, we could create the matrix directly into these variables, // without using the temporary RotationMatrix object. This would // save us a function call and a few copy operations. setupLocalToParent(pos, orientMatrix); }
bool Ned3DObjectManager::interactPlaneTerrain(PlaneObject &plane, TerrainObject &terrain) { Terrain *terr = terrain.getTerrain(); if(terr == NULL) return false; //test for plane collision with terrain Vector3 planePos = plane.getPosition(); EulerAngles planeOrient = plane.getOrientation(); Vector3 disp = planePos - disp; RotationMatrix planeMatrix; planeMatrix.setup(plane.getOrientation()); // get plane's orientation float planeBottom = plane.getBoundingBox().min.y; float terrainHeight = terr->getHeight(planePos.x,planePos.z); if(plane.isPlaneAlive() && planeBottom < terrainHeight) { //collision Vector3 viewVector = planeMatrix.objectToInertial(Vector3(0,0,1)); if(viewVector * terr->getNormal(planePos.x,planePos.z) < -0.5f // dot product || plane.isCrashing()) { plane.killPlane(); int partHndl = gParticle.createSystem("planeexplosion"); gParticle.setSystemPos(partHndl, plane.getPosition()); int boomHndl = gSoundManager.requestSoundHandle("Boom.wav"); int boomInst = gSoundManager.requestInstance(boomHndl); if(boomInst != SoundManager::NOINSTANCE) { gSoundManager.setPosition(boomHndl,boomInst,plane.getPosition()); gSoundManager.play(boomHndl,boomInst); gSoundManager.releaseInstance(boomHndl,boomInst); } plane.setSpeed(0.0f); planePos += 2.0f * viewVector; planeOrient.pitch = kPi / 4.0f; planeOrient.bank = kPi / 4.0f; plane.setOrientation(planeOrient); } else planePos.y = terrainHeight + planePos.y - planeBottom; //plane.setPPosition(planePos); return true; } return false; }
void PlaneObject::damage(int hp) { // if god mode is on leave if (!takeDamage) return; m_hp -= hp; setTextureAndSmoke(); // change to a texture with more damange on it if(m_isPlaneAlive && m_hp <= 0) { m_planeState = PS_CRASHING; m_velocity = Vector3::kForwardVector; m_eaOrient[0].pitch = degToRad(20); RotationMatrix r; r.setup(m_eaOrient[0]); m_velocity = r.objectToInertial(m_velocity); m_velocity *= m_maxSpeed * m_speedRatio * 20.0f; } }
bool Ned3DObjectManager::interactPlaneWater(PlaneObject &plane, WaterObject &water) { Water *pWater = water.getWater(); if(pWater == NULL) return false; // Test for plane collision with water Vector3 planePos = plane.getPosition(); EulerAngles planeOrient = plane.getOrientation(); Vector3 disp = planePos - disp; RotationMatrix planeMatrix; planeMatrix.setup(plane.getOrientation()); // get plane's orientation float planeBottom = plane.getBoundingBox().min.y; float waterHeight = pWater->getWaterHeight(); if(plane.isPlaneAlive() && planeBottom < waterHeight) { //collision Vector3 viewVector = planeMatrix.objectToInertial(Vector3(0,0,1)); plane.killPlane(); plane.setSpeed(0.0f); planePos += 2.0f * viewVector; planeOrient.pitch = kPi / 4.0f; planeOrient.bank = kPi / 4.0f; plane.setOrientation(planeOrient); plane.setPPosition(planePos); int partHndl = gParticle.createSystem("planeexplosion"); gParticle.setSystemPos(partHndl, plane.getPosition()); int boomHndl = gSoundManager.requestSoundHandle("Boom.wav"); int boomInst = gSoundManager.requestInstance(boomHndl); if(boomInst != SoundManager::NOINSTANCE) { gSoundManager.setPosition(boomHndl,boomInst,plane.getPosition()); gSoundManager.play(boomHndl,boomInst); gSoundManager.releaseInstance(boomHndl,boomInst); } return true; } return false; }