Jump to content
art3mis

Dynamically rotate geometry via VEX

Recommended Posts

So as a starting point am using VEX code from this thread but so far not working.

 

I need to dynamically rotate geometry in VEX (the geometry is constantly rotating)  and change the speed of rotation via a float parameter.

I also tried this fairly simple code from cgwiki which gives me a constant rotation but am unable to dynamically alter the rate of rotation

matrix3 mat = ident();
float angle = atan(@P.x, @P.y);
float r = length(set(@P.x, @P.y));//*chf('amount');
 
@P.x = sin(@Time+angle)*r ;
@P.y = cos(@Time+angle)*r;

 

 

 

Edited by art3mis

Share this post


Link to post
Share on other sites

So managed to get this working but one curious glitch however is that the in the viewport it appears the lighting is 'baked'. When my geometry is rotating it appears as if the light is rotating with it.  If I try and manually alter the rotation in the Transform this doesn't happen.

matrix3 mat = ident();
float angle = atan(@P.x, @P.y);
float r = length(set(@P.x, @P.y));//*chf('amount');
 
@P.x = sin((@Time*chf('amount'))+angle)*r ;
@P.y = cos((@Time*chf('amount'))+angle)*r;

 

Edited by art3mis

Share this post


Link to post
Share on other sites
matrix3 m = ident();
vector axis = set(0,1,0);
float angle = radians(chf("angle")*360);
rotate(m,angle,axis);
@P *= m;
@N *= m;

When you rotate the @P you also need to rotate the @N, or else it will look like the light is baked.

Share this post


Link to post
Share on other sites

Thanks!! I figured something to do with normals. But in my case would it simply be adding?

@N=@P;

Another thing I was wondering is if it is possible to determine the current RPM value using my above VEX code?

Edited by art3mis

Share this post


Link to post
Share on other sites

Setting N to P would only be a good idea if you're rotating a unit sphere. Otherwise your normals aren't going to be normalized, and may possibly make no sense when rendering or displaying.

Thomas is correct in that you should update the normals as well as P... multiplying by the same matrix (and possibly normalizing afterwards to be safe) is a good choice. The Deformation Wrangle SOP will update normals and other vector attributes automatically, if you want to give that node a shot... it requires slightly different syntax.

Share this post


Link to post
Share on other sites

Thanks Henry. So a little more complicated than expected. So will try to integrate @Time into Thomas example to make dynamic.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×