/// <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; } }
public static Vector3DF operator *(Matrix33 left, Vector3DF right) { float* elements = stackalloc float[3]; elements[0] = 0; elements[1] = 0; elements[2] = 0; float* rop = stackalloc float[3]; rop[0] = right.X; rop[1] = right.Y; rop[2] = right.Z; float* v = left.Values; { for (int i = 0; i < 3; ++i) { for (int k = 0; k < 3; ++k) { elements[i] += v[i * 3 + k] * rop[k]; } } } Vector3DF result = new Vector3DF(); result.X = elements[0]; result.Y = elements[1]; result.Z = elements[2]; return result; }
/// <summary> /// カメラ行列(左手系)を設定する。 /// </summary> /// <param name="eye">カメラの位置</param> /// <param name="at">カメラの注視点</param> /// <param name="up">カメラの上方向</param> public void SetLookAtLH(Vector3DF eye, Vector3DF at, Vector3DF up) { // F=正面、R=右方向、U=上方向 Vector3DF F = (at - eye).Normal; Vector3DF R = Vector3DF.Cross(up, F).Normal; Vector3DF U = Vector3DF.Cross(F, 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(R, eye); v[1 * 4 + 3] = -Vector3DF.Dot(U, eye); v[2 * 4 + 3] = -Vector3DF.Dot(F, eye); v[3 * 4 + 3] = 1.0f; } }
public static Vector3DF operator *(Matrix33 left, Vector3DF right) { float *elements = stackalloc float[3]; elements[0] = 0; elements[1] = 0; elements[2] = 0; float *rop = stackalloc float[3]; rop[0] = right.X; rop[1] = right.Y; rop[2] = right.Z; float *v = left.Values; { for (int i = 0; i < 3; ++i) { for (int k = 0; k < 3; ++k) { elements[i] += v[i * 3 + k] * rop[k]; } } } Vector3DF result = new Vector3DF(); result.X = elements[0]; result.Y = elements[1]; result.Z = elements[2]; return(result); }
/// <summary> /// 2点間の距離を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>v1とv2の距離</returns> public static float Distance(Vector3DF v1, 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)); }
/// <summary> /// 通常の描画に加えてテクスチャを描画する。 /// </summary> /// <param name="upperLeftPos">テクスチャの左上の描画位置</param> /// <param name="upperRightPos">テクスチャの右上の描画位置</param> /// <param name="lowerRightPos">テクスチャの右下の描画位置</param> /// <param name="lowerLeftPos">テクスチャの左下の描画位置</param> /// <param name="upperLeftCol">テクスチャの左上の頂点色</param> /// <param name="upperRightCol">テクスチャの右上の頂点色</param> /// <param name="lowerRightCol">テクスチャの右下の頂点色</param> /// <param name="lowerLeftCol">テクスチャの左下の頂点色</param> /// <param name="upperLeftUV">テクスチャの左上のUV値</param> /// <param name="upperRightUV">テクスチャの右上のUV値</param> /// <param name="lowerRightUV">テクスチャの右下のUV値</param> /// <param name="lowerLeftUV">テクスチャの左下のUV値</param> /// <param name="texture">描画するテクスチャ</param> /// <param name="alphaBlend">アルファブレンドの種類</param> /// <param name="depthWrite">深度を比較するか?</param> /// <param name="depthTest">深度を書き込むか?</param> /// <remarks>OnDrawAdditionallyの中以外では実行してはいけない。</remarks> public void DrawSpriteAdditionally(Vector3DF upperLeftPos, Vector3DF upperRightPos, Vector3DF lowerRightPos, Vector3DF lowerLeftPos, Color upperLeftCol, Color upperRightCol, Color lowerRightCol, Color lowerLeftCol, Vector2DF upperLeftUV, Vector2DF upperRightUV, Vector2DF lowerRightUV, Vector2DF lowerLeftUV, Texture2D texture, AlphaBlendMode alphaBlend, bool depthWrite, bool depthTest) { coreLayer3D.DrawSpriteAdditionally( upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos, upperLeftCol, upperRightCol, lowerRightCol, lowerLeftCol, upperLeftUV, upperRightUV, lowerRightUV, lowerLeftUV, IG.GetTexture2D(texture), (swig.AlphaBlendMode)alphaBlend, depthWrite, depthTest); }
/// <summary> /// 通常の描画に加えてテクスチャを描画する。 /// </summary> /// <param name="upperLeftPos">テクスチャの左上の描画位置</param> /// <param name="upperRightPos">テクスチャの右上の描画位置</param> /// <param name="lowerRightPos">テクスチャの右下の描画位置</param> /// <param name="lowerLeftPos">テクスチャの左下の描画位置</param> /// <param name="upperLeftCol">テクスチャの左上の頂点色</param> /// <param name="upperRightCol">テクスチャの右上の頂点色</param> /// <param name="lowerRightCol">テクスチャの右下の頂点色</param> /// <param name="lowerLeftCol">テクスチャの左下の頂点色</param> /// <param name="upperLeftUV">テクスチャの左上のUV値</param> /// <param name="upperRightUV">テクスチャの右上のUV値</param> /// <param name="lowerRightUV">テクスチャの右下のUV値</param> /// <param name="lowerLeftUV">テクスチャの左下のUV値</param> /// <param name="texture">描画するテクスチャ</param> /// <param name="alphaBlend">アルファブレンドの種類</param> /// <param name="depthTest">深度を書き込むか?</param> /// <param name="depthWrite">深度を比較するか?</param> /// <remarks>OnDrawAdditionallyの中以外では実行してはいけない。</remarks> public void DrawSpriteAdditionally(Vector3DF upperLeftPos, Vector3DF upperRightPos, Vector3DF lowerRightPos, Vector3DF lowerLeftPos, Color upperLeftCol, Color upperRightCol, Color lowerRightCol, Color lowerLeftCol, Vector2DF upperLeftUV, Vector2DF upperRightUV, Vector2DF lowerRightUV, Vector2DF lowerLeftUV, Texture2D texture, AlphaBlendMode alphaBlend, bool depthWrite, bool depthTest) { Layer.DrawSpriteAdditionally( upperLeftPos, upperRightPos, lowerRightPos, lowerLeftPos, upperLeftCol, upperRightCol, lowerRightCol, lowerLeftCol, upperLeftUV, upperRightUV, lowerRightUV, lowerLeftUV, texture, alphaBlend, depthWrite, depthTest); }
/// <summary> /// スカラーで除算する。 /// </summary> /// <param name="v1">値1</param> /// <param name="v2">値2</param> /// <returns>v1/v2</returns> public static Vector3DF DivideByScalar(Vector3DF v1, float v2) { var ret = new Vector3DF(); ret.X = v1.X / v2; ret.Y = v1.Y / v2; ret.Z = v1.Z / v2; return(ret); }
/// <summary> /// 除算する。 /// </summary> /// <param name="v1">値1</param> /// <param name="v2">値2</param> /// <returns>v1/v2</returns> public static Vector3DF Divide(Vector3DF v1, Vector3DF v2) { var ret = new Vector3DF(); ret.X = v1.X / v2.X; ret.Y = v1.Y / v2.Y; ret.Z = v1.Z / v2.Z; return(ret); }
/// <summary> /// 減算する。 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> public static Vector3DF Subtract(Vector3DF v1, Vector3DF v2) { Vector3DF o = new Vector3DF(); o.X = v1.X - v2.X; o.Y = v1.Y - v2.Y; o.Z = v1.Z - v2.Z; return(o); }
/// <summary> /// 加算する。 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> public static Vector3DF Add(Vector3DF v1, Vector3DF v2) { Vector3DF o = new Vector3DF(); o.X = v1.X + v2.X; o.Y = v1.Y + v2.Y; o.Z = v1.Z + v2.Z; return(o); }
/// <summary> /// 外積を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>外積v1×v2</returns> /// <remarks> /// 右手の親指がv1、人差し指がv2としたとき、中指の方向を返す。 /// </remarks> public static Vector3DF Cross(Vector3DF v1, Vector3DF v2) { Vector3DF o = new Vector3DF(); 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); }
protected override void OnDraw(RenderTexture2D dst, RenderTexture2D src) { Vector3DF weights = new Vector3DF(); float[] ws = new float[3]; float total = 0.0f; float dispersion = intensity * intensity; for (int i = 0; i < 3; i++) { float pos = 1.0f + 2.0f * i; ws[i] = (float)Math.Exp(-0.5f * pos * pos / dispersion); total += ws[i] * 2.0f; } weights.X = ws[0] / total; weights.Y = ws[1] / total; weights.Z = ws[2] / total; material2dX.SetTexture2D("g_texture", src); material2dX.SetVector3DF("g_weight", weights); material2dX.SetTextureFilterType("g_texture", TextureFilterType.Linear); var size = src.Size; var format = src.Format; if (tempTexture == null || (!tempTexture.Size.Equals(size) || tempTexture.Format != format)) { if (format == TextureFormat.R32G32B32A32_FLOAT) { tempTexture = Engine.Graphics.CreateRenderTexture2D(size.X, size.Y, TextureFormat.R32G32B32A32_FLOAT); } else { tempTexture = Engine.Graphics.CreateRenderTexture2D(size.X, size.Y, TextureFormat.R8G8B8A8_UNORM); } } DrawOnTexture2DWithMaterial(tempTexture, material2dX); material2dY.SetTexture2D("g_texture", tempTexture); material2dY.SetVector3DF("g_weight", weights); material2dY.SetTextureFilterType("g_texture", TextureFilterType.Linear); DrawOnTexture2DWithMaterial(dst, material2dY); }
public override void OnDraw(RenderTexture2D dst, RenderTexture2D src) { Vector3DF weights = new Vector3DF(); float[] ws = new float[3]; float total = 0.0f; float dispersion = intensity * intensity; for (int i = 0; i < 3; i++) { float pos = 1.0f + 2.0f * i; ws[i] = (float)Math.Exp(-0.5f * pos * pos / dispersion); total += ws[i] * 2.0f; } weights.X = ws[0] / total; weights.Y = ws[1] / total; weights.Z = ws[2] / total; material2dX.SetTexture2D("g_texture", src); material2dX.SetVector3DF("g_weight", weights); material2dX.SetTextureFilterType("g_texture", TextureFilterType.Linear); var size = src.Size; var format = src.Format; if (tempTexture == null || (tempTexture.Size != size || tempTexture.Format != format)) { if (format == TextureFormat.R32G32B32A32_FLOAT) { tempTexture = Engine.Graphics.CreateRenderTexture2D(size.X, size.Y, TextureFormat.R32G32B32A32_FLOAT); } else { tempTexture = Engine.Graphics.CreateRenderTexture2D(size.X, size.Y, TextureFormat.R8G8B8A8_UNORM); } } DrawOnTexture2DWithMaterial(tempTexture, material2dX); material2dY.SetTexture2D("g_texture", tempTexture); material2dY.SetVector3DF("g_weight", weights); material2dY.SetTextureFilterType("g_texture", TextureFilterType.Linear); DrawOnTexture2DWithMaterial(dst, material2dY); }
/// <summary> /// 行列でベクトルを変形させる。 /// </summary> /// <param name="in_">変形前ベクトル</param> /// <returns>変形後ベクトル</returns> public Vector3DF Transform3D(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 = new Vector3DF(); o.X = values[0]; o.Y = values[1]; o.Z = values[2]; return o; }
/// <summary> /// 2点間の距離を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>v1とv2の距離</returns> public static float Distance(Vector3DF v1, 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); }
/// <summary> /// 内積を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>内積v1・v2</returns> public static float Dot(Vector3DF v1, Vector3DF v2) { return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z; }
/// <summary> /// 外積を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>外積v1×v2</returns> /// <remarks> /// 右手の親指がv1、人差し指がv2としたとき、中指の方向を返す。 /// </remarks> public static Vector3DF Cross( Vector3DF v1, Vector3DF v2 ) { Vector3DF o = new Vector3DF(); 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="eye">カメラの位置</param> /// <param name="at">カメラの注視点</param> /// <param name="up">カメラの上方向</param> public void SetLookAtRH(Vector3DF eye, Vector3DF at, Vector3DF up) { // F=正面、R=右方向、U=上方向 Vector3DF F = (eye - at).Normal; Vector3DF R = Vector3DF.Cross(up, F).Normal; Vector3DF U = Vector3DF.Cross(F, 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(R, eye); v[1 * 4 + 3] = -Vector3DF.Dot(U, eye); v[2 * 4 + 3] = -Vector3DF.Dot(F, eye); v[3 * 4 + 3] = 1.0f; } }
/// <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; } }
/// <summary> /// 内積を取得する。 /// </summary> /// <param name="v1">v1ベクトル</param> /// <param name="v2">v2ベクトル</param> /// <returns>内積v1・v2</returns> public static float Dot(Vector3DF v1, Vector3DF v2) { return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z); }
public void SetVector3DF(string name, Vector3DF value) { CoreInstance.SetVector3DF(name, value); }
/// <summary> /// 行列でベクトルを変形させる。 /// </summary> /// <param name="in_">変形前ベクトル</param> /// <returns>変形後ベクトル</returns> public Vector3DF Transform3D(Vector3DF in_) { float* values = stackalloc float[4]; fixed (float* v = Values) { for (int i = 0; i < 4; i++) { values[i] = 0; values[i] += in_.X * v[i * 4 + 0]; values[i] += in_.Y * v[i * 4 + 1]; values[i] += in_.Z * v[i * 4 + 2]; values[i] += v[i * 4 + 3]; } } Vector3DF o = new Vector3DF(); o.X = values[0] / values[3]; o.Y = values[1] / values[3]; o.Z = values[2] / values[3]; return o; }
public void SetVector3DF(string name, Vector3DF value) { SwigObject.SetVector3DF(name, value); }