--
FgRenderFrame() is a glut callback function for rendering
FgRenderFrame() {
ssgCullAndDraw( globals->get_scenery()->get_scene_graph())
}
SceneGraph
A scene graph is essentially just a tree structured database
containing a hierarchy of branches and a bunch of leaf nodes.To
ssgCullAndDraw we are passing the address of the root node. I have
given the flow culling and rendering below
My doubts
1. When I printed the clip planes of frustum the values are changing
dynamically. how we are deciding the frustum's clip planes and how we
are positioning the frustum in scenegraph.
2. How is the bounding sphere related to frustum.
void ssgCullAndDraw ( ssgBranch *r ){
_ssgCurrentContext->cull(r) ;
_ssgDrawDList ();
}
void ssgContext::cull ( ssgBranch *r )
{
r -> cull ( frustum, cameraMatrix, TRUE ) ;
}
void ssgBranch::cull ( sgFrustum *f, sgMat4 m, int test_needed )
{
if ( ! preTravTests ( &test_needed, SSGTRAV_CULL ) ) //SSGTRAV_CULL=1
return ;
int cull_result = cull_test ( f, m, test_needed ) ;
if ( cull_result == SSG_OUTSIDE )
return ;
for ( ssgEntity *e = getKid ( 0 ) ; e != NULL ; e = getNextKid() )
e -> cull ( f, m, cull_result != SSG_INSIDE ) ; //cull_result is
either SSG_INSIDE or SSG_STTRADLE
postTravTests ( SSGTRAV_CULL ) ;
}
int ssgEntity::preTravTests ( int *test_needed, int which )
{
if ( (getTraversalMask() & which) == 0 ) //returns
traversal_mask=0xFFFFFFFF which=1
{
if ( which & SSGTRAV_HOT ) //SSGTRAV_HOT=4
stats_hot_no_trav ++ ;
return FALSE ;
}
if ( preTravCB != NULL ) // initialized to preTravCB = NULL
{
int result = (*preTravCB)(this,which) ;
if ( result == 0 ) return FALSE ;
if ( result == 2 ) *test_needed = 0 ;
}
return TRUE ;
}
ssgCullResult ssgEntity::cull_test ( sgFrustum *f, sgMat4 m, int test_needed )
{
if ( ! test_needed )
return SSG_INSIDE ; //SSG_INSIDE =true // draw the node
stats_cull_test++ ;
cout<<" No of test :"<< stats_cull_test<<"test ="<<test_needed<<endl;
sgSphere tmp = *(getBSphere()) ;
if ( tmp.isEmpty () ) //returns (radius < SG_ZERO )
return SSG_OUTSIDE ;
tmp . orthoXform ( m ) ;
return (ssgCullResult) f -> contains ( &tmp ) ;
}
void ssgLeaf::cull ( sgFrustum *f, sgMat4 m, int test_needed )
{
int cull_result = cull_test ( f, m, test_needed ) ;
if ( cull_result == SSG_OUTSIDE )
return ;
if ( isTranslucent () )
_ssgDrawLeaf ( this ) ;
else
draw () ;
}
void ssgEntity::postTravTests ( int which )
{
if ( postTravCB != NULL )
(*postTravCB)(this,which) ;
}
sgFrustum (void)
{
ortho = FALSE ;
nnear = SG_ONE ;
ffar = 1000000.0f ;
hfov = SG_45 ;
vfov = SG_45 ;
if ( ortho )
{
right = SG_HALF * hfov ;
top = SG_HALF * vfov ;
}
else
{
right = nnear * (SGfloat) tan ( hfov * SG_DEGREES_TO_RADIANS / SG_TWO ) ;
top = nnear * (SGfloat) tan ( vfov * SG_DEGREES_TO_RADIANS / SG_TWO ) ;
}
left = -right ;
bot = -top ;
}
SGfloat width = right - left ;
SGfloat height = top - bot ;
SGfloat depth = ffar - nnear ;
if ( ortho )
{
/* orthographic */
mat[0][0] = SG_TWO / width ;
mat[0][1] = SG_ZERO ;
mat[0][2] = SG_ZERO ;
mat[0][3] = SG_ZERO ;
mat[1][0] = SG_ZERO ;
mat[1][1] = SG_TWO / height ;
mat[1][2] = SG_ZERO ;
mat[1][3] = SG_ZERO ;
mat[2][0] = SG_ZERO ;
mat[2][1] = SG_ZERO ;
mat[2][2] = -SG_TWO / depth ;
mat[2][3] = SG_ZERO ;
mat[3][0] = -( left + right ) / width ;
mat[3][1] = -( bot + top ) / height ;
mat[3][2] = -( nnear + ffar ) / depth ;
mat[3][3] = SG_ONE ;
}
else
{
/* perspective */
mat[0][0] = SG_TWO * nnear / width ; //109.4
mat[0][1] = SG_ZERO ;
mat[0][2] = SG_ZERO ;
mat[0][3] = SG_ZERO ;
mat[1][0] = SG_ZERO ;
mat[1][1] = SG_TWO * nnear / height ; //145.9
mat[1][2] = SG_ZERO ;
mat[1][3] = SG_ZERO ;
mat[2][0] = ( right + left ) / width ; //0
mat[2][1] = ( top + bot ) / height ; //0
mat[2][2] = -( ffar + nnear ) / depth ; //-1
mat[2][3] = -SG_ONE ; //
mat[3][0] = SG_ZERO ;
mat[3][1] = SG_ZERO ;
mat[3][2] = -SG_TWO * nnear * ffar / depth ; //20
mat[3][3] = SG_ZERO ;
}
sgSetVec4( plane[ SG_LEFT_PLANE ], SG_ONE, SG_ZERO, SG_ZERO, SG_ONE );
sgSetVec4( plane[ SG_RIGHT_PLANE ], -SG_ONE, SG_ZERO, SG_ZERO, SG_ONE );
sgSetVec4( plane[ SG_BOT_PLANE ], SG_ZERO, SG_ONE, SG_ZERO, SG_ONE );
sgSetVec4( plane[ SG_TOP_PLANE ], SG_ZERO, -SG_ONE, SG_ZERO, SG_ONE );
sgSetVec4( plane[ SG_NEAR_PLANE ], SG_ZERO, SG_ZERO, SG_ONE, SG_ONE );
sgSetVec4( plane[ SG_FAR_PLANE ], SG_ZERO, SG_ZERO, -SG_ONE, SG_ONE );
for ( int i = 0 ; i < 6 ; i++ )
{
sgVec4 tmp ;
//cout<<"in ";
for ( int j = 0 ; j < 4 ; j++ )
tmp[j] = sgScalarProductVec4 ( plane[i], mat[j] ) ;
sgScaleVec4 ( plane[i], tmp, SG_ONE / sgLengthVec3 ( tmp ) ) ; //
1/sqrt(109.4 * 109.4 +20 * 20)
}
}
}
_______________________________________________
Flightgear-users mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-users
2f585eeea02e2c79d7b1d8c4963bae2d