Browse Source

Half float, refactoring, IS

Panagiotis Christopoulos Charitos 13 năm trước cách đây
mục cha
commit
281e2fa526

BIN
docs/drafts/2011-10-18.ora


+ 14 - 0
docs/drafts/octree.py

@@ -0,0 +1,14 @@
+from math import *
+
+octree_node_size = 112
+
+def recurse(depth):
+	if depth == 0:
+		return 1
+	else:
+		return pow(8, depth) + recurse(depth - 1)
+
+def octree_size(depth):
+	return recurse(depth) * octree_node_size
+
+print("Size %d" % (octree_size(3)))

BIN
docs/drafts/scene.odt


+ 4 - 4
include/anki/collision/Aabb.h

@@ -81,7 +81,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -89,8 +89,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& b) const
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& b) const
 	{
 	{
 		b = *this;
 		b = *this;
 	}
 	}
@@ -128,7 +128,7 @@ void Aabb::set(const Container& container)
 	typename Container::const_iterator it = container.begin() + 1;
 	typename Container::const_iterator it = container.begin() + 1;
 	for(; it != container.end(); ++it)
 	for(; it != container.end(); ++it)
 	{
 	{
-		for(int j = 0; j < 3; j++)
+		for(U j = 0; j < 3; j++)
 		{
 		{
 			if((*it)[j] > max[j])
 			if((*it)[j] > max[j])
 			{
 			{

+ 3 - 2
include/anki/collision/CollisionShape.h

@@ -3,6 +3,7 @@
 
 
 #include "anki/collision/Forward.h"
 #include "anki/collision/Forward.h"
 #include "anki/math/Forward.h"
 #include "anki/math/Forward.h"
+#include "anki/util/StdTypes.h"
 
 
 namespace anki {
 namespace anki {
 
 
@@ -75,13 +76,13 @@ public:
 	/// returns 0.0, else it returns the distance. If the distance is < 0.0
 	/// returns 0.0, else it returns the distance. If the distance is < 0.0
 	/// then the collision shape lies behind the plane and if > 0.0 then
 	/// then the collision shape lies behind the plane and if > 0.0 then
 	/// in front of it
 	/// in front of it
-	virtual float testPlane(const Plane& p) const = 0;
+	virtual F32 testPlane(const Plane& p) const = 0;
 
 
 	/// Transform
 	/// Transform
 	virtual void transform(const Transform& trf) = 0;
 	virtual void transform(const Transform& trf) = 0;
 
 
 	/// Get the AABB
 	/// Get the AABB
-	virtual void getAabb(Aabb&) const = 0;
+	virtual void toAabb(Aabb&) const = 0;
 
 
 	/// Visitor accept
 	/// Visitor accept
 	virtual void accept(MutableVisitor&) = 0;
 	virtual void accept(MutableVisitor&) = 0;

+ 34 - 34
include/anki/collision/Frustum.h

@@ -53,21 +53,21 @@ public:
 		return type;
 		return type;
 	}
 	}
 
 
-	float getNear() const
+	F32 getNear() const
 	{
 	{
 		return near;
 		return near;
 	}
 	}
-	void setNear(const float x)
+	void setNear(const F32 x)
 	{
 	{
 		near = x;
 		near = x;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
-	float getFar() const
+	F32 getFar() const
 	{
 	{
 		return far;
 		return far;
 	}
 	}
-	void setFar(const float x)
+	void setFar(const F32 x)
 	{
 	{
 		far = x;
 		far = x;
 		recalculate();
 		recalculate();
@@ -98,8 +98,8 @@ public:
 protected:
 protected:
 	/// @name Viewing variables
 	/// @name Viewing variables
 	/// @{
 	/// @{
-	float near = 0.0;
-	float far = 0.0;
+	F32 near = 0.0;
+	F32 far = 0.0;
 	/// @}
 	/// @}
 
 
 	/// Used to check against the frustum
 	/// Used to check against the frustum
@@ -146,7 +146,7 @@ public:
 	}
 	}
 
 
 	/// Set all
 	/// Set all
-	PerspectiveFrustum(float fovX_, float fovY_, float near_, float far_)
+	PerspectiveFrustum(F32 fovX_, F32 fovY_, F32 near_, F32 far_)
 		: Frustum(FT_PERSPECTIVE)
 		: Frustum(FT_PERSPECTIVE)
 	{
 	{
 		setAll(fovX_, fovY_, near_, far_);
 		setAll(fovX_, fovY_, near_, far_);
@@ -155,28 +155,28 @@ public:
 
 
 	/// @name Accessors
 	/// @name Accessors
 	/// @{
 	/// @{
-	float getFovX() const
+	F32 getFovX() const
 	{
 	{
 		return fovX;
 		return fovX;
 	}
 	}
-	void setFovX(float ang)
+	void setFovX(F32 ang)
 	{
 	{
 		fovX = ang;
 		fovX = ang;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
-	float getFovY() const
+	F32 getFovY() const
 	{
 	{
 		return fovY;
 		return fovY;
 	}
 	}
-	void setFovY(float ang)
+	void setFovY(F32 ang)
 	{
 	{
 		fovY = ang;
 		fovY = ang;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
 	/// Set all the parameters and recalculate the planes and shape
 	/// Set all the parameters and recalculate the planes and shape
-	void setAll(float fovX_, float fovY_, float near_, float far_)
+	void setAll(F32 fovX_, F32 fovY_, F32 near_, F32 far_)
 	{
 	{
 		fovX = fovX_;
 		fovX = fovX_;
 		fovY = fovY_,
 		fovY = fovY_,
@@ -190,7 +190,7 @@ public:
 	PerspectiveFrustum& operator=(const PerspectiveFrustum& b);
 	PerspectiveFrustum& operator=(const PerspectiveFrustum& b);
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Calculate and get transformed
 	/// Calculate and get transformed
 	PerspectiveFrustum getTransformed(const Transform& trf) const
 	PerspectiveFrustum getTransformed(const Transform& trf) const
@@ -209,14 +209,14 @@ public:
 	/// Implements Frustum::calculateProjectionMatrix
 	/// Implements Frustum::calculateProjectionMatrix
 	Mat4 calculateProjectionMatrix() const;
 	Mat4 calculateProjectionMatrix() const;
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& aabb) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& aabb) const;
 
 
 private:
 private:
 	/// @name Viewing variables
 	/// @name Viewing variables
 	/// @{
 	/// @{
-	float fovX = 0.0;
-	float fovY = 0.0;
+	F32 fovX = 0.0;
+	F32 fovY = 0.0;
 	/// @}
 	/// @}
 
 
 	/// @name Shape
 	/// @name Shape
@@ -255,8 +255,8 @@ public:
 	}
 	}
 
 
 	/// Set all
 	/// Set all
-	OrthographicFrustum(float left_, float right_, float near_,
-		float far_, float top_, float bottom_)
+	OrthographicFrustum(F32 left_, F32 right_, F32 near_,
+		F32 far_, F32 top_, F32 bottom_)
 		: Frustum(FT_ORTHOGRAPHIC)
 		: Frustum(FT_ORTHOGRAPHIC)
 	{
 	{
 		setAll(left_, right_, near_, far_, top_, bottom_);
 		setAll(left_, right_, near_, far_, top_, bottom_);
@@ -265,49 +265,49 @@ public:
 
 
 	/// @name Accessors
 	/// @name Accessors
 	/// @{
 	/// @{
-	float getLeft() const
+	F32 getLeft() const
 	{
 	{
 		return left;
 		return left;
 	}
 	}
-	void setLeft(float f)
+	void setLeft(F32 f)
 	{
 	{
 		left = f;
 		left = f;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
-	float getRight() const
+	F32 getRight() const
 	{
 	{
 		return right;
 		return right;
 	}
 	}
-	void setRight(float f)
+	void setRight(F32 f)
 	{
 	{
 		right = f;
 		right = f;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
-	float getTop() const
+	F32 getTop() const
 	{
 	{
 		return top;
 		return top;
 	}
 	}
-	void setTop(float f)
+	void setTop(F32 f)
 	{
 	{
 		top = f;
 		top = f;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
-	float getBottom() const
+	F32 getBottom() const
 	{
 	{
 		return bottom;
 		return bottom;
 	}
 	}
-	void setBottom(float f)
+	void setBottom(F32 f)
 	{
 	{
 		bottom = f;
 		bottom = f;
 		recalculate();
 		recalculate();
 	}
 	}
 
 
 	/// Set all
 	/// Set all
-	void setAll(float left_, float right_, float near_,
-		float far_, float top_, float bottom_)
+	void setAll(F32 left_, F32 right_, F32 near_,
+		F32 far_, F32 top_, F32 bottom_)
 	{
 	{
 		left = left_;
 		left = left_;
 		right = right_;
 		right = right_;
@@ -329,7 +329,7 @@ public:
 	OrthographicFrustum& operator=(const OrthographicFrustum& b);
 	OrthographicFrustum& operator=(const OrthographicFrustum& b);
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const
+	F32 testPlane(const Plane& p) const
 	{
 	{
 		return obb.testPlane(p);
 		return obb.testPlane(p);
 	}
 	}
@@ -340,10 +340,10 @@ public:
 	/// Implements Frustum::setTransform
 	/// Implements Frustum::setTransform
 	void setTransform(const Transform& trf);
 	void setTransform(const Transform& trf);
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& aabb) const
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& aabb) const
 	{
 	{
-		obb.getAabb(aabb);
+		obb.toAabb(aabb);
 	}
 	}
 
 
 	/// Implements Frustum::calculateProjectionMatrix
 	/// Implements Frustum::calculateProjectionMatrix
@@ -360,7 +360,7 @@ public:
 private:
 private:
 	/// @name Viewing variables
 	/// @name Viewing variables
 	/// @{
 	/// @{
-	float left = 0.0, right = 0.0, top = 0.0, bottom = 0.0;
+	F32 left = 0.0, right = 0.0, top = 0.0, bottom = 0.0;
 	/// @}
 	/// @}
 
 
 	/// @name Shape
 	/// @name Shape

+ 3 - 3
include/anki/collision/LineSegment.h

@@ -80,7 +80,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -88,8 +88,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& b) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& b) const;
 
 
 	LineSegment getTransformed(const Transform& transform) const;
 	LineSegment getTransformed(const Transform& transform) const;
 
 

+ 4 - 4
include/anki/collision/Obb.h

@@ -90,7 +90,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -98,8 +98,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& aabb) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& aabb) const;
 
 
 	Obb getTransformed(const Transform& transform) const;
 	Obb getTransformed(const Transform& transform) const;
 
 
@@ -141,7 +141,7 @@ void Obb::set(const Container& container)
 	{
 	{
 		const Vec3& v = *it;
 		const Vec3& v = *it;
 
 
-		for(int j = 0; j < 3; j++)
+		for(U j = 0; j < 3; j++)
 		{
 		{
 			if(v[j] > max[j])
 			if(v[j] > max[j])
 			{
 			{

+ 13 - 13
include/anki/collision/Plane.h

@@ -25,7 +25,7 @@ public:
 	Plane(const Plane& b);
 	Plane(const Plane& b);
 
 
 	/// Constructor
 	/// Constructor
-	Plane(const Vec3& normal_, float offset_);
+	Plane(const Vec3& normal_, F32 offset_);
 
 
 	/// @see setFrom3Points
 	/// @see setFrom3Points
 	Plane(const Vec3& p0, const Vec3& p1, const Vec3& p2)
 	Plane(const Vec3& p0, const Vec3& p1, const Vec3& p2)
@@ -35,7 +35,7 @@ public:
 	}
 	}
 
 
 	/// @see setFromPlaneEquation
 	/// @see setFromPlaneEquation
-	Plane(float a, float b, float c, float d)
+	Plane(F32 a, F32 b, F32 c, F32 d)
 		: CollisionShape(CST_PLANE)
 		: CollisionShape(CST_PLANE)
 	{
 	{
 		setFromPlaneEquation(a, b, c, d);
 		setFromPlaneEquation(a, b, c, d);
@@ -57,15 +57,15 @@ public:
 		normal = x;
 		normal = x;
 	}
 	}
 
 
-	float getOffset() const
+	F32 getOffset() const
 	{
 	{
 		return offset;
 		return offset;
 	}
 	}
-	float& getOffset()
+	F32& getOffset()
 	{
 	{
 		return offset;
 		return offset;
 	}
 	}
-	void setOffset(const float x)
+	void setOffset(const F32 x)
 	{
 	{
 		offset = x;
 		offset = x;
 	}
 	}
@@ -93,7 +93,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -101,8 +101,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& b) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& b) const;
 
 
 	/// Return the transformed
 	/// Return the transformed
 	Plane getTransformed(const Transform& trf) const;
 	Plane getTransformed(const Transform& trf) const;
@@ -110,13 +110,13 @@ public:
 	/// It gives the distance between a point and a plane. if returns >0
 	/// It gives the distance between a point and a plane. if returns >0
 	/// then the point lies in front of the plane, if <0 then it is behind
 	/// then the point lies in front of the plane, if <0 then it is behind
 	/// and if =0 then it is co-planar
 	/// and if =0 then it is co-planar
-	float test(const Vec3& point) const
+	F32 test(const Vec3& point) const
 	{
 	{
 		return normal.dot(point) - offset;
 		return normal.dot(point) - offset;
 	}
 	}
 
 
 	/// Get the distance from a point to this plane
 	/// Get the distance from a point to this plane
-	float getDistance(const Vec3& point) const
+	F32 getDistance(const Vec3& point) const
 	{
 	{
 		return fabs(test(point));
 		return fabs(test(point));
 	}
 	}
@@ -130,7 +130,7 @@ public:
 
 
 	/// Test a CollisionShape
 	/// Test a CollisionShape
 	template<typename T>
 	template<typename T>
-	float testShape(const T& x) const
+	F32 testShape(const T& x) const
 	{
 	{
 		return x.testPlane(*this, x);
 		return x.testPlane(*this, x);
 	}
 	}
@@ -139,14 +139,14 @@ private:
 	/// @name Data
 	/// @name Data
 	/// @{
 	/// @{
 	Vec3 normal;
 	Vec3 normal;
-	float offset;
+	F32 offset;
 	/// @}
 	/// @}
 
 
 	/// Set the plane from 3 points
 	/// Set the plane from 3 points
 	void setFrom3Points(const Vec3& p0, const Vec3& p1, const Vec3& p2);
 	void setFrom3Points(const Vec3& p0, const Vec3& p1, const Vec3& p2);
 
 
 	/// Set from plane equation is ax+by+cz+d
 	/// Set from plane equation is ax+by+cz+d
-	void setFromPlaneEquation(float a, float b, float c, float d);
+	void setFromPlaneEquation(F32 a, F32 b, F32 c, F32 d);
 };
 };
 /// @}
 /// @}
 
 

+ 3 - 3
include/anki/collision/Ray.h

@@ -83,7 +83,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -91,8 +91,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& aabb) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& aabb) const;
 
 
 	Ray getTransformed(const Transform& transform) const;
 	Ray getTransformed(const Transform& transform) const;
 
 

+ 11 - 14
include/anki/collision/Sphere.h

@@ -27,7 +27,7 @@ public:
 	{}
 	{}
 
 
 	/// Constructor
 	/// Constructor
-	Sphere(const Vec3& center_, float radius_)
+	Sphere(const Vec3& center_, F32 radius_)
 		: CollisionShape(CST_SPHERE), center(center_), radius(radius_)
 		: CollisionShape(CST_SPHERE), center(center_), radius(radius_)
 	{}
 	{}
 	/// @}
 	/// @}
@@ -47,15 +47,15 @@ public:
 		center = x;
 		center = x;
 	}
 	}
 
 
-	float getRadius() const
+	F32 getRadius() const
 	{
 	{
 		return radius;
 		return radius;
 	}
 	}
-	float& getRadius()
+	F32& getRadius()
 	{
 	{
 		return radius;
 		return radius;
 	}
 	}
-	void setRadius(const float x)
+	void setRadius(const F32 x)
 	{
 	{
 		radius = x;
 		radius = x;
 	}
 	}
@@ -83,7 +83,7 @@ public:
 	}
 	}
 
 
 	/// Implements CollisionShape::testPlane
 	/// Implements CollisionShape::testPlane
-	float testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const;
 
 
 	/// Implements CollisionShape::transform
 	/// Implements CollisionShape::transform
 	void transform(const Transform& trf)
 	void transform(const Transform& trf)
@@ -91,8 +91,8 @@ public:
 		*this = getTransformed(trf);
 		*this = getTransformed(trf);
 	}
 	}
 
 
-	/// Implements CollisionShape::getAabb
-	void getAabb(Aabb& b) const;
+	/// Implements CollisionShape::toAabb
+	void toAabb(Aabb& b) const;
 
 
 	Sphere getTransformed(const Transform& transform) const;
 	Sphere getTransformed(const Transform& transform) const;
 
 
@@ -106,11 +106,10 @@ public:
 
 
 private:
 private:
 	Vec3 center;
 	Vec3 center;
-	float radius;
+	F32 radius;
 };
 };
 /// @}
 /// @}
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Container>
 template<typename Container>
 void Sphere::set(const Container& container)
 void Sphere::set(const Container& container)
@@ -126,7 +125,7 @@ void Sphere::set(const Container& container)
 	{
 	{
 		const Vec3& v = *it;
 		const Vec3& v = *it;
 
 
-		for(int j = 0; j < 3; j++)
+		for(U j = 0; j < 3; j++)
 		{
 		{
 			if(v[j] > max[j])
 			if(v[j] > max[j])
 			{
 			{
@@ -142,14 +141,14 @@ void Sphere::set(const Container& container)
 	center = (min + max) * 0.5; // average
 	center = (min + max) * 0.5; // average
 
 
 	// max distance between center and the vec3 arr
 	// max distance between center and the vec3 arr
-	float maxDist = (container.front() - center).getLengthSquared();
+	F32 maxDist = (container.front() - center).getLengthSquared();
 
 
 	typename Container::const_iterator it_ = container.begin() + 1;
 	typename Container::const_iterator it_ = container.begin() + 1;
 	for(; it_ != container.end(); ++it_)
 	for(; it_ != container.end(); ++it_)
 	{
 	{
 		const Vec3& v = *it_;
 		const Vec3& v = *it_;
 
 
-		float dist = (v - center).getLengthSquared();
+		F32 dist = (v - center).getLengthSquared();
 		if(dist > maxDist)
 		if(dist > maxDist)
 		{
 		{
 			maxDist = dist;
 			maxDist = dist;
@@ -159,8 +158,6 @@ void Sphere::set(const Container& container)
 	radius = Math::sqrt(maxDist);
 	radius = Math::sqrt(maxDist);
 }
 }
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 50 - 14
include/anki/math/F16.h

@@ -12,32 +12,68 @@ namespace anki {
 class F16
 class F16
 {
 {
 public:
 public:
+	/// @name Constructors
+	/// @{
 	explicit F16();
 	explicit F16();
-	explicit F16(const F32 f);
 	F16(const F16& a);
 	F16(const F16& a);
+	explicit F16(const F32 f);
+	/// @}
 
 
 	/// @name Operators with same type
 	/// @name Operators with same type
 	/// @{
 	/// @{
-	F16& operator=(const F16& b);
-	F16 operator+(const F16& b) const;
-	F16& operator+=(const F16& b);
-	F16 operator-(const F16& b) const;
-	F16& operator-=(const F16& b);
-	F16 operator*(const F16& b) const;
-	F16& operator*=(const F16& b);
-	F16 operator/(const F16& b) const;
-	F16& operator/=(const F16& b);
-	Bool operator==(const F16& b) const;
-	Bool operator!=(const F16& b) const;
+	F16& operator=(const F16 b);
+	F16 operator+(const F16 b) const;
+	F16& operator+=(const F16 b);
+	F16 operator-(const F16 b) const;
+	F16& operator-=(const F16 b);
+	F16 operator*(const F16 b) const;
+	F16& operator*=(const F16 b);
+	F16 operator/(const F16 b) const;
+	F16& operator/=(const F16 b);
+	Bool operator==(const F16 b) const;
+	Bool operator!=(const F16 b) const;
 	/// @}
 	/// @}
 
 
-	static F32 toF32(F16 h);
-	static F16 toF16(F32 f);
+	/// @name Operators with F32
+	/// @{
+	F16& operator=(const F32 b);
+	F32 operator+(const F32 b) const;
+	F16& operator+=(const F32 b);
+	F32 operator-(const F32 b) const;
+	F16& operator-=(const F32 b);
+	F32 operator*(const F32 b) const;
+	F16& operator*=(const F32 b);
+	F32 operator/(const F32 b) const;
+	F16& operator/=(const F32 b);
+	Bool operator==(const F32 b) const;
+	Bool operator!=(const F32 b) const;
+	/// @}
+
+	/// @name Other
+	/// @{
+	F32 toF32() const;
+	/// @}
+
+	/// @name Friends
+	/// @{
+	friend F32 operator+(const F32 f, const F16 h);
+	friend F32 operator-(const F32 f, const F16 h);
+	friend F32 operator*(const F32 f, const F16 h);
+	friend F32 operator/(const F32 f, const F16 h);
+	friend std::ostream& operator<<(std::ostream& s, const F16& m);
+	/// @}
 private:
 private:
 	U16 data;
 	U16 data;
+
+	static F32 toF32(F16 h);
+	static F16 toF16(F32 f);
 };
 };
 /// @}
 /// @}
 
 
+static_assert(sizeof(F16) == 2, "Incorrect size");
+
 } // end namespace anki
 } // end namespace anki
 
 
+#include "anki/math/F16.inl.h"
+
 #endif
 #endif

+ 220 - 0
include/anki/math/F16.inl.h

@@ -0,0 +1,220 @@
+#include "anki/math/MathCommonSrc.h"
+
+namespace anki {
+
+//==============================================================================
+// Constructors                                                                =
+//==============================================================================
+
+// Default
+inline F16::F16()
+{}
+
+// Copy
+inline F16::F16(const F16& b)
+{
+	data = b.data;
+}
+
+// F32
+inline F16::F16(const F32 f)
+{
+	*this = toF16(f);
+}
+
+//==============================================================================
+// Operators with same                                                         =
+//==============================================================================
+
+// Copy
+inline F16& F16::operator=(const F16 b)
+{
+	data = b.data;
+	return *this;
+}
+
+// +
+inline F16 F16::operator+(const F16 b) const
+{
+	return toF16(toF32() + b.toF32());
+}
+
+// +=
+inline F16& F16::operator+=(const F16 b)
+{
+	*this = toF16(toF32() + b.toF32());
+	return *this;
+}
+
+// -
+inline F16 F16::operator-(const F16 b) const
+{
+	return toF16(toF32() - b.toF32());
+}
+
+// -=
+inline F16& F16::operator-=(const F16 b)
+{
+	*this = toF16(toF32() - b.toF32());
+	return *this;
+}
+
+// *
+inline F16 F16::operator*(const F16 b) const
+{
+	return toF16(toF32() * b.toF32());
+}
+
+// *=
+inline F16& F16::operator*=(const F16 b)
+{
+	*this = toF16(toF32() * b.toF32());
+	return *this;
+}
+
+// /
+inline F16 F16::operator/(const F16 b) const
+{
+	return toF16(toF32() / b.toF32());
+}
+
+// /=
+inline F16& F16::operator/=(const F16 b)
+{
+	*this = toF16(toF32() / b.toF32());
+	return *this;
+}
+
+// ==
+inline Bool F16::operator==(const F16 b) const
+{
+	return toF32() == b.toF32();
+}
+
+// !=
+inline Bool F16::operator!=(const F16 b) const
+{
+	return toF32() != b.toF32();
+}
+
+//==============================================================================
+// Operators with F32                                                          =
+//==============================================================================
+
+// Copy
+inline F16& F16::operator=(const F32 b)
+{
+	*this = toF16(b);
+	return *this;
+}
+
+// +
+inline F32 F16::operator+(const F32 b) const
+{
+	return toF32() + b;
+}
+
+// +=
+inline F16& F16::operator+=(const F32 b)
+{
+	*this = toF16(toF32() + b);
+	return *this;
+}
+
+// -
+inline F32 F16::operator-(const F32 b) const
+{
+	return toF32() - b;
+}
+
+// -=
+inline F16& F16::operator-=(const F32 b)
+{
+	*this = toF16(toF32() - b);
+	return *this;
+}
+
+// *
+inline F32 F16::operator*(const F32 b) const
+{
+	return toF32() * b;
+}
+
+// *=
+inline F16& F16::operator*=(const F32 b)
+{
+	*this = toF16(toF32() * b);
+	return *this;
+}
+
+// /
+inline F32 F16::operator/(const F32 b) const
+{
+	return toF32() / b;
+}
+
+// /=
+inline F16& F16::operator/=(const F32 b)
+{
+	*this = toF16(toF32() / b);
+	return *this;
+}
+
+// ==
+inline Bool F16::operator==(const F32 b) const
+{
+	return Math::isZero(toF32() - b);
+}
+
+// !=
+inline Bool F16::operator!=(const F32 b) const
+{
+	return !Math::isZero(toF32() - b);
+}
+
+//==============================================================================
+// Other                                                                       =
+//==============================================================================
+
+// toF32
+inline F32 F16::toF32() const
+{
+	return toF32(*this);
+}
+
+//==============================================================================
+// Other                                                                       =
+//==============================================================================
+
+// F32 + F16
+inline F32 operator+(const F32 f, const F16 h)
+{
+	return f + h.toF32();
+}
+
+// F32 - F16
+inline F32 operator-(const F32 f, const F16 h)
+{
+	return f - h.toF32();
+}
+
+// F32 * F16
+inline F32 operator*(const F32 f, const F16 h)
+{
+	return f * h.toF32();
+}
+
+// F32 / F16
+inline F32 operator/(const F32 f, const F16 h)
+{
+	return f / h.toF32();
+}
+
+// Print
+inline std::ostream& operator<<(std::ostream& s, const F16& m)
+{
+	s << m.toF32();
+	return s;
+}
+
+} // end namespace anki

+ 1 - 0
include/anki/math/Forward.h

@@ -14,6 +14,7 @@ class Axisang;
 class Mat3;
 class Mat3;
 class Mat4;
 class Mat4;
 class Transform;
 class Transform;
+class F16;
 
 
 } // end namespace
 } // end namespace
 
 

+ 1 - 1
include/anki/math/Mat4.inl.h

@@ -357,7 +357,7 @@ inline Bool Mat4::operator!=(const Mat4& b) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-// Operators with F32                                                        =
+// Operators with F32                                                          =
 //==============================================================================
 //==============================================================================
 
 
 // 4x4 + F32
 // 4x4 + F32

+ 0 - 5
include/anki/math/Math.h

@@ -3,10 +3,8 @@
 
 
 #include "anki/math/MathCommonIncludes.h"
 #include "anki/math/MathCommonIncludes.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 /// @addtogroup Math
 /// @addtogroup Math
 /// @{
 /// @{
 
 
@@ -55,11 +53,8 @@ private:
 };
 };
 /// @}
 /// @}
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #include "anki/math/Math.inl.h"
 #include "anki/math/Math.inl.h"
 
 
-
 #endif
 #endif

+ 1 - 0
include/anki/math/MathCommonSrc.h

@@ -7,6 +7,7 @@
 #include "anki/math/Mat3.h"
 #include "anki/math/Mat3.h"
 #include "anki/math/Mat4.h"
 #include "anki/math/Mat4.h"
 #include "anki/math/Transform.h"
 #include "anki/math/Transform.h"
+#include "anki/math/F16.h"
 #include "anki/math/Math.h"
 #include "anki/math/Math.h"
 
 
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"

+ 3 - 3
include/anki/scene/Spatial.h

@@ -42,7 +42,7 @@ public:
 		return aabb;
 		return aabb;
 	}
 	}
 
 
-	uint32_t getSpatialTimestamp() const
+	U32 getSpatialTimestamp() const
 	{
 	{
 		return timestamp;
 		return timestamp;
 	}
 	}
@@ -66,14 +66,14 @@ public:
 	void spatialMarkUpdated()
 	void spatialMarkUpdated()
 	{
 	{
 		timestamp = Timestamp::getTimestamp();
 		timestamp = Timestamp::getTimestamp();
-		spatialCs->getAabb(aabb);
+		spatialCs->toAabb(aabb);
 	}
 	}
 
 
 protected:
 protected:
 	CollisionShape* spatialCs = nullptr;
 	CollisionShape* spatialCs = nullptr;
 
 
 private:
 private:
-	uint32_t timestamp = Timestamp::getTimestamp();
+	U32 timestamp = Timestamp::getTimestamp();
 	OctreeNode* octreeNode = nullptr; ///< What octree node includes this
 	OctreeNode* octreeNode = nullptr; ///< What octree node includes this
 	Aabb aabb; ///< A faster shape
 	Aabb aabb; ///< A faster shape
 };
 };

+ 55 - 0
shaders/IsMinMax.glsl

@@ -0,0 +1,55 @@
+#pragma anki start vertexShader
+
+#pragma anki include "shaders/SimpleVert.glsl"
+
+#pragma anki start fragmentShader
+
+#pragma anki include "shaders/LinearDepth.glsl"
+
+#if !defined(TILES_X_COUNT) || !defined(TILES_Y_COUNT) || !defined(RENDERER_WIDTH) || !defined(RENDERER_HEIGHT)
+#	error "See file"
+#endif
+
+uniform vec2 nearFar;
+uniform sampler2D depthMap;
+
+in vec2 vTexCoords;
+
+out vec2 fColor;
+
+//==============================================================================
+void main()
+{
+#if 1
+	const int FROM_W = RENDERER_WIDTH / TILES_X_COUNT / 2;
+	const int FROM_H = RENDERER_HEIGHT / TILES_Y_COUNT / 2;
+
+	float maxDepth = -10.0;
+	float minDepth = 10.0;
+
+	for(int i = -FROM_W; i < FROM_W; i++)
+	{
+		for(int j = -FROM_H; j < FROM_H; j++)
+		{
+			float depth = textureOffset(depthMap, vTexCoords, ivec2(i, j)).r;
+
+			if(depth < minDepth)
+			{
+				minDepth = depth;
+			}
+			if(depth > maxDepth)
+			{
+				maxDepth = depth;
+			}
+		}
+	}
+
+	fColor = vec2(linearizeDepth(minDepth, nearFar.x, nearFar.y),
+		linearizeDepth(maxDepth, nearFar.x, nearFar.y));
+#else
+	fColor = vec2(float(gl_FragCoord.x) / TILES_X_COUNT, 
+		float(gl_FragCoord.y) / TILES_Y_COUNT);
+#endif
+}
+
+

+ 5 - 5
src/collision/Aabb.cpp

@@ -9,7 +9,7 @@ namespace anki {
 Aabb Aabb::getTransformed(const Transform& transform) const
 Aabb Aabb::getTransformed(const Transform& transform) const
 {
 {
 	Mat3 absM;
 	Mat3 absM;
-	for(int i = 0; i < 9; ++i)
+	for(U i = 0; i < 9; ++i)
 	{
 	{
 		absM[i] = fabs(transform.getRotation()[i]);
 		absM[i] = fabs(transform.getRotation()[i]);
 	}
 	}
@@ -24,12 +24,12 @@ Aabb Aabb::getTransformed(const Transform& transform) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-float Aabb::testPlane(const Plane& p) const
+F32 Aabb::testPlane(const Plane& p) const
 {
 {
 	const Aabb& aabb = *this;
 	const Aabb& aabb = *this;
 	Vec3 diagMin, diagMax;
 	Vec3 diagMin, diagMax;
 	// set min/max values for x,y,z direction
 	// set min/max values for x,y,z direction
-	for(int i = 0; i < 3; i++)
+	for(U i = 0; i < 3; i++)
 	{
 	{
 		if(p.getNormal()[i] >= 0.0)
 		if(p.getNormal()[i] >= 0.0)
 		{
 		{
@@ -44,7 +44,7 @@ float Aabb::testPlane(const Plane& p) const
 	}
 	}
 
 
 	// minimum on positive side of plane, box on positive side
 	// minimum on positive side of plane, box on positive side
-	float test = p.test(diagMin);
+	F32 test = p.test(diagMin);
 	if(test > 0.0)
 	if(test > 0.0)
 	{
 	{
 		return test;
 		return test;
@@ -68,7 +68,7 @@ Aabb Aabb::getCompoundShape(const Aabb& b) const
 {
 {
 	Aabb out;
 	Aabb out;
 
 
-	for(uint i = 0; i < 3; i++)
+	for(U i = 0; i < 3; i++)
 	{
 	{
 		out.min[i] = (min[i] < b.min[i]) ? min[i] : b.min[i];
 		out.min[i] = (min[i] < b.min[i]) ? min[i] : b.min[i];
 		out.max[i] = (max[i] > b.max[i]) ? max[i] : b.max[i];
 		out.max[i] = (max[i] > b.max[i]) ? max[i] : b.max[i];

+ 34 - 34
src/collision/CollisionAlgorithmsMatrix.cpp

@@ -81,21 +81,21 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& /*a*/, const Ls& /*b*/)
 //==============================================================================
 //==============================================================================
 bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Obb& obb)
 bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Obb& obb)
 {
 {
-	float maxS = std::numeric_limits<float>::min();
-	float minT = std::numeric_limits<float>::max();
+	F32 maxS = std::numeric_limits<F32>::min();
+	F32 minT = std::numeric_limits<F32>::max();
 
 
 	// compute difference vector
 	// compute difference vector
 	Vec3 diff = obb.getCenter() - ls.getOrigin();
 	Vec3 diff = obb.getCenter() - ls.getOrigin();
 
 
 	// for each axis do
 	// for each axis do
-	for(int i = 0; i < 3; ++i)
+	for(U i = 0; i < 3; ++i)
 	{
 	{
 		// get axis i
 		// get axis i
 		Vec3 axis = obb.getRotation().getColumn(i);
 		Vec3 axis = obb.getRotation().getColumn(i);
 
 
 		// project relative vector onto axis
 		// project relative vector onto axis
-		float e = axis.dot(diff);
-		float f = ls.getDirection().dot(axis);
+		F32 e = axis.dot(diff);
+		F32 f = ls.getDirection().dot(axis);
 
 
 		// ray is parallel to plane
 		// ray is parallel to plane
 		if(Math::isZero(f))
 		if(Math::isZero(f))
@@ -108,13 +108,13 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Obb& obb)
 			continue;
 			continue;
 		}
 		}
 
 
-		float s = (e - obb.getExtend()[i]) / f;
-		float t = (e + obb.getExtend()[i]) / f;
+		F32 s = (e - obb.getExtend()[i]) / f;
+		F32 t = (e + obb.getExtend()[i]) / f;
 
 
 		// fix order
 		// fix order
 		if(s > t)
 		if(s > t)
 		{
 		{
-			float temp = s;
+			F32 temp = s;
 			s = t;
 			s = t;
 			t = temp;
 			t = temp;
 		}
 		}
@@ -164,8 +164,8 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Sphere& s)
 {
 {
 	const Vec3& v = ls.getDirection();
 	const Vec3& v = ls.getDirection();
 	Vec3 w0 = s.getCenter() - ls.getOrigin();
 	Vec3 w0 = s.getCenter() - ls.getOrigin();
-	float w0dv = w0.dot(v);
-	float rsq = s.getRadius() * s.getRadius();
+	F32 w0dv = w0.dot(v);
+	F32 rsq = s.getRadius() * s.getRadius();
 
 
 	if(w0dv < 0.0) // if the ang is >90
 	if(w0dv < 0.0) // if the ang is >90
 	{
 	{
@@ -173,7 +173,7 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Sphere& s)
 	}
 	}
 
 
 	Vec3 w1 = w0 - v; // aka center - P1, where P1 = seg.origin + seg.dir
 	Vec3 w1 = w0 - v; // aka center - P1, where P1 = seg.origin + seg.dir
-	float w1dv = w1.dot(v);
+	F32 w1dv = w1.dot(v);
 
 
 	if(w1dv > 0.0) // if the ang is <90
 	if(w1dv > 0.0) // if the ang is <90
 	{
 	{
@@ -188,11 +188,11 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Sphere& s)
 //==============================================================================
 //==============================================================================
 bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Aabb& aabb)
 bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Aabb& aabb)
 {
 {
-	float maxS = std::numeric_limits<float>::min();
-	float minT = std::numeric_limits<float>::max();
+	F32 maxS = std::numeric_limits<F32>::min();
+	F32 minT = std::numeric_limits<F32>::max();
 
 
 	// do tests against three sets of planes
 	// do tests against three sets of planes
-	for(int i = 0; i < 3; ++i)
+	for(U i = 0; i < 3; ++i)
 	{
 	{
 		// segment is parallel to plane
 		// segment is parallel to plane
 		if(Math::isZero(ls.getDirection()[i]))
 		if(Math::isZero(ls.getDirection()[i]))
@@ -207,13 +207,13 @@ bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Aabb& aabb)
 		else
 		else
 		{
 		{
 			// compute intersection parameters and sort
 			// compute intersection parameters and sort
-			float s = (aabb.getMin()[i] - ls.getOrigin()[i]) 
+			F32 s = (aabb.getMin()[i] - ls.getOrigin()[i]) 
 				/ ls.getDirection()[i];
 				/ ls.getDirection()[i];
-			float t = (aabb.getMax()[i] - ls.getOrigin()[i]) 
+			F32 t = (aabb.getMax()[i] - ls.getOrigin()[i]) 
 				/ ls.getDirection()[i];
 				/ ls.getDirection()[i];
 			if(s > t)
 			if(s > t)
 			{
 			{
-				float temp = s;
+				F32 temp = s;
 				s = t;
 				s = t;
 				t = temp;
 				t = temp;
 			}
 			}
@@ -252,7 +252,7 @@ bool CollisionAlgorithmsMatrix::collide(const Obb& o0, const Obb& o1)
 	const Vec3& b = o1.getExtend();
 	const Vec3& b = o1.getExtend();
 
 
 	// test factors
 	// test factors
-	float cTest, aTest, bTest;
+	F32 cTest, aTest, bTest;
 	bool parallelAxes = false;
 	bool parallelAxes = false;
 
 
 	// transpose of rotation of B relative to A, i.e. (R_b^T * R_a)^T
 	// transpose of rotation of B relative to A, i.e. (R_b^T * R_a)^T
@@ -260,9 +260,9 @@ bool CollisionAlgorithmsMatrix::collide(const Obb& o0, const Obb& o1)
 
 
 	// absolute value of relative rotation matrix
 	// absolute value of relative rotation matrix
 	Mat3 rabs;
 	Mat3 rabs;
-	for(uint i = 0; i < 3; ++i)
+	for(U i = 0; i < 3; ++i)
 	{
 	{
-		for(uint j = 0; j < 3; ++j)
+		for(U j = 0; j < 3; ++j)
 		{
 		{
 			rabs(i, j) = fabs(rt(i, j));
 			rabs(i, j) = fabs(rt(i, j));
 			// if magnitude of dot product between axes is close to one
 			// if magnitude of dot product between axes is close to one
@@ -547,16 +547,16 @@ bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Sphere& s)
 {
 {
 	Vec3 w(s.getCenter() - r.getOrigin());
 	Vec3 w(s.getCenter() - r.getOrigin());
 	const Vec3& v = r.getDirection();
 	const Vec3& v = r.getDirection();
-	float proj = v.dot(w);
-	float wsq = w.getLengthSquared();
-	float rsq = s.getRadius() * s.getRadius();
+	F32 proj = v.dot(w);
+	F32 wsq = w.getLengthSquared();
+	F32 rsq = s.getRadius() * s.getRadius();
 
 
 	if(proj < 0.0 && wsq > rsq)
 	if(proj < 0.0 && wsq > rsq)
 	{
 	{
 		return false;
 		return false;
 	}
 	}
 
 
-	float vsq = v.getLengthSquared();
+	F32 vsq = v.getLengthSquared();
 
 
 	return (vsq * wsq - proj * proj <= vsq * rsq);
 	return (vsq * wsq - proj * proj <= vsq * rsq);
 }
 }
@@ -564,11 +564,11 @@ bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Sphere& s)
 //==============================================================================
 //==============================================================================
 bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Aabb& aabb)
 bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Aabb& aabb)
 {
 {
-	float maxS = std::numeric_limits<float>::min();
-	float minT = std::numeric_limits<float>::max();
+	F32 maxS = std::numeric_limits<F32>::min();
+	F32 minT = std::numeric_limits<F32>::max();
 
 
 	// do tests against three sets of planes
 	// do tests against three sets of planes
-	for(int i = 0; i < 3; ++i)
+	for(U i = 0; i < 3; ++i)
 	{
 	{
 		// ray is parallel to plane
 		// ray is parallel to plane
 		if(Math::isZero(r.getDirection()[i]))
 		if(Math::isZero(r.getDirection()[i]))
@@ -583,13 +583,13 @@ bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Aabb& aabb)
 		else
 		else
 		{
 		{
 			// compute intersection parameters and sort
 			// compute intersection parameters and sort
-			float s = (aabb.getMin()[i] - r.getOrigin()[i]) /
+			F32 s = (aabb.getMin()[i] - r.getOrigin()[i]) /
 				r.getDirection()[i];
 				r.getDirection()[i];
-			float t = (aabb.getMax()[i] - r.getOrigin()[i]) /
+			F32 t = (aabb.getMax()[i] - r.getOrigin()[i]) /
 				r.getDirection()[i];
 				r.getDirection()[i];
 			if(s > t)
 			if(s > t)
 			{
 			{
-				float temp = s;
+				F32 temp = s;
 				s = t;
 				s = t;
 				t = temp;
 				t = temp;
 			}
 			}
@@ -624,7 +624,7 @@ bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Aabb& aabb)
 //==============================================================================
 //==============================================================================
 bool CollisionAlgorithmsMatrix::collide(const Sphere& a, const Sphere& b)
 bool CollisionAlgorithmsMatrix::collide(const Sphere& a, const Sphere& b)
 {
 {
-	float tmp = a.getRadius() + b.getRadius();
+	F32 tmp = a.getRadius() + b.getRadius();
 	return (a.getCenter() - b.getCenter()).getLengthSquared() <= tmp * tmp;
 	return (a.getCenter() - b.getCenter()).getLengthSquared() <= tmp * tmp;
 }
 }
 
 
@@ -635,7 +635,7 @@ bool CollisionAlgorithmsMatrix::collide(const Sphere& s, const Aabb& aabb)
 
 
 	// find the box's closest point to the sphere
 	// find the box's closest point to the sphere
 	Vec3 cp; // Closest Point
 	Vec3 cp; // Closest Point
-	for(uint i = 0; i < 3; i++)
+	for(U i = 0; i < 3; i++)
 	{
 	{
 		// if the center is greater than the max then the closest
 		// if the center is greater than the max then the closest
 		// point is the max
 		// point is the max
@@ -654,9 +654,9 @@ bool CollisionAlgorithmsMatrix::collide(const Sphere& s, const Aabb& aabb)
 		}
 		}
 	}
 	}
 
 
-	float rsq = s.getRadius() * s.getRadius();
+	F32 rsq = s.getRadius() * s.getRadius();
 
 
-	// if the c lies totaly inside the box then the sub is the zero,
+	// if the c lies totally inside the box then the sub is the zero,
 	// this means that the length is also zero and thus its always smaller
 	// this means that the length is also zero and thus its always smaller
 	// than rsq
 	// than rsq
 	Vec3 sub = c - cp;
 	Vec3 sub = c - cp;

+ 16 - 16
src/collision/Frustum.cpp

@@ -49,14 +49,14 @@ PerspectiveFrustum& PerspectiveFrustum::operator=(const PerspectiveFrustum& b)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-float PerspectiveFrustum::testPlane(const Plane& p) const
+F32 PerspectiveFrustum::testPlane(const Plane& p) const
 {
 {
-	float o = 0.0;
+	F32 o = 0.0;
 
 
 	for(const Vec3& dir : dirs)
 	for(const Vec3& dir : dirs)
 	{
 	{
 		LineSegment ls(eye, dir);
 		LineSegment ls(eye, dir);
-		float t = ls.testPlane(p);
+		F32 t = ls.testPlane(p);
 
 
 		if(t == 0)
 		if(t == 0)
 		{
 		{
@@ -101,7 +101,7 @@ void PerspectiveFrustum::setTransform(const Transform& trf_)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void PerspectiveFrustum::getAabb(Aabb& aabb) const
+void PerspectiveFrustum::toAabb(Aabb& aabb) const
 {
 {
 	std::array<Vec3, 5> points = {{
 	std::array<Vec3, 5> points = {{
 		dirs[0], dirs[1], dirs[2], dirs[3], Vec3(0.0)}};
 		dirs[0], dirs[1], dirs[2], dirs[3], Vec3(0.0)}};
@@ -115,7 +115,7 @@ void PerspectiveFrustum::recalculate()
 {
 {
 	// Planes
 	// Planes
 	//
 	//
-	float c, s; // cos & sine
+	F32 c, s; // cos & sine
 
 
 	Math::sinCos(Math::PI + fovX / 2, s, c);
 	Math::sinCos(Math::PI + fovX / 2, s, c);
 	// right
 	// right
@@ -138,9 +138,9 @@ void PerspectiveFrustum::recalculate()
 	//
 	//
 	eye = Vec3(0.0, 0.0, -near);
 	eye = Vec3(0.0, 0.0, -near);
 
 
-	float x = far / tan((Math::PI - fovX) / 2.0);
-	float y = tan(fovY / 2.0) * far;
-	float z = -far;
+	F32 x = far / tan((Math::PI - fovX) / 2.0);
+	F32 y = tan(fovY / 2.0) * far;
+	F32 z = -far;
 
 
 	dirs[0] = Vec3(x, y, z - near); // top right
 	dirs[0] = Vec3(x, y, z - near); // top right
 	dirs[1] = Vec3(-x, y, z - near); // top left
 	dirs[1] = Vec3(-x, y, z - near); // top left
@@ -159,8 +159,8 @@ Mat4 PerspectiveFrustum::calculateProjectionMatrix() const
 	ANKI_ASSERT(fovX != 0.0 && fovX != 0.0);
 	ANKI_ASSERT(fovX != 0.0 && fovX != 0.0);
 	Mat4 projectionMat;
 	Mat4 projectionMat;
 
 
-	float f = 1.0 / tan(fovY * 0.5); // f = cot(fovY/2)
-	float g = near - far;
+	F32 f = 1.0 / tan(fovY * 0.5); // f = cot(fovY/2)
+	F32 g = near - far;
 
 
 	projectionMat(0, 0) = f * fovY / fovX; // = f/aspectRatio;
 	projectionMat(0, 0) = f * fovY / fovX; // = f/aspectRatio;
 	projectionMat(0, 1) = 0.0;
 	projectionMat(0, 1) = 0.0;
@@ -218,12 +218,12 @@ Mat4 OrthographicFrustum::calculateProjectionMatrix() const
 {
 {
 	ANKI_ASSERT(right != 0.0 && left != 0.0 && top != 0.0 && bottom != 0.0
 	ANKI_ASSERT(right != 0.0 && left != 0.0 && top != 0.0 && bottom != 0.0
 		&& near != 0.0 && far != 0.0);
 		&& near != 0.0 && far != 0.0);
-	float difx = right - left;
-	float dify = top - bottom;
-	float difz = far - near;
-	float tx = -(right + left) / difx;
-	float ty = -(top + bottom) / dify;
-	float tz = -(far + near) / difz;
+	F32 difx = right - left;
+	F32 dify = top - bottom;
+	F32 difz = far - near;
+	F32 tx = -(right + left) / difx;
+	F32 ty = -(top + bottom) / dify;
+	F32 tz = -(far + near) / difz;
 	Mat4 m;
 	Mat4 m;
 
 
 	m(0, 0) = 2.0 / difx;
 	m(0, 0) = 2.0 / difx;

+ 6 - 6
src/collision/LineSegment.cpp

@@ -6,14 +6,14 @@
 namespace anki {
 namespace anki {
 
 
 //==============================================================================
 //==============================================================================
-float LineSegment::testPlane(const Plane& p) const
+F32 LineSegment::testPlane(const Plane& p) const
 {
 {
 	const LineSegment& ls = *this;
 	const LineSegment& ls = *this;
 	const Vec3& p0 = ls.getOrigin();
 	const Vec3& p0 = ls.getOrigin();
 	Vec3 p1 = ls.getOrigin() + ls.getDirection();
 	Vec3 p1 = ls.getOrigin() + ls.getDirection();
 
 
-	float dist0 = p.test(p0);
-	float dist1 = p.test(p1);
+	F32 dist0 = p.test(p0);
+	F32 dist1 = p.test(p1);
 
 
 	if(dist0 > 0.0)
 	if(dist0 > 0.0)
 	{
 	{
@@ -49,16 +49,16 @@ LineSegment LineSegment::getTransformed(const Transform& transform) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void LineSegment::getAabb(Aabb& aabb) const
+void LineSegment::toAabb(Aabb& aabb) const
 {
 {
 	Vec3 min = origin;
 	Vec3 min = origin;
 	Vec3 max = origin + dir;
 	Vec3 max = origin + dir;
 
 
-	for(uint i = 0; i < 3; ++i)
+	for(U i = 0; i < 3; ++i)
 	{
 	{
 		if(max[i] < min[i])
 		if(max[i] < min[i])
 		{
 		{
-			float tmp = max[i];
+			F32 tmp = max[i];
 			max[i] = min[i];
 			max[i] = min[i];
 			min[i] = tmp;
 			min[i] = tmp;
 		}
 		}

+ 6 - 6
src/collision/Obb.cpp

@@ -17,18 +17,18 @@ Obb::Obb(const Vec3& center_, const Mat3& rotation_, const Vec3& extends_)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================
-float Obb::testPlane(const Plane& p) const
+F32 Obb::testPlane(const Plane& p) const
 {
 {
 	const Obb& obb = *this;
 	const Obb& obb = *this;
 	Vec3 xNormal = obb.getRotation().getTransposed() * p.getNormal();
 	Vec3 xNormal = obb.getRotation().getTransposed() * p.getNormal();
 
 
 	// maximum extent in direction of plane normal
 	// maximum extent in direction of plane normal
-	float r =
+	F32 r =
 		fabs(obb.getExtend().x() * xNormal.x()) +
 		fabs(obb.getExtend().x() * xNormal.x()) +
 		fabs(obb.getExtend().y() * xNormal.y()) +
 		fabs(obb.getExtend().y() * xNormal.y()) +
 		fabs(obb.getExtend().z() * xNormal.z());
 		fabs(obb.getExtend().z() * xNormal.z());
 	// signed distance between box center and plane
 	// signed distance between box center and plane
-	float d = p.test(obb.getCenter());
+	F32 d = p.test(obb.getCenter());
 
 
 	// return signed distance
 	// return signed distance
 	if(fabs(d) < r)
 	if(fabs(d) < r)
@@ -67,7 +67,7 @@ Obb Obb::getCompoundShape(const Obb& b) const
 	b.getExtremePoints(points1);
 	b.getExtremePoints(points1);
 
 
 	std::array<Vec3, 16> points;
 	std::array<Vec3, 16> points;
-	for(uint i = 0; i < 8; i++)
+	for(U i = 0; i < 8; i++)
 	{
 	{
 		points[i] = points0[i];
 		points[i] = points0[i];
 		points[i + 8] = points1[i];
 		points[i + 8] = points1[i];
@@ -120,10 +120,10 @@ void Obb::getExtremePoints(std::array<Vec3, 8>& points) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Obb::getAabb(Aabb& aabb) const
+void Obb::toAabb(Aabb& aabb) const
 {
 {
 	Mat3 absM;
 	Mat3 absM;
-	for(int i = 0; i < 9; ++i)
+	for(U i = 0; i < 9; ++i)
 	{
 	{
 		absM[i] = fabs(rotation[i]);
 		absM[i] = fabs(rotation[i]);
 	}
 	}

+ 6 - 6
src/collision/Plane.cpp

@@ -9,12 +9,12 @@ Plane::Plane(const Plane& b)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================
-Plane::Plane(const Vec3& normal_, float offset_)
+Plane::Plane(const Vec3& normal_, F32 offset_)
 	: CollisionShape(CST_PLANE), normal(normal_), offset(offset_)
 	: CollisionShape(CST_PLANE), normal(normal_), offset(offset_)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================
-float Plane::testPlane(const Plane& /*p*/) const
+F32 Plane::testPlane(const Plane& /*p*/) const
 {
 {
 	ANKI_ASSERT(0 && "Ambiguous call");
 	ANKI_ASSERT(0 && "Ambiguous call");
 	return 0.0;
 	return 0.0;
@@ -37,10 +37,10 @@ void Plane::setFrom3Points(const Vec3& p0, const Vec3& p1, const Vec3& p2)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Plane::setFromPlaneEquation(float a, float b, float c, float d)
+void Plane::setFromPlaneEquation(F32 a, F32 b, F32 c, F32 d)
 {
 {
 	// normalize for cheap distance checks
 	// normalize for cheap distance checks
-	float lensq = a * a + b * b + c * c;
+	F32 lensq = a * a + b * b + c * c;
 	// length of normal had better not be zero
 	// length of normal had better not be zero
 	ANKI_ASSERT(!Math::isZero(lensq));
 	ANKI_ASSERT(!Math::isZero(lensq));
 
 
@@ -52,7 +52,7 @@ void Plane::setFromPlaneEquation(float a, float b, float c, float d)
 	}
 	}
 	else
 	else
 	{
 	{
-		float recip = 1.0 / sqrt(lensq);
+		F32 recip = 1.0 / sqrt(lensq);
 		normal = Vec3(a * recip, b * recip, c * recip);
 		normal = Vec3(a * recip, b * recip, c * recip);
 		offset = d * recip;
 		offset = d * recip;
 	}
 	}
@@ -74,7 +74,7 @@ Plane Plane::getTransformed(const Transform& trf) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Plane::getAabb(Aabb&) const
+void Plane::toAabb(Aabb&) const
 {
 {
 	ANKI_ASSERT(0 && "Can't do that");
 	ANKI_ASSERT(0 && "Can't do that");
 }
 }

+ 4 - 4
src/collision/Ray.cpp

@@ -13,11 +13,11 @@ Ray Ray::getTransformed(const Transform& transform) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-float Ray::testPlane(const Plane& p) const
+F32 Ray::testPlane(const Plane& p) const
 {
 {
 	const Ray& r = *this;
 	const Ray& r = *this;
-	float dist = p.test(r.getOrigin());
-	float cos_ = p.getNormal().dot(r.getDirection());
+	F32 dist = p.test(r.getOrigin());
+	F32 cos_ = p.getNormal().dot(r.getDirection());
 
 
 	if(cos_ > 0.0) // the ray points to the same half-space as the plane
 	if(cos_ > 0.0) // the ray points to the same half-space as the plane
 	{
 	{
@@ -44,7 +44,7 @@ float Ray::testPlane(const Plane& p) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Ray::getAabb(Aabb&) const
+void Ray::toAabb(Aabb&) const
 {
 {
 	ANKI_ASSERT(0 && "Can't do that");
 	ANKI_ASSERT(0 && "Can't do that");
 }
 }

+ 8 - 8
src/collision/Sphere.cpp

@@ -5,10 +5,10 @@
 namespace anki {
 namespace anki {
 
 
 //==============================================================================
 //==============================================================================
-float Sphere::testPlane(const Plane& p) const
+F32 Sphere::testPlane(const Plane& p) const
 {
 {
 	const Sphere& s = *this;
 	const Sphere& s = *this;
-	float dist = p.test(s.getCenter());
+	F32 dist = p.test(s.getCenter());
 
 
 	if(dist > s.getRadius())
 	if(dist > s.getRadius())
 	{
 	{
@@ -46,9 +46,9 @@ Sphere Sphere::getCompoundShape(const Sphere& b) const
 	/// @todo test this
 	/// @todo test this
 	/*
 	/*
 	Vec3 centerDiff = b.center - a.center;
 	Vec3 centerDiff = b.center - a.center;
-	float radiusDiff = b.radius - a.radius;
+	F32 radiusDiff = b.radius - a.radius;
 	Vec3 radiusDiffSqr = radiusDiff * radiusDiff;
 	Vec3 radiusDiffSqr = radiusDiff * radiusDiff;
-	float lenSqr = centerDiff.getLengthSquared();
+	F32 lenSqr = centerDiff.getLengthSquared();
 
 
 	if(radiusDiffSqrt >= 0.0)
 	if(radiusDiffSqrt >= 0.0)
 	{
 	{
@@ -63,8 +63,8 @@ Sphere Sphere::getCompoundShape(const Sphere& b) const
 	}
 	}
 	else
 	else
 	{
 	{
-		float l = sqrt(lenSqr);
-		float t = (l + b.radius - a.radius) / (2.0 * l);
+		F32 l = sqrt(lenSqr);
+		F32 t = (l + b.radius - a.radius) / (2.0 * l);
 		return Sphere(a.center + t * centerDiff, (l + a.radius + b.radius) /
 		return Sphere(a.center + t * centerDiff, (l + a.radius + b.radius) /
 			2.0);
 			2.0);
 	}
 	}
@@ -72,7 +72,7 @@ Sphere Sphere::getCompoundShape(const Sphere& b) const
 
 
 	Vec3 c = b.getCenter() - a.getCenter(); // Vector from one center to the
 	Vec3 c = b.getCenter() - a.getCenter(); // Vector from one center to the
 	                                        // other
 	                                        // other
-	float cLen = c.getLength();
+	F32 cLen = c.getLength();
 
 
 	if(cLen + b.getRadius() < a.getRadius())
 	if(cLen + b.getRadius() < a.getRadius())
 	{
 	{
@@ -92,7 +92,7 @@ Sphere Sphere::getCompoundShape(const Sphere& b) const
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void Sphere::getAabb(Aabb& aabb) const
+void Sphere::toAabb(Aabb& aabb) const
 {
 {
 	aabb.setMin(center - radius);
 	aabb.setMin(center - radius);
 	aabb.setMax(center + radius);
 	aabb.setMax(center + radius);

+ 23 - 9
src/math/F16.cpp

@@ -2,11 +2,21 @@
 
 
 namespace anki {
 namespace anki {
 
 
+//==============================================================================
+union Val32
+{
+	I32 i;
+	F32 f;
+	U32 u;
+};
+
 //==============================================================================
 //==============================================================================
 F16 F16::toF16(F32 f)
 F16 F16::toF16(F32 f)
 {
 {
 	F16 out;
 	F16 out;
-	I32 i = *(I32*)(&f);
+	Val32 v32;
+	v32.f = f;
+	I32 i = v32.i;
 	I32 s = (i >> 16) & 0x00008000;
 	I32 s = (i >> 16) & 0x00008000;
 	I32 e = ((i >> 23) & 0x000000ff) - (127 - 15);
 	I32 e = ((i >> 23) & 0x000000ff) - (127 - 15);
 	I32 m = i & 0x007fffff;
 	I32 m = i & 0x007fffff;
@@ -81,8 +91,9 @@ F32 F16::toF32(F16 h)
 	{
 	{
 		if(m == 0)
 		if(m == 0)
 		{
 		{
-			i = s << 31;
-			return *(F32*)&i;
+			Val32 v32;
+			v32.i = s << 31;
+			return v32.f;
 		}
 		}
 		else
 		else
 		{
 		{
@@ -100,21 +111,24 @@ F32 F16::toF32(F16 h)
 	{
 	{
 		if(m == 0)
 		if(m == 0)
 		{
 		{
-			i = (s << 31) | 0x7f800000;
-			return *(F32*)&i;
+			Val32 v32;
+			v32.i = (s << 31) | 0x7f800000;
+			return v32.f;
 		}
 		}
 		else
 		else
 		{
 		{
-			i = (s << 31) | 0x7f800000 | (m << 13);
-			return *(F32*)&i;
+			Val32 v32;
+			v32.i = (s << 31) | 0x7f800000 | (m << 13);
+			return v32.f;
 		}
 		}
 	}
 	}
 
 
 	e = e + (127 - 15);
 	e = e + (127 - 15);
 	m = m << 13;
 	m = m << 13;
 
 
-	i = (s << 31) | (e << 23) | m;
-	return *(F32*)&i;
+	Val32 v32;
+	v32.i = (s << 31) | (e << 23) | m;
+	return v32.f;
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 29 - 34
src/math/Math.cpp

@@ -1,61 +1,57 @@
 #include "anki/math/MathCommonSrc.h"
 #include "anki/math/MathCommonSrc.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
-const float Math::PI = 3.14159265358979323846;
-const float Math::EPSILON = 1.0e-6;
-
+const F32 Math::PI = 3.14159265358979323846;
+const F32 Math::EPSILON = 1.0e-6;
 
 
 //==============================================================================
 //==============================================================================
-float Math::polynomialSinQuadrant(const float a)
+F32 Math::polynomialSinQuadrant(const F32 a)
 {
 {
 	return a * (1.0 + a * a * (-0.16666 + a * a *
 	return a * (1.0 + a * a * (-0.16666 + a * a *
 		(0.0083143 - a * a * 0.00018542)));
 		(0.0083143 - a * a * 0.00018542)));
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
-void Math::sinCos(const float a_, float& sina, float& cosa)
+void Math::sinCos(const F32 a_, F32& sina, F32& cosa)
 {
 {
-	bool negative = false;
-	float a = a_;
+	Bool negative = false;
+	F32 a = a_;
 	if(a < 0.0)
 	if(a < 0.0)
 	{
 	{
 		a = -a;
 		a = -a;
 		negative = true;
 		negative = true;
 	}
 	}
-	const float TWO_OVER_PI = 1.0 / (PI / 2.0);
-	float floatA = TWO_OVER_PI * a;
-	int intA = (int)floatA;
+	const F32 TWO_OVER_PI = 1.0 / (PI / 2.0);
+	F32 floatA = TWO_OVER_PI * a;
+	I intA = (int)floatA;
 
 
-	const float RATIONAL_HALF_PI = 201 / 128.0;
-	const float REMAINDER_HALF_PI = 4.8382679e-4;
+	const F32 RATIONAL_HALF_PI = 201 / 128.0;
+	const F32 REMAINDER_HALF_PI = 4.8382679e-4;
 
 
 	floatA = (a - RATIONAL_HALF_PI * intA) - REMAINDER_HALF_PI * intA;
 	floatA = (a - RATIONAL_HALF_PI * intA) - REMAINDER_HALF_PI * intA;
 
 
-	float floatAMinusHalfPi = (floatA - RATIONAL_HALF_PI) - REMAINDER_HALF_PI;
+	F32 floatAMinusHalfPi = (floatA - RATIONAL_HALF_PI) - REMAINDER_HALF_PI;
 
 
 	switch(intA & 3)
 	switch(intA & 3)
 	{
 	{
-		case 0: // 0 - Pi/2
-			sina = polynomialSinQuadrant(floatA);
-			cosa = polynomialSinQuadrant(-floatAMinusHalfPi);
-			break;
-		case 1: // Pi/2 - Pi
-			sina = polynomialSinQuadrant(-floatAMinusHalfPi);
-			cosa = polynomialSinQuadrant(-floatA);
-			break;
-		case 2: // Pi - 3Pi/2
-			sina = polynomialSinQuadrant(-floatA);
-			cosa = polynomialSinQuadrant(floatAMinusHalfPi);
-			break;
-		case 3: // 3Pi/2 - 2Pi
-			sina = polynomialSinQuadrant(floatAMinusHalfPi);
-			cosa = polynomialSinQuadrant(floatA);
-			break;
+	case 0: // 0 - Pi/2
+		sina = polynomialSinQuadrant(floatA);
+		cosa = polynomialSinQuadrant(-floatAMinusHalfPi);
+		break;
+	case 1: // Pi/2 - Pi
+		sina = polynomialSinQuadrant(-floatAMinusHalfPi);
+		cosa = polynomialSinQuadrant(-floatA);
+		break;
+	case 2: // Pi - 3Pi/2
+		sina = polynomialSinQuadrant(-floatA);
+		cosa = polynomialSinQuadrant(floatAMinusHalfPi);
+		break;
+	case 3: // 3Pi/2 - 2Pi
+		sina = polynomialSinQuadrant(floatAMinusHalfPi);
+		cosa = polynomialSinQuadrant(floatA);
+		break;
 	};
 	};
 
 
 	if(negative)
 	if(negative)
@@ -64,5 +60,4 @@ void Math::sinCos(const float a_, float& sina, float& cosa)
 	}
 	}
 }
 }
 
 
-
-} // end namespace
+} // end namespace anki

+ 30 - 4
src/renderer/Is.cpp

@@ -199,11 +199,37 @@ void Is::projectShape(const Camera& cam,
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-Bool Is::circleIntersects(const Tile& tile, const Vec2& circleCenter,
-	F32 circleRadius)
+Bool Is::circleIntersects(const Tile& tile, const Vec2& c, F32 r)
 {
 {
-	// XXX
-	return true;
+	// For more info about the algorithm see the collision between an AABB and
+	// a sphere
+
+	Vec2 cp; // Closes point
+	for(U i = 0; i < 2; i++)
+	{
+		if(c[i] > tile.coords[1][i])
+		{
+			cp[i] = tile.coords[1][i];
+		}
+		else if(c[i] < tile.coords[0][i])
+		{
+			cp[i] = tile.coords[0][i];
+		}
+		else
+		{
+			cp[i] = c[i];
+		}
+	}
+
+	F32 rsq = r * r;
+	Vec2 sub = c - cp;
+
+	if(sub.getLengthSquared() <= rsq)
+	{
+		return true;
+	}
+
+	return false;
 }
 }
 
 
 //==============================================================================
 //==============================================================================