Browse Source

Changes in the printing of the math classes

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
75f015bb98

+ 6 - 14
src/Main.cpp

@@ -411,6 +411,12 @@ void mainLoop()
 }
 
 
+ostream& operator<<(ostream& s, const Vec3& v)
+{
+	s << fixed << v.x << ' ' << v.y << ' ' << v.z;
+	return s;
+}
+
 //======================================================================================================================
 // main                                                                                                                =
 //======================================================================================================================
@@ -418,20 +424,6 @@ int main(int argc, char* argv[])
 {
 	new App(argc, argv);
 
-/*	{
-		RsrcPtr<LightProps> l;
-		l.loadRsrc("/users/panoscc/Desktop/test.txt");
-		INFO(l->getRsrcReferencesNum());
-		{
-			RsrcPtr<LightProps> ll;
-			ll.loadRsrc("/users/panoscc/Desktop/test.txt");
-			INFO(l->getRsrcReferencesNum());
-		}
-		INFO(l->getRsrcReferencesNum());
-	}
-
-	return 0;*/
-
 	init();
 
 	mainLoop();

+ 4 - 2
src/Math/Euler.h

@@ -29,11 +29,13 @@ class Euler
 		         Euler(const Euler& b);
 		explicit Euler(const Quat& q);
 		explicit Euler(const Mat3& m3);
-		// other
-		void print() const;
 };
 
 
+// other operators
+extern ostream& operator<<(ostream& s, const Euler& e);
+
+
 } // end namespace
 
 

+ 6 - 0
src/Math/Euler.inl.h

@@ -119,5 +119,11 @@ inline Euler::Euler(const Mat3& m3)
 	x = atan2f(sx, cx);
 }
 
+// print
+inline ostream& operator<<(ostream& s, const Euler& e)
+{
+	s << e.x << ' ' << e.y << ' ' << e.z;
+	return s;
+}
 
 } // end namespace

+ 1 - 0
src/Math/Mat3.h

@@ -96,6 +96,7 @@ extern Mat3 operator +(float f, const Mat3& m3);
 extern Mat3 operator -(float f, const Mat3& m3);
 extern Mat3 operator *(float f, const Mat3& m3);
 extern Mat3 operator /(float f, const Mat3& m3);
+extern ostream& operator<<(ostream& s, const Mat3& m);
 
 
 } // end namespace

+ 14 - 12
src/Math/Mat3.inl.h

@@ -665,18 +665,6 @@ inline void Mat3::reorthogonalize()
 	setColumns(xAxis, yAxis, zAxis);
 }
 
-// print
-inline void Mat3::print() const
-{
-	for(int i=0; i<3; i++)
-	{
-		for(int j=0; j<3; j++)
-			cout << fixed << ME(i, j) << " ";
-		cout << endl;
-	}
-	cout << endl;
-}
-
 // Determinant
 inline float Mat3::getDet() const
 {
@@ -746,4 +734,18 @@ inline const Mat3& Mat3::getIdentity()
 	return ident;
 }
 
+// print
+inline ostream& operator<<(ostream& s, const Mat3& m)
+{
+	for(int i=0; i<3; i++)
+	{
+		for(int j=0; j<3; j++)
+			s << m(i, j) << ' ';
+
+		if(i != 2)
+			s << "\n";
+	}
+	return s;
+}
+
 } // end namespace

+ 1 - 1
src/Math/Mat4.h

@@ -72,7 +72,6 @@ class Mat4
 		Vec3  getTranslationPart() const;
 		void  transpose();
 		Mat4  getTransposed() const;
-		void  print() const;
 		float getDet() const;
 		void  invert();
 		Mat4  getInverse() const;
@@ -90,6 +89,7 @@ extern Mat4 operator +(float f, const Mat4& m4);
 extern Mat4 operator -(float f, const Mat4& m4);
 extern Mat4 operator *(float f, const Mat4& m4);
 extern Mat4 operator /(float f, const Mat4& m4);
