Files
Graphics-Rasterizer/DirectionalLight.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

88 lines
2.5 KiB
C++

#include "DirectionalLight.h"
DirectionalLight::DirectionalLight(Vector3D lightDirection) : Light()
{
_lightDirection = lightDirection;
_normalizedLightDirection = lightDirection;
_normalizedLightDirection.Normalize();
}
DirectionalLight::DirectionalLight(Vector3D lightDirection, int red, int green, int blue) : Light(red, green, blue)
{
_lightDirection = lightDirection;
_normalizedLightDirection = lightDirection;
_normalizedLightDirection.Normalize();
}
DirectionalLight::DirectionalLight(const DirectionalLight& other) : Light(other)
{
Copy(other);
}
void DirectionalLight::SetLightDirection(float x, float y, float z)
{
SetLightDirection(Vector3D(x, y, z));
}
void DirectionalLight::SetLightDirection(Vector3D direction)
{
_lightDirection = direction;
}
Vector3D DirectionalLight::GetLightDirection() const
{
return _lightDirection;
}
COLORREF DirectionalLight::CalculateLightShared(const Model& currentModel, const Vector3D& currentNormal, COLORREF colorIn)
{
float workingRed = (float)GetRedLightIntensity();
float workingGreen = (float)GetGreenLightIntensity();
float workingBlue = (float)GetBlueLightIntensity();
workingRed *= currentModel.GetRedReflectionCoefficient();
workingGreen *= currentModel.GetGreenReflectionCoefficient();
workingBlue *= currentModel.GetBlueReflectionCoefficient();
float lightDotProd = Vector3D::DotProduct(_normalizedLightDirection, currentNormal);
workingRed *= lightDotProd;
workingGreen *= lightDotProd;
workingBlue *= lightDotProd;
workingRed += (float)GetRValue(colorIn);
workingGreen += (float)GetGValue(colorIn);
workingBlue += (float)GetBValue(colorIn);
int finalRed = BoundsCheck(0, 255, (int)workingRed);
int finalGreen = BoundsCheck(0, 255, (int)workingGreen);
int finalBlue = BoundsCheck(0, 255, (int)workingBlue);
COLORREF outputColor = RGB(finalRed, finalGreen, finalBlue);
return outputColor;
}
COLORREF DirectionalLight::CalculateLight(const Model& currentModel, const Polygon3D& currentPolygon, COLORREF colorIn)
{
return CalculateLightShared(currentModel, currentPolygon.GetNormal(), colorIn);
}
COLORREF DirectionalLight::CalculateLight(const Model& currentModel, const Vertex& currentVertex, COLORREF colorIn)
{
return CalculateLightShared(currentModel, currentVertex.GetNormal(), colorIn);
}
DirectionalLight& DirectionalLight::operator= (const DirectionalLight& rhs)
{
if (this != &rhs)
{
Copy(rhs);
}
return *this;
}
void DirectionalLight::Copy(const DirectionalLight& other)
{
_lightDirection = other.GetLightDirection();
Light::Copy(other);
}