There is a memory leak
This commit is contained in:
@@ -11,8 +11,8 @@ Camera::Camera()
|
||||
: viewMatrix(Matrix4())
|
||||
, bNeedsViewBuild(false)
|
||||
{
|
||||
yaw = 0;
|
||||
pitch = 0.2;
|
||||
yaw = 3.1415f/2;
|
||||
pitch = 0;
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
@@ -21,40 +21,37 @@ Camera::~Camera()
|
||||
|
||||
void Camera::mouseMove(float deltaYaw, float deltaPitch)
|
||||
{
|
||||
yaw -= deltaYaw / 500.f;
|
||||
yaw += deltaYaw / 500.f;
|
||||
pitch += deltaPitch / 500.f;
|
||||
//std::cout << "Yaw: " << yaw << " Pitch: " << pitch << std::endl;
|
||||
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
|
||||
Vector xyz = glm::cross(cameraDirection, Vector(0, 0, 1));
|
||||
Quaternion result = Quaternion(glm::dot(cameraDirection, Vector(0, 0, 1)) + 1, xyz.x, xyz.y, xyz.z);
|
||||
//std::cout << "Result " << Vector(0, 0, 1) * glm::normalize(result) << " cameraDirection: " << cameraDirection << std::endl;
|
||||
getTransform().setRelativeRotation(result);
|
||||
Matrix4 viewMat = glm::lookAt(getTransform().getPosition(), getTransform().getPosition() + cameraDirection, Vector(0, 1, 0));
|
||||
getTransform().setRotation(viewMat); // quaternion from matrix, janky but im bad at math
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void Camera::mouseScroll(float x)
|
||||
{
|
||||
getTransform().addRelativeLocation(getTransform().getForward()*x);
|
||||
getTransform().translate(getTransform().getForward()*x);
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void Camera::moveX(float amount)
|
||||
{
|
||||
getTransform().addRelativeLocation(getTransform().getForward()*amount);
|
||||
getTransform().translate(getTransform().getForward()*amount);
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void Camera::moveY(float amount)
|
||||
{
|
||||
getTransform().addRelativeLocation(getTransform().getRight()*amount);
|
||||
getTransform().translate(getTransform().getRight()*amount);
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void Camera::buildViewMatrix()
|
||||
{
|
||||
Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition();
|
||||
Vector lookAt = eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
|
||||
Vector eyePos = getTransform().getPosition();
|
||||
Vector lookAt = eyePos + getTransform().getForward();
|
||||
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
|
||||
|
||||
cameraPos = eyePos;
|
||||
bNeedsViewBuild = false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ struct Camera
|
||||
}
|
||||
Vector getCameraPosition() const
|
||||
{
|
||||
return Vector(viewMatrix[3]);
|
||||
return cameraPos;
|
||||
}
|
||||
void mouseMove(float deltaX, float deltaY);
|
||||
void mouseScroll(float x);
|
||||
@@ -29,6 +29,8 @@ struct Camera
|
||||
void moveY(float amount);
|
||||
void buildViewMatrix();
|
||||
Matrix4 viewMatrix;
|
||||
Vector cameraPos;
|
||||
Vector cameraDirection;
|
||||
//Transforms relative to actor
|
||||
float yaw;
|
||||
float pitch;
|
||||
|
||||
@@ -4,7 +4,6 @@ using namespace Seele::Component;
|
||||
|
||||
DEFINE_COMPONENT(Transform)
|
||||
|
||||
|
||||
void Transform::setPosition(Vector pos)
|
||||
{
|
||||
transform.setPosition(pos);
|
||||
@@ -19,32 +18,15 @@ void Transform::setScale(Vector scale)
|
||||
{
|
||||
transform.setScale(scale);
|
||||
}
|
||||
|
||||
void Transform::setRelativeLocation(Vector location)
|
||||
void Transform::translate(Vector direction)
|
||||
{
|
||||
transform = Math::Transform(location, transform.getRotation(), transform.getScale());
|
||||
transform.setPosition(transform.getPosition() + direction);
|
||||
}
|
||||
void Transform::setRelativeRotation(Vector rotation)
|
||||
void Transform::rotate(Quaternion quat)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition(), Quaternion(rotation), transform.getScale());
|
||||
transform.setRotation(transform.getRotation() * quat);
|
||||
}
|
||||
void Transform::setRelativeRotation(Quaternion rotation)
|
||||
void Transform::scale(Vector scale)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition(), rotation, transform.getScale());
|
||||
}
|
||||
void Transform::setRelativeScale(Vector scale)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition(), transform.getRotation(), scale);
|
||||
}
|
||||
void Transform::addRelativeLocation(Vector translation)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition() + translation, transform.getRotation(), transform.getScale());
|
||||
}
|
||||
void Transform::addRelativeRotation(Vector rotation)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition(), transform.getRotation() * Quaternion(rotation), transform.getScale());
|
||||
}
|
||||
void Transform::addRelativeRotation(Quaternion rotation)
|
||||
{
|
||||
transform = Math::Transform(transform.getPosition(), transform.getRotation() * rotation, transform.getScale());
|
||||
transform.setScale(transform.getScale() + scale);
|
||||
}
|
||||
@@ -21,15 +21,9 @@ struct Transform
|
||||
void setPosition(Vector pos);
|
||||
void setRotation(Quaternion quat);
|
||||
void setScale(Vector scale);
|
||||
|
||||
void setRelativeLocation(Vector location);
|
||||
void setRelativeRotation(Quaternion rotation);
|
||||
void setRelativeRotation(Vector rotation);
|
||||
void setRelativeScale(Vector scale);
|
||||
|
||||
void addRelativeLocation(Vector translation);
|
||||
void addRelativeRotation(Quaternion rotation);
|
||||
void addRelativeRotation(Vector rotation);
|
||||
void translate(Vector direction);
|
||||
void rotate(Quaternion quat);
|
||||
void scale(Vector scale);
|
||||
private:
|
||||
Math::Transform transform;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user