Commit 4028a2aa authored by David Gilbert's avatar David Gilbert

Doubles!

parent 94a50daa
......@@ -6,11 +6,11 @@
#undef up
struct Camera : Component<Camera> {
explicit Camera() : fov(75), near(0.1f), far(100), worldUp(glm::vec3(0, 1, 0)) {}
explicit Camera(float fov, float near, float far, glm::vec3 up = glm::vec3(0, 1, 0)) : fov(fov), near(near), far(far), worldUp(up) { }
explicit Camera() : fov(75), near(0.1f), far(100), worldUp(glm::dvec3(0, 1, 0)) {}
explicit Camera(float fov, float near, float far, glm::dvec3 up = glm::dvec3(0, 1, 0)) : fov(fov), near(near), far(far), worldUp(up) { }
float fov;
float near;
float far;
glm::vec3 worldUp;
glm::dvec3 worldUp;
};
......@@ -4,15 +4,15 @@
struct TransformData {
glm::vec3 pos;
glm::dvec3 pos;
glm::quat rot;
glm::vec3 scale;
glm::dvec3 scale;
};
struct DrawCall {
Material material;
Geometry geometry;
glm::mat4 lastRenderTransform;
glm::mat4 thisRenderTransform;
glm::dmat4 lastRenderTransform;
glm::dmat4 thisRenderTransform;
int recursionDepth;
};
\ No newline at end of file
......@@ -150,4 +150,4 @@ public:
};
glm::mat4 interpolate(TransformData a, TransformData b, float t, glm::vec3 camPos);
\ No newline at end of file
glm::mat4 interpolate(TransformData a, TransformData b, double t, glm::dvec3 camPos);
\ No newline at end of file
......@@ -27,7 +27,7 @@ private:
std::vector<Entity> trajectories;
glm::vec3 applyKepler(Planet::Handle planet, float dt);
glm::dvec3 applyKepler(Planet::Handle planet, float dt);
public:
CONSTRUCT_SYSTEM(OrbitalSimulationSystem) {}
......@@ -43,8 +43,8 @@ public:
void simulateOrbitals(float dt, float totalTime);
float solarToWorld(double solar);
float AUToWorld(double au);
double solarToWorld(double solar);
double AUToWorld(double au);
double solarToAU(double s);
double AUToSolar(double au);
......
......@@ -13,8 +13,8 @@ struct Planet : Component<Planet> {
double mass; // in solar masses
double radius; // in solar radius
glm::vec3 heliocentricPosition; // in au
glm::mat4 heliocentricRotation;
glm::dvec3 heliocentricPosition; // in au
glm::dmat4 heliocentricRotation;
// Orbital elements
double eccentricity;
......
......@@ -35,7 +35,7 @@ private:
bool m_keyState[SDL_NUM_SCANCODES];
float speed = 10;
double speed = 5;
void handleKeyboard(KeyboardEvent e);
void handleMouse(MouseEvent e);
......@@ -48,15 +48,15 @@ public:
bool startup() override;
void shutdown() override;
void setPosition(glm::vec3 p) {
void setPosition(glm::dvec3 p) {
cameraTransform->position = p;
}
glm::vec3 getWorldPosition() {
glm::dvec3 getWorldPosition() {
return cameraTransform->lastGlobalTransform.pos;
}
glm::vec3 getPosition() {
glm::dvec3 getPosition() {
return cameraTransform->position;
}
......@@ -67,7 +67,7 @@ public:
else return "Sun";
}
void setRotation(glm::mat4 r) {
void setRotation(glm::dmat4 r) {
cameraTransform->rotation = r;
}
......
......@@ -6,19 +6,19 @@
struct Transform : Component<Transform> {
Transform::Handle parent;
glm::vec3 lastPosition;
glm::mat4 lastRotation;
glm::vec3 lastScale;
glm::dvec3 lastPosition;
glm::dmat4 lastRotation;
glm::dvec3 lastScale;
glm::vec3 position;
glm::mat4 rotation;
glm::vec3 scale;
glm::dvec3 position;
glm::dmat4 rotation;
glm::dvec3 scale;
glm::mat4 lastRenderTransform;
glm::dmat4 lastRenderTransform;
TransformData lastGlobalTransform;
TransformData thisGlobalTransform;
Transform() : position(glm::vec3(0, 0, 0)), lastPosition(glm::vec3(0, 0, 0)), lastScale(glm::vec3(1.0, 1.0, 1.0)), scale(glm::vec3(1.0, 1.0, 1.0)) {};
Transform() : position(glm::dvec3(0, 0, 0)), lastPosition(glm::dvec3(0, 0, 0)), lastScale(glm::dvec3(1.0, 1.0, 1.0)), scale(glm::dvec3(1.0, 1.0, 1.0)) {};
};
......@@ -21,11 +21,11 @@ using namespace ACGL::Utils;
const glm::vec2 SHADOW_MAP_RESOLUTION = {512, 512};
glm::mat4 interpolate(TransformData a, TransformData b, float t, glm::vec3 camPos) {
glm::mat4 interpolate(TransformData a, TransformData b, double t, glm::dvec3 camPos) {
a.pos = a.pos - camPos;
b.pos = b.pos - camPos;
glm::vec3 pos = a.pos + (b.pos - a.pos) * t;
glm::quat rot = glm::slerp(a.rot, b.rot, t);
glm::quat rot = glm::slerp(a.rot, b.rot, static_cast<float>(t));
glm::vec3 s = a.scale + (b.scale - a.scale) * t;
return glm::translate(pos) * glm::mat4_cast(rot) * glm::scale(s);
......@@ -251,8 +251,8 @@ void RendererSystem::frame(double interp, double totalTime) {
currentOffset.y /= gBufferRes.y;
aaProj = glm::perspectiveFov<float>(glm::radians(cam->fov), windowSize.x, windowSize.y, cam->near, cam->far);
auto viewProjectionMatrix = glm::translate(currentOffset) * aaProj * glm::inverse(camTransform);
auto prevViewProjectionMatrix = glm::translate(currentOffset) * aaProj * glm::inverse(trans->lastRenderTransform);
glm::mat4 viewProjectionMatrix = glm::translate(currentOffset) * aaProj * glm::inverse(camTransform);
glm::mat4 prevViewProjectionMatrix = glm::translate(currentOffset) * aaProj * static_cast<glm::mat4>(glm::inverse(trans->lastRenderTransform));
m_lastGBufferRenderSetupTime = 0;
m_lastGBufferRenderSubmitTime = 0;
......@@ -266,6 +266,8 @@ void RendererSystem::frame(double interp, double totalTime) {
//glEnable(GL_RASTERIZER_DISCARD);
PrimitiveQuery *q = new PrimitiveQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
for (size_t i = 0; i < m_submittedDrawCallsOpaque.size(); i++) {
auto counter2Start = SDL_GetPerformanceCounter();
......@@ -278,12 +280,13 @@ void RendererSystem::frame(double interp, double totalTime) {
m_tfShaderProg->use();
m_tfShaderProg->setUniform("uFar", cam->far);
m_tfShaderProg->setUniform("uModelMatrix", drawCall.thisRenderTransform);
m_tfShaderProg->setUniform("uModelMatrix", static_cast<glm::mat4>(drawCall.thisRenderTransform));
m_tfShaderProg->setUniform("uViewProjectionMatrix", viewProjectionMatrix);
m_tfShaderProg->setUniform("cameraPosition", glm::vec3{ camPos.x, camPos.y, camPos.z });
m_tfShaderProg->setUniform("recursionDepth", (float) j+1);
m_tfShaderProg->setUniform("viewport", windowSize);
glm::vec3 rPos = glm::vec3(drawCall.thisRenderTransform * glm::vec4{ 0, 0, 0, 1 });
// First pass will render the geometry vao into the transform feedback buffer which is the first one initially
if (j == 0) {
......@@ -330,11 +333,11 @@ void RendererSystem::frame(double interp, double totalTime) {
drawCall.material.prog->setUniform("uTintColor", drawCall.material.tintColor);
drawCall.material.prog->setUniform("uEmissiveColor", drawCall.material.emissiveColor);
drawCall.material.prog->setUniform("uModelMatrix", drawCall.thisRenderTransform);
drawCall.material.prog->setUniform("uModelMatrix", static_cast<glm::mat4>(drawCall.thisRenderTransform));
drawCall.material.prog->setUniform("uViewProjectionMatrix", viewProjectionMatrix);
drawCall.material.prog->setUniform("cameraPosition", glm::vec3{ camPos.x, camPos.y, camPos.z });
drawCall.material.prog->setUniform("uPrevModelMatrix", drawCall.lastRenderTransform);
drawCall.material.prog->setUniform("uPrevModelMatrix", static_cast<glm::mat4>(drawCall.lastRenderTransform));
drawCall.material.prog->setUniform("uPrevViewProjectionMatrix", prevViewProjectionMatrix);
// Draw directly to screen
......@@ -424,7 +427,7 @@ void RendererSystem::frame(double interp, double totalTime) {
m_deferredCombineProgram->setUniform("cameraPosition",
glm::vec3{camPos.x, camPos.y, camPos.z});
auto invViewProj = glm::inverse(viewProjectionMatrix);
glm::mat4 invViewProj = glm::inverse(viewProjectionMatrix);
m_deferredCombineProgram->setUniform("uViewProjectionInverseMatrix",
invViewProj);
......@@ -461,8 +464,8 @@ void RendererSystem::frame(double interp, double totalTime) {
m_deferredCombineProgram->setUniform(
"uOneOverShadowTexSize", glm::vec2{ 1.0f / size.x, 1.0f / size.y });
}
m_deferredCombineProgram->setUniform("uLightPosition", light.lastSimulateTransform.pos + (light.thisSimulateTransform.pos - light.lastSimulateTransform.pos) * interp - origPos);
glm::vec3 interpolatedLight = light.lastSimulateTransform.pos + (light.thisSimulateTransform.pos - light.lastSimulateTransform.pos) * interp - origPos;
m_deferredCombineProgram->setUniform("uLightPosition", interpolatedLight);
m_deferredCombineProgram->setUniform("uLightColor", light.color);
glDrawArrays(
GL_TRIANGLE_STRIP, 0,
......@@ -487,7 +490,7 @@ void RendererSystem::frame(double interp, double totalTime) {
drawCall.material.prog->setUniform("uEmissiveColor", drawCall.material.emissiveColor);
drawCall.material.prog->setUniform("uOneOverScreenSize", 1.0f/compositingRes);
drawCall.material.prog->setUniform("uModelMatrix", drawCall.thisRenderTransform);
drawCall.material.prog->setUniform("uModelMatrix", static_cast<glm::mat4>(drawCall.thisRenderTransform));
drawCall.material.prog->setUniform("uViewProjectionMatrix", viewProjectionMatrix);
drawCall.material.prog->setUniform("uViewProjectionInverseMatrix", invViewProj);
......@@ -496,7 +499,7 @@ void RendererSystem::frame(double interp, double totalTime) {
drawCall.material.prog->setUniform("uObjectPosition", pos );
drawCall.material.prog->setUniform("uCameraPosition", camPos);
drawCall.material.prog->setUniform("uSunDir", m_submittedLights[0].dir);
drawCall.material.prog->setUniform("uPrevModelMatrix", drawCall.lastRenderTransform);
drawCall.material.prog->setUniform("uPrevModelMatrix", static_cast<glm::mat4>(drawCall.lastRenderTransform));
drawCall.material.prog->setUniform("uPrevViewProjectionMatrix", prevViewProjectionMatrix);
drawCall.geometry.vao->render();
......
......@@ -65,7 +65,7 @@ bool OrbitalSimulationSystem::startup() {
return true;
}
glm::vec3 OrbitalSimulationSystem::applyKepler(Planet::Handle planet, float dt) {
glm::dvec3 OrbitalSimulationSystem::applyKepler(Planet::Handle planet, float dt) {
// compute the mean anomaly
......@@ -101,7 +101,7 @@ glm::vec3 OrbitalSimulationSystem::applyKepler(Planet::Handle planet, float dt)
// Radial distance to sun
double r = sqrt(xv*xv + yv*yv);
glm::vec3 position;
glm::dvec3 position;
position.x = r*(cos(planet->ascendingNode)*cos(planet->longitudePerihelion + trueAnomaly) -
sin(planet->ascendingNode)*sin(planet->longitudePerihelion + trueAnomaly)*cos(planet->inclination));
......@@ -121,17 +121,17 @@ void OrbitalSimulationSystem::simulateOrbitals(float dt, float totalTime) {
Planet::Handle planet;
Transform::Handle transform;
glm::vec3 position;
glm::dvec3 position;
for (auto p : planets) {
p.unpack<Planet, Transform>(planet, transform);
// dt here is interpreted as a DAY NUMBER. TODO: Conversion/scale
position = applyKepler(planet, dt*0.1 );
position = glm::vec3(AUToWorld(position.x), AUToWorld(position.y), AUToWorld(position.z));
position = glm::dvec3(AUToWorld(position.x), AUToWorld(position.y), AUToWorld(position.z));
// TODO: Natural conversion from au to world coords
transform->position = glm::vec3(position.x, position.y, position.z);
transform->position = glm::dvec3(position.x, position.y, position.z);
}
}
......@@ -149,10 +149,10 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
auto planetComponent = planetEntity.assign<Planet>(n, m, r, e, a, i, N, P, T);
// Move the planet to the right position:
glm::vec3 pos = applyKepler(planetComponent, 0);
pos = glm::vec3(AUToWorld(pos.x), AUToWorld(pos.y), AUToWorld(pos.z));
glm::dvec3 pos = applyKepler(planetComponent, 0);
pos = glm::dvec3(AUToWorld(pos.x), AUToWorld(pos.y), AUToWorld(pos.z));
planetTransform->scale = glm::vec3(solarToWorld(r), solarToWorld(r), solarToWorld(r));
planetTransform->scale = glm::dvec3(solarToWorld(r), solarToWorld(r), solarToWorld(r));
planetTransform->position = pos;
planetEntity.assign<Drawable>(defaultGeom, planetMat, 2);
......@@ -162,7 +162,7 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
auto atmosphereTransform = atmosphere.assign<Transform>();
atmosphereTransform->parent = planetTransform;
atmosphere.assign<Drawable>(defaultGeom, atmosphereMat);
atmosphereTransform->scale = planetTransform->scale * 1.05f;
atmosphereTransform->scale = planetTransform->scale * 1.05;
// Let's add a moon!
......@@ -175,20 +175,20 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
// change starting point
//float t = static_cast <float> (rand()) / static_cast <float> (RAND_MAX / 10.0f);
pos = applyKepler(moonComponent, 0);
pos = glm::vec3(AUToWorld(pos.x), AUToWorld(pos.y), AUToWorld(pos.z));
pos = glm::dvec3(AUToWorld(pos.x), AUToWorld(pos.y), AUToWorld(pos.z));
moonTransform->position = pos;
moonTransform->scale = glm::vec3(solarToWorld(r*0.5f), solarToWorld(r*0.5f), solarToWorld(r*0.5f));
moonTransform->scale = glm::dvec3(solarToWorld(r*0.5f), solarToWorld(r*0.5f), solarToWorld(r*0.5f));
// Add the transformation matrixes to calculate the trajectory from a standard circle:
float b = a*sqrt(1 - e*e);
float distLength = AUToWorld(sqrt(a*a - b*b));
double b = a*sqrt(1 - e*e);
double distLength = AUToWorld(sqrt(a*a - b*b));
glm::vec3 dist = planetTransform->position * (distLength / glm::length(planetTransform->position));
glm::vec3 tScale = glm::vec3(AUToWorld(b), 1, AUToWorld(a));
glm::dvec3 dist = planetTransform->position * (distLength / glm::length(planetTransform->position));
glm::dvec3 tScale = glm::dvec3(AUToWorld(b), 1, AUToWorld(a));
glm::mat4 tRot = glm::rotate<float>(P, glm::vec3( 0, -1, 0));
tRot = tRot * glm::rotate<float>(i, glm::vec3(-1, 0, 0));
glm::dmat4 tRot = glm::rotate<double>(P, glm::dvec3( 0, -1, 0));
tRot = tRot * glm::rotate<double>(i, glm::dvec3(-1, 0, 0));
auto traj = m_scene->create();
auto trajTransform = traj.assign<Transform>();
......@@ -211,12 +211,12 @@ void OrbitalSimulationSystem::showTrajectories() {
// Right now planets are 10 times closer to each other than in reality and 10 times bigger
float OrbitalSimulationSystem::AUToWorld(double au) {
double OrbitalSimulationSystem::AUToWorld(double au) {
return distanceScale * solarToWorld(AUToSolar(au));
}
float OrbitalSimulationSystem::solarToWorld(double solar) {
return static_cast <float> (solar) * solarRadius * scaleFactor;
double OrbitalSimulationSystem::solarToWorld(double solar) {
return (solar) * solarRadius * scaleFactor;
}
double OrbitalSimulationSystem::solarToAU(double s) {
......
......@@ -2,7 +2,7 @@
#include <engine/scene/OrbitalSimulationSystem.hpp>
glm::vec3 rotate(glm::vec3 vec, glm::mat4 mat);
glm::dvec3 rotate(glm::dvec3 vec, glm::dmat4 mat);
glm::vec3 mod289(glm::vec3 x)
{
......@@ -191,8 +191,8 @@ bool PlayerSystem::startup() {
// Create an entity that is used to position the camera in the scene
player = m_scene->create();
cameraTransform = player.assign<Transform>();
camera = player.assign<Camera>(75, 1.0f, 200000000);
cameraTransform->position = glm::vec3(0, 0, 1000);
camera = player.assign<Camera>(75, 0.1f, 200000000);
cameraTransform->position = glm::dvec3(0, 0, 1000);
m_renderer->setMainCamera(player);
m_audio->setListener(player);
......@@ -251,17 +251,17 @@ void PlayerSystem::handleMouse(MouseEvent e) {
}
glm::vec4 v = glm::vec4(0, 0, winSize.x, winSize.y);
glm::vec3 winCoords = glm::vec3(x, fixedY, depth);
glm::dvec3 winCoords = glm::dvec3(x, fixedY, depth);
Camera::Handle cam = player.component<Camera>();
//glm::mat4 view = glm::lookAt(cameraTransform->position, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
glm::mat4 model = glm::translate(cameraTransform->thisGlobalTransform.pos) * glm::mat4_cast(cameraTransform->lastGlobalTransform.rot) * glm::scale(cameraTransform->scale);
glm::dmat4 model = glm::translate(cameraTransform->thisGlobalTransform.pos) * static_cast<glm::dmat4>(glm::mat4_cast(cameraTransform->lastGlobalTransform.rot)) * glm::scale(cameraTransform->scale);
glm::mat4 proj = m_renderer->getProjectionMatrix();
glm::dmat4 proj = m_renderer->getProjectionMatrix();
glm::vec3 worldCoords = glm::unProject(winCoords, glm::inverse(model) , proj, v);
glm::dvec3 worldCoords = glm::unProject(winCoords, glm::inverse(model) , proj, v);
std::cout << worldCoords.x << " " << worldCoords.y << " " << worldCoords.z << "\n";
......@@ -270,10 +270,10 @@ void PlayerSystem::handleMouse(MouseEvent e) {
continue;
}
Transform::Handle p = e.component<Transform>();
glm::vec3 pos = p->position;
glm::dvec3 pos = p->position;
if (length(p->position - worldCoords) <= p->scale.x + 100){
attachToParent(e);
setPosition(glm::vec3(e.component<Transform>()->scale.x + 100, 0, 0));
setPosition(glm::dvec3(e.component<Transform>()->scale.x + 100, 0, 0));
}
}
}
......@@ -282,11 +282,11 @@ void PlayerSystem::handleMouse(MouseEvent e) {
// If the mouse is captured
if (SDL_GetRelativeMouseMode()) {
// Rotate the camera based on the mouse movement
auto mouseMove = glm::vec2(-(float)e.originalEvent.motion.xrel, -(float)e.originalEvent.motion.yrel);
auto mouseMove = glm::dvec2(-(float)e.originalEvent.motion.xrel, -(float)e.originalEvent.motion.yrel);
auto up = rotate(camera->worldUp, glm::inverse(cameraTransform->rotation));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, mouseMove.x * 0.001f, up);
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, mouseMove.y * 0.001f, glm::vec3(1, 0, 0));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, mouseMove.x * 0.001, up);
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, mouseMove.y * 0.001, glm::dvec3(1, 0, 0));
}
break;
}
......@@ -296,47 +296,48 @@ void PlayerSystem::handleMouse(MouseEvent e) {
}
void PlayerSystem::update(float dt) {
glm::vec3 moveDir(0);
glm::vec2 rotDir(0);
glm::dvec3 moveDir(0);
glm::dvec2 rotDir(0);
float speedMod = 1.0f;
double speedMod = 1.0;
// Move the camera based on WASD keyboard input
if (!ImGui::GetIO().WantCaptureKeyboard) {
if (m_keyState[SDL_SCANCODE_W]) moveDir -= glm::vec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_S]) moveDir += glm::vec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_A]) moveDir -= glm::vec3(1, 0, 0);
if (m_keyState[SDL_SCANCODE_D]) moveDir += glm::vec3(1, 0, 0);
if (m_keyState[SDL_SCANCODE_W]) moveDir -= glm::dvec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_S]) moveDir += glm::dvec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_A]) moveDir -= glm::dvec3(1, 0, 0);
if (m_keyState[SDL_SCANCODE_D]) moveDir += glm::dvec3(1, 0, 0);
if (m_keyState[SDL_SCANCODE_SPACE]) { moveDir += glm::vec3(0, 1, 0); }
if (m_keyState[SDL_SCANCODE_SPACE]) { moveDir += glm::dvec3(0, 1, 0); }
if (m_keyState[SDL_SCANCODE_LSHIFT]) speedMod = 100;
if (m_keyState[SDL_SCANCODE_LEFT]) rotDir += glm::vec2(1, 0);
if (m_keyState[SDL_SCANCODE_RIGHT]) rotDir -= glm::vec2(1, 0);
if (m_keyState[SDL_SCANCODE_UP]) rotDir += glm::vec2(0, 1);
if (m_keyState[SDL_SCANCODE_DOWN]) rotDir -= glm::vec2(0, 1);
if (m_keyState[SDL_SCANCODE_LEFT]) rotDir += glm::dvec2(1, 0);
if (m_keyState[SDL_SCANCODE_RIGHT]) rotDir -= glm::dvec2(1, 0);
if (m_keyState[SDL_SCANCODE_UP]) rotDir += glm::dvec2(0, 1);
if (m_keyState[SDL_SCANCODE_DOWN]) rotDir -= glm::dvec2(0, 1);
// Rotate the camera based on the mouse movement
auto up = rotate(camera->worldUp, glm::inverse(cameraTransform->rotation));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.x * 0.05f, glm::vec3(0, 1, 0));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.y * 0.05f, glm::vec3(1, 0, 0));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.x * 0.05, glm::dvec3(0, 1, 0));
cameraTransform->rotation = glm::rotate(cameraTransform->rotation, rotDir.y * 0.05, glm::dvec3(1, 0, 0));
if (moveDir.x != 0 || moveDir.y || moveDir.z != 0 ) {
moveDir = rotate(glm::normalize(moveDir), cameraTransform->rotation);
cameraTransform->position += moveDir * dt * speed * speedMod;
cameraTransform->position += moveDir * static_cast<double>(dt) * speed * speedMod;
printf("PlayerSystem %f \n", cameraTransform->position.z);
}
}
// Check if we have to move the player to a different coordinate system.
float r;
double r;
// Hack to check if the parent is not sun or we don't have a parent (FIXME)
if (cameraTransform->parent.valid() && cameraTransform->parent->parent.valid()) {
// we're following a planet!
r = m_orbitals->solarToWorld(parentEntity.component<Planet>()->radius);
float dist = glm::length(cameraTransform->position);
double dist = glm::length(cameraTransform->position);
// If we drift away from the planet, stop following its orbit:
if (dist > r * 2.5 ) {
......@@ -354,7 +355,7 @@ void PlayerSystem::update(float dt) {
// Calculate the normalized direction from camera to model. This is the camera projected onto the surface of the sphere.
// Ideally, we want to alter our up vector such that after some time it resembles the sphere normals at the projected camera point.
glm::vec3 p = glm::normalize(cameraTransform->position);
glm::dvec3 p = glm::normalize(cameraTransform->position);
camera->worldUp = p;
......@@ -365,7 +366,7 @@ void PlayerSystem::update(float dt) {
float noise = fBM(p, 8, 80, 0.003);
p = p * r;
p += noise * r;
if (dist <= glm::length(p) + 1) {
if (dist <= glm::length(p) + 0.1) {
// We're inside a planet. Due to that not being good for our health, let's get out quick:
cameraTransform->position = cameraTransform->lastPosition;
}
......@@ -398,9 +399,9 @@ void PlayerSystem::update(float dt) {
void PlayerSystem::shutdown() {}
glm::vec3 rotate(glm::vec3 vec, glm::mat4 mat) {
auto temp = mat * glm::vec4(vec.x, vec.y, vec.z, 0);
return glm::vec3(temp.x, temp.y, temp.z);
glm::dvec3 rotate(glm::dvec3 vec, glm::dmat4 mat) {
auto temp = mat * glm::dvec4(vec.x, vec.y, vec.z, 0);
return glm::dvec3(temp.x, temp.y, temp.z);
}
......@@ -43,13 +43,15 @@ void SceneGraphSystem::prepareDraw(double interp) {
Transform::Handle parent = transform->parent;
TransformData lastGlobalTransform = { transform->lastPosition, glm::quat_cast(transform->lastRotation), transform->lastScale };
TransformData thisGlobalTransform = { transform->position, glm::quat_cast(transform->rotation), transform->scale };
while (parent.valid()) {
while (parent.valid()) {
TransformData lastParentTransform = { parent->lastPosition, glm::quat_cast(parent->lastRotation), parent->lastScale };
TransformData thisParentTransform = { parent->position, glm::quat_cast(parent->rotation), parent->scale };
// For now, only look at the positions of our parent, scale and rotation needs some additional logic TODO
// For now, only look at the positions of our parent, scale and rotation needs some additional logic TODO
/*
/*
lastGlobalTransform.scale *= lastParentTransform.scale;
thisGlobalTransform.scale *= thisParentTransform.scale;
......@@ -59,10 +61,9 @@ void SceneGraphSystem::prepareDraw(double interp) {
lastGlobalTransform.pos = lastParentTransform.pos + (lastGlobalTransform.pos * lastParentTransform.scale) * glm::inverse(lastParentTransform.rot);
thisGlobalTransform.pos = thisParentTransform.pos + (thisGlobalTransform.pos * thisParentTransform.scale) * glm::inverse(thisParentTransform.rot);
*/
lastGlobalTransform.pos = lastParentTransform.pos + lastGlobalTransform.pos;
thisGlobalTransform.pos = thisParentTransform.pos + thisGlobalTransform.pos;
*/
lastGlobalTransform.pos = lastParentTransform.pos + lastGlobalTransform.pos;
thisGlobalTransform.pos = thisParentTransform.pos + thisGlobalTransform.pos;
parent = parent->parent;
}
......@@ -75,11 +76,10 @@ void SceneGraphSystem::prepareDraw(double interp) {
// Only works if we have just ONE camera
auto cameras = m_entityManager.entities_with_components<Camera>();
glm::vec3 cam;
glm::dvec3 cam;
for (auto e : cameras) {
cam = e.component<Transform>()->thisGlobalTransform.pos;
}
Drawable::Handle drawable;
for (auto e : drawableEntities) {
......@@ -98,7 +98,7 @@ void SceneGraphSystem::prepareDraw(double interp) {
e.unpack<Light, Transform>(light, transform);
auto viewMatrix = glm::lookAt<float>(-light->dir, { 0,0,0 }, glm::vec3(0.0f, 1.0f, 0.0f));
auto lightVP = glm::ortho<float>(-1500.0f, +1500.0f, 1500.0f, -1500.0f, 0.0f, -1000.0f) * viewMatrix;
auto lightVP = glm::ortho<double>(-1500.0, +1500.0, 1500.0, -1500.0, 0.0, -1000.0) * static_cast<glm::dmat4>(viewMatrix);
m_renderer->submit({light->color, light->castShadow,light->dir, light->type, transform->lastGlobalTransform, transform->thisGlobalTransform, lightVP, nullptr, nullptr});
}
......
......@@ -61,7 +61,7 @@ bool AtmosphereTestScene::startup() {
// Add a Drawable component to it so the renderer has something to draw
sun.assign<Drawable>(geom1, sunMaterial);
float scale = m_orbitals->solarRadius * m_orbitals->scaleFactor * 0.1;
sunTransform->scale = glm::vec3(scale);
sunTransform->scale = glm::dvec3(scale);