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:
33
Vector3D.cpp
33
Vector3D.cpp
@ -2,16 +2,16 @@
|
||||
|
||||
Vector3D::Vector3D()
|
||||
{
|
||||
SetX(1);
|
||||
SetY(1);
|
||||
SetZ(1);
|
||||
_x = 1;
|
||||
_y = 1;
|
||||
_z = 1;
|
||||
}
|
||||
|
||||
Vector3D::Vector3D(float x, float y, float z)
|
||||
{
|
||||
SetX(x);
|
||||
SetY(y);
|
||||
SetZ(z);
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
}
|
||||
|
||||
Vector3D::Vector3D(const Vector3D& other)
|
||||
@ -54,7 +54,7 @@ void Vector3D::SetZ(const float z)
|
||||
_z = z;
|
||||
}
|
||||
|
||||
void Vector3D::Normalize()
|
||||
const void Vector3D::Normalize()
|
||||
{
|
||||
float length = sqrt(_x * _x + _y * _y + _z * _z);
|
||||
|
||||
@ -68,12 +68,17 @@ void Vector3D::Normalize()
|
||||
|
||||
float Vector3D::DotProduct(const Vector3D v1, const Vector3D v2)
|
||||
{
|
||||
return ((v1.GetX() * v2.GetX()) + (v1.GetY() * v2.GetY()) + (v1.GetZ() * v2.GetZ()));
|
||||
return v1.GetX() * v2.GetX() + v1.GetY() * v2.GetY() + v1.GetZ() * v2.GetZ();
|
||||
}
|
||||
|
||||
float Vector3D::Length(const Vector3D v1, const Vector3D v2)
|
||||
{
|
||||
return (float)sqrt(pow((v1.GetX() - v2.GetX()), 2) + pow((v1.GetY() - v2.GetY()), 2) + pow((v1.GetZ() - v2.GetZ()), 2));
|
||||
}
|
||||
|
||||
Vector3D Vector3D::CrossProduct(const Vector3D v1, const Vector3D v2)
|
||||
{
|
||||
return Vector3D((v1.GetY() * v2.GetZ()) - (v1.GetZ() * v2.GetY()), (v1.GetZ() * v2.GetX()) - (v1.GetX() * v2.GetZ()), (v1.GetX() * v2.GetY()) - (v1.GetY() * v2.GetX()));
|
||||
return Vector3D(v1.GetY() * v2.GetZ() - v1.GetZ() * v2.GetY(), v1.GetZ() * v2.GetX() - v1.GetX() * v2.GetZ(), v1.GetX() * v2.GetY() - v1.GetY() * v2.GetX());
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +87,16 @@ const Vector3D Vector3D::operator+ (const Vector3D& rhs) const
|
||||
return Vector3D(_x + rhs.GetX(), _y + rhs.GetY(), _z + rhs.GetZ());
|
||||
}
|
||||
|
||||
const Vector3D Vector3D::operator/ (const float rhs) const
|
||||
{
|
||||
return Vector3D(_x / rhs, _y / rhs, _z / rhs);
|
||||
}
|
||||
|
||||
const Vector3D Vector3D::operator/ (const int rhs) const
|
||||
{
|
||||
return Vector3D(_x / rhs, _y / rhs, _z / rhs);
|
||||
}
|
||||
|
||||
void Vector3D::Copy(const Vector3D& other)
|
||||
{
|
||||
_x = other.GetX();
|
||||
|
Reference in New Issue
Block a user