本文整理汇总了C++中vec3::GetLengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3::GetLengthSquared方法的具体用法?C++ vec3::GetLengthSquared怎么用?C++ vec3::GetLengthSquared使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3
的用法示例。
在下文中一共展示了vec3::GetLengthSquared方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnTick
//.........这里部分代码省略.........
Spline* _path = game_->GetLevel()->QueryPath()->GetPath(active_path_);
vec3 target = _path->GetValue();
// Check if vehicle stopped. That would mean either crashed against something or too steep hill.
if (mode_run_delta_frame_count%7 == 4 && game_->GetVehicle()->GetHealth() > 0) {
if (QueryVehicleHindered(_time, _velocity)) {
const vec3 _direction = game_->GetVehicle()->GetOrientation() * vec3(0,1,0);
const vec3 wanted_direction = target-_position;
const float forward_angle = LEPRA_XY_ANGLE(wanted_direction, _direction);
// Amplify angle to be either full left or full right.
const float angle = (forward_angle < 0)? -1.0f : 1.0f;
game_->GetVehicle()->SetEnginePower(1, -angle);
SetMode(kModeBackingUp);
return;
}
}
// Are we heading towards an elevator?
if (mode_ != kModeGetOnElevator && mode_ != kModeGetOffElevator && _path->GetType() == "to_elevator") {
if (_path->GetDistanceLeft() <= ELEVATOR_WAIT_DISTANCE) {
if (elevator_get_on_position_.GetDistanceSquared(_position) <= ELEVATOR_WAIT_DISTANCE*ELEVATOR_WAIT_DISTANCE) {
log_.AHeadline("Normal mode close to end of path to elevator, changing mode.");
SetMode(kModeWaitingForElevator);
return;
}
}
}
// Did we just pass (fly by?) the goal?
if (mode_run_delta_frame_count%3 == 0) {
const vec3 goal_direction = game_->GetGoal()->GetPosition() - _position;
if (::fabs(goal_direction.z) < 2 &&
goal_direction.GetLengthSquared() < ELEVATOR_FAR_DISTANCE*ELEVATOR_FAR_DISTANCE &&
_velocity.GetLengthSquared() < 6*6) {
const vec3 vehicle_direction = game_->GetVehicle()->GetOrientation() * vec3(0,1,0);
const float delta_angle = ::fabs(LEPRA_XY_ANGLE(goal_direction, vehicle_direction));
if (delta_angle >= PIF-PIF/4 && delta_angle <= PIF+PIF/4) {
log_.AHeadline("Passed goal, it's right behind me!");
SetMode(kModeBackingUpToGoal);
return;
}
}
}
// Step target (aim) ahead.
{
const float actual_distance2 = target.GetDistanceSquared(_position);
const float max_aim_factor = (mode_ == kModeGetOffElevator)? 1.0f : 1.5f;
const float wanted_distance = aim_distance * Math::Clamp(_velocity.GetLength() / 2.5f, 0.5f, max_aim_factor);
if (actual_distance2 < wanted_distance*wanted_distance) {
const float move_ahead = wanted_distance*1.1f - ::sqrt(actual_distance2);
_path->StepInterpolation(move_ahead * _path->GetDistanceNormal());
log_volatile(log_.Debugf("Stepping %f (=%f m from %f."), move_ahead*_path->GetDistanceNormal(), move_ahead, _path->GetCurrentInterpolationTime()));
}
// Check if we're there yet.
const float t = _path->GetCurrentInterpolationTime();
_path->GotoAbsoluteTime(1.0f);
const float target_distance = (mode_ == kModeGetOnElevator)? ON_ELEVATOR_DISTANCE : ON_GOAL_DISTANCE + game_->GetVehicle()->GetForwardSpeed()/4;
if (IsCloseToTarget(_position, target_distance)) {
const bool towards_elevator = (_path->GetType() == "to_elevator");
if (towards_elevator) {
if (mode_ == kModeGetOnElevator) {
SetMode(kModeOnElevator);
return;