- 积分
- 106
- 帖子
- 18
- 主题
- 10
- 精华
- 0
- 最后登录
- 2013-11-25
- 在线时间
- 22 小时
- 私信
|
发表时间 : 2012-9-12 09:45:41
|
浏览 : 1309 评论 : 0
void main ( int argc , char *argv[] )
{
vgIsector *isector;
vgIsector *z_isector;
float x, y, z, h, p, r;
float *los;
float zobs;
float dx, dy;
float length;
float hx, hy;
float cs, sn;
vgPosition *pos;
vgPosition *obs_pos;
vgObserver *obs;
if ( argc < 2 )
{
printf ( "syntax : %s <config file>\n" , argv[0] );
exit ( -1 );
}
/* init, define, and config the system */
vgInitSys();
vgDefineSys( argv[1] );
vgConfigSys();
obs = vgGetObserv( 0 ); /* must be at least one observer defined */
pos = vgNewPos(); /* create a position instance for later use */
obs_pos = vgNewPos(); /* create a position instance for observer */
dx = 2.5f;
dy = 2.5f;
/* Compute heading in degrees from dy, dx */
h = fatan2( dy, dx ) * 57.295779513082323 - 90.0f;
/* Compute length of dx, dy vector */
length = fsqrt( dx*dx + dy*dy );
/* Create the los isector */
isector = make_los_isector( vgGetScene( 0 ), VGIS_TERRALL,
-10000.0f, 10000.0f, 20.0f * length );
/* Create the z isector for the observer */
z_isector = make_z_isector( vgGetScene( 0 ), VGIS_TERRALL,
-10000.0f, 10000.0f );
/* Set the Initial position for isector */
/* Isector is above observer. x,y,z define the los starting point.
h, p, r define the los direction */
vgPosVec( pos, 500.0f, 500.0f, 50.0f, h, -85.0f, 0.0f );
/* Set the initial position for observer */
/* Move position along line (h+90), but look at h-90) */
/* compute vector components of los range in direction of heading */
vgGetSinCos( h, &sn, &cs );
hx = -sn * (length + 20.0f);
hy = cs * (length + 20.0f);
vgPosVec( obs_pos, 500.0f - hy, 500.0f + hx, 0.0f, h-90.0f, 0.0f, 0.0f );
los = (float *) vgMalloc( sizeof (float)*4, vgGetSharedArena() );
/* the real-time loop */
while ( 1 )
{
/* Normal processing, Players, Motion models, Isectors, etc. */
vgSyncFrame();
vgFrame();
/* Get the current vector values for the observer position */
vgGetPosVec( obs_pos, &x, &y, &z, &h, &p, &r );
/* Compute new position for observer */
x += dx; y += dy;
/* Use z isector to compute terrain elevation for observer,
add 3.0 so that the eye is above the ground */
zobs = compute_z( z_isector, x, y ) + 3.0f;
/* Position the observer */
vgPosVec( obs_pos, x, y, zobs, h, p, r );
vgPos( obs, obs_pos );
/* Get the current vector values for the isector position */
vgGetPosVec( pos, &x, &y, &z, &h, &p, &r );
/* Compute new x,y position for the isector */
x += dx; y += dy;
vgPosVec( pos, x, y, z, h, p, r );
/* Set the los Isector position and compute results */
compute_los( isector, pos, los );
printf( "line of sight distance for (%f,%f) = %f\n",
x, y, los[0] );
}
vgFree( los );
|
|