Reformated gravity.cc
This commit is contained in:
parent
487b5fe00b
commit
7df64d460c
24
gravity.cc
24
gravity.cc
@ -1,10 +1,11 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "gravity.h"
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "gravity.h"
|
||||
#include "game.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
static const double constant_field_increment = 1.0;
|
||||
static const double newton_field_increment = 1000.0;
|
||||
@ -44,12 +45,16 @@ void gravity_draw (cairo_t * cr) {
|
||||
output << (g_g / 1000) << "K";
|
||||
cairo_save(cr);
|
||||
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);
|
||||
std::string output_str = output.str();
|
||||
cairo_text_extents_t 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_restore(cr);
|
||||
}
|
||||
@ -83,13 +88,12 @@ vec2d gravity_vector (const ball * b) {
|
||||
} else {
|
||||
vec2d b_c = vec2d{width / 2.0, height / 2.0} - b->position;
|
||||
double r2 = vec2d::dot(b_c, b_c);
|
||||
if (r2 < g_r*g_r) {
|
||||
if (r2 < g_r * g_r)
|
||||
return vec2d{0, 0};
|
||||
} else {
|
||||
else
|
||||
return g_g / r2 / sqrt(r2) * b_c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gravity_collisions(ball* begin, ball* end) {
|
||||
if (constant_field)
|
||||
|
Loading…
Reference in New Issue
Block a user