glebedev's picture

Matrix3d / Subtract method adds

Project:The Open Toolkit library
Version:1.x-dev
Component:Code
Category:feature request
Priority:minor
Assigned:Unassigned
Status:open
Description

This is not subtraction:

/// Subtract left matrix from this matrix.
/// The matrix to subtract.
public void Subtract(ref Matrix3d matrix)
{
R0C0 = R0C0 + matrix.R0C0;
R0C1 = R0C1 + matrix.R0C1;
R0C2 = R0C2 + matrix.R0C2;
R1C0 = R1C0 + matrix.R1C0;
R1C1 = R1C1 + matrix.R1C1;
R1C2 = R1C2 + matrix.R1C2;
R2C0 = R2C0 + matrix.R2C0;
R2C1 = R2C1 + matrix.R2C1;
R2C2 = R2C2 + matrix.R2C2;
}

/// Subtract left matrix from this matrix.
/// The matrix to subtract.
/// The resulting matrix of the subtraction.
public void Subtract(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = R0C0 + matrix.R0C0;
result.R0C1 = R0C1 + matrix.R0C1;
result.R0C2 = R0C2 + matrix.R0C2;
result.R1C0 = R1C0 + matrix.R1C0;
result.R1C1 = R1C1 + matrix.R1C1;
result.R1C2 = R1C2 + matrix.R1C2;
result.R2C0 = R2C0 + matrix.R2C0;
result.R2C1 = R2C1 + matrix.R2C1;
result.R2C2 = R2C2 + matrix.R2C2;
}

/// Subtract left matrix from left matrix.
/// The matrix on the matrix side of the equation.
/// The matrix on the right side of the equation
/// The resulting matrix of the subtraction.
public static void Subtract(ref Matrix3d left, ref Matrix3d right, out Matrix3d result)
{
result.R0C0 = left.R0C0 + right.R0C0;
result.R0C1 = left.R0C1 + right.R0C1;
result.R0C2 = left.R0C2 + right.R0C2;
result.R1C0 = left.R1C0 + right.R1C0;
result.R1C1 = left.R1C1 + right.R1C1;
result.R1C2 = left.R1C2 + right.R1C2;
result.R2C0 = left.R2C0 + right.R2C0;
result.R2C1 = left.R2C1 + right.R2C1;
result.R2C2 = left.R2C2 + right.R2C2;
}


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Category:bug report» feature request
Priority:critical» minor

There's a reason why Matrix3d is not part of the public API. There's also a reason why the code is commented-out: it's simply not implemented.

I'm leaving this open in case someone wishes to work on those structures. I won't be spending any time on Matrix3/Matrix3d but if you can find a use for them, please be my guest! :-)

anathema's picture

#2

If you have no objections, I'm going to take Matrix4d.cs and adapt it to become Matrix3d. Can I submit a patch of this when done?

the Fiddler's picture

#3

I'll happily add this to trunk, if you also tackle the Matrix3 struct (single-precision version).

anathema's picture

#4

Sure, no problem. Can I commit the changes directly, or do I post them here?

anathema's picture

#5

The code is ready...where do I send it? :-)

AndyKorth's picture

#6

Hi Anathema. I'm working on the matrix classes. I noticed the odd state of Matrix3d.cs and then found this post. If you still have this patch, please let me know and I'll apply it and add it to my repository.

Since it's probably a long one, you can post it on https://gist.github.com/ and link it here. That's probably pretty convenient. Thanks!

anathema's picture

#7

Hi Andy,
I'll be happy to send what I've got along to you :-) It'll have to be in the New Year though, as I'm currently away from home!

AndyKorth's picture

#9

Thanks! Have a great New Year!

Robmaister's picture

#10

I've also got a Matrix3(d) implementation here: https://github.com/GoldBlockGames/OpenTK/blob/master/Source/OpenTK/Math/...

And a Matrix3x4/4x3 implementation that's I'm going to copy from my project to the OpenTK project and push to github very soon. I'm planning on writing an implementation for all of the matrix sizes accepted by OpenGL.

anathema's picture

#11

Ya beat me to it! :-) Yours is - unsurprisingly - pretty much the same as mine. The only difference I can see is that I added an indexer to mine:

        /// <summary>
        /// Gets or sets the value at a specified row and column.
        /// </summary>
        public double this[int rowIndex, int columnIndex] { get; set; }

I've found this to be quite a useful thing to have - could it be added to the OpenTK classes, please?

On a related note, I would like to see this one fixed too. The best solution seems to be to use CultureInfo.CurrentCulture.TextInfo.ListSeparator instead of the comma to separate the values. Are there plans to address this? :-)