From ea5904139f80cb96400febcfb289a8fd4729da2c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 31 May 2016 00:38:01 +0200 Subject: o Fixing rotation and alignment for non-cube shapes. --- Boxer.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Boxer.py b/Boxer.py index c347049..facb4e3 100644 --- a/Boxer.py +++ b/Boxer.py @@ -1,7 +1,7 @@ # import Boxer; reload(Boxer); import BoxerGui as bg; reload(bg); #import FreeCAD -from FreeCAD import Base, Vector, Matrix +from FreeCAD import Base, Vector, Matrix, Placement, Rotation import Part from enum import Enum import math @@ -232,12 +232,19 @@ def makeBox(doc, cfg): sep = cfg.outerWidth * 0.05 def m(rotX, rotY, moveX, moveY, moveZ): + if rotX and rotY: + p = Placement(Vector(0, 0, 0), Rotation(Vector(1, 1, 1), 120)) + m = p.toMatrix() + else: + m = Matrix() + if rotX: + m.rotateX(math.radians(90)) + if rotY: + m.rotateY(math.radians(90)) + v = Vector(cfg.innerWidth, cfg.innerDepth, cfg.innerHeight) v.scale(moveX, moveY, moveZ) - m = Matrix() - m.rotateX(math.radians(rotX)) - m.rotateY(math.radians(rotY)) m.move(v) return m @@ -245,32 +252,32 @@ def makeBox(doc, cfg): # right top bottom s = Part.makePolygon(makeBoxSide(cfg, BoxSide.front)) - s.transformShape(m(90, 0, -0.5, -0.5, 0.5)) + s.transformShape(m(True, False, -0.5, -0.5, 0.5)) front = doc.addObject("Part::Feature", "Front") front.Shape = s s = Part.makePolygon(makeBoxSide(cfg, BoxSide.back)) - s.transformShape(m(90, 0, -0.5, 0.5, 0.5)) + s.transformShape(m(True, False, -0.5, 0.5, 0.5)) back = doc.addObject("Part::Feature", "Back") back.Shape = s l = Part.makePolygon(makeBoxSide(cfg, BoxSide.left)) - l.transformShape(m(0, 90, -0.5, 0.5, 0.5)) + l.transformShape(m(True, True, -0.5, -0.5, 0.5)) left = doc.addObject("Part::Feature", "Left") left.Shape = l l = Part.makePolygon(makeBoxSide(cfg, BoxSide.right)) - l.transformShape(m(0, 90, 0.5, 0.5, 0.5)) + l.transformShape(m(True, True, 0.5, -0.5, 0.5)) right = doc.addObject("Part::Feature", "Right") right.Shape = l l = Part.makePolygon(makeBoxSide(cfg, BoxSide.top)) - l.transformShape(m(0, 0, -0.5, 0.5, 0.5)) + l.transformShape(m(False, False, -0.5, 0.5, 0.5)) top = doc.addObject("Part::Feature", "Top") top.Shape = l l = Part.makePolygon(makeBoxSide(cfg, BoxSide.bottom)) - l.transformShape(m(0, 0, -0.5, 0.5, -0.5)) + l.transformShape(m(False, False, -0.5, 0.5, -0.5)) bottom = doc.addObject("Part::Feature", "Bottom") bottom.Shape = l -- cgit v1.2.3