Browse Source

Same as before

Panagiotis Christopoulos Charitos 14 years ago
parent
commit
ba34e26d35
6 changed files with 124 additions and 318 deletions
  1. 0 3
      anki/scene/Camera.cpp
  2. 62 144
      anki/scene/Camera.h
  3. 0 9
      anki/scene/Frustumable.h
  4. 1 27
      anki/scene/SceneNode.cpp
  5. 18 135
      anki/scene/SceneNode.h
  6. 43 0
      anki/scene/Spartial.h

+ 0 - 3
anki/scene/Camera.cpp

@@ -6,9 +6,6 @@ namespace anki {
 
 
 
 
 //==============================================================================
 //==============================================================================
-// Constructors & desrtuctor                                                   =
-//==============================================================================
-
 Camera::~Camera()
 Camera::~Camera()
 {}
 {}
 
 

+ 62 - 144
anki/scene/Camera.h

@@ -1,9 +1,10 @@
 #ifndef ANKI_SCENE_CAMERA_H
 #ifndef ANKI_SCENE_CAMERA_H
 #define ANKI_SCENE_CAMERA_H
 #define ANKI_SCENE_CAMERA_H
 
 
-#include "anki/collision/Collision.h"
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/SceneNode.h"
-#include "anki/scene/VisibilityInfo.h"
+#include "anki/scene/Spartial.h"
+#include "anki/scene/Movable.h"
+#include "anki/scene/Frustumable.h"
 #include <boost/array.hpp>
 #include <boost/array.hpp>
 #include <deque>
 #include <deque>
 #include <vector>
 #include <vector>
@@ -12,157 +13,74 @@
 namespace anki {
 namespace anki {
 
 
 
 
-class SpotLight;
-class PointLight;
-
-
 /// @addtogroup Scene
 /// @addtogroup Scene
 /// @{
 /// @{
 
 
 /// Camera SceneNode interface class
 /// Camera SceneNode interface class
-class Camera: public SceneNode, public VisibilityInfo
+class Camera: public SceneNode, public Movable, public Spartial,
+	public Frustumable
 {
 {
-	public:
-		/// @note Don't EVER change the order
-		enum CameraType
-		{
-			CT_PERSPECTIVE,
-			CT_ORTHOGRAPHIC,
-			CT_NUM
-		};
-
-		enum FrustrumPlanes
-		{
-			FP_LEFT = 0,
-			FP_RIGHT,
-			FP_NEAR,
-			FP_TOP,
-			FP_BOTTOM,
-			FP_FAR,
-			FP_NUM
-		};
-
-		Camera(CameraType type, Scene& scene, ulong flags, SceneNode* parent);
-
-		virtual ~Camera();
-
-		/// @name Accessors
-		/// @{
-		CameraType getCameraType() const
-		{
-			return type;
-		}
-
-		float getZNear() const
-		{
-			return zNear;
-		}
-		void setZNear(float znear);
-
-		float getZFar() const
-		{
-			return zFar;
-		}
-		void setZFar(float zfar);
-
-		const Mat4& getProjectionMatrix() const
-		{
-			return projectionMat;
-		}
-
-		const Mat4& getViewMatrix() const
-		{
-			return viewMat;
-		}
-
-		/// See the declaration of invProjectionMat for info
-		const Mat4& getInvProjectionMatrix() const
-		{
-			return invProjectionMat;
-		}
-
-		const Plane& getWSpaceFrustumPlane(FrustrumPlanes id) const
-		{
-			return wspaceFrustumPlanes[id];
-		}
-		/// @}
-
-		void lookAtPoint(const Vec3& point);
-
-		/// This does:
-		/// - Update view matrix
-		/// - Update frustum planes
-		virtual void moveUpdate();
-
-		/// @name Frustum checks
-		/// @{
-
-		/// Check if the given camera is inside the frustum clipping planes.
-		/// This is used mainly to test if the projected lights are visible
-		bool insideFrustum(const CollisionShape& vol) const;
-		/// @}
-
-	protected:
-		float zNear, zFar;
-
-		/// @name The frustum planes in local and world space
-		/// @{
-		boost::array<Plane, FP_NUM> lspaceFrustumPlanes;
-		boost::array<Plane, FP_NUM> wspaceFrustumPlanes;
-		/// @}
-
-		/// @name Matrices
-		/// @{
-		Mat4 projectionMat;
-		Mat4 viewMat;
-
-		/// Used in deferred shading for the calculation of view vector (see
-		/// CalcViewVector). The reason we store this matrix here is that we
-		/// don't want it to be re-calculated all the time but only when the
-		/// projection params (fovX, fovY, zNear, zFar) change. Fortunately
-		/// the projection params change rarely. Note that the Camera as we all
-		/// know re-calculates the matrices only when the parameters change!!
-		Mat4 invProjectionMat;
-		/// @}
-
-		/// Calculate projectionMat and invProjectionMat
-		virtual void calcProjectionMatrix() = 0;
-		virtual void calcLSpaceFrustumPlanes() = 0;
-		void updateViewMatrix();
-		void updateWSpaceFrustumPlanes();
-
-	private:
-		CameraType type;
+public:
+	/// @note Don't EVER change the order
+	enum CameraType
+	{
+		CT_PERSPECTIVE,
+		CT_ORTHOGRAPHIC,
+		CT_COUNT
+	};
+
+	Camera(CameraType type,
+		const char* name, Scene* scene,
+		uint movableFlags, Movable* movParent,
+		CollisionShape* spartCs,
+		Frustum* frustum)
+		: type(type_), SceneNode(name, scene),
+			Movable(movableFlags, movParent), Spartial(spartCs),
+			Frustumable(frustum)
+	{}
+
+	virtual ~Camera();
+
+	/// @name Accessors
+	/// @{
+	CameraType getCameraType() const
+	{
+		return type;
+	}
+	/// @}
+
+	/// @name
+
+	void lookAtPoint(const Vec3& point);
+
+	/// This does:
+	/// - Update view matrix
+	/// - Update frustum planes
+	virtual void moveUpdate();
+
+protected:
+
+	/// @name Matrices
+	/// @{
+	Mat4 projectionMat;
+	Mat4 viewMat;
+
+	/// Used in deferred shading for the calculation of view vector (see
+	/// CalcViewVector). The reason we store this matrix here is that we
+	/// don't want it to be re-calculated all the time but only when the
+	/// projection params (fovX, fovY, zNear, zFar) change. Fortunately
+	/// the projection params change rarely. Note that the Camera as we all
+	/// know re-calculates the matrices only when the parameters change!!
+	Mat4 invProjectionMat;
+	/// @}
+private:
+	CameraType type;
+
+	void updateViewMatrix();
 };
 };
 /// @}
 /// @}
 
 
 
 
-
-inline Camera::Camera(CameraType t, Scene& scene, ulong flags,
-	SceneNode* parent)
-:	SceneNode(SNT_CAMERA, scene, flags, parent),
- 	type(t)
-{
-	name = "Camera:" + name;
-}
-
-
-inline void Camera::setZNear(float znear_)
-{
-	zNear = znear_;
-	calcProjectionMatrix();
-	calcLSpaceFrustumPlanes();
-}
-
-
-inline void Camera::setZFar(float zfar_)
-{
-	zFar = zfar_;
-	calcProjectionMatrix();
-	calcLSpaceFrustumPlanes();
-}
-
-
 } // end namespace
 } // end namespace
 
 
 
 

+ 0 - 9
anki/scene/Frustumable.h

@@ -19,15 +19,6 @@ public:
 		: frustum(fr)
 		: frustum(fr)
 	{}
 	{}
 
 
-	const Frustum& getFrustum() const
-	{
-		return *frustum;
-	}
-	Frustum& getFrustum()
-	{
-		return *frustum;
-	}
-
 	bool insideFrustum(const CollisionShape& cs) const
 	bool insideFrustum(const CollisionShape& cs) const
 	{
 	{
 		return frustum->insideFrustum(cs);
 		return frustum->insideFrustum(cs);

+ 1 - 27
anki/scene/SceneNode.cpp

@@ -6,9 +6,7 @@ namespace anki {
 
 
 
 
 //==============================================================================
 //==============================================================================
-SceneNode::SceneNode(const char* name_, long flags_,
-	SceneNode* parent, Scene* scene_)
-	: Base(this, parent), name(name_), flags(flags_), scene(scene_)
+SceneNode::SceneNode(const char* name, Scene* scene)
 {
 {
 	scene->registerNode(this);
 	scene->registerNode(this);
 }
 }
@@ -21,28 +19,4 @@ SceneNode::~SceneNode()
 }
 }
 
 
 
 
-//==============================================================================
-void SceneNode::updateWorldTransform()
-{
-	prevWTrf = wTrf;
-
-	if(getParent())
-	{
-		if(isFlagEnabled(SNF_IGNORE_LOCAL_TRANSFORM))
-		{
-			wTrf = getParent()->getWorldTransform();
-		}
-		else
-		{
-			wTrf = Transform::combineTransformations(
-				getParent()->getWorldTransform(), lTrf);
-		}
-	}
-	else // else copy
-	{
-		wTrf = lTrf;
-	}
-}
-
-
 } // end namespace
 } // end namespace

+ 18 - 135
anki/scene/SceneNode.h

@@ -1,186 +1,69 @@
 #ifndef ANKI_SCENE_SCENE_NODE_H
 #ifndef ANKI_SCENE_SCENE_NODE_H
 #define ANKI_SCENE_SCENE_NODE_H
 #define ANKI_SCENE_SCENE_NODE_H
 
 
-#include "anki/math/Math.h"
-#include "anki/collision/Obb.h"
-#include "anki/util/Object.h"
 #include <string>
 #include <string>
 
 
 
 
 namespace anki {
 namespace anki {
 
 
 
 
-class Scene;
+class Scene; // Don't include
+
+class Movable;
 class Renderable;
 class Renderable;
-class Frustum;
+class Frustumable;
+class Spartial;
 
 
 
 
 /// @addtogroup scene
 /// @addtogroup scene
 /// @{
 /// @{
 
 
 /// Interface class backbone of scene
 /// Interface class backbone of scene
-class SceneNode: public Object<SceneNode>
+class SceneNode
 {
 {
 public:
 public:
-	typedef Object<SceneNode> Base;
-
-	enum SceneNodeFlags
-	{
-		SNF_NONE = 0,
-		SNF_IGNORE_LOCAL_TRANSFORM = 1, ///< Get the parent's world transform
-		SNF_MOVED = 2 ///< Moved in the previous frame. The scene update sets it
-	};
-
 	/// The one and only constructor
 	/// The one and only constructor
-	/// @param flags The flags with the node properties
-	/// @param parent The nods's parent. It can be nullptr
+	/// @param name The unique name of the node
+	/// @param scene The scene that will register it
 	explicit SceneNode(
 	explicit SceneNode(
 		const char* name,
 		const char* name,
-		long flags,
-		SceneNode* parent,
 		Scene* scene);
 		Scene* scene);
 
 
 	/// Unregister node
 	/// Unregister node
 	virtual ~SceneNode();
 	virtual ~SceneNode();
 
 
-	/// @name Accessors
+	/// @name Accessors of properties
 	/// @{
 	/// @{
-	const Transform& getLocalTransform() const
-	{
-		return lTrf;
-	}
-	Transform& getLocalTransform()
-	{
-		return lTrf;
-	}
-	void setLocalTransform(const Transform& x)
-	{
-		lTrf = x;
-	}
-
-	const Transform& getWorldTransform() const
-	{
-		return wTrf;
-	}
-	Transform& getWorldTransform()
-	{
-		return wTrf;
-	}
-	void setWorldTransform(const Transform& x)
+	virtual Movable* getMovable()
 	{
 	{
-		wTrf = x;
+		return NULL;
 	}
 	}
 
 
-	const Transform& getPrevWorldTransform() const
+	virtual Renderable* getRenderable()
 	{
 	{
-		return prevWTrf;
+		return NULL;
 	}
 	}
 
 
-	ulong getFlags() const
+	virtual Frustumable* getFrustumable()
 	{
 	{
-		return flags;
+		return NULL;
 	}
 	}
-	/// @}
 
 
-	/// @name Flag manipulation
-	/// @{
-	void enableFlag(SceneNodeFlags flag, bool enable = true)
-	{
-		if(enable)
-		{
-			flags |= flag;
-		}
-		else
-		{
-			flags &= ~flag;
-		}
-	}
-	void disableFlag(SceneNodeFlags flag)
+	virtual Spartial* getSpartial()
 	{
 	{
-		enableFlag(flag, false);
-	}
-	bool isFlagEnabled(SceneNodeFlags flag) const
-	{
-		return flags & flag;
+		return NULL;
 	}
 	}
 	/// @}
 	/// @}
 
 
-	/// @name Updates
-	/// Two separate updates for the main loop. The update happens anyway
-	/// and the updateTrf only when the node is being moved
-	/// @{
-
-	/// This is called every frame
+	/// This is called by the scene every frame
 	virtual void frameUpdate(float prevUpdateTime, float crntTime)
 	virtual void frameUpdate(float prevUpdateTime, float crntTime)
 	{
 	{
 		(void)prevUpdateTime;
 		(void)prevUpdateTime;
 		(void)crntTime;
 		(void)crntTime;
 	}
 	}
 
 
-	/// This is called if the node moved
-	virtual void moveUpdate()
-	{}
-	/// @}
-
-	virtual Renderable* getRenderable()
-	{
-		return NULL;
-	}
-
-	virtual Frustum* getFrustum()
-	{
-		return NULL;
-	}
-
-	/// @name Mess with the local transform
-	/// @{
-	void rotateLocalX(float angDegrees)
-	{
-		lTrf.getRotation().rotateXAxis(angDegrees);
-	}
-	void rotateLocalY(float angDegrees)
-	{
-		lTrf.getRotation().rotateYAxis(angDegrees);
-	}
-	void rotateLocalZ(float angDegrees)
-	{
-		lTrf.getRotation().rotateZAxis(angDegrees);
-	}
-	void moveLocalX(float distance)
-	{
-		Vec3 x_axis = lTrf.getRotation().getColumn(0);
-		lTrf.getOrigin() += x_axis * distance;
-	}
-	void moveLocalY(float distance)
-	{
-		Vec3 y_axis = lTrf.getRotation().getColumn(1);
-		lTrf.getOrigin() += y_axis * distance;
-	}
-	void moveLocalZ(float distance)
-	{
-		Vec3 z_axis = lTrf.getRotation().getColumn(2);
-		lTrf.getOrigin() += z_axis * distance;
-	}
-	/// @}
-
-	/// This update happens only when the object gets moved. Called only by
-	/// the Scene
-	void updateWorldTransform();
-
 private:
 private:
 	std::string name; ///< A unique name
 	std::string name; ///< A unique name
-
-	Transform lTrf; ///< The transformation in local space
-
-	/// The transformation in world space (local combined with parent's
-	/// transformation)
-	Transform wTrf;
-
-	/// Keep the previous transformation for blurring calculations
-	Transform prevWTrf;
-
-	ulong flags; ///< The state flags
-
 	Scene* scene; ///< For registering and unregistering
 	Scene* scene; ///< For registering and unregistering
 };
 };
 /// @}
 /// @}

+ 43 - 0
anki/scene/Spartial.h

@@ -0,0 +1,43 @@
+#ifndef ANKI_SCENE_SPARTIAL_H
+#define ANKI_SCENE_SPARTIAL_H
+
+#include "anki/collision/Collision.h"
+
+
+namespace anki {
+
+
+/// @addtogroup Scene
+/// @{
+
+/// Spartial "interface" for scene nodes
+///
+/// It indicates scene nodes that need to be placed in the scene's octree and
+/// they participate in the visibility tests
+class Spartial
+{
+public:
+	/// Pass the collision shape here so we can avoid the virtuals
+	Spartial(CollisionShape* x)
+		: cs(fr)
+	{}
+
+	const CollisionShape& getCollisionShape() const
+	{
+		return *cs;
+	}
+	CollisionShape& getCollisionShape()
+	{
+		return *cs;
+	}
+
+private:
+	CollisionShape* cs;
+};
+/// @}
+
+
+} // namespace anki
+
+
+#endif