00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "orthographicLens.h"
00016 #include "indent.h"
00017 #include "bamReader.h"
00018
00019 TypeHandle OrthographicLens::_type_handle;
00020
00021
00022
00023
00024
00025
00026
00027 PT(Lens) OrthographicLens::
00028 make_copy() const {
00029 return new OrthographicLens(*this);
00030 }
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 bool OrthographicLens::
00041 is_linear() const {
00042 return true;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052 bool OrthographicLens::
00053 is_orthographic() const {
00054 return true;
00055 }
00056
00057
00058
00059
00060
00061
00062 void OrthographicLens::
00063 write(ostream &out, int indent_level) const {
00064 indent(out, indent_level) << get_type() << " film size = " << get_film_size() << "\n";
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 void OrthographicLens::
00074 do_compute_projection_mat(Lens::CData *lens_cdata) {
00075 CoordinateSystem cs = lens_cdata->_cs;
00076 if (cs == CS_default) {
00077 cs = get_default_coordinate_system();
00078 }
00079
00080 PN_stdfloat a = 2.0f / (lens_cdata->_far_distance - lens_cdata->_near_distance);
00081 PN_stdfloat b = -(lens_cdata->_far_distance + lens_cdata->_near_distance) / (lens_cdata->_far_distance - lens_cdata->_near_distance);
00082
00083 LMatrix4 canonical;
00084 switch (cs) {
00085 case CS_zup_right:
00086 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00087 0.0f, 0.0f, a, 0.0f,
00088 0.0f, 1.0f, 0.0f, 0.0f,
00089 0.0f, 0.0f, b, 1.0f);
00090 break;
00091
00092 case CS_yup_right:
00093 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00094 0.0f, 1.0f, 0.0f, 0.0f,
00095 0.0f, 0.0f, -a, 0.0f,
00096 0.0f, 0.0f, b, 1.0f);
00097 break;
00098
00099 case CS_zup_left:
00100 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00101 0.0f, 0.0f, -a, 0.0f,
00102 0.0f, 1.0f, 0.0f, 0.0f,
00103 0.0f, 0.0f, b, 1.0f);
00104 break;
00105
00106 case CS_yup_left:
00107 canonical.set(1.0f, 0.0f, 0.0f, 0.0f,
00108 0.0f, 1.0f, 0.0f, 0.0f,
00109 0.0f, 0.0f, a, 0.0f,
00110 0.0f, 0.0f, b, 1.0f);
00111 break;
00112
00113 default:
00114 gobj_cat.error()
00115 << "Invalid coordinate system " << (int)cs << " in OrthographicLens!\n";
00116 canonical = LMatrix4::ident_mat();
00117 }
00118
00119 lens_cdata->_projection_mat = do_get_lens_mat_inv(lens_cdata) * canonical * do_get_film_mat(lens_cdata);
00120 lens_cdata->_projection_mat_left = lens_cdata->_projection_mat_right = lens_cdata->_projection_mat;
00121
00122 do_adjust_comp_flags(lens_cdata,
00123 CF_projection_mat_inv | CF_projection_mat_left_inv | CF_projection_mat_right_inv,
00124 CF_projection_mat);
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 void OrthographicLens::
00134 register_with_read_factory() {
00135 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 TypedWritable *OrthographicLens::
00147 make_from_bam(const FactoryParams ¶ms) {
00148 OrthographicLens *lens = new OrthographicLens;
00149 DatagramIterator scan;
00150 BamReader *manager;
00151
00152 parse_params(params, scan, manager);
00153 lens->fillin(scan, manager);
00154
00155 return lens;
00156 }