CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
reckoning_Vector3f.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/reckoning/reckoning_Definitions.h>
17 
18 
19 namespace nn
20 {
21 namespace pia
22 {
23 namespace reckoning
24 {
25 
26 /*!
27  @brief Vector3fクラスは3次元ベクトルを扱うStrategyのために用意されたクラスです。
28  */
29 class Vector3f
30 {
31 public:
32  float x;
33  float y;
34  float z;
35 
36  /*!
37  @brief デフォルトコンストラクタです。
38  */
40  : x(0.f), y(0.f), z(0.f) {};
41 
42  /*!
43  @brief 引数で要素の初期化を行うコンストラクタです。
44  @param[in] vx, vy, vz 初期化する値を入れる必要があります。
45  */
46  Vector3f(const float vx, const float vy, const float vz)
47  {
48  this->x = vx;
49  this->y = vy;
50  this->z = vz;
51  }
52 
53  /*!
54  @brief 0ベクトルをセットします。
55  */
56  void MakeZero()
57  {
58  x = y = z = 0.f;
59  }
60 
61  /*!
62  @brief 2点間の距離の2乗を返します。
63  @param[in] v 距離を求めたい対象のベクトル
64  @return 距離の2乗を返します。
65  */
66  float SquaredDistance(const Vector3f& v) const
67  {
68  float dx = this->x - v.x;
69  float dy = this->y - v.y;
70  float dz = this->z - v.z;
71  return dx * dx + dy * dy + dz * dz;
72  }
73 
74  /*!
75  @brief 対象のベクトルに対して指定したベクトルを加算します。
76  @param[out] out 対象ベクトル
77  @param[in] v 加算ベクトル
78  */
79  static void Add(Vector3f* out, const Vector3f& v)
80  {
81  out->x += v.x;
82  out->y += v.y;
83  out->z += v.z;
84  return;
85  }
86 
87  /*!
88  @brief 対象のベクトルに対して指定した値をスカラー乗算します。
89  @param[out] out 対象ベクトル
90  @param[in] t 乗算値
91  */
92  static void Mul(Vector3f* out, const float& t)
93  {
94  out->x *= t;
95  out->y *= t;
96  out->z *= t;
97  }
98 
99  /*!
100  @brief 指定したベクトルを加算して代入します。
101  @param[in] v 加算ベクトル
102  @return 加算後のベクトルを返します。
103  */
105  {
106  x += v.x;
107  y += v.y;
108  z += v.z;
109  return *this;
110  }
111 
112  /*!
113  @brief 指定した値でスカラー除算して代入します。
114  @param[in] t 除算値
115  @return 除算後のベクトルを返します。
116  */
117  Vector3f& operator/=(const float& t)
118  {
119  x /= t;
120  y /= t;
121  z /= t;
122  return *this;
123  }
124 
125 protected:
126 private:
127 };
128 }
129 }
130 } // end of namespace nn::pia::reckoning