//----------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------- float CPlayerCar::CalculateMotorRpm( void ) { //Get Ground contact for rear wheels bool bGroundContact = m_pPhysVehicle->HasGroundContact(2) || m_pPhysVehicle->HasGroundContact(3); bGroundContact = true; if( !bGroundContact ) { //motor accelerates by 4000 rpm per second if no ground contact float desiredRpm = m_engineRpm + gpGlobals->frametime * 4000.0f; return min( desiredRpm, m_info.motorMaxRpm ); } //Wheels have ground contact. //Get the linear forward velocity of the car Vector3f vForward; AngleToVector( GetAngle(), vForward ); float fForwardVel = VectorDot(GetVelocity(), -vForward); float fWheelRpm = fForwardVel / (2.0f*PI*m_info.wheelRadius) * 60.0f; float fAxleAndGearTranslation = m_info.axleRatio * m_info.gearRatios[m_engineGear-1]; float fMotorRpm = fWheelRpm * fAxleAndGearTranslation; return fMotorRpm; }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- void CEntityTypeSunLight::Render( void ) { BaseClass::Render(); if( IsSelected() ) { Vector3f dir; AngleToVector(GetAbsAngles(), dir); draw_line(GetAbsCenter(), GetAbsCenter()+dir*10.0f); } }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- void CEntityTypeSunLight::OnParamChanged( const std::string &key, const std::string &oldval, const std::string &newval ) { BaseClass::OnParamChanged(key,oldval,newval); UpdateLightParams(); if( key.compare("angles") == 0 ) { Vector3f dir; AngleToVector(GetAbsAngles(), dir); char vec[128]; sprintf_s( vec, "%.3f %.3f %.3f", dir.x, dir.y, dir.z ); m_keyvals["direction"] = string(vec); } }
int CCamera::CheckCameraPos( vec3_t pos , float dist , vec3_t angles ) { vec3_t forward , end; trace_t trace; vec3_t mins , maxs; AngleToVector( angles , forward ); VectorScale( forward , forward , dist ); VectorAdd( end , pos , forward ); mins[0] = -10.0f; mins[1] = -10.0f; mins[2] = -10.0f; maxs[0] = 10.0f; maxs[1] = 10.0f; maxs[2] = 10.0f; trace = m_world->Trace( pos , mins , maxs , end , MASK_PLAYERSOLID ); if( trace.fraction == 1.0f ) { VectorCopy( m_position , end ); return true; } if( trace.fraction < 0.2f || trace.fraction * dist < 30.0f ) { VectorScale( forward , forward , 1.0f ); VectorAdd( m_position , pos , forward ); return false; } else if( trace.fraction < 0.5f ) { VectorScale( forward , forward , trace.fraction * 0.8f ); VectorAdd( m_position , pos , forward ); return true; } else { VectorScale( forward , forward , trace.fraction * 0.9f ); VectorAdd( m_position , pos , forward ); return true; } }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- void CEntityTypeSunLight::UpdateLightParams( void ) { Vector4f color = StrUtils::GetVector4( GetValue("color") ); color.x /= 255.0f; color.y /= 255.0f; color.z /= 255.0f; Vector4f specularColor = StrUtils::GetVector4( GetValue("specularColor") ); specularColor.x /= 255.0f; specularColor.y /= 255.0f; specularColor.z /= 255.0f; Vector3f ambient1 = StrUtils::GetVector3( GetValue("ambientMin") ) / 255.0f; Vector3f ambient2 = StrUtils::GetVector3( GetValue("ambientMax") ) / 255.0f; Vector3f dir; AngleToVector(GetAbsAngles(), dir); CSunLight *light = GetRenderInterfaces()->GetRendererInterf()->GetLightList()->GetSunLight(m_lightIndex); light->SetDirection(dir.Normalize()); light->SetColor(color); light->SetSpecular(specularColor); light->SetAmbient1(ambient1); light->SetAmbient2(ambient2); }
int CWndWorld::ControlFlying( DWORD dwMessage, CPoint point ) { static float fTurnAngle = 0.0f; static BOOL s_bTraceKeyed = 0, s_bSelectKeyed = 0, s_bTurbo2 = 0; // static BOOL s_bFastTurn; int nMsg = 0; // BOOL bFlyKey; BOOL bUp, bDown, bLeft, bRight; BOOL bAcc = FALSE; BOOL bTurbo; // BOOL bFastTurn = FALSE; BYTE nFrame = MAX_CORR_SIZE_150; CMover* pMover = CMover::GetActiveMover(); bUp = g_bKeyTable[g_Neuz.Key.chUp]; bDown = g_bKeyTable['S']; // 좌/우 회전 bLeft = g_bKeyTable[g_Neuz.Key.chLeft]; bRight = g_bKeyTable['D']; // 급선회. // bFastTurn = g_bKeyTable[ VK_SHIFT ]; // CMover* pMoverTarget = (CMover*)g_WorldMng.Get()->GetObjFocus() ; // 가속 상태면 전진 명령 계속 보냄 bool fMoved = false; bool fBehavior = false; if( pMover->m_pActMover->IsStateFlag( OBJSTAF_ACC ) ) { if( pMover->SendActMsg( OBJMSG_FORWARD ) == 1 ) { fMoved = true; } } else { if( pMover->SendActMsg( OBJMSG_STAND ) == 1 ) { fMoved = true; } } // bAcc = g_bKeyTable[VK_SPACE]; if( bAcc && !s_bAccKeyed ) // 키 누른순간에만 토글시킴. { if( pMover->m_pActMover->IsStateFlag( OBJSTAF_ACC ) ) // 가속중이었다면 { pMover->SendActMsg( OBJMSG_ACC_STOP ); // 가속 멈춤 if( pMover->m_pActMover->IsActTurn() ) { fMoved = true; } } else { // 가속중이 아니었다면 가속 시킴. if( pMover->SendActMsg( OBJMSG_ACC_START ) == 0 ) g_WndMng.PutString( prj.GetText( TID_GAME_AIRFUELEMPTY ) ); else { if( pMover->SendActMsg( OBJMSG_FORWARD ) == 1 ) fMoved = true; } } } s_bAccKeyed = bAcc; bTurbo = g_bKeyTable[g_Neuz.Key.chWalk]; if( bTurbo && !s_bTurbo2 ) // 토글 방식. { if( pMover->m_pActMover->IsStateFlag( OBJSTAF_TURBO ) ) { if( pMover->SendActMsg( OBJMSG_MODE_TURBO_OFF ) == 1 ) fMoved = true; } else { if( pMover->SendActMsg( OBJMSG_MODE_TURBO_ON ) == 1 ) fMoved = true; } } s_bTurbo2 = bTurbo; if( pMover->m_pActMover->IsFly() ) { if( g_bKeyTable[g_Neuz.Key.chTrace] && !s_bTraceKeyed ) { CCtrl* pFocusObj = (CCtrl*)(pMover->GetWorld()->GetObjFocus()); if( pFocusObj && pFocusObj->GetType() == OT_MOVER ) { CMover* pFocusMover = (CMover*)pFocusObj; if( pMover->m_dwFlag & MVRF_TRACKING ) // 이미 실행중이면 해제. { pMover->m_dwFlag &= (~MVRF_TRACKING); // 추적모드해제. pMover->m_idTracking = NULL_ID; } else { // 비행중 추적모드. pMover->m_dwFlag |= MVRF_TRACKING; // 추적모드. pMover->m_idTracking = pFocusMover->GetId(); } } else { // 타겟이 없을때 Z키를 누르면 자동추적이 풀린다. pMover->m_dwFlag &= (~MVRF_TRACKING); // 추적모드해제. pMover->m_idTracking = NULL_ID; } } s_bTraceKeyed = g_bKeyTable[g_Neuz.Key.chTrace]; // 타겟선택 키 if( g_bKeyTable[VK_TAB] && !s_bSelectKeyed ) { if( m_aFlyTarget.GetSize() > 0 ) // 선택된 타겟있을때. { if( m_nSelect >= m_aFlyTarget.GetSize() ) m_nSelect = 0; OBJID idSelect = m_aFlyTarget.GetAt( m_nSelect++ ); CMover *pSelectMover = prj.GetMover( idSelect ); if( IsValidObj(pSelectMover) ) { CWorld *pWorld = pMover->GetWorld(); if( pWorld ) { pWorld->SetObjFocus( pSelectMover ); // 이놈을 타겟으로 설정함. pMover->m_idTracking = pSelectMover->GetId(); // 탭으로 타겟을 바꾸면 자동추적타겟도 그놈으로 바뀐다. } } } } s_bSelectKeyed = g_bKeyTable[VK_TAB]; } if( /*m_bFlyMove &&*/ m_bLButtonDown || g_bKeyTable[VK_INSERT] ) // 192 = ` { CObj *pObj = pMover->GetWorld()->GetObjFocus(); // 타겟잡힌놈이 있을때만 휘두를수 있다. if( pObj && pObj->GetType() == OT_MOVER ) { if( pMover->IsAttackAble( pObj ) ) // 공격 가능한지 검사. { OBJID idTarget = ((CMover *)pObj)->GetId(); ItemProp *pWeapon = pMover->GetActiveHandItemProp(); if( pWeapon ) { g_pPlayer->PlayCombatMusic(); if( pWeapon->dwItemKind3 == IK3_WAND ) { D3DXVECTOR3 vFront, vTarget; AngleToVector( &vFront, g_pPlayer->GetAngle(), -g_pPlayer->GetAngleX(), 1.0f ); vTarget = pObj->GetPos() - g_pPlayer->GetPos(); D3DXVec3Normalize( &vTarget, &vTarget ); // 타겟쪽으로의 벡터의 유닛벡터. FLOAT fDot = D3DXVec3Dot( &vFront, &vTarget ); if( fDot >= cosf(D3DXToRadian(60.0f)) ) // 타겟이 내가 보는 방향의 +-30도 안에 있으면 발사할수 있다. { if( pMover->IsRangeObj( pObj, 64.0f ) ) // 사정거리에 들어오면 발사. { pMover->DoAttackMagic( pObj, 0 ); } } } else { pMover->SendActMsg( OBJMSG_ATK1, idTarget ); } } } } } // fTurnAngle = 0.6f; ItemProp* pItemProp = prj.GetItemProp( g_pPlayer->GetRideItemIdx() ); if( pItemProp ) { fTurnAngle = pItemProp->fFlightLRAngle; } else { Error( "ControlFlying : 빗자루정보 읽기 실패 %d", g_pPlayer->GetRideItemIdx() ); fTurnAngle = 0.6f; } if( bUp ) { if( g_WorldMng.Get()->GetFullHeight( pMover->GetPos() ) < pMover->GetPos().y ) { if( pMover->SendActMsg( OBJMSG_LOOKDOWN ) == 1 ) { fMoved = true; } } } else if( bDown ) { if( pMover->SendActMsg( OBJMSG_LOOKUP ) == 1 ) { fMoved = true; } } else { if( pMover->SendActMsg( OBJMSG_STOP_LOOK ) == 1 ) { fMoved = true; } } if( bLeft ) { m_fRollAng -= 1.0f; if( m_fRollAng < -45.0f ) m_fRollAng = -45.0f; if( pMover->SendActMsg( OBJMSG_LTURN, (int)( fTurnAngle * 100.0f ) ) == 1 ) { fMoved = true; } } else if( bRight ) { m_fRollAng += 1.0f; if( m_fRollAng > 45.0f ) m_fRollAng = 45.0f; if( pMover->SendActMsg( OBJMSG_RTURN, (int)( fTurnAngle * 100.0f ) ) == 1 ) { fMoved = true; } } else { if( m_fRollAng < 0 ) { m_fRollAng += 2.0f; if( m_fRollAng > 0 ) m_fRollAng = 0; } else if( m_fRollAng > 0 ) { m_fRollAng -= 2.0f; if( m_fRollAng < 0 ) m_fRollAng = 0; } if( pMover->SendActMsg( OBJMSG_STOP_TURN ) == 1 ) { fMoved = true; // fBehavior = true; } } // 오른쪽 버튼 드래그는 빗자루 움직임 if( dwMessage == WM_MOUSEMOVE /*&& m_bRButtonDown*/ ) { float fAng = pMover->GetAngle(); float fAdd = (point.x - m_ptMouseOld.x) / 2.0f; fAng -= fAdd; pMover->SetAngle( fAng ); float fAngX = pMover->GetAngleX(); float fAddX = (point.y - m_ptMouseOld.y) / 4.0f; fAngX += fAddX; if( fAddX > 0 && fAngX > 45.0f ) fAngX = 45.0f; else if( fAddX < 0 && fAngX < -45.0f ) fAngX = -45.0f; pMover->SetAngleX( fAngX ); if( fAdd || fAddX ) g_DPlay.PostPlayerAngle( TRUE ); } BOOL bTempKey; if( bTempKey = g_bKeyTable[ '8' ] ) { if( !m_bTemp3ed ) { pMover->SendActMsg( OBJMSG_TEMP2 ); // __bTestLOD ^= 1; } } m_bTemp3ed = bTempKey; if( fMoved ) { g_DPlay.SendPlayerMoved2( nFrame ); } if( fBehavior ) { pMover->ClearDest(); g_DPlay.SendPlayerBehavior2(); } return nMsg; }
void CActionMover::ProcessFlyParticle( float fLenSq ) { CMover *pMover = m_pMover; // 운영자 투명모드때는 파티클 안나옴. if( (pMover->IsMode( TRANSPARENT_MODE ) ) == 0 ) { ItemProp* pRideProp = prj.GetItemProp( m_pMover->m_dwRideItemIdx ); // 현재 타고있는 탈것의 프로퍼티. // 비행 파티클 처리. if( fLenSq > 0.01f ) { if( (pMover->IsActiveMover() && g_Neuz.m_camera.m_fZoom > 2.0f) || pMover->IsActiveMover() == FALSE ) // 일정속도 이상이 되면 꼬리에 파티클이 나오기 시작. { int nType = 0; if( pRideProp && pRideProp->dwID == II_RID_RID_BOR_RIDINGCLOUD ) nType = 1; CreateFlyParticle( pMover, pMover->GetAngleX(), nType ); } } if( fLenSq > 0.001f ) { if( (pMover->IsActiveMover() && g_Neuz.m_camera.m_fZoom > 1.0f) || pMover->IsActiveMover() == FALSE ) { if( pRideProp && pRideProp->dwItemKind3 == IK3_BOARD ) // 보드만 꼬리가 나온다. { if( m_pTail ) { if( pRideProp->dwID == II_RID_RID_BOR_RIDINGCLOUD ) // 근두운일때 { if( m_pTail->GetType() != 2 ) // 생성되었던 꼬리고 근두운용이 아니면 m_pTail->ChangeTexture( D3DDEVICE, "etc_Tail2.bmp", 2 ); } else { if( m_pTail->GetType() != 1 ) // 생성되었던 꼬리고 일반보드용이 아니면 m_pTail->ChangeTexture( D3DDEVICE, "etc_Tail1.bmp", 1 ); // 일반보드용으로 텍스쳐 교체. } } if( m_pTail == NULL ) // 아직 할당 안됐으면 할당하고. { if( pRideProp->dwID == II_RID_RID_BOR_RIDINGCLOUD ) // 근두운... { m_pTail = (CTailEffectBelt*)g_TailEffectMng.AddEffect( g_Neuz.m_pd3dDevice, "etc_Tail2.bmp", 2 ); } else { m_pTail = (CTailEffectBelt*)g_TailEffectMng.AddEffect( g_Neuz.m_pd3dDevice, "etc_Tail1.bmp", 1 ); } } D3DXVECTOR3 vPos1, vPos2; D3DXVECTOR3 vLocal; FLOAT fAngXZ = pMover->GetAngle(); FLOAT fAngH = pMover->GetAngleX(); AngleToVectorXZ( &vLocal, fAngXZ, -1.0f ); fAngXZ -= 90.0f; if( fAngXZ < 0 ) fAngXZ += 360.0f; AngleToVector( &vPos1, fAngXZ, -fAngH, 0.5f ); vPos1 += pMover->GetPos(); vPos1 += vLocal; fAngXZ = pMover->GetAngle(); fAngH = pMover->GetAngleX(); AngleToVectorXZ( &vLocal, fAngXZ, -1.0f ); fAngXZ += 90.0f; if( fAngXZ > 360.0f ) fAngXZ -= 360.0f; AngleToVector( &vPos2, fAngXZ, -fAngH, 0.5f ); vPos2 += pMover->GetPos(); vPos2 += vLocal; if( m_pTail ) m_pTail->CreateTail( vPos1, vPos2 ); } } } } // 투명모드가 아닐때 }
Vector3 RandomMover::VectorChange(void) { return AngleToVector(RandomAngle(), Random::Number(mMoveSpeed / 16, mMoveSpeed)); }