Browse Source

Making testapp to compile

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
efd9567fec
4 changed files with 87 additions and 71 deletions
  1. 40 19
      include/anki/collision/Frustum.h
  2. 16 1
      include/anki/scene/Light.h
  3. 22 44
      src/collision/Frustum.cpp
  4. 9 7
      testapp/Main.cpp

+ 40 - 19
include/anki/collision/Frustum.h

@@ -76,9 +76,6 @@ public:
 	}
 	/// @}
 
-	/// Implements CollisionShape::transform. Ignores scale
-	void transform(const Transform& trf);
-
 	/// Implements CollisionShape::accept
 	void accept(MutableVisitor& v)
 	{
@@ -97,16 +94,16 @@ public:
 	virtual Mat4 calculateProjectionMatrix() const = 0;
 
 protected:
-	/// Used to check against the frustum
-	std::array<Plane, FP_COUNT> planes;
-
 	/// @name Viewing variables
 	/// @{
 	float near;
 	float far;
 	/// @}
 
-	Transform trf; ///< Retain the tranformation
+	/// Used to check against the frustum
+	std::array<Plane, FP_COUNT> planes;
+
+	Transform trf; ///< Retain the transformation
 
 	/// Called when a viewing variable changes. It recalculates the planes and
 	/// the other variables
@@ -115,6 +112,14 @@ protected:
 	/// Copy
 	Frustum& operator=(const Frustum& b);
 
+	void transformPlanes()
+	{
+		for(Plane& p : planes)
+		{
+			p.transform(trf);
+		}
+	}
+
 private:
 	FrustumType type;
 };
@@ -203,21 +208,24 @@ public:
 	void getAabb(Aabb& aabb) const;
 
 private:
-	/// @name Shape
-	/// @{
-	Vec3 eye; ///< The eye point
-	std::array<Vec3, 4> dirs; ///< Directions
-	/// @}
-
 	/// @name Viewing variables
 	/// @{
 	float fovX;
 	float fovY;
 	/// @}
 
+	/// @name Shape
+	/// @{
+	Vec3 eye; ///< The eye point
+	std::array<Vec3, 4> dirs; ///< Directions
+	/// @}
+
 	/// Implements CollisionShape::recalculate. Recalculate @a planes, @a eye
 	/// and @a dirs
 	void recalculate();
+
+	/// Transform the @a eye and @a dirs using @a Frustrum::trf
+	void transformShape();
 };
 
 /// Frustum shape for orthographic cameras
@@ -303,6 +311,7 @@ public:
 		recalculate();
 	}
 
+	/// Needed for debug drawing
 	const Obb& getObb() const
 	{
 		return obb;
@@ -313,13 +322,19 @@ public:
 	OrthographicFrustum& operator=(const OrthographicFrustum& b);
 
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	float testPlane(const Plane& p) const
+	{
+		return obb.testPlane(p);
+	}
 
 	/// Override Frustum::transform
 	void transform(const Transform& trf);
 
 	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& aabb) const;
+	void getAabb(Aabb& aabb) const
+	{
+		obb.getAabb(aabb);
+	}
 
 	/// Implements Frustum::calculateProjectionMatrix
 	Mat4 calculateProjectionMatrix() const;
@@ -333,19 +348,25 @@ public:
 	}
 
 private:
-	/// @name Shape
+	/// @name Viewing variables
 	/// @{
-	Obb obb; ///< Including shape
+	float left, right, top, bottom;
 	/// @}
 
-	/// @name Viewing variables
+	/// @name Shape
 	/// @{
-	float left, right, top, bottom;
+	Obb obb; ///< Including shape
 	/// @}
 
 	/// Implements CollisionShape::recalculate. Recalculate @a planes and
 	/// @a obb
 	void recalculate();
+
+	/// Transform the @a obb using @a Frustrum::trf
+	void transformShape()
+	{
+		obb.transform(trf);
+	}
 };
 /// @}
 

