Esempio n. 1
0
 public static Quaternion ToQuaternion(this Vector3 v)
 {
     /*
      * Quaternion q = new Quaternion();
      * // Abbreviations for the various angular functions
      * double cy = Math.Cos(v.Z * 0.5);
      * double sy = Math.Sin(v.Z * 0.5);
      * double cr = Math.Cos(v.X * 0.5);
      * double sr = Math.Sin(v.X * 0.5);
      * double cp = Math.Cos(v.Y * 0.5);
      * double sp = Math.Sin(v.Y * 0.5);
      *
      * q.W = (float)(cy * cr * cp + sy * sr * sp);
      * q.X = (float)(cy * sr * cp - sy * cr * sp);
      * q.Y = (float)(cy * cr * sp + sy * sr * cp);
      * q.Z = (float)(sy * cr * cp - cy * sr * sp);
      * return q;
      */
     return(MatrixHelper.CreateRotate(v).ExtractRotation());
 }
Esempio n. 2
0
 public static Vector3 ToEuler(this Quaternion q)
 {
     /*
      * Vector3 v = new Vector3();
      * // roll (x-axis rotation)
      * var sinr = 2.0 * (q.W * q.X + q.Y * q.Z);
      * var cosr = 1.0 - 2.0 * (q.X * q.X + q.Y * q.Y);
      * v.X = (float)Math.Atan2(sinr, cosr);
      *
      * // pitch (y-axis rotation)
      * double sinp = 2.0 * (q.W * q.Y - q.Z * q.X);
      * if (Math.Abs(sinp) >= 1) v.Y = MathHelper.PiOver2; // use 90 degrees if out of range
      * else v.Y = (float)Math.Asin(sinp);
      *
      * // yaw (z-axis rotation)
      * double siny = 2.0 * (q.W * q.Z + q.X * q.Y);
      * double cosy = 1.0 - 2.0 * (q.Y * q.Y + q.Z * q.Z);
      * v.Z = (float)Math.Atan2(siny, cosy);
      *
      * return v;
      */
     return(MatrixHelper.ExtractEulerRotation(Matrix4.CreateFromQuaternion(q)) * -1.0f);
 }
Esempio n. 3
0
        public static void DrawTexture(Texture2D tex, RectangleF srcRect, RectangleF dstRect, Color4 color, Vector3 rot, Vector2 scale, Vector2 pivot, int layer = -1, bool flipY = false)
        {
            if (tex == null)
            {
                return;
            }
            if (layer < 0)
            {
                GL.Disable(EnableCap.DepthTest);
            }

            var ortho = Matrix4.CreateOrthographicOffCenter(0, MMW.ClientSize.Width, 0, MMW.ClientSize.Height, 0.0f, 1.0f);

            var trans = new Vector3(pivot.X, pivot.Y, 0.0f);
            var mat   = Matrix4.CreateTranslation(-trans);

            mat      *= MatrixHelper.CreateRotate(new Vector3(rot.X, rot.Y, -rot.Z));
            mat      *= Matrix4.CreateScale(scale.X * dstRect.Width, scale.Y * dstRect.Height, 1.0f);
            mat.Row3 += new Vector4(trans + new Vector3(dstRect.X, MMW.Height - dstRect.Y, 0.0f));
            mat      *= ortho;

            tex2Shader.UseShader();
            tex2Shader.SetParameter(tex2Shader.loc_layer, layer < 0 ? 0f : (float)layer);
            tex2Shader.SetParameter(tex2Shader.loc_flipY, flipY ? 1.0f : 0.0f);
            tex2Shader.SetParameter(tex2Shader.loc_color, ref color);
            tex2Shader.SetParameter(TextureUnit.Texture0, tex);
            tex2Shader.SetParameter(tex2Shader.loc_mvp, ref mat, false);
            DrawSubMesh(texMesh2.subMeshes[0]);
            tex2Shader.UnuseShader();

            GL.BindTexture(TextureTarget.Texture2D, 0);
            if (layer < 0)
            {
                GL.Enable(EnableCap.DepthTest);
            }
        }