Skip to content

Commit

Permalink
Merge pull request #6 from GuusKemperman/transform-change
Browse files Browse the repository at this point in the history
Updated coordinate system
  • Loading branch information
GuusKemperman committed Aug 11, 2024
2 parents 6eea214 + d1755f1 commit 349f146
Show file tree
Hide file tree
Showing 81 changed files with 244 additions and 469 deletions.
Binary file removed Assets/Models/Cone/Cone_Cone.asset
Binary file not shown.
Binary file removed Assets/Models/Cone/Cone_Prefab.asset
Binary file not shown.
Binary file removed Assets/Models/Cone/M_Cone_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Cube/Cube_Cube_001.asset
Binary file not shown.
Binary file removed Assets/Models/Cube/Cube_Prefab.asset
Binary file not shown.
Binary file removed Assets/Models/Cube/M_Cube_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Cylinder/Cylinder_Cylinder.asset
Binary file not shown.
Binary file removed Assets/Models/Cylinder/Cylinder_Prefab.asset
Binary file not shown.
Binary file removed Assets/Models/Cylinder/M_Cylinder_glb_0.asset
Binary file not shown.
3 changes: 0 additions & 3 deletions Assets/Models/Cylinder_Standing.glb

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions Assets/Models/DamagedHelmet.glb

This file was deleted.

Binary file removed Assets/Models/DamagedHelmet/DamagedHelmet_Prefab.asset
Binary file not shown.
Binary file not shown.
Binary file removed Assets/Models/DamagedHelmet/DamagedHelmet_tex0.asset
Binary file not shown.
Binary file removed Assets/Models/DamagedHelmet/DamagedHelmet_tex1.asset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Assets/Models/DamagedHelmet/Material_MR.asset
Binary file not shown.
Binary file removed Assets/Models/IcoSphere/IcoSphere_Icosphere.asset
Binary file not shown.
Binary file removed Assets/Models/IcoSphere/IcoSphere_Prefab.asset
Binary file not shown.
Binary file removed Assets/Models/IcoSphere/M_IcoSphere_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Monkey/M_Monkey_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Monkey/Monkey_Prefab.asset
Binary file not shown.
Binary file added Assets/Models/PF_Cone.asset
Binary file not shown.
Binary file added Assets/Models/PF_Cube.asset
Binary file not shown.
Binary file added Assets/Models/PF_Cylinder.asset
Binary file not shown.
Binary file added Assets/Models/PF_IcoSphere.asset
Binary file not shown.
Binary file added Assets/Models/PF_Monkey.asset
Binary file not shown.
Binary file added Assets/Models/PF_Plane.asset
Binary file not shown.
Binary file added Assets/Models/PF_Sphere.asset
Binary file not shown.
Binary file added Assets/Models/PF_Torus.asset
Binary file not shown.
Binary file removed Assets/Models/Plane/M_Plane_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Plane/Plane_Plane.asset
Binary file not shown.
Binary file removed Assets/Models/Plane/Plane_Prefab.asset
Binary file not shown.
Binary file added Assets/Models/SM_Cone.asset
Binary file not shown.
Binary file added Assets/Models/SM_Cube.asset
Binary file not shown.
Binary file added Assets/Models/SM_Cylinder.asset
Binary file not shown.
Binary file added Assets/Models/SM_Icosphere.asset
Binary file not shown.
Binary file added Assets/Models/SM_Plane.asset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Assets/Models/Sphere/M_Sphere_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Sphere/Sphere_Prefab.asset
Binary file not shown.
Binary file removed Assets/Models/Torus/M_Torus_glb_0.asset
Binary file not shown.
Binary file removed Assets/Models/Torus/Torus_Prefab.asset
Binary file not shown.
16 changes: 0 additions & 16 deletions Include/Components/CameraComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@

