Selaa lähdekoodia

Controllers and visibility changes

Panagiotis Christopoulos Charitos 15 vuotta sitten
vanhempi
sitoutus
df6f28eb53

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 1
build/debug/Makefile


+ 4 - 2
src/Core/Object.cpp

@@ -1,4 +1,6 @@
 #include <algorithm>
+#include <boost/foreach.hpp>
+
 #include "Object.h"
 #include "Assert.h"
 #include "Exception.h"
@@ -28,9 +30,9 @@ Object::~Object()
 	}
 
 	// delete all children
-	for(Container::reverse_iterator it=objChilds.rbegin(); it!=objChilds.rend(); it++)
+	BOOST_REVERSE_FOREACH(Object* child, objChilds)
 	{
-		delete *it;
+		delete child;
 	}
 }
 

+ 1 - 1
src/Core/Object.h

@@ -28,7 +28,7 @@ class Object
 		/// @}
 
 	private:
-		Object* objParent;
+		Object* objParent; ///< May be nullptr
 		Container objChilds;
 
 		void addChild(Object* child);

+ 2 - 2
src/Main.cpp

@@ -18,7 +18,7 @@
 #include "skybox.h"
 #include "map.h"
 #include "SkelAnim.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "Parser.h"
 #include "ParticleEmitter.h"
 #include "PhyCharacter.h"
@@ -328,8 +328,8 @@ void mainLoop()
 		AppSingleton::getInstance().execStdinScpripts();
 		SceneSingleton::getInstance().getPhysics().update(timer.getCrntTime());
 		SceneSingleton::getInstance().updateAllWorldStuff();
-		SceneSingleton::getInstance().updateAllControllers();
 		SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
+		SceneSingleton::getInstance().updateAllControllers();
 
 		MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());
 

+ 11 - 9
src/Renderer/Is.cpp

@@ -1,14 +1,16 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
+#include <boost/array.hpp>
+
 #include "Is.h"
 #include "Renderer.h"
 #include "Camera.h"
 #include "Light.h"
 #include "PointLight.h"
 #include "SpotLight.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "App.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "Sm.h"
 #include "Smo.h"
 #include "Scene.h"
@@ -29,18 +31,18 @@ Is::Is(Renderer& r_):
 //======================================================================================================================
 void Is::calcViewVectors()
 {
-	Vec3 viewVectors[4];
+	boost::array<Vec3, 4> viewVectors;
 
 	const Camera& cam = r.getCamera();
 
-	const uint& w = r.getWidth();
-	const uint& h = r.getHeight();
+	uint w = r.getWidth();
+	uint h = r.getHeight();
 
 	// From right up and CC wise to right down, Just like we render the quad
-	uint pixels[4][2]={{w, h}, {0, h}, {0, 0}, {w, 0}};
-	uint viewport[4]={0, 0, w, h};
+	uint pixels[4][2] = {{w, h}, {0, h}, {0, 0}, {w, 0}};
+	boost::array<uint, 4> viewport = {{0, 0, w, h}};
 
-	for(int i=0; i<4; i++)
+	for(int i = 0; i < 4; i++)
 	{
 		/*
 		Original Code:
@@ -60,7 +62,7 @@ void Is::calcViewVectors()
 	}
 
 	ASSERT(sizeof(viewVectors) == viewVectorsVbo.getSizeInBytes());
-	viewVectorsVbo.write(viewVectors);
+	viewVectorsVbo.write(&viewVectors[0]);
 }
 
 

+ 1 - 1
src/Renderer/Sm.cpp

@@ -3,7 +3,7 @@
 #include "Renderer.h"
 #include "App.h"
 #include "Scene.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "Camera.h"
 #include "RendererInitializer.h"
 

+ 1 - 1
src/Renderer/Smo.cpp

@@ -1,7 +1,7 @@
 #include "Smo.h"
 #include "Renderer.h"
 #include "Light.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "PointLight.h"
 #include "SpotLight.h"
 #include "Camera.h"

+ 2 - 2
src/Resources/Core/ResourceManager.cpp

@@ -6,7 +6,7 @@
 #include "Mesh.h"
 #include "Skeleton.h"
 #include "SkelAnim.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "ParticleEmitterProps.h"
 #include "Script.h"
 #include "Model.h"
@@ -39,7 +39,7 @@ SPECIALIZE_TEMPLATE_STUFF(Material, materials)
 SPECIALIZE_TEMPLATE_STUFF(Mesh, meshes)
 SPECIALIZE_TEMPLATE_STUFF(Skeleton, skeletons)
 SPECIALIZE_TEMPLATE_STUFF(SkelAnim, skelAnims)
-SPECIALIZE_TEMPLATE_STUFF(LightData, lightProps)
+SPECIALIZE_TEMPLATE_STUFF(LightRsrc, lightProps)
 SPECIALIZE_TEMPLATE_STUFF(ParticleEmitterProps, particleEmitterProps)
 SPECIALIZE_TEMPLATE_STUFF(Script, scripts)
 SPECIALIZE_TEMPLATE_STUFF(Model, models)

+ 2 - 2
src/Resources/Core/ResourceManager.h

@@ -17,7 +17,7 @@ class Material;
 class Mesh;
 class Skeleton;
 class SkelAnim;
-class LightData;
+class LightRsrc;
 class ParticleEmitterProps;
 class Script;
 class Model;
@@ -64,7 +64,7 @@ class ResourceManager
 		Types<Mesh>::Container meshes;
 		Types<Skeleton>::Container skeletons;
 		Types<SkelAnim>::Container skelAnims;
-		Types<LightData>::Container lightProps;
+		Types<LightRsrc>::Container lightProps;
 		Types<ParticleEmitterProps>::Container particleEmitterProps;
 		Types<Script>::Container scripts;
 		Types<Model>::Container models;

+ 3 - 3
src/Resources/LightData.cpp → src/Resources/LightRsrc.cpp

@@ -1,5 +1,5 @@
 #include <cstring>
-#include "LightData.h"
+#include "LightRsrc.h"
 #include "Parser.h"
 #include "Texture.h"
 
@@ -7,7 +7,7 @@
 //======================================================================================================================
 // Constructor                                                                                                         =
 //======================================================================================================================
-LightData::LightData():
+LightRsrc::LightRsrc():
 	diffuseCol(0.5),
 	specularCol(0.5),
 	castsShadow_(false),
@@ -21,7 +21,7 @@ LightData::LightData():
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-void LightData::load(const char* filename)
+void LightRsrc::load(const char* filename)
 {
 	Scanner scanner(filename);
 	const Scanner::Token* token;

+ 4 - 4
src/Resources/LightData.h → src/Resources/LightRsrc.h

@@ -8,7 +8,7 @@
 
 
 /// Light properties Resource
-class LightData
+class LightRsrc
 {
 	public:
 		enum LightType
@@ -39,8 +39,8 @@ class LightData
 	/// @}
 		
 	public:
-		LightData();
-		~LightData() {}
+		LightRsrc();
+		~LightRsrc() {}
 		void load(const char* filename);
 		const Texture& getTexture() const;
 
@@ -52,7 +52,7 @@ class LightData
 };
 
 
-inline const Texture& LightData::getTexture() const
+inline const Texture& LightRsrc::getTexture() const
 {
 	ASSERT(texture.get() != NULL);
 	return *texture;

+ 2 - 2
src/Scene/Camera.cpp

@@ -183,9 +183,9 @@ void Camera::updateViewMatrix()
 
 
 //======================================================================================================================
-// updateTrf                                                                                                           =
+// moveUpdate                                                                                                          =
 //======================================================================================================================
-void Camera::updateTrf()
+void Camera::moveUpdate()
 {
 	updateViewMatrix();
 	updateWSpaceFrustumPlanes();

+ 4 - 1
src/Scene/Camera.h

@@ -58,7 +58,10 @@ class Camera: public SceneNode
 		/// This does:
 		/// - Update view matrix
 		/// - Update frustum planes
-		void updateTrf();
+		void moveUpdate();
+
+		/// Do nothing
+		void frameUpdate() {}
 
 		/// Do nothing
 		void init(const char*) {}

+ 3 - 2
src/Scene/Controllers/Controller.cpp

@@ -6,8 +6,9 @@
 //======================================================================================================================
 // Constructor                                                                                                         =
 //======================================================================================================================
-Controller::Controller(ControllerType type_):
-	type(type_) 
+Controller::Controller(ControllerType type_, SceneNode& node):
+	controlledNode(node),
+	type(type_)
 {
 	SceneSingleton::getInstance().registerController(this);
 }

+ 17 - 11
src/Scene/Controllers/Controller.h

@@ -1,7 +1,8 @@
 #ifndef CONTROLLER_H
 #define CONTROLLER_H
 
-#include "Properties.h"
+
+class SceneNode;
 
 
 /// Scenegraph node controller (A)
@@ -10,20 +11,25 @@ class Controller
 	public:
 		enum ControllerType
 		{ 
-			CT_SKEL_ANIM, 
-			CT_SKEL,
-			CT_MATERIAL,
-			CT_LIGHT_MTL,
-			CT_TRF,
-			CT_LIGHT
+			CT_SKEL_ANIM_SKIN_NODE,
+			CT_NUM
 		};
 	
-	PROPERTY_R(ControllerType, type, getType) ///< Once the type is set nothing can change it
-
-	public:
-		Controller(ControllerType type_);
+		Controller(ControllerType type, SceneNode& node);
 		virtual ~Controller();
+
+		/// @name Accessors
+		/// @{
+		ControllerType getType() const {return type;}
+		/// @}
+
 		virtual void update(float time) = 0;
+
+	protected:
+		SceneNode& controlledNode;
+
+	private:
+		ControllerType type; ///< Once the type is set nothing can change it
 };
 
 

+ 3 - 3
src/Scene/Controllers/LightPropsScriptCtrl.h

@@ -7,13 +7,13 @@
 class Light;
 
 
-class LightPropsScriptCtrl: public Controller
+/*class LightPropsScriptCtrl: public Controller
 {
 	public:
 		Light* light;
 		
 		LightPropsScriptCtrl(Light* light_): controller(CT_LIGHT), light(light_) {}
-		void update(float) { /* ToDo */ }
-};
+		void update(float) {  ToDo  }
+};*/
 
 #endif

+ 7 - 2
src/Scene/Controllers/SkelAnimModelNodeCtrl.cpp

@@ -11,7 +11,7 @@
 // SkelAnimModelNodeCtrl                                                                                               =
 //======================================================================================================================
 SkelAnimModelNodeCtrl::SkelAnimModelNodeCtrl(SkinNode& skinNode_):
-	Controller(CT_SKEL_ANIM),
+	Controller(CT_SKEL_ANIM_SKIN_NODE, skinNode_),
 	frame(0.0),
 	skinNode(skinNode_)
 {}
@@ -26,7 +26,7 @@ void SkelAnimModelNodeCtrl::interpolate(const SkelAnim& animation, float frame,
 	ASSERT(frame < animation.framesNum);
 
 	// calculate the t (used in slerp and lerp) using the keyframs and the frame and
-	// calc the lPose and rPose witch indicate the pose ids in witch the frame lies between
+	// calc the lPose and rPose witch indicate the pose IDs in witch the frame lies between
 	const Vec<uint>& keyframes = animation.keyframes;
 	float t = 0.0;
 	uint lPose = 0, rPose = 0;
@@ -162,6 +162,11 @@ void SkelAnimModelNodeCtrl::update(float)
 		frame = 0.0;
 	}
 
+	if(!controlledNode.isVisible())
+	{
+		return;
+	}
+
 	interpolate(*skelAnim, frame, skinNode.getBoneTranslations(), skinNode.getBoneRotations());
 	updateBoneTransforms(skinNode.getSkin().getSkeleton(), skinNode.getBoneTranslations(), skinNode.getBoneRotations());
 	if(MainRendererSingleton::getInstance().getDbg().isEnabled() &&

+ 3 - 3
src/Scene/Controllers/TrfScriptCtrl.h

@@ -5,13 +5,13 @@
 
 
 /// Transformation controlled by a script
-class TrfScriptCtrl: public Controller
+/*class TrfScriptCtrl: public Controller
 {
 	public:
 		SceneNode* node;
 	
 		TrfScriptCtrl(SceneNode* node_): Controller(CT_TRF), node(node_) {}
-		void Update(float) { /* ToDo */ }
-};
+		void Update(float) {  ToDo  }
+};*/
 
 #endif

+ 3 - 0
src/Scene/GhostNode.h

@@ -12,6 +12,9 @@ class GhostNode: public SceneNode
 		GhostNode(): SceneNode(SNT_GHOST, false, NULL) {}
 		~GhostNode() {}
 		void init(const char*) {}
+
+		void moveUpdate() {}
+		void frameUpdate() {}
 };
 
 

+ 1 - 1
src/Scene/Light.cpp

@@ -1,5 +1,5 @@
 #include "Light.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 
 
 //======================================================================================================================

+ 9 - 2
src/Scene/Light.h

@@ -21,7 +21,7 @@ Specular intensity of material: Sm
 #include "SceneNode.h"
 #include "Camera.h"
 #include "RsrcPtr.h"
-#include "LightData.h"
+#include "LightRsrc.h"
 
 
 /// Light scene node. It can be spot or point
@@ -44,11 +44,18 @@ class Light: public SceneNode
 	/// @}
 
 	public:
-		RsrcPtr<LightData> lightData;
+		RsrcPtr<LightRsrc> lightData;
 	
 		Light(LightType type, bool compoundFlag, SceneNode* parent = NULL);
 		~Light() {}
 		void init(const char* filename);
+
+		void moveUpdate() {}
+		void frameUpdate() {}
+
+	private:
+		//LightType type;
+
 };
 
 

+ 2 - 2
src/Scene/ModelNode.cpp

@@ -19,9 +19,9 @@ void ModelNode::init(const char* filename)
 
 
 //======================================================================================================================
-// updateTrf                                                                                                           =
+// moveUpdate                                                                                                          =
 //======================================================================================================================
