浏览代码

- Doc updates
- Scene work

Panagiotis Christopoulos Charitos 14 年之前
父节点
当前提交
9c688c0d0b

+ 12 - 1
anki/collision/CollisionShape.h

@@ -11,7 +11,8 @@ namespace anki {
 /// @addtogroup Collision
 /// @{
 
-/// Abstract class for collision shapes
+/// Abstract class for collision shapes. It also features a visitor for
+/// implementing specific code outside the collision codebase (eg rendering)
 class CollisionShape
 {
 public:
@@ -52,14 +53,20 @@ public:
 	};
 
 
+	/// @name Constructors & destructor
+	/// @{
 	CollisionShape(CollisionShapeType cid_)
 		: cid(cid_)
 	{}
+	/// @}
 
+	/// @name Accessors
+	/// @{
 	CollisionShapeType getCollisionShapeType() const
 	{
 		return cid;
 	}
+	/// @}
 
 	/// If the collision shape intersects with the plane then the method
 	/// returns 0.0, else it returns the distance. If the distance is < 0.0
@@ -73,10 +80,14 @@ public:
 	/// Get the AABB
 	virtual void getAabb(Aabb&) const = 0;
 
+	/// Visitor accept
 	virtual void accept(MutableVisitor&) = 0;
+	/// Visitor accept
 	virtual void accept(ConstVisitor&) const = 0;
 
 private:
+	/// Keep an ID to avoid (in some cases) the visitor and thus the cost of
+	/// virtuals
 	CollisionShapeType cid;
 };
 /// @}

+ 0 - 47
anki/scene/Frustumable.h

@@ -70,53 +70,6 @@ protected:
 };
 
 
-/// XXX
-/*class PerspectiveFrustumable: public Frustumable
-{
-public:
-	/// @name Constructors
-	/// @{
-	PerspectiveFrustumable(PerspectiveFrustum* fr)
-		: Frustumable(fr)
-	{}
-	/// @}
-
-	/// @name Accessors
-	/// @{
-	float getFovX() const
-	{
-		return toPerpectiveFrustum()->getFovX();
-	}
-	void setFovX(float ang)
-	{
-		toPerpectiveFrustum()->setFovX(ang);
-		frustumUpdate();
-	}
-
-	float getFovY() const
-	{
-		return toPerpectiveFrustum()->getFovY();
-	}
-	void setFovY(float ang)
-	{
-		toPerpectiveFrustum()->setFovY(ang);
-		frustumUpdate();
-	}
-	/// @}
-
-private:
-	PerspectiveFrustum* toPerpectiveFrustum()
-	{
-		return static_cast<PerspectiveFrustum*>(frustum);
-	}
-	const PerspectiveFrustum* toPerpectiveFrustum() const
-	{
-		return static_cast<const PerspectiveFrustum*>(frustum);
-	}
-};*/
-/// @}
-
-
 } // namespace anki
 
 

+ 6 - 1
anki/scene/Light.h

@@ -87,13 +87,18 @@ public:
 	const ModelPatchBase& getModelPatchBase() const
 	{
 		ANKI_ASSERT(0 && "Lights don't support it");
-		throw "";
+		throw ""; // Make the compiler not to complain about return val
 	}
 
 	Material& getMaterial()
 	{
 		return *mtl;
 	}
+
+	Light* getLight()
+	{
+		return this;
+	}
 	/// @}
 
 private:

+ 0 - 106
anki/scene/MaterialRuntime.cpp

