示例#1
0
        /// <summary>
        /// カメラ行列(左手系)を設定する。
        /// </summary>
        /// <param name="eye">カメラの位置</param>
        /// <param name="at">カメラの注視点</param>
        /// <param name="up">カメラの上方向</param>
        public void SetLookAtLH(ref Vector3DF eye, ref Vector3DF at, ref Vector3DF up)
        {
            // F=正面、R=右方向、U=上方向
            Vector3DF F = (at - eye).Normal;
            Vector3DF R = Vector3DF.Cross(ref up, ref F).Normal;
            Vector3DF U = Vector3DF.Cross(ref F, ref R).Normal;

            fixed(float *v = Values)
            {
                v[0 * 4 + 0] = R.X;
                v[0 * 4 + 1] = R.Y;
                v[0 * 4 + 2] = R.Z;
                v[0 * 4 + 3] = 0.0f;

                v[1 * 4 + 0] = U.X;
                v[1 * 4 + 1] = U.Y;
                v[1 * 4 + 2] = U.Z;
                v[1 * 4 + 3] = 0.0f;

                v[2 * 4 + 0] = F.X;
                v[2 * 4 + 1] = F.Y;
                v[2 * 4 + 2] = F.Z;
                v[2 * 4 + 3] = 0.0f;

                v[0 * 4 + 3] = -Vector3DF.Dot(ref R, ref eye);
                v[1 * 4 + 3] = -Vector3DF.Dot(ref U, ref eye);
                v[2 * 4 + 3] = -Vector3DF.Dot(ref F, ref eye);
                v[3 * 4 + 3] = 1.0f;
            }
        }
示例#2
0
        /// <summary>
        /// 任意軸の反時計回転行列(右手)を設定する。
        /// </summary>
        /// <param name="axis">軸</param>
        /// <param name="angle">回転量(ラジアン)</param>
        public void SetRotationAxis(ref Vector3DF axis, float angle)
        {
            float s  = (float)Math.Sin(angle);
            float c  = (float)Math.Cos(angle);
            float cc = 1.0f - c;

            fixed(float *v = Values)
            {
                v[0 * 4 + 0] = cc * (axis.X * axis.X) + c;
                v[1 * 4 + 0] = cc * (axis.X * axis.Y) + (axis.Z * s);
                v[2 * 4 + 0] = cc * (axis.Z * axis.X) - (axis.Y * s);

                v[0 * 4 + 1] = cc * (axis.X * axis.Y) - (axis.Z * s);
                v[1 * 4 + 1] = cc * (axis.Y * axis.Y) + c;
                v[2 * 4 + 1] = cc * (axis.Y * axis.Z) + (axis.X * s);

                v[0 * 4 + 2] = cc * (axis.Z * axis.X) + (axis.Y * s);
                v[1 * 4 + 2] = cc * (axis.Y * axis.Z) - (axis.X * s);
                v[2 * 4 + 2] = cc * (axis.Z * axis.Z) + c;

                v[0 * 4 + 3] = 0.0f;
                v[1 * 4 + 3] = 0.0f;
                v[2 * 4 + 3] = 0.0f;
            }
        }
示例#3
0
        /// <summary>
        /// 2点間の距離を取得する。
        /// </summary>
        /// <param name="v1">値1</param>
        /// <param name="v2">値2</param>
        /// <returns>距離</returns>
        public static float Distance(ref Vector3DF v1, ref Vector3DF v2)
        {
            float dx = v1.X - v2.X;
            float dy = v1.Y - v2.Y;
            float dz = v1.Z - v2.Z;

            return((float)Math.Sqrt(dx * dx + dy * dy + dz * dz));
        }
示例#4
0
        /// <summary>
        /// 外積を取得する。
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public static Vector3DF Cross(ref Vector3DF v1, ref Vector3DF v2)
        {
            Vector3DF o;
            float     x = v1.Y * v2.Z - v1.Z * v2.Y;
            float     y = v1.Z * v2.X - v1.X * v2.Z;
            float     z = v1.X * v2.Y - v1.Y * v2.X;

            o.X = x;
            o.Y = y;
            o.Z = z;
            return(o);
        }
        /// <summary>
        /// 行列でベクトルを変形させる。
        /// </summary>
        /// <param name="in_">変形前ベクトル</param>
        /// <returns>変形後ベクトル</returns>
        public Vector3DF Transform3D(ref Vector3DF in_)
        {
            float *values = stackalloc float[4];

            fixed(float *v = Values)
            {
                for (int i = 0; i < 3; i++)
                {
                    values[i]  = 0;
                    values[i] += in_.X * v[i * 3 + 0];
                    values[i] += in_.Y * v[i * 3 + 1];
                    values[i] += in_.Z * v[i * 3 + 2];
                }
            }

            Vector3DF o;

            o.X = values[0];
            o.Y = values[1];
            o.Z = values[2];
            return(o);
        }
示例#6
0
 /// <summary>
 /// 内積を取得する。
 /// </summary>
 /// <param name="v1">値1</param>
 /// <param name="v2">値2</param>
 /// <returns>内積</returns>
 public static float Dot(ref Vector3DF v1, ref Vector3DF v2)
 {
     return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z);
 }
 public void SetVector3DF(string name, Vector3DF value)
 {
     SwigObject.SetVector3DF(name, value);
 }