绕轴旋转

绕轴旋转_第1张图片
绕轴旋转(学习from cgwiki)
int points[] = primpoints(0,@primnum); // list of points in prim

// get @P of first and second point
vector p0 = point(0,‘P’,points[0]);
vector p1 = point(0,‘P’,points[1]);

vector axis = p0-p1;

float angle = ch(‘angle’);
matrix3 rotm = ident();
rotate(rotm, angle, axis);

// get midpoint of edge
vector pivot = (p0+p1)/2;

// move point to origin, rotate, move back

@P -= pivot;
@P *= rotm;
@P += pivot;

你可能感兴趣的:(经验分享)