Jump to content

Primitive Center Rotate in VEX


Trilec

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
Link to comment
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 2
Link to comment
Share on other sites

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
Link to comment
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. 

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