Jump to content
noumiere

Orient of a point in a line

Recommended Posts

I have a snippet that scatters points on a grid and for each point, creates a unit vector Line comprised of two points that point at an object (in this case, a point).

Everything works fine until I add the 'orient' attribute to the system. For some reason, it treats the rotation of all points as one and the axis is at the scene center.

What I'm trying to do is have each point have it's own local rotation so that if I copy a geo to these points, they will aim at that object instead of staying upright.

I've attached the scene file

Thanks!

line_Orient_v03.hip

Share this post


Link to post
Share on other sites

Hi noumiere,

What I would do is create an orientation matrix(I'd prefer vops). If you use the vector you created pointing at your target: 
vector p = point(1, "P", 0);
v@N = normalize(p - @P);
I added it to the normal in this case.

Take the cross product of an up vector {0,1,0} and @N. And normalize it. That's our X vector.
Now do another cross product of our normal and our newly created X vector. Normalize it. That's our Z vector.
The normalized @N is our Y vector.

Add these into a "vector to matrix3". Take that result into a "matrix3 to Quaternion" and that result is our orientation. If you're using vops(like me); bind export "orient" as a vector4 attribute. Your cubes or lines should be pointing at the target while having control of their local orientation. Your line node direction might have to be changed to -1, depending on what you're after.

I can upload a hipfile later tonight if needed.

Share this post


Link to post
Share on other sites

Thanks a lot for the reply, Joachim. I have tried to implement what you said in a Point Vop and have attached it to the file. For some reason , the second point in the line does not seem to be oriented.

Do you have any idea why? Could I be that my VOPs is incorrect?

Thanks

line_Orient_v04.hip

Edited by noumiere
spelling

Share this post


Link to post
Share on other sites

Hi! Vops looks correct, the problem is that the target point you're creating doesn't really inherit the orientation. You could create the orientation again and point it back to the origin point, but that seems unnecessary. What I would do is change your approach to creating that second point. Easiest way I can think of is to not create a new point at all. Instead move the origin point along the normal @P += @N*chf("distance_mult");. And merge that moved point back with the original. You can use an "add" node to create the line between the points if necessary. And if you resample all points should point the same direction.

Share this post


Link to post
Share on other sites

Hey Joachim, your explanation made a lot of sense! I implemented your suggestions and removed the second point, instead I merged in the initial point. The issue arises with the Normals for the merged point, or maybe I'm not sure of where in the stream I should resample?

 

line_Orient_Vector.hip

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

×