Exemplo n.º 1
0
 public static TransformMatrix CreateScaler(float scaleX, float scaleY, float scaleZ /*=1.0f*/)
 {
   TransformMatrix scaler = new TransformMatrix();
   scaler.m[0, 0] = scaleX;
   scaler.m[1, 1] = scaleY;
   scaler.m[2, 2] = scaleZ;
   return scaler;
 }
Exemplo n.º 2
0
 public static TransformMatrix CreateTranslation(float transX, float transY, float transZ /*=0.0f*/)
 {
   TransformMatrix translation = new TransformMatrix();
   translation.m[0, 3] = transX;
   translation.m[1, 3] = transY;
   translation.m[2, 3] = transZ;
   return translation;
 }
Exemplo n.º 3
0
        public static TransformMatrix CreateZRotation(float angle, float x, float y, float ar /*=1.0f*/)
        {
            // angle about the Z axis, centered at x,y where our coordinate system has aspect ratio ar.
            // Trans(x,y,0)*Scale(1/ar,1,1)*RotateZ(angle)*Scale(ar,1,1)*Trans(-x,-y,0)
            float           c   = (float)Math.Cos(angle);
            float           s   = (float)Math.Sin(angle);
            TransformMatrix rot = new TransformMatrix();

            rot.m[0, 0] = c;
            rot.m[0, 1] = -s / ar;
            rot.m[0, 3] = -x * c + s * y / ar + x;
            rot.m[1, 0] = s * ar;
            rot.m[1, 1] = c;
            rot.m[1, 3] = -ar * x * s - c * y + y;
            return(rot);
        }
        public TransformMatrix multiply(TransformMatrix right)
        {
            TransformMatrix result = new TransformMatrix();

            result.m[0, 0] = m[0, 0] * right.m[0, 0] + m[0, 1] * right.m[1, 0] + m[0, 2] * right.m[2, 0];
            result.m[0, 1] = m[0, 0] * right.m[0, 1] + m[0, 1] * right.m[1, 1] + m[0, 2] * right.m[2, 1];
            result.m[0, 2] = m[0, 0] * right.m[0, 2] + m[0, 1] * right.m[1, 2] + m[0, 2] * right.m[2, 2];
            result.m[0, 3] = m[0, 0] * right.m[0, 3] + m[0, 1] * right.m[1, 3] + m[0, 2] * right.m[2, 3] + m[0, 3];
            result.m[1, 0] = m[1, 0] * right.m[0, 0] + m[1, 1] * right.m[1, 0] + m[1, 2] * right.m[2, 0];
            result.m[1, 1] = m[1, 0] * right.m[0, 1] + m[1, 1] * right.m[1, 1] + m[1, 2] * right.m[2, 1];
            result.m[1, 2] = m[1, 0] * right.m[0, 2] + m[1, 1] * right.m[1, 2] + m[1, 2] * right.m[2, 2];
            result.m[1, 3] = m[1, 0] * right.m[0, 3] + m[1, 1] * right.m[1, 3] + m[1, 2] * right.m[2, 3] + m[1, 3];
            result.m[2, 0] = m[2, 0] * right.m[0, 0] + m[2, 1] * right.m[1, 0] + m[2, 2] * right.m[2, 0];
            result.m[2, 1] = m[2, 0] * right.m[0, 1] + m[2, 1] * right.m[1, 1] + m[2, 2] * right.m[2, 1];
            result.m[2, 2] = m[2, 0] * right.m[0, 2] + m[2, 1] * right.m[1, 2] + m[2, 2] * right.m[2, 2];
            result.m[2, 3] = m[2, 0] * right.m[0, 3] + m[2, 1] * right.m[1, 3] + m[2, 2] * right.m[2, 3] + m[2, 3];
            result.alpha   = alpha * right.alpha;
            return(result);
        }
        // assignment operator
        public TransformMatrix assign(TransformMatrix right)
        {
            m[0, 0] = right.m[0, 0];
            m[0, 1] = right.m[0, 1];
            m[0, 2] = right.m[0, 2];
            m[0, 3] = right.m[0, 3];

            m[1, 0] = right.m[1, 0];
            m[1, 1] = right.m[1, 1];
            m[1, 2] = right.m[1, 2];
            m[1, 3] = right.m[1, 3];

            m[2, 0] = right.m[2, 0];
            m[2, 1] = right.m[2, 1];
            m[2, 2] = right.m[2, 2];
            m[2, 3] = right.m[2, 3];
            alpha   = right.alpha;
            return(this);
        }
