public CVector4(CVector3 v) { this.x = v.x; this.y = v.y; this.z = v.z; this.w = 1.0f; }
public void Set(CVector3 v) { this.x = v.x; this.y = v.y; this.z = v.z; this.w = 1.0f; }
/// <summary> /// 外積を求める /// </summary> /// <param name="v1">入力ベクトル1</param> /// <param name="v2">入力ベクトル2</param> /// <returns>外積ベクトル</returns> public static CVector3 Cross(CVector3 v1, CVector3 v2) { CVector3 v = new CVector3(); v.x = v1.y * v2.z - v1.z * v2.y; v.y = v1.z * v2.x - v1.x * v2.z; v.z = v1.x * v2.y - v1.y * v2.x; return(v); }
/// <summary> /// 法線ベクトルを求める /// </summary> /// <param name="v1">入力ベクトル1</param> /// <param name="v2">入力ベクトル2</param> /// <param name="v3">入力ベクトル3</param> /// <returns>法線ベクトル</returns> public static CVector3 Normal(CVector3 v1, CVector3 v2, CVector3 v3) { CVector3 v = new CVector3(); CVector3 a = new CVector3(); CVector3 b = new CVector3(); a = v2 - v1; b = v3 - v2; v = CVector3.Cross(a, b); v = v.Normalize(); return(v); }
// 評価 public override bool Equals(object obj) { if (obj == null) { return(false); } CVector3 v = obj as CVector3; if ((object)v == null) { return(false); } return((this.x == v.x) && (this.y == v.y) && (this.z == v.z)); }
public CVector3(CVector3 v) { this.x = v.x; this.y = v.y; this.z = v.z; }
/// <summary> /// 内積を求める /// </summary> /// <param name="v1">入力ベクトル1</param> /// <param name="v2">入力ベクトル2</param> /// <returns>内積値</returns> public static float Dot(CVector3 v1, CVector3 v2) { return(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z); }
/// <summary> /// 3方向ベクトルと4x4行列の積 /// 備考:4行目の行列には1をかけます /// </summary> /// <param name="dv">出力先ベクトル</param> /// <param name="v">計算用ベクトル</param> /// <param name="m">計算用行列</param> public static void MatApply3(CVector3 dv, CVector3 v, CMatrix4 m) { dv.x = v.x * m.m[0, 0] + v.y * m.m[1, 0] + v.z * m.m[2, 0] + 1.0f * m.m[3, 0]; dv.y = v.x * m.m[0, 1] + v.y * m.m[1, 1] + v.z * m.m[2, 1] + 1.0f * m.m[3, 1]; dv.z = v.x * m.m[0, 2] + v.y * m.m[1, 2] + v.z * m.m[2, 2] + 1.0f * m.m[3, 2]; }