Files
Graphics-Rasterizer/Vertex.cpp
IDunnoDev 19639d70d1 Week6 [02/11] - [04/11]
Added Camera Class
Added *= operator to the matrix class
Added Transformation Queue vector to the Model Class
Added Get Vertex, Polygon and Polygon Vertex methods to the Model Class
Added DehomogenizeAllVerticies method to the Model Class
Added GetPolygonVertexCount method to Polygon Class
Added Ability to have multiple models in a "scene" in the Rasterizer
Added DrawWireFrame method to the Rasterizer Class
Added Aspect Ratio and View Matrix to the Rasterizer Class
Added TransformTools namespace to hold shared transformation functions
Added Dehomogenize method to the Vector Class
Moved Transformation methods to a new shared name space
2021-12-11 14:15:02 +00:00

117 lines
1.9 KiB
C++

#include "Vertex.h"
Vertex::Vertex()
{
_x = 0.0f;
_y = 0.0f;
_z = 0.0f;
_w = 0.0f;
}
Vertex::Vertex(const float x, const float y, const float z)
{
_x = x;
_y = y;
_z = z;
_w = 1.0f;
}
Vertex::Vertex(const float x, const float y, const float z, const float w)
{
_x = x;
_y = y;
_z = z;
_w = w;
}
Vertex::Vertex(const Vertex & other)
{
Copy(other);
}
float Vertex::GetX() const
{
return _x;
}
void Vertex::SetX(const float x)
{
_x = x;
}
float Vertex::GetY() const
{
return _y;
}
void Vertex::SetY(const float y)
{
_y = y;
}
float Vertex::GetZ() const
{
return _z;
}
void Vertex::SetZ(const float z)
{
_z = z;
}
float Vertex::GetW() const
{
return _w;
}
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
// to ourselves
if (this != &rhs)
{
Copy(rhs);
}
return *this;
}
// The const at the end of the declaraion for '==" indicates that this operation does not change
// any of the member variables in this class.
bool Vertex::operator==(const Vertex& rhs) const
{
return (_x == rhs.GetX() && _y == rhs.GetY() && _z == rhs.GetZ() && _w == rhs.GetW());
}
// You can see three different uses of 'const' here:
//
// The first const indicates that the method changes the return value, but it is not moved in memory
// The second const indicates that the parameter is passed by reference, but it is not modified
// The third const indicates that the operator does not change any of the memory variables in the class.
const Vertex Vertex::operator+(const Vertex& rhs) const
{
return Vertex(_x + rhs.GetX(), _y + rhs.GetY(), _z + rhs.GetZ(), _w + rhs.GetW());
}
void Vertex::Copy(const Vertex& other)
{
_x = other.GetX();
_y = other.GetY();
_z = other.GetZ();
_w = other.GetW();
}