3DAnimation.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:58k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "XMudClient.h"
  3. #include "D3DRMScreen.h"
  4. #include "3DSound.h"
  5. #include "3DFunction.h"
  6. #include "MainScreen.h"
  7. #include "MenuCreateNew.h"
  8. #include "Internetmsg.h"
  9. D3DVECTOR g_CameraPosition;
  10. extern LPDIRECT3DRMFRAME3 g_lpplayer;
  11. extern LPDIRECT3DRMFRAME3 g_pChaseFrame;
  12. extern LPDIRECT3DRMFRAME3 g_sFrame;
  13. extern LPDIRECT3DRM3 g_lpD3DRM;
  14. extern PathInfo info;
  15. extern rmfullglobals myglobs;
  16. extern int g_playerState;
  17. extern BOOL g_GetSameMove;
  18. extern CMainScreen m_MainScreen;
  19. extern CRITICAL_SECTION csAnimation;
  20. extern CList <animationCallbackArgs *, animationCallbackArgs *> animationlist;
  21. extern CList<CPlayerInfo*,CPlayerInfo*>playerlist;
  22. extern int g_nReceiveMsgState,g_nGameState,nSpareTime,nRecTimes;
  23. float g_fightreadyDelta = 4.00f/40.0f;
  24.  BOOL bRestartAlready=FALSE;
  25. extern SOCKET hLCltForRSvrSock;
  26. void __cdecl animationCallback(LPDIRECT3DRMFRAME3 obj, LPVOID arg, 
  27.                                D3DVALUE delta)
  28. {
  29.   D3DVECTOR *path;
  30.   animationCallbackArgs* cb;
  31.   animationCallbackArgs* cbfight;
  32.   D3DVECTOR playerpos,sFramepos,pSoundPos,tmpSoundPos,camerapos;
  33.   D3DVECTOR Npcposite;
  34.   int i,j,k;
  35.   BOOL bM = FALSE;
  36.   TFightTag *lpFightTag;
  37.   
  38.   g_lpplayer->GetPosition(myglobs.scene, &playerpos);
  39.   
  40.   EnterCriticalSection(&csAnimation);
  41.   j = animationlist.GetCount();
  42.   if(j < 2)
  43.   {
  44.     bM = TRUE;
  45.     j = 3;
  46.   }
  47.   for(i=0;i<j;i++)
  48.   {
  49.     if ( bM )
  50.       cb = animationlist.GetHead();
  51.     else
  52.       cb = animationlist.GetAt(animationlist.FindIndex(i));
  53.     
  54.     obj = cb->frame3obj;
  55.     if( i != 0 ){
  56.       if(cb->cXFileType == "NPC"){
  57.         switch( cb->PlayerState ){
  58.         case STOP:
  59.           {
  60.             cb->animset->SetTime(cb->time);
  61.             cb->time += (g_fightreadyDelta*delta);
  62.             if(cb->time > STOP_START + NUM_STOP_FRAMES) {
  63.               cb->time = STOP_START;
  64.             }else{
  65.               if(cb->way!=-1) {
  66.                 if(!m_MainScreen.bSelectOne) {
  67.                   cb->time = LEFTGO_START;
  68.                   cb->PlayerState = LEFTGO;
  69.                 }
  70.               }else {
  71.                 cb->frame3obj->GetPosition(myglobs.scene,&Npcposite);
  72.                 g_pChaseFrame->SetPosition(myglobs.scene,Npcposite.x,Npcposite.y,playerpos.z);
  73.                 cb->frame3obj->LookAt(g_pChaseFrame,myglobs.scene,D3DRMCONSTRAIN_Z);
  74.               }
  75.             }
  76.           }
  77.           break;
  78.           
  79.         case LEFTGO:
  80.           {
  81.             cb->animset->SetTime(cb->time);
  82.             cb->time += (g_fightreadyDelta*delta)*2;
  83.             if(cb->time > LEFTGO_START + NUM_LEFTGO_FRAMES){
  84.               Npcposite = GetNextPosite(cb->frame3obj,cb);
  85.               
  86.               g_pChaseFrame->SetPosition( myglobs.scene,Npcposite.x, Npcposite.y, Npcposite.z);
  87.               cb->frame3obj->LookAt( g_pChaseFrame, myglobs.scene,D3DRMCONSTRAIN_Z);
  88.               cb->frame3obj->SetPosition( myglobs.scene,Npcposite.x, Npcposite.y, Npcposite.z);
  89.               
  90.               cb->time = RIGHTGO_START;
  91.               cb->PlayerState = RIGHTGO;
  92.             }
  93.             if(m_MainScreen.bSelectOne)
  94.             {
  95.               if(m_MainScreen.szSelectEName == cb->cXFileName)
  96.               {
  97.                 cb->time = STOP_START;
  98.                 cb->PlayerState = STOP;
  99.               }
  100.             }
  101.           }
  102.           break;
  103.         case RIGHTGO:
  104.           {
  105.             cb->animset->SetTime(cb->time);
  106.             cb->time += (g_fightreadyDelta*delta)*2;
  107.             if(cb->time > RIGHTGO_START + NUM_RIGHTGO_FRAMES){
  108.               Npcposite = GetNextPosite(cb->frame3obj,cb);
  109.               
  110.               g_pChaseFrame->SetPosition( myglobs.scene,Npcposite.x, Npcposite.y, Npcposite.z);
  111.               cb->frame3obj->LookAt( g_pChaseFrame, myglobs.scene,D3DRMCONSTRAIN_Z);
  112.               cb->frame3obj->SetPosition( myglobs.scene,Npcposite.x, Npcposite.y, Npcposite.z);
  113.               
  114.               cb->time = LEFTGO_START;
  115.               cb->PlayerState = LEFTGO;
  116.             }
  117.             if(m_MainScreen.bSelectOne)
  118.             {
  119.               if(m_MainScreen.szSelectEName == cb->cXFileName)
  120.               {
  121.                 cb->time = STOP_START;
  122.                 cb->PlayerState = STOP;
  123.               }
  124.             }
  125.           }
  126.           break;
  127.         case FIGHTREADY:
  128.           {
  129.             cb->animset->SetTime(cb->time);
  130.             cb->time += (g_fightreadyDelta*delta);
  131.             if( cb->time > FIGHTREADY_START + NUM_FIGHTREADY_FRAMES)
  132.             {
  133.               k = cb->fightopplist.GetCount();
  134.               if(k==0)break;
  135.               k = rand()%k;
  136.               lpFightTag = cb->fightopplist.GetAt(cb->fightopplist.FindIndex(k));
  137.               cbfight = animationlist.GetAt(lpFightTag->tagPosite);
  138.               switch(rand()%10)
  139.               {
  140.               case 0:
  141.                 {
  142.                   cb->time = HAND_START;
  143.                   cb->PlayerState = HAND;
  144.                   
  145.                   switch( rand() % 2 )
  146.                   {
  147.                   case 0:
  148.                     cbfight->time = WOUND_START;
  149.                     if( cbfight->cXFileName.IsEmpty() )
  150.                       g_playerState = WOUND;
  151.                     else
  152.                       cbfight->PlayerState = WOUND;
  153.                     break;
  154.                   case 1:
  155.                     cbfight->time = GURAD_START;
  156.                     if( cbfight->cXFileName.IsEmpty() )
  157.                       g_playerState = GURAD;
  158.                     else
  159.                       cbfight->PlayerState = GURAD;
  160.                     break;
  161.                   }
  162.                 }
  163.                 break;
  164.               case 1:
  165.                 {
  166.                   cb->time = FOOT_START;
  167.                   cb->PlayerState = FOOT;
  168.                   
  169.                   switch( rand() % 2 )
  170.                   {
  171.                   case 0:
  172.                     cbfight->time = WOUND_START;
  173.                     if( cbfight->cXFileName.IsEmpty() )
  174.                       g_playerState = WOUND;
  175.                     else
  176.                       cbfight->PlayerState = WOUND;
  177.                     break;
  178.                   case 1:
  179.                     cbfight->time = GURAD_START;
  180.                     if( cbfight->cXFileName.IsEmpty() )
  181.                       g_playerState = GURAD;
  182.                     else
  183.                       cbfight->PlayerState = GURAD;
  184.                     break;
  185.                   }
  186.                 }
  187.                 break;
  188.               case 2://NPC