Пример #1
0
void AimHelperHudget::update(float deltaSec) {
    Ship* ship = m_hud->player()->ship();

    if (!ship) {
        setVisible(false);
        return;
    }

    WorldObject* targetObject = ship->targetObject();

    if(!targetObject) {
        setVisible(false);
        return;
    }

    calculateTargetPoint(targetObject);

    if (m_lastTargetWorldObject == targetObject && m_lastVisible) {
        m_smoothTargetPoint = glm::mix(m_smoothTargetPoint, m_targetPoint, 5.0f * deltaSec);
    } else {
        m_smoothTargetPoint = m_targetPoint;
    }

    pointToWorldPoint(m_smoothTargetPoint);
    setRelativeDistance(1.0f);

    if (hovered()) {
        setDirectionAngle(directionAngle() + 12.0f * deltaSec);
    } else {
        setDirectionAngle(0.0f);
    }

    m_lastTargetWorldObject = targetObject;
    m_lastVisible = visible();
}
Пример #2
0
void Object::lookAt(Point * to)
{
    Point direction(position->x + 10, 0, position->z);
    Point * p = new Point(to->x - position->x, 0, to->z - position->z);

    if (p->z <= 0) direction.z *= -1;

    float pModule = sqrt(pow(p->x, 2) + pow(p->z, 2));
    float dModule = sqrt(pow(direction.x, 2) + pow(direction.z, 2));

    float product = p->x * direction.x + p->z + direction.z;
    float productModule = pModule * dModule;

    if (productModule != 0) {
        float aux = product / productModule;

        if ( aux >= -1 && aux <= 1) {
            float angle = acos(aux) * 180 / M_PI;

            if (p->z <= 0) angle = 360 - angle;

            setDirectionAngle(angle);
        }
    }
}
Пример #3
0
void Object::rotate(float amount) {
    setDirectionAngle(directionAngle + amount);
}
Пример #4
0
Object::Object(Point * initialPosition, float m) {
    position = initialPosition;
    setDirectionAngle(0);
    movementAmount = m;
}
Пример #5
0
Object::Object(float m) {
    position = new Point(0, 0, 0);
    setDirectionAngle(0);
    movementAmount = m;
}