Files
Graphics-Rasterizer/Polygon3D.cpp
IDunnoDev df3c9fac81 Week9 [23/11] - [29/11]
Added Lighting Changes for Vertex Normal Calculation
Added Method to Get a Polygons Vertices as a Vector array
Added Methods to Add the Color to a Polygon and Vertex Object
Added Normalization to the Polygon normal vector
Added Vector Normal Calculation to the Model Class
Added Light Calculation method to the Rasterizer Class
Added Flag to Rasterizer to stop processing when the screen is minimised
Added Flat and Gouraud Drawing Methods to the Resterizer
Added Standard and INT triangle drawing Methods
Added Function to mimic sgn function from Java
Added Length to Vector3D class
Added / operator to Vector3D class
Added Get(x,y,z,w)Int methods to Vertex class
Changed Color Variables on the Vertex/Polygon classes to use r, g and b values rather than COLORREF
Changed Camera translation functions to use normal Translation Functions
Cleaned up Code
Removed Unused code from the Camera Class
2021-12-11 19:26:56 +00:00

112 lines
1.7 KiB
C++

#include "Polygon3D.h"
Polygon3D::Polygon3D() : _indices{ 0 }
{
_depth = 0.0f;
_color = RGB(0, 0, 0);
_culled = false;
}
Polygon3D::Polygon3D(int index0, int index1, int index2)
{
_indices[0] = index0;
_indices[1] = index1;
_indices[2] = index2;
_depth = 0.0f;
_color = RGB(0, 0, 0);
_culled = false;
}
Polygon3D::Polygon3D(const Polygon3D& other)
{
Copy(other);
}
Polygon3D::~Polygon3D()
{
}
size_t Polygon3D::GetPolygonVertexCount() const
{
return sizeof(_indices) / sizeof(_indices[0]);
}
int Polygon3D::GetIndex(const int index) const
{
return _indices[index];
}
void Polygon3D::SetNormal(const Vector3D& normal)
{
_normal = normal;
}
const Vector3D& Polygon3D::GetNormal() const
{
return _normal;
}
void Polygon3D::NormalizeNormal()
{
_normal.Normalize();
}
void Polygon3D::SetColor(int red, int green, int blue)
{
int redChecked = BoundsCheck(0, 255, red);
int greenChecked = BoundsCheck(0, 255, green);
int blueChecked = BoundsCheck(0, 255, blue);
_color = RGB(redChecked, greenChecked, blueChecked);
}
void Polygon3D::SetColor(const COLORREF color)
{
_color = color;
}
COLORREF Polygon3D::GetColor() const
{
return _color;
}
void Polygon3D::SetDepth(float depth)
{
_depth = depth;
}
float Polygon3D::GetDepth() const
{
return _depth;
}
void Polygon3D::SetCulled(bool culled)
{
_culled = culled;
}
bool Polygon3D::GetCulled() const
{
return _culled;
}
Polygon3D& Polygon3D::operator= (const Polygon3D& rhs)
{
if (this != &rhs)
{
Copy(rhs);
}
return *this;
}
void Polygon3D::Copy(const Polygon3D& other)
{
for (int i = 0; i < sizeof(_indices)/sizeof(_indices[0]); i++)
{
_indices[i] = other.GetIndex(i);
}
_normal = other.GetNormal();
_culled = other.GetCulled();
_depth = other.GetDepth();
_color = other.GetColor();
}