Skip to content

Instantly share code, notes, and snippets.

@Squid3d
Created March 10, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Squid3d/3c79dbe2424d4b71bf60 to your computer and use it in GitHub Desktop.
Save Squid3d/3c79dbe2424d4b71bf60 to your computer and use it in GitHub Desktop.
Simple lookat constraint example for Splice/Maya - used to illustrate rather than edjumakate
/*
Classic gl LookAt
aims down the z axis at the lookAt object
*/
// create up and lookAt locators
// create a cube at the origin
// add a spliceMayaNode
// add inputs:
// lookAt Mat44
// upVec Mat44
// add Output:
// result Mat44
// add Opererator:
// LookAtClassicOp
// kl for op
require Math;
operator LookAtClassicOp(
in Mat44 lookAt, // locator
io Mat44 result,
in Mat44 upVec // locator
) {
// working in world coords, assuming the cube
// is at origin
Vec3 z;
z = lookAt.translation(); // p2 - p1 (lookAt - Vec3(0))
z.normalize();
Vec3 x;
x = upVec.translation().cross(z);
x.normalize();
Vec3 y;
y = z.cross(x);
// splice is column-major
Mat33 rot(x.x, y.x , z.x,
x.y, y.y, z.y,
x.z, y.z, z.z);
Vec3 trans(0.0,0.0,0.0);
Vec3 scale(1.0,1.0,1.0);
result.set(trans, rot, scale);
}
// pipe the result of this node into a decomposeMatrix->Rotate[cube]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment