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:
90
Camera.cpp
90
Camera.cpp
@ -1,19 +1,11 @@
|
||||
#include "Camera.h"
|
||||
|
||||
Camera::Camera()
|
||||
{
|
||||
}
|
||||
|
||||
Camera::Camera(float xRot, float yRot, float zRot, const Vertex& pos)
|
||||
{
|
||||
_initialRotation[0] = xRot;
|
||||
_currentRotation[0] = xRot;
|
||||
_initialRotation[1] = yRot;
|
||||
_currentRotation[1] = yRot;
|
||||
_initialRotation[2] = zRot;
|
||||
_currentRotation[2] = zRot;
|
||||
_initialPosition = pos;
|
||||
_currentPosition = pos;
|
||||
_xRot = xRot;
|
||||
_yRot = yRot;
|
||||
_zRot = zRot;
|
||||
_cameraPosition = pos;
|
||||
}
|
||||
|
||||
Camera::Camera(const Camera& other)
|
||||
@ -27,61 +19,56 @@ Camera::~Camera()
|
||||
|
||||
Matrix Camera::UpdateCameraPosition(const Vertex& newPos)
|
||||
{
|
||||
_currentPosition = newPos;
|
||||
_cameraPosition = newPos;
|
||||
return GetCurrentCameraTransformMatrix();
|
||||
}
|
||||
|
||||
Matrix Camera::RotateCamera(float xRot, float yRot, float zRot)
|
||||
{
|
||||
_currentRotation[0] = xRot;
|
||||
_currentRotation[1] = yRot;
|
||||
_currentRotation[2] = zRot;
|
||||
_xRot = xRot;
|
||||
_yRot = yRot;
|
||||
_zRot = zRot;
|
||||
return GetCurrentCameraTransformMatrix();
|
||||
}
|
||||
|
||||
Matrix Camera::GetCurrentCameraTransformMatrix()
|
||||
{
|
||||
return GetCameraRotationMatrix(Axis::X, _currentRotation[0]) * GetCameraRotationMatrix(Axis::Y, _currentRotation[1]) * GetCameraRotationMatrix(Axis::Z, _currentRotation[2]) * GetCameraTranslateMatrix(_currentPosition);
|
||||
return GetCameraRotationMatrix(Axis::X, _xRot) * GetCameraRotationMatrix(Axis::Y, _yRot) * GetCameraRotationMatrix(Axis::Z, _zRot) * GetCameraTranslateMatrix(_cameraPosition);
|
||||
}
|
||||
|
||||
float Camera::GetCurrentRotationValue(const Axis axis)
|
||||
void Camera::SetXRot(const float value)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case (Axis::X):
|
||||
return _currentRotation[0];
|
||||
case (Axis::Y):
|
||||
return _currentRotation[1];
|
||||
case (Axis::Z):
|
||||
return _currentRotation[2];
|
||||
default:
|
||||
throw "No valid axis?";
|
||||
}
|
||||
_xRot = value;
|
||||
}
|
||||
|
||||
float Camera::GetInitialRotationValue(const Axis axis)
|
||||
float Camera::GetXRot() const
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case (Axis::X):
|
||||
return _initialRotation[0];
|
||||
case (Axis::Y):
|
||||
return _initialRotation[1];
|
||||
case (Axis::Z):
|
||||
return _initialRotation[2];
|
||||
default:
|
||||
throw "No valid axis?";
|
||||
}
|
||||
return _xRot;
|
||||
}
|
||||
|
||||
Vertex Camera::GetCurrentPosition()
|
||||
void Camera::SetYRot(const float value)
|
||||
{
|
||||
return _currentPosition;
|
||||
_yRot = value;
|
||||
}
|
||||
|
||||
Vertex Camera::GetInitialPosition()
|
||||
float Camera::GetYRot() const
|
||||
{
|
||||
return _initialPosition;
|
||||
return _yRot;
|
||||
}
|
||||
|
||||
void Camera::SetZRot(const float value)
|
||||
{
|
||||
_zRot = value;
|
||||
}
|
||||
|
||||
float Camera::GetZRot() const
|
||||
{
|
||||
return _zRot;
|
||||
}
|
||||
|
||||
Vertex Camera::GetCameraPosition() const
|
||||
{
|
||||
return _cameraPosition;
|
||||
}
|
||||
|
||||
Camera& Camera::operator=(const Camera& rhs)
|
||||
@ -95,12 +82,9 @@ Camera& Camera::operator=(const Camera& rhs)
|
||||
|
||||
void Camera::Copy(const Camera& other)
|
||||
{
|
||||
_initialRotation[0] = other._initialRotation[0];
|
||||
_currentRotation[0] = other._currentRotation[0];
|
||||
_initialRotation[1] = other._initialRotation[1];
|
||||
_currentRotation[1] = other._currentRotation[1];
|
||||
_initialRotation[2] = other._initialRotation[2];
|
||||
_currentRotation[2] = other._currentRotation[2];
|
||||
_initialPosition = other._initialPosition;
|
||||
_currentPosition = other._currentPosition;
|
||||
_xRot = other.GetXRot();
|
||||
_yRot = other.GetYRot();
|
||||
_zRot = other.GetZRot();
|
||||
|
||||
_cameraPosition = other.GetCameraPosition();
|
||||
}
|
Reference in New Issue
Block a user