Exemplo n.º 6
0
            /// <summary>
            /// Draw a texture rotated around (x,y).
            /// </summary>
            /// <param name="x"></param>
            /// <param name="y"></param>
            /// <param name="nw"></param>
            /// <param name="nh"></param>
            /// <param name="zrot"></param>
            /// <param name="uoff"></param>
            /// <param name="voff"></param>
            /// <param name="umax"></param>
            /// <param name="vmax"></param>
            /// <param name="color"></param>
            public void Draw(float x, float y, float nw, float nh, float zrot, float uoff, float voff, float umax, float vmax,
                             uint color)
            {
                if (_textureNumber >= 0)
                {
                    // Rotate around the x,y point of the specified rectangle; maintain aspect ratio (1.0f)
                    TransformMatrix localTransform = new TransformMatrix();
                    localTransform.SetZRotation(zrot, x, y, 1.0f);
                    TransformMatrix finalTransform = GUIGraphicsContext.GetFinalTransform();
                    localTransform = finalTransform.multiply(localTransform);

                    DXNative.FontEngineDrawTexture(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax, color, localTransform.Matrix);
                }
                else
                {
                    if (logTextures)
                    {
                        Log.Info("fontengine:Draw() ERROR. Texture is disposed:{0} {1}", _textureNumber.ToString(), _imageName);
                    }
                }
            }
Exemplo n.º 7
0
        public void RenderAnimation(ref TransformMatrix matrix)
        {
            // If we have finished an animation, reset the animation state
            // We do this here (rather than in Animate()) as we need the
            // currentProcess information in the UpdateStates() function of the
            // window and control classes.

            // Now do the real animation
            if (_currentProcess != AnimationProcess.None)
            {
                Calculate();
            }
            if (_currentState == AnimationState.StateApplied)
            {
                _currentProcess = AnimationProcess.None;
                _queuedProcess  = AnimationProcess.None;
            }
            if (_currentState != AnimationState.None)
            {
                matrix.multiplyAssign(_matrix);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="matrix"></param>
 public static void AddTransform(TransformMatrix matrix)
 {
   GroupTransforms.Add(GroupTransforms.Count > 0
                          ? GroupTransforms[GroupTransforms.Count - 1].multiply(matrix)
                          : matrix);
   UpdateFinalTransform(GroupTransforms[GroupTransforms.Count - 1]);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="matrix"></param>
 public static void SetWindowTransform(TransformMatrix matrix)
 {
   // reset the group transform stack
   GroupTransforms.Clear();
   GroupTransforms.Add(_guiTransform.multiply(matrix));
   _bypassUICalibration = 0;
   UpdateFinalTransform(GroupTransforms[0]);
 }
Exemplo n.º 10
0
 public FinalTransformBucket(TransformMatrix finalTransform, TransformMatrix finalTransformCalibrated)
 {
   // The matrices on the stack must be copies otherwise they may be illegally manipulated while on the stack.
   _finalTransformMatrix = (TransformMatrix)finalTransform.Clone();
   _finalTransformMatrixCalibrated = (TransformMatrix)finalTransformCalibrated.Clone();
 }
Exemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="matrix"></param>
 public static void UpdateFinalTransform(TransformMatrix matrix)
 {
   _finalTransform = matrix;
   _finalTransformCalibrated = GetOffsetCorrectionTransform().multiply(matrix);
 }
Exemplo n.º 12
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="posX"></param>
    /// <param name="posY"></param>
    /// <param name="needsScaling"></param>
    public static void SetScalingResolution(int posX, int posY, bool needsScaling)
    {
      if (!needsScaling)
      {
        _guiTransform = TransformMatrix.CreateTranslation(posX, posY, 0);
      }

      Cameras.Clear();
      Cameras.Add(new Point(Width / 2, Height / 2));
      UpdateCameraPosition(Cameras[Cameras.Count-1]);

      // reset the final transform and window transforms
      UpdateFinalTransform(_guiTransform);
    }
Exemplo n.º 13
0
 public TransformMatrix multiply(TransformMatrix right)
 {
   TransformMatrix result = new TransformMatrix();
   result.m[0, 0] = m[0, 0] * right.m[0, 0] + m[0, 1] * right.m[1, 0] + m[0, 2] * right.m[2, 0];
   result.m[0, 1] = m[0, 0] * right.m[0, 1] + m[0, 1] * right.m[1, 1] + m[0, 2] * right.m[2, 1];
   result.m[0, 2] = m[0, 0] * right.m[0, 2] + m[0, 1] * right.m[1, 2] + m[0, 2] * right.m[2, 2];
   result.m[0, 3] = m[0, 0] * right.m[0, 3] + m[0, 1] * right.m[1, 3] + m[0, 2] * right.m[2, 3] + m[0, 3];
   result.m[1, 0] = m[1, 0] * right.m[0, 0] + m[1, 1] * right.m[1, 0] + m[1, 2] * right.m[2, 0];
   result.m[1, 1] = m[1, 0] * right.m[0, 1] + m[1, 1] * right.m[1, 1] + m[1, 2] * right.m[2, 1];
   result.m[1, 2] = m[1, 0] * right.m[0, 2] + m[1, 1] * right.m[1, 2] + m[1, 2] * right.m[2, 2];
   result.m[1, 3] = m[1, 0] * right.m[0, 3] + m[1, 1] * right.m[1, 3] + m[1, 2] * right.m[2, 3] + m[1, 3];
   result.m[2, 0] = m[2, 0] * right.m[0, 0] + m[2, 1] * right.m[1, 0] + m[2, 2] * right.m[2, 0];
   result.m[2, 1] = m[2, 0] * right.m[0, 1] + m[2, 1] * right.m[1, 1] + m[2, 2] * right.m[2, 1];
   result.m[2, 2] = m[2, 0] * right.m[0, 2] + m[2, 1] * right.m[1, 2] + m[2, 2] * right.m[2, 2];
   result.m[2, 3] = m[2, 0] * right.m[0, 3] + m[2, 1] * right.m[1, 3] + m[2, 2] * right.m[2, 3] + m[2, 3];
   result.alpha = alpha * right.alpha;
   return result;
 }
Exemplo n.º 14
0
 private bool RenderAnimation(uint time)
 {
   TransformMatrix transform = new TransformMatrix();
   // show animation
   _showAnimation.Animate(time, true);
   UpdateStates(_showAnimation.AnimationType, _showAnimation.CurrentProcess, _showAnimation.CurrentState);
   _showAnimation.RenderAnimation(ref transform);
   // close animation
   _closeAnimation.Animate(time, true);
   UpdateStates(_closeAnimation.AnimationType, _closeAnimation.CurrentProcess, _closeAnimation.CurrentState);
   _closeAnimation.RenderAnimation(ref transform);
   GUIGraphicsContext.SetWindowTransform(transform);
   return true;
 }
Exemplo n.º 15
0
 public static TransformMatrix CreateZRotation(float angle, float x, float y, float ar /*=1.0f*/)
 {
   // angle about the Z axis, centered at x,y where our coordinate system has aspect ratio ar.
   // Trans(x,y,0)*Scale(1/ar,1,1)*RotateZ(angle)*Scale(ar,1,1)*Trans(-x,-y,0)
   float c = (float)Math.Cos(angle);
   float s = (float)Math.Sin(angle);
   TransformMatrix rot = new TransformMatrix();
   rot.m[0, 0] = c;
   rot.m[0, 1] = -s / ar;
   rot.m[0, 3] = -x * c + s * y / ar + x;
   rot.m[1, 0] = s * ar;
   rot.m[1, 1] = c;
   rot.m[1, 3] = -ar * x * s - c * y + y;
   return rot;
 }
Exemplo n.º 16
0
    // assignment operator
    public TransformMatrix assign(TransformMatrix right)
    {
      m[0, 0] = right.m[0, 0];
      m[0, 1] = right.m[0, 1];
      m[0, 2] = right.m[0, 2];
      m[0, 3] = right.m[0, 3];

      m[1, 0] = right.m[1, 0];
      m[1, 1] = right.m[1, 1];
      m[1, 2] = right.m[1, 2];
      m[1, 3] = right.m[1, 3];

      m[2, 0] = right.m[2, 0];
      m[2, 1] = right.m[2, 1];
      m[2, 2] = right.m[2, 2];
      m[2, 3] = right.m[2, 3];
      alpha = right.alpha;
      return this;
    }
Exemplo n.º 17
0
    public static void SetScalingResolution( /*RESOLUTION res,*/ int posX, int posY, bool needsScaling)
    {
      //m_windowResolution = res;
      if (needsScaling)
      {
        /*
                // calculate necessary scalings
                float fFromWidth = (float)g_settings.m_ResInfo[res].iWidth;
                float fFromHeight = (float)g_settings.m_ResInfo[res].iHeight;
                float fToPosX = (float)g_settings.m_ResInfo[m_Resolution].Overscan.left;
                float fToPosY = (float)g_settings.m_ResInfo[m_Resolution].Overscan.top;
                float fToWidth = (float)g_settings.m_ResInfo[m_Resolution].Overscan.right - fToPosX;
                float fToHeight = (float)g_settings.m_ResInfo[m_Resolution].Overscan.bottom - fToPosY;
                // add additional zoom to compensate for any overskan built in skin
                float fZoom = g_SkinInfo.GetSkinZoom();
                if (!g_guiSkinzoom) // lookup gui setting if we didn't have it already
                  g_guiSkinzoom = (CSettingInt*)g_guiSettings.GetSetting("lookandfeel.skinzoom");
                if (g_guiSkinzoom)
                  fZoom *= (100 + g_guiSkinzoom->GetData()) * 0.01f;
                fZoom -= 1.0f;
                fToPosX -= fToWidth * fZoom * 0.5f;
                fToWidth *= fZoom + 1.0f;
                // adjust for aspect ratio as zoom is given in the vertical direction and we don't 
                // do aspect ratio corrections in the gui code 
                fZoom = fZoom / g_settings.m_ResInfo[m_Resolution].fPixelRatio;
                fToPosY -= fToHeight * fZoom * 0.5f;
                fToHeight *= fZoom + 1.0f;
                _windowScaleX = fToWidth / fFromWidth;
                _windowScaleY = fToHeight / fFromHeight;
                TransformMatrix windowOffset = TransformMatrix.CreateTranslation((float)posX, (float)posY);
                TransformMatrix guiScaler = TransformMatrix.CreateScaler(fToWidth / fFromWidth, fToHeight / fFromHeight);
                TransformMatrix guiOffset = TransformMatrix.CreateTranslation(fToPosX, fToPosY);
                _guiTransform = guiOffset * guiScaler * windowOffset;
        */
      }
      else
      {
        _guiTransform = TransformMatrix.CreateTranslation((float)posX, (float)posY, 0);
        //_windowScaleX = 1.0f;
        //_windowScaleY = 1.0f;
      }

      _cameras.Clear();
      _cameras.Add(new Point(Width / 2, Height / 2));
      UpdateCameraPosition(_cameras[_cameras.Count-1]);
      // reset the final transform and window transforms
      UpdateFinalTransform(_guiTransform);
    }
Exemplo n.º 18
0
      public void Draw(float x, float y, float nw, float nh, float zrot, float uoff, float voff, float umax, float vmax,
                       int color)
      {
        if (_textureNumber >= 0)
        {
          // Rotate around the x,y point of the specified rectangle; maintain aspect ratio (1.0f)
          TransformMatrix localTransform = new TransformMatrix();
          localTransform.SetZRotation(zrot, x, y, 1.0f);
          TransformMatrix finalTransform = GUIGraphicsContext.GetFinalTransform();
          localTransform = finalTransform.multiply(localTransform);

          FontEngineDrawTexture(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax, color, localTransform.Matrix);
        }
        else
        {
          if (logTextures)
          {
            Log.Info("fontengine:Draw() ERROR. Texture is disposed:{0} {1}", _textureNumber.ToString(), _imageName);
          }
        }
      }
Exemplo n.º 19
0
    /// <summary>
    /// Draw a texture rotated around (x,y) blended with a diffuse texture.
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="nw"></param>
    /// <param name="nh"></param>
    /// <param name="zrot"></param>
    /// <param name="uoff"></param>
    /// <param name="voff"></param>
    /// <param name="umax"></param>
    /// <param name="vmax"></param>
    /// <param name="color"></param>
    /// <param name="diffuseTextureNo"></param>
    /// <param name="uoffd"></param>
    /// <param name="voffd"></param>
    /// <param name="umaxd"></param>
    /// <param name="vmaxd"></param>
    public void Draw(float x, float y, float nw, float nh, float zrot, float uoff, float voff, 
                     float umax, float vmax, uint color, int blendableTextureNo, float uoffd, 
                     float voffd, float umaxd, float vmaxd, FontEngineBlendMode blendMode)
    {
      if (_textureNumber >= 0)
      {
        // Rotate around the x,y point of the specified rectangle; maintain aspect ratio (1.0f)
        TransformMatrix localTransform = new TransformMatrix();
        localTransform.SetZRotation(zrot, x, y, 1.0f);
        TransformMatrix finalTransform = GUIGraphicsContext.GetFinalTransform();
        localTransform = finalTransform.multiply(localTransform);

        DXNative.FontEngineDrawTexture2(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax,
                               color, localTransform.Matrix,
                               blendableTextureNo, uoffd, voffd, umaxd, vmaxd,
                               blendMode);
      }
    }
Exemplo n.º 20
0
    // multiplication operators
    public TransformMatrix multiplyAssign(TransformMatrix right)
    {
      float t00 = m[0, 0] * right.m[0, 0] + m[0, 1] * right.m[1, 0] + m[0, 2] * right.m[2, 0];
      float t01 = m[0, 0] * right.m[0, 1] + m[0, 1] * right.m[1, 1] + m[0, 2] * right.m[2, 1];
      float t02 = m[0, 0] * right.m[0, 2] + m[0, 1] * right.m[1, 2] + m[0, 2] * right.m[2, 2];
      m[0, 3] = m[0, 0] * right.m[0, 3] + m[0, 1] * right.m[1, 3] + m[0, 2] * right.m[2, 3] + m[0, 3];
      m[0, 0] = t00;
      m[0, 1] = t01;
      m[0, 2] = t02;
      t00 = m[1, 0] * right.m[0, 0] + m[1, 1] * right.m[1, 0] + m[1, 2] * right.m[2, 0];
      t01 = m[1, 0] * right.m[0, 1] + m[1, 1] * right.m[1, 1] + m[1, 2] * right.m[2, 1];
      t02 = m[1, 0] * right.m[0, 2] + m[1, 1] * right.m[1, 2] + m[1, 2] * right.m[2, 2];
      m[1, 3] = m[1, 0] * right.m[0, 3] + m[1, 1] * right.m[1, 3] + m[1, 2] * right.m[2, 3] + m[1, 3];
      m[1, 0] = t00;
      m[1, 1] = t01;
      m[1, 2] = t02;
      t00 = m[2, 0] * right.m[0, 0] + m[2, 1] * right.m[1, 0] + m[2, 2] * right.m[2, 0];
      t01 = m[2, 0] * right.m[0, 1] + m[2, 1] * right.m[1, 1] + m[2, 2] * right.m[2, 1];
      t02 = m[2, 0] * right.m[0, 2] + m[2, 1] * right.m[1, 2] + m[2, 2] * right.m[2, 2];
      m[2, 3] = m[2, 0] * right.m[0, 3] + m[2, 1] * right.m[1, 3] + m[2, 2] * right.m[2, 3] + m[2, 3];
      m[2, 0] = t00;
      m[2, 1] = t01;
      m[2, 2] = t02;
      alpha *= right.alpha;

      return this;
    }
Exemplo n.º 21
0
 /// <summary>
 /// This is a convenience method for users who wish to manage the control transform matrix with an OpenGL-like matrix stack.
 /// The matrix stack managed is *not* used to set the final transform for MP callers who do not use Push/Pop.
 /// </summary>
 public static void PopMatrix()
 {
   // Pop the transform matrix off of the stack.
   if (FinalTransformStack.Count > 0)
   {
     FinalTransformBucket bucket = FinalTransformStack.Pop();
     _finalTransform = bucket.FinalTransform;
     _finalTransformCalibrated = bucket.FinalTransformCalibrated;
   }
   else
   {
     throw new InvalidOperationException("Attempt to pop final transform matrix off of an empty stack");
   }
 }
Exemplo n.º 22
0
 /// <summary>
 /// Rotates the control transform matrix by the specified angle (in degrees) around the z-axis.
 /// </summary>
 public static void RotateZ(float angle, float x, float y)
 {
   var m = new TransformMatrix();
   angle *= DegreeToRadian;
   m.SetZRotation(angle, x, y, 1.0f);
   UpdateFinalTransform(ControlTransform.multiplyAssign(m));
 }
Exemplo n.º 23
0
 public static TransformMatrix CreateFader(float a)
 {
   TransformMatrix fader = new TransformMatrix();
   fader.alpha = a;
   return fader;
 }
Exemplo n.º 24
0
 public static void AddTransform(TransformMatrix matrix)
 {
   if (_groupTransforms.Count > 0)
   {
     _groupTransforms.Add(_groupTransforms[_groupTransforms.Count - 1].multiply(matrix));
   }
   else
   {
     _groupTransforms.Add(matrix);
   }
   UpdateFinalTransform(_groupTransforms[_groupTransforms.Count - 1]);
 }
Exemplo n.º 25
0
 public object Clone()
 {
   TransformMatrix matrix = new TransformMatrix();
   matrix.assign(this);
   return matrix;
 }
Exemplo n.º 26
0
    public void RenderAnimation(ref TransformMatrix matrix)
    {
      // If we have finished an animation, reset the animation state
      // We do this here (rather than in Animate()) as we need the
      // currentProcess information in the UpdateStates() function of the
      // window and control classes.

      // Now do the real animation
      if (_currentProcess != AnimationProcess.None)
      {
        Calculate();
      }
      if (_currentState == AnimationState.StateApplied)
      {
        _currentProcess = AnimationProcess.None;
        _queuedProcess = AnimationProcess.None;
      }
      if (_currentState != AnimationState.None)
      {
        matrix.multiplyAssign(_matrix);
      }
    }
Exemplo n.º 27
0
 /// <summary>
 /// Rotates the control transform matrix by the specified angle (in degrees) around the z-axis.
 /// </summary>
 public static void RotateZ(float angle, float x, float y)
 {
   TransformMatrix m = new TransformMatrix();
   angle *= DEGREE_TO_RADIAN;
   m.SetZRotation(angle, x, y, 1.0f);
   UpdateFinalTransform(ControlTransform.multiplyAssign(m));
 }