@@ -1,106 +0,0 @@
-#include "anki/scene/MaterialRuntime.h"
-#include "anki/resource/Material.h"
-#include "anki/resource/Texture.h"
-#include "anki/resource/Resource.h"
-#include "anki/resource/ShaderProgram.h"
-#include <boost/foreach.hpp>
-
-
-namespace anki {
-
-
-//==============================================================================
-// MaterialRuntimeVariable                                                     =
-//==============================================================================
-
-//==============================================================================
-MaterialRuntimeVariable::MaterialRuntimeVariable(const MaterialVariable& mv)
-	: mvar(mv), buildinId(-1)
-{}
-
-
-//==============================================================================
-MaterialRuntimeVariable::~MaterialRuntimeVariable()
-{}
-
-
-//==============================================================================
-const MaterialRuntimeVariable::Variant&
-	MaterialRuntimeVariable::getVariantConst() const
-{
-	return copyVariant ? *copyVariant : mvar.getVariant();
-}
-
-
-//==============================================================================
-MaterialRuntimeVariable::Variant& MaterialRuntimeVariable::getVariantMutable()
-{
-	if(copyVariant.get() == NULL)
-	{
-		copyVariant.reset(new Variant(mvar.getVariant()));
-	}
-
-	return *copyVariant;
-}
-
-
-//==============================================================================
-// MaterialRuntime                                                             =
-//==============================================================================
-
-//==============================================================================
-MaterialRuntime::MaterialRuntime(const Material& mtl_)
-	: mtl(mtl_)
-{
-	// Copy props
-	MaterialProperties& me = *this;
-	const MaterialProperties& he = mtl.getBaseClass();
-	me = he;
-
-	// Create vars
-	Material::VarsContainer::const_iterator it = mtl.getVariables().begin();
-	for(; it != mtl.getVariables().end(); ++it)
-	{
-		const MaterialVariable& var = *it;
-
-		MaterialRuntimeVariable* varr = new MaterialRuntimeVariable(var);
-		vars.push_back(varr);
-		varNameToVar[varr->getMaterialVariable().getName().c_str()] = varr;
-	}
-}
-
-
-//==============================================================================
-MaterialRuntime::~MaterialRuntime()
-{}
-
-
-//==============================================================================
-MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
-	const char* name)
-{
-	VariablesHashMap::iterator it = varNameToVar.find(name);
-	if(it == varNameToVar.end())
-	{
-		throw ANKI_EXCEPTION("Cannot get material runtime variable "
-			"with name \"" + name + '\"');
-	}
-	return *(it->second);
-}
-
-
-//==============================================================================
-const MaterialRuntimeVariable& MaterialRuntime::findVariableByName(
-	const char* name) const
-{
-	VariablesHashMap::const_iterator it = varNameToVar.find(name);
-	if(it == varNameToVar.end())
-	{
-		throw ANKI_EXCEPTION("Cannot get material runtime variable "
-			"with name \"" + name + '\"');
-	}
-	return *(it->second);
-}
-
-
-} // end namespace

+ 0 - 234
anki/scene/MaterialRuntime.h

@@ -1,234 +0,0 @@
-#ifndef ANKI_SCENE_MATERIAL_RUNTIME_H
-#define ANKI_SCENE_MATERIAL_RUNTIME_H
-
-#include "anki/resource/Material.h"
-#include "anki/util/ConstCharPtrHashMap.h"
-#include "anki/resource/Resource.h"
-#include "anki/math/Math.h"
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/variant.hpp>
-
-
-namespace anki {
-
-
-class Texture;
-class MaterialVariable;
-
-
-/// Variable of runtime materials
-///
-/// This holds a copy of the MaterialVariable's data in order to be read write
-/// inside the main loop
-class MaterialRuntimeVariable
-{
-public:
-	/// The data union. The Texture resource is read-only at runtime
-	/// Don't EVER replace the texture with const Texture*. The asynchronous
-	/// operations will fail
-	typedef MaterialVariable::Variant Variant;
-
-	/// Constructor. Initialize using a material variable
-	MaterialRuntimeVariable(const MaterialVariable& mv);
-
-	/// Destructor
-	~MaterialRuntimeVariable();
-
-	/// @name Accessors
-	/// @{
-	const MaterialVariable& getMaterialVariable() const
-	{
-		return mvar;
-	}
-
-	const Variant& getVariant() const
-	{
-		return getVariantConst();
-	}
-	Variant& getVariant()
-	{
-		return getVariantMutable();
-	}
-
-	/// Get the value of the variant
-	/// @exception boost::exception when you try to get the incorrect data
-	/// type
-	template<typename Type>
-	const Type& getValue() const
-	{
-		return boost::get<Type>(getVariantConst());
-	}
-
-	/// @copydoc getValue
-	template<typename Type>
-	Type& getValue()
-	{
-		return boost::get<Type>(getVariantMutable());
-	}
-
-	template<typename Type>
-	void setValue(const Type& v)
-	{
-		boost::get<Type>(getVariantMutable()) = v;
-	}
-
-	int getBuildinId() const
-	{
-		return buildinId;
-	}
-	int& getBuildinId()
-	{
-		return buildinId;
-	}
-	void setBuildinId(const int x)
-	{
-		buildinId = x;
-	}
-	/// @}
-
-private:
-	const MaterialVariable& mvar; ///< Know the resource
-	boost::scoped_ptr<Variant> copyVariant; /// The copy of the data
-	int buildinId; ///< -1 is "dont know yet"
-
-	/// Return either the mvar's variant or your own if exists
-	const Variant& getVariantConst() const;
-
-	/// Implement the COW technique. If someone asks the variant for writing
-	/// then create a copy
-	Variant& getVariantMutable();
-};
-
-
-/// One layer above the material resource
-class MaterialRuntime: public MaterialProperties
-{
-	public:
-		/// A type
-		typedef boost::ptr_vector<MaterialRuntimeVariable>
-			VariablesContainer;
-
-		typedef boost::iterator_range<VariablesContainer::const_iterator>
-			ConstIteratorRange;
-		typedef boost::iterator_range<VariablesContainer::iterator>
-			MutableIteratorRange;
-
-		typedef ConstCharPtrHashMap<MaterialRuntimeVariable*>::Type
-			VariablesHashMap;
-
-		/// @name Constructors & destructor
-		/// @{
-		MaterialRuntime(const Material& mtl);
-		~MaterialRuntime();
-		/// @}
-
-		/// @name Accessors
-		/// @{
-		bool getShadow() const
-		{
-			return shadow;
-		}
-		bool& getShadow()
-		{
-			return shadow;
-		}
-		void setShadow(bool x)
-		{
-			shadow = x;
-		}
-
-		int getBlendingSFactor() const
-		{
-			return blendingSfactor;
-		}
-		int& getBlendingSFactor()
-		{
-			return blendingSfactor;
-		}
-		void setBlendingSFactor(int x)
-		{
-			blendingSfactor = x;
-		}
-
-		int getBlendingDFactor() const
-		{
-			return blendingDfactor;
-		}
-		int& getBlendingDFactor()
-		{
-			return blendingDfactor;
-		}
-		void setBlendingDFactor(int x)
-		{
-			blendingDfactor = x;
-		}
-
-		bool getDepthTesting() const
-		{
-			return depthTesting;
-		}
-		bool& getDepthTesting()
-		{
-			return depthTesting;
-		}
-		void setDepthTesting(bool x)
-		{
-			depthTesting = x;
-		}
-
-		bool getWireframe() const
-		{
-			return wireframe;
-		}
-		bool& getWireframe()
-		{
-			return wireframe;
-		}
-		void setWireframe(bool x)
-		{
-			wireframe = x;
-		}
-
-		ConstIteratorRange getVariables() const
-		{
-			return ConstIteratorRange(vars.begin(), vars.end());
-		}
-		MutableIteratorRange getVariables()
-		{
-			return MutableIteratorRange(vars.begin(), vars.end());
-		}
-
-		const Material& getMaterial() const
-		{
-			return mtl;
-		}
-		/// @}
-
-		/// Find a material runtime variable. On failure it throws an exception
-		/// @param[in] name The name of the var
-		/// @return It returns a MaterialRuntimeUserDefinedVar
-		/// @exception Exception
-		MaterialRuntimeVariable& findVariableByName(const char* name);
-
-		/// The const version of getUserDefinedVarByName
-		/// @see getUserDefinedVarByName
-		const MaterialRuntimeVariable& findVariableByName(
-			const char* name) const;
-
-		bool variableExists(const char* name) const
-		{
-			return varNameToVar.find(name) != varNameToVar.end();
-		}
-
-	private:
-		const Material& mtl; ///< The resource
-		VariablesContainer vars;
-		VariablesHashMap varNameToVar;
-};
-
-
-} // end namespace
-
-
-#endif

+ 1 - 1
anki/scene/Movable.cpp

