//----------------------------------------------------------------------------------------------- inline void ConvertEulerAnglesToVector( const EulerAngles& angles, FloatVector3& out_vector ) { float pitchRadians = ConvertDegreesToRadians( angles.pitchDegreesAboutY ); float yawRadians = ConvertDegreesToRadians( angles.yawDegreesAboutZ ); out_vector.x = cos( yawRadians ) * cos( pitchRadians ); out_vector.y = sin( yawRadians ) * cos( pitchRadians ); out_vector.z = sin( pitchRadians ); }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- inline const Vector3 Camera3D::GetForwardVector() const { float pitchRadians = ConvertDegreesToRadians( m_orientation.pitchDegrees ); float yawRadians = ConvertDegreesToRadians( m_orientation.yawDegrees ); float cosPitch = cos( pitchRadians ); Vector3 cameraForward( cosPitch * sin( yawRadians ), -sin( pitchRadians ), cosPitch * cos( yawRadians ) ); cameraForward.Normalize(); return cameraForward; }
//----------------------------------------------------------------------------------------------- inline void Camera::GenerateClippingPlanes() { float currentAngleAroundZRadians = ConvertDegreesToRadians( m_heading.yawDegreesAboutZ ); float halfHorizontalFieldOfViewRadians = ConvertDegreesToRadians( 45.f ); leftClippingPlane.normal = FloatVector3( -sin( currentAngleAroundZRadians + halfHorizontalFieldOfViewRadians ), cos( currentAngleAroundZRadians + halfHorizontalFieldOfViewRadians ), 0.f ); leftClippingPlane.normal.Normalize(); rightClippingPlane.normal = FloatVector3( sin( currentAngleAroundZRadians - halfHorizontalFieldOfViewRadians ), -cos( currentAngleAroundZRadians - halfHorizontalFieldOfViewRadians ), 0.f ); rightClippingPlane.normal.Normalize(); leftClippingPlane.distanceToOrigin = -DotProduct( m_position, leftClippingPlane.normal ); rightClippingPlane.distanceToOrigin = -DotProduct( m_position, rightClippingPlane.normal ); }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- inline const Vector3 Camera3D::GetRightVector() const { float rollRadians = ConvertDegreesToRadians( m_orientation.rollDegrees ); float yawRadians = ConvertDegreesToRadians( m_orientation.yawDegrees - 90.0f ); float cosRoll = cos( rollRadians ); Vector3 cameraRight(cosRoll * sin( yawRadians ), -sin( rollRadians ), cosRoll * cos( yawRadians )); cameraRight.Normalize(); return cameraRight; }
///--------------------------------------------------------------------------------- /// very slow ///--------------------------------------------------------------------------------- void Vector2::SetLengthAndHeadingDegrees( float newLength, float headingDegrees ) { float length = newLength; float headingRadians = ConvertDegreesToRadians( headingDegrees ); x = length * cos( headingRadians ); y = length * sin( headingRadians ); }
void CClientVehicle::SetRotation(const CVector3& vecRotation) { if(IsSpawned()) { // Remove the vehicle from the world m_pVehicle->RemoveFromWorld(); // Get the vehicle matrix Matrix matMatrix; m_pVehicle->GetMatrix(&matMatrix); // Convert the rotation to radians and apply it to the vehicle matrix CVector3 vecNewRotation = vecRotation; ConvertDegreesToRadians(vecNewRotation); g_pClient->GetGame()->ConvertEulerAnglesToRotationMatrix(vecNewRotation, matMatrix); // Set the new vehicle matrix m_pVehicle->SetMatrix(&matMatrix); // Re-add the vehicle to the world m_pVehicle->AddToWorld(); } m_vecRotation = vecRotation; }
//----------------------------------------------------------------------------------------------- inline void Camera::MoveInXYPlane( float angleDegrees, float magnitudeBetweenZeroAndOne, float deltaSeconds ) { float adjustedAngleDegrees = angleDegrees + m_heading.yawDegreesAboutZ - 90.f; FloatVector3 movementVector( cos( ConvertDegreesToRadians( adjustedAngleDegrees ) ), sin( ConvertDegreesToRadians( adjustedAngleDegrees ) ), 0.f ); m_position += ( movementVector ) * magnitudeBetweenZeroAndOne * MOVEMENT_SPEED * deltaSeconds; GenerateClippingPlanes(); }
inline bool Node::CalcLeftFrustumPlaneClipping(Vector3 boundingSphereLocation, float sphereRadius ){ const float halfoffieldOfView = ConvertDegreesToRadians(45.0f * 0.5f); const Vector3 leftPlaneNDirection = Vector3(-cos( halfoffieldOfView ), 0.0f, sin(halfoffieldOfView )); float dotOfLeftNP = DotProduct(leftPlaneNDirection, boundingSphereLocation); return CalcFrustumPlaneVisible(dotOfLeftNP, sphereRadius); }
//----------------------------------------------------------------------------------------------- Vector3f FirstPersonControllerStrategy::GetNonOffsetForwardViewVector() { Vector3f forwardViewVector; float yawInRadians = ConvertDegreesToRadians( m_pose.m_orientation.yawDegreesAboutZ ); float pitchInRadians = ConvertDegreesToRadians( m_pose.m_orientation.pitchDegreesAboutY ); float cosinePitch = cos( pitchInRadians ); float sinPitch = sin( pitchInRadians ); Vector3f forward( cos( yawInRadians ), sin( yawInRadians ), 0.f ); forwardViewVector.x = forward.x * cosinePitch; forwardViewVector.y = forward.y * cosinePitch; forwardViewVector.z = -sinPitch; return forwardViewVector; }
void CVehicle::GetRotation ( CVector & vecRotation ) { if ( m_pAttachedTo ) GetAttachedRotation ( vecRotation ); else { GetRotationDegrees ( vecRotation ); ConvertDegreesToRadians ( vecRotation ); } }
///--------------------------------------------------------------------------------- /// very slow ///--------------------------------------------------------------------------------- void Vector2::RotateDegrees( float degrees ) { float length = CalcLength(); float headingInDegrees = CalcHeadingDegrees(); headingInDegrees += degrees; float headingInRadians = ConvertDegreesToRadians( headingInDegrees ); x = length * cos( headingInRadians ); y = length * sin( headingInRadians ); }
//----------------------------------------------------------------------------------------------- inline void Matrix44::MakeRotation( float angleDegrees, float rotateX, float rotateY, float rotateZ ) { this->MakeIdentity(); Vector3 axisVector( rotateX, rotateY, rotateZ ); axisVector.Normalize(); float angleRadians = ConvertDegreesToRadians( angleDegrees ); this->m_entries[0] = cos( angleRadians ) + ( ( axisVector.x * axisVector.x ) * ( 1 - cos( angleRadians ) ) ); this->m_entries[1] = ( axisVector.x * axisVector.y * ( 1 - cos( angleRadians ) ) ) - ( axisVector.z * sin( angleRadians ) ); this->m_entries[2] = ( axisVector.x * axisVector.z * ( 1 - cos( angleRadians ) ) ) + ( axisVector.y * sin( angleRadians ) ); this->m_entries[4] = ( axisVector.y * axisVector.x * ( 1 - cos( angleRadians ) ) ) + ( axisVector.z * sin( angleRadians ) ); this->m_entries[5] = cos( angleRadians ) + ( ( axisVector.y * axisVector.y ) * ( 1 - cos( angleRadians ) ) ); this->m_entries[6] = ( axisVector.y * axisVector.z * ( 1 - cos( angleRadians ) ) ) - ( axisVector.x * sin( angleRadians ) ); this->m_entries[8] = ( axisVector.z * axisVector.x * ( 1 - cos( angleRadians ) ) ) - ( axisVector.y * sin( angleRadians ) ); this->m_entries[9] = ( axisVector.z * axisVector.y * ( 1 - cos( angleRadians ) ) ) + ( axisVector.x * sin( angleRadians ) ); this->m_entries[10] = cos( angleRadians ) + ( ( axisVector.z * axisVector.z ) * ( 1 - cos( angleRadians ) ) ); }
//----------------------------------------------------------------------------------------------- inline void Matrix44::MakePerspective( float fovyDegrees, float aspectRatio, float zNearDistance, float zFarDistance ) { this->MakeIdentity(); float fovyRadians = ConvertDegreesToRadians( fovyDegrees ); float fValue = 0.f; float fValueDenom = tan( fovyRadians * 0.5f ); if( fValueDenom != 0.f ) fValue = 1.f / fValueDenom; float oneOverNearMinusFar = 0.f; if( ( zNearDistance - zFarDistance ) != 0.f ) oneOverNearMinusFar = 1.f / ( zNearDistance - zFarDistance ); this->m_entries[0] = fValue / aspectRatio; this->m_entries[5] = fValue; this->m_entries[10] = ( zNearDistance + zFarDistance ) * oneOverNearMinusFar; this->m_entries[11] = -1.f; this->m_entries[14] = ( 2.f * zNearDistance * zFarDistance ) * oneOverNearMinusFar; }
void Camera3D::UpdateCameraFromInput(float deltaSeconds, const float& moveSpeed){ const float degreesPerMouseDelta = 0.08f; float moveSpeedUnitsPerSecond = moveSpeed; const float flySpeedUnitsPerSecond = moveSpeed * 0.5f; const float turboMultiplier = 8.0f; float yawRadians = ConvertDegreesToRadians(m_orientation.yawDegreesAboutZ); UNUSED(yawRadians); //this allows movement absolute to the world basis //move camera forward according to yaw Vector3 cameraForwardXY;// = Vector3(cos(yawRadians), sin(yawRadians), 0.0f); //define forward cameraForwardXY = GetForwardVector(); cameraForwardXY.Normalize(); //cameraForwardXY = Vector3::FORWARD; //move camera left according to yaw Vector3 cameraLeftXY = Vector3(-cameraForwardXY.y, cameraForwardXY.x, 0); //move camera right according to yaw Vector3 cameraRightXY = -1.0f * cameraLeftXY; //move camera backward according to yaw Vector3 cameraBackwardXY = -1.0f * cameraForwardXY; Vector3 cameraMovementVector(0.0f, 0.0f, 0.0f); //move in a direction if (theInputSystem->IsKeyDown('W') || theInputSystem->IsKeyDown(VK_UP)){ cameraMovementVector += cameraForwardXY * moveSpeedUnitsPerSecond * deltaSeconds; } else if (theInputSystem->IsKeyDown('S') || theInputSystem->IsKeyDown(VK_DOWN)){ cameraMovementVector += cameraBackwardXY * moveSpeedUnitsPerSecond * deltaSeconds; } else if (theInputSystem->IsKeyDown('A') || theInputSystem->IsKeyDown(VK_LEFT)){ cameraMovementVector += cameraLeftXY * moveSpeedUnitsPerSecond * deltaSeconds; } else if (theInputSystem->IsKeyDown('D') || theInputSystem->IsKeyDown(VK_RIGHT)){ cameraMovementVector += cameraRightXY * moveSpeedUnitsPerSecond * deltaSeconds; } //keyboard flight else if (theInputSystem->IsKeyDown('Q')){ cameraMovementVector.z += flySpeedUnitsPerSecond * deltaSeconds; } else if (theInputSystem->IsKeyDown('E')){ cameraMovementVector.z -= flySpeedUnitsPerSecond * deltaSeconds; } //turn on turbo, turbo only increases move speed if (theInputSystem->IsKeyDown(VK_SHIFT)){ cameraMovementVector *= turboMultiplier; } //adding the combined movement vector to camera pos m_position += cameraMovementVector; Vector2 mouseResetPosition (400.0f , 300.0f ); Vector2 mousePosition = theInputSystem->GetMousePosition(); //theInputSystem->ConsolePrintMousePosition(); Vector2 distanceMouseHasMovedSinceLastFrame = mousePosition - mouseResetPosition; if(!theInputSystem->IsKeyDown(VK_CONTROL)) theInputSystem->SnapMousePosition((int)mouseResetPosition.x, (int)mouseResetPosition.y ); m_orientation.yawDegreesAboutZ -= distanceMouseHasMovedSinceLastFrame.x * degreesPerMouseDelta * deltaSeconds; m_orientation.pitchDegreesAboutY += distanceMouseHasMovedSinceLastFrame.y * degreesPerMouseDelta* deltaSeconds; //clamp pitch degrees if(m_orientation.pitchDegreesAboutY > 89.0f ) m_orientation.pitchDegreesAboutY = 89.0f; if(m_orientation.pitchDegreesAboutY < -89.0f ) m_orientation.pitchDegreesAboutY = -89.0f; }
bool CVehicle::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true ); // Wrap them around 360 m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f ); m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f ); m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f ); // Set the respawn matrix SetRespawnPosition ( m_vecPosition ); SetRespawnRotationDegrees ( m_vecRotationDegrees ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Is it valid? if ( CVehicleManager::IsValidModel ( iTemp ) ) { // Remember it and generate a new random color m_usModel = static_cast < unsigned short > ( iTemp ); m_Color = RandomizeColor (); GetInitialDoorStates ( m_ucDoorStates ); m_usAdjustableProperty = 0; } else { CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "turretX" data if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) ) { m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX ); } // Grab the "turretY" data if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) ) { m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY ); } // Grab the "health" data if ( GetCustomDataFloat ( "health", m_fHealth, true ) ) { if ( m_fHealth < 0.0f ) m_fHealth = 0.0f; } // Grab the "Sirens" data if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) ) { m_bSirenActive = false; } // Grab the "landingGearDown" data if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) ) { m_bLandingGearDown = true; } if ( !GetCustomDataBool ( "locked", m_bLocked, true ) ) { m_bLocked = false; } // Grab the "specialState" data if ( GetCustomDataInt ( "specialState", iTemp, true ) ) { m_usAdjustableProperty = static_cast < unsigned short > ( iTemp ); } else { m_usAdjustableProperty = 0; } // Grab the "color" data char szTemp [ 256 ]; if ( GetCustomDataString ( "color", szTemp, 256, true ) ) { char* sz1 = strtok ( szTemp, "," ); char* sz2 = strtok ( NULL, "," ); char* sz3 = strtok ( NULL, "," ); char* sz4 = strtok ( NULL, "," ); if ( sz1 ) m_Color.SetColor1 ( atoi ( sz1 ) ); if ( sz2 ) m_Color.SetColor2 ( atoi ( sz2 ) ); if ( sz3 ) m_Color.SetColor3 ( atoi ( sz3 ) ); if ( sz4 ) m_Color.SetColor4 ( atoi ( sz4 ) ); } if ( GetCustomDataInt ( "paintjob", iTemp, true ) ) m_ucPaintjob = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) ) { if ( m_pUpgrades ) { if ( strcmp ( szTemp, "all" ) == 0 ) { m_pUpgrades->AddAllUpgrades (); } else { bool bTemp = true; while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, "," ) ) { bTemp = false; unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) ); if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) ) { m_pUpgrades->AddUpgrade ( usUpgrade ); } } } } } if ( GetCustomDataString ( "plate", szTemp, 9, true ) ) { SetRegPlate ( szTemp ); } if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); return true; }
bool CVehicle::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true ); // Wrap them around 360 m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f ); m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f ); m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f ); // Set the respawn matrix SetRespawnPosition ( m_vecPosition ); SetRespawnRotationDegrees ( m_vecRotationDegrees ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Is it valid? if ( CVehicleManager::IsValidModel ( iTemp ) ) { // Remember it and generate a new random color SetModel ( static_cast < unsigned short > ( iTemp ) ); m_usAdjustableProperty = 0; } else { CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the variant data if ( GetCustomDataInt ( "variant1", iTemp, true ) ) { m_ucVariant = static_cast < unsigned char > ( iTemp ); } if ( GetCustomDataInt ( "variant2", iTemp, true ) ) { m_ucVariant2 = static_cast < unsigned char > ( iTemp ); } if ( m_ucVariant == 254 && m_ucVariant2 == 254 ) CVehicleManager::GetRandomVariation ( m_usModel, m_ucVariant, m_ucVariant2 ); // Grab the "turretX" data if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) ) { m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX ); } // Grab the "turretY" data if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) ) { m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY ); } // Grab the "health" data if ( GetCustomDataFloat ( "health", m_fHealth, true ) ) { if ( m_fHealth < 0.0f ) m_fHealth = 0.0f; } // Grab the "Sirens" data if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) ) { m_bSirenActive = false; } // Grab the "landingGearDown" data if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) ) { m_bLandingGearDown = true; } if ( !GetCustomDataBool ( "locked", m_bLocked, true ) ) { m_bLocked = false; } // Grab the "specialState" data if ( GetCustomDataInt ( "specialState", iTemp, true ) ) { m_usAdjustableProperty = static_cast < unsigned short > ( iTemp ); } else { m_usAdjustableProperty = 0; } // Grab the "color" data char szTemp [ 256 ]; if ( GetCustomDataString ( "color", szTemp, 256, true ) ) { uchar ucValues[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; char* sz1 = strtok ( szTemp, ", " ); if ( sz1 ) ucValues[0] = atoi ( sz1 ); int i; for ( i = 1 ; i < 12 ; i++ ) { char* szn = strtok ( NULL, ", " ); if ( !szn ) break; ucValues[i] = atoi ( szn ); } if ( i == 3 || i == 6 || i == 9 || i == 12 ) { m_Color.SetRGBColors ( SColorRGBA ( ucValues[0], ucValues[1], ucValues[2], 0 ), SColorRGBA ( ucValues[3], ucValues[4], ucValues[5], 0 ), SColorRGBA ( ucValues[6], ucValues[7], ucValues[8], 0 ), SColorRGBA ( ucValues[9], ucValues[10], ucValues[11], 0 ) ); } else { m_Color.SetPaletteColors ( ucValues[0], ucValues[1], ucValues[2], ucValues[3] ); } } if ( GetCustomDataInt ( "paintjob", iTemp, true ) ) m_ucPaintjob = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) ) { if ( m_pUpgrades ) { if ( strcmp ( szTemp, "all" ) == 0 ) { m_pUpgrades->AddAllUpgrades (); } else { bool bTemp = true; while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, ", " ) ) { bTemp = false; unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) ); if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) ) { m_pUpgrades->AddUpgrade ( usUpgrade ); } } } } } if ( GetCustomDataString ( "plate", szTemp, 9, true ) ) SetRegPlate ( szTemp ); if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); if ( !GetCustomDataBool ( "collisions", m_bCollisionsEnabled, true ) ) m_bCollisionsEnabled = true; if ( GetCustomDataInt ( "alpha", iTemp, true ) ) m_ucAlpha = static_cast < unsigned char > ( iTemp ); bool bFrozen; if ( GetCustomDataBool ( "frozen", bFrozen, true ) ) m_bIsFrozen = bFrozen; return true; }
///--------------------------------------------------------------------------------- /// very slow ///--------------------------------------------------------------------------------- void Vector2::SetUnitLengthAndHeadingDegrees( float headingDegrees ) { float headingRadians = ConvertDegreesToRadians( headingDegrees ); x = cos( headingRadians ); y = sin( headingRadians ); }
bool CPed::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <ped> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <ped> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <ped> (line %u)\n", m_uiLine ); return false; } float fRotation = 0.0f; GetCustomDataFloat ( "rotZ", fRotation, true ); m_fRotation = ConvertDegreesToRadians ( fRotation ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Is it valid? unsigned short usModel = static_cast < unsigned short > ( iTemp ); if ( CPedManager::IsValidModel ( usModel ) ) { // Remember it and generate a new random color m_usModel = usModel; } else { CLogger::ErrorPrintf ( "Bad 'model' id specified in <ped> (line %u)\n", m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <ped> (line %u)\n", m_uiLine ); return false; } GetCustomDataFloat ( "health", m_fHealth, true ); GetCustomDataFloat ( "armor", m_fArmor, true ); if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); if ( !GetCustomDataBool ( "collisions", m_bCollisionsEnabled, true ) ) m_bCollisionsEnabled = true; if ( GetCustomDataInt ( "alpha", iTemp, true ) ) m_ucAlpha = static_cast < unsigned char > ( iTemp ); bool bFrozen; if ( GetCustomDataBool ( "frozen", bFrozen, true ) ) m_bFrozen = bFrozen; return true; }
bool CObject::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotation.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotation.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotation.fZ, true ); // We store radians, but load degrees ConvertDegreesToRadians ( m_vecRotation ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Valid id? if ( CObjectManager::IsValidModel ( iTemp ) ) { // Set the object id m_usModel = static_cast < unsigned short > ( iTemp ); } else { CLogger::ErrorPrintf ( "Bad 'model' id specified in <object> (line %u)\n", m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <object> (line %u)\n", m_uiLine ); return false; } if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); if ( !GetCustomDataBool ( "doublesided", m_bDoubleSided, true ) ) m_bDoubleSided = false; if ( !GetCustomDataFloat ( "scale", m_vecScale.fX, true ) ) m_vecScale.fX = 1.0f; m_vecScale.fY = m_vecScale.fX; m_vecScale.fZ = m_vecScale.fX; GetCustomDataFloat ( "scaleX", m_vecScale.fX, true ); GetCustomDataFloat ( "scaleY", m_vecScale.fY, true ); GetCustomDataFloat ( "scaleZ", m_vecScale.fZ, true ); if ( !GetCustomDataBool ( "collisions", m_bCollisionsEnabled, true ) ) m_bCollisionsEnabled = true; if ( GetCustomDataInt ( "alpha", iTemp, true ) ) m_ucAlpha = static_cast < unsigned char > ( iTemp ); bool bFrozen; if ( GetCustomDataBool ( "frozen", bFrozen, true ) ) m_bIsStatic = bFrozen; // Success return true; }
bool CObject::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <object> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotation.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotation.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotation.fZ, true ); // We store radians, but load degrees ConvertDegreesToRadians ( m_vecRotation ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Valid id? if ( CObjectManager::IsValidModel ( iTemp ) ) { // Set the object id m_usModel = static_cast < unsigned short > ( iTemp ); } else { CLogger::ErrorPrintf ( "Bad 'model' id specified in <object> (line %u)\n", m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <object> (line %u)\n", m_uiLine ); return false; } if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); // Success return true; }