+ 16 - 1
include/anki/scene/Light.h

@@ -5,8 +5,8 @@
 #include "anki/scene/Movable.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Spatial.h"
-#include "anki/resource/Material.h"
 #include "anki/resource/Resource.h"
+#include "anki/resource/TextureResource.h"
 
 namespace anki {
 
@@ -225,6 +225,15 @@ public:
 	{
 		projectionMat = x;
 	}
+
+	Texture& getTexture()
+	{
+		return *tex;
+	}
+	const Texture& getTexture() const
+	{
+		return *tex;
+	}
 	/// @}
 
 	/// @name Movable virtuals
@@ -251,10 +260,16 @@ public:
 	}
 	/// @}
 
+	void loadTexture(const char* filename)
+	{
+		tex.load(filename);
+	}
+
 private:
 	PerspectiveFrustum frustum;
 	Mat4 projectionMat;
 	Mat4 viewMat;
+	TextureResourcePointer tex;
 	ReadWriteProperty<float>* fovProp; ///< Have it here for updates
 	ReadWriteProperty<float>* distProp; ///< Have it here for updates
 

+ 22 - 44
src/collision/Frustum.cpp

@@ -11,9 +11,10 @@ namespace anki {
 //==============================================================================
 Frustum& Frustum::operator=(const Frustum& b)
 {
-	planes = b.planes;
+	ANKI_ASSERT(type == b.type);
 	near = b.near;
 	far = b.far;
+	planes = b.planes;
 	trf = b.trf;
 	return *this;
 }
@@ -32,18 +33,6 @@ bool Frustum::insideFrustum(const CollisionShape& b) const
 	return true;
 }
 
-//==============================================================================
-void Frustum::transform(const Transform& trf_)
-{
-	trf.transform(trf_);
-
-	// Planes
-	for(Plane& p : planes)
-	{
-		p.transform(trf);
-	}
-}
-
 //==============================================================================
 // PerspectiveFrustum                                                          =
 //==============================================================================
@@ -52,10 +41,10 @@ void Frustum::transform(const Transform& trf_)
 PerspectiveFrustum& PerspectiveFrustum::operator=(const PerspectiveFrustum& b)
 {
 	Frustum::operator=(b);
-	eye = b.eye;
-	dirs = b.dirs;
 	fovX = b.fovX;
 	fovY = b.fovY;
+	eye = b.eye;
+	dirs = b.dirs;
 	return *this;
 }
 
@@ -87,10 +76,8 @@ float PerspectiveFrustum::testPlane(const Plane& p) const
 }
 
 //==============================================================================
-void PerspectiveFrustum::transform(const Transform& trf_)
+void PerspectiveFrustum::transformShape()
 {
-	Frustum::transform(trf_);
-
 	eye.transform(trf);
 
 	for(Vec3& dir : dirs)
@@ -99,6 +86,14 @@ void PerspectiveFrustum::transform(const Transform& trf_)
 	}
 }
 
+//==============================================================================
+void PerspectiveFrustum::transform(const Transform& trf_)
+{
+	trf.transform(trf_);
+	transformPlanes();
+	transformShape();
+}
+
 //==============================================================================
 void PerspectiveFrustum::getAabb(Aabb& aabb) const
 {
@@ -146,9 +141,8 @@ void PerspectiveFrustum::recalculate()
 
 	// Transform
 	//
-	Transform tmptrf = trf;
-	trf.setIdentity();
-	transform(tmptrf);
+	transformPlanes();
+	transformShape();
 }
 
 //==============================================================================
@@ -187,32 +181,20 @@ OrthographicFrustum& OrthographicFrustum::operator=(
 	const OrthographicFrustum& b)
 {
 	Frustum::operator=(b);
-	obb = b.obb;
 	left = b.left;
 	right = b.right;
 	top = b.top;
 	bottom = b.bottom;
+	obb = b.obb;
 	return *this;
 }
 
