C #: Declaration and use of XNA vectors for matrix multiplication, and. al

advertisements

I am trying to declare and use XNA Vectors for Matrix Multiplication, Summation, etc. in C#.

Those will be used for Image processing to make it faster than regular SetPixel and GetPixel. However, I am always failing to find a working example and I tried many examples online but it seems I am missing something.

Any help and sample code?

Thanks!


If you are worried about Performance then you can revert to coding in unsafe context.

By marking a type, type member, or statement block with the unsafe keyword, you're permitted to use pointer types and perform C++ style pointer operations on memory within that scope, and to be able to do this within the managed execution framework. Unsafe code can run faster than a corresponding safe implementation.

Here is a nice, short example that comes from the book C# 4.0 in a Nutshell:

unsafe void BlueFilter (int[,] bitmap)
  {
    int length = bitmap.Length;
    fixed (int* b=bitmap)
    {
        int* p=b;
        for (int i=0, i<length; i++)
        *p++ &= 0xFF;
    }
   }

(Source)


Apart from that you should also take a look at this SO Question

Why is matrix multiplication in .NET so slow?