float BoidManager::getDistanceBetween(XMVECTOR vectorBetween) { float distanceBetween; distanceBetween = XMVectorGetX(XMVector4Length((vectorBetween))); return distanceBetween; }
FLOAT32 CFVec4::Distance( CFVec4Arg fv4To ) const { CFVec4 v4Temp; v4Temp = fv4To - *this; XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( &v4Temp ); return XMVectorGetX( XMVector4Length( v4V ) ); }
/** * @param vMagnitude Contains the scalar magnitude in each component. */ void CFVec4::Normalise( CFVec4 &vMagnitude ) { XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( this ); XMVECTOR& v4VMag = *reinterpret_cast<XMVECTOR*>( &vMagnitude ); //TODO: Is there a cheaper way of doing this? v4VMag = XMVector4Length( v4V ); v4V = XMVector4Normalize( v4V ); }
/** * @return A vector quantity with the scalar in each component. */ CFVec4 CFVec4::MagnitudeV( void ) const { CFVec4 v4Return; const XMVECTOR& v4V = *reinterpret_cast<const XMVECTOR*>( this ); XMVECTOR& v4Result = *reinterpret_cast<XMVECTOR*>( &v4Return ); v4Result = XMVector4Length( v4V ); return v4Return; }
/** * @return A vector quantity with the scalar in each component. */ CFVec4 CFVec4::DistanceV( CFVec4Arg fv4To ) const { CFVec4 v4Temp; v4Temp = fv4To - *this; XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( &v4Temp ); v4V = XMVector4Length( v4V ); return v4Temp; }
CFVec4 CFVec4::GetNormal( FLOAT32 &fMagnitude ) const { CFVec4 v4Return; const XMVECTOR& v4V = *reinterpret_cast<const XMVECTOR*>( this ); XMVECTOR& v4Result = *reinterpret_cast<XMVECTOR*>( &v4Return ); //TODO: Is there a cheaper way of doing this? fMagnitude = XMVectorGetX( XMVector4Length( v4V ) ); v4Result = XMVector4Normalize( v4V ); return v4Return; }
bool WorldEntity::circlePointIntersect( XMVECTOR point, XMVECTOR circleCenter, float circleRadius ) { XMVECTOR diff = point - circleCenter; XMVECTOR len = XMVector4Length( diff ); XMFLOAT4 realLen; XMStoreFloat4( &realLen, len ); if( realLen.x < circleRadius ){ return true; } return false; }
FLOAT32 CFVec4::Magnitude( void ) const { const XMVECTOR& v4V = *reinterpret_cast<const XMVECTOR*>( this ); return XMVectorGetX( XMVector4Length( v4V ) ); }
bool WorldEntity::circleAALineIntersect( XMVECTOR start, XMVECTOR end, XMVECTOR circleCenter, float circleRadius ) { //A collision function we actually understand... //Create a vector from the start to the circle position XMVECTOR cToStart = circleCenter - start; XMVECTOR cToEnd = circleCenter - end; XMVECTOR lenToStart = XMVector4Length( cToStart ); XMVECTOR lenToEnd = XMVector4Length( cToEnd ); XMFLOAT4 ans; XMStoreFloat4( &ans, lenToStart ); if( ans.x <= circleRadius ){ return true; } XMStoreFloat4( &ans, lenToEnd ); if( ans.x <= circleRadius ){ return true; } //Calculate the start to end XMVECTOR endToStart = end - start; XMVECTOR endToStartLen = XMVector4Length( endToStart ); XMFLOAT4 tmp; XMStoreFloat4(&tmp, endToStartLen); tmp.x = 1.0f / tmp.x; XMVECTOR tmpA = XMVectorScale(endToStart, tmp.x); XMVECTOR tmpB = XMVectorScale(cToStart, tmp.x); //Project it onto the start -> end vector XMVECTOR dot = XMVector4Dot( tmpA, tmpB ); //Calculate the Perpendicular point XMVECTOR per = start + ( endToStart * dot ); //If the perpendicular point is within range of the circle, there is a collision XMVECTOR perDist = XMVector4Length( circleCenter - per ); XMStoreFloat4( &ans, perDist ); if( ans.x > circleRadius ){ return false; } //Store the dot product to see how far down the line the collision happens XMStoreFloat4( &ans, dot ); //If the dot product is negative, the collision is outside the range if( ans.x < 0.0f ){ return false; } //If the dot product is bigger than 1.0f, meaning it scaled the vector passed the segment, the collision is outside the range if( ans.x > 1.0f ){ return false; } return true; }