잉히
2015년 10월 13일 화요일
Unreal Engine 4 FVector operator
FVector 에 관련된 코드를 보다 보니 ^ 연산자랑 | 연산자를 발견.
무엇인가 싶었는데 ^ 는 외적 연산, | 는 내적 연산 이더라.
FVector::CrossProduct 도 내부적으론 ^ 를 사용하며,
FVector::DotProduct 또한 내부적으로 | 를 사용하여 처리 함.
아래 코드는 FVector 의 operator 관련 코드를 발췌한 부분.
FORCEINLINE FVector FVector::operator^( const FVector& V ) const { return FVector ( Y * V.Z - Z * V.Y, Z * V.X - X * V.Z, X * V.Y - Y * V.X ); } FORCEINLINE FVector FVector::CrossProduct( const FVector& A, const FVector& B ) { return A ^ B; } FORCEINLINE float FVector::operator|( const FVector& V ) const { return X*V.X + Y*V.Y + Z*V.Z; } FORCEINLINE float FVector::DotProduct( const FVector& A, const FVector& B ) { return A | B; } FORCEINLINE FVector FVector::operator+( const FVector& V ) const { return FVector( X + V.X, Y + V.Y, Z + V.Z ); } FORCEINLINE FVector FVector::operator-( const FVector& V ) const { return FVector( X - V.X, Y - V.Y, Z - V.Z ); } FORCEINLINE FVector FVector::operator-( float Bias ) const { return FVector( X - Bias, Y - Bias, Z - Bias ); } FORCEINLINE FVector FVector::operator+( float Bias ) const { return FVector( X + Bias, Y + Bias, Z + Bias ); } FORCEINLINE FVector FVector::operator*( float Scale ) const { return FVector( X * Scale, Y * Scale, Z * Scale ); } FORCEINLINE FVector FVector::operator/( float Scale ) const { const float RScale = 1.f/Scale; return FVector( X * RScale, Y * RScale, Z * RScale ); } FORCEINLINE FVector FVector::operator*( const FVector& V ) const { return FVector( X * V.X, Y * V.Y, Z * V.Z ); } FORCEINLINE FVector FVector::operator/( const FVector& V ) const { return FVector( X / V.X, Y / V.Y, Z / V.Z ); } FORCEINLINE bool FVector::operator==( const FVector& V ) const { return X==V.X && Y==V.Y && Z==V.Z; } FORCEINLINE bool FVector::operator!=( const FVector& V ) const { return X!=V.X || Y!=V.Y || Z!=V.Z; } FORCEINLINE bool FVector::Equals(const FVector& V, float Tolerance) const { return FMath::Abs(X-V.X) <= Tolerance && FMath::Abs(Y-V.Y) <= Tolerance && FMath::Abs(Z-V.Z) <= Tolerance; } FORCEINLINE bool FVector::AllComponentsEqual(float Tolerance) const { return FMath::Abs( X - Y ) <= Tolerance && FMath::Abs( X - Z ) <= Tolerance && FMath::Abs( Y - Z ) <= Tolerance; } FORCEINLINE FVector FVector::operator-() const { return FVector( -X, -Y, -Z ); } FORCEINLINE FVector FVector::operator+=( const FVector& V ) { X += V.X; Y += V.Y; Z += V.Z; DiagnosticCheckNaN(); return *this; } FORCEINLINE FVector FVector::operator-=( const FVector& V ) { X -= V.X; Y -= V.Y; Z -= V.Z; DiagnosticCheckNaN(); return *this; } FORCEINLINE FVector FVector::operator*=( float Scale ) { X *= Scale; Y *= Scale; Z *= Scale; DiagnosticCheckNaN(); return *this; } FORCEINLINE FVector FVector::operator/=( float V ) { const float RV = 1.f/V; X *= RV; Y *= RV; Z *= RV; DiagnosticCheckNaN(); return *this; } FORCEINLINE FVector FVector::operator*=( const FVector& V ) { X *= V.X; Y *= V.Y; Z *= V.Z; DiagnosticCheckNaN(); return *this; } FORCEINLINE FVector FVector::operator/=( const FVector& V ) { X /= V.X; Y /= V.Y; Z /= V.Z; DiagnosticCheckNaN(); return *this; } FORCEINLINE float& FVector::operator[]( int32 Index ) { check(Index >= 0 && Index < 3); if( Index == 0 ) { return X; } else if( Index == 1) { return Y; } else { return Z; } } FORCEINLINE float FVector::operator[]( int32 Index )const { check(Index >= 0 && Index < 3); if( Index == 0 ) { return X; } else if( Index == 1) { return Y; } else { return Z; } }
댓글 없음:
댓글 쓰기
최근 게시물
이전 게시물
홈
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기