Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Matrix multiplcation broken?  (Read 3890 times)
Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« on: June 21, 2006, 08:42:34 PM »

In the latest MTV3D65, if I have the following :

Code:
A 3D Vector =   {1, 1, 1}

A 3D Matrix = { {1, 0, 0, 0},
                {0, 1, 0, 0},
                {0, 0, 1, 0},
                {0, 0, 0, 0} }


And I mutiply the both using the * overload (matrix3d * vector3d = vector3d)

I get {0, 0, 0} as the resulting vector, whereas it should be {1, 1, 1} !

Also, since TV_3DMATRIX is in fact 4D, why doesn't it accept multiplication with a 4D vector (resulting in another 4D vector)?
Logged

Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #1 on: June 26, 2006, 09:47:35 PM »

Went unseen, so I'll submit a bug to the bugtracker.
Logged

Waterman
Moderator
Community Member
*****
Posts: 1159


« Reply #2 on: June 27, 2006, 07:23:36 AM »

Afaik you should get a matrix as result when multiplying a matrix with a vector, not a vector. In addition, i am pretty sure that the lenght of the vector (3) must appear in the dimensions of the matrix, otherwise there could be problems...
Logged

Things should be described as simply as possible - but not simpler [A. Einstein]
Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #3 on: June 27, 2006, 08:31:03 AM »

Quote
Afaik you should get a matrix as result when multiplying a matrix with a vector, not a vector.

If DirectX is column-major, that would be the case. But I'm pretty positive that it's row-major.

Quote
In addition, i am pretty sure that the lenght of the vector (3) must appear in the dimensions of the matrix, otherwise there could be problems...

I know, but TV_3DMATRIX won't let me do otherwise Tongue
There's only one kind of matrix (4x4), and the only thing I'm able to multiply it with is a 3D vector.
Anyway, whatever TV3D assumes (full 0's for missing column or full 1's), shouldn't have an incident on the final result in my case.
Logged

SylvainTV
Administrator
Community Member
*****
Posts: 4971


WWW
« Reply #4 on: June 27, 2006, 11:09:43 AM »

OK going to check this.

Also a simple reminder for new people that might check this thread :
the operators overloading doesn't work in VB.NET 2003 (.NET 1.1)[/code]
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
SylvainTV
Administrator
Community Member
*****
Posts: 4971


WWW
« Reply #5 on: June 28, 2006, 05:31:02 PM »

I tried :

Code:
private void Form1_Load(object sender, System.EventArgs e)
{
TVMathLibrary ml = new TVMathLibrary();
TV_3DMATRIX mat = new TV_3DMATRIX();
ml.TVMatrixIdentity(ref mat);
TV_3DVECTOR vec = new TV_3DVECTOR(1,1,1);
TV_3DVECTOR vec2 = new TV_3DVECTOR(0,0,0);
vec2 = vec * mat;
Console.WriteLine(vec2.x + " " + vec2.y + " " + vec2.z);
}


It worked.

An Identity matrix is
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

I think the problem is that you have put 0 in the m44. with 1 it works. If you do the computation manually, you will find the same I think.

When you multiply a vector3 by a matrix, the engine assumes (x,y,z,1)
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #6 on: June 28, 2006, 06:23:47 PM »

My point was that if m44 is 0, the whole returned vector is nullified, and it should not. If it assumes (x, y, z, 1), then the multiplication is :



Sorry to be so insistant... but it is a bug.

Edit : Just read about D3D matrix conventions, and according to this post, row vectors and row-major operations are used. So my operation is right, and it should return (1, 1, 1, 0).
Logged

SylvainTV
Administrator
Community Member
*****
Posts: 4971


WWW
« Reply #7 on: June 28, 2006, 06:42:53 PM »

Yea sorry, well it's not really a bug , just a hidden dx feature . I just looked at the dxsdk documentation to see the function i use for the multiplication...

D3DXVec3TransformCoord
Transforms a 3D vector by a given matrix, projecting the result back into w = 1.

I think the projection the result back into w = 1 must use the w line somewhere...

Thanks for telling me that, I didn't know the projecting part :p

So now the question is, should I leave it like that (using TVVec3TransformCoord) or change it to a manual computation ?
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #8 on: June 28, 2006, 06:46:23 PM »

Aah, there's the reason. Cheesy

Well since the overloaded operation is multiplication, you definitely should change re-do it manually. There can be an operation in TVMathLib for D3DXVec3TransformCoord projection with an appropriate name, but matrix multiplication is matrix multiplication...
Logged

newborn
Customers
Community Member
*****
Posts: 2451


WWW
« Reply #9 on: June 28, 2006, 10:26:03 PM »

quick question : other than looking cool and knowledgable, what is the end use of all this?
Logged

Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #10 on: June 28, 2006, 10:47:36 PM »

This for one thing uses matrices. And I always wondered why the m44 cell needed to be = 1.
There are many uses for matrix multiplication... mostly in shaders, where you have to do everything, because TV3D takes care of most of the matrix stuff behind-the-scenes.
Logged

billythekid
Community Member
*
Posts: 814


« Reply #11 on: June 28, 2006, 11:54:44 PM »

newborn - Computer graphics is all about linear algebra aka matrix math.
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4971


WWW
« Reply #12 on: July 02, 2006, 10:11:24 AM »

OK fixed. Now it uses the manual way.
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks