void EschFrameRef::set_direction(float ii, float ij, float ik, dword update) { dir.i = ii; dir.j = ij; dir.k = ik; dir.normalize(); EschVector top(orient.mtx[ESCH_MTX_D], orient.mtx[ESCH_MTX_E], orient.mtx[ESCH_MTX_F]); //��� Create right vector EschVector right = top CROSS dir; //��� Fill in matrix for ortho rotation //��� Transform orient.mtx[ESCH_MTX_A] = right.i; orient.mtx[ESCH_MTX_B] = right.j; orient.mtx[ESCH_MTX_C] = right.k; orient.mtx[ESCH_MTX_G] = dir.i; orient.mtx[ESCH_MTX_H] = dir.j; orient.mtx[ESCH_MTX_I] = dir.k; if (update & ESCH_UPD_ORTHO) orthogonalize(update); else if (update & ESCH_UPD_INVERSE) compute_inverse(); }
int main() { compute_inverse(); int n = 0 , k = 0 , t , i=0, j=1; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&k); for(i=0;i<n;i++) scanf("%lld",&ar[i]); std::sort( ar , ar + n ); printf("Case #%d: %lld\n",j++,answer(n,k)); } }
void Channel::_updateNearFar( const mesh::BoundingSphere& boundingSphere ) { // compute dynamic near/far plane of whole model const FrameData& frameData = _getFrameData(); const eq::Matrix4f& rotation = frameData.getCameraRotation(); const eq::Matrix4f headTransform = getHeadTransform() * rotation; eq::Matrix4f modelInv; compute_inverse( headTransform, modelInv ); const eq::Vector3f zero = modelInv * eq::Vector3f::ZERO; eq::Vector3f front = modelInv * eq::Vector3f( 0.0f, 0.0f, -1.0f ); front -= zero; front.normalize(); front *= boundingSphere.w(); const eq::Vector3f center = frameData.getCameraPosition().get_sub_vector< 3 >() - boundingSphere.get_sub_vector< 3 >(); const eq::Vector3f nearPoint = headTransform * ( center - front ); const eq::Vector3f farPoint = headTransform * ( center + front ); if( useOrtho( )) { LBASSERTINFO( fabs( farPoint.z() - nearPoint.z() ) > std::numeric_limits< float >::epsilon(), nearPoint << " == " << farPoint ); setNearFar( -nearPoint.z(), -farPoint.z() ); } else { // estimate minimal value of near plane based on frustum size const eq::Frustumf& frustum = getFrustum(); const float width = fabs( frustum.right() - frustum.left() ); const float height = fabs( frustum.top() - frustum.bottom() ); const float size = LB_MIN( width, height ); const float minNear = frustum.near_plane() / size * .001f; const float zNear = LB_MAX( minNear, -nearPoint.z() ); const float zFar = LB_MAX( zNear * 2.f, -farPoint.z() ); setNearFar( zNear, zFar ); } }
void FrameData::moveCamera( const float x, const float y, const float z ) { if( _pilotMode ) { eq::Matrix4f matInverse; compute_inverse( _rotation, matInverse ); eq::Vector4f shift = matInverse * eq::Vector4f( x, y, z, 1 ); _position += shift; } else { _position.x() += x; _position.y() += y; _position.z() += z; } setDirty( DIRTY_CAMERA ); }
void Renderer::updateNearFar( const Vector4f& boundingSphere ) { const Matrix4f& view = getViewMatrix(); Matrix4f viewInv; compute_inverse( view, viewInv ); const Vector3f& zero = viewInv * Vector3f::ZERO; Vector3f front = viewInv * Vector3f( 0.0f, 0.0f, -1.0f ); front -= zero; front.normalize(); front *= boundingSphere.w(); const Vector3f& translation = getModelMatrix().get_translation(); const Vector3f& center = translation - boundingSphere.get_sub_vector< 3 >(); const Vector3f& nearPoint = view * ( center - front ); const Vector3f& farPoint = view * ( center + front ); if( _impl->useOrtho( )) { LBASSERTINFO( fabs( farPoint.z() - nearPoint.z() ) > std::numeric_limits< float >::epsilon(), nearPoint << " == " << farPoint ); setNearFar( -nearPoint.z(), -farPoint.z() ); } else { // estimate minimal value of near plane based on frustum size const eq::Frustumf& frustum = _impl->getFrustum(); const float width = fabs( frustum.right() - frustum.left() ); const float height = fabs( frustum.top() - frustum.bottom() ); const float size = LB_MIN( width, height ); const float minNear = frustum.near_plane() / size * .001f; const float zNear = LB_MAX( minNear, -nearPoint.z() ); const float zFar = LB_MAX( zNear * 2.f, -farPoint.z() ); setNearFar( zNear, zFar ); } }
static char *test_compute_inverse() { Matrix *a = create_matrix(3, 3); // The matrix b will contain the value of the a's inverse. Matrix *b = create_matrix(3, 3); b->value[0][0] = -1; b->value[0][1] = 0.5; b->value[0][2] = 0; b->value[1][0] = 0.5; b->value[1][1] = -1; b->value[1][2] = 0.5; b->value[2][0] = 0.3333333; b->value[2][1] = 0.5; b->value[2][2] = -0.333333; for(int i = 0, k = 1; i < 3; i++) { for(int j = 0; j < 3; j++, k++) { if(k != 5) { a->value[i][j] = k; } else { // The matrix that has all the values from 1 to 9 in spiral // has no inverse, so I replaced the 5 with an four. a->value[i][j] = 4; } } } a->determinant = get_determinant(a); compute_inverse(a); mu_assert("The invers is not equal to the matrix b", compare_matrices( a->inverse, b)); destroy_matrix(a); destroy_matrix(b); return 0; }
void EschFrameRef::set_top(float ii, float ij, float ik, dword update) { EschVector v(ii,ij,ik); v.normalize(); //��� Create right vector EschVector right = v CROSS dir; //��� Fill in matrix for ortho rotation //��� Transform orient.mtx[ESCH_MTX_A] = right.i; orient.mtx[ESCH_MTX_B] = right.j; orient.mtx[ESCH_MTX_C] = right.k; orient.mtx[ESCH_MTX_D] = v.i; orient.mtx[ESCH_MTX_E] = v.j; orient.mtx[ESCH_MTX_F] = v.k; if (update & ESCH_UPD_ORTHO) orthogonalize_top(update); else if (update & ESCH_UPD_INVERSE) compute_inverse(); }
//�������������������������������������������������������������������������Ŀ // EschFrameRef - set_top � //��������������������������������������������������������������������������� void EschFrameRef::set_top(const EschVector *v, dword update) { EschVector top(v->i, v->j, v->k); top.normalize(); //��� Create right vector EschVector right = top CROSS dir; //��� Fill in matrix for ortho rotation //��� Transform orient.mtx[ESCH_MTX_A] = right.i; orient.mtx[ESCH_MTX_B] = right.j; orient.mtx[ESCH_MTX_C] = right.k; orient.mtx[ESCH_MTX_D] = top.i; orient.mtx[ESCH_MTX_E] = top.j; orient.mtx[ESCH_MTX_F] = top.k; if (update & ESCH_UPD_ORTHO) orthogonalize_top(update); else if (update & ESCH_UPD_INVERSE) compute_inverse(); }