Panagiotis Christopoulos Charitos 14 år sedan
förälder
incheckning
f353a3031b
2 ändrade filer med 43 tillägg och 12 borttagningar
  1. 20 6
      anki/scene/Light.cpp
  2. 23 6
      anki/scene/Light.h

+ 20 - 6
anki/scene/Light.cpp

@@ -14,7 +14,8 @@ Light::Light(LightType t, const char* fmtl, // Light
 	const char* name, Scene* scene, // Scene
 	uint movableFlags, Movable* movParent, // Movable
 	CollisionShape* cs) // Spatial
-	: SceneNode(name, scene), Movable(movableFlags, movParent),
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this),
 		Spatial(cs), type(t)
 {
 	mtl.load(fmtl);
@@ -37,13 +38,26 @@ PointLight::PointLight(const char* fmtl,
 	uint movableFlags, Movable* movParent)
 	: Light(LT_POINT, fmtl, name, scene, movableFlags, movParent, &sphereW)
 {
-	Property<PerspectiveFrustum>* prop =
-		new ReadWritePointerProperty<PerspectiveFrustum>("frustum", &frustum);
+	PropertyBase& pbase = findPropertyBaseByName("radius");
+	Property<float>& prop = pbase.upCast<Property<float> >();
+	ANKI_CONNECT(&prop, valueChanged, this, updateRadius);
 
-	addNewProperty(prop);
-
-	ANKI_CONNECT(prop, valueChanged, this, updateFrustumSlot);
+	sphereL.setCenter(Vec3(0.0));
+	sphereL.setRadius(prop.getValue());
 }
 
 
+//==============================================================================
+// SpotLight                                                                   =
+//==============================================================================
+
+//==============================================================================
+SpotLight::SpotLight(const char* fmtl,
+	const char* name, Scene* scene,
+	uint movableFlags, Movable* movParent)
+	: Light(LT_SPOT, fmtl, name, scene, movableFlags, movParent, &frustum),
+		Frustumable(frustum)
+{}
+
+
 } // end namespace

+ 23 - 6
anki/scene/Light.h

@@ -6,7 +6,8 @@
 #include "anki/scene/Renderable.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Spatial.h"
-#include "anki/gl/Vao.h"
+#include "anki/resource/Material.h"
+#include "anki/resource/Resource.h"
 
 
 namespace anki {
@@ -86,10 +87,10 @@ public:
 	const ModelPatchBase& getModelPatchBase() const
 	{
 		ANKI_ASSERT(0 && "Lights don't support it");
-		return NULL;
+		throw "";
 	}
 
-	MaterialRuntime& getMaterial()
+	Material& getMaterial()
 	{
 		return *mtl;
 	}
@@ -105,6 +106,8 @@ private:
 class PointLight: public Light
 {
 public:
+	ANKI_OBSERVING(PointLight)
+
 	/// @name Constructors/Destructor
 	/// @{
 	PointLight(const char* fmtl,
@@ -117,16 +120,22 @@ public:
 
 	/// Overrides Movable::moveUpdate(). This does:
 	/// - Update the collision shape
-	void moveUpdate()
+	void movableUpdate()
 	{
-		Movable::moveUpdate();
-		sphereW = sphereL.getTransformed();
+		Movable::movableUpdate();
+		sphereW = sphereL.getTransformed(getWorldTransform());
 	}
 	/// @}
 
 public:
 	Sphere sphereW;
 	Sphere sphereL;
+
+	void updateRadius(const float& r)
+	{
+		sphereL.setRadius(r);
+	}
+	ANKI_SLOT(updateRadius, const float&)
 };
 
 
@@ -134,8 +143,16 @@ public:
 class SpotLight: public Light, public Frustumable
 {
 public:
+	/// @name Constructors/Destructor
+	/// @{
+	SpotLight(const char* fmtl,
+		const char* name, Scene* scene,
+		uint movableFlags, Movable* movParent)
+	{}
+	/// @}
 
 private:
+	PerspectiveFrustum frustum;
 };