Browse Source

Add UTC offset function

master
C. J. Howard 2 years ago
parent
commit
7a8edd9a5a
4 changed files with 52 additions and 2 deletions
  1. +1
    -1
      src/game/state/nuptial-flight.cpp
  2. +2
    -1
      src/game/world.cpp
  3. +1
    -0
      src/physics/time/time.hpp
  4. +48
    -0
      src/physics/time/utc.hpp

+ 1
- 1
src/game/state/nuptial-flight.cpp View File

@ -143,7 +143,7 @@ nuptial_flight::nuptial_flight(game::context& ctx):
}
// Load biome
game::load::biome(ctx, "desert-scrub.bio");
game::load::biome(ctx, "debug.bio");
// Set world time
game::world::set_time(ctx, 2022, 6, 21, 12, 0, 0.0);

+ 2
- 1
src/game/world.cpp View File

@ -41,6 +41,7 @@
#include "physics/orbit/ephemeris.hpp"
#include "physics/time/gregorian.hpp"
#include "physics/time/constants.hpp"
#include "physics/time/utc.hpp"
#include "render/material.hpp"
#include "render/model.hpp"
#include "render/passes/shadow-map-pass.hpp"
@ -116,7 +117,7 @@ void set_time(game::context& ctx, double t)
void set_time(game::context& ctx, int year, int month, int day, int hour, int minute, double second)
{
const double utc_offset = ctx.longitude / (math::two_pi<double> / 24.0);
const double utc_offset = physics::time::utc::offset<double>(ctx.longitude);
const double t = physics::time::gregorian::to_ut1<double>(year, month, day, hour, minute, second, utc_offset);
set_time(ctx, t);
}

+ 1
- 0
src/physics/time/time.hpp View File

@ -31,5 +31,6 @@ namespace time {}
#include "gregorian.hpp"
#include "jd.hpp"
#include "ut1.hpp"
#include "utc.hpp"
#endif // ANTKEEPER_PHYSICS_TIME_HPP

+ 48
- 0
src/physics/time/utc.hpp View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_PHYSICS_TIME_UTC_HPP
#define ANTKEEPER_PHYSICS_TIME_UTC_HPP
#include "math/constants.hpp"
namespace physics {
namespace time {
/// Coordinated Universal Time (UTC).
namespace utc {
/**
* Calculates the UTC offset at a given longitude
*
* @param longitude Longitude, in radians.
* @return UTC offset.
*/
template <class T>
T offset(T longitude)
{
return longitude / (math::two_pi<double> / 24.0);
}
} // namespace utc
} // namespace time
} // namespace physics
#endif // ANTKEEPER_PHYSICS_TIME_UTC_HPP

Loading…
Cancel
Save