Jump to content
  • Advertisement
Sign in to follow this  
dragon32078

Dotting a vector and a matrix

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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)).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!