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
This commit is contained in:
148
Vertex.cpp
148
Vertex.cpp
@ -6,6 +6,11 @@ Vertex::Vertex()
|
||||
_y = 0.0f;
|
||||
_z = 0.0f;
|
||||
_w = 0.0f;
|
||||
_contributeCount = 0;
|
||||
_normal = Vector3D(0, 0, 0);
|
||||
_r = 0;
|
||||
_g = 0;
|
||||
_b = 0;
|
||||
}
|
||||
|
||||
Vertex::Vertex(const float x, const float y, const float z)
|
||||
@ -14,6 +19,11 @@ Vertex::Vertex(const float x, const float y, const float z)
|
||||
_y = y;
|
||||
_z = z;
|
||||
_w = 1.0f;
|
||||
_contributeCount = 0;
|
||||
_normal = Vector3D(0, 0, 0);
|
||||
_r = 0;
|
||||
_g = 0;
|
||||
_b = 0;
|
||||
}
|
||||
|
||||
Vertex::Vertex(const float x, const float y, const float z, const float w)
|
||||
@ -22,6 +32,11 @@ Vertex::Vertex(const float x, const float y, const float z, const float w)
|
||||
_y = y;
|
||||
_z = z;
|
||||
_w = w;
|
||||
_contributeCount = 0;
|
||||
_normal = Vector3D(0, 0, 0);
|
||||
_r = 0;
|
||||
_g = 0;
|
||||
_b = 0;
|
||||
}
|
||||
|
||||
Vertex::Vertex(const Vertex & other)
|
||||
@ -69,6 +84,132 @@ void Vertex::SetW(const float w)
|
||||
_w = w;
|
||||
}
|
||||
|
||||
const int Vertex::GetContributeCount() const
|
||||
{
|
||||
return _contributeCount;
|
||||
}
|
||||
|
||||
void Vertex::IncrementContributeCount()
|
||||
{
|
||||
_contributeCount++;
|
||||
}
|
||||
|
||||
void Vertex::ResetContributeCount()
|
||||
{
|
||||
_contributeCount = 0;
|
||||
}
|
||||
|
||||
const Vector3D& Vertex::GetNormal() const
|
||||
{
|
||||
return _normal;
|
||||
}
|
||||
|
||||
void Vertex::SetNormal(float x, float y, float z)
|
||||
{
|
||||
_normal.SetX(x);
|
||||
_normal.SetY(y);
|
||||
_normal.SetZ(z);
|
||||
}
|
||||
|
||||
void Vertex::SetNormal(const Vector3D& normal)
|
||||
{
|
||||
SetNormal(normal.GetX(), normal.GetY(), normal.GetZ());
|
||||
}
|
||||
|
||||
void Vertex::NormalizeNormal()
|
||||
{
|
||||
_normal.Normalize();
|
||||
}
|
||||
|
||||
void Vertex::ResetNormal(bool resetCount)
|
||||
{
|
||||
SetNormal(0, 0, 0);
|
||||
if (resetCount)
|
||||
{
|
||||
ResetContributeCount();
|
||||
}
|
||||
}
|
||||
|
||||
const COLORREF Vertex::GetColor() const
|
||||
{
|
||||
return RGB(_r, _g, _b);
|
||||
}
|
||||
|
||||
int Vertex::GetR() const
|
||||
{
|
||||
return _r;
|
||||
}
|
||||
|
||||
int Vertex::GetG() const
|
||||
{
|
||||
return _g;
|
||||
}
|
||||
|
||||
int Vertex::GetB() const
|
||||
{
|
||||
return _b;
|
||||
}
|
||||
|
||||
void Vertex::SetColor(int r, int g, int b)
|
||||
{
|
||||
_r = r;
|
||||
_g = g;
|
||||
_b = b;
|
||||
}
|
||||
|
||||
void Vertex::SetColor(const COLORREF colorIn)
|
||||
{
|
||||
SetColor((int)GetRValue(colorIn), (int)GetGValue(colorIn), (int)GetBValue(colorIn));
|
||||
}
|
||||
|
||||
int Vertex::GetXInt(bool forceRoundUp) const
|
||||
{
|
||||
if (forceRoundUp)
|
||||
{
|
||||
return (int)ceil(GetX());
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)floor(GetX());
|
||||
}
|
||||
;}
|
||||
|
||||
int Vertex::GetYInt(bool forceRoundUp) const
|
||||
{
|
||||
if (forceRoundUp)
|
||||
{
|
||||
return (int)ceil(GetY());
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)floor(GetY());
|
||||
}
|
||||
}
|
||||
|
||||
int Vertex::GetZInt(bool forceRoundUp) const
|
||||
{
|
||||
if (forceRoundUp)
|
||||
{
|
||||
return (int)ceil(GetZ());
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)floor(GetZ());
|
||||
}
|
||||
}
|
||||
|
||||
int Vertex::GetWInt(bool forceRoundUp) const
|
||||
{
|
||||
if (forceRoundUp)
|
||||
{
|
||||
return (int)ceil(GetW());
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)floor(GetW());
|
||||
}
|
||||
}
|
||||
|
||||
void Vertex::Dehomogenize()
|
||||
{
|
||||
_x = _x / _w;
|
||||
@ -90,7 +231,7 @@ Vertex& Vertex::operator=(const Vertex& rhs)
|
||||
|
||||
const Vector3D Vertex::operator-(const Vertex& rhs) const
|
||||
{
|
||||
return Vector3D(rhs.GetX() - GetX(), rhs.GetY() - GetY(), rhs.GetZ() - GetZ());
|
||||
return Vector3D(rhs.GetX() - _x, rhs.GetY() - _y, rhs.GetZ() - _z);
|
||||
}
|
||||
|
||||
// The const at the end of the declaraion for '==" indicates that this operation does not change
|
||||
@ -118,4 +259,9 @@ void Vertex::Copy(const Vertex& other)
|
||||
_y = other.GetY();
|
||||
_z = other.GetZ();
|
||||
_w = other.GetW();
|
||||
|
||||
_contributeCount = other.GetContributeCount();
|
||||
SetNormal(other.GetNormal());
|
||||
|
||||
SetColor(other.GetR(), other.GetG(), other.GetB());
|
||||
}
|
||||
|
Reference in New Issue
Block a user