Point3d org = attRef.Position;
Vector3d zVec = vd.Viewport.ViewDirection;
Vector3d yVec = vd.Viewport.CameraUpVector;
Vector3d xVec = yVec.CrossProduct(zVec).GetNormal();
Matrix3d viewMat =
Matrix3d.AlignCoordinateSystem(
Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
org, xVec, yVec, zVec) *
Matrix3d
.WorldToPlane(new Plane
(org, attRef
.Normal)) * Matrix3d.Rotation(-attRef.Rotation, attRef.Normal, org);