Jump to content

Dual @orient Modifications?


Atom

Recommended Posts

Hi All,

I have an attribute wrangle with some vex code that causes particles to face the same alignment the camera is facing. This is so card rendering works better.

The initial alignment code is working but I would like to extend it so my particle cards can be rotated randomly along the z-axis, into the scene. I'm not sure how to break apart the current alignment axis, modify it and put it back together so I get both features, alignment to camera and random z-axis rotation.

Here is the alignment portion that currently works.

string cam = chs("cam");
matrix camX = optransform(cam);
p@orient = quaternion(matrix3(camX));

Here is my attempt to randomize an axis but it is just overriding @orient instead of modifying the previous @orient.

string cam = chs("cam");
matrix camX = optransform(cam);
p@orient = quaternion(matrix3(camX));

vector nvec = {0,0,0};
vector axis = {0,0,1};      // Axis to rotate.
vector tmp_P = {0,0,0};
float rand = 0;
vector4 quat = {0,0,0,1};
vector4 product = {0,0,0,1};

// Randomize rotation.
rand = fit01(random(@ptnum),0,360);
quat = quaternion(radians(rand), nvec);
product = qmultiply({0,0,0,1}, quat);
@orient=product;

How do I mix in a new modification to @orient?

Link to comment
Share on other sites

Thanks for taking a look at my problem. I think your code is almost it, however, I believe your solution reveals a bug in the Houdini Matrix API.

string cam = chs("cam");

matrix3 cam_xform = (matrix3)optransform(cam);

float angle = rand(@ptnum + chf("seed")) * 360;
angle = radians(angle);

vector axis = normalize( point(1, "P", 0) - v@P );
//vector axis = normalize({0,0,0});  // Shouldn't this perform no operation?
rotate(cam_xform, angle, axis);

p@orient = quaternion(cam_xform);

Ideally I want the rotation to occur like a fan spinning. So there should be no wobble along the other axis. The cards needs to face exactly forward.

In this GIF you can see why I might think there is an error in the API. If I pass an axis of {0,0,0} there should be no change. However, as you can see in the animation displayed there is a change. And that change varies based upon the random angle supplied.

Is there any way to lock other axis before issuing a matrix math operation? I thought that is what the supplied axis actually would do but that does not seem to be the case there is a little "play" in the math for some reason...

 

rot_issue.gif

Link to comment
Share on other sites

If I put a transform on the shape side of the copy and move the ROTZ parameter that is the style of rotation I am looking to achieve. Because my final render is going to be instances via Redshift I can't just send copies, it wants point cloud with @orient rotations. That is why am looking for a VEX based solution.

rot_issue.gif

Link to comment
Share on other sites

  • 2 weeks later...

Here are two methods:

// Point wrangle.
// Will orient towards camera axis.

#define PI 3.1415926535897932384

matrix3 r = (matrix3) optransform("/obj/cam1");
vector axis = set(r.zx, r.zy, r.zz);
float angle = 2*PI * rand(@ptnum);
rotate(r, angle, axis);

@orient = quaternion(r);
// Point wrangle.
// Will orient towards camera position.

#define PI 3.1415926535897932384

// Matrix returning version of makebasis procedure.
matrix3 makebasis(vector z, up)
{
    vector x, y;
    makebasis(x, y, z, up);
    return set(x, y, z);
}

vector eye, z, up;
eye = {0,0,0} * optransform("/obj/cam1");
z = normalize(@P - eye);
up = {0,1,0};

matrix3 r = makebasis(z, up);
vector axis = set(r.zx, r.zy, r.zz);
float angle = 2*PI * rand(@ptnum);
rotate(r, angle, axis);

@orient = quaternion(r);

The difference between the methods is that second one is accounting for perspective, which may suit your case better.

camera_facing.gif

 

 

camera_facing.hipnc

 

UP: Somehow, I didn't notice @Juraj's post, which already did the same thing. Does the wobbly problem occur here as well, @Atom?

Edited by f1480187
  • Like 7
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...