1、void main(void) static vgObserver *obs; static vgChannel *chan; static vgScene *scene; static vgObject *m1,*m2; static vgPlayer *tank,*heli,*missile1,*missile2; static vgPlayer *e2c,*tank_crater,*e2c_crater; static vgIsector *fortank,*formissile1,*formissile2; static vgIsector *fore2c,*forheli,*forc
2、rater; static vgPosition *pos,*e2c_pos,*heli_pos,*missile_pos,*target_pos; static vgFx *h_blade1,*h_blade2; static vgFx *e_blade1,*e_blade2,*e_trail1,*e_trail2; static vgFx *e_airhit,*e_engsmoke,*e_engburn,*e_flash; static vgFx *e_fire,*e_smoke,*e_explode,*e_debris; static vgFx *m1_flame,*m1_trail,*
3、m2_flame,*m2_trail; static vgFx *t_flash,*t_explode1,*t_debris1,*t_smoke; static vgFx *t_flame,*t_explode2, *t_debris2,*t_fire; static vgPath *tank_path,*tankupdown_path,*heli_path; static vgSplineNavigator *tank_nav,*tankupdown_nav,*heli_nav; static vgPath *missile1_path,*missile2_path,*helitoe2c_p
4、ath; static vgSplineNavigator *missile1_nav,*missile2_nav,*helitoe2c_nav; static VelocityMarker vm; static float x,y,z; static float h=,p=,r=; static float e2cBspeed=; /预警机螺旋桨转速 static float heliBspeed=; static float vvec4,e2cISresult4,m1ISresult4,m2Isresult4; static float hsin,hcos; static float ps
5、in,pcos; static int tankhitted=0; /坦克状态标志 static int e2ccrashed=0; /预警机是否坠毁 static int i=0; static int m,n,idx; static float tx,ty,tz,th,tp,tr; static float hx,hy,hz,hh,hp,hr; static float crashed_x,crashed_y,crashed_z; vgInitSys(); vgInitFx(); vgDefineSys(); vgConfigSys(); /初始化Vega变量 obs=vgGetObser
6、v(0); chan=vgGetObservChan(obs,0); scene=vgGetScene(0); m1=vgFindObj(missile1 m2=vgFindObj(missile2 tank=vgFindPlyr(p_Tank heli=vgFindPlyr(p_Heli missile1=vgFindPlyr(p_Missile1 missile2=vgFindPlyr(p_Missile2 e2c=vgFindPlyr(p_E2C tank_crater=vgFindPlyr(p_Tank_Crater e2c_crater=vgFindPlyr(p_E2C_Crater
7、 fortank=vgFindIsect(forTank fore2c=vgFindIsect(forE2C forheli=vgFindIsect(forHeli formissile1=vgFindIsect(formissile1 formissile2=vgFindIsect(formissile2 forcrater=vgFindIsect(forCrater tank_path=vgFindPath(tank_use tank_nav=vgFindSplineNavigator( tankupdown_path=vgFindPath(tank_updown tankupdown_n
8、av=vgFindSplineNavigator( heli_path=vgFindPath(heli_use heli_nav=vgFindSplineNavigator( h_blade1=vgFindFx(H_blade1 h_blade2=vgFindFx(H_blade2 e_blade1=vgFindFx(E_blade1 e_blade2=vgFindFx(E_blade2 e_trail1=vgFindFx(E_trail1 e_trail2=vgFindFx(E_trail2 e_airhit=vgFindFx(E_airhit e_engsmoke=vgFindFx(E_e
9、ngsmoke e_engburn=vgFindFx(E_engburn e_flash=vgFindFx(E_flash e_explode=vgFindFx(E_explode e_debris=vgFindFx(E_debris e_fire=vgFindFx(E_fire e_smoke=vgFindFx(E_smoke m1_trail=vgFindFx(M1_trail m1_flame=vgFindFx(M1_flame m2_trail=vgFindFx(M2_trail m2_flame=vgFindFx(M2_flame t_flash=vgFindFx(T_flash t
10、_explode1=vgFindFx(T_explode1 t_debris1=vgFindFx(T_debris1 t_flame=vgFindFx(T_flame t_fire=vgFindFx(T_fire t_explode2=vgFindFx(T_explode2 t_debris2=vgFindFx(T_debris2 t_smoke=vgFindFx(T_smoke /注册回调函数 vgAddFunc(chan,VGCHAN_POSTDRAW,DrawInfoCallBack,NULL); startTime=vgGetTime(); while(1) vgSyncFrame()
11、; vgFrame(); /处理输入事件 stateHandler(); /判断直升机状态 if(vgGetIsectResult(fore2c,VGIS_GETLOS,e2cISresult) e2ccrashed=1; /预警机坠地 crashed_x=e2cISresult1; crashed_y=e2cISresult2; crashed_z=e2cISresult3; /控制预警机飞行状态 if(!e2c_pos) e2c_pos=vgNewPos(); vgPosVec(e2c_pos,x,y,z,h,p,r); vgPos(e2c,e2c_pos); computeVVec(&v
12、vec1,e2c_pos);e2ccrashed&z h+=H_RATE; if(h h-=; vgGetSinCos(h,&hsin,&hcos); vgGetSinCos(p,&psin,&pcos); x=ORIGINX+e2c_radius*hcos; y=ORIGINX+e2c_radius*hsin; z+=Z_RATE*psin; /计算时间间隔 timeNow=vgGetTime()-startTime; switch(state) case 0: /初始状态 /初始化E2C预警机位姿 z=ZSTART; p=; r=; /设置视点 vgProp(obs,VGOBS_TETHE
13、RSTATE,VGOBS_FIXED); vgProp(obs,VGOBS_LOOKAT_TARGET,VGOBS_L_NONE); vgObservPlyr(obs,e2c); pos=vgNewPos(); vgPosVec(pos,100,25,5,100,-10,0); vgObservTetherPos(obs,pos); /设置直升机和坦克的初始位置 vgProp(tankupdown_nav,VGSPLINENAV_CURRENT_INDEX,0); vgPosVec(pos,-180,0,0); vgPos(heli,pos); vgPosVec(pos,2208,1035,0
14、,0,0,0); vgPos(tank,pos); vgPosVec(pos,0,0,0,0,0,0); vgPos(tank_crater,pos); vgPos(e2c_crater,pos); vgDelPos(pos); /设置特效状态 e2cBspeed=; vgProp(e_blade1,VGFX_BSPEED,e2cBspeed); heliBspeed=; vgProp(h_blade1,VGFX_BSPEED,heliBspeed); vgProp(h_blade2,VGFX_BSPEED,heliBspeed); vgProp(e_blade1,VGFX_STATE,VG_
15、ON); vgProp(e_blade2,VGFX_STATE,VG_ON); vgProp(e_trail1,VGFX_STATE,VG_ON); vgProp(e_trail2,VGFX_STATE,VG_ON); vgFxTime(e_trail1,VGFX_STARTTIME,VGFX_NOW); vgFxTime(e_trail2,VGFX_STARTTIME,VGFX_NOW); startTime=vgGetTime(); state=1; break; case 1: /坦克开始行动 if(timeNow+randomNum(5) vgProp(tank_nav,VGSPLIN
16、ENAV_CURRENT_INDEX,0); startTime=vgGetTime(); state=2; case 2: /锁定坦克 vgProp(tank_nav,VGCOMMON_ENABLED,VG_ON); vgProp(tank,VGPLYR_SPLINE_NAVIGATOR,VG_ON); vgPlyrNav(tank,(vgNavigator*)tank_nav); vgPosVec(pos,0,-8,5,0,-10,0); vgObservPlyr(obs,tank); if(timeNow vgProp(obs,VGOBS_TETHERSTATE,VGOBS_FIXED)
17、; pos=vgNewPos(); vgPosVec(pos,0,0,0,0,0,0); vgObservTetherPos(obs,pos); vgObservPlyr(obs,e2c); vgDelPos(pos); vgProp(obs,VGOBS_LOOKAT_TARGET,VGOBS_L_PLYR); vgObservLookatPlyr(obs,tank); state=3; break; case 3: /监视坦克行动 if(i-300) vgPosVec(pos,0,0,i,0,0,0); i-; state=4; break; case 4: /直升机启动 vgProp(ob
18、s,VGOBS_LOOKAT_TARGET,VGOBS_L_NONE); vgPosVec(pos,90,-10,0); vgObservPlyr(obs,heli); vgProp(h_blade1,VGFX_STATE,VG_ON); vgProp(h_blade2,VGFX_STATE,VG_ON); if(heliBspeed heliBspeed+=; else vgProp(heli_nav,VGSPLINENAV_CURRENT_INDEX,0); state=5; case 5: /直升机行动 vgProp(heli_nav,VGCOMMON_ENABLED,VG_ON); v
19、gProp(heli,VGPLYR_SPLINE_NAVIGATOR,VG_ON); vgProp(heli_nav,VGSPLINENAV_START_INDEX,0); vgProp(heli_nav,VGSPLINENAV_STOP_AT_END,VG_ON); vgPlyrNav(heli,(vgNavigator*)heli_nav); vgProp(obs,VGOBS_TETHERSTATE,VGOBS_SPIN); vgProp(obs,VGOBS_SPINRAD,80); vgProp(obs,VGOBS_SPINDELTA,; vgProp(obs,VGOBS_SPINELE
20、V,20); if(vgGetProp(tank_nav,VGSPLINENAV_CURRENT_INDEX)=vgGetProp(tank_path,VGPATH_NUM_CTRLPTS)-1) m1launchable=1; m2launchable=1; case 6: /发射第一枚导弹 /创建导弹路径 missile1_path=vgNewPath(MISSILE1_PATH,NULL); vgName(missile1_path,M1_path missile_pos=vgNewPos(); target_pos=vgNewPos(); vgGetWCSPos(missile1,mi
21、ssile_pos); vgGetPosVec(missile_pos,&tx,&ty,&tz,&th,&tp,&tr); vgProp(missile1,VGPLYR_CSREF,VGPLYR_ABSOLUTE); vgPosVec(missile_pos,tx,ty,tz,0,0,0); vgPos(missile1,missile_pos); vgGetPos(tank,target_pos); vgGetPosVec(target_pos,& vgPosVec(target_pos,tx,ty,tz,0,0,0); vgPathAddCtrlPointPos(missile1_path
22、,missile_pos); vgPathAddCtrlPointPos(missile1_path,target_pos); vgDelPos(missile_pos); vgDelPos(target_pos); missile1_nav=vgNewSplineNavigator(MISSILE1_NAV,missile1_path); vgName(missile1_nav,M1_nav vgProp(missile1_nav,VGCOMMON_ENABLED,VG_ON); vgProp(missile1_nav,VGSPLINENAV_START_INDEX,0); vgProp(m
23、issile1_nav,VGSPLINENAV_RENDER,VG_OFF); vgNavigatorAddMarker(missile1_nav,0,VGSPLINENAV_LINEAR,0,NULL,0); vgNavigatorAddMarker(missile1_nav,0,VGSPLINENAV_ABSOLUTE_HPR,VG_FALSE,NULL,0); =; vgNavigatorAddMarker(missile1_nav,0,VGSPLINENAV_VELOCITIES,0,&vm,sizeof(VelocityMarker); vgNavigatorAddMarker(missile1_nav,1,VGNAV_EMPTY,0,NULL,0); vgMakeSplineNavigator(missile1_nav); /控制导弹特效 vgProp(m1_flame,VGFX_STATE,VG_ON); vgProp(m1_trail,VGFX_STATE,VG_ON); vgProp(m1_flame,VGFX_DURATION,VGFX_ALWAYS); vgProp(m1_trail,VGFX_DURATION,VGFX_ALWAYS); vgFxTime(m1_flame,VGFX_STARTTIME,VGFX_NOW);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1