Jump to content

Function newb


Mzigaib

Recommended Posts

Newb question!

 

If I go to aliases and variables and create a function like:

 

float test(float x, float y)
{
float result = x+y;
return $result;
}
 
And to test it I go to texport I do like:
 
echo `test(3,5)`
 
I get:
 
Expression error: Undefined variable
 
I was expecting 8, what am I doing wrong?
 
Thanks!
Link to comment
Share on other sites

Thanks Graham!

 

Now I want to create a function for my camera focus that works like a ramp based on distance so I want to get the distance between my camera and the target and divide it with a max distance and then I remap the values later so for that I did this:

 

float focus (vector cam,vector target,float maxdist)
{
vector direction = cam-target;
float dist = length(direction);
float ndist = dist / maxdist;
return ndist;
}
 
I can remap the values later but if I go to textport to test it like this:
 
echo `focus(vector3(1,1,1),vector3(5,5,5),5)`
 
Houdini tells me this:
 
Expression error: Invalid number of arguments for function
 
What am I doing wrong?
 
Thanks again!
Edited by Mzigaib
Link to comment
Share on other sites

[sOLVED]!

 

I made a modification and it worked:

 

float focus (float maxdist,float near,float far)
{
vector cam = vector3(ch("/obj/cam1/tx"),ch("/obj/cam1/ty"),ch("/obj/cam1/tz"));
vector target = vector3(ch("/obj/target/tx"),ch("/obj/target/ty"),ch("/obj/target/tz"));
float dist = distance(cam[0],cam[1],cam[2],target[0],target[1],target[2]);
float ndist = clamp(maxdist/dist,near,far);
float finalfocus = fit01(ndist,near,far);
return finalfocus;
}
 
I hope it helps someone.
 
Cheers!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...