}// createPointClound public void create(Vector3d u, Vector3d v) { // body bone Vector3d center = (u + v) / 2; Vector3d dir = (v - u).normalize(); double radius = (u - v).Length() / 2; Matrix4d scaleMat = Matrix4d.ScalingMatrix(radius / _x, 1, 1); Vector3d axis = new Vector3d(1, 0, 0); Vector3d rotAxis = axis.Cross(dir).normalize(); Matrix4d transMat = Matrix4d.TranslationMatrix(center); Matrix4d rotMat = Matrix4d.IdentityMatrix(); if (!double.IsNaN(rotAxis.x) && !double.IsNaN(rotAxis.y) && !double.IsNaN(rotAxis.z)) { double acos = axis.Dot(dir); if (acos < -1) { acos = -1; } else if (acos > 1) { acos = 1; } double rot_angle = Math.Acos(acos); rotMat = Matrix4d.RotationMatrix(rotAxis, rot_angle); } Matrix4d T = transMat * rotMat * scaleMat; this.TransformFromUnit(T); }// create
public Matrix4d getTransformMatrix(int perspective) { Matrix4d m = Matrix4d.IdentityMatrix(); switch (this.motion) { case MotionType.NONE: break; case MotionType.Pan: { Vector3d d = this.currPos - this.startPos; m = Matrix4d.TranslationMatrix(d); break; } case MotionType.Scale: { m[0, 0] = m[1, 1] = m[2, 2] = 1.0 + (this.currPos.x - this.startPos.x); break; } case MotionType.Rotate: default: { m = this.getRotationMatrix(perspective); break; } } return(m); }