00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "orthographicLens.h"
00020 #include "indent.h"
00021
00022 TypeHandle OrthographicLens::_type_handle;
00023
00024
00025
00026
00027
00028
00029
00030 PT(Lens) OrthographicLens::
00031 make_copy() const {
00032 return new OrthographicLens(*this);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 bool OrthographicLens::
00044 is_linear() const {
00045 return true;
00046 }
00047
00048
00049
00050
00051
00052
00053 void OrthographicLens::
00054 write(ostream &out, int indent_level) const {
00055 indent(out, indent_level) << get_type() << " film size = " << get_film_size() << "\n";
00056 }
00057
00058
00059
00060
00061
00062
00063
00064 void OrthographicLens::
00065 compute_projection_mat() {
00066 CoordinateSystem cs = _cs;
00067 if (cs == CS_default) {
00068 cs = default_coordinate_system;
00069 }
00070
00071 float a = 2.0f / (_far_distance - _near_distance);
00072 float b = -(_far_distance + _near_distance) / (_far_distance - _near_distance);
00073
00074 LMatrix4f canonical;
00075 switch (cs) {
00076 case CS_zup_right:
00077 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00078 0.0f, 0.0f, a, 0.0f,
00079 0.0f, 1.0f, 0.0f, 0.0f,
00080 0.0f, 0.0f, b, 1.0f);
00081 break;
00082
00083 case CS_yup_right:
00084 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00085 0.0f, 1.0f, 0.0f, 0.0f,
00086 0.0f, 0.0f, -a, 0.0f,
00087 0.0f, 0.0f, b, 1.0f);
00088 break;
00089
00090 case CS_zup_left:
00091 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00092 0.0f, 0.0f, -a, 0.0f,
00093 0.0f, 1.0f, 0.0f, 0.0f,
00094 0.0f, 0.0f, b, 1.0f);
00095 break;
00096
00097 case CS_yup_left:
00098 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00099 0.0f, 1.0f, 0.0f, 0.0f,
00100 0.0f, 0.0f, a, 0.0f,
00101 0.0f, 0.0f, b, 1.0f);
00102 break;
00103
00104 default:
00105 gobj_cat.error()
00106 << "Invalid coordinate system " << (int)cs << " in PerspectiveLens!\n";
00107 canonical = LMatrix4f::ident_mat();
00108 }
00109
00110
00111 _projection_mat = get_lens_mat_inv() * canonical * get_film_mat();
00112 adjust_comp_flags(CF_projection_mat_inv,
00113 CF_projection_mat);
00114 }