Skip to content

Commit

Permalink
added AlignConsecutiveAssignments to .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
gue-ni committed Apr 25, 2023
1 parent 572ec92 commit a887122
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 175 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
Expand Down
20 changes: 10 additions & 10 deletions OpenGL_Flightsim/src/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
glm::vec3 get_intercept_point(const glm::vec3& position, const glm::vec3& velocity, const glm::vec3& target_position,
const glm::vec3& target_velocity)
{
auto velocity_delta = target_velocity - velocity;
auto position_delta = target_position - position;
auto velocity_delta = target_velocity - velocity;
auto position_delta = target_position - position;
auto time_to_intercept = glm::length(position_delta) / glm::length(velocity_delta);
return target_position + target_velocity * time_to_intercept;
}

void fly_towards(Airplane& airplane, const glm::vec3& target)
{
auto& rb = airplane;
auto& rb = airplane;
auto& joystick = airplane.joystick;
auto position = rb.position;
auto position = rb.position;
auto direction = glm::normalize(rb.inverse_transform_direction(target - rb.position));
auto angle = glm::angle(phi::FORWARD, direction);
auto angle = glm::angle(phi::FORWARD, direction);

float rudder = direction.z;
float rudder = direction.z;
float elevator = direction.y * 5.0f;

float m = phi::PI / 4.0f;
float agressive_roll = direction.z;
float wings_level_roll = rb.right().y;
float m = phi::PI / 4.0f;
float agressive_roll = direction.z;
float wings_level_roll = rb.right().y;
float wings_level_influence = phi::inverse_lerp(0.0f, m, glm::clamp(angle, -m, m));
float aileron = phi::lerp(wings_level_roll, agressive_roll, wings_level_influence);
float aileron = phi::lerp(wings_level_roll, agressive_roll, wings_level_influence);

joystick = glm::clamp(glm::vec4(aileron, rudder, elevator, 0.0f), glm::vec4(-1.0f), glm::vec4(1.0f));
}
Expand Down
28 changes: 14 additions & 14 deletions OpenGL_Flightsim/src/clipmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "gfx.h"

constexpr unsigned int primitive_restart = 0xFFFFU;
const std::string path = "assets/textures/terrain/1/";
const std::string path = "assets/textures/terrain/1/";

