Removed fisheye lense, added image plane and fov calculation
This commit is contained in:
parent
f37b8bc9c6
commit
2eb55b9e98
1 changed files with 4 additions and 25 deletions
|
@ -3,35 +3,14 @@
|
|||
|
||||
PerspectiveCamera::PerspectiveCamera() : forwardDirection(0, 0, 1), upDirection(0, 1, 0), fovAngle(70) {}
|
||||
|
||||
/**
|
||||
* Rotate a vector around an arbitrary axis
|
||||
* Input and output vectors are normalized
|
||||
*
|
||||
* @author Arvid Schröder
|
||||
* @param original Vector to be rotated
|
||||
* @param axis Direction Vector used as axis to be rotated around
|
||||
* @param angle Rotation angle in degrees
|
||||
* @return normalized rotated vector
|
||||
*/
|
||||
Vector3d rotateVector(const Vector3d &original, const Vector3d &axis, const float angle) {
|
||||
const Vector3d &original_norm = normalized(original);
|
||||
const Vector3d &axis_norm = normalized(axis);
|
||||
return normalized(
|
||||
original_norm * cos(angle) +
|
||||
crossProduct(axis_norm, original_norm) * sin(angle) +
|
||||
axis * (dotProduct(axis_norm, original_norm)) * (1.0 - cos(angle)));
|
||||
}
|
||||
|
||||
Ray PerspectiveCamera::createRay(float x, float y) const {
|
||||
// IMPLEMENT ME!
|
||||
// Set up a left-handed coordinate system,
|
||||
// in which the camera looks along the positive z-Axis
|
||||
|
||||
float angle_x = x * this->fovAngle * 2 * PI / 360;
|
||||
float angle_y = y * this->fovAngle * 2 * PI / 360;
|
||||
Vector3d normalVector = normalized(crossProduct(forwardDirection, upDirection));
|
||||
Vector3d normalVector_fov = normalVector * tan(this->fovAngle / 360 * PI);
|
||||
Vector3d upVector_fov = this->upDirection * tan(this->fovAngle / 360 * PI);
|
||||
Vector3d directionVector = normalized(forwardDirection + x * normalVector_fov + y * upVector_fov);
|
||||
|
||||
Vector3d rotationVector = crossProduct(forwardDirection, upDirection);
|
||||
Vector3d rotated_x = rotateVector(forwardDirection, upDirection, angle_x);
|
||||
Vector3d directionVector = rotateVector(rotated_x, rotationVector, angle_y);
|
||||
return Ray {this->position, directionVector};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue