53 #include <OpenMesh/Tools/VDPM/ViewingParameters.hh> 68 for (
unsigned int i = 0; i < 16; ++i)
69 modelview_matrix_[i] = 0.0;
73 tolerance_square_ = 0.001f;
78 update_viewing_configurations()
86 float a11, a12, a13, a21, a22, a23, a31, a32, a33;
90 #if ((defined(_MSC_VER) && (_MSC_VER >= 1800)) ) 91 Vec3f inv_rot[3]{ {},{},{} };
92 Vec3f normal[4]{ {},{},{},{} };
98 a11 = (float) modelview_matrix_[0];
99 a12 = (float) modelview_matrix_[4];
100 a13 = (float) modelview_matrix_[8];
101 trans[0] = (float) modelview_matrix_[12];
103 a21 = (float) modelview_matrix_[1];
104 a22 = (float) modelview_matrix_[5];
105 a23 = (float) modelview_matrix_[9];
106 trans[1] = (float) modelview_matrix_[13];
108 a31 = (float) modelview_matrix_[2];
109 a32 = (float) modelview_matrix_[6];
110 a33 = (float) modelview_matrix_[10];
111 trans[2] = (float) modelview_matrix_[14];
113 invdet = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
114 invdet= (float) 1.0/invdet;
116 (inv_rot[0])[0] = (a33*a22-a32*a23) * invdet;
117 (inv_rot[0])[1] = -(a33*a12-a32*a13) * invdet;
118 (inv_rot[0])[2] = (a23*a12-a22*a13) * invdet;
119 (inv_rot[1])[0] = -(a33*a21-a31*a23) * invdet;
120 (inv_rot[1])[1] = (a33*a11-a31*a13) * invdet;
121 (inv_rot[1])[2] = -(a23*a11-a21*a13) * invdet;
122 (inv_rot[2])[0] = (a32*a21-a31*a22) * invdet;
123 (inv_rot[2])[1] = -(a32*a11-a31*a12) * invdet;
124 (inv_rot[2])[2] = (a22*a11-a21*a12) * invdet;
126 eye_pos_ = -
Vec3f(
dot(inv_rot[0], trans),
127 dot(inv_rot[1], trans),
128 dot(inv_rot[2], trans));
129 right_dir_ =
Vec3f(a11, a12, a13);
130 up_dir_ =
Vec3f(a21, a22, a23);
131 view_dir_ = -
Vec3f(a31, a32, a33);
134 const float half_theta = fovy() * 0.5f;
135 const float half_phi = atanf(aspect() * tanf(half_theta));
137 const float sin1 = sinf(half_theta);
138 const float cos1 = cosf(half_theta);
139 const float sin2 = sinf(half_phi);
140 const float cos2 = cosf(half_phi);
142 normal[0] = cos2 * right_dir_ + sin2 * view_dir_;
143 normal[1] = -cos1 * up_dir_ - sin1 * view_dir_;
144 normal[2] = -cos2 * right_dir_ + sin2 * view_dir_;
145 normal[3] = cos1 * up_dir_ - sin1 * view_dir_;
147 for (
int i=0; i<4; i++)
148 frustum_plane_[i] = Plane3d(normal[i], eye_pos_);
155 std::cout <<
" ModelView matrix: " << std::endl;
156 std::cout <<
" |" << modelview_matrix_[0] <<
" " << modelview_matrix_[4] <<
" " << modelview_matrix_[8] <<
" " << modelview_matrix_[12] <<
"|" << std::endl;
157 std::cout <<
" |" << modelview_matrix_[1] <<
" " << modelview_matrix_[5] <<
" " << modelview_matrix_[9] <<
" " << modelview_matrix_[13] <<
"|" << std::endl;
158 std::cout <<
" |" << modelview_matrix_[2] <<
" " << modelview_matrix_[6] <<
" " << modelview_matrix_[10] <<
" " << modelview_matrix_[14] <<
"|" << std::endl;
159 std::cout <<
" |" << modelview_matrix_[3] <<
" " << modelview_matrix_[7] <<
" " << modelview_matrix_[11] <<
" " << modelview_matrix_[15] <<
"|" << std::endl;
160 std::cout <<
" Fovy: " << fovy_ << std::endl;
161 std::cout <<
" Aspect: " << aspect_ << std::endl;
162 std::cout <<
" Tolerance^2: " << tolerance_square_ << std::endl;
163 std::cout <<
" Eye Pos: " << eye_pos_ << std::endl;
164 std::cout <<
" Right dir: " << right_dir_ << std::endl;
165 std::cout <<
" Up dir: " << up_dir_ << std::endl;
166 std::cout <<
" View dir: " << view_dir_ << std::endl;
VectorT< float, 3 > Vec3f
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.