+extern ostream& operator<<(ostream& s, const Mat4& m);
 
 
 } // end namespace

+ 13 - 18
src/Math/Mat4.inl.h

@@ -521,24 +521,6 @@ inline const Mat4& Mat4::getZero()
 	return zero;
 }
 
-// print
-inline void Mat4::print() const
-{
-	cout << fixed;
-	for(int i=0; i<4; i++)
-	{
-		for(int j=0; j<4; j++)
-		{
-			if(ME(i, j) < 0.0)
-				cout << ME(i, j) << " ";
-			else
-				cout << " " << ME(i, j) << " ";
-		}
-		cout << endl;
-	}
-	cout << endl;
-}
-
 // Determinant
 inline float Mat4::getDet() const
 {
@@ -699,5 +681,18 @@ inline Mat4 Mat4::combineTransformations(const Mat4& m0, const Mat4& m1)
 	return m4;
 }
 
+// print
+inline ostream& operator<<(ostream& s, const Mat4& m)
+{
+	for(int i=0; i<4; i++)
+	{
+		for(int j=0; j<4; j++)
+			s << m(i, j) << ' ';
+
+		if(i != 3)
+			s << "\n";
+	}
+	return s;
+}
 
 } // end namespace

+ 4 - 1
src/Math/Quat.h

@@ -40,7 +40,6 @@ class Quat
 		Quat  getConjugated() const;
 		void  normalize();
 		Quat  getNormalized() const;
-		void  print() const;
 		float dot(const Quat& b) const;
 		Quat  slerp(const Quat& q1, float t) const; ///< returns slerp(this, q1, t)
 		Quat  getRotated(const Quat& b) const; ///< The same as Quat * Quat
@@ -50,6 +49,10 @@ class Quat
 };
 
 
+// other operators
+extern ostream& operator<<(ostream& s, const Quat& q);
+
+
 } // end namespace
 
 

+ 7 - 6
src/Math/Quat.inl.h

@@ -206,12 +206,6 @@ inline void Quat::invert()
 	ME = getInverted();
 }
 
-// print
-inline void Quat::print() const
-{
-	cout << fixed << "(w,x,y,z) = " << w << ' ' << x << ' ' << y << ' ' << z  << '\n' << endl;
-}
-
 // CalcFromVecVec
 inline void Quat::setFrom2Vec3(const Vec3& from, const Vec3& to)
 {
@@ -295,4 +289,11 @@ inline const Quat::Quat& getIdentity()
 	return ident;
 }
 
+// print
+inline ostream& operator<<(ostream& s, const Quat& q)
+{
+	s << q.w << ' ' << q.x << ' ' << q.y << ' ' << q.z;
+	return s;
+}
+
 } // end namespace

+ 1 - 1
src/Math/Vec2.h

@@ -56,7 +56,6 @@ class Vec2
 		void   normalize();
 		Vec2   getNormalized() const;
 		float  dot(const Vec2& b) const;
-		void   print() const;
 };
 
 
@@ -65,6 +64,7 @@ extern Vec2 operator +(float f, const Vec2& v2);
 extern Vec2 operator -(float f, const Vec2& v2);
 extern Vec2 operator *(float f, const Vec2& v2);
 extern Vec2 operator /(float f, const Vec2& v2);
+extern ostream& operator<<(ostream& s, const Vec2& v);
 
 
 } // end namespace

+ 3 - 4
src/Math/Vec2.inl.h

@@ -236,11 +236,10 @@ inline Vec2 Vec2::getOne()
 }
 
 // print
-inline void Vec2::print() const
+inline ostream& operator<<(ostream& s, const Vec2& v)
 {
-	for(int i=0; i<2; i++)
-		cout << fixed << ME[i] << ' ';
-	cout << "\n" << endl;
+	s << v.x << ' ' << v.y;
+	return s;
 }
 
 

+ 8 - 2
src/Math/Vec3.h

@@ -61,8 +61,12 @@ class Vec3
 		Vec3  getRotated(const Quat& q) const; ///< Returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
 		void  rotate(const Quat& q);
 		Vec3  lerp(const Vec3& v1, float t) const; ///< return lerp(this, v1, t)
-		void  print() const;
-		// transformations. The faster way is by far the mat4 * vec3 or the Transformed(Vec3, Mat3)
+
+		/**
+		 * @name Transformations
+		 * The faster way is by far the mat4 * vec3 or the getTransformed(Vec3, Mat3)
+		 */
+		/**@{*/
 		Vec3  getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const;
 		void  transform(const Vec3& translate, const Mat3& rotate, float scale);
 		Vec3  getTransformed(const Vec3& translate, const Mat3& rotate) const;
@@ -75,6 +79,7 @@ class Vec3
 		void  transform(const Mat4& transform);
 		Vec3  getTransformed(const Transform& transform) const;
 		void  transform(const Transform& transform);
+		/**@}*/
 };
 
 
@@ -83,6 +88,7 @@ extern Vec3 operator +(float f, const Vec3& v);
 extern Vec3 operator -(float f, const Vec3& v);
 extern Vec3 operator *(float f, const Vec3& v);
 extern Vec3 operator /(float f, const Vec3& v);
+extern ostream& operator<<(ostream& s, const Vec3& v);
 
 
 } // end namespace

+ 6 - 8
src/Math/Vec3.inl.h

@@ -278,14 +278,6 @@ inline void Vec3::rotate(const Quat& q)
 	ME = getRotated(q);
 }
 
-// print
-inline void Vec3::print() const
-{
-	for(int i=0; i<3; i++)
-		cout << fixed << ME[i] << " ";
-	cout << "\n" << endl;
-}
-
 // lerp
 inline Vec3 Vec3::lerp(const Vec3& v1, float t) const
 {
@@ -356,5 +348,11 @@ inline void Vec3::transform(const Transform& transform)
 	ME = getTransformed(transform);
 }
 
+// print
+inline ostream& operator<<(ostream& s, const Vec3& v)
+{
+	s << v.x << ' ' << v.y << ' ' << v.z;
+	return s;
+}
 
 } // end namespace

+ 1 - 1
src/Math/Vec4.h

@@ -53,7 +53,6 @@ class Vec4
 		float getLength() const;
 		Vec4  getNormalized() const;
 		void  normalize();
-		void  print() const;
 		float dot(const Vec4& b) const;
 };
 
@@ -63,6 +62,7 @@ extern Vec4 operator +(float f, const Vec4& v4);
 extern Vec4 operator -(float f, const Vec4& v4);
 extern Vec4 operator *(float f, const Vec4& v4);
 extern Vec4 operator /(float f, const Vec4& v4);
+extern ostream& operator<<(ostream& s, const Vec4& v);
 
 
 } // end namespace

+ 3 - 5
src/Math/Vec4.inl.h

@@ -248,12 +248,10 @@ inline void Vec4::normalize()
 }
 
 // print
-inline void Vec4::print() const
+inline ostream& operator<<(ostream& s, const Vec4& v)
 {
-	for(int i=0; i<4; i++)
-		cout << fixed << ME[i] << " ";
-	cout << "\n" << endl;
+	s << v.x << ' ' << v.y << ' ' << v.z << ' ' << v.w;
+	return s;
 }
 
-
 } // end namespace

+ 1 - 1
src/Physics/Physics.cpp

@@ -43,7 +43,7 @@ btRigidBody* Physics::createNewRigidBody(float mass, const Transform& startTrans
 	btRigidBody* body = new btRigidBody(cInfo);
 	body->setContactProcessingThreshold(defaultContactProcessingThreshold);
 
-	if(mask==-1 && group==-1)
+	if(mask==-1 || group==-1)
 		dynamicsWorld->addRigidBody(body);
 	else
 		dynamicsWorld->addRigidBody(body, group, mask);