Пример #1
0
void Matrix3DUtils::rotateZ(Matrix3D &m, const float angle, bool local, Vector3D *pivot) {
    if (local) {
        getDir(m, _vector);
        rotateAxis(m, angle, _vector, pivot);
    } else {
        rotateAxis(m, angle, Z_AXIS, pivot);
    }
}
Пример #2
0
void SpaceObject::matchVelocity(std::string objectName) {
  Object *o = ObjectMgr::get().find(objectName);

  if (o && objectName != id) {
    Vector deltaV = o->getVelocity() - velocity;
    if (deltaV.magnitude() > 0.1f) {
      Vector thrustDir = deltaV.normalize();
      Vector axis = (look % thrustDir).normalize();
      if (axis.magnitude() < 0.01f)
        axis = up;
      float ang = look.angle(thrustDir);
      if (ang < 0.01f || fabs(ang - 180.0f) < 0.1f)
        axis = up;

      if (ang > 0.0001f) {
        if (ang > topTurnSpeed * GlobalTime::get().frameSec)
          ang = topTurnSpeed * GlobalTime::get().frameSec;

        rotateAxis(axis, ang);
      }

      thrust(100.0f);
    }
  }
}
Пример #3
0
void SpaceObject::pointTowards(std::string objectName) {
  Object *o = ObjectMgr::get().find(objectName);

  if (o && objectName != id) {
    Vector delta = o->getPos() - pos;
    delta = delta.normalize();
    Vector axis = (delta % look).normalize();
    //std::cerr<<"youch!!!!\n";
    if (axis.magnitude() < 0.01f)
      axis = up;

    float ang = look.angle(delta);

    if (ang < 0.01f || fabs(ang - 180.0f) < 0.1f)
      axis = up;

    if (ang > 0.0001f
        || (look.normalize() - delta.normalize()).magnitude() > 1.0f) {

      if (ang > topTurnSpeed * GlobalTime::get().frameSec)
        ang = topTurnSpeed * GlobalTime::get().frameSec;

      rotateAxis(axis, ang);
    }
  }
}
Пример #4
0
void Object::angularMove() {
  Vector dt1 = omega * (GlobalTime::get().frameSec);
  Vector dt2 = (omega + dt1 * .5) * (GlobalTime::get().frameSec);
  Vector dt3 = (omega + dt2 * .5) * (GlobalTime::get().frameSec);
  Vector dt4 = (omega + dt3) * (GlobalTime::get().frameSec);
  //pos+=velocity*(GlobalTime::get().frameSec);
  Vector incr = (dt1 / 6 + dt2 / 3 + dt3 / 3 + dt4 / 6);
  rotateAxis(incr.normalize(), RAD2DEG(incr.magnitude()));
  alpha *= 0;
}
Пример #5
0
//NOTE - NEED TO FIX LIKE WITH STOP AND MATCHVELOCITY
//180* BUG
void SpaceObject::track(std::string objectName) {
  Object *o = ObjectMgr::get().find(objectName);

  if (o && objectName != id) {
    //Vector from your position to object being tracked
    Vector delta = o->getPos() - pos;
    float seconds = ((-1 * (velocity - o->getVelocity()).magnitude()
        + sqrt(
            (velocity - o->getVelocity()).magnitude()
                * (velocity - o->getVelocity()).magnitude()
                + 2 * topAccel * delta.magnitude())) / (topAccel));
    float seconds2 = ((-1 * (velocity - o->getVelocity()).magnitude()
        - sqrt(
            (velocity - o->getVelocity()).magnitude()
                * (velocity - o->getVelocity()).magnitude()
                + 2 * topAccel * delta.magnitude())) / (topAccel));

    if (seconds2 > seconds)
      seconds = seconds2;

    //float seconds = sqrt((delta.magnitude()*2.0f)/topAccel);
    //Distance 1s from now
    Vector shootFor = delta + (o->getVelocity() - velocity) * seconds;
    shootFor = shootFor.normalize();
    Vector axis = (look % shootFor).normalize();
    //std::cerr<<"youch!!!!\n";
    if (axis.magnitude() < 0.01f)
      axis = up;

    float ang = look.angle(shootFor);

    if (ang < 0.01f || fabs(ang - 180.0f) < 0.1f)
      axis = up;

    if (ang > 0.0001f) {
      if (ang > topTurnSpeed * GlobalTime::get().frameSec)
        ang = topTurnSpeed * GlobalTime::get().frameSec;

      rotateAxis(axis, ang);
    }

    thrust(100.0f);

    //if(detectCollision(o)) done=true;
  }

}
Пример #6
0
void SpaceObject::stop() {
  if (velocity.magnitude()) {
    Vector thrustDir = (velocity * -1).normalize();
    Vector axis = (look % thrustDir).normalize();
    if (axis.magnitude() < 0.01f)
      axis = up;
    float ang = look.angle(thrustDir);
    if (ang < 0.01f || fabs(ang - 180.0f) < 0.1f)
      axis = up;

    if (ang > 0.0001f) {
      if (ang > topTurnSpeed * GlobalTime::get().frameSec)
        ang = topTurnSpeed * GlobalTime::get().frameSec;
      rotateAxis(axis, ang);
    }
    applyForce(thrustDir * topAccel * mass * 0.8f);
  }
}
Пример #7
0
Quat VKTS_APIENTRY rotateRz(const float anglez)
{
    return rotateAxis(anglez, 0.0f, 0.0f, 1.0f);
}
Пример #8
0
Quat VKTS_APIENTRY rotateRy(const float angley)
{
    return rotateAxis(angley, 0.0f, 1.0f, 0.0f);
}
Пример #9
0
Quat VKTS_APIENTRY rotateRx(const float anglex)
{
    return rotateAxis(anglex, 1.0f, 0.0f, 0.0f);
}