vector to degrees

   7825   9   0
User Avatar
Member
41 posts
Joined: July 2014
Offline
I would like to add a new parameter to the knife node. Let's call it rotation. It would be the same as direction parameter (which is a vector) but it would be displayed in rotation degrees. So vector (1,0,0) would be something like (90,0,0).
And also if I would change values in one parameter (for example direction) it would update the information in the second parameter (rotation). So I could use whichever one I want.
Something like this. Any way to do it?


Another option would be to have a set of two buttons - one would switch the display of direction values to vector units and the other one to degrees. Point is to be able to choose between these two units.
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
For expressions I'm accumstomed to using python.

So for this to work, set your script to Python.

Then you can use the function
degrees(x)
where x is the degrees you want.

Now, if what your wanting to do is what I think it is, remember that to get that degree rotation you want, the direction parameter needs to have a ‘paired’ value with one of the other direction paramters to get the degree rotation you want.


So for instance try pairing the x and y direction paramters. For y set it to any value between degrees(0) and degrees(45). Now do the same for the x direction paramter, matching the corresponding values for y.

Now to continue with y more than the value of 45, you have to change x differently. So if y is degrees(60) you have to set x to degrees(30).

See what's happening? over 45 degrees, in this case for y = 60 is 15 more than 45…so x starts to go in the opposite direction the same amount of degrees from 45; Hence 30. So this way, if y is the primary working direction parameter you can get the ‘continuous’ rotation from 0-90 degrees, so long as x has the ‘appropriate’ corresponding value.

You'll have to play around with these pairings to see how it's working together, then you should be able to write out some expressions that give you what you want.
Edited by BabaJ - March 5, 2017 18:37:51
User Avatar
Member
8531 posts
Joined: July 2007
Offline
let's say your Rotation parm tuple is named r
then put these 3 python expressions in each of the Direction parms
dirx:
euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[0]
diry:
euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[1]
dirz:
euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[2]
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
Thanks for showing a better way using a function that deals with matrices.

I'd probably benefit from taking a time out from Houdini and study matrix math a bit so I can spot times like with this posts example of when to use such functions.

Vex has some similar matrix functions I haven't touched yet either.
User Avatar
Member
41 posts
Joined: July 2014
Offline
Thank you guys for your response.

tamte
Thank you but I am clearly doing something wrong. My Houdini freezes when I add the second chunk of code and change expression language to python. Can you please debug with me?

1. Through the edit parameter interface I add a new parameter to the knife node - direction vector (I also tried duplicating the “Direction” parameter)
2. I change the name to “r” and change the label to “Rotation”
3. Click apply and accept
4. I copy and paste the first chunk of your code into the first field and press enter.
5. Right click -> expression -> change language to python
6. Copy and paste the second chunk of your code into the second field and press enter.
7. Right click -> expression -> change language to python
8. Houdini freezes

User Avatar
Member
8531 posts
Joined: July 2007
Offline
put the expressions to your Direction parms, not rotation parms
you will use Rotation to enter your angles
now you are just creating infinite dependency of r to itself
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
41 posts
Joined: July 2014
Offline
Awesome, it works now. Thank you.
One more question - the connection to the handle is broken. Which is probably logical, because as you stated the “Rotation” parameters are driving the Direction parameters which are connected to the handle parameters.

Is it possible to have the handle connected to the “Rotation” parameters?
So whenever I move the handle it updates the “Rotation” parameters and whenever I change the “Rotation” parameters it updates the handle as well?
User Avatar
Member
8531 posts
Joined: July 2007
Offline
sure, just wrap it up into an asset and you can have custom handle

Attachments:
ts_custom_knifesop.hipnc (61.9 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
41 posts
Joined: July 2014
Offline
Works fabulous! Thank you.
User Avatar
Member
33 posts
Joined: Sept. 2014
Offline
hi tamte, im trying to make the same but different way, from vector to degrees, i need to transfer my Normal vector to Rotation on Obj context, i tried everything and searched in vector3 and matrix field in Help houdini and nothing works.

something like this i tried

euler = hou.node(“/obj/box”).parmTuple(“r”).eval()
normal = hou.Vector3(hou.node(“/obj/point/hhh”).parmTuple(“vector”).eval()).normalized()
dir = hou.Vector3((0,1,0))*hou.hmath.buildRotate(euler)

print hou.hmath.buildRotate(normal).explode()
Edited by Konstantin Kovalenko - July 9, 2019 05:13:59
  • Quick Links