Panagiotis Christopoulos Charitos 14 gadi atpakaļ
vecāks
revīzija
f90f6ffab9

+ 30 - 0
anki/scene/Camera.cpp

@@ -24,4 +24,34 @@ void Camera::lookAtPoint(const Vec3& point)
 }
 
 
+//==============================================================================
+// PerspectiveCamera                                                           =
+//==============================================================================
+
+//==============================================================================
+PerspectiveCamera::PerspectiveCamera(const char* name, Scene* scene,
+	uint movableFlags, Movable* movParent)
+	: Camera(CT_PERSPECTIVE, name, scene, movableFlags, movParent, &frustum)
+{
+	Property<PerspectiveFrustum>& prop =
+		addProperty("frustum", &frustum, PropertyBase::PF_READ_WRITE);
+	ANKI_CONNECT(&prop, valueChanged, this, updateFrustumSlot);
+}
+
+
+//==============================================================================
+// OrthographicCamera                                                          =
+//==============================================================================
+
+//==============================================================================
+OrthographicCamera::OrthographicCamera(const char* name, Scene* scene,
+	uint movableFlags, Movable* movParent)
+	: Camera(CT_ORTHOGRAPHIC, name, scene, movableFlags, movParent, &frustum)
+{
+	Property<OrthographicFrustum>& prop =
+		addProperty("frustum", &frustum, PropertyBase::PF_READ_WRITE);
+	ANKI_CONNECT(&prop, valueChanged, this, updateFrustumSlot);
+}
+
+
 } // end namespace

+ 34 - 17
anki/scene/Camera.h

@@ -29,12 +29,11 @@ public:
 	/// @name Constructors
 	/// @{
 	Camera(CameraType type_,
-		const char* name, Scene* scene,
-		uint movableFlags, Movable* movParent,
-		CollisionShape* spartCs,
-		Frustum* frustum)
-		: SceneNode(name, scene), Movable(movableFlags, movParent),
-			Spatial(spartCs), Frustumable(frustum), type(type_)
+		const char* name, Scene* scene, // SceneNode
+		uint movableFlags, Movable* movParent, // Movable
+		Frustum* frustum) // Spatial &  Frustumable
+		: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
+			Spatial(frustum), Frustumable(frustum), type(type_)
 	{}
 	/// @}
 
@@ -63,7 +62,7 @@ public:
 	}
 	/// @}
 
-	/// @name Implementation of virtuals
+	/// @name SceneNode virtuals
 	/// @{
 
 	/// Re-implements SceneNode::getMovable()
@@ -73,16 +72,20 @@ public:
 	}
 
 	/// Re-implements SceneNode::getFrustumable()
-	virtual Frustumable* getFrustumable()
+	Frustumable* getFrustumable()
 	{
 		return this;
 	}
 
 	/// Re-implements SceneNode::getSpatial()
-	virtual Spatial* getSpatial()
+	Spatial* getSpatial()
 	{
 		return this;
 	}
+	/// @}
+
+	/// @name Movable virtuals
+	/// @{
 
 	/// Re-impements Movable::moveUpdate(). This does:
 	/// - Update view matrix
@@ -93,6 +96,10 @@ public:
 		updateViewMatrix();
 		getFrustum().transform(getWorldTransform());
 	}
+	/// @}
+
+	/// @name Frustumable virtuals
+	/// @{
 
 	/// Implements Frustumable::frustumUpdate(). Calculate the projection
 	/// matrix
@@ -136,13 +143,12 @@ private:
 class PerspectiveCamera: public Camera
 {
 public:
+	ANKI_OBSERVING(PerspectiveCamera)
+
 	/// @name Constructors
 	/// @{
 	PerspectiveCamera(const char* name, Scene* scene,
-		uint movableFlags, Movable* movParent)
-		: Camera(CT_PERSPECTIVE, name, scene, movableFlags, movParent,
-			&frustum, &frustum)
-	{}
+		uint movableFlags, Movable* movParent);
 	/// @}
 
 	/// @name Accessors
@@ -176,6 +182,12 @@ public:
 
 private:
 	PerspectiveFrustum frustum;
+
+	void updateFrustumSlot(const PerspectiveFrustum&)
+	{
+		frustumUpdate();
+	}
+	ANKI_SLOT(updateFrustumSlot, const PerspectiveFrustum&)
 };
 
 
@@ -183,13 +195,12 @@ private:
 class OrthographicCamera: public Camera
 {
 public:
+	ANKI_OBSERVING(OrthographicCamera)
+
 	/// @name Constructors
 	/// @{
 	OrthographicCamera(const char* name, Scene* scene,
-		uint movableFlags, Movable* movParent)
-		: Camera(CT_ORTHOGRAPHIC, name, scene, movableFlags, movParent,
-			&frustum, &frustum)
-	{}
+		uint movableFlags, Movable* movParent);
 	/// @}
 
 	/// @name Accessors
