• メインページ
  • クラス
  • ファイル
  • ファイル一覧
  • ファイルメンバ

narVec3.h

00001 /*-----------------------------------------------------------------------*
00002   Project:  Nintendo Augmented Reality Library.
00003   File:     narVec3.h
00004 
00005   Copyright (C)2011-2012 Nintendo Co., Ltd.  All rights reserved.
00006 
00007   These coded instructions, statements, and computer programs contain
00008   proprietary information of Nintendo and/or its licensed developers
00009   and are protected by national and international copyright laws. They
00010   may not be disclosed to third parties or copied or duplicated in any
00011   form, in whole or in part, without the prior written consent of
00012   Nintendo.
00013   The content herein is highly confidential and should be handled
00014   accordingly.
00015 *-----------------------------------------------------------------------*/
00016 
00018 
00023 #ifndef NAR_VEC_3_H__
00024 #define NAR_VEC_3_H__
00025 
00026 #include "narPort.h"
00027 #include "narMath.h"
00028 
00029 #ifdef NAR_CTR__
00030 namespace nn {
00031     namespace math {
00032         struct VEC3;
00033     }
00034 }
00035 #endif
00036 
00037 namespace mw { namespace nar
00038 {
00042     struct Vec3F_st
00043     {
00044         Vec3F_st()
00045         {}
00046 
00047         Vec3F_st( f32 x, f32 y, f32 z )
00048         {
00049             Set( x, y, z );
00050         }
00051 
00052         Vec3F_st( f32 val )
00053         {
00054             SetAll( val );
00055         }
00056 
00057         void Set( f32 x, f32 y, f32 z )
00058         {
00059             X() = x; Y() = y; Z() = z;
00060         }
00061 
00062         void SetAll( f32 val )
00063         {
00064             Set( val, val, val );
00065         }
00066 
00067         f32 & X() { return ma_[ me_X ]; }
00068         f32 & Y() { return ma_[ me_Y ]; }
00069         f32 & Z() { return ma_[ me_Z ]; }
00070         const f32 & X() const { return ma_[ me_X ]; }
00071         const f32 & Y() const { return ma_[ me_Y ]; }
00072         const f32 & Z() const { return ma_[ me_Z ]; }
00073 
00074 
00077         Vec3F_st & Add( const Vec3F_st & cr )
00078         {
00079             X() += cr.X();
00080             Y() += cr.Y();
00081             Z() += cr.Z();
00082             return *this;
00083         }
00084 
00087         Vec3F_st & Sub( const Vec3F_st & cr )
00088         {
00089             X() -= cr.X();
00090             Y() -= cr.Y();
00091             Z() -= cr.Z();
00092             return *this;
00093         }
00094 
00097         Vec3F_st & Scale( f32 a )
00098         {
00099             X() *= a;
00100             Y() *= a;
00101             Z() *= a;
00102             return *this;
00103         }
00104 
00107         Vec3F_st operator*( f32 a ) const
00108         {
00109             Vec3F_st ret( *this );
00110             return ret.Scale( a );
00111         }
00112 
00115         Vec3F_st & Div( f32 d )
00116         {
00117             if ( d != 0.f )
00118             {
00119                 Scale( 1.f / d );
00120             }
00121             return * this;
00122         }
00123         
00126         f32 Dot( const Vec3F_st & cr ) const
00127         {
00128             return X() * cr.X() + Y() * cr.Y() + Z() * cr.Z();
00129         }
00130 
00133         Vec3F_st & Cross( const Vec3F_st & cr_A, const Vec3F_st & cr_B )
00134         {
00135             f32 ax = cr_A.X();
00136             f32 ay = cr_A.Y();
00137             f32 az = cr_A.Z();
00138             f32 bx = cr_B.X();
00139             f32 by = cr_B.Y();
00140             f32 bz = cr_B.Z();
00141 
00142             X() = ay * bz - az * by;
00143             Y() = az * bx - ax * bz;
00144             Z() = ax * by - ay * bx;
00145             return *this;
00146         }
00147 
00150         bool Normalize()
00151         {
00152             f32 L = GetLength();
00153             if ( L < c_Epsilon ) return false;
00154             Scale( static_cast< f32 >( 1.0 ) / L );
00155             return true;
00156         }
00157 
00160         f32 GetSquareLength() const
00161         {
00162             return Pow2( X() ) + Pow2( Y() ) + Pow2( Z() );
00163         }
00164 
00167         f32 GetLength() const
00168         {
00169             return Sqrt( GetSquareLength() );
00170         }
00171 
00174         f32 GetSquareDistance( const Vec3F_st & cr_Vec ) const
00175         {
00176             return Pow2( cr_Vec.X() - X() ) + Pow2( cr_Vec.Y() - Y() ) + Pow2( cr_Vec.Z() - Z() );
00177         }
00178 
00181         f32 GetDistance( const Vec3F_st & cr_Vec ) const
00182         {
00183             return Sqrt( GetSquareDistance( cr_Vec ) );
00184         }
00185 
00186         enum
00187         {
00188             me_X, me_Y, me_Z, me_ArrayNum
00189         };
00190 
00191         f32 ma_[ me_ArrayNum ];
00192 
00193 #ifdef NAR_CTR__
00194         void CopyTo( nn::math::VEC3 &r ) const
00195         {
00196             r.x = X(); r.y = Y(); r.z = Z();
00197         }
00198 #endif
00199     };
00200 }
00201 }
00202 #endif
00203 

© 2011-2012 Nintendo Co., Ltd. All rights reserved.