Jump to content
Trilec

Primitive Center Rotate in VEX

Recommended Posts

Thought I'd share a little primitive center rotation snippet, any comments welcome.

Note: Requires connectivity node upstream set to primitive and attrib "class".
 

//Rotate primitive around center and defined axis
	int points[] = primpoints(0, @primnum);
	vector axis = set(0,1,0);      //define user axis
//vector axis = normalize(@N); //if normal axis is required

	float angle = ch('angle');
	matrix3 rotm = ident();
	rotate(rotm, radians(angle), axis);

//get center (requires connectivity node, set primitime and sttrib "class")
	string grp = '\@class='+itoa(i@class);
	vector CenterPivot = getbbox_center(0,grp);
	vector pos;

// move points to origin, rotate, move back
	foreach(int pt; points) {
    	pos = point(0,"P",pt);
    	pos -= CenterPivot;
    	pos *= rotm;
    	pos += CenterPivot;
   		setpointattrib(0,"P",pt,pos, "set");
	}

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi Curt,

once you have defined primitive classes, you could also run this over points:

float amount = radians(chf('angle'));
vector axis = normalize(chv('axis'));

int class = prim(0, 'class', i@primnum);
string grp = '@class==' + itoa(class);
vector pivot = getbbox_center(0, grp);

matrix m_rot = ident();
rotate(m_rot, amount, axis);
vector pos = (v@P - pivot) * m_rot + pivot;

v@P = pos;
v@N *= m_rot;

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks Konstantin ,
For curiosity sake, would this section be executed per/particle, does Houdini optimize for this? (thinking multi threading).

 

int class = prim(0, 'class', i@primnum);
string grp = '@class==' + itoa(class);
vector pivot = getbbox_center(0, grp);

matrix m_rot = ident();
rotate(m_rot, amount, axis);

 

C

Edited by Trilec

Share this post


Link to post
Share on other sites
10 hours ago, Trilec said:

Thanks Konstantin ,
For curiosity sake, would this section be executed per/particle, does Houdini optimize for this? (thinking multi threading).

Exactly. You would need to inspect the performance monitor to make sure it really is more performant, though.

We've already had some cases where code that looks elegant does not perform too well and vice versa.

Unfortunately I could not point you to a resource that goes deep about the inner workings and performance of VEX code. 

Share this post


Link to post
Share on other sites

thanks again, often its "un-optimized meany, can be faster than optimized few".

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

×