update camera class
This commit is contained in:
parent
f38e7d8081
commit
a99f5e3531
@ -4,11 +4,17 @@
|
||||
|
||||
class camera {
|
||||
public:
|
||||
__device__ camera() {
|
||||
lower_left_corner = vec3(-2.0, -1.0, -1.0);
|
||||
horizontal = vec3( 4.0, 0.0, 0.0);
|
||||
vertical = vec3( 0.0, 2.0, 0.0);
|
||||
origin = vec3( 0.0, 0.0, 0.0);
|
||||
__device__ camera(vec3 lookfrom, vec3 lookat, vec3 vup, float vfov, float aspect) {
|
||||
float theta = vfov*M_PI/180;
|
||||
float half_height = tan(theta/2);
|
||||
float half_width = aspect*half_height;
|
||||
origin = lookfrom;
|
||||
vec3 w = unit_vector(lookfrom - lookat);
|
||||
vec3 u = unit_vector(cross(vup, w));
|
||||
vec3 v = cross(w, u);
|
||||
lower_left_corner = origin - half_width*u - half_height*v - w;
|
||||
horizontal = 2*half_width*u;
|
||||
vertical = 2*half_height*v;
|
||||
}
|
||||
__device__ ray get_ray(float u, float v) {
|
||||
return ray(origin, lower_left_corner + u*horizontal + v*vertical - origin);
|
||||
|
10
src/main.cu
10
src/main.cu
@ -93,7 +93,7 @@ __global__ void render(vec3 *fb,
|
||||
fb[pixel_idx] = col;
|
||||
}
|
||||
|
||||
__global__ void create_world(hitable **d_list, int d_list_size, hitable **d_world, camera **d_camera) {
|
||||
__global__ void create_world(hitable **d_list, int d_list_size, hitable **d_world, camera **d_camera, int nx, int ny) {
|
||||
if (threadIdx.x == 0 && blockIdx.y == 0) {
|
||||
d_list[0] = new sphere(vec3( 0, 0 , -1), 0.5, new lambertian(vec3(0.1, 0.2, 0.5)));
|
||||
d_list[1] = new sphere(vec3( 0, -100.5, -1), 100, new lambertian(vec3(0.8, 0.8, 0.0)));
|
||||
@ -101,7 +101,11 @@ __global__ void create_world(hitable **d_list, int d_list_size, hitable **d_worl
|
||||
d_list[3] = new sphere(vec3(-1, 0 , -1), 0.5, new dielectric(1.5));
|
||||
d_list[4] = new sphere(vec3(-1, 0 , -1), -0.45, new dielectric(1.5));
|
||||
*d_world = new hitable_list(d_list, d_list_size);
|
||||
*d_camera = new camera();
|
||||
*d_camera = new camera(vec3(-2,2,1),
|
||||
vec3(0,0,-1),
|
||||
vec3(0,1,0),
|
||||
20.0,
|
||||
float(nx)/float(ny));
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +148,7 @@ int main() {
|
||||
checkCudaErrors(cudaMalloc((void **)&d_world, sizeof(hitable *)));
|
||||
camera **d_camera;
|
||||
checkCudaErrors(cudaMalloc((void **)&d_camera, sizeof(camera *)));
|
||||
create_world<<<1,1>>>(d_list, d_list_size, d_world, d_camera);
|
||||
create_world<<<1,1>>>(d_list, d_list_size, d_world, d_camera, nx, ny);
|
||||
checkCudaErrors(cudaGetLastError());
|
||||
checkCudaErrors(cudaDeviceSynchronize());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user