## 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();

//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");
}```

• 1

##### 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;```

• 1

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

## Create an account

Register a new account