| 866 | // ---------------------------------------------------------------------------------------- |
| 867 | |
| 868 | class camera_transform |
| 869 | { |
| 870 | |
| 871 | public: |
| 872 | |
| 873 | camera_transform ( |
| 874 | ) |
| 875 | { |
| 876 | *this = camera_transform(vector<double>(1,1,1), |
| 877 | vector<double>(0,0,0), |
| 878 | vector<double>(0,0,1), |
| 879 | 90, |
| 880 | 1); |
| 881 | } |
| 882 | |
| 883 | camera_transform ( |
| 884 | const vector<double>& camera_pos_, |
| 885 | const vector<double>& camera_looking_at_, |
| 886 | const vector<double>& camera_up_direction_, |
| 887 | const double camera_field_of_view_, |
| 888 | const unsigned long num_pixels_ |
| 889 | ) |
| 890 | { |
| 891 | // make sure requires clause is not broken |
| 892 | DLIB_CASSERT(0 < camera_field_of_view_ && camera_field_of_view_ < 180, |
| 893 | "\t camera_transform::camera_transform()" |
| 894 | << "\n\t Invalid inputs were given to this function." |
| 895 | << "\n\t camera_field_of_view_: " << camera_field_of_view_ |
| 896 | ); |
| 897 | |
| 898 | camera_pos = camera_pos_; |
| 899 | camera_looking_at = camera_looking_at_; |
| 900 | camera_up_direction = camera_up_direction_; |
| 901 | camera_field_of_view = camera_field_of_view_; |
| 902 | num_pixels = num_pixels_; |
| 903 | |
| 904 | dlib::vector<double> X,Y,Z; |
| 905 | Z = (camera_looking_at - camera_pos).normalize(); |
| 906 | Y = camera_up_direction - dot(camera_up_direction,Z)*Z; |
| 907 | Y = Y.normalize(); |
| 908 | X = Z.cross(Y); |
| 909 | |
| 910 | set_rowm(proj,0) = trans(X); |
| 911 | // Minus because images have y axis going down but we want the 3d projection to appear using a normal coordinate system with y going up. |
| 912 | set_rowm(proj,1) = -trans(Y); |
| 913 | set_rowm(proj,2) = trans(Z); |
| 914 | |
| 915 | width = num_pixels/2.0; |
| 916 | dist_scale = width/std::tan(pi/180*camera_field_of_view/2); |
| 917 | } |
| 918 | |
| 919 | vector<double> get_camera_pos() const { return camera_pos; } |
| 920 | vector<double> get_camera_looking_at() const { return camera_looking_at; } |
| 921 | vector<double> get_camera_up_direction()const { return camera_up_direction; } |
| 922 | double get_camera_field_of_view() const { return camera_field_of_view; } |
| 923 | unsigned long get_num_pixels() const { return num_pixels; } |
| 924 | |
| 925 | inline dpoint operator() ( |
no outgoing calls
no test coverage detected