Dynamically rotate geometry via VEX

   152   3   1
User Avatar
Member
274 posts
Joined: June 2016
Offline
I need to dynamically rotate geometry in VEX (the geometry is constantly rotating)  and change the speed of rotation via a float parameter.

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

https://forums.odforce.net/topic/42933-solved-vex-rotate-vector-by-degrees-or-matrix/ [forums.odforce.net]

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 - Oct. 17, 2019 20:52:48
User Avatar
Member
85 posts
Joined: July 2015
Offline
// create matrix
matrix3 m = ident();

// create parameters
float speed = ch('speed');
float frame = @Frame;
vector rotationaxis = chv("rotationaxis");

// rotate matrix
float angle = radians*frame*speed;
 
rotate(m, angle, rotationaxis);
 
// rotate geo with matrix
@P *= m;
Manuel Köster - FX @ Animal Logic

shadesoforange.de
User Avatar
Member
274 posts
Joined: June 2016
Offline
Thanks Manuel!

So radians is undefined but even when I define it I get an oscillating scale effect.


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 - Oct. 17, 2019 22:02:23
User Avatar
Member
85 posts
Joined: July 2015
Offline
Whoops,
should've double checked my code. My bad.

// create matrix
matrix3 m = ident();

// create parameters
float speed = ch('speed');
float frame = @Frame;
vector rotationaxis = chv("rotationaxis");

// rotate matrix
float angle = radians(frame*speed);
 
rotate(m, angle, rotationaxis);

// rotate geo with matrix
@P *= m;


art3mis
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.

That's because you specified a normal before that wrangle. You are modifying the position of the points, but not the normal. You can either recalculate the normals after the wrangle, or you switch to using the matrix method in the wrangle and modify P and N there. Like this:

// create matrix
matrix3 m = ident();

// create parameters
float speed = ch('speed');
float frame = @Frame;
vector rotationaxis = chv("rotationaxis");

// rotate matrix
float angle = radians(frame*speed);
 
rotate(m, angle, rotationaxis);
 
// rotate position and normal with matrix
@P *= m;
@N *= m;
Manuel Köster - FX @ Animal Logic

shadesoforange.de
  • Quick Links