diff --git a/BaseFramework.vcxproj b/BaseFramework.vcxproj
index 5fe775d..c1b3ee3 100644
--- a/BaseFramework.vcxproj
+++ b/BaseFramework.vcxproj
@@ -146,16 +146,19 @@
+
+
+
@@ -164,6 +167,7 @@
+
diff --git a/BaseFramework.vcxproj.filters b/BaseFramework.vcxproj.filters
index bf48fe3..a13257d 100644
--- a/BaseFramework.vcxproj.filters
+++ b/BaseFramework.vcxproj.filters
@@ -39,6 +39,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -71,6 +77,12 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
diff --git a/Camera.cpp b/Camera.cpp
new file mode 100644
index 0000000..4576a2c
--- /dev/null
+++ b/Camera.cpp
@@ -0,0 +1,102 @@
+#include "Camera.h"
+
+Camera::Camera(float xRot, float yRot, float zRot, const Vertex& pos)
+{
+ _initialRotation[0] = xRot;
+ _currentRotation[0] = xRot;
+ _initialRotation[1] = yRot;
+ _currentRotation[1] = yRot;
+ _initialRotation[2] = zRot;
+ _currentRotation[2] = zRot;
+ _initialPosition = pos;
+ _currentPosition = pos;
+}
+
+Camera::Camera(const Camera& other)
+{
+ Copy(other);
+}
+
+Camera::~Camera()
+{
+}
+
+Matrix Camera::UpdateCameraPosition(const Vertex& newPos)
+{
+ _currentPosition = newPos;
+ return GetCurrentCameraTransformMatrix();
+}
+
+Matrix Camera::RotateCamera(float xRot, float yRot, float zRot)
+{
+ _currentRotation[0] = xRot;
+ _currentRotation[1] = yRot;
+ _currentRotation[2] = zRot;
+ return GetCurrentCameraTransformMatrix();
+}
+
+Matrix Camera::GetCurrentCameraTransformMatrix()
+{
+ return GetCameraRotationMatrix(Axis::X, _currentRotation[0]) * GetCameraRotationMatrix(Axis::Y, _currentRotation[1]) * GetCameraRotationMatrix(Axis::Z, _currentRotation[2]) * GetCameraTranslateMatrix(_currentPosition);
+}
+
+float Camera::GetCurrentRotationValue(const Axis axis)
+{
+ switch (axis)
+ {
+ case (Axis::X):
+ return _currentRotation[0];
+ case (Axis::Y):
+ return _currentRotation[1];
+ case (Axis::Z):
+ return _currentRotation[2];
+ default:
+ throw "No valid axis?";
+ }
+}
+
+float Camera::GetInitialRotationValue(const Axis axis)
+{
+ switch (axis)
+ {
+ case (Axis::X):
+ return _initialRotation[0];
+ case (Axis::Y):
+ return _initialRotation[1];
+ case (Axis::Z):
+ return _initialRotation[2];
+ default:
+ throw "No valid axis?";
+ }
+}
+
+Vertex Camera::GetCurrentPosition()
+{
+ return _currentPosition;
+}
+
+Vertex Camera::GetInitialPosition()
+{
+ return _initialPosition;
+}
+
+Camera& Camera::operator=(const Camera& rhs)
+{
+ if (this != &rhs)
+ {
+ Copy(rhs);
+ }
+ return *this;
+}
+
+void Camera::Copy(const Camera& other)
+{
+ _initialRotation[0] = other._initialRotation[0];
+ _currentRotation[0] = other._currentRotation[0];
+ _initialRotation[1] = other._initialRotation[1];
+ _currentRotation[1] = other._currentRotation[1];
+ _initialRotation[2] = other._initialRotation[2];
+ _currentRotation[2] = other._currentRotation[2];
+ _initialPosition = other._initialPosition;
+ _currentPosition = other._currentPosition;
+}
\ No newline at end of file
diff --git a/Camera.h b/Camera.h
new file mode 100644
index 0000000..bab2b43
--- /dev/null
+++ b/Camera.h
@@ -0,0 +1,39 @@
+#pragma once
+#include "Vertex.h"
+#include "Matrix.h"
+#include "TransformTools.h"
+
+using namespace TransformTools;
+
+class Camera
+{
+public:
+ Camera(float xRot, float yRot, float zRot, const Vertex& pos);
+ Camera(const Camera& other);
+
+ ~Camera();
+
+ Matrix UpdateCameraPosition(const Vertex& newPos);
+ Matrix RotateCamera(float xRot, float yRot, float zRot);
+
+ Matrix GetCurrentCameraTransformMatrix();
+
+ float GetCurrentRotationValue(const Axis axis);
+ float GetInitialRotationValue(const Axis axis);
+ Vertex GetCurrentPosition();
+ Vertex GetInitialPosition();
+
+ Camera& operator= (const Camera& rhs);
+
+private:
+ float _initialRotation[3] = { 0 };
+ Vertex _initialPosition;
+
+ float _currentRotation[3] = { 0 };
+ Vertex _currentPosition;
+
+ Matrix _currentCameraTransform;
+
+ void Copy(const Camera& other);
+};
+
diff --git a/Matrix.cpp b/Matrix.cpp
index 549fe5c..159c3a2 100644
--- a/Matrix.cpp
+++ b/Matrix.cpp
@@ -82,6 +82,12 @@ Matrix& Matrix::operator= (const Matrix& rhs)
return *this;
}
+Matrix& Matrix::operator*= (const Matrix& rhs)
+{
+ *this = *this * rhs;
+ return *this;
+}
+
bool Matrix::operator== (const Matrix& other) const
{
for (int i = 0; i < ROWS; i++)
diff --git a/Matrix.h b/Matrix.h
index 31f03d5..a14733d 100644
--- a/Matrix.h
+++ b/Matrix.h
@@ -28,6 +28,7 @@ public:
Matrix IdentityMatrix();
Matrix& operator= (const Matrix& rhs);
+ Matrix& operator*= (const Matrix& rhs);
bool operator==(const Matrix& other) const;
const Matrix operator*(const Matrix& other) const;
diff --git a/Model.cpp b/Model.cpp
index b6706aa..3b9d659 100644
--- a/Model.cpp
+++ b/Model.cpp
@@ -18,6 +18,11 @@ const vector& Model::GetVertices()
return _vertices;
}
+const vector& Model::GetPendingTransforms()
+{
+ return _pendingTransforms;
+}
+
size_t Model::GetPolygonCount()
{
return _polygons.size();
@@ -28,12 +33,67 @@ size_t Model::GetVerticesCount()
return _vertices.size();
}
+size_t Model::GetPendingTransformCount()
+{
+ return _pendingTransforms.size();
+}
+
void Model::AddVertex(float x, float y, float z)
{
_vertices.push_back(Vertex(x, y, z));
+ _transformedVertices.push_back(Vertex(x, y, z));
}
void Model::AddPolygon(int index0, int index1, int index2)
{
_polygons.push_back(Polygon3D(index0, index1, index2));
+}
+
+void Model::EnqueueTransform(Matrix transform)
+{
+ _pendingTransforms.push_back(transform);
+}
+
+void Model::ClearPendingTransforms()
+{
+ _pendingTransforms.clear();
+}
+
+Polygon3D Model::GetPolygon(int index)
+{
+ return _polygons[index];
+}
+
+Vertex Model::GetVertex(int polygonIndex, int vertexPolygonIndex)
+{
+ return GetVertex(GetPolygon(polygonIndex).GetIndex(vertexPolygonIndex));
+}
+
+Vertex Model::GetVertex(int index)
+{
+ return _transformedVertices[index];
+}
+
+void Model::ApplyTransformToLocalVertices(const Matrix& transform)
+{
+ for (int i = 0; i < GetVerticesCount(); i++)
+ {
+ _transformedVertices[i] = transform * _vertices[i];
+ }
+}
+
+void Model::ApplyTransformToTransformedVertices(const Matrix& transform)
+{
+ for (int i = 0; i < GetVerticesCount(); i++)
+ {
+ _transformedVertices[i] = transform * _transformedVertices[i];
+ }
+}
+
+void Model::DehomogenizeAllVertices()
+{
+ for (Vertex ¤tVertex : _transformedVertices)
+ {
+ currentVertex.Dehomogenize();
+ }
}
\ No newline at end of file
diff --git a/Model.h b/Model.h
index 593164c..56f4b3c 100644
--- a/Model.h
+++ b/Model.h
@@ -1,7 +1,7 @@
#pragma once
-
#include "Polygon3D.h"
#include "Vertex.h"
+#include "Matrix.h"
#include
using namespace std;
@@ -15,15 +15,30 @@ public:
const vector& GetPolygons();
const vector& GetVertices();
+ const vector& GetPendingTransforms();
size_t GetPolygonCount();
size_t GetVerticesCount();
+ size_t GetPendingTransformCount();
void AddVertex(float x, float y, float z);
void AddPolygon(int index0, int index1, int index2);
+ void EnqueueTransform(Matrix transform);
+ void ClearPendingTransforms();
+
+ Polygon3D GetPolygon(int index);
+ Vertex GetVertex(int polygonIndex, int vertexPolygonIndex);
+ Vertex GetVertex(int index);
+
+ void ApplyTransformToLocalVertices(const Matrix& transform);
+ void ApplyTransformToTransformedVertices(const Matrix& transform);
+ void DehomogenizeAllVertices();
private:
vector _polygons;
vector _vertices;
+ vector _transformedVertices;
+ vector _pendingTransforms;
+
};
diff --git a/Polygon3D.cpp b/Polygon3D.cpp
index 63f3a8a..2db1c3e 100644
--- a/Polygon3D.cpp
+++ b/Polygon3D.cpp
@@ -20,6 +20,11 @@ Polygon3D::~Polygon3D()
{
}
+size_t Polygon3D::GetPolygonVertexCount()
+{
+ return sizeof(_indices) / sizeof(_indices[0]);
+}
+
int Polygon3D::GetIndex(const int index) const
{
return _indices[index];
diff --git a/Polygon3D.h b/Polygon3D.h
index b6cdaef..d34456a 100644
--- a/Polygon3D.h
+++ b/Polygon3D.h
@@ -8,8 +8,10 @@ public:
~Polygon3D();
- int GetIndex(int index) const;
+ size_t GetPolygonVertexCount();
+ int GetIndex(int index) const;
+
Polygon3D& operator= (const Polygon3D& rhs);
private:
diff --git a/Rasteriser.cpp b/Rasteriser.cpp
index d35fa65..19c5fc1 100644
--- a/Rasteriser.cpp
+++ b/Rasteriser.cpp
@@ -1,47 +1,102 @@
#include "Rasteriser.h"
-#include
-
-using namespace std;
Rasteriser app;
bool Rasteriser::Initialise()
{
- //_initialVertexArray.push_back(Vertex(175, 175, 0, 1));
- //_initialVertexArray.push_back(Vertex(225, 175, 0, 1));
- //_initialVertexArray.push_back(Vertex(225, 225, 0, 1));
- //_initialVertexArray.push_back(Vertex(175, 225, 0, 1));
-
- _initialVertexArray.push_back(Vertex(150, 200, 1));
- _initialVertexArray.push_back(Vertex(187.5f, 187.5f, 1));
- _initialVertexArray.push_back(Vertex(200, 150, 1));
- _initialVertexArray.push_back(Vertex(212.5f, 187.5f, 1));
- _initialVertexArray.push_back(Vertex(250, 200, 1));
- _initialVertexArray.push_back(Vertex(212.5f, 212.5f, 1));
- _initialVertexArray.push_back(Vertex(200, 250, 1));
- _initialVertexArray.push_back(Vertex(187.5, 212.5f, 1));
+ Model modelA;
+ Model modelB;
+ Model modelC;
+ if (MD2Loader::LoadModel(".\\marvin.MD2", modelA, &Model::AddPolygon, &Model::AddVertex))
+ {
+ _sceneModels.push_back(modelA);
+ }
+ else
+ {
+ return false;
+ }
- _currentVertexArray = _initialVertexArray;
+ if (MD2Loader::LoadModel(".\\megaman.MD2", modelB, &Model::AddPolygon, &Model::AddVertex))
+ {
+ _sceneModels.push_back(modelB);
+ }
+ else
+ {
+ return false;
+ }
+
+ if (MD2Loader::LoadModel(".\\cheff.MD2", modelC, &Model::AddPolygon, &Model::AddVertex))
+ {
+ _sceneModels.push_back(modelC);
+ }
+ else
+ {
+ return false;
+ }
return true;
}
void Rasteriser::Update(const Bitmap& bitmap)
-{
+{
int currentRot = (_rotation % 360);
- for (int i = 0; i < _initialVertexArray.size(); i++) {
- Matrix currentTransfomation = GetRotationMatrixFromPoint(Axis::Z, (float) currentRot, _initialVertexArray[0].GetX(), _initialVertexArray[0].GetY(), 0);
- _currentVertexArray[i] = currentTransfomation * _initialVertexArray[i];
+ Vertex startPos = Vertex(-50, 0, 0);
+ int currentZOff = 0;
+ int currentModelIndex = 0;
+
+ for (Model ¤tModel : _sceneModels)
+ {
+ currentModel.EnqueueTransform(GetTranslateMatrix(startPos));
+ currentModel.EnqueueTransform(GetRotationMatrix(Axis::Y, (float) currentRot));
+ startPos.SetX(startPos.GetX() + 50);
+ if ((currentModelIndex % 2) == 1)
+ {
+ currentZOff = 0;
+ }
+ else
+ {
+ currentZOff = 100;
+ }
+ startPos.SetZ((float)currentZOff);
+ currentModelIndex++;
}
- _rotation += 1;
+
+ _currentAspectRatio = (float)(bitmap.GetWidth() / bitmap.GetHeight());
+ _currentPerspectiveMatrix = GetPerspectiveProjectionMatrix(1, _currentAspectRatio);
+ _currentViewMatrix = GetViewMatrix(1, bitmap.GetWidth(), bitmap.GetHeight());
+
+ if (_rotation == 360)
+ {
+ _rotation = 0;
+ }
+ else
+ {
+ _rotation += 1;
+ }
}
void Rasteriser::Render(const Bitmap& bitmap)
{
ClearViewport(bitmap);
- SelectObject(bitmap.GetDC(), GetStockObject(DC_BRUSH));
- //DrawSquare(bitmap.GetDC(), _initialVertexArray);
- DrawShape(bitmap.GetDC(), _currentVertexArray);
+ //SelectObject(bitmap.GetDC(), GetStockObject(DC_BRUSH));
+
+ Camera mainCamera = Camera(0, 0, 0, Vertex(0, 0, -100));
+
+ for (Model ¤tModel : _sceneModels)
+ {
+ Matrix workingMatrix = workingMatrix.IdentityMatrix();
+ for (Matrix currentTransform : currentModel.GetPendingTransforms())
+ {
+ workingMatrix *= currentTransform;
+ }
+ currentModel.ApplyTransformToLocalVertices(workingMatrix);
+ currentModel.ApplyTransformToTransformedVertices(mainCamera.GetCurrentCameraTransformMatrix());
+ currentModel.ApplyTransformToTransformedVertices(_currentPerspectiveMatrix);
+ currentModel.DehomogenizeAllVertices();
+ currentModel.ApplyTransformToTransformedVertices(_currentViewMatrix);
+ DrawWireFrame(bitmap.GetDC(), currentModel);
+ currentModel.ClearPendingTransforms();
+ }
}
void Rasteriser::ClearViewport(const Bitmap& bitmap)
@@ -49,41 +104,6 @@ void Rasteriser::ClearViewport(const Bitmap& bitmap)
bitmap.Clear(RGB(255, 255, 255));
}
-Matrix Rasteriser::GetTranslateMatrix(const float x, const float y, const float z)
-{
- return Matrix({ 1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1 });
-}
-
-Matrix Rasteriser::GetScaleMatrix(const float x, const float y, const float z)
-{
- return Matrix({ x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 });
-}
-
-Matrix Rasteriser::GetRotationMatrix(const Axis rotAxis, const float rotDegrees)
-{
- float rotationRadian = DegreesToRadians(rotDegrees);
- switch (rotAxis)
- {
- case (Axis::X):
- return Matrix({ 1, 0, 0, 0, 0, cos(rotationRadian), -sin(rotationRadian), 0, 0, sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1 });
- case (Axis::Y):
- return Matrix({ cos(rotationRadian), 0, sin(rotationRadian), 0, 0, 1, 0, 0, -sin(rotationRadian), 0, cos(rotationRadian), 0, 0, 0, 0, 1 });
- default:
- case (Axis::Z):
- return Matrix({ cos(rotationRadian), -sin(rotationRadian), 0, 0, sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 });
- }
-}
-
-Matrix Rasteriser::GetRotationMatrixFromPoint(const Axis rotAxis, const float rotDegrees, const float x, const float y, const float z)
-{
- return GetTranslateMatrix(x, y, z) * GetRotationMatrix(rotAxis, rotDegrees) * GetTranslateMatrix(-x, -y, -z);
-}
-
-float Rasteriser::DegreesToRadians(const float degrees)
-{
- return (degrees * _PI) / 180;
-}
-
void Rasteriser::DrawSquare(HDC hDc, const vector verticies)
{
POINT pointArray[4];
@@ -112,4 +132,26 @@ void Rasteriser::DrawShape(HDC hDc, const vector verticies)
SetDCBrushColor(hDc, RGB(rand() % 256, rand() % 256, rand() % 256));
SetDCPenColor(hDc, RGB(rand() % 256, rand() % 256, rand() % 256));
Polygon(hDc, pointArray.data(), (int) verticies.size());
+}
+
+void Rasteriser::DrawWireFrame(HDC hDc, Model& model)
+{
+ vector pointArray;
+ vector sizeArray;
+
+ int modelPolygonCount = (int) model.GetPolygonCount();
+ for (int i = 0; i < modelPolygonCount; i++)
+ {
+ int currentPolygonVertexCount = (int) model.GetPolygon(i).GetPolygonVertexCount();
+ for (int j = 0; j < currentPolygonVertexCount; j++)
+ {
+ POINT newPoint;
+ newPoint.x = (long) model.GetVertex(i, j).GetX();
+ newPoint.y = (long) model.GetVertex(i, j).GetY();
+ pointArray.push_back(newPoint);
+ }
+ sizeArray.push_back(currentPolygonVertexCount);
+ }
+
+ PolyPolygon(hDc, pointArray.data(), sizeArray.data(), modelPolygonCount);
}
\ No newline at end of file
diff --git a/Rasteriser.h b/Rasteriser.h
index 8c331b1..23c8be3 100644
--- a/Rasteriser.h
+++ b/Rasteriser.h
@@ -2,9 +2,14 @@
#include "Framework.h"
#include "Vertex.h"
#include "Matrix.h"
+#include "TransformTools.h"
+#include "Camera.h"
+#include "Model.h"
+#include "MD2Loader.h"
#include
-enum class Axis { X, Y, Z };
+using namespace std;
+using namespace TransformTools;
class Rasteriser : public Framework
{
@@ -17,17 +22,16 @@ public:
void DrawSquare(HDC hDc, const vector verticies);
void DrawShape(HDC hDc, const vector verticies);
- Matrix GetTranslateMatrix(const float x, const float y, const float z);
- Matrix GetScaleMatrix(const float x, const float y, const float z);
- Matrix GetRotationMatrix(const Axis rotAxis, const float rotDegrees);
- Matrix GetRotationMatrixFromPoint(const Axis rotAxis, const float rotDegrees, const float x, const float y, const float z);
-
- float DegreesToRadians(const float degrees);
+ void DrawWireFrame(HDC hDc, Model& model);
private:
- vector _initialVertexArray;
- vector _currentVertexArray;
- const float _PI = (float) acos(-1);
+ vector _sceneModels;
+
+ Matrix _currentPerspectiveMatrix;
+ Matrix _currentViewMatrix;
+ float _currentAspectRatio;
+
int _rotation;
+
};
diff --git a/TransformTools.cpp b/TransformTools.cpp
new file mode 100644
index 0000000..ef27d44
--- /dev/null
+++ b/TransformTools.cpp
@@ -0,0 +1,90 @@
+#include "TransformTools.h"
+
+Matrix TransformTools::GetTranslateMatrix(const float x, const float y, const float z)
+{
+ return Matrix({ 1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1 });
+}
+
+Matrix TransformTools::GetTranslateMatrix(const Vertex& position)
+{
+ return GetTranslateMatrix(position.GetX(), position.GetY(), position.GetZ());
+}
+
+Matrix TransformTools::GetScaleMatrix(const float x, const float y, const float z)
+{
+ return Matrix({ x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 });
+}
+
+Matrix TransformTools::GetRotationMatrix(const Axis rotAxis, const float rotDegrees)
+{
+ float rotationRadian = DegreesToRadians(rotDegrees);
+ switch (rotAxis)
+ {
+ case (Axis::X):
+ return Matrix({ 1, 0, 0, 0, 0, cos(rotationRadian), -sin(rotationRadian), 0, 0, sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1 });
+ case (Axis::Y):
+ return Matrix({ cos(rotationRadian), 0, sin(rotationRadian), 0, 0, 1, 0, 0, -sin(rotationRadian), 0, cos(rotationRadian), 0, 0, 0, 0, 1 });
+ case (Axis::Z):
+ return Matrix({ cos(rotationRadian), -sin(rotationRadian), 0, 0, sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 });
+ default:
+ throw "Invalid axis selected";
+ }
+}
+
+Matrix TransformTools::GetRotationMatrixFromPoint(const Axis rotAxis, const float rotDegrees, const float x, const float y, const float z)
+{
+ return GetTranslateMatrix(x, y, z) * GetRotationMatrix(rotAxis, rotDegrees) * GetTranslateMatrix(-x, -y, -z);
+}
+
+float TransformTools::DegreesToRadians(const float degrees)
+{
+ return (degrees * PI) / 180;
+}
+
+Matrix TransformTools::GetOrthegraphicProjectionMatrix(float d)
+{
+ return Matrix({ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, d, 0, 0, 0, 1 });
+}
+
+Matrix TransformTools::GetPerspectiveProjectionMatrix(float d, float aspectRatio)
+{
+ float distanceAspect = d / aspectRatio;
+
+ return Matrix({ distanceAspect, 0, 0, 0, 0, d, 0, 0, 0, 0, d, 0, 0, 0, 1, 0 });
+}
+
+Matrix TransformTools::GetViewMatrix(float d, int width, int height)
+{
+ float widthCenter = (float) width / 2.0f;
+ float heightCenter = (float) height / 2.0f;
+ float distanceCenter = (float) d / 2.0f;
+
+ return Matrix({ widthCenter, 0, 0, widthCenter, 0, -heightCenter, 0, heightCenter, 0, 0, distanceCenter, distanceCenter, 0, 0, 0, 1 });
+}
+
+Matrix TransformTools::GetCameraTranslateMatrix(const float x, const float y, const float z)
+{
+ return Matrix({ 1, 0, 0, -x, 0, 1, 0, -y, 0, 0, 1, -z, 0, 0, 0, 1 });
+}
+
+Matrix TransformTools::GetCameraTranslateMatrix(const Vertex& position)
+{
+ return GetCameraTranslateMatrix(position.GetX(), position.GetY(), position.GetZ());
+}
+
+
+Matrix TransformTools::GetCameraRotationMatrix(const Axis rotAxis, const float rotDegrees)
+{
+ float rotationRadian = DegreesToRadians(rotDegrees);
+ switch (rotAxis)
+ {
+ case (Axis::X):
+ return Matrix({ 1, 0, 0, 0, 0, cos(rotationRadian), sin(rotationRadian), 0, 0, -sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1 });
+ case (Axis::Y):
+ return Matrix({ cos(rotationRadian), 0, -sin(rotationRadian), 0, 0, 1, 0, 0, sin(rotationRadian), 0, cos(rotationRadian), 0, 0, 0, 0, 1 });
+ case (Axis::Z):
+ return Matrix({ cos(rotationRadian), sin(rotationRadian), 0, 0, -sin(rotationRadian), cos(rotationRadian), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 });
+ default:
+ throw "Invalid axis selected";
+ }
+}
\ No newline at end of file
diff --git a/TransformTools.h b/TransformTools.h
new file mode 100644
index 0000000..9b15aa3
--- /dev/null
+++ b/TransformTools.h
@@ -0,0 +1,29 @@
+#pragma once
+#include "Matrix.h"
+#include
+
+enum class Axis { X, Y, Z };
+
+namespace TransformTools
+{
+ const float PI = (float)acos(-1);
+
+ Matrix GetTranslateMatrix(const float x, const float y, const float z);
+ Matrix GetTranslateMatrix(const Vertex& position);
+
+ Matrix GetScaleMatrix(const float x, const float y, const float z);
+
+ Matrix GetRotationMatrix(const Axis rotAxis, const float rotDegrees);
+ Matrix GetRotationMatrixFromPoint(const Axis rotAxis, const float rotDegrees, const float x, const float y, const float z);
+
+ Matrix GetOrthegraphicProjectionMatrix(float d);
+ Matrix GetPerspectiveProjectionMatrix(float d, float aspectRatio);
+ Matrix GetViewMatrix(float d, int width, int height);
+
+ Matrix GetCameraRotationMatrix(const Axis rotAxis, const float rotDegrees);
+ Matrix GetCameraTranslateMatrix(const float x, const float y, const float z);
+ Matrix GetCameraTranslateMatrix(const Vertex& position);
+
+ float DegreesToRadians(const float degrees);
+};
+
diff --git a/Vertex.cpp b/Vertex.cpp
index 739f89c..2a5d694 100644
--- a/Vertex.cpp
+++ b/Vertex.cpp
@@ -69,6 +69,14 @@ void Vertex::SetW(const float w)
_w = w;
}
+void Vertex::Dehomogenize()
+{
+ _x = _x / _w;
+ _y = _y / _w;
+ _z = _z / _w;
+ _w = _w / _w;
+}
+
Vertex& Vertex::operator=(const Vertex& rhs)
{
// Only do the assignment if we are not assigning
diff --git a/Vertex.h b/Vertex.h
index 0782a1e..2923b0d 100644
--- a/Vertex.h
+++ b/Vertex.h
@@ -17,6 +17,8 @@ public:
float GetW() const;
void SetW(const float w);
+ void Dehomogenize();
+
// Assignment operator
Vertex& operator= (const Vertex& rhs);
diff --git a/cheff.md2 b/cheff.md2
new file mode 100644
index 0000000..63518cd
Binary files /dev/null and b/cheff.md2 differ
diff --git a/marvin.md2 b/marvin.md2
new file mode 100644
index 0000000..d5a4aa0
Binary files /dev/null and b/marvin.md2 differ
diff --git a/megaman.MD2 b/megaman.MD2
new file mode 100644
index 0000000..9bb8945
Binary files /dev/null and b/megaman.MD2 differ