namespace CE
{
class BinaryGSONObject;
class World;
class TransformComponent;

class CameraComponent
{
public:
const glm::mat4& GetViewProjection() const { return mViewProjection; }
const glm::mat4& GetView() const { return mView; }
const glm::mat4& GetProjection() const { return mProjection; }
const glm::mat4& GetOrthographicProjection() const { return mOrthographicProjection; }

void UpdateView(glm::vec3 position, glm::vec3 forward, glm::vec3 up, bool recalulateViewProjection = true);
void UpdateView(const TransformComponent& transform, bool recalulateViewProjection = true);
void UpdateProjection(glm::vec2 viewportSize, bool recalculateViewProjection = true);
void UpdateProjection(float aspectRatio, bool recalculateViewProjection = true);

// By default, the view/proj are recalculated at the end of every frame.
void RecalculateViewProjection();

/**
* \brief Returns the selected camera. If none is selected, will lazily select one.
* \return entt::null if no camera in the world, otherwise the owner of the camera. The owner is guaranteed to have a camera attached to it.
Expand All @@ -39,7 +24,6 @@ namespace CE

glm::mat4 mView{};
glm::mat4 mProjection{};
glm::mat4 mOrthographicProjection{};
glm::mat4 mViewProjection{};

private:
Expand Down
2 changes: 1 addition & 1 deletion Include/Components/FlyCamControllerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CE
class FlyCamControllerComponent
{
public:
void ApplyTranslation(TransformComponent& transform, const glm::vec3& timeScaledMovementInput) const;
void ApplyTranslation(TransformComponent& transform, glm::vec3 timeScaledMovementInput) const;
void ApplyRotation(TransformComponent& transform, const std::array<glm::quat, 2>& timeScaledRotations) const;

float mMovementSpeed = 18.0f;
Expand Down
6 changes: 0 additions & 6 deletions Include/Components/StaticMeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ namespace CE

AssetHandle<Material> mMaterial{};

bool mTilesWithMeshScale = false;

float mTiling = 1;

bool mHighlightedMesh = false;

private:
friend ReflectAccess;
static MetaType Reflect();
Expand Down
85 changes: 24 additions & 61 deletions Include/Components/TransformComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ namespace CE
X,
Y,
Z,
Right = X,
Up = Y,
Forward = Z,
Forward = X,
Right = Y,
Up = Z,
};
};

constexpr glm::vec3 ToVector3(Axis::Values axis) { glm::vec3 v{}; v[static_cast<int>(axis)] = 1.0f; return v; }

constexpr glm::vec2 To2DRightForward(glm::vec3 v3)
constexpr glm::vec2 To2D(glm::vec3 v3)
{
return { v3[Axis::Right], v3[Axis::Forward] };
}

constexpr glm::vec3 To3DRightForward(glm::vec2 v2, float up = 0.0f)
constexpr glm::vec3 To3D(glm::vec2 v2, float up = 0.0f)
{
glm::vec3 v3{};
v3[Axis::Right] = v2.x;
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace CE
glm::mat4 GetLocalMatrix() const;
void SetLocalMatrix(const glm::mat4& matrix);

const glm::mat4& GetWorldMatrix() const;
glm::mat4 GetWorldMatrix() const;
void SetWorldMatrix(const glm::mat4& matrix);

std::tuple<glm::vec3, glm::vec3, glm::quat> GetLocalPositionScaleOrientation() const;
Expand Down Expand Up @@ -103,101 +103,66 @@ namespace CE
// -----------------------------------------------------------------------------------------------------------------//

glm::vec3 GetLocalPosition() const;
glm::vec2 GetLocalPosition2D() const;

glm::vec3 GetWorldPosition() const;
glm::vec2 GetWorldPosition2D() const;

void SetLocalPosition(const glm::vec3 position);
void SetLocalPosition(const glm::vec2 position);

void TranslateLocalPosition(const glm::vec3 translation);
void TranslateLocalPosition(const glm::vec2 translation);
void SetLocalPosition(glm::vec3 position);
void SetLocalPosition(glm::vec2 position);

void SetWorldPosition(glm::vec3 position);
void SetWorldPosition(const glm::vec2 position);

void TranslateWorldPosition(const glm::vec3 translation);
void TranslateWorldPosition(const glm::vec2 translation);
void SetWorldPosition(glm::vec2 position);

// -----------------------------------------------------------------------------------------------------------------//
// Getting/setting the orientation //
// -----------------------------------------------------------------------------------------------------------------//

glm::quat GetLocalOrientation() const;
glm::vec3 GetLocalOrientationEuler() const;

glm::quat GetWorldOrientation() const;
glm::vec3 GetWorldOrientationEuler() const;

// In radians
void SetLocalOrientation(const glm::vec3 rotationEuler);
void SetLocalOrientation(const glm::quat rotation);

// In radians
void SetWorldOrientation(const glm::vec3 rotationEuler);
void SetLocalOrientation(glm::quat rotation);
void SetWorldOrientation(glm::quat orientation);

glm::vec3 GetLocalForward() const;
glm::vec3 GetLocalUp() const;
glm::vec3 GetLocalRight() const;

glm::vec3 GetLocalAxis(const Axis::Values axis) const;
glm::vec3 GetLocalAxis(Axis::Values axis) const;

glm::vec3 GetWorldForward() const;
glm::vec3 GetWorldUp() const;
glm::vec3 GetWorldRight() const;
glm::vec3 GetWorldAxis(const Axis::Values axis) const;

void SetLocalForward(const glm::vec3& forward);
void SetLocalUp(const glm::vec3& up);
void SetLocalRight(const glm::vec3& right);
glm::vec3 GetWorldAxis(Axis::Values axis) const;

void SetLocalForward(glm::vec3 forward);
void SetLocalUp(glm::vec3 up);
void SetLocalRight(glm::vec3 right);

void SetWorldForward(const glm::vec3& forward);
void SetWorldUp(const glm::vec3& up);
void SetWorldRight(const glm::vec3& right);
void SetWorldForward(glm::vec3 forward);
void SetWorldUp(glm::vec3 up);
void SetWorldRight(glm::vec3 right);

// -----------------------------------------------------------------------------------------------------------------//
// Getting/setting the Scale //
// -----------------------------------------------------------------------------------------------------------------//

glm::vec3 GetLocalScale() const;
glm::vec2 GetLocalScale2D() const;
float GetLocalScaleUniform() const;

glm::vec3 GetWorldScale() const;
glm::vec2 GetWorldScale2D() const;
float GetWorldScaleUniform() const;
float GetWorldScaleUniform2D() const;

void SetLocalScale(const float xyz);
void SetLocalScaleRightForward(const float scale);
void SetLocalScale(const glm::vec3 scale);
void SetLocalScale(const glm::vec2 scale);
void SetLocalScale(float xyz);
void SetLocalScale(glm::vec2 scale);
void SetLocalScale(glm::vec3 scale);

void SetWorldScale(const float xyz);
void SetWorldScale(float xyz);
void SetWorldScale(glm::vec2 scale);
void SetWorldScale(glm::vec3 scale);
void SetWorldScale(const glm::vec2 scale);

private:
void AttachChild(TransformComponent& child);
void DetachChild(TransformComponent& child);

void UpdateCachedWorldMatrix();

// We do not serialize the world
// matrix, so we require
// the archiver to call UpdateCachedWorldMatrix..
friend Archiver;


// We don't have custom setter/getter support yet.
// WorldDetails may inspect mLocalPosition and
// adjust its value without ever updating the world
// matrix.
friend WorldDetails;
friend Registry;

friend ReflectAccess;
static MetaType Reflect();
REFLECT_AT_START_UP(TransformComponent);
Expand All @@ -208,8 +173,6 @@ namespace CE
glm::quat mLocalOrientation = { 1.0f, 0.0f, 0.0f, 0.0f };
glm::vec3 mLocalScale = { 1.0f, 1.0f, 1.0f };

glm::mat4 mCachedWorldMatrix{ 1.0f };

// Storing a pointer is safe, as pointer stability has been enabled.
TransformComponent* mParent{};

Expand Down
2 changes: 2 additions & 0 deletions Include/Engine/Precomp/Precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#pragma warning(disable : 4201)
#endif

#define GLM_FORCE_LEFT_HANDED

#include "glm/glm.hpp"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
Expand Down
2 changes: 1 addition & 1 deletion Include/Utilities/Geometry3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace CE

inline AABB3D::AABB3D(std::span<const glm::vec3> points)
{
for (const glm::vec3& point : points)
for (glm::vec3 point : points)
{
mMin = glm::min(point, mMin);
mMax = glm::max(point, mMax);
Expand Down
2 changes: 1 addition & 1 deletion Include/Utilities/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace CE
static glm::quat CalculateRotationBetweenOrientations(glm::quat start, glm::quat end);

// Stolen from https://stackoverflow.com/questions/44705398/about-glm-quaternion-rotation
static glm::vec3 RotateVector(const glm::vec3& v, const glm::quat& q);
static glm::vec3 RotateVector(glm::vec3 v, const glm::quat& q);

static constexpr uint32 floorlog2(uint32 x)
{
Expand Down
30 changes: 19 additions & 11 deletions Source/Assets/Importers/ModelImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,38 @@ namespace
CE::AssetHandle<T> mHandle{};
};

std::string RemoveExtension(const auto& str)
{
return std::filesystem::path{ str }.filename().replace_extension().string();
}

std::string GetEmbedTexName(const std::filesystem::path& modelPath, const int index)
{
return modelPath.filename().replace_extension().string().append("_tex").append(std::to_string(index));
return CE::Format("T_{}_{}", RemoveExtension(modelPath), index);
}

std::string GetTexName(const char* name)
std::string GetTexName(std::string_view name)
{
return std::filesystem::path(name).filename().replace_extension().string();
return CE::Format("T_{}", RemoveExtension(name));
}

std::string GetMeshName(const std::filesystem::path& modelPath, const char* name)
std::string GetMeshName(std::string_view name)
{
return modelPath.filename().replace_extension().string().append("_").append(name);
return CE::Format("SM_{}", RemoveExtension(name));
}

std::string GetSceneName(const std::filesystem::path& modelPath)
{
return modelPath.filename().replace_extension().string().append("_").append("Prefab");
return CE::Format("PF_{}", RemoveExtension(modelPath));
}

std::string GetMaterialName(const std::filesystem::path& modelPath, const char* name, const int index)
std::string GetMaterialName(const std::filesystem::path& modelPath, std::string_view name, const int index)
{
return (*name == *"") ? "M_" + modelPath.filename().string() + *"_Unnamed_Material_" + std::to_string(index) : name;
if (name.empty())
{
return CE::Format("MT_{}_{}", RemoveExtension(modelPath), index);
}
return CE::Format("MT_{}", name);
}

int GetIndexFromAssimpTextureName(const char* name)
Expand Down Expand Up @@ -178,7 +187,7 @@ std::optional<std::vector<CE::ImportedAsset>> CE::ModelImporter::Import(const st
{
const aiMesh& mesh = *scene->mMeshes[i];

const std::string meshName = GetMeshName(file, mesh.mName.C_Str());
const std::string meshName = GetMeshName(mesh.mName.C_Str());

const std::span<const glm::vec3> positions = { reinterpret_cast<const glm::vec3*>(mesh.mVertices), mesh.mNumVertices };
std::vector<uint32> indices{};
Expand Down Expand Up @@ -279,8 +288,7 @@ std::optional<std::vector<CE::ImportedAsset>> CE::ModelImporter::Import(const st

StaticMeshComponent& meshComponent = reg.AddComponent<StaticMeshComponent>(meshHolder);

meshComponent.mStaticMesh = dummyStaticMeshes.emplace_back(GetMeshName(file,
scene->mMeshes[node.mMeshes[i]]->mName.C_Str())).mHandle;
meshComponent.mStaticMesh = dummyStaticMeshes.emplace_back(GetMeshName(scene->mMeshes[node.mMeshes[i]]->mName.C_Str())).mHandle;
meshComponent.mMaterial = std::move(mat);
}

Expand Down
16 changes: 10 additions & 6 deletions Source/Assets/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,27 @@ CE::World CE::Level::CreateDefaultWorld()
reg.AddComponent<NameComponent>(camera, "Main Camera");

TransformComponent& transform = reg.AddComponent<TransformComponent>(camera);
transform.SetLocalPosition({ 5.5f, 2.5f, -7.5f });
transform.SetLocalOrientation({ glm::radians(14.5f), glm::radians(-33.0f), 0.0f });
transform.SetLocalPosition({ -10.0, 10.0f, 6.0f });
transform.SetLocalOrientation(glm::quat{ glm::vec3{ 0.0f, glm::radians(22.5), glm::radians(-45.0f) } });
}


const glm::vec3 mainLightDir{ glm::radians(0.0f), glm::radians(38.5f), glm::radians(-51.0f) };

{
const entt::entity light = reg.Create();
reg.AddComponent<NameComponent>(light, "Main Light");
DirectionalLightComponent& lightComponent = reg.AddComponent<DirectionalLightComponent>(light);
lightComponent.mColor *= 6.0f;
reg.AddComponent<TransformComponent>(light).SetLocalOrientation({ glm::radians(-15.6), glm::radians(-47.6), glm::radians(51.6) });
lightComponent.mColor *= .7f;

reg.AddComponent<TransformComponent>(light).SetLocalOrientation(glm::quat{ mainLightDir });
}

{
const entt::entity light = reg.Create();
reg.AddComponent<NameComponent>(light, "Secondary Light");
reg.AddComponent<DirectionalLightComponent>(light).mColor *= 3.0f;
reg.AddComponent<TransformComponent>(light).SetLocalOrientation({ glm::radians(113.8), glm::radians(53.54), glm::radians(90.7) });
reg.AddComponent<DirectionalLightComponent>(light).mColor *= .3f;
reg.AddComponent<TransformComponent>(light).SetLocalOrientation(glm::quat{ -mainLightDir });
}

return world;
Expand Down
Loading

0 comments on commit 349f146

Please sign in to comment.