-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.h
57 lines (48 loc) · 1.81 KB
/
Camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Created by sysgen on 2/12/21.
//
#ifndef UNTITLED1_CAMERA_H
#define UNTITLED1_CAMERA_H
#include <CL/sycl.hpp>
#include "Ray.h"
namespace sc = cl::sycl;
class Camera {
private:
Ray principalRay;
sc::float3 upVector;
sc::float3 horizontalVector;
float rotation;//Currently disabled
float horizontalFov;
float X;
float Y;
float virtualRecDistance;
float virtualRecScale;
public:
Camera(const sc::float3& position, const sc::float3& direction, float hF, float r, float x, float y ):
principalRay(Ray(position, sc::normalize(direction))), horizontalFov(sc::radians(hF/2)), rotation(r), X(x), Y(y) {
virtualRecDistance = 1000;
virtualRecScale = sc::tan(horizontalFov); // NOLINT(cppcoreguidelines-narrowing-conversions)
virtualRecScale = 1000*virtualRecScale/(X);
upVector = {0,0,1};
horizontalVector = sc::normalize(sc::cross(direction, upVector));
upVector = sc::normalize(sc::cross(horizontalVector, direction)); //This may lead to an inverted camera, verify
};
inline Ray getRay(float x, float y) const {
sc::float3 horizontalComp = (horizontalVector*(x-(X/2.0f))*virtualRecScale);
sc::float3 verticalComp = (upVector*(y-(Y/2.0f))*virtualRecScale);
sc::float3 forwardComp = principalRay.getDirection()*virtualRecDistance;
return Ray(principalRay.getOrigin(),
sc::normalize(horizontalComp+verticalComp+forwardComp));
}
inline std::vector<std::vector<Ray>> getRays() const {
std::vector<std::vector<Ray>> rays;
rays.resize((int)X, std::vector<Ray>((int)Y));
for (int i = 0; i < X; i++){
for(int j = 0; j < Y; j++){
rays[i][j] = getRay(i,j);
}
}
return rays;
}
};
#endif //UNTITLED1_CAMERA_H