change coordinate system to Z-up

This commit is contained in:
Bailey Harrison 2023-09-19 13:53:19 +01:00
parent 591d0ea3c2
commit 35f4340380
9 changed files with 33 additions and 19 deletions

@ -1 +1 @@
Subproject commit 0e89587db3ebee4d463f191bd296374c5fafc8ea
Subproject commit c351692490513cdb0e5a2c925aaf7ea4a9b672f4

View File

@ -28,7 +28,7 @@ void main() {
fragNorm = mat3(transpose(inverse(frameSetUniformBuffer.view * constants.model))) * inNorm;
fragUV = inUV;
vec3 lightPos = vec3(2000.0, 2000.0, -2000.0);
vec3 lightPos = vec3(2000.0, -2000.0, 2000.0);
fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0));
gl_Position.y *= -1.0;

View File

@ -66,6 +66,13 @@ namespace engine::util {
// get rotation
glm::quat rotation = glm::quat_cast(transform);
// ASSIMP always makes the root node Y-up
// We want Z-up
if (parentNode->mParent == nullptr) {
// if this is the root node
rotation *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{1.0f, 0.0f, 0.0f});
}
// update position, scale, rotation
auto parentTransform = scene->GetComponent<TransformComponent>(parentObj);
parentTransform->position = position;
@ -101,6 +108,7 @@ namespace engine::util {
Entity LoadMeshFromFile(Scene* parent, const std::string& path, bool is_static)
{
Assimp::Importer importer;
class myStream : public Assimp::LogStream {

BIN
test/res/models/MY_AXES.dae (Stored with Git LFS)

Binary file not shown.

BIN
test/res/models/far_away_cube.dae (Stored with Git LFS) Normal file

Binary file not shown.

BIN
test/res/models/uvcheck.dae (Stored with Git LFS)

Binary file not shown.

View File

@ -36,12 +36,12 @@ void CameraControllerSystem::OnUpdate(float ts) {
if (scene_->app()->input_manager()->GetButton("sprint")) speed *= 10.0f;
float dx = scene_->app()->input_manager()->GetAxis("movex");
float dz = (-scene_->app()->input_manager()->GetAxis("movey"));
float dy = (-scene_->app()->input_manager()->GetAxis("movey"));
// calculate new pitch and yaw
constexpr float kMaxPitch = glm::half_pi<float>();
constexpr float kMinPitch = -kMaxPitch;
constexpr float kMaxPitch = glm::pi<float>();
constexpr float kMinPitch = 0.0f;
float d_pitch = scene_->app()->input_manager()->GetAxis("looky") * -1.0f *
c->kCameraSensitivity;
@ -53,10 +53,10 @@ void CameraControllerSystem::OnUpdate(float ts) {
c->kCameraSensitivity;
// update position relative to camera direction in xz plane
const glm::vec3 d2x_rotated = glm::rotateY(glm::vec3{dx, 0.0f, 0.0f}, c->yaw);
const glm::vec3 d2z_rotated =
glm::rotateY(glm::rotateX(glm::vec3{0.0f, 0.0f, dz}, c->pitch), c->yaw);
glm::vec3 h_vel = (d2x_rotated + d2z_rotated);
const glm::vec3 d2x_rotated = glm::rotateZ(glm::vec3{dx, 0.0f, 0.0f}, c->yaw);
const glm::vec3 d2y_rotated =
glm::rotateZ(glm::rotateX(glm::vec3{0.0f, 0.0f, dy}, c->pitch), c->yaw);
glm::vec3 h_vel = (d2x_rotated + d2y_rotated);
h_vel *= speed;
t->position += h_vel * dt;
@ -80,8 +80,8 @@ void CameraControllerSystem::OnUpdate(float ts) {
const float half_yaw = c->yaw / 2.0f;
glm::quat yaw_quat{};
yaw_quat.x = 0.0f;
yaw_quat.y = glm::sin(half_yaw);
yaw_quat.z = 0.0f;
yaw_quat.y = 0.0f;
yaw_quat.z = glm::sin(half_yaw);
yaw_quat.w = glm::cos(half_yaw);
// update rotation

View File

@ -10,7 +10,7 @@ struct CameraControllerComponent {
static constexpr float kWalkSpeed = 4.0f;
static constexpr float kCameraSensitivity = 0.007f;
float yaw = 0.0f;
float pitch = 0.0f;
float pitch = glm::half_pi<float>();
};
class CameraControllerSystem

View File

@ -57,7 +57,7 @@ void PlayGame(GameSettings settings) {
ConfigureInputs(app.input_manager());
{
auto my_scene = app.scene_manager()->CreateEmptyScene();
static auto my_scene = app.scene_manager()->CreateEmptyScene();
/* create camera */
{
@ -68,7 +68,7 @@ void PlayGame(GameSettings settings) {
auto camera_transform =
my_scene->GetComponent<engine::TransformComponent>(camera);
camera_transform->position = {0.0f, 10.0f, 0.0f};
camera_transform->position = {0.0f, 0.0f, 10.0f};
my_scene->RegisterComponent<CameraControllerComponent>();
my_scene->RegisterSystem<CameraControllerSystem>();
@ -119,7 +119,7 @@ void PlayGame(GameSettings settings) {
my_scene, app.GetResourcePath("models/cobble_house/cobble_house.dae"),
false);
my_scene->GetComponent<engine::TransformComponent>(cobbleHouse)
->position += glm::vec3{33.0f, 0.1f, 35.0f};
->position += glm::vec3{33.0f, 35.0f, 0.1f};
auto cobbleCustom =
my_scene->AddComponent<engine::CustomComponent>(cobbleHouse);
cobbleCustom->onInit = [](void) {
@ -132,6 +132,8 @@ void PlayGame(GameSettings settings) {
};
}
static auto cube = engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/far_away_cube.dae"), true);
/* some text */
{
engine::Entity textbox =
@ -153,6 +155,7 @@ void PlayGame(GameSettings settings) {
engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/MY_AXES.dae"), true);
my_scene->GetComponent<engine::TransformComponent>(engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/uvcheck.dae"), true))->position += glm::vec3{20.0f, 20.0f, 20.0f};
/* teapot */
my_scene
->GetComponent<engine::TransformComponent>(