scam_c.h (3613B)
1 /* Copyright (C) 2021-2023 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifndef SCAM_C_H 17 #define SCAM_C_H 18 19 #include "scam.h" /* For enum scam_type */ 20 21 #include <rsys/logger.h> 22 #include <rsys/ref_count.h> 23 24 struct perspective { 25 double screen2world[9]; 26 double camera2world[9]; 27 28 double position[3]; /* Lens position */ 29 30 double solid_angle; /* In sr */ 31 double rcp_tan_half_fov; /* 1 / tan(vertical_fov / 2) */ 32 double aspect_ratio; /* width / height */ 33 double lens_radius; /* 0 <=> pinhole camera */ 34 double focal_distance; /* Unused when lens_radius == 0 */ 35 }; 36 #define PERSPECTIVE_DEFAULT__ { \ 37 {1,0,0, 0,1,0, 0,0,1}, /* Screen to world transformation */ \ 38 {1,0,0, 0,1,0, 0,0,1}, /* Camera to world transformation */ \ 39 {0,0,0}, /* Lens position */ \ 40 0.60111772988434627069, /* horizontal_fov * 2*sin(vertical_fov/2) */ \ 41 1.0, /* 1/tan(vertical_fov/2) */ \ 42 1.0, /* Aspect ratio */ \ 43 0.0, /* Lens radius */ \ 44 -1.0 /* Focal distance */ \ 45 } 46 static const struct perspective PERSPECTIVE_DEFAULT = PERSPECTIVE_DEFAULT__; 47 48 struct orthographic { 49 double screen2world[9]; 50 double camera2world[9]; 51 52 double position[3]; /* Lens position */ 53 54 double height; /* Height of the image plane */ 55 double aspect_ratio; /* width / height */ 56 }; 57 #define ORTHOGRAPHIC_DEFAULT__ { \ 58 {1,0,0, 0,1,0, 0,0,1}, /* Screen to world transformation */ \ 59 {1,0,0, 0,1,0, 0,0,1}, /* Camera to world transformation */ \ 60 {0,0,0}, /* Lens position */ \ 61 1.0, /* Height */ \ 62 1.0, /* Aspect ratio */ \ 63 } 64 static const struct orthographic ORTHOGRAPHIC_DEFAULT = ORTHOGRAPHIC_DEFAULT__; 65 66 struct scam { 67 enum scam_type type; 68 union { 69 struct perspective persp; 70 struct orthographic ortho; 71 } param; 72 73 int verbose; 74 struct logger* logger; 75 struct logger logger__; 76 77 struct mem_allocator* allocator; 78 ref_T ref; 79 }; 80 81 extern LOCAL_SYM res_T 82 camera_create 83 (struct logger* logger, /* NULL <=> use builtin logger */ 84 struct mem_allocator* allocator, /* NULL <=> use default allocator */ 85 const int verbose, /* Verbosity level */ 86 const enum scam_type type, 87 struct scam** scam); 88 89 extern LOCAL_SYM void 90 orthographic_generate_ray 91 (const struct scam* cam, 92 const struct scam_sample* sample, 93 struct scam_ray* ray); 94 95 extern LOCAL_SYM void 96 perspective_generate_ray 97 (const struct scam* cam, 98 const struct scam_sample* sample, 99 struct scam_ray* ray); 100 101 #endif /* SCAM_C_H */