Rotate geometry by normal vector

Given points with normals and faces instanced on them.
For only one chosen point I want to extract the rotation in degrees from the normal,
and use it to rotate other geometry.
lets say this cross to point to the instanced face.
any ideas ?

question.3.toe (5.35 KB)

You’ll need to use a “rotation about an arbitrary axis” matrix where your axis is the normal of the point and the angle is rotation amount. The tricky part is that you need to multiply each point of the primitive(the xyz pos) by the matrix which at this moment I can’t think of way to do that on an instance.

I’ve done it number of times but mostly inside of my own GLSL shader or in SOP world. But I’m sure you don’t want to do it to the SOP.

You can emulate an instancing in a vertex shader by using a copy SOP and then creating some custom attributes for your positions, normals, primitive etc… Then you can use the rotate about an arbitrary axis matrix on each point of each primitive. You can also do whatever other transforms you want as well. I found that shader was pretty much equally as fast as instancing GPU wise.

To do all your transforms you’ll need to center the primitive (to origin of the scene) and then move back to it’s previous position after - at least scaling and rotation.

A “Rotate about an Arbitrary Angle” matrix:

```mat4 rotationMatrix(vec3 axis, float angle) { axis = normalize(axis); float s = sin(angle); float c = cos(angle); float oc = 1.0 - c; return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 0.0, 0.0, 0.0, 1.0); }```

hope this helps
Keith

Wow, thanks alot Keith,
but I decided to go more simple.
this is my solution…

Barak.
question.4.toe (6.1 KB)

Nice one. Yeah last night I actually looked at the geo COMP and realized there was a rotate to vector. Perfect…

Keith

I am not totally clear with that,
what are you handling to rotate the whole geometry?
What are the null COMP for?
and why are combinaning n[xyz] and t[xyz] together in the math CHOP?