What does +- mean in VEX?

   1076   5   1
User Avatar
Member
226 posts
Joined: 7月 2013
Offline
I saw a tutorial where the position of scattered copies using Copy to Points node are raised in the Y axis with this expression:
v@scale = rand(@ptnum);
v@P.y += v@scale.y/2;

It uses a randomised scale on an object copied to points on a flat Grid and then moves them up by half their height so they sit flush on the grid. What I don't understand is why the second line uses += rather than =

Can someone explain? The Houdini documentation mentions "Variable assignment" operators:

= += -= *= /= %= &= |= ^=
User Avatar
Member
8532 posts
Joined: 7月 2007
Offline
a += b;
Is a short form of
a = a + b;

similarly all the other operations, -,*,/,%,&,|,^
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
4495 posts
Joined: 2月 2012
Online
It's a common syntax in C style languages, now even languages like Python have the same syntax.

+= can be translated as "add whatever is to the right of the += to the variable on the left of the +=".
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
7 posts
Joined: 4月 2023
Offline
Hello this is Gulshan Negi
Well, In my recent search about it I found below:

-=: Subtraction and assignment
*=: Multiplication and assignment
/=: Division and assignment
%=: Modulus and assignment
&=: Bitwise AND and assignment
|=: Bitwise OR and assignment
^=: Bitwise XOR and assignment

Thanks
User Avatar
Member
226 posts
Joined: 7月 2013
Offline
Thanks for your answers.

After experimenting I found that if you just use: v@P.y = v@scale.y/2;

...then the geometry will flatten out on the Y axis like a plane rather than retain its shape. So, presumably this is working on all points of the geo as VEX tends to do, telling Houdini to place them all at the same Y position, whereas += moves each point up by the same amount, thus retaining the shape of the geo.
User Avatar
Member
226 posts
Joined: 7月 2013
Offline
Thanks Gulshan
  • Quick Links