Jump to content
  • Advertisement
Sign in to follow this  
TheStudent111

Multiplication support in GLM

This topic is 911 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

Why is multiplication supported in GLM. Isn't there no such thing as multiplication in the traditional sense when it comes to vectors as it does not make sense geometrically. I have learned that the dot product is the multiplication equivalent for vectors.

 

For example:

    // Vector Multiplication
    glm::vec3 e = glm::vec3(2.0f, 2.0f, 2.0f);
    glm::vec3 f = glm::vec3(3.0f, 3.0f, 3.0f);

    glm::vec3 ef = e * f;

 

Since it is supported I am kind of curious as to what it is used for in terms of graphics or physics. Geometrically what does it look like, and what is the operation used for?

Edited by TheStudent111

Share this post


Link to post
Share on other sites
Advertisement

It doesn't look like anything geometrically, it's just component-wise multiplication. One typical use is in blending, where you might multiply colors together channel-wise. Not all vec3's are geometric, sometimes they are (ab?)used as a bag of three related values.

Share this post


Link to post
Share on other sites

After some coffee smile.png I have seen that you are NOT talking about the dot product (which I assumed and talk about below - I will still leave this for others), but about the component-wise multiplication. I don't think that one has a name in math; I don't know of any major use in math either. It has no real significance (besides some programming tricks) nor geometric meaning that I know of. You are correct in thinking that the dot product is closer to usual multiplication than component-wise multiplication.

 

This is the dot/scalar product: <a,b> = a_1 * b_1 + a_2 * b_2 + a_3 * b_3, where a = (a_1, a_2, a_3) and b = (b_1, b_2, b_3).

 

If you take normalized vectors, i.e. vectors of length 1, and compute the dot product, it gives you a sense of how parallel they are: the dot product gives you the cosine of the angle between two vectors (|a| = length of a):

 

<a,b> = |a| * |b| * cos(angle(a,b)).

 

Most of the time mathematicians write a * b as a multiplication and mean <a,b>; usually it is clear from context what operation should be performed.

 

In math the dot product is often used to split a vector a into components parallel to a vector b (dot product = 1) and orthogonal to b (dot product = 0) to compute projections of vectors onto lines or planes. This is also the reason the dot product can be used in lighting computations: Somewhere in there it contains the angle between the light ray and the surface normal, which gives you the direction of the reflected light ray.

 

To summarize: dot(a,b) = how parallel are a and b?, component-wise multiplication a * b is not much more than scaling each component of a individually. The notation a * b for component-wise multiplication is a mostly 3d graphics/programming thing. I believe it stems from SSE and similar instruction sets.

Share this post


Link to post
Share on other sites

Thanks guys for the responses. OK, so component based multiplication is used in graphics tricks such as blending.

 

Does the same logic apply to adding a vector with a scalar. I know that formally, in linear algebra you cannot add a scalar with a vector as they are different dimensions.

 

But while I was reading something on graphics I stumbled onto this:

http://www.learnopengl.com/#!Getting-started/Transformations

 

scroll onto the heading labeled scalar vector operations.

The author seemed to have written that it is possible to add a scalar quantity with a vector. Is this also used as tricks for graphics. Like component wise multiplication is used for blending but does not mean anything geometrically.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!