Jump to content

How to Calculate @w to Aim RBD Object


thompson.alt

Recommended Posts

As I'm just starting to understand quaternions and orientation in Houdini, I'm not sure how complicated this is to achieve. I could be completely over thinking it.

Ultimately I would like to create a force in dops to rotate the packed object to its current direction of motion, or it's velocity. Modifying @w seems to be the best way to do that.

For a first step, I'm trying to make a setup that takes a rbd packed object and rotate it back to it's original orientation. While it technically does that, it doesn't do it logically. It flips around its axis in bizarre ways. As I understand, it's behaving erratically because it's trying to rotate around all of its axes at the same time.

This is the code I'm using in a pop wrangle node:

vector  qToE(vector4 q_value){
    float   q_0 = q_value.w ; 
    float   q_1 = q_value.x ; 
    float   q_2 = q_value.y ; 
    float   q_3 = q_value.z ; 
    vector  out = {0,0,0} ; 
            out.x = atan2(2*(q_0*q_1+q_2*q_3), (1-2*(q_1*q_1+q_2*q_2))) ; 
            out.y = asin(2*(q_0*q_2-q_3*q_1)) ;
            out.z = atan2(2*(q_0*q_3+q_1*q_2), (1-2*(q_2*q_2+q_3*q_3))) ;
    return out ; 
}


v@euler = qToE(@orient);
@w = -v@euler*1*{1,1,1};

This is where I got the quaternion to euler function:

I've attached my houdini file to this post. If anyone has any tips, I'd be very happy to hear them!

 

Thanks!

orient_rotate_v01.hip

Link to comment
Share on other sites

I've made some progress since yesterday. Here is the code I'm using now:

vector4 first_orient = @orient;
vector4 second_orient = {0,0,0,1};

matrix3 transform = lookat(@v, 0, {0,1,0});
//second_orient = quaternion(transform);

// Get the difference between the two quaternions
// https://stackoverflow.com/questions/1755631/difference-between-two-quaternions
vector4 transition = qmultiply(second_orient, qinvert(first_orient));

// Convert to Angle-Axis
// http://www.tokeru.com/cgwiki/index.php?title=JoyOfVex17#Convert_back_to_matrix
vector angle_axis = qconvert(transition);

//@orient = transition;
//@N = angle_axis;

@w = angle_axis*chf("strength");

For now they're trying to orient themselves with their velocity. This is working quite a bit better, but I think there's still some funny flipping going on.

Link to comment
Share on other sites

18 hours ago, anim said:

not sure if you are taking this as a VEX exercise, but if not, you can use POP Look At to easily do this

 

Thanks Tomas! I had actually tried that earlier, but it wasn't working for packed rbd objects. It seems the problem was that they don't respond to @torque like particles do.

The solution I found was to convert @torque to @w after the fact. Does anyone know if there is a rotational force like @torque that work on rbd objects?

Now I can dig into how POP Look At and see how the math works too.

 

Thanks again!

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