|
|
@@ -9,7 +9,7 @@ namespace anki {
|
|
|
//==============================================================================
|
|
|
Camera::Camera(
|
|
|
const char* name, SceneGraph* scene, // SceneNode
|
|
|
- Frustum* frustum, // Spatial & Frustumable
|
|
|
+ Frustum* frustum, // SpatialComponent & FrustumComponent
|
|
|
CameraType type_)
|
|
|
: SceneNode(name, scene),
|
|
|
MoveComponent(this),
|
|
|
@@ -17,13 +17,10 @@ Camera::Camera(
|
|
|
FrustumComponent(frustum),
|
|
|
type(type_)
|
|
|
{
|
|
|
- sceneNodeProtected.moveC = this;
|
|
|
- sceneNodeProtected.spatialC = this;
|
|
|
- sceneNodeProtected.frustumC = this;
|
|
|
-
|
|
|
// Init components
|
|
|
newComponent<MoveComponent>(this);
|
|
|
newComponent<SpatialComponent>(this, frustum);
|
|
|
+ newComponent<FrustumComponent>(this, frustum);
|
|
|
}
|
|
|
|
|
|
//==============================================================================
|
|
|
@@ -33,14 +30,47 @@ Camera::~Camera()
|
|
|
//==============================================================================
|
|
|
void Camera::lookAtPoint(const Vec3& point)
|
|
|
{
|
|
|
+ MoveComponent& move = getComponent<MoveComponent>();
|
|
|
+
|
|
|
const Vec3& j = Vec3(0.0, 1.0, 0.0);
|
|
|
- Vec3 vdir = (point - getLocalTransform().getOrigin()).getNormalized();
|
|
|
+ Vec3 vdir = (point - move.getLocalTransform().getOrigin()).getNormalized();
|
|
|
Vec3 vup = j - vdir * j.dot(vdir);
|
|
|
Vec3 vside = vdir.cross(vup);
|
|
|
|
|
|
- Mat3 rot = getLocalTransform().getRotation();
|
|
|
+ Mat3 rot = move.getLocalTransform().getRotation();
|
|
|
rot.setColumns(vside, vup, -vdir);
|
|
|
- setLocalRotation(rot);
|
|
|
+ move.setLocalRotation(rot);
|
|
|
+}
|
|
|
+
|
|
|
+//==============================================================================
|
|
|
+void Camera::frustumUpdate()
|
|
|
+{
|
|
|
+ // Frustum
|
|
|
+ FrustumComponent& fr = getComponent<FrustumComponent>();
|
|
|
+ fr.setProjectionMatrix(fr.getFrustum().calculateProjectionMatrix());
|
|
|
+ fr.setViewProjectionMatrix(fr.getProjectionMatrix() * fr.getViewMatrix());
|
|
|
+ fr.markForUpdate();
|
|
|
+
|
|
|
+ // Spatial
|
|
|
+ SpatialComponent& sp = getComponent<SpatialComponent>();
|
|
|
+ sp.markForUpdate();
|
|
|
+}
|
|
|
+
|
|
|
+//==============================================================================
|
|
|
+void Camera::moveUpdate(MoveComponent& move)
|
|
|
+{
|
|
|
+ // Frustum
|
|
|
+ FrustumComponent& fr = getComponent<FrustumComponent>();
|
|
|
+ fr.setViewMatrix(move.getWorldTransform().getInverse());
|
|
|
+ fr.setViewProjectionMatrix(fr.getProjectionMatrix() * fr.getViewMatrix());
|
|
|
+ fr.setOrigin(move.getWorldTransform().getOrigin());
|
|
|
+ fr.markForUpdate();
|
|
|
+ fr.getFrustum().setTransform(move.getWorldTransform());
|
|
|
+
|
|
|
+ // Spatial
|
|
|
+ SpatialComponent& sp = getComponent<SpatialComponent>();
|
|
|
+ sp.setOrigin(move.getWorldTransform().getOrigin());
|
|
|
+ sp.markForUpdate();
|
|
|
}
|
|
|
|
|
|
//==============================================================================
|