Page 1 of 1 [ 7 posts ]

#### Fart Annoyed Question( about scaling vectors)

 Print view Previous topic | Next topic

#### Fart Annoyed Question( about scaling vectors)

Author Message
 Post subject: Fart Annoyed Question( about scaling vectors)  Posted: September 5th, 2017, 4:03 pm

Joined: September 1st, 2017, 10:46 pm
Posts: 15
Location: Mississippi, USA
In the beginners tutorial 20b, when chili is setting up the grid of bricks, he says to setup the grid rectangle using:
Code:
RectF( topleft + Vec2( x * brickWidth, y * brickHeight ) );

My Question is would it be wrong to make brickWidth and brickHeight a vector to scale x, y?
like this:
Code:
RectF( topleft + Vec2( x, y ) * Vec2( brickWidth, brickHeight ) );

Should i use vectors like that? Is it bad form? or does it affect performance?

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 6th, 2017, 12:12 am

Joined: December 31st, 2011, 4:53 pm
Posts: 3514
Location: Japan
In general, vector multiplication means the dot product (x1 * x2 + y1 * y2). There is also the cross product that is sometimes used. What you are doing there is called the Hadamard product, and it is seldom used in linear algebra, so I would not define my operator* to mean that.

In 3D Fundamentals I have a function GetHadamard though, because it is useful for lighting / color calculations.

_________________
Chili

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 6th, 2017, 4:49 am

Joined: February 28th, 2013, 3:23 am
Posts: 2909
Location: Oklahoma, United States
Took me awhile to see it, but to multiply two vectors in the manner you want, you would actually want to turn the second vector into a matrix with the X component in the top left of the matrix and the Y component in the bottom right of the matrix. In this way you end up doing the dot product on each column or row of the matrix and the result of each ends up being the result for the X and Y.

Code:
Vec2 a( 1, 3 );
Vec2 b( 4, 5 );
Mat2x2 c
{
b.x,    0.f,
0.f,   b.y
};

Vec2 result;
result.x = ( a.x * c.values[0][0] ) + ( a.y * c.values[1][0] );
result.y = ( a.x * c.values[0][1] ) + ( a.y * c.values[1][1] );

// Would be the same as
Vec2 result = Vec2(
DotProduct( a, { c.values[0][0], c.values[1][0] },
DotProduct( a, { c.values[0][1], c.values[1][1] }
);

// Or, if you have one of the chili frameworks that has his _Vec2 template class
Vec2 result = Vec2(
a * { c[0][0], c[1][0] },
a * { c[0][1], c[1][1] }
);
// Since he overloads his operator*(const _Vec2 &) function to be the dot product operation.

In this example, the Mat2x2 would be a class of floats in a 2D array
Code:
class Mat2x2
{
public:
Mat2x2( float V00, float V01, float V10, float V11 );

float values[2][2];
};

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 6th, 2017, 9:26 am

Joined: December 31st, 2011, 4:53 pm
Posts: 3514
Location: Japan
As part of a larger affine transformation matrix multiplication would be a decent choice, but for this application it's a loser. Added complexity AND lower performance.

In hlsl for example v1 * v2 is per component product (it's used a lot for color / lighting bullshits), where as dot( v1,v2 ) and mul( v1,v2 ) give the dot product.

_________________
Chili

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 6th, 2017, 2:02 pm

Joined: February 28th, 2013, 3:23 am
Posts: 2909
Location: Oklahoma, United States
I agree it's a bad fit for this purpose, was simply making an observation or stating a realization.

Did not realize mul(vector, vector) returned dot product, guess I"m glad I never used it for multiplying vectors when I need per component multiplication. I guess, I haven't checked this page out before.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 6th, 2017, 2:36 pm

Joined: December 31st, 2011, 4:53 pm
Posts: 3514
Location: Japan
This is the page where i got that info (in doing a little bit of fact checking before making my post).

https://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx

_________________
Chili

 Post subject: Re: Fart Annoyed Question( about scaling vectors)  Posted: September 7th, 2017, 3:04 am

Joined: February 28th, 2013, 3:23 am
Posts: 2909
Location: Oklahoma, United States
Holy crap, had to read the entire page to find it so blatant about what mul does lol. Thanks for the link chili.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Display posts from previous:  Sort by

 Page 1 of 1 [ 7 posts ]

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: