Jump to content

lookat Vex function


AntoineSfx

Recommended Posts

https://www.sidefx.com/docs/houdini/vex/functions/lookat.html

Computes a rotation matrix or angles to orient the z-axis along the vector (to-from) under the transformation.

matrix3  lookat(vector from, vector to)

matrix3  lookat(vector from, vector to, float roll)

matrix3  lookat(vector from, vector to, vector up)

 

Can you explain me how to use this function to have a line along the z axis, anywhere is space,  point to another point in space ?
I don't understand what the from and to vector are.

Edited by AntoineSfx
Link to comment
Share on other sites

Hi Antoine, the  lookat() function is mainly there to make pigheads stare at spheres. But it might also work on lines ; )

image.png.1f00ee71ab06e04f320fef823814208c.png

vector pos_target = point(1, 'P', 0);
vector pos_geo = getbbox_center(0);
matrix3 rot = lookat(pos_geo, pos_target);

v@P -= pos_geo;
v@P *= rot;
v@P += pos_geo;

 

lookat.hipnc

  • Like 4
Link to comment
Share on other sites

3 hours ago, konstantin magnus said:

Hi Antoine, the  lookat() function is mainly there to make pigheads stare at spheres. But it might also work on lines ; )

image.png.1f00ee71ab06e04f320fef823814208c.png


vector pos_target = point(1, 'P', 0);
vector pos_geo = getbbox_center(0);
matrix3 rot = lookat(pos_geo, pos_target);

v@P -= pos_geo;
v@P *= rot;
v@P += pos_geo;

 

lookat.hipnc

Thanks that's clear now. I will try on an elf head and see it works too.

Link to comment
Share on other sites

  • 1 year later...

Hi Patis-san,

For unpacked, you can write something like this (Point Wrangle):

vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m = lookat ( source, target );
@P -= source;
@P *= m;
@P += source;

For packed, you can write over the transform primitive intrinsic attribute. Since it's a matrix3, you don't have to worry about translation to origin and back (Primitive Wrangle):

vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m = lookat ( source, target );
setprimintrinsic ( 0, "transform", @primnum, m );

image.thumb.png.64a781677587a0ab11edfaa12c2b22ff.png

Edited by animatrix
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

4 hours ago, animatrix said:

Hi Patis-san,

For unpacked, you can write something like this (Point Wrangle):


vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m = lookat ( source, target );
@P -= source;
@P *= m;
@P += source;

For packed, you can write over the transform primitive intrinsic attribute. Since it's a matrix3, you don't have to worry about translation to origin and back (Primitive Wrangle):


vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m = lookat ( source, target );
setprimintrinsic ( 0, "transform", @primnum, m );

image.thumb.png.64a781677587a0ab11edfaa12c2b22ff.png

Thank you! I could do that.

vector target = point ( 1, "P", 0 );

int closept[] = pcfind(0,"P",target,1500,1000);
foreach(int i; closept)
{
    vector source = point ( 0, "P", i );
    matrix3 m = lookat ( -source, -target );
    setprimintrinsic ( 0, "transform", i, m );
}

By theway, is there anyway that distance influence quantity of angle fluctuate(matrix3 m)?

In other words the more closely, look at directly.

The more far, a little bit turn to the direction.

thank you.

Link to comment
Share on other sites

Yes depending on what you want to do, you can write something like this:

vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m0 = primintrinsic ( 0, "transform", @primnum );
matrix3 m1 = lookat ( source, target );
float d = ch("amount");

vector4 q0 = quaternion ( m0 );
vector4 q1 = quaternion ( m1 );
vector4 q2 = slerp ( q0, q1, d );

matrix3 m2 = qconvert ( q2 );

setprimintrinsic ( 0, "transform", @primnum, m2 );

In this case, d is between 0 and 1, but if you want you could fit your per-point distance between 0 and 1 using the pcfind max distance for example.

  • Thanks 2
Link to comment
Share on other sites

52 minutes ago, animatrix said:

Yes depending on what you want to do, you can write something like this:


vector source = getbbox_center ( 0 );
vector target = point ( 1, "P", 0 );

matrix3 m0 = primintrinsic ( 0, "transform", @primnum );
matrix3 m1 = lookat ( source, target );
float d = ch("amount");

vector4 q0 = quaternion ( m0 );
vector4 q1 = quaternion ( m1 );
vector4 q2 = slerp ( q0, q1, d );

matrix3 m2 = qconvert ( q2 );

setprimintrinsic ( 0, "transform", @primnum, m2 );

In this case, d is between 0 and 1, but if you want you could fit your per-point distance between 0 and 1 using the pcfind max distance for example.

Thank you for teaching me! I could do that I wanted :)

Now, I am customizing it more useful !

thank you.

  • Like 2
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...