@@ -245,6 +256,12 @@ public:
 
 private:
 	OrthographicFrustum frustum;
+
+	void updateFrustumSlot(const OrthographicFrustum&)
+	{
+		frustumUpdate();
+	}
+	ANKI_SLOT(updateFrustumSlot, const OrthographicFrustum&)
 };
 /// @}
 

+ 6 - 4
anki/scene/Frustumable.h

@@ -2,6 +2,7 @@
 #define ANKI_SCENE_FRUSTUMABLE_H
 
 #include "anki/collision/Frustum.h"
+#include "anki/scene/Spatial.h"
 
 
 namespace anki {
@@ -10,7 +11,7 @@ namespace anki {
 /// @addtogroup Scene
 /// @{
 
-/// Frustumable "interface" for scene nodes
+/// Frustumable interface for scene nodes
 class Frustumable
 {
 public:
@@ -58,12 +59,13 @@ public:
 	/// Called when a frustum parameter changes
 	virtual void frustumUpdate() = 0;
 
-	bool insideFrustum(const CollisionShape& cs) const
+	/// Is a spatial inside the frustum
+	bool insideFrustum(const Spatial& sp) const
 	{
-		return frustum->insideFrustum(cs);
+		return frustum->insideFrustum(sp.getSpatialCollisionShape());
 	}
 
-private:
+protected:
 	Frustum* frustum;
 };
 

+ 1 - 1
anki/scene/Property.h

@@ -89,7 +89,7 @@ private:
 	uint tid;
 	uint flags;
 
-	/// Runtime checking of type
+	/// Runtime type checking
 	template<typename T>
 	void checkType() const
 	{

+ 9 - 28
anki/scene/Renderable.h

@@ -5,10 +5,9 @@
 namespace anki {
 
 
-class PassLevelKey;
-class MaterialRuntime;
-class MeshBase;
-class Transform;
+class ModelPatchBase;
+class Material;
+class PropertyMap;
 
 
 /// @addtogroup Scene
@@ -26,33 +25,15 @@ public:
 		return NULL;
 	}
 
-	/// Get the material runtime
-	virtual MaterialRuntime& getMaterialRuntime() = 0;
+	/// Get the material runtime. Dont access it from the ModelPatchBase
+	/// because the lights dont have one
+	virtual Material& getMaterial() = 0;
 
-	/// Get current transform
-	virtual const Transform* getWorldTransform(const PassLevelKey& k)
-	{
-		return NULL;
-	}
+	/// Access to property map to get the values of the shader variables
+	virtual PropertyMap& getPropertyMap() = 0;
 
-	/// Get previous transform
-	virtual const Transform* getPreviousWorldTransform(
-		const PassLevelKey& k)
-	{
-		return NULL;
-	}
+private:
 
-	/// Get projection matrix (for lights)
-	virtual const Mat4* getProjectionMatrix() const
-	{
-		return NULL;
-	}
-
-	/// Get view matrix (for lights)
-	virtual const Mat4* getViewMatrix() const
-	{
-		return NULL;
-	}
 };
 /// @}
 

+ 1 - 11
anki/scene/SceneNode.h

@@ -20,7 +20,7 @@ class Spatial;
 /// @{
 
 /// Interface class backbone of scene
-class SceneNode
+class SceneNode: public PropertyMap
 {
 public:
 	/// @name Constructors/Destructor
@@ -43,15 +43,6 @@ public:
 	{
 		return name;
 	}
-
-	const PropertyMap& getPropertyMap() const
-	{
-		return pmap;
-	}
-	PropertyMap& getPropertyMap()
-	{
-		return pmap;
-	}
 	/// @}
 
 	/// @name Accessors of components
@@ -87,7 +78,6 @@ public:
 private:
 	std::string name; ///< A unique name
 	Scene* scene; ///< Keep it here for unregistering
-	PropertyMap pmap;
 };
 /// @}
 

+ 8 - 8
anki/scene/Spatial.h

@@ -18,21 +18,21 @@ class Spatial
 {
 public:
 	/// Pass the collision shape here so we can avoid the virtuals
-	Spatial(CollisionShape* cs_)
-		: cs(cs_)
+	Spatial(CollisionShape* cs)
+		: spatialCs(cs)
 	{}
 
-	const CollisionShape& getCollisionShape() const
+	const CollisionShape& getSpatialCollisionShape() const
 	{
-		return *cs;
+		return *spatialCs;
 	}
-	CollisionShape& getCollisionShape()
+	CollisionShape& getSpatialCollisionShape()
 	{
-		return *cs;
+		return *spatialCs;
 	}
 
-private:
-	CollisionShape* cs;
+protected:
+	CollisionShape* spatialCs;
 };
 /// @}