Skip to content

Instantly share code, notes, and snippets.

@yone80
Last active December 28, 2016 01:56
Show Gist options
  • Save yone80/92e9cbbdc3ef0428c86c to your computer and use it in GitHub Desktop.
Save yone80/92e9cbbdc3ef0428c86c to your computer and use it in GitHub Desktop.
VEXpression
float angle = ch('angle') * -1;
float range = ch('range');
if(angle==0.0 || range==0.0) return;
angle = radians(angle / range);
int limit = chi('limit');
vector origin = chv('orig');
vector dir = normalize( chv('dir') );
vector up = normalize( chv('up') );
vector rotaxis = cross(up, dir);
/* Distance from Origin-Plane */
vector v = @P-origin;
float dist = dot(v, dir);
if(limit==1) dist = clamp(dist, -range, range);
if(limit==2) dist = clamp(dist, 0, range);
vector onplanepos = @P-dir*dist;
/* Rotate */
vector rotoffset = up / angle - origin;
vector4 q = quaternion(angle * dist, rotaxis);
vector base = qrotate(q, rotoffset) - rotoffset;
onplanepos = qrotate(q, onplanepos);
@P = base + onplanepos;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment