2
0
Panagiotis Christopoulos Charitos 12 жил өмнө
parent
commit
f7889c6260

+ 118 - 6
bench/Main.cpp

@@ -100,7 +100,7 @@ void initSubsystems()
 //#if ANKI_GL == ANKI_GL_ES
 #if 1
 	initializer.get("samples") = 1;
-	initializer.get("is.groundLightEnabled") = false;
+	initializer.get("is.groundLightEnabled") = true;
 	initializer.get("is.maxPointLights") = 64;
 	initializer.get("is.maxPointLightsPerTile") = 8;
 	initializer.get("is.maxSpotLightsPerTile") = 4;
@@ -243,7 +243,7 @@ void initScene()
 	scene.newSceneNode(spot, "spot0");
 	spot->setOuterAngle(toRad(45.0));
 	spot->setInnerAngle(toRad(15.0));
-	spot->setLocalTransform(Transform(Vec3(10.769279, 13.472027, -0.324927),
+	spot->setLocalTransform(Transform(Vec3(7.769279, 8.472027, -0.324927),
 		Mat3(Quat(-0.267508, 0.664765, 0.244565, 0.653239)), 1.0));
 	spot->setDiffuseColor(Vec4(2.0));
 	spot->setSpecularColor(Vec4(1.0, 0.0, 1.0, 1.0));
@@ -255,22 +255,128 @@ void initScene()
 
 	PointLight* pl;
 	scene.newSceneNode(pl, "pl0");
-	pl->setRadius(12.5);
+	pl->setRadius(8.5);
 	pl->setDiffuseColor(Vec4(0.5, 0.3, 0.2, 1.0));
 	pl->setSpecularColor(Vec4(0.1, 0.0, 0.0, 1.0));
 	pl->setLocalOrigin(Vec3(10, 2.0, -0.8));
 
-	scene.newSceneNode(pl, "pl1");
+	/*scene.newSceneNode(pl, "pl1");
 	pl->setRadius(12.5);
 	pl->setDiffuseColor(Vec4(0.5, 0.3, 0.2, 1.0));
 	pl->setSpecularColor(Vec4(0.1, 0.0, 0.0, 1.0));
-	pl->setLocalOrigin(Vec3(0, 2.0, -0.8));
+	pl->setLocalOrigin(Vec3(0, 2.0, -0.8));*/
 
 	scene.newSceneNode(pl, "pl2");
-	pl->setRadius(12.5);
+	pl->setRadius(8.5);
 	pl->setDiffuseColor(Vec4(0.5, 0.3, 0.2, 1.0));
 	pl->setSpecularColor(Vec4(0.1, 0.0, 0.0, 1.0));
 	pl->setLocalOrigin(Vec3(-11, 2.0, -0.8));
+
+
+	// bounce lights
+	const F32 bounceRadius = 2.0;
+	const F32 lightPower = 0.3;
+	const F32 posy = 9.844058;
+	F32 posz = -5.550180;
+	scene.newSceneNode(pl, "bpl0");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, lightPower, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232, posy, posz));
+
+	scene.newSceneNode(pl, "bpl1");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, lightPower, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232, posy, posz));
+
+	scene.newSceneNode(pl, "bpl2");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, 0.0, lightPower, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 6.5, posy, posz));
+
+	scene.newSceneNode(pl, "bpl3");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, 0.0, lightPower, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 6.5, posy, posz));
+
+	scene.newSceneNode(pl, "bpl4");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 13, posy, posz));
+
+	scene.newSceneNode(pl, "bpl5");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 13, posy, posz));
+
+	scene.newSceneNode(pl, "bpl6");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 13 - 6.5, posy, posz));
+
+	scene.newSceneNode(pl, "bpl7");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 13 - 6.5, posy, posz));
+
+
+	posz = 4.050180;
+
+
+	scene.newSceneNode(pl, "bpl0_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, 0.0, lightPower, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232, posy, posz));
+
+	/*scene.newSceneNode(pl, "bpl1_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, 0.0, lightPower, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232, posy, posz));*/
+
+	scene.newSceneNode(pl, "bpl2_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 6.5, posy, posz));
+
+	scene.newSceneNode(pl, "bpl3_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(lightPower, 0.0, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 6.5, posy, posz));
+
+	scene.newSceneNode(pl, "bpl4_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, lightPower, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 13, posy, posz));
+
+	scene.newSceneNode(pl, "bpl5_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, lightPower, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 13, posy, posz));
+
+	scene.newSceneNode(pl, "bpl6_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, 0.0, lightPower, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(10.270232 - 13 - 6.5, posy, posz));
+
+	/*scene.newSceneNode(pl, "bpl7_");
+	pl->setRadius(bounceRadius);
+	pl->setDiffuseColor(Vec4(0.0, lightPower, 0.0, 1.0));
+	pl->setSpecularColor(Vec4(0.0, 0.0, 0.0, 1.0));
+	pl->setLocalOrigin(Vec3(6.570232 - 13 - 6.5, posy, posz));*/
 }
 
 //==============================================================================
@@ -334,6 +440,12 @@ static Bool mainLoopExtra()
 		mover.rotateLocalX(ang * in.getMousePosition().y() * mouseSensivity);
 	}
 
+	if(in.getKey(KC_F1) == 1)
+	{
+		MainRendererSingleton::get().getDbg().setEnabled(
+			!MainRendererSingleton::get().getDbg().getEnabled());
+	}
+
 	if(InputSingleton::get().getKey(KC_ESCAPE))
 	{
 		return false;

+ 7 - 39
include/anki/event/Event.h

@@ -2,6 +2,7 @@
 #define ANKI_EVENT_EVENT_H
 
 #include "anki/scene/Common.h"
+#include "anki/scene/SceneObject.h"
 #include "anki/util/Bitset.h"
 #include "anki/Math.h"
 
@@ -15,7 +16,7 @@ class SceneNode;
 /// @{
 
 /// The base class for all events
-class Event: public Bitset<U8>
+class Event: public SceneObject, public Bitset<U8>
 {
 	friend class EventManager;
 
@@ -24,8 +25,7 @@ public:
 	enum EventFlags
 	{
 		EF_NONE = 0,
-		EF_REANIMATE = 1 << 0,
-		EF_MARKED_FOR_DELETION = 1 << 1
+		EF_REANIMATE = 1 << 0
 	};
 
 	/// @name Constructors/Destructor
@@ -55,26 +55,11 @@ public:
 		return crntTime >= startTime + duration;
 	}
 
-	EventManager& getEventManager()
-	{
-		return *manager;
-	}
-	const EventManager& getEventManager() const
-	{
-		return *manager;
-	}
-
-	SceneNode* getSceneNode()
-	{
-		return node;
-	}
-	const SceneNode* getSceneNode() const
-	{
-		return node;
-	}
+	EventManager& getEventManager();
+	const EventManager& getEventManager() const;
 
-	SceneAllocator<U8> getSceneAllocator() const;
-	SceneAllocator<U8> getSceneFrameAllocator() const;
+	SceneNode* getSceneNode();
+	const SceneNode* getSceneNode() const;
 	/// @}
 
 	/// This method should be implemented by the derived classes
@@ -93,19 +78,6 @@ public:
 		return true;
 	}
 
-	/// Mark event for deletion
-	void markForDeletion()
-	{
-		enableBits(EF_MARKED_FOR_DELETION);
-		node = nullptr;
-	}
-
-	/// Ask if event is marked for deletion
-	Bool isMarkedForDeletion() const
-	{
-		return bitsEnabled(EF_MARKED_FOR_DELETION);
-	}
-
 protected:
 	/// The time the event will start. Eg 23:00. If it's < 0 then start the 
 	/// event now
@@ -148,10 +120,6 @@ protected:
 	/// Return the u between current time and when the event started
 	/// @return A number [0.0, 1.0]
 	F32 getDelta(F32 crntTime) const;
-
-private:
-	EventManager* manager = nullptr; ///< Keep it here to access allocators etc
-	SceneNode* node = nullptr; ///< Optional scene node
 };
 /// @}
 

+ 2 - 2
include/anki/event/EventManager.h

@@ -26,11 +26,11 @@ public:
 
 	/// @name Accessors
 	/// @{
-	SceneGraph& getScene()
+	SceneGraph& getSceneGraph()
 	{
 		return *scene;
 	}
-	const SceneGraph& getScene() const
+	const SceneGraph& getSceneGraph() const
 	{
 		return *scene;
 	}

+ 7 - 1
include/anki/scene/SceneObject.h

@@ -45,6 +45,8 @@ public:
 
 	SceneObject(Type type, SceneObject* parent, SceneGraph* scene);
 
+	virtual ~SceneObject();
+
 	/// @name Accessors
 	/// @{
 	Type getType() const
@@ -60,6 +62,10 @@ public:
 	{
 		return *scene;
 	}
+	const SceneGraph& getSceneGraph() const
+	{
+		return *scene;
+	}
 	/// @}
 
 	Bool isMarkedForDeletion() const
@@ -112,7 +118,7 @@ public:
 	const ScObj& downCast() const
 	{
 		ANKI_ASSERT(ScObj::getClassType() == getType());
-		ScObj* out = staticCastPtr<ScObj*>(this);
+		const ScObj* out = staticCastPtr<const ScObj*>(this);
 		return *out;
 	}
 

+ 35 - 13
src/event/Event.cpp

@@ -1,35 +1,57 @@
 #include "anki/event/Event.h"
 #include "anki/event/EventManager.h"
+#include "anki/scene/SceneGraph.h"
 #include "anki/util/Assert.h"
 
 namespace anki {
 
 //==============================================================================
-Event::Event(EventManager* manager_, F32 startTime_, F32 duration_, 
-	SceneNode* snode_, U8 flags)
-	:	Bitset<U8>(flags), 
+Event::Event(EventManager* manager, F32 startTime_, F32 duration_, 
+	SceneNode* node, U8 flags)
+	:	SceneObject(EVENT_TYPE, node, &manager->getSceneGraph()),
+		Bitset<U8>(flags), 
 		startTime(startTime_),
-		duration(duration_),
-		manager(manager_),
-		node(snode_)
-{
-	ANKI_ASSERT(manager);
-}
+		duration(duration_)
+{}
 
 //==============================================================================
 Event::~Event()
 {}
 
 //==============================================================================
-SceneAllocator<U8> Event::getSceneAllocator() const
+EventManager& Event::getEventManager()
+{
+	return getSceneGraph().getEventManager();
+}
+
+//==============================================================================
+const EventManager& Event::getEventManager() const
 {
-	return manager->getSceneAllocator();
+	return getSceneGraph().getEventManager();
 }
 
 //==============================================================================
-SceneAllocator<U8> Event::getSceneFrameAllocator() const
+SceneNode* Event::getSceneNode()
 {
-	return manager->getSceneFrameAllocator();
+	SceneObject* parent = getParent();
+	if(parent)
+	{
+		return &parent->downCast<SceneNode>();
+	}
+
+	return nullptr;
+}
+
+//==============================================================================
+const SceneNode* Event::getSceneNode() const
+{
+	const SceneObject* parent = getParent();
+	if(parent)
+	{
+		return &parent->downCast<SceneNode>();
+	}
+
+	return nullptr;
 }
 
 //==============================================================================

+ 2 - 2
src/event/SceneAmbientColorEvent.cpp

@@ -10,13 +10,13 @@ SceneAmbientColorEvent::SceneAmbientColorEvent(EventManager* manager,
 	:	Event(manager, startTime, duration), 
 		finalColor(finalColor_)
 {
-	originalColor = getEventManager().getScene().getAmbientColor();
+	originalColor = getSceneGraph().getAmbientColor();
 }
 
 //==============================================================================
 void SceneAmbientColorEvent::update(F32 /*prevUpdateTime*/, F32 crntTime)
 {
-	getEventManager().getScene().setAmbientColor(
+	getSceneGraph().setAmbientColor(
 		interpolate(originalColor, finalColor, getDelta(crntTime)));
 }
 

+ 4 - 0
src/scene/SceneObject.cpp

@@ -12,6 +12,10 @@ SceneObject::SceneObject(Type type, SceneObject* parent, SceneGraph* scene_)
 	ANKI_ASSERT(scene);
 }
 
+//==============================================================================
+SceneObject::~SceneObject()
+{}
+
 //==============================================================================
 SceneAllocator<U8> SceneObject::getSceneAllocator() const
 {