Starting implementation of UI framework

This commit is contained in:
Dynamitos
2021-01-19 15:30:00 +01:00
parent 65caae9e21
commit fb3c66cc4c
57 changed files with 381 additions and 186 deletions
-1
View File
@@ -47,7 +47,6 @@ protected:
PActor parent;
Array<PActor> children;
PComponent rootComponent;
Transform transform;
};
DEFINE_REF(Actor);
} // namespace Seele
+1 -1
View File
@@ -15,7 +15,7 @@ CameraActor::CameraActor()
cameraComponent->setParent(sceneComponent);
cameraComponent->setOwner(this);
addWorldTranslation(Vector(0, 0, 50));
addWorldRotation(Vector(0, -1, 0));
addWorldRotation(Vector(0, -100, 0));
}
CameraActor::~CameraActor()
@@ -1,5 +1,7 @@
#include "CameraComponent.h"
#include "Scene/Actor/Actor.h"
#include <algorithm>
#include <iostream>
using namespace Seele;
@@ -11,7 +13,7 @@ CameraComponent::CameraComponent()
{
distance = 50;
rotationX = 0;
rotationY = -0.5f;
rotationY = -1.f;
}
CameraComponent::~CameraComponent()
@@ -21,25 +23,26 @@ CameraComponent::~CameraComponent()
void CameraComponent::mouseMove(float deltaX, float deltaY)
{
//0.01 mouse sensitivity
rotationX += deltaX/100.f;
rotationY += deltaY/100.f;
rotationX += deltaX/500.f;
rotationY += deltaY/500.f;
rotationY = std::clamp(rotationY, -1.5f, 1.5f);
addWorldRotation(Vector(rotationX, rotationY, 0));
getParent()->setWorldRotation(glm::rotate(glm::quat(), rotationX, Vector(0, 1, 0)));
getParent()->setWorldRotation(glm::rotate(glm::quat(), rotationY, Vector(1, 0, 0)));
bNeedsViewBuild = true;
}
void CameraComponent::mouseScroll(double x)
{
distance += static_cast<float>(x);
distance -= static_cast<float>(x);
distance = std::max(distance, 1.f);
addWorldTranslation(Vector(0, 0, x));
getParent()->addWorldTranslation(Vector(0, 0, x));
bNeedsViewBuild = true;
}
void CameraComponent::moveOrigin(float up)
{
originPoint.y += up;
addWorldTranslation(Vector(0, up, 0));
getParent()->addWorldTranslation(Vector(0, up, 0));
bNeedsViewBuild = true;
}
@@ -26,6 +26,14 @@ public:
}
return projectionMatrix;
}
Vector getCameraPosition()
{
if(bNeedsViewBuild)
{
buildViewMatrix();
}
return cameraPosition;
}
void mouseMove(float deltaX, float deltaY);
void mouseScroll(double x);
void moveOrigin(float up);
+12 -5
View File
@@ -6,6 +6,9 @@ using namespace Seele;
Component::Component()
{
relativeLocation = Vector(0);
relativeRotation = Vector(0);
relativeScale = Vector(1, 1, 1);
}
Component::~Component()
{
@@ -101,17 +104,17 @@ void Component::setRelativeScale(Vector scale)
}
void Component::addWorldTranslation(Vector translation)
{
const Vector newWorldLocation = translation + transform.getPosition();
const Vector newWorldLocation = translation + getTransform().getPosition();
setWorldLocation(newWorldLocation);
}
void Component::addWorldRotation(Vector rotation)
{
const Quaternion newWorldRotation = toQuaternion(rotation) * transform.getRotation();
const Quaternion newWorldRotation = toQuaternion(rotation) * getTransform().getRotation();
setWorldRotation(newWorldRotation);
}
void Component::addWorldRotation(Quaternion rotation)
{
const Quaternion newWorldRotation = rotation * transform.getRotation();
const Quaternion newWorldRotation = rotation * getTransform().getRotation();
setWorldRotation(newWorldRotation);
}
Transform Component::getTransform() const
@@ -169,9 +172,13 @@ void Component::updateComponentTransform(Quaternion relativeRotationQuat)
bComponentTransformClean = true;
Transform newTransform;
const Transform relTransform(relativeLocation, relativeRotationQuat, relativeScale);
if (parent != nullptr)
if(parent != nullptr)
{
newTransform = parent->getTransform() * relTransform;
newTransform = relTransform * parent->getTransform();
}
else
{
newTransform = relTransform;
}
bool bHasChanged = !getTransform().equals(newTransform);
if (bHasChanged)
@@ -3,6 +3,7 @@
#include "Material/MaterialInstance.h"
#include "Asset/MeshAsset.h"
#include "Graphics/VertexShaderInput.h"
#include <iostream>
using namespace Seele;
+6
View File
@@ -10,6 +10,12 @@ using namespace Seele;
Scene::Scene(Gfx::PGraphics graphics)
: graphics(graphics)
{
lightEnv.directionalLights[0].color = Vector4(1, 0, 0, 1);
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
lightEnv.numDirectionalLights = 1;
lightEnv.numPointLights = 0;
srand(time(NULL));
}
Scene::~Scene()
+1 -1
View File
@@ -30,7 +30,7 @@ struct LightEnv
{
DirectionalLight directionalLights[MAX_DIRECTIONAL_LIGHTS];
PointLight pointLights[MAX_POINT_LIGHTS];
uint32 numDirectionalLgiths;
uint32 numDirectionalLights;
uint32 numPointLights;
};