
Added Light Base Class Added AmbientLight, DirectionalLight and PointLight Classes Added Constructor to the Camera Class Added Light CoEff's to the Model Class Added Color Variables to Polygon3D Class Added Light Vector to hold the lights in the Rasteriser Added Camera Vector to hold multiple Cameras and Methods to set which is the current Added Lighting to the Rasterizer Added DrawSolidFlat method to the Rastorizer Added Bounds Check to the SharedTools for Int and Float values Added Color Enum Class Added Normalize Method to the Vector3D Class Renamed the TransformTools to SharedTools since adding more non transform methods to it
78 lines
2.1 KiB
C++
78 lines
2.1 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::CalculateLight(const Model& currentModel, const Polygon3D& currentPolygon, 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, currentPolygon.GetNormal());
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
} |