ssol_camera.h (1743B)
1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) 2 * Copyright (C) 2016, 2018 CNRS 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef SSOL_CAMERA_H 18 #define SSOL_CAMERA_H 19 20 #include <rsys/float3.h> 21 #include <rsys/ref_count.h> 22 23 struct ssol_device; 24 25 struct ssol_camera { 26 /* Orthogonal basis of the camera */ 27 float axis_x[3]; 28 float axis_y[3]; 29 float axis_z[3]; 30 31 float position[3]; 32 float fov_x; /* Field of view in radians */ 33 float rcp_proj_ratio; /* height / width */ 34 35 ref_T ref; 36 struct ssol_device* dev; 37 }; 38 39 static FINLINE void 40 camera_ray 41 (const struct ssol_camera* cam, 42 const float sample[2], /* In [0, 1[ */ 43 float org[3], 44 float dir[3]) 45 { 46 float x[3], y[3], len; 47 (void)len; /* avoid warning in debug */ 48 ASSERT(cam && sample && org && dir); 49 ASSERT(sample[0] >= 0 || sample[0] < 1.f); 50 ASSERT(sample[1] >= 0 || sample[1] < 1.f); 51 52 f3_mulf(x, cam->axis_x, sample[0]*2.f - 1.f); 53 f3_mulf(y, cam->axis_y, sample[1]*2.f - 1.f); 54 f3_add(dir, f3_add(dir, x, y), cam->axis_z); 55 len = f3_normalize(dir, dir); 56 ASSERT(len >= 1.e-6f); 57 f3_set(org, cam->position); 58 } 59 60 #endif /* SSOL_CAMERA_H */ 61