@@ -8,7 +8,7 @@ namespace anki {
 
 //==============================================================================
 Movable::Movable(uint flags_, Movable* parent, PropertyMap& pmap)
-	: Base(this, parent), shouldUpdateWTrf(true), flags(flags_)
+	: Base(this, parent), flags(flags_)
 {
 	pmap.addNewProperty(
 		new ReadWritePointerProperty<Transform>("localTransform", &lTrf));

+ 3 - 15
anki/scene/Movable.h

@@ -31,10 +31,10 @@ public:
 	/// @{
 
 	/// The one and only constructor
-	/// @param flags_ The flags
+	/// @param flags The flags
 	/// @param parent The parent. It can be nullptr
 	/// @param pmap Property map to add a few variables
-	Movable(uint flags_, Movable* parent, PropertyMap& pmap);
+	Movable(uint flags, Movable* parent, PropertyMap& pmap);
 	/// @}
 
 	/// @name Accessors
@@ -46,22 +46,18 @@ public:
 	void setLocalTransform(const Transform& x)
 	{
 		lTrf = x;
-		shouldUpdateWTrf = true;
 	}
 	void setLocalTranslation(const Vec3& x)
 	{
 		lTrf.setOrigin(x);
-		shouldUpdateWTrf = true;
 	}
 	void setLocalRotation(const Mat3& x)
 	{
 		lTrf.setRotation(x);
-		shouldUpdateWTrf = true;
 	}
 	void setLocalScale(float x)
 	{
 		lTrf.setScale(x);
-		shouldUpdateWTrf = true;
 	}
 
 	const Transform& getWorldTransform() const
@@ -105,40 +101,34 @@ public:
 	void rotateLocalX(float angDegrees)
 	{
 		lTrf.getRotation().rotateXAxis(angDegrees);
-		shouldUpdateWTrf = true;
 	}
 	void rotateLocalY(float angDegrees)
 	{
 		lTrf.getRotation().rotateYAxis(angDegrees);
-		shouldUpdateWTrf = true;
 	}
 	void rotateLocalZ(float angDegrees)
 	{
 		lTrf.getRotation().rotateZAxis(angDegrees);
-		shouldUpdateWTrf = true;
 	}
 	void moveLocalX(float distance)
 	{
 		Vec3 x_axis = lTrf.getRotation().getColumn(0);
 		lTrf.getOrigin() += x_axis * distance;
-		shouldUpdateWTrf = true;
 	}
 	void moveLocalY(float distance)
 	{
 		Vec3 y_axis = lTrf.getRotation().getColumn(1);
 		lTrf.getOrigin() += y_axis * distance;
-		shouldUpdateWTrf = true;
 	}
 	void moveLocalZ(float distance)
 	{
 		Vec3 z_axis = lTrf.getRotation().getColumn(2);
 		lTrf.getOrigin() += z_axis * distance;
-		shouldUpdateWTrf = true;
 	}
 	/// @}
 
 	/// This is called by the @a update() method only when the object had
-	/// actually moved
+	/// actually moved. It's overridable
 	virtual void movableUpdate()
 	{}
 
@@ -150,8 +140,6 @@ public:
 	void update();
 
 protected:
-	bool shouldUpdateWTrf; ///< Its true when we change the local transform
-
 	Transform lTrf; ///< The transformation in local space
 
 	/// The transformation in world space (local combined with parent's

+ 5 - 0
anki/scene/Renderable.h

@@ -73,6 +73,11 @@ public:
 	/// Access the material
 	virtual const Material& getMaterial() const = 0;
 
+	virtual Light* getLight()
+	{
+		return nullptr;
+	}
+
 	MutableRange getProperties()
 	{
 		return MutableRange(props.begin(), props.end());

+ 17 - 24
anki/scene/Scene.h

@@ -2,6 +2,7 @@
 #define ANKI_SCENE_SCENE_H
 
 #include "anki/scene/SceneNode.h"
+#include "anki/scene/VisibilityTester.h"
 #include "anki/math/Math.h"
 #include <boost/range/iterator_range.hpp>
 #include <vector>
@@ -33,17 +34,6 @@ public:
 	~Scene();
 	/// @}
 
-	/// Put a node in the appropriate containers
-	void registerNode(SceneNode* node);
-	void unregisterNode(SceneNode* node);
-
-	void update(float prevUpdateTime, float crntTime, int frame);
-
-	/*void doVisibilityTests(Camera& cam)
-	{
-		//XXX visibilityTester->test(cam);
-	}*/
-
 	/// @name Accessors
 	/// @{
 	const Vec3& getAmbientColor() const
@@ -69,21 +59,24 @@ public:
 	}
 	/// @}
 
+	/// Put a node in the appropriate containers
+	void registerNode(SceneNode* node);
+	void unregisterNode(SceneNode* node);
+
+	void update(float prevUpdateTime, float crntTime, int frame);
+
+	/*void doVisibilityTests(Camera& cam)
+	{
+		//XXX visibilityTester->test(cam);
+	}*/
+
 private:
-	/// @name Containers of scene's data
-	/// @{
 	Types<SceneNode>::Container nodes;
-	/*Types<Movable>::Container movables;
-	Types<Renderable>::Container renderables;
-	Types<Spatial>::Container spatials;
-	Types<Frustumable>::Container frustumables;*/
-	/// @}
-
 	Types<SceneNode>::NameToItemMap nameToNode;
-
 	Vec3 ambientCol; ///< The global ambient color
+	Camera* mainCam;
 
-	/// XXX
+	/// Add to a container
 	template<typename T>
 	void addC(typename Types<T>::Container& c, T* ptr)
 	{
@@ -91,7 +84,7 @@ private:
 		c.push_back(ptr);
 	}
 
-	/// XXX
+	/// Add to a dictionary
 	template<typename T>
 	void addDict(typename Types<T>::NameToItemMap& d, T* ptr)
 	{
@@ -103,7 +96,7 @@ private:
 		d[ptr->getName().c_str()] = ptr;
 	}
 
-	/// XXX
+	/// Remove from a container
 	template<typename T>
 	void removeC(typename Types<T>::Container& c, T* ptr)
 	{
@@ -120,7 +113,7 @@ private:
 		c.erase(it);
 	}
 
-	/// XXX
+	/// Remove from a dictionary
 	template<typename T>
 	void removeDict(typename Types<T>::NameToItemMap& d, T* ptr)
 	{

+ 0 - 22
anki/scene/Scene.inl.h

@@ -1,22 +0,0 @@
-namespace anki {
-
-
-template<typename ContainerType, typename Type>
-inline void Scene::putBackNode(ContainerType& container, Type* x)
-{
-	ANKI_ASSERT(std::find(container.begin(), container.end(), x) == container.end());
-	container.push_back(x);
-}
-
-
-template<typename ContainerType, typename Type>
-inline void Scene::eraseNode(ContainerType& container, Type* x)
-{
-	typename ContainerType::iterator it =
-		std::find(container.begin(), container.end(), x);
-	ANKI_ASSERT(it != container.end());
-	container.erase(it);
-}
-
-
-} // end namespace

+ 2 - 12
anki/scene/VisibilityTester.cpp

@@ -19,10 +19,9 @@ void VisibilityTester::test(Frustumable& cam, Scene& scene,
 	for(SceneNode* node : scene.getAllNodes())
 	{
 		Renderable* r = node->getRenderable();
-		Frustumable* fr = node->getFrustumable();
 		Spatial* sp = node->getSpatial();
 
-		if(!sp || (!fr && !r))
+		if(!sp || !r)
 		{
 			continue;
 		}
@@ -32,21 +31,12 @@ void VisibilityTester::test(Frustumable& cam, Scene& scene,
 			continue;
 		}
 
-
-		VisibilityInfo::Pair p = {nullptr, nullptr};
-
-		if(fr)
-		{
-			p.frustumable = fr;
-		}
-
 		if(r)
 		{
 			r->enableFlag(Renderable::RF_VISIBLE);
-			p.renderable = r;
 		}
 
-		vinfo.pairs.push_back(p);
+		vinfo.renderables.push_back(r);
 	}
 }
 

+ 5 - 11
anki/scene/VisibilityTester.h

@@ -20,22 +20,16 @@ class VisibilityInfo
 	friend class VisibilityTester;
 
 public:
-	struct Pair
-	{
-		Renderable* renderable;
-		Frustumable* frustumable;
-	};
-
-	typedef std::vector<Pair> Pairs;
+	typedef std::vector<Renderable*> Renderables;
 
-	boost::iterator_range<Pairs::iterator> getPairs()
+	boost::iterator_range<Renderables::iterator> getRenderables()
 	{
-		return boost::iterator_range<Pairs::iterator>(
-			pairs.begin(), pairs.end());
+		return boost::iterator_range<Renderables::iterator>(
+			renderables.begin(), renderables.end());
 	}
 
 private:
-	Pairs pairs;
+	Renderables renderables;
 };