def _rotateEachEntWithQuaternion(self, q, ents, angle): """ Rotate each object along selected axis """ for ent in ents: ort = ent.placeable.Orientation v1 = ort.rotatedVector(QVector3D(1,0,0)) v2 = ort.rotatedVector(QVector3D(0,1,0)) v3 = ort.rotatedVector(QVector3D(0,0,1)) # rotated unit vectors are equals of objects unit vectors in objects perspective # this gives equation M * x = x' (x=(i,j,k) & x'=(i',j',k')) # ( M = conversion matrix, x = world unit vector, x' = object unit vector) # multiply each sides of equation with inverted matrix of M^-1 gives us: # I * x = M^-1 *x' => x = M^-1 * x' # => we can now express world unit vectors i,j,k with i',j',k' # with help of inverted matrix, and use objects quaternion to rotate # along world unit vectors i, j, k m = ((v1.x(),v1.y(),v1.z()),(v2.x(),v2.y(),v2.z()),(v3.x(),v3.y(),v3.z())) inv = mu.invert_3x3_matrix(m) if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis axis = QVector3D(inv[0][0],inv[0][1],inv[0][2]) elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis axis = QVector3D(inv[1][0],inv[1][1],inv[1][2]) elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis axis = QVector3D(inv[2][0],inv[2][1],inv[2][2]) q = QQuaternion.fromAxisAndAngle(axis, angle) q.normalize() ent.placeable.Orientation = ort*q
def __init__(self, entity=None, comp=None, changetype=None): circuits.BaseComponent.__init__(self) self.entity = entity self.comp = comp if self.comp is not None: # normal run, check for nonEC run now # Todo: OnChanged() is deprecated comp.connect("OnChanged()", self.onChanged) self.rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 1)
def __init__(self, entity=None, comp=None, changetype=None): circuits.BaseComponent.__init__(self) self.entity = entity self.comp = comp if self.comp is not None: #normal run, check for nonEC run now # Todo: OnChanged() is deprecated comp.connect("OnChanged()", self.onChanged) self.rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 1)
def _manipulate2(self, ents, amountx, amounty, changevec, centervecs, centerpoint): # calculate quaternion for rotation # get axis # print "amountx %s"%amountx # print "amounty %s"%amounty # print "changevec %s"%changevec if self.grabbed and self.grabbed_axis is not None: local = False # self.controller.useLocalTransform mov = changevec.length() * 30 axis = None #angle = 90 # just do 90 degrees rotations #angle = 15 # just do 15 degrees rotations angle = 5 # just do 5 degrees rotations if amountx < 0 and amounty < 0: dir = -1 elif amountx < 0 and amounty >= 0: dir = 1 if self.grabbed_axis == self.AXIS_BLUE: dir *= -1 elif amountx >= 0 and amounty < 0: dir = -1 elif amountx >= 0 and amounty >= 0: dir = 1 mov *= dir angle *= dir q = None euler = None if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis axis = QVector3D(1, 0, 0) # disable this for now # return elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis axis = QVector3D(0, 1, 0) # disable this for now # return elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis axis = QVector3D(0, 0, 1) q = QQuaternion.fromAxisAndAngle(axis, angle) q.normalize() self._rotateEntsWithQuaternion(q, ents, amountx, amounty, changevec, centervecs, centerpoint) self._rotateEachEntWithQuaternion(q, ents, angle) pass
def _manipulate2(self, ents, amountx, amounty, changevec, centervecs, centerpoint): # calculate quaternion for rotation # get axis # print "amountx %s"%amountx # print "amounty %s"%amounty # print "changevec %s"%changevec if self.grabbed and self.grabbed_axis is not None: local = False # self.controller.useLocalTransform mov = changevec.length() * 30 axis = None #angle = 90 # just do 90 degrees rotations #angle = 15 # just do 15 degrees rotations angle = 5 # just do 5 degrees rotations if amountx < 0 and amounty < 0: dir = -1 elif amountx < 0 and amounty >= 0: dir = 1 if self.grabbed_axis == self.AXIS_BLUE: dir *= -1 elif amountx >= 0 and amounty < 0: dir = -1 elif amountx >= 0 and amounty >= 0: dir = 1 mov *= dir angle *= dir q = None euler = None if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis axis = QVector3D(1,0,0) # disable this for now # return elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis axis = QVector3D(0,1,0) # disable this for now # return elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis axis = QVector3D(0,0,1) q = QQuaternion.fromAxisAndAngle(axis, angle) q.normalize() self._rotateEntsWithQuaternion(q, ents, amountx, amounty, changevec, centervecs, centerpoint) self._rotateEachEntWithQuaternion(q, ents, angle) pass
def _manipulate(self, ent, amountx, amounty, changevec): if self.grabbed and self.grabbed_axis is not None: local = self.controller.useLocalTransform mov = changevec.length() * 30 ort = ent.placeable.Orientation if amountx < 0 and amounty < 0: dir = -1 elif amountx < 0 and amounty >= 0: dir = 1 if not local and self.grabbed_axis == self.AXIS_BLUE: dir *= -1 elif amountx >= 0 and amounty < 0: dir = -1 elif amountx >= 0 and amounty >= 0: dir = 1 mov *= dir if local: if self.grabbed_axis == self.AXIS_RED: axis = Vec(1, 0, 0) elif self.grabbed_axis == self.AXIS_GREEN: axis = Vec(0, 1, 0) elif self.grabbed_axis == self.AXIS_BLUE: axis = Vec(0, 0, 1) ort = ort * Quat.fromAxisAndAngle(axis, mov) else: euler = quat_to_euler(ort) if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis euler[0] -= math.radians(mov) elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis euler[1] += math.radians(mov) elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis euler[2] += math.radians(mov) ort = euler_to_quat(euler) ent.placeable.Orientation = ort ent.network.Orientation = ort
def _manipulate(self, ent, amountx, amounty, changevec): if self.grabbed and self.grabbed_axis is not None: local = self.controller.useLocalTransform mov = changevec.length() * 30 ort = ent.placeable.Orientation if amountx < 0 and amounty < 0: dir = -1 elif amountx < 0 and amounty >= 0: dir = 1 if not local and self.grabbed_axis == self.AXIS_BLUE: dir *= -1 elif amountx >= 0 and amounty < 0: dir = -1 elif amountx >= 0 and amounty >= 0: dir = 1 mov *= dir if local: if self.grabbed_axis == self.AXIS_RED: axis = Vec(1, 0, 0) elif self.grabbed_axis == self.AXIS_GREEN: axis = Vec(0, 1, 0) elif self.grabbed_axis == self.AXIS_BLUE: axis = Vec(0, 0, 1) ort = ort * Quat.fromAxisAndAngle(axis, mov) else: euler = quat_to_euler(ort) if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis euler[0] -= math.radians(mov) elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis euler[1] += math.radians(mov) elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis euler[2] += math.radians(mov) ort = euler_to_quat(euler) ent.placeable.Orientation = ort ent.network.Orientation = ort
def camcontrol(self, rotate=None, move=None): cament = naali.getCamera() p = cament.placeable #print p.Position, p.Orientation if rotate is not None: ort = p.Orientation rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), float(rotate)) ort *= rot p.Orientation = ort if move is not None: pos = p.Position pos += Vec(float(move), 0, 0) p.Position = pos baseurl, imgname = save_screenshot() imgurl = baseurl + imgname #return "%s, %s" % (p.Position, p.Orientation) return relhtml % imgurl
def camcontrol(self, rotate=None, move=None): cament = naali.getCamera() p = cament.placeable #print p.Position, p.Orientation if rotate is not None: ort = p.Orientation rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), float(rotate)) ort *= rot p.Orientation = ort if move is not None: pos = p.Position pos += Vec(float(move), 0, 0) p.Position = pos baseurl, imgname = save_screenshot() imgurl = baseurl + imgname #return "%s, %s" % (p.Position, p.Orientation) return relhtml % imgurl
def render(self, camposx=None, camposy=None, camposz=None, camang=None): #, camortx=None, camorty=None, camortz=None, camortw=None): cament = naali.getCamera() p = cament.placeable if camposx is not None: pos = Vec(*(float(v) for v in [camposx, camposy, camposz])) p.Position = pos if camang is not None: ort = p.Orientation start = Quat(0, 0, -0.707, -0.707) rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), -float(camang)) new = start * rot p.Orientation = new #if camortx is not None: # ort = Quat(*(float(v) for v in [camortw, camortx, camorty, camortz])) # p.Orientation = ort #return str(p.Position), str(p.Orientation) #self.render1() baseurl, imgname = save_screenshot() imgurl = baseurl + imgname pos = p.Position ort = p.Orientation #vec, ang = toAngleAxis(p.Orientation) #print vec, ang euler = quat_to_euler([ort.scalar(), ort.x(), ort.y(), ort.z()]) ang = euler[0] if ang < 0: ang = 360 + ang return abshtml % (imgurl, ang, pos.x(), pos.y(), pos.z() #ort.scalar(), ort.x(), ort.y(), ort.z(), )
def render(self, camposx=None, camposy=None, camposz=None, camang=None): #, camortx=None, camorty=None, camortz=None, camortw=None): cament = naali.getCamera() p = cament.placeable if camposx is not None: pos = Vec(*(float(v) for v in [camposx, camposy, camposz])) p.position = pos if camang is not None: ort = p.orientation start = Quat(0, 0, -0.707, -0.707) rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), -float(camang)) new = start * rot p.orientation = new #if camortx is not None: # ort = Quat(*(float(v) for v in [camortw, camortx, camorty, camortz])) # p.orientation = ort #return str(p.position), str(p.orientation) #self.render1() baseurl, imgname = save_screenshot() imgurl = baseurl + imgname pos = p.position ort = p.orientation #vec, ang = toAngleAxis(p.orientation) #print vec, ang euler = mu.quat_to_euler(ort) ang = euler[0] if ang < 0: ang = 360 + ang return abshtml % (imgurl, ang, pos.x(), pos.y(), pos.z() #ort.scalar(), ort.x(), ort.y(), ort.z(), )
if 0: #camera entity - it is an entity nowadays, and there is EC cam even try: cament = naali.getCamera() print "CAM:", cament.id except ValueError: print "no CAM" else: p = cament.placeable print p.Position, p.Orientation import PythonQt.QtGui from PythonQt.QtGui import QQuaternion as Quat from PythonQt.QtGui import QVector3D as Vec ort = p.Orientation rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 10) #ort *= Quat(0, -.707, 0, .707) ort *= rot p.Orientation = ort #ec cam stuff: print "FOV:", cament.camera.GetVerticalFov() if 0: #calcing the camera angle around up axis for web ui import PythonQt.QtGui from PythonQt.QtGui import QQuaternion as Quat from PythonQt.QtGui import QVector3D as Vec from objectedit.conversions import quat_to_euler#, euler_to_quat
def onChanged(self): y = self.comp.GetAttribute("y") self.rot = Quat.fromAxisAndAngle(Vec(0, y, 0), 1)
def onChanged(self): y = self.comp.GetAttribute('y') self.rot = Quat.fromAxisAndAngle(Vec(0, y, 0), 1)
if 0: #camera entity - it is an entity nowadays, and there is EC cam even try: cament = naali.getCamera() print "CAM:", cament.id except ValueError: print "no CAM" else: p = cament.placeable print p.Position, p.Orientation import PythonQt.QtGui from PythonQt.QtGui import QQuaternion as Quat from PythonQt.QtGui import QVector3D as Vec ort = p.Orientation rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 10) #ort *= Quat(0, -.707, 0, .707) ort *= rot p.Orientation = ort #ec cam stuff: print "FOV:", cament.camera.GetVerticalFov() if 0: #calcing the camera angle around up axis for web ui import PythonQt.QtGui from PythonQt.QtGui import QQuaternion as Quat from PythonQt.QtGui import QVector3D as Vec from objectedit.conversions import quat_to_euler #, euler_to_quat def toAngleAxis(quat):
if 0: #camera entity - it is an entity nowadays, and there is EC cam even try: cament = naali.getCamera() print "CAM:", cament.id except ValueError: print "no CAM" else: p = cament.placeable print p.position, p.orientation import PythonQt.QtGui from PythonQt.QtGui import QQuaternion as Quat from PythonQt.QtGui import QVector3D as Vec ort = p.orientation rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 10) #ort *= Quat(0, -.707, 0, .707) ort *= rot p.orientation = ort #ec cam stuff: print "FOV:", cament.camera.GetVerticalFov() if 0: #calcing the camera angle around up axis for web ui import PythonQt.QtGui from PythonQt.QtGui import QQuaternion from PythonQt.QtGui import QVector3D import mathutils as mu