Jump to content

static Variables !


Recommended Posts

hi

i have simple question .

i create a box and connect transform sop to it.i set tz (translate Z) channel to $FF.

so when i play animation , the box should go forward.

i created float parameter which it's name is ("Turn Direction") for transform node.

now i want something like that : when i play animation , box move forward and if i set "Turn Direction" like below plan , rotation of transform ch("ry") change and the box turn in other direction .

Plan :

if :

Turn Direction == 1 , add 0.1 to ry in each frame

if :

Turn Direction == 0 , ry not change

if :

Turn Direction == -1 , add -0.1 to ry in each frame

in c++ i can use below code for this purpose , but i thing that Houdini don't have static variables !

static float RotateY = 0 ;

float TurnDirection = 0; // or 1 or -1

if (TurnDirection == 1 )

{

RotateY += 0.1 ; // or RotateY = RotateY + 0.1 ;

}

else if (TurnDirection == -1 )

{

RotateY -= 0.1 ; // or RotateY = RotateY - 0.1 ;

}

i attach my project file and i hope that somebody can help me :)

thanks

Box.hip

Link to comment
Share on other sites

Hi mate, see attached for centered pivot (using "centroid"); I also reverted the rotation order back to default and then it worked.

You can use python to make the rotation logic you want; I'm not familiar enough with Python in Houdini to add that in, but reading the documentation or watching the videos on the SideFX website about it should help you do it.

Box_centered1.hipnc

Link to comment
Share on other sites

If you want to add or subtract .1 to each frame it's best to use a SOP Solver.

Have a look at the file that I attached, I also included a python script in there to create the behavior lookup that you wanted.

File should be pretty clear, you're welcome to ask questions though :)

cheers,

Manuel

SOP_Solver_Python_Rotation.hipnc

Link to comment
Share on other sites

And here's another way:

Create some sort of control like a toggle - in my example it's either 0 or 1.

Animate it.

Fetch the control into chops and convert it to a -1 to 1 value.

Use the areaCHOP to integrate the value.

Optionally multiply it with a multiplier.

Grab the result and stuff it into the ry parameter of a transform.

Obviously my example doesn't cover all three states - it's pretty extensible though.

SOP solvers and python stuff are probably somewhat more flexible and in vogue.

You most likely want to read up on the concepts behind Houdini's SOP context.

It's kind of stateless, means Frame X doesn't remember what Frame (X-1) has done to the geometry.

Link to comment
Share on other sites

If you want to add or subtract .1 to each frame it's best to use a SOP Solver.

Have a look at the file that I attached, I also included a python script in there to create the behavior lookup that you wanted.

File should be pretty clear, you're welcome to ask questions though :)

cheers,

Manuel

Thanks for that Manuel, I could certainly use a look at some more python being used inside Houdini too :)

Just to be clarify: you used a SOP solver inside of DOPs because the SOPs context evaluates from scratch each frame without remembering the state of the previous frame, whereas DOPs does?

Edited by ryew
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...