Panagiotis Christopoulos Charitos 14 лет назад
Родитель
Сommit
eeac6a736c

+ 2 - 4
anki/collision/CollisionShape.h

@@ -28,9 +28,8 @@ public:
 	};
 
 	/// Generic mutable visitor
-	class MutableVisitor
+	struct MutableVisitor
 	{
-	public:
 		virtual void visit(LineSegment&) = 0;
 		virtual void visit(Obb&) = 0;
 		virtual void visit(Frustum&) = 0;
@@ -41,9 +40,8 @@ public:
 	};
 
 	/// Generic const visitor
-	class ConstVisitor
+	struct ConstVisitor
 	{
-	public:
 		virtual void visit(const LineSegment&) = 0;
 		virtual void visit(const Obb&) = 0;
 		virtual void visit(const Frustum&) = 0;

+ 30 - 3
anki/collision/Frustum.h

@@ -40,9 +40,20 @@ public:
 		FP_COUNT ///< Number of planes
 	};
 
+	/// @name Constructors
+	/// @{
 	Frustum(FrustumType type_)
 		: CollisionShape(CST_FRUSTUM), type(type_)
 	{}
+	/// @}
+
+	/// @name Accessors
+	/// @{
+	FrustumType getFrustumType() const
+	{
+		return type;
+	}
+	/// @}
 
 	/// Copy
 	Frustum& operator=(const Frustum& b);
@@ -61,14 +72,16 @@ public:
 		v.visit(*this);
 	}
 
-	/// Check if a collision shape is inside the frustum
+	/// Check if a collision shape @a b is inside the frustum
 	bool insideFrustum(const CollisionShape& b) const;
 
 	/// Calculate the projection matrix
 	virtual Mat4 calculateProjectionMatrix() const = 0;
 
 protected:
-	boost::array<Plane, FP_COUNT> planes; ///< Used to check frustum
+	/// Used to check against the frustum
+	boost::array<Plane, FP_COUNT> planes;
+
 	/// @name Viewing variables
 	/// @{
 	float zNear;
@@ -157,10 +170,17 @@ public:
 	Mat4 calculateProjectionMatrix() const;
 
 private:
+	/// @name Shape
+	/// @{
 	Vec3 eye; ///< The eye point
 	boost::array<Vec3, 4> dirs; ///< Directions
+	/// @}
+
+	/// @name Viewing variables
+	/// @{
 	float fovX;
 	float fovY;
+	/// @}
 
 	/// Implements CollisionShape::recalculate. Recalculate @a planes, @a eye
 	/// and @a dirs
@@ -265,8 +285,15 @@ public:
 	Mat4 calculateProjectionMatrix() const;
 
 private:
-	Obb obb; ///< Incluring shape
+	/// @name Shape
+	/// @{
+	Obb obb; ///< Including shape
+	/// @}
+
+	/// @name Viewing variables
+	/// @{
 	float left, right, top, bottom;
+	/// @}
 
 	/// Implements CollisionShape::recalculate. Recalculate @a planes and
 	/// @a obb

+ 2 - 0
anki/math/Transform.h

@@ -43,6 +43,8 @@ public:
 	/// @name Operators with same type
 	/// @{
 	Transform& operator=(const Transform& b);
+	bool operator==(const Transform& b) const;
+	bool operator!=(const Transform& b) const;
 	/// @}
 
 	/// @name Other

+ 14 - 0
anki/math/Transform.inl.h

@@ -107,6 +107,20 @@ inline Transform& Transform::operator=(const Transform& b)
 }
 
 
+// ==
+inline bool Transform::operator==(const Transform& b) const
+{
+	return origin == b.origin && rotation == b.rotation && scale == b.scale;
+}
+
+
+// !=
+inline bool Transform::operator!=(const Transform& b) const
+{
+	return !operator==(b);
+}
+
+
 //==============================================================================
 // Other                                                                       =
 //==============================================================================

+ 45 - 0
anki/scene/Frustumable.h

@@ -0,0 +1,45 @@
+#ifndef ANKI_SCENE_FRUSTUMABLE_H
+#define ANKI_SCENE_FRUSTUMABLE_H
+
+#include "anki/collision/Frustum.h"
+
+
+namespace anki {
+
+
+/// @addtogroup Scene
+/// @{
+
+/// Frustumable "interface" for scene nodes
+class Frustumable
+{
+public:
+	/// Pass the frustum here so we can avoid the virtuals
+	Frustumable(Frustum* fr)
+		: frustum(fr)
+	{}
+
+	const Frustum& getFrustum() const
+	{
+		return *frustum;
+	}
+	Frustum& getFrustum()
+	{
+		return *frustum;
+	}
+
+	bool insideFrustum(const CollisionShape& cs) const
+	{
+		return frustum->insideFrustum(cs);
+	}
+
+private:
+	Frustum* frustum;
+};
+/// @}
+
+
+} // namespace anki
+
+
+#endif

+ 33 - 0
anki/scene/Movable.cpp

@@ -0,0 +1,33 @@
+#include "anki/scene/Movable.h"
+
+
+namespace anki {
+
+
+//==============================================================================
+void Movable::updateWorldTransform()
+{
+	prevWTrf = wTrf;
+
+	if(getParent())
+	{
+		if(isFlagEnabled(MF_IGNORE_LOCAL_TRANSFORM))
+		{
+			wTrf = getParent()->getWorldTransform();
+		}
+		else
+		{
+			wTrf = Transform::combineTransformations(
+				getParent()->getWorldTransform(), lTrf);
+		}
+	}
+	else // else copy
+	{
+		wTrf = lTrf;
+	}
+
+	enableFlag(MF_MOVED, prevWTrf != wTrf);
+}
+
+
+} // namespace anki

+ 144 - 0
anki/scene/Movable.h

@@ -0,0 +1,144 @@
+#ifndef ANKI_SCENE_MOVABLE_H
+#define ANKI_SCENE_MOVABLE_H
+
+#include "anki/util/Object.h"
+#include "anki/math/Math.h"
+
+
+namespace anki {
+
+
+/// @addtogroup Scene
+/// @{
+
+/// Interface for movable scene nodes
+class Movable: public Object<Movable>
+{
+public:
+	typedef Object<Movable> Base;
+
+	enum MovableFlag
+	{
+		MF_NONE = 0,
+		MF_IGNORE_LOCAL_TRANSFORM = 1, ///< Get the parent's world transform
+		MF_MOVED = 2 ///< Moved in the previous frame
+	};
+
+	/// @name Constructors
+	/// @{
+
+	/// The one and only constructor
+	/// @param flags_ The flags
+	/// @param parent The parent. It can be nullptr
+	Movable(uint flags_, Movable* parent)
+		: Base(this, parent), flags(flags_)
+	{}
+	/// @}
+
+	/// @name Accessors
+	/// @{
+	const Transform& getLocalTransform() const
+	{
+		return lTrf;
+	}
+	Transform& getLocalTransform()
+	{
+		return lTrf;
+	}
+	void setLocalTransform(const Transform& x)
+	{
+		lTrf = x;
+	}
+
+	const Transform& getWorldTransform() const
+	{
+		return wTrf;
+	}
+
+	const Transform& getPrevWorldTransform() const
+	{
+		return prevWTrf;
+	}
+
+	ulong getFlags() const
+	{
+		return flags;
+	}
+	/// @}
+
+	/// @name Flag manipulation
+	/// @{
+	void enableFlag(MovableFlag flag, bool enable = true)
+	{
+		flags = enable ? flags | flag : flags & ~flag;
+	}
+	void disableFlag(MovableFlag flag)
+	{
+		enableFlag(flag, false);
+	}
+	bool isFlagEnabled(MovableFlag flag) const
+	{
+		return flags & flag;
+	}
+	/// @}
+
+	/// @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 always. It updates the MF_MOVED flag
+	void updateWorldTransform();
+
+	/// This is called after the updateWorldTransform() and if the MF_MOVED is
+	/// true
+	virtual void moveUpdate()
+	{
+		ANKI_ASSERT(isFlagEnabled(MF_MOVED));
+	}
+
+protected:
+	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
+};
+/// @}
+
+
+} // end namespace
+
+
+#endif

+ 7 - 1
anki/scene/Renderable.h

@@ -11,7 +11,12 @@ class Vao;
 class Transform;
 
 
-/// XXX
+/// @addtogroup Scene
+/// @{
+
+/// Renderable interface
+///
+/// Implemented by renderable scene nodes
 class Renderable
 {
 public:
@@ -31,6 +36,7 @@ public:
 	virtual const Transform& getPreviousWorldTransform(
 		const PassLevelKey& k) = 0;
 };
+/// @}
 
 
 } // end namespace