//-----------------------------------------------------------------------------
// calculate viewing region
void MapCodegenState::calc_viewingregion(pointf f[], double *minz, double *maxz) {
        /* calculate rays through projection plane */
        ntlVec3d camera( -gCamX, -gCamY, -gCamZ );
        ntlVec3d lookat( -gLookatX, -gLookatY, 0.0 );
        ntlVec3d direction = lookat - camera;
        double fovy = 90.0;
        double aspect = (double)gViewSizeX/gViewSizeY;
        /* calculate width of screen using perpendicular triangle diven by
         * viewing direction and screen plane */
        double screenWidth = direction.getNorm()*tan( (fovy*0.5/180.0)*M_PI );

        /* calculate vector orthogonal to up and viewing direction */
        ntlVec3d upVec(0.0, 1.0, 0.0);
        ntlVec3d rightVec( upVec.crossProd(direction) );
        rightVec.normalize();

        /* calculate screen plane up vector, perpendicular to viewdir and right vec */
        upVec = ntlVec3d( rightVec.crossProd(direction) );
        upVec.normalize();

        /* check if vectors are valid FIXME what to do if not? */
        if( (upVec==ntlVec3d(0.0)) || (rightVec==ntlVec3d(0.0)) ) {
          return;
        }

        /* length from center to border of screen plane */
        rightVec *= (screenWidth*aspect * -1.0);
        upVec *= (screenWidth * -1.0);

        /* calc edges positions */
        double zplane = 0.0;
        double maxzcnt = ABS(camera[2]-zplane);
        double minzcnt = maxzcnt;
        ntlVec3d e[4];
        e[0] = direction + rightVec + upVec;    
        e[1] = direction - rightVec + upVec;    
        e[2] = direction + rightVec - upVec;    
        e[3] = direction - rightVec - upVec;    
        for(int i=0;i<4;i++) {
                if((zplane-e[i][2])>1.0) { // only treat negative directions
                        e[i][0] /= (zplane-e[i][2]); 
                        e[i][1] /= (zplane-e[i][2]); 
                }
                //ntlVec3d p1( camera[0] + e[i][0] * camera[2], camera[1] + e[i][1] * camera[2], 0.0 );
                f[i].x = gViewRegion[i].x = camera[0] + e[i][0] * camera[2];
                f[i].y = gViewRegion[i].y = camera[1] + e[i][1] * camera[2];

                //double currz = ABS(e[i][2] + zplane);
                ntlVec3d fiVec = ntlVec3d(f[i].x,f[i].y,zplane);
                double currz = (fiVec-camera).getNorm();
                //cout << "  f"<<i<<" "<<fiVec<<" c:"<< camera <<" d:"<<(fiVec-camera)<<"  curr:"<<currz<<endl;
                //if(i==0) {
                        //minzcnt = currz;
                        //maxzcnt = currz;
                //} else {
                        if( minzcnt > currz) minzcnt = currz;
                        if( maxzcnt < currz) maxzcnt = currz;
                //}
        }

        // save min./max. z distance
        *maxz = maxzcnt;
        *minz = minzcnt;
}
Exemple #2
0
ntlVec3d Attribute::getAsVec3d() {
	return ntlVec3d(0.);
}