void CGuard::Update(float fElapsedTime) { if(CheckForPlayer()) { ComputeMovement(fElapsedTime); this->addTime(fElapsedTime); CBase::Update(fElapsedTime); } else CEnemy::Update( fElapsedTime ); m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY()); for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++) { Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i]; tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY())); // Create a circle based on clsoest point with capsule radius Circle testCircle; testCircle.m_Center = ClosestPoint; testCircle.m_fRadius = temp->GetRadius(); if( GetSphere()->CheckCollision(testCircle) ) { tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center; sphere2_to_1 = Vector2DNormalize(sphere2_to_1); float dist = GetSphere()->m_fRadius + testCircle.m_fRadius; tVector2D scaler = (sphere2_to_1 * (dist * 0.01f)); tVector2D newpos = GetSphere()->m_Center + scaler; SetPosX(newpos.fX); SetPosY(newpos.fY); } } if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1)) { IsUndead = true; AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" ); } if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2)) { IsUndead = false; AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" ); } }
int ExportSecAnim(LWXPanelID pan) { LWItemID idMasterObjID; char strMessage[256]; Matrix12 bi_mRot; _iFrame = 0; _ctFrames = 0; _ctBones = 0; ctBoneEnvelopes = 0; ctMorphEnvelopes = 0; if(!_evaluate) { // lightwave error _msg->error("Lightwave process error !\nClose plugins window and try again.\n", NULL); return AFUNC_BADAPP; } // !!!! make it work with a selected object, not the first one in scene ReloadGlobalObjects(); bool bExportOnlySelected = false; int ctSkeletonBones=0; // find selected object - to be replaced with the master bone int ctSelected = 0; int ctMeshes=0; _objid = _iti->first(LWI_OBJECT,0); idMasterObjID = LWITEM_NULL; while(_objid != LWITEM_NULL) { if(_iti->type(_objid) == LWI_OBJECT) { if(_ifi->itemFlags(_objid) & LWITEMF_SELECTED) { ctSelected++; idMasterObjID = _objid; } ctMeshes++; } _objid = _iti->next(_objid); } if (idMasterObjID == LWITEM_NULL) { // lightwave error _msg->error("ERROR: Object for top level bone not selected.\n", NULL); return AFUNC_BADAPP; } if (ctSelected > 1) { // lightwave error _msg->error("ERROR: More than one object selected.\n", NULL); return AFUNC_BADAPP; } // get scene name _strFileName = strdup(_sci->filename); // open the file to print into char fnmOut[256]; strcpy(fnmOut, _strFileName); char *pchDot = strrchr(fnmOut, '.'); if (pchDot!=NULL) { strcpy(pchDot, ".aa"); } _ctNumBones = 0; AddBoneToCount(idMasterObjID); if ((_f = fopen(fnmOut,"w")) == NULL) { _msg->error("ERROR: File open.\n", NULL); return AFUNC_BADAPP; } // calculate number of frames to export _ctFrames = ((_ifi->previewEnd-_ifi->previewStart)/_ifi->previewStep)+1; if (_ctFrames<=0) { _ctFrames = 1; } // find all morph channels for the current mesh _pmiFirst = NULL; FindMorphChannels(NULL); AddMotionHandler(idMasterObjID); sprintf(strMessage,"ctBoneEnvelopes: %d",_ctBones); _msg->error(strMessage,fnmOut); bRecordDefaultFrame = true; if (!ExecCmd("GoToFrame 0")) { // goto end; } bRecordDefaultFrame = false; int bExportAnimBackward = *(int*)_xpanf->formGet( pan, ID_ANIM_ORDER); float fTime; // export normal order if(!bExportAnimBackward) { // for each frame in current preview selection for (int iFrame=_ifi->previewStart; iFrame<=_ifi->previewEnd; iFrame+=_ifi->previewStep) { // go to that frame if (!ExecCmd("GoToFrame %d", iFrame)) { // goto end; } assert(_iFrame>=0 && _iFrame<_ctFrames); // NOTE: walking all frames implicitly lets the internal itemmotion handler record all bone positions // we walk the morph maps manually _iFrame++; } // get time fTime = (float) GetCurrentTime(); // export backward } else { // remember time in last frame if (!ExecCmd("GoToFrame %d", _ifi->previewEnd)) { //goto end; return AFUNC_BADGLOBAL; } // get time fTime = (float) GetCurrentTime(); // for each frame in current preview selection going from last to first for (int iFrame=_ifi->previewEnd; iFrame>=_ifi->previewStart; iFrame-=_ifi->previewStep) { // go to that frame if (!ExecCmd("GoToFrame %d", iFrame)) { //goto end; return AFUNC_BADGLOBAL; } assert(_iFrame>=0 && _iFrame<_ctFrames); LWTimeInfo *_tmi = (LWTimeInfo *)_global( LWTIMEINFO_GLOBAL, GFUSE_TRANSIENT ); // NOTE: walking all frames implicitly lets the internal itemmotion handler record all bone positions // we walk the morph maps manually _iFrame++; } } // find the number of morph envelopes for(MorphInfo *ptmpmi=_pmiFirst;ptmpmi!=NULL; ptmpmi = ptmpmi->mi_pmiNext) ctMorphEnvelopes++; fTime = (float) GetCurrentTime(); char strAnimID[256]; strcpy(strAnimID,_strFileName); GetAnimID(strAnimID); fprintf(_f, "SE_ANIM %s;\n\n",SE_ANIM_VER); fprintf(_f, "SEC_PER_FRAME %g;\n",fTime / _ifi->previewEnd * _ifi->previewStep); fprintf(_f, "FRAMES %d;\n", _ctFrames); fprintf(_f, "ANIM_ID \"%s\";\n\n", strAnimID); fprintf(_f, "BONEENVELOPES %d\n{\n", _ctNumBones); BoneInfo *pbiLast = NULL; for (BoneInfo *pbi=_pbiFirst; pbi!=NULL; pbi = pbi->bi_pbiNext) { bool bRootBone = false; // write its info fprintf(_f, " NAME \"%s\"\n", pbi->bi_strName); // write first frame - default pose fprintf(_f, " DEFAULT_POSE {"); BoneFrame &bfDef = pbi->bi_abfFrames[0]; MakeRotationAndPosMatrix(bi_mRot,bfDef.fi_vPos,bfDef.fi_vRot); PrintMatrix(_f,bi_mRot,0); fprintf(_f, "}\n"); fprintf(_f, " {\n"); LWItemType itLast; if(!pbiLast) itLast = LWI_OBJECT; else itLast = pbiLast->bi_lwItemType; // write anim // for each frame for (int iFrame=0; iFrame<_ctFrames; iFrame++) { // Fill 3x4 matrix and store rotation and position in it BoneFrame &bf = pbi->bi_abfFrames[iFrame]; MakeRotationAndPosMatrix(bi_mRot,bf.fi_vPos,bf.fi_vRot); // write matrix to file PrintMatrix(_f,bi_mRot,4); fprintf(_f,"\n"); } pbiLast = pbi; fprintf(_f," }\n\n"); } fprintf(_f,"}\n"); fprintf(_f, "\nMORPHENVELOPES %d\n{\n", ctMorphEnvelopes); // for each morph in list {for (MorphInfo *pmi=_pmiFirst; pmi!=NULL; pmi = pmi->mi_pmiNext) { // write its info fprintf(_f, " NAME \"%s\"\n", pmi->mi_strName); fprintf(_f, " {\n"); for (int iFrame=0; iFrame<_ctFrames; iFrame++) { fprintf(_f, " %g;\n", pmi->mi_afFrames[iFrame]); } fprintf(_f," }\n\n"); } } fprintf(_f,"}\n"); // free all morph infos { MorphInfo *pmi=_pmiFirst; MorphInfo *pmiNext=NULL; for(;;) { if(pmi==NULL) { break; } pmiNext = pmi->mi_pmiNext; free(pmi->mi_strName); free(pmi->mi_afFrames); free(pmi); pmi = pmiNext; }} fprintf(_f, "SE_ANIM_END;\n"); fclose(_f); RemoveMotionHandler(idMasterObjID); _pbiFirst = NULL; return AFUNC_OK; };