Dotting a vector and a matrix

This topic is 3496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am uncertain what happens in my vertex shader file when I write this line of code: float dotProduct = dot( vector, matrix ); I assume it treats the vector as a row vector, which means the matrix's column must match the vector in terms of elements. I am uncertain which column of the matrix is dotted against the vector. Thank you in advance, Kevin

Share on other sites
Which shader language are using? That's not legal in HLSL...I'm not sure what happens in GLSL or Cg.

Share on other sites
you can explicitly select what part of the matrix you want to 'dot' :)

float dotProduct = dot( vector, matrix[0] );

or an 4x4 would be like
float4 dotProduct = float4( dot( vector, matrix[0]),                            dot( vector, matrix[1]),                            dot( vector, matrix[2]),                             dot( vector, matrix[3]));

Share on other sites
This is simply a matrix-vector-multiplication, but "the other way around" than usual when you're using DX. It is equivalent to mul(matrix, vector) or mul(vector, transpose(matrix)). It is useful for instance when matrix is orthonormal (i.e. all rows and columns are unit length and perpendicular to each other, e.g. a rotation matrix). In that case, the transpose of the matrix is the inverse, so mul(matrix, vector) = mul(vector, inverse(matrix)).

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×