Jump to content

Turn Point Pos/n/up Into Matrix


andrewlowell

Recommended Posts

Ok I'm still in the process of learning all about matrix-math and the python not-documented or not-implemented isn't really helping things.

I'm trying to reproduce the functionality of the copy-sop, but on object level, with copies of actual nodes/objects. Everything is working fine but I want to do more than just position, I'd like to use the normals/up as well instead of just setting positions.

So, my question is how I can turn the point position, N, and up into a hou.matrix4

Once I have the matrix 4 I think it should be an easy task of assigning that transform matrix to the object transform.

Link to comment
Share on other sites

So, my question is how I can turn the point position, N, and up into a hou.matrix4

I guess the somewhat "standard"-ish method (for an "abc" frame with "a" aligned to the normal) would be:

up = normalize(UP)
a  = normalize(N)
b  = normalize(up - dot(up,a)*a)
c  = cross(a,b)

This frame will flip whenever the normal is identical, or directly opposite to the up vector... no way around it that I know of.

Another method avoids the flipping, but replaces it with a constantly (but smoothly) varying frame. It also doesn't use the up vector as it derives its own perpendicular to N:

a  = normalize(N)
b  = normalize(vector3(a.z-a.y,a.x-a.z,a.y-a.x))
c  = cross(a,b)

To put these in the form of a matrix (assuming row vectors, which I think is true throughout Houdini -- i.e: Hom, VEX, hscript, etc):

// Here, p[x,y,z] stands for the point's position (i.e: translation)
Matrix4 M = { a.x, a.y, a.z, 0,
			  b.x, b.y, b.z, 0,
			  c.x, c.y, c.z, 0,
			  p.x, p.y, p.z, 1  }

All of the above is in pseudo-code, but hopefully clear enough that you can translate it to "hom-speak" without much trouble.

HTH.

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