Reformated gravity.cc

This commit is contained in:
Karma Riuk 2023-05-17 13:25:36 +02:00
parent 487b5fe00b
commit 7df64d460c

View File

@ -1,10 +1,11 @@
#include <string> #include "gravity.h"
#include <sstream>
#include "game.h"
#include <cmath> #include <cmath>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <sstream>
#include "gravity.h" #include <string>
#include "game.h"
static const double constant_field_increment = 1.0; static const double constant_field_increment = 1.0;
static const double newton_field_increment = 1000.0; static const double newton_field_increment = 1000.0;
@ -44,12 +45,16 @@ void gravity_draw (cairo_t * cr) {
output << (g_g / 1000) << "K"; output << (g_g / 1000) << "K";
cairo_save(cr); cairo_save(cr);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_select_font_face(cr,
"sans-serif",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 16); cairo_set_font_size(cr, 16);
std::string output_str = output.str(); std::string output_str = output.str();
cairo_text_extents_t extent; cairo_text_extents_t extent;
cairo_text_extents(cr, output_str.c_str(), &extent); cairo_text_extents(cr, output_str.c_str(), &extent);
cairo_move_to (cr, width/2 - extent.width/2, height/2 + extent.height/2); cairo_move_to(
cr, width / 2 - extent.width / 2, height / 2 + extent.height / 2);
cairo_show_text(cr, output_str.c_str()); cairo_show_text(cr, output_str.c_str());
cairo_restore(cr); cairo_restore(cr);
} }
@ -83,13 +88,12 @@ vec2d gravity_vector (const ball * b) {
} else { } else {
vec2d b_c = vec2d{width / 2.0, height / 2.0} - b->position; vec2d b_c = vec2d{width / 2.0, height / 2.0} - b->position;
double r2 = vec2d::dot(b_c, b_c); double r2 = vec2d::dot(b_c, b_c);
if (r2 < g_r*g_r) { if (r2 < g_r * g_r)
return vec2d{0, 0}; return vec2d{0, 0};
} else { else
return g_g / r2 / sqrt(r2) * b_c; return g_g / r2 / sqrt(r2) * b_c;
} }
} }
}
void gravity_collisions(ball* begin, ball* end) { void gravity_collisions(ball* begin, ball* end) {
if (constant_field) if (constant_field)