Commits

Lazar Sumar  committed 5d10b0f

Added Point3 class.

  • Participants
  • Parent commits 2e9ed36

Comments (0)

Files changed (4)

File Math/Point3.cpp

+/** class:     Point3
+  * Author:    Lazar Sumar
+  * Date:      10th August 2011
+  * Copyright: GPL, use but please give me due credit.
+  */
+#include "Point3.h"
+
+Point3::Point3() {
+	_x = _y = _z = 0.0;
+}
+
+Point3::Point3(double x, double y, double z) {
+	_x = x;
+	_y = y;
+	_z = z;
+}
+
+Point3::Point3(const Point3& v) {
+	_x = v._x;
+	_y = v._y;
+	_z = v._z;
+}
+
+Point3::Point3(const Point3* v) {
+	_x = v->_x;
+	_y = v->_y;
+	_z = v->_z;
+}
+
+Point3::~Point3() {
+	// Empty
+}
+
+Point3& Point3::operator=(const Point3& v) {
+	_x = v._x;
+	_y = v._y;
+	_z = v._z;
+
+	return *this;
+}
+
+// Getters
+double Point3::getX() const {
+	return _x;
+}
+
+double Point3::getY() const {
+	return _y;
+}
+
+double Point3::getZ() const {
+	return _z;
+}
+
+bool Point3::isOrigin() const {
+	return (_x == 0.0 && _y == 0.0 && _z == 0.0);
+}
+
+#ifdef VECTOR3_H
+
+Point3& Point3::operator+=(const Vector3& v) {
+	_x += v.getX();
+	_y += v.getY();
+	_z += v.getZ();
+
+	return *this;
+}
+
+Vector3 Point3::operator-(const Point3& p) const {
+	return Vector3(_x - p._x, _y - p._y, _z - p._z);
+}
+
+Point3 Point3::operator+(const Vector3& v) const {
+	Point3 p(this);
+
+	p += v;
+
+	return p;
+}
+
+#endif
+
+// Comparison operators
+int Point3::operator==(const Point3& p) const {
+	return (_x == p._x && _y == p._y && _z == p._z);
+}
+
+int Point3::operator!=(const Point3& p) const {
+	return !(*this == p);
+}
+

File Math/Point3.h

+/** class:     Point3
+  * Author:    Lazar Sumar
+  * Date:      10th August 2011
+  * Copyright: GPL, use but please give me due credit.
+  */
+#pragma once
+
+#include "Vector3.h"
+
+#ifndef POINT3_H
+#define POINT3_H
+
+class Point3 {
+private:
+	double _x, _y, _z;
+public:
+	Point3();
+	Point3(double x, double y, double z);
+	Point3(const Point3& v);
+	Point3(const Point3* v);
+	~Point3();
+
+	Point3& operator=(const Point3& v);
+
+	// Getters
+	double getX() const;
+	double getY() const;
+	double getZ() const;
+
+	// member functions and operations on vectors
+	bool isOrigin() const; // Test for null vector (zero vector) (0, 0, 0)
+	
+#ifdef VECTOR3_H
+	// assignment operators
+	Point3& operator+=(const Vector3& v);
+	
+	// operators
+	Vector3 operator-(const Point3& p) const;
+	Point3 operator+(const Vector3& v) const;
+#endif
+
+	// Comparison operators
+	int operator==(const Point3& v) const;
+	int operator!=(const Point3& v) const;
+};
+
+#endif

File vs2010/bibliotheca/bibliotheca.vcxproj

   </ItemDefinitionGroup>
   <ItemGroup>
     <ClInclude Include="..\..\Math\Geometry.h" />
+    <ClInclude Include="..\..\Math\Point3.h" />
     <ClInclude Include="..\..\Math\Vector3.h" />
     <ClInclude Include="..\..\Util\NumericStrings.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\Math\Geometry.cpp" />
+    <ClCompile Include="..\..\Math\Point3.cpp" />
     <ClCompile Include="..\..\Math\Vector3.cpp" />
     <ClCompile Include="..\..\Util\NumericStrings.cpp" />
   </ItemGroup>

File vs2010/bibliotheca/bibliotheca.vcxproj.filters

     <ClInclude Include="..\..\Util\NumericStrings.h">
       <Filter>Util\Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\Math\Point3.h">
+      <Filter>Math\Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\Math\Geometry.cpp">
     <ClCompile Include="..\..\Util\NumericStrings.cpp">
       <Filter>Util\Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\Math\Point3.cpp">
+      <Filter>Math\Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>