## 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 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 on other sites
```matrix3 m = ident();
vector axis = set(0,1,0);
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 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 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 on other sites

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

## Create an account

Register a new account