struct Seam {
gfx::gl::VertexBuffer vbo;
Expand All @@ -12,7 +12,7 @@ struct Seam {

Seam(int columns, float size)
{
int rows = 1;
int rows = 1;
index_count = columns;

std::vector<glm::vec3> vertices;
Expand Down Expand Up @@ -132,8 +132,8 @@ class Clipmap : public gfx::Object3D
{
#if 1
if (!context.is_shadow_pass) {
auto camera_pos = context.camera->get_world_position();
float height = camera_pos.y;
auto camera_pos = context.camera->get_world_position();
float height = camera_pos.y;
auto camera_pos_xy = glm::vec2(camera_pos.x, camera_pos.z);

heightmap.bind(2);
Expand All @@ -159,12 +159,12 @@ class Clipmap : public gfx::Object3D
for (int l = min_level; l <= levels; l++) {
const int rows = 5, cols = 5;
// float border = 0.0f;
float scale = std::pow(2.0f, l);
float next_scale = std::pow(2.0f, l + 2);
float scale = std::pow(2.0f, l);
float next_scale = std::pow(2.0f, l + 2);
float scaled_segment_size = segment_size * scale;
float tile_size = segments * scaled_segment_size;
glm::vec2 snapped = glm::floor(camera_pos_xy / next_scale) * next_scale;
auto base = calc_base(l, camera_pos_xy);
float tile_size = segments * scaled_segment_size;
glm::vec2 snapped = glm::floor(camera_pos_xy / next_scale) * next_scale;
auto base = calc_base(l, camera_pos_xy);

shader.uniform("u_Scale", scale);
shader.uniform("u_SegmentSize", scaled_segment_size);
Expand All @@ -183,7 +183,7 @@ class Clipmap : public gfx::Object3D
center.draw();
} else {
auto prev_base = calc_base(l - 1, camera_pos_xy);
auto diff = glm::abs(base - prev_base);
auto diff = glm::abs(base - prev_base);

auto l_offset = glm::vec2(tile_size, tile_size);
if (diff.x == tile_size) {
Expand Down Expand Up @@ -283,11 +283,11 @@ class Clipmap : public gfx::Object3D

glm::vec2 calc_base(int level, glm::vec2 camera_pos)
{
float scale = std::pow(2.0f, level);
float next_scale = std::pow(2.0f, level + 2);
float tile_size = segments * segment_size * scale;
float scale = std::pow(2.0f, level);
float next_scale = std::pow(2.0f, level + 2);
float tile_size = segments * segment_size * scale;
glm::vec2 snapped = glm::floor(camera_pos / next_scale) * next_scale;
glm::vec2 base = snapped - tile_size * 2.0f;
glm::vec2 base = snapped - tile_size * 2.0f;
return base;
}

Expand Down
16 changes: 8 additions & 8 deletions OpenGL_Flightsim/src/collider.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ struct Heightmap {
float get_height(const glm::vec2& coord) const
{
glm::vec2 tmp = glm::clamp(coord / magnification, glm::vec2(-1.0f), glm::vec2(1.0f));
auto uv = phi::scale(tmp, glm::vec2(-1.0f), glm::vec2(1.0f), glm::vec2(0.0f), glm::vec2(1.0f));
float value = sample(uv).r;
float height = scale * value + shift;
auto uv = phi::scale(tmp, glm::vec2(-1.0f), glm::vec2(1.0f), glm::vec2(0.0f), glm::vec2(1.0f));
float value = sample(uv).r;
float height = scale * value + shift;
return height;
}
};
Expand All @@ -102,13 +102,13 @@ bool test_collision(const Ray& r, const Sphere& s, float* t)
// test collision between two spheres
bool test_collision(const Sphere& a, const Sphere& b, phi::CollisionInfo* info)
{
float distance = glm::length(a.center - b.center);
float distance = glm::length(a.center - b.center);
float radius_sum = a.radius + b.radius;

if (distance < radius_sum) {
info->normal = glm::normalize(b.center - a.center);
info->normal = glm::normalize(b.center - a.center);
info->penetration = radius_sum - distance;
info->point = a.center + a.radius * info->normal;
info->point = a.center + a.radius * info->normal;
return true;
} else {
return false;
Expand Down Expand Up @@ -167,8 +167,8 @@ bool test_moving_collision(const Sphere& s0, const glm::vec3& velocity0, const S
#else
// Christer_Ericson-Real-Time_Collision_Detection.pdf#page=226
float tmp_t = 0.0f;
auto v = velocity0 - velocity1;
auto vlen = glm::length(v);
auto v = velocity0 - velocity1;
auto vlen = glm::length(v);

Ray ray(s0.center, v / vlen);
Sphere sphere(s1.center, s0.radius + s1.radius);
Expand Down
62 changes: 31 additions & 31 deletions OpenGL_Flightsim/src/flightmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ float get_air_density(float altitude)
{
assert(0.0f <= altitude && altitude <= 11000.0f);
float temperature = get_air_temperature(altitude);
float pressure = 101325.0f * std::pow(1 - 0.0065f * (altitude / 288.15f), 5.25f);
float pressure = 101325.0f * std::pow(1 - 0.0065f * (altitude / 288.15f), 5.25f);
return 0.00348f * (pressure / temperature);
}

Expand All @@ -47,12 +47,12 @@ struct Airfoil {
// lift_coeff, drag_coeff
std::tuple<float, float> sample(float alpha) const
{
int max_index = static_cast<int>(data.size() - 1);
float t = phi::inverse_lerp(min_alpha, max_alpha, alpha) * max_index;
float integer = std::floor(t);
int max_index = static_cast<int>(data.size() - 1);
float t = phi::inverse_lerp(min_alpha, max_alpha, alpha) * max_index;
float integer = std::floor(t);
float fractional = t - integer;
int index = static_cast<int>(integer);
auto value = (index < max_index) ? phi::lerp(data[index], data[index + 1], fractional) : data[max_index];
int index = static_cast<int>(integer);
auto value = (index < max_index) ? phi::lerp(data[index], data[index + 1], fractional) : data[max_index];
return {value.y, value.z};
}
};
Expand Down Expand Up @@ -85,18 +85,18 @@ struct PropellorEngine : public Engine {

void apply_forces(phi::RigidBody* rigid_body, phi::Seconds dt) override
{
float speed = rigid_body->get_speed();
float altitude = rigid_body->position.y;
float speed = rigid_body->get_speed();
float altitude = rigid_body->position.y;
float engine_power = phi::units::watts(horsepower);

const float a = 1.83f, b = -1.32f; // efficiency curve fit coefficients
float turnover_rate = rpm / 60.0f;
float turnover_rate = rpm / 60.0f;
float propellor_advance_ratio = speed / (turnover_rate * propellor_diameter);
float propellor_efficiency = a * propellor_advance_ratio + b * std::pow(propellor_advance_ratio, 3);
float propellor_efficiency = a * propellor_advance_ratio + b * std::pow(propellor_advance_ratio, 3);
assert(0.0f <= propellor_efficiency && propellor_efficiency <= 1.0f);

const float c = 0.12f; // mechanical power loss factor
float air_density = isa::get_air_density(altitude);
const float c = 0.12f; // mechanical power loss factor
float air_density = isa::get_air_density(altitude);
float power_drop_off_factor = ((air_density / isa::sea_level_air_density) - c) / (1 - c);
assert(0.0f <= power_drop_off_factor && power_drop_off_factor <= 1.0f);

Expand All @@ -118,19 +118,19 @@ class Wing : public phi::ForceGenerator
const glm::vec3 normal;
const glm::vec3 center_of_pressure;

float lift_multiplier = 1.0f;
float drag_multiplier = 1.0f;
float lift_multiplier = 1.0f;
float drag_multiplier = 1.0f;
float efficiency_factor = 1.0f;

float deflection = 0.0f;
float control_input = 0.0f;
float min_deflection = -10.0f;
float max_deflection = +10.0f;
float max_actuator_speed = 90.0f;
float deflection = 0.0f;
float control_input = 0.0f;
float min_deflection = -10.0f;
float max_deflection = +10.0f;
float max_actuator_speed = 90.0f;
float max_actuator_torque = 6000.0f;

public:
float incidence = 0.0f;
float incidence = 0.0f;
bool is_control_surface = true;

Wing(const Airfoil* airfoil, const glm::vec3& position, float area, float span, const glm::vec3& normal = phi::UP)
Expand Down Expand Up @@ -165,7 +165,7 @@ class Wing : public phi::ForceGenerator
void apply_forces(phi::RigidBody* rigid_body, phi::Seconds dt) override
{
glm::vec3 local_velocity = rigid_body->get_point_velocity(center_of_pressure);
float speed = glm::length(local_velocity);
float speed = glm::length(local_velocity);

if (speed <= phi::EPSILON) return;

Expand All @@ -191,8 +191,8 @@ class Wing : public phi::ForceGenerator
float air_density = isa::get_air_density(0.0f); // something is not right here, so let's assume sea level

float dynamic_pressure = 0.5f * std::pow(speed, 2) * air_density * area;
glm::vec3 lift = lift_direction * lift_coeff * lift_multiplier * dynamic_pressure;
glm::vec3 drag = drag_direction * (drag_coeff + induced_drag_coeff) * drag_multiplier * dynamic_pressure;
glm::vec3 lift = lift_direction * lift_coeff * lift_multiplier * dynamic_pressure;
glm::vec3 drag = drag_direction * (drag_coeff + induced_drag_coeff) * drag_multiplier * dynamic_pressure;

// aerodynamic forces are applied at the center of pressure
rigid_body->add_force_at_point(lift + drag, center_of_pressure);
Expand All @@ -215,7 +215,7 @@ class Wing : public phi::ForceGenerator
deflection = (control_input >= 0.0f ? max_deflection : min_deflection) * std::abs(control_input);
#endif

auto axis = glm::normalize(glm::cross(phi::FORWARD, normal));
auto axis = glm::normalize(glm::cross(phi::FORWARD, normal));
auto rotation = glm::rotate(glm::mat4(1.0f), glm::radians(incidence + deflection), axis);
return glm::vec3(rotation * glm::vec4(normal, 1.0f));
}
Expand All @@ -229,9 +229,9 @@ struct Airplane : public phi::RigidBody {
bool is_landed = false;

#if LOG_FLIGHT
float log_timer = 0.0f;
float log_timer = 0.0f;
float log_intervall = 0.1f;
float flight_time = 0.0f;
float flight_time = 0.0f;
std::ofstream log_file;
#endif

Expand Down Expand Up @@ -267,8 +267,8 @@ struct Airplane : public phi::RigidBody {
#if LOG_FLIGHT
flight_time += dt;
if ((log_timer -= dt) <= 0.0f) {
log_timer = log_intervall;
auto av = glm::degrees(rigid_body.angular_velocity);
log_timer = log_intervall;
auto av = glm::degrees(rigid_body.angular_velocity);
auto euler = glm::degrees(glm::eulerAngles(glm::normalize(rigid_body.orientation)));

/* clang-format off */
Expand Down Expand Up @@ -299,7 +299,7 @@ struct Airplane : public phi::RigidBody {
if (is_landed) {
// std::cout << "contact\n";
// calculate friction with ground
const float static_friction_coeff = 0.2f;
const float static_friction_coeff = 0.2f;
const float kinetic_friction_coeff = 0.55f;
if (get_speed() > phi::EPSILON) {
add_friction(phi::UP, glm::normalize(velocity), kinetic_friction_coeff);
Expand Down Expand Up @@ -337,7 +337,7 @@ struct Airplane : public phi::RigidBody {
// mach number
float get_mach() const
{
float temperature = isa::get_air_temperature(get_altitude());
float temperature = isa::get_air_temperature(get_altitude());
float speed_of_sound = std::sqrt(1.402f * 286.f * temperature);
return get_speed() / speed_of_sound;
}
Expand All @@ -353,7 +353,7 @@ struct Airplane : public phi::RigidBody {
float get_ias() const
{
// See: https://aerotoolbox.com/airspeed-conversions/
float air_density = isa::get_air_density(get_altitude());
float air_density = isa::get_air_density(get_altitude());
float dynamic_pressure = 0.5f * std::pow(get_speed(), 2) * air_density; // bernoulli's equation
return std::sqrt(2 * dynamic_pressure / isa::sea_level_air_density);
}
Expand Down
Loading

0 comments on commit a887122

Please sign in to comment.