-void ModelNode::updateTrf()
+void ModelNode::moveUpdate()
 {
 	// Update bounding shape
 	boundingShapeWSpace = model->getBoundingShape().getTransformed(worldTransform);

+ 3 - 1
src/Scene/ModelNode.h

@@ -31,7 +31,9 @@ class ModelNode: public SceneNode
 		void init(const char* filename);
 
 		/// Update the bounding shape
-		void updateTrf();
+		void moveUpdate();
+
+		void frameUpdate() {}
 
 		/// @name Accessors
 		/// @{

+ 2 - 2
src/Scene/ParticleEmitter.cpp

@@ -68,9 +68,9 @@ void ParticleEmitter::init(const char* filename)
 
 
 //======================================================================================================================
-// update                                                                                                              =
+// frameUpdate                                                                                                         =
 //======================================================================================================================
-void ParticleEmitter::update()
+void ParticleEmitter::frameUpdate()
 {
 	float crntTime = AppSingleton::getInstance().getTicks() / 1000.0;
 

+ 2 - 1
src/Scene/ParticleEmitter.h

@@ -41,7 +41,8 @@ class ParticleEmitter: public SceneNode, public ParticleEmitterPropsStruct
 		RsrcPtr<ParticleEmitterProps> particleEmitterProps; ///< The resource
 		static btTransform startingTrf;
 
-		void update();
+		void frameUpdate();
+		void moveUpdate() {}
 };
 
 

+ 1 - 1
src/Scene/PointLight.h

@@ -18,7 +18,7 @@ class PointLight: public Light
 inline void PointLight::init(const char* filename)
 {
 	Light::init(filename);
-	if(lightData->getType() != LightData::LT_POINT)
+	if(lightData->getType() != LightRsrc::LT_POINT)
 	{
 		throw EXCEPTION("Light data is wrong type");
 		return;

+ 2 - 2
src/Scene/RenderableNode.cpp

@@ -11,9 +11,9 @@ RenderableNode::RenderableNode(const Sphere& boundingShapeLSpace_, SceneNode* pa
 
 
 //======================================================================================================================
-// updateTrf                                                                                                           =
+// moveUpdate                                                                                                          =
 //======================================================================================================================
-void RenderableNode::updateTrf()
+void RenderableNode::moveUpdate()
 {
 	boundingShapeWSpace = boundingShapeLSpace.getTransformed(getWorldTransform());
 }

+ 2 - 1
src/Scene/RenderableNode.h

@@ -23,7 +23,8 @@ class RenderableNode: public SceneNode
 		const Sphere& getBoundingShapeWSpace() const {return boundingShapeWSpace;}
 
 		/// Update the bounding shape
-		virtual void updateTrf();
+		virtual void moveUpdate();
+		void frameUpdate() {}
 
 	private:
 		Sphere boundingShapeLSpace;

+ 2 - 2
src/Scene/Scene.cpp

@@ -132,8 +132,8 @@ void Scene::updateAllWorldStuff()
 		SceneNode* obj = queue[head++]; // queue pop
 
 		obj->updateWorldTransform();
-		obj->updateTrf();
-		obj->update();
+		obj->frameUpdate();
+		obj->moveUpdate();
 		++num;
 
 		Object::Container::iterator it = obj->getObjChildren().begin();

+ 26 - 8
src/Scene/SceneNode.h

@@ -4,7 +4,6 @@
 #include <memory>
 #include "Math.h"
 #include "Object.h"
-#include "Properties.h"
 
 
 class Material;
@@ -34,24 +33,37 @@ class SceneNode: private Object
 
 		/// @name Accessors
 		/// @{
-		GETTER_SETTER(Transform, localTransform, getLocalTransform, setLocalTransform)
-		GETTER_SETTER(Transform, worldTransform, getWorldTransform, setWorldTransform)
+		const Transform& getLocalTransform() const {return localTransform;}
+		Transform& getLocalTransform() {return localTransform;}
+		void setLocalTransform(const Transform& t) {localTransform = t;}
+
+		const Transform& getWorldTransform() const {return worldTransform;}
+		Transform& getWorldTransform() {return worldTransform;}
+		void setWorldTransform(const Transform& t) {worldTransform = t;}
+
 		SceneNodeType getSceneNodeType() const {return type;}
+
+		bool isVisible() const {return visible;}
+		void setVisible(bool v) {visible = v;}
 		/// @}
 
 		/// @name Updates
 		/// Two separate updates for the main loop. The update happens anyway and the updateTrf only when the node is being
 		/// moved
 		/// @{
-		virtual void update() {}
-		virtual void updateTrf() {}
+
+		/// This is called every frame
+		virtual void frameUpdate() = 0;
+
+		/// This is called if the node moved
+		virtual void moveUpdate() = 0;
 		/// @}
 
 		/// @name Mess with the local transform
 		/// @{
-		void rotateLocalX(float angDegrees) {localTransform.getRotation().rotateXAxis(angDegrees);}
-		void rotateLocalY(float angDegrees) {localTransform.getRotation().rotateYAxis(angDegrees);}
-		void rotateLocalZ(float angDegrees) {localTransform.getRotation().rotateZAxis(angDegrees);}
+		void rotateLocalX(float angDegrees) {getLocalTransform().getRotation().rotateXAxis(angDegrees);}
+		void rotateLocalY(float angDegrees) {getLocalTransform().getRotation().rotateYAxis(angDegrees);}
+		void rotateLocalZ(float angDegrees) {getLocalTransform().getRotation().rotateZAxis(angDegrees);}
 		void moveLocalX(float distance);
 		void moveLocalY(float distance);
 		void moveLocalZ(float distance);
@@ -65,6 +77,12 @@ class SceneNode: private Object
 		SceneNodeType type;
 		bool compoundFlag; ///< This means that the children will inherit the world transform of this node
 
+		/// @name Runtime info
+		/// @{
+		bool visible; ///< Visible by any camera
+		bool moved;
+		/// @}
+
 		void updateWorldTransform(); ///< This update happens only when the object gets moved
 };
 

+ 2 - 2
src/Scene/SkinNode.cpp

@@ -19,9 +19,9 @@ void SkinNode::init(const char* filename)
 
 
 //======================================================================================================================
-// updateTrf                                                                                                           =
+// moveUpdate                                                                                                          =
 //======================================================================================================================
-void SkinNode::updateTrf()
+void SkinNode::moveUpdate()
 {
 	boundingShapeWSpace.set(tails);
 	boundingShapeWSpace = boundingShapeWSpace.getTransformed(worldTransform);

+ 1 - 1
src/Scene/SkinNode.h

@@ -42,7 +42,7 @@ class SkinNode: public SceneNode
 
 		/// Update boundingShapeWSpace from bone tails (not bone and heads cause its faster that way). The tails come from
 		/// the previous frame
-		void updateTrf();
+		void moveUpdate();
 
 	private:
 		RsrcPtr<Skin> skin; ///< The resource

+ 1 - 1
src/Scene/SpotLight.cpp

@@ -7,7 +7,7 @@
 void SpotLight::init(const char* filename)
 {
 	Light::init(filename);
-	if(lightData->getType() != LightData::LT_SPOT)
+	if(lightData->getType() != LightRsrc::LT_SPOT)
 	{
 		throw EXCEPTION("Light data is wrong type");
 	}

+ 15 - 2
src/Scene/VisibilityTester.cpp

@@ -32,6 +32,14 @@ VisibilityTester::VisibilityTester(Scene& scene_):
 //======================================================================================================================
 void VisibilityTester::test(Camera& cam)
 {
+	//
+	// Set all nodes to not visible
+	//
+	BOOST_FOREACH(SceneNode* node, scene.getAllNodes())
+	{
+		node->setVisible(false);
+	}
+
 	//
 	// Collect the lights for the main cam
 	//
@@ -51,6 +59,7 @@ void VisibilityTester::test(Camera& cam)
 				if(cam.insideFrustum(sphere))
 				{
 					cam.getVisiblePointLights().push_back(pointl);
+					pointl->setVisible(true);
 				}
 				break;
 			}
@@ -62,6 +71,7 @@ void VisibilityTester::test(Camera& cam)
 				if(cam.insideFrustum(spotl->getCamera()))
 				{
 					cam.getVisibleSpotLights().push_back(spotl);
+					spotl->setVisible(true);
 				}
 				break;
 			}
@@ -101,7 +111,7 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless, Camera& cam)
 	cam.getVisibleMsRenderableNodes().clear();
 	cam.getVisibleBsRenderableNodes().clear();
 
-	BOOST_FOREACH(const ModelNode* node, scene.getModelNodes())
+	BOOST_FOREACH(ModelNode* node, scene.getModelNodes())
 	{
 		// Skip if the ModeNode is not visible
 		if(!test(*node, cam))
@@ -109,8 +119,10 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless, Camera& cam)
 			continue;
 		}
 
+		node->setVisible(true);
+
 		// If not test every patch individually
-		BOOST_FOREACH(const ModelPatchNode* modelPatchNode, node->getModelPatchNodes())
+		BOOST_FOREACH(ModelPatchNode* modelPatchNode, node->getModelPatchNodes())
 		{
 			// Skip shadowless
 			if(skipShadowless && !modelPatchNode->getCpMtl().isShadowCaster())
@@ -129,6 +141,7 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless, Camera& cam)
 				{
 					cam.getVisibleMsRenderableNodes().push_back(modelPatchNode);
 				}
+				modelPatchNode->setVisible(true);
 			}
 		}
 	}

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä