computations for variables question?

   1696   4   1
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
Hi, a very newbie question I am sure.
But while defining a variable I wanted to do a simple computation and then I found out as the manual says:

You cannot do any computation on the right side of the equals sign (. The following are syntax errors:

float @mass = 1 / area; // Error
vector @up = set(0, 1, 0); // Error

So my question is How then you DO computations? I am a bit confused:
Basically I ended up doing this:

f@grad = @ptnum;
@grad /= @numpt-1;

instead of what could have simply been written like this:

f@grad = @ptnum/(@numpt-1);

This is a very simple example but what if I need a very complex computation, what do I use then?

https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
float mass = 1 / area;
@mass = mass;
Edited by animatrix_ - Aug. 25, 2016 12:51:43
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
280 posts
Joined: Dec. 2015
Offline
Ok,
I think I answer my own question but please correct me if I am wrong.
The problem with the above code was that ptnum and numpt are integers and will not translate properly to the float value I included. The following however do just fine:

f@grad = float (@ptnum)/ (@numpt-1);



Edited by Nicolas Heluani - Aug. 31, 2016 10:03:37
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
pusat
float mass = 1 / area;
@mass = mass;


Thanks pusat….I know is simple but it was confusing the fact I couldn't put the computation in the same line (I am a bit OCD).
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
The form

float @mass = 1;

is a special case in vex wrangling that has to do with the option “Enforce Prototypes”. This forces you to declare each and every export variable to a constant value or not at all and it initializes to 0. Enforce Prototypes is all about protecting you from typos and mis-declaring exports and ending up with needless attributes on the geometry in complex wrangle code.

As you found out you can do operations on the right side if you use the simplified variable initialization form:

f@mass = float (@ptnum)/(float (@numpt) - 1);

Dividing two integers gives you an integer, never a float. Gets everyone once in a while. You have to cast one integer to a float. I usually cast both to be clear to others reading the code later on. Even further declare the known variables with their type, even though it is not necessary.

f@mass = float (i@ptnum)/(float (i@numpt) - 1);
There's at least one school like the old school!
  • Quick Links