fixed pixel direction and flipped coordinate system
This commit is contained in:
parent
ef79acef73
commit
f5a6e9e119
2 changed files with 11 additions and 6 deletions
|
@ -7,9 +7,9 @@ Ray PerspectiveCamera::createRay(float x, float y) const {
|
|||
// Set up a left-handed coordinate system,
|
||||
// in which the camera looks along the positive z-Axis
|
||||
|
||||
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 normalVector = normalized(crossProduct(upDirection, forwardDirection));
|
||||
Vector3d normalVector_fov = normalVector * std::abs(tan(this->fovAngle / 360.0f * PI));
|
||||
Vector3d upVector_fov = this->upDirection * std::abs(tan(this->fovAngle / 360.0f * PI));
|
||||
Vector3d directionVector = normalized(forwardDirection + x * normalVector_fov + y * upVector_fov);
|
||||
|
||||
return Ray {this->position, directionVector};
|
||||
|
|
|
@ -14,11 +14,16 @@ Texture SimpleRenderer::renderImage(Scene const &scene, Camera const &camera, in
|
|||
|
||||
// Create the image by casting one ray into the scene for each pixel
|
||||
float pixel_step_x = 2 * max_x / width;
|
||||
float pixel_step_y = 2 * max_y / width;
|
||||
float pixel_step_y = 2 * max_y / height;
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
Ray ray = camera.createRay((x - width/2) * pixel_step_x, (y - width/2) * pixel_step_y);
|
||||
image.setPixelAt(x, y, scene.traceRay(ray));
|
||||
Ray ray = camera.createRay((x - width/2) * pixel_step_x, (y - height/2) * pixel_step_y);
|
||||
image.setPixelAt(x, height - 1 - y, scene.traceRay(ray));
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < 20; x++) {
|
||||
for (int y = 0; y < 20; y++) {
|
||||
image.setPixelAt(x, y, Color(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
return image;
|
||||
|
|
Loading…
Reference in a new issue