1、坦克入侵实例的代码#include #include #include #include #include #include #include #include #include #include #define MISSILE1_NAV ./#define MISSILE2_PATH ./#define MISSILE2_NAV ./#define HELITOE2C_PATH ./#define HELITOE2C_NAV ./static void DrawInfoCallBack(vgCommon *chan,void *udata);static void stateHandler(
2、void);static void computeVVec(float *vv,vgPosition *pos);static int randomNum(int number); /获取随机整数值static float e2c_radius=; /预警机巡航半径static int state=0; /仿真运行状态static int m1launchable=0; /导弹1是否可发射static int m2launchable=0; /导弹2是否可发射static int e2cDownable=0; /E2C是否可失事static int m1used=0; /导弹1是否已发射 st
3、atic int m2used=0; /导弹2是否已发射 static float startTime=0; /计时起始时间static float timeNow=0; /计时间隔时间static float deltaFrameTime=; /帧渲染间隔时间void main(void) static vgObserver *obs; static vgChannel *chan; static vgScene *scene; static vgObject *m1,*m2; static vgPlayer *tank,*heli,*missile1,*missile2; static v
4、gPlayer *e2c,*tank_crater,*e2c_crater; static vgIsector *fortank,*formissile1,*formissile2; static vgIsector *fore2c,*forheli,*forcrater; 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 v
5、gFx *e_airhit,*e_engsmoke,*e_engburn,*e_flash; static vgFx *e_fire,*e_smoke,*e_explode,*e_debris; static vgFx *m1_flame,*m1_trail,*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
6、,*heli_path; static vgSplineNavigator *tank_nav,*tankupdown_nav,*heli_nav; static vgPath *missile1_path,*missile2_path,*helitoe2c_path; static vgSplineNavigator *missile1_nav,*missile2_nav,*helitoe2c_nav; static VelocityMarker vm; static float x,y,z; static float h=,p=,r=; static float e2cBspeed=; /
7、预警机螺旋桨转速 static float heliBspeed=; static float vvec4,e2cISresult4,m1ISresult4,m2Isresult4; static float hsin,hcos; static float psin,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,
8、hp,hr; static float crashed_x,crashed_y,crashed_z; vgInitSys(); vgInitFx(); vgDefineSys(); vgConfigSys(); /初始化Vega变量 obs=vgGetObserv(0); chan=vgGetObservChan(obs,0); scene=vgGetScene(0); m1=vgFindObj(missile1); m2=vgFindObj(missile2); tank=vgFindPlyr(p_Tank); heli=vgFindPlyr(p_Heli); missile1=vgFind
9、Plyr(p_Missile1); missile2=vgFindPlyr(p_Missile2); e2c=vgFindPlyr(p_E2C); tank_crater=vgFindPlyr(p_Tank_Crater); e2c_crater=vgFindPlyr(p_E2C_Crater); fortank=vgFindIsect(forTank); fore2c=vgFindIsect(forE2C); forheli=vgFindIsect(forHeli); formissile1=vgFindIsect(formissile1); formissile2=vgFindIsect(
10、formissile2); forcrater=vgFindIsect(forCrater); tank_path=vgFindPath(tank_use); tank_nav=vgFindSplineNavigator(tank_use); tankupdown_path=vgFindPath(tank_updown); tankupdown_nav=vgFindSplineNavigator(tank_updown); heli_path=vgFindPath(heli_use); heli_nav=vgFindSplineNavigator(heli_use); h_blade1=vgF
11、indFx(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_engsmoke); e_engburn=vgFindFx(E_engburn); e_flash=vgFindFx(E_flash); e_explode=vgFindFx
12、(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_explode1=vgFindFx(T_explode1); t_debris1=vgFindFx(T_debris1);
13、 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(); vgFrame(); /处理输入事件 stateHandler(); /判断直升机状态 if
14、(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(&vvec1,e2c_pos); if(!e2ccrashed&z h+=H_RATE; if(h
15、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_TETHERSTATE,VGOBS_FIXED); vgProp(obs,VGOBS_LOOKA
16、T_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,0,0,0); vgPos(tank,pos); vgPosVec(pos,0,0,
17、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_ON); vgProp(e_blade2,VGFX_STATE,VG_ON); vgP
18、rop(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,VGSPLINENAV_CURRENT_INDEX,0); startTime=vgGetTime(
19、); state=2; break; case 2: /锁定坦克 vgProp(tank_nav,VGCOMMON_ENABLED,VG_ON); vgProp(tank,VGPLYR_SPLINE_NAVIGATOR,VG_ON); vgPlyrNav(tank,(vgNavigator*)tank_nav); vgProp(obs,VGOBS_TETHERSTATE,VGOBS_FIXED); pos=vgNewPos(); vgPosVec(pos,0,-8,5,0,-10,0); vgObservTetherPos(obs,pos); vgObservPlyr(obs,tank); v
20、gDelPos(pos); if(timeNow+randomNum(5) vgProp(obs,VGOBS_TETHERSTATE,VGOBS_FIXED); 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); startTime=vgGetTime(); state=3; br
21、eak; case 3: /监视坦克行动 if(i-300) pos=vgNewPos(); vgPosVec(pos,0,0,i,0,0,0); vgObservTetherPos(obs,pos); vgObservPlyr(obs,e2c); vgDelPos(pos); i-; if(timeNow+randomNum(5) startTime=vgGetTime(); state=4; break; case 4: /直升机启动 vgProp(obs,VGOBS_LOOKAT_TARGET,VGOBS_L_NONE); vgProp(obs,VGOBS_TETHERSTATE,VGO
22、BS_FIXED); pos=vgNewPos(); vgPosVec(pos,90,-10,0); vgObservTetherPos(obs,pos); vgObservPlyr(obs,heli); vgDelPos(pos); 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); startTime=vgGetTime(); state=5; v
23、gProp(h_blade1,VGFX_BSPEED,heliBspeed); vgProp(h_blade2,VGFX_BSPEED,heliBspeed); break; case 5: /直升机行动 vgProp(heli_nav,VGCOMMON_ENABLED,VG_ON); vgProp(heli,VGPLYR_SPLINE_NAVIGATOR,VG_ON); vgProp(heli_nav,VGSPLINENAV_START_INDEX,0); vgProp(heli_nav,VGSPLINENAV_STOP_AT_END,VG_ON); vgPlyrNav(heli,(vgNa
24、vigator*)heli_nav); vgProp(obs,VGOBS_TETHERSTATE,VGOBS_SPIN); vgObservPlyr(obs,heli); vgProp(obs,VGOBS_SPINRAD,80); vgProp(obs,VGOBS_SPINDELTA,; vgProp(obs,VGOBS_SPINELEV,20); if(vgGetProp(tank_nav,VGSPLINENAV_CURRENT_INDEX)=vgGetProp(tank_path,VGPATH_NUM_CTRLPTS)-1) m1launchable=1; m2launchable=1;
25、break; case 6: /发射第一枚导弹 /创建导弹路径 missile1_path=vgNewPath(MISSILE1_PATH,NULL); vgName(missile1_path,M1_path); missile_pos=vgNewPos(); target_pos=vgNewPos(); vgGetWCSPos(missile1,missile_pos); vgGetPosVec(missile_pos,&tx,&ty,&tz,&th,&tp,&tr); vgProp(missile1,VGPLYR_CSREF,VGPLYR_ABSOLUTE); vgPosVec(miss
26、ile_pos,tx,ty,tz,0,0,0); vgPos(missile1,missile_pos); vgGetPos(tank,target_pos); vgGetPosVec(target_pos,&tx,&ty,&tz,&th,&tp,&tr); vgPosVec(target_pos,tx,ty,tz,0,0,0); vgPathAddCtrlPointPos(missile1_path,missile_pos); vgPathAddCtrlPointPos(missile1_path,target_pos); vgDelPos(missile_pos); vgDelPos(ta
27、rget_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(missile1_nav,VGSPLINENAV_RENDER,VG_OFF); vgNavigatorAddMarker(missile1_nav,0,VGSPLINENAV_LINEAR,0
28、,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