马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 newer 于 2018-7-14 16:23 编辑
正常的带属性图块的旋转,属性会和图块一起旋转的,
如下图:
上面实现的代码如下,使用了点监视器和矩阵变换
 - (defun c:tt ()
- (defun _callback (dypnt)
- (if (not (equal dypnt lastpnt 1e-3))
- (progn (setq rot (angle ori dypnt))
- (setq mat (xdrx_matrix_setrotation (setq rot (rem (- rot lastang) (* 2 pi))) '(0 0 1) ori))
- (xdrx_entity_transform e mat)
- (redraw)
- (xdrx_grdraw 1 1 ori dypnt)
- )
- )
- (setq lastpnt dypnt lastang (angle ori dypnt))
- )
- (if (setq e (xdrx_entsel "\n拾取块<退出>:" '((0 . "insert"))))
- (progn (setq pt (cadr e)
- e (car e)
- ori (xdrx_getpropertyvalue e "position")
- refvec (angle ori pt)
- ang (xdrx_getpropertyvalue e "rotation")
- lastang (angle ori pt)
- atts (xdrx_getpropertyvalue e "attributeentities")
- )
- (xdrx_pointmonitor "_callback")
- (getpoint)
- (xdrx_pointmonitor)
- )
- )
- (redraw)
- (princ)
- )
那么问题来了,如果属性随着图块旋转的过程中,如何让文字的方向始终固定呢? 就如属性绕着块旋转,数字文字本身也自转回原来的方向,就如月亮始终保持一面面向地球一样。
上面的代码,随着鼠标,属性和图块一起旋转,每次旋转了rot角度, 如果同时,让属性文字绕着自身的中点逆旋转-rot角度,那么就能让属性文字方向始终固定了。
下面的代码,比上面的代码仅仅多了几行,在图块和属性作用旋转变换矩阵旋转后
 - (mapcar '(lambda(x)
- (setq ori1 (xdrx_getpropertyvalue x "9pt" 5)
- mat1(xdrx_matrix_setrotation (- rot) '(0 0 1) ori1));构建属性旋转变换矩阵,属性逆旋转-rot,回到原来的方向
- (xdrx_entity_transform x mat1)) atts)
上面代码atts变量是所有的属性实体名表,mapcar循环处理每个属性,找出每个属性的中心点,然后构建一个绕着中心点旋转-rot的变换矩阵作用到属性实体上就可以了。
下面是结果的动图:
实现的完整代码:
 - (defun c:tt ()
- (defun _callback (dypnt)
- (if (not (equal dypnt lastpnt 1e-3))
- (progn (setq rot (angle ori dypnt))
- (setq mat (xdrx_matrix_setrotation (setq rot (rem (- rot lastang) (* 2 pi))) '(0 0 1) ori));构建旋转变换矩阵
- (xdrx_entity_transform e mat);矩阵变换,块和属性都正常旋转角度rot
- (mapcar '(lambda(x)
- (setq ori1 (xdrx_getpropertyvalue x "9pt" 5)
- mat1(xdrx_matrix_setrotation (- rot) '(0 0 1) ori1));构建属性旋转变换矩阵,属性逆旋转-rot,回到原来的方向
- (xdrx_entity_transform x mat1)) atts)
- (redraw)
- (xdrx_grdraw 1 1 ori dypnt)
- )
- )
- (setq lastpnt dypnt lastang (angle ori dypnt))
- )
- (if (setq e (xdrx_entsel "\n拾取块<退出>:" '((0 . "insert"))))
- (progn (setq pt (cadr e)
- e (car e)
- ori (xdrx_getpropertyvalue e "position")
- refvec (angle ori pt)
- ang (xdrx_getpropertyvalue e "rotation")
- lastang (angle ori pt)
- atts (xdrx_getpropertyvalue e "attributeentities")
- )
- (xdrx_pointmonitor "_callback")
- (getpoint)
- (xdrx_pointmonitor)
- )
- )
- (redraw)
- (princ)
- )
附加问题:如果只想让图块旋转,属性不动如何实现?
答案就是只设置图块的旋转角就行了。
 - (defun c:tt ()
- (defun _callback (dypnt)
- (if (not (equal dypnt lastpnt 1e-3))
- (progn (setq rot (angle ori dypnt)
- rot (- rot refvec))
- (xdrx_setpropertyvalue e "rotation" (rem (+ ang rot) (* 2 pi)))
- (redraw)
- (xdrx_grdraw 1 1 ori dypnt)
- )
- )
- (setq lastpnt dypnt)
- )
- (if (setq e (xdrx_entsel "\n拾取块<退出>:" '((0 . "insert"))))
- (progn (setq pt (cadr e)
- e (car e)
- ori (xdrx_getpropertyvalue e "position")
- refvec (angle ori pt)
- ang (xdrx_getpropertyvalue e "rotation")
- lastpnt '(0 0 0)
- )
- (xdrx_pointmonitor "_callback")
- (getpoint)
- (xdrx_pointmonitor)
- )
- )
- (redraw)
- (princ)
- )
|