-
-//==============================================================================
-float OrthographicFrustum::testPlane(const Plane& p) const
-{
-	return obb.testPlane(p);
-}
-
 //==============================================================================
 void OrthographicFrustum::transform(const Transform& trf_)
 {
-	Frustum::transform(trf_);
-	obb.transform(trf);
-}
-
-//==============================================================================
-void OrthographicFrustum::getAabb(Aabb& aabb) const
-{
-	obb.getAabb(aabb);
+	trf.transform(trf_);
+	transformPlanes();
+	transformShape();
 }
 
 //==============================================================================
@@ -228,7 +210,7 @@ Mat4 OrthographicFrustum::calculateProjectionMatrix() const
 
 	m(0, 0) = 2.0 / difx;
 	m(0, 1) = 0.0;
-	m(0, 2) = 0.0:
+	m(0, 2) = 0.0;
 	m(0, 3) = tx;
 	m(1, 0) = 0.0;
 	m(1, 1) = 2.0 / dify;
@@ -250,7 +232,6 @@ Mat4 OrthographicFrustum::calculateProjectionMatrix() const
 void OrthographicFrustum::recalculate()
 {
 	// Planes
-	//
 	planes[FP_LEFT] = Plane(Vec3(1.0, 0.0, 0.0), left);
 	planes[FP_RIGHT] = Plane(Vec3(-1.0, 0.0, 0.0), -right);
 	planes[FP_NEAR] = Plane(Vec3(0.0, 0.0, -1.0), near);
@@ -259,16 +240,13 @@ void OrthographicFrustum::recalculate()
 	planes[FP_BOTTOM] = Plane(Vec3(0.0, 1.0, 0.0), bottom);
 
 	// OBB
-	//
 	Vec3 c((right + left) * 0.5, (top + bottom) * 0.5, - (far + near) * 0.5);
 	Vec3 e = Vec3(right, top, -far) - c;
 	obb = Obb(c, Mat3::getIdentity(), e);
 
 	// Transform
-	//
-	Transform tmptrf = trf;
-	trf.setIdentity();
-	transform(tmptrf);
+	transformPlanes();
+	transformShape();
 }
 
 } // end namespace

+ 9 - 7
testapp/Main.cpp

@@ -69,15 +69,17 @@ void init()
 	// lights
 
 	SpotLight* spot = new SpotLight("spot0", &scene, Movable::MF_NONE, nullptr);
-	spot_lights[0]->init("maps/temple/light2.light");
-	spot_lights[0]->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0), Mat3(Euler(Math::toRad(-20), Math::toRad(20), 0.0)), 1.0));
-	spot_lights[1] = new SpotLight(scene, SceneNode::SNF_NONE, NULL);
-	spot_lights[1]->init("maps/temple/light3.light");
-	spot_lights[1]->setLocalTransform(Transform(Vec3(-2.3, 6.3, 2.9), Mat3(Euler(Math::toRad(-70), Math::toRad(-20), 0.0)), 1.0));
-
+	spot->setFov(Math::toRad(45.0));
+	spot->setLocalTransform(Transform(Vec3(1.3, 4.3, 3.0),
+		Mat3(Euler(Math::toRad(-20), Math::toRad(20), 0.0)), 1.0));
+	spot->setColor(Vec4(4.0));
+	spot->setSpecularColor(Vec4(1.0));
+	spot->loadTexture("gfx/lights/flashlight.tga");
+	spot->setDistance(20.0);
+	spot->setShadowEnabled(true);
 
 	// horse
-	horse = new ModelNode(scene, SceneNode::SNF_NONE, NULL);
+	ModelNode* horse = new ModelNode(scene, SceneNode::SNF_NONE, NULL);
 	horse->init("meshes/horse/horse.mdl");
 	horse->setLocalTransform(Transform(Vec3(-2, 0, 0), Mat3::getIdentity(), 1.0));