2#include <glm/gtx/quaternion.hpp>
3#include "CurvedEarthPositionComponent.h"
4#include "Components/Core/TransformComponent.h"
10void Cogs::Core::CurvedEarthPositionComponent::registerType()
13 Field(
Name(
"position"), &CurvedEarthPositionComponent::position)
16 Method(
Name(
"update"), &CurvedEarthPositionComponent::update)
19 DynamicComponent::registerDerivedType<CurvedEarthPositionComponent>().setMethods(methods).setFields(fields);
23void Cogs::Core::CurvedEarthPositionComponent::update()
25 const float R = 6371000.f;
27 if (!hasChanged())
return;
29 auto * trComp = getComponent<TransformComponent>();
31 float d = glm::length(glm::vec2(position));
33 trComp->position = glm::vec3(position.x,
35 position.z - (R - glm::sqrt((R - d)*(R + d))));
36 const glm::vec3 a = glm::vec3(0, 0, 1);
37 const glm::vec3 b = glm::normalize(trComp->position - glm::vec3(0, 0, -R));
38 const glm::vec3 n = glm::cross(a, b);
39 const float n_l = glm::length(n);
40 if (std::numeric_limits<float>::epsilon() < glm::abs(n_l)) {
41 trComp->rotation = glm::angleAxis(glm::acos(glm::dot(a, b)), (1.f / n_l)*n);
44 trComp->rotation = glm::quat();
Field definition describing a single data member of a data structure.
Simple method definition.
Contains reflection support.
Represents an unique name.