58 #include <OpenMesh/Tools/VDPM/ViewingParameters.hh>
73 for (
unsigned int i = 0; i < 16; ++i)
74 modelview_matrix_[i] = 0.0;
78 tolerance_square_ = 0.001f;
83 update_viewing_configurations()
91 float a11, a12, a13, a21, a22, a23, a31, a32, a33;
95 #if (_MSC_VER >= 1900 )
96 Vec3f inv_rot[3]{ {},{},{} };
97 Vec3f normal[4]{ {},{},{},{} };
103 a11 = (float) modelview_matrix_[0];
104 a12 = (float) modelview_matrix_[4];
105 a13 = (float) modelview_matrix_[8];
106 trans[0] = (float) modelview_matrix_[12];
108 a21 = (float) modelview_matrix_[1];
109 a22 = (float) modelview_matrix_[5];
110 a23 = (float) modelview_matrix_[9];
111 trans[1] = (float) modelview_matrix_[13];
113 a31 = (float) modelview_matrix_[2];
114 a32 = (float) modelview_matrix_[6];
115 a33 = (float) modelview_matrix_[10];
116 trans[2] = (float) modelview_matrix_[14];
118 invdet = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
119 invdet= (float) 1.0/invdet;
121 (inv_rot[0])[0] = (a33*a22-a32*a23) * invdet;
122 (inv_rot[0])[1] = -(a33*a12-a32*a13) * invdet;
123 (inv_rot[0])[2] = (a23*a12-a22*a13) * invdet;
124 (inv_rot[1])[0] = -(a33*a21-a31*a23) * invdet;
125 (inv_rot[1])[1] = (a33*a11-a31*a13) * invdet;
126 (inv_rot[1])[2] = -(a23*a11-a21*a13) * invdet;
127 (inv_rot[2])[0] = (a32*a21-a31*a22) * invdet;
128 (inv_rot[2])[1] = -(a32*a11-a31*a12) * invdet;
129 (inv_rot[2])[2] = (a22*a11-a21*a12) * invdet;
131 eye_pos_ = -
Vec3f(
dot(inv_rot[0], trans),
132 dot(inv_rot[1], trans),
133 dot(inv_rot[2], trans));
134 right_dir_ =
Vec3f(a11, a12, a13);
135 up_dir_ =
Vec3f(a21, a22, a23);
136 view_dir_ = -
Vec3f(a31, a32, a33);
139 const float half_theta = fovy() * 0.5f;
140 const float half_phi = atanf(aspect() * tanf(half_theta));
142 const float sin1 = sinf(half_theta);
143 const float cos1 = cosf(half_theta);
144 const float sin2 = sinf(half_phi);
145 const float cos2 = cosf(half_phi);
147 normal[0] = cos2 * right_dir_ + sin2 * view_dir_;
148 normal[1] = -cos1 * up_dir_ - sin1 * view_dir_;
149 normal[2] = -cos2 * right_dir_ + sin2 * view_dir_;
150 normal[3] = cos1 * up_dir_ - sin1 * view_dir_;
152 for (
int i=0; i<4; i++)
153 frustum_plane_[i] = Plane3d(normal[i], eye_pos_);
160 std::cout <<
" ModelView matrix: " << std::endl;
161 std::cout <<
" |" << modelview_matrix_[0] <<
" " << modelview_matrix_[4] <<
" " << modelview_matrix_[8] <<
" " << modelview_matrix_[12] <<
"|" << std::endl;
162 std::cout <<
" |" << modelview_matrix_[1] <<
" " << modelview_matrix_[5] <<
" " << modelview_matrix_[9] <<
" " << modelview_matrix_[13] <<
"|" << std::endl;
163 std::cout <<
" |" << modelview_matrix_[2] <<
" " << modelview_matrix_[6] <<
" " << modelview_matrix_[10] <<
" " << modelview_matrix_[14] <<
"|" << std::endl;
164 std::cout <<
" |" << modelview_matrix_[3] <<
" " << modelview_matrix_[7] <<
" " << modelview_matrix_[11] <<
" " << modelview_matrix_[15] <<
"|" << std::endl;
165 std::cout <<
" Fovy: " << fovy_ << std::endl;
166 std::cout <<
" Aspect: " << aspect_ << std::endl;
167 std::cout <<
" Tolerance^2: " << tolerance_square_ << std::endl;
168 std::cout <<
" Eye Pos: " << eye_pos_ << std::endl;
169 std::cout <<
" Right dir: " << right_dir_ << std::endl;
170 std::cout <<
" Up dir: " << up_dir_ << std::endl;
171 std::cout <<
" View dir: " << view_dir_ << std::endl;
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
VectorT< float, 3 > Vec3f