feat: More info drawn
This commit is contained in:
@@ -122,6 +122,11 @@ float normalize_angle_diff(const float diff)
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float angle_to_heading(float const angle)
|
||||||
|
{
|
||||||
|
return normalize_angle(angle) * 180.0f / M_PIf;
|
||||||
|
}
|
||||||
|
|
||||||
int rand_int(int const min, int const max)
|
int rand_int(int const min, int const max)
|
||||||
{
|
{
|
||||||
return SDL_rand(max - min) + min;
|
return SDL_rand(max - min) + min;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ vec2 v2i_to_v2(vec2i const v);
|
|||||||
// Angle functions
|
// Angle functions
|
||||||
float normalize_angle(float const angle);
|
float normalize_angle(float const angle);
|
||||||
float normalize_angle_diff(float const diff);
|
float normalize_angle_diff(float const diff);
|
||||||
|
float angle_to_heading(float const angle);
|
||||||
|
|
||||||
// Random generation functions
|
// Random generation functions
|
||||||
int rand_int(int const min, int const max);
|
int rand_int(int const min, int const max);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
|
|||||||
if (key_states[SDL_SCANCODE_E]) renderer.zoom_camera(-zoom_spd * (1.0f / 60.0f));
|
if (key_states[SDL_SCANCODE_E]) renderer.zoom_camera(-zoom_spd * (1.0f / 60.0f));
|
||||||
|
|
||||||
// Clear
|
// Clear
|
||||||
renderer.color(0, 0, 0, 255);
|
renderer.color(0, 0, 0);
|
||||||
SDL_RenderClear(sdl_renderer);
|
SDL_RenderClear(sdl_renderer);
|
||||||
|
|
||||||
// World draw
|
// World draw
|
||||||
@@ -80,14 +80,14 @@ int main(int argc, char *argv[])
|
|||||||
world.tick(1.0f / 60.0f);
|
world.tick(1.0f / 60.0f);
|
||||||
|
|
||||||
// World axis
|
// World axis
|
||||||
renderer.color(32, 32, 32, 255);
|
renderer.color(32, 32, 32);
|
||||||
renderer.line(-vec2_unity * 2000, vec2_unity * 2000);
|
renderer.line(-vec2_unity * 2000, vec2_unity * 2000);
|
||||||
renderer.line(-vec2_unitx * 2000, vec2_unitx * 2000);
|
renderer.line(-vec2_unitx * 2000, vec2_unitx * 2000);
|
||||||
|
|
||||||
// Scale and position
|
// Scale and position
|
||||||
vec2 center = renderer.get_camera_pos();
|
vec2 center = renderer.get_camera_pos();
|
||||||
float zoom = 100.0f/renderer.get_zoom();
|
float zoom = 100.0f/renderer.get_zoom();
|
||||||
renderer.color(128, 128, 255, 255);
|
renderer.color(128, 128, 255);
|
||||||
renderer.dbg_txt(0, 0, "(%0.1f, %0.1f) @%0.2f", center.x, center.y, zoom);
|
renderer.dbg_txt(0, 0, "(%0.1f, %0.1f) @%0.2f", center.x, center.y, zoom);
|
||||||
|
|
||||||
SDL_RenderPresent(sdl_renderer);
|
SDL_RenderPresent(sdl_renderer);
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ public:
|
|||||||
return 1.0f / _scale;
|
return 1.0f / _scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
void color(uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(_sdl, r, g, b, a);
|
SDL_SetRenderDrawColor(_sdl, r, g, b, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
void line(vec2 a, vec2 b)
|
void line(vec2 a, vec2 b)
|
||||||
@@ -126,7 +126,7 @@ public:
|
|||||||
SDL_RenderLines(_sdl, points, 5);
|
SDL_RenderLines(_sdl, points, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dbg_txt(float x, float y, const char *fmt, ...)
|
void dbg_txt(float const x, float const y, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -135,6 +135,21 @@ public:
|
|||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void txt(vec2 const pos, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
|
|
||||||
|
vec2 p = to_screenv2(to_viewv2(pos));
|
||||||
|
SDL_RenderDebugText(_sdl, p.x, p.y, buf);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dxd
|
} // namespace dxd
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ void dxd::sim::AFSpawner::tick(float timestep, World *world)
|
|||||||
|
|
||||||
void dxd::sim::AFSpawner::draw(Renderer *rend)
|
void dxd::sim::AFSpawner::draw(Renderer *rend)
|
||||||
{
|
{
|
||||||
rend->color(0, 127, 0, 255);
|
rend->color(0, 127, 0);
|
||||||
rend->rect(vec2_zero, _SPAWN_BOUNDS*2);
|
rend->rect(vec2_zero, _SPAWN_BOUNDS*2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,17 @@ void dxd::sim::Aircraft::tick(float timestep, World *world)
|
|||||||
|
|
||||||
void dxd::sim::Aircraft::draw(Renderer *rend)
|
void dxd::sim::Aircraft::draw(Renderer *rend)
|
||||||
{
|
{
|
||||||
rend->color(255, 255, 255, 255);
|
// Indicator
|
||||||
|
rend->color(255, 255, 255);
|
||||||
rend->box(_position, 1);
|
rend->box(_position, 1);
|
||||||
rend->line(_position, _position + polar_to_vec2(_direction, 3));
|
rend->line(_position, _position + polar_to_vec2(_direction, 3));
|
||||||
|
|
||||||
rend->color(255, 64, 64, 255);
|
// Status
|
||||||
|
rend->color(0, 255, 0);
|
||||||
|
rend->txt(_position - vec2_unity, "%03.0f", angle_to_heading(_direction));
|
||||||
|
rend->txt(_position - vec2_unity*2.5f, "%03.0f", _speed * _SPD_TO_KTS);
|
||||||
|
|
||||||
|
// Target
|
||||||
|
rend->color(255, 64, 64);
|
||||||
rend->diamond(_target, 1);
|
rend->diamond(_target, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ private:
|
|||||||
vec2 _target;
|
vec2 _target;
|
||||||
int _trail_cooldown;
|
int _trail_cooldown;
|
||||||
|
|
||||||
const int _TRAIL_DELAY = 60;
|
const int _TRAIL_DELAY = 120;
|
||||||
const int _TRAIL_DURATION = 420;
|
const int _TRAIL_DURATION = 420;
|
||||||
const float _MAX_TURN_RATE = 0.3f;
|
const float _MAX_TURN_RATE = 0.3f;
|
||||||
|
const float _SPD_TO_KTS = 60.0f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Aircraft(vec2 position, float direction, float speed, vec2 target)
|
Aircraft(vec2 position, float direction, float speed, vec2 target)
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ void dxd::sim::AircraftTrail::tick(float timestep, World *world)
|
|||||||
|
|
||||||
void dxd::sim::AircraftTrail::draw(Renderer *rend)
|
void dxd::sim::AircraftTrail::draw(Renderer *rend)
|
||||||
{
|
{
|
||||||
rend->color(128, 128, 128, 255);
|
rend->color(128, 128, 128);
|
||||||
rend->box(_position, .5);
|
rend->box(_position, .5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ void dxd::sim::Airfield::tick(float timestep, World *world)
|
|||||||
|
|
||||||
void dxd::sim::Airfield::draw(Renderer *rend)
|
void dxd::sim::Airfield::draw(Renderer *rend)
|
||||||
{
|
{
|
||||||
rend->color(127, 127, 127, 255);
|
rend->color(127, 127, 127);
|
||||||
rend->rect(_position, 5);
|
rend->rect(_position, 5);
|
||||||
rend->diamond(_position, 5);
|
rend->diamond(_position, 5);
|
||||||
|
|
||||||
rend->color(64, 64, 255, 255);
|
rend->color(64, 64, 255);
|
||||||
vec2 a = _position + polar_to_vec2(_rw_heading, +_WR_LENGTH);
|
vec2 a = _position + polar_to_vec2(_rw_heading, +_WR_LENGTH);
|
||||||
vec2 b = _position + polar_to_vec2(_rw_heading, -_WR_LENGTH);
|
vec2 b = _position + polar_to_vec2(_rw_heading, -_WR_LENGTH);
|
||||||
rend->line(a, b);
|
rend->line(a, b);
|
||||||
|
|||||||
Reference in New Issue
Block a user