Matrix Util : Matrix « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » 2D Graphics » MatrixScreenshots 
Matrix Util
       
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

public class Utils
{
    public static Vector3 Gravity = new Vector3(0.0f, -9.81f0.0f);

    public static void AddScaledVector(ref Vector3 vector, float scale, ref Vector3 result)
    {
        Vector3 temp;
        Vector3.Multiply(ref vector, scale, out temp);
        Vector3.Add(ref result, ref temp, out result);
    }

    public static void AddScaledVector(ref Vector3 vector, float scale, ref Quaternion result)
    {
        Quaternion q = new Quaternion(vector, scale);
        Quaternion.Multiply(ref q, ref result, out q);
        result.W += q.W * 0.5f;
        result.X += q.X * 0.5f;
        result.Y += q.Y * 0.5f;
        result.Z += q.Z * 0.5f;
    }

    public static Vector3 TransformInverseDirection(ref Vector3 vector, ref Matrix tensor)
    {
        return new Vector3(
            vector.X * tensor.M11 + vector.Y * tensor.M21 + vector.Z * tensor.M31,
            vector.X * tensor.M12 + vector.Y * tensor.M22 + vector.Z * tensor.M32,
            vector.X * tensor.M13 + vector.Y * tensor.M23 + vector.Z * tensor.M33
            );
    }

    public static void LinearInterpolation(ref Matrix a, ref Matrix b, float prop, out Matrix result)
    {
        // TODO: Optimize if needed!!
        Matrix t1;
        Matrix.Multiply(ref a, prop, out t1);

        Matrix t2;
        Matrix.Multiply(ref b, (- prop), out t2);

        Matrix.Add(ref t1, ref t1, out result);
    }

    public static Matrix CreateMatrix(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
    {
        Matrix m = Matrix.Identity;
        m.M11 = m11; m.M12 = m12; m.M13 = m13;
        m.M21 = m21; m.M22 = m22; m.M23 = m23;
        m.M31 = m31; m.M32 = m32; m.M33 = m33;
        return m;
    }
}

   
    
    
    
    
    
    
  
Related examples in the same category
1.new Matrix(0.707f, 0.707f, -0.707f, 0.707f, 0, 0)
2.Text direction (Matrix Rotate)
3.Matrix DemoMatrix Demo
4.Matrix DrawMatrix Draw
5.Multiply two Matrixes
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.