坦克入侵实例的代码Word下载.docx
《坦克入侵实例的代码Word下载.docx》由会员分享,可在线阅读,更多相关《坦克入侵实例的代码Word下载.docx(31页珍藏版)》请在冰豆网上搜索。
voidmain(void)
{
staticvgObserver*obs;
staticvgChannel*chan;
staticvgScene*scene;
staticvgObject*m1,*m2;
staticvgPlayer*tank,*heli,*missile1,*missile2;
staticvgPlayer*e2c,*tank_crater,*e2c_crater;
staticvgIsector*fortank,*formissile1,*formissile2;
staticvgIsector*fore2c,*forheli,*forcrater;
staticvgPosition*pos,*e2c_pos,*heli_pos,*missile_pos,*target_pos;
staticvgFx*h_blade1,*h_blade2;
staticvgFx*e_blade1,*e_blade2,*e_trail1,*e_trail2;
staticvgFx*e_airhit,*e_engsmoke,*e_engburn,*e_flash;
staticvgFx*e_fire,*e_smoke,*e_explode,*e_debris;
staticvgFx*m1_flame,*m1_trail,*m2_flame,*m2_trail;
staticvgFx*t_flash,*t_explode1,*t_debris1,*t_smoke;
staticvgFx*t_flame,*t_explode2,*t_debris2,*t_fire;
staticvgPath*tank_path,*tankupdown_path,*heli_path;
staticvgSplineNavigator*tank_nav,*tankupdown_nav,*heli_nav;
staticvgPath*missile1_path,*missile2_path,*helitoe2c_path;
staticvgSplineNavigator*missile1_nav,*missile2_nav,*helitoe2c_nav;
staticVelocityMarkervm;
staticfloatx,y,z;
staticfloath=,p=,r=;
staticfloate2cBspeed=;
//预警机螺旋桨转速
staticfloatheliBspeed=;
staticfloatvvec[4],e2cISresult[4],m1ISresult[4],m2Isresult[4];
staticfloathsin,hcos;
staticfloatpsin,pcos;
staticinttankhitted=0;
//坦克状态标志
staticinte2ccrashed=0;
//预警机是否坠毁
staticinti=0;
staticintm,n,idx;
staticfloattx,ty,tz,th,tp,tr;
staticfloathx,hy,hz,hh,hp,hr;
staticfloatcrashed_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=vgFindPlyr("
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("
formissile2"
forcrater=vgFindIsect("
forCrater"
tank_path=vgFindPath("
tank_use"
tank_nav=vgFindSplineNavigator("
tankupdown_path=vgFindPath("
tank_updown"
tankupdown_nav=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_engsmoke"
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_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();
vgFrame();
//处理输入事件
stateHandler();
//判断直升机状态
if(vgGetIsectResult(fore2c,VGIS_GETLOS,e2cISresult))
e2ccrashed=1;
//预警机坠地
crashed_x=e2cISresult[1];
crashed_y=e2cISresult[2];
crashed_z=e2cISresult[3];
}
//控制预警机飞行状态
if(!
e2c_pos)e2c_pos=vgNewPos();
vgPosVec(e2c_pos,x,y,z,h,p,r);
vgPos(e2c,e2c_pos);
computeVVec(&
vvec[1],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)
case0:
//初始状态
//初始化E2C预警机位姿
z=ZSTART;
p=;
r=;
//设置视点
vgProp(obs,VGOBS_TETHERSTATE,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,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_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;
case1:
//坦克开始行动
if(timeNow>
+randomNum(5))
{
vgProp(tank_nav,VGSPLINENAV_CURRENT_INDEX,0);
startTime=vgGetTime();
state=2;
}
case2:
//锁定坦克
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);
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;
case3:
//监视坦克行动
if(i>
-300)
{
vgPosVec(pos,0,0,i,0,0,0);
i--;
state=4;
break;
case4:
//直升机启动
vgProp(obs,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;
case5:
//直升机行动
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,(vgNavigator*)heli_nav);
vgProp(obs,VGOBS_TETHERSTATE,VGOBS_SPIN);
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;
case6:
//发射第一枚导弹
//创建导弹路径
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(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,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(missile1_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);