Esempio n. 1
0
    def manipulate(self, ents, movedx, movedy):
        if ents is not None:
            fov = naali.getCamera().camera.GetVerticalFov()
            width, height = rend.GetWindowWidth(), rend.GetWindowHeight()
            campos = naali.getCamera().placeable.Position
            ent = ents[-1]
            entpos = ent.placeable.Position
            length = (campos - entpos).length()

            worldwidth = (math.tan(fov / 2) * length) * 2
            worldheight = (height * worldwidth) / width

            ## used in freemoving to get the size of movement right
            # factor for move size
            movefactor = width / height
            amountx = (worldwidth * movedx) * movefactor
            amounty = (worldheight * movedy) * movefactor

            self.setManipulatorScale(ents)

            rightvec = get_right(naali.getCamera())
            upvec = get_up(naali.getCamera())

            rightvec *= amountx
            upvec *= amounty
            changevec = rightvec - upvec

            for ent in ents:
                self._manipulate(ent, amountx, amounty, changevec)
                self.controller.soundRuler(ent)

            if self.usesManipulator:
                self.moveTo(ents)
Esempio n. 2
0
    def manipulate(self, ents, movedx, movedy):
        if ents is not None:
            fov = naali.getCamera().camera.GetVerticalFov()
            width, height = rend.GetWindowWidth(), rend.GetWindowHeight()
            campos = naali.getCamera().placeable.Position
            ent = ents[-1]
            entpos = ent.placeable.Position
            length = (campos-entpos).length()
                
            worldwidth = (math.tan(fov/2)*length) * 2
            worldheight = (height*worldwidth) / width

            ## used in freemoving to get the size of movement right
            # factor for move size
            movefactor = width / height
            amountx = (worldwidth * movedx) * movefactor
            amounty = (worldheight * movedy) * movefactor

            self.setManipulatorScale(ents)

            rightvec = get_right(naali.getCamera())
            upvec = get_up(naali.getCamera())

            rightvec *= amountx
            upvec *= amounty
            changevec = rightvec - upvec
            
            for ent in ents:
                self._manipulate(ent, amountx, amounty, changevec)
                self.controller.soundRuler(ent)
                
            if self.usesManipulator:
                self.moveTo(ents)
Esempio n. 3
0
    def _renderimgurl(self,
                      camposx=None,
                      camposy=None,
                      camposz=None,
                      camortx=None,
                      camorty=None,
                      camortz=None,
                      camortw=None):
        cament = naali.getCamera()
        p = cament.placeable
        orgpos = Vec(0, 0, 0)
        orgort = Quat(1, 0, 0, 0)

        if camposx is not None:
            pos = Vec(*(float(v) for v in [camposx, camposy, camposz]))
            p.Position = pos

        if camortx is not None:
            ort = Quat(*(float(v)
                         for v in [camortw, camortx, camorty, camortz]))
            p.Orientation = ort

        baseurl, imgname = save_screenshot()

        p.Position = orgpos
        p.Orientation = orgort
        return baseurl, imgname
Esempio n. 4
0
    def manipulate(self, ents, movedx, movedy):
        if ents is not None:
            fov = naali.getCamera().camera.GetVerticalFov()
            width, height = rend.GetWindowWidth(), rend.GetWindowHeight()
            campos = naali.getCamera().placeable.position
            ent = ents[-1]
            entpos = ent.placeable.position
            length = (campos - entpos).length()

            worldwidth = (math.tan(fov / 2) * length) * 2
            worldheight = (height * worldwidth) / width

            ## used in freemoving to get the size of movement right
            # factor for move size
            movefactor = width / height
            amountx = (worldwidth * movedx) * movefactor
            amounty = (worldheight * movedy) * movefactor

            self.setManipulatorScale(ents)

            rightvec = mu.get_right(naali.getCamera())
            upvec = mu.get_up(naali.getCamera())

            rightvec *= amountx
            upvec *= amounty
            changevec = rightvec - upvec

            # group rotation
            if self.NAME == "RotationManipulator" and len(
                    ents) > 1 and self.grabbed_axis == self.AXIS_BLUE:
                self.setCenterPointAndCenterVectors(ents)
                self._manipulate2(ents, amountx, amounty, changevec,
                                  self.entCenterVectors, self.centerPoint)
            else:
                for ent in ents:
                    self._manipulate(ent, amountx, amounty, changevec)
                    #self.controller.soundRuler(ent)

                if not self.manipulator is None:
                    if len(ents) > 0 and self.NAME != "FreeMoveManipulator":
                        placeable = ents[0].placeable
                        #self.manipulator.ruler.DoDrag(placeable.Position, placeable.Orientation, placeable.Scale)

                #self.manipulator.ruler.UpdateRuler()

            if self.usesManipulator:
                self.moveTo(ents)
Esempio n. 5
0
    def manipulate(self, ents, movedx, movedy):
        if ents is not None:
            fov = naali.getCamera().camera.GetVerticalFov()
            width, height = rend.GetWindowWidth(), rend.GetWindowHeight()
            campos = naali.getCamera().placeable.Position
            ent = ents[-1]
            entpos = ent.placeable.Position
            length = (campos-entpos).length()
                
            worldwidth = (math.tan(fov/2)*length) * 2
            worldheight = (height*worldwidth) / width

            ## used in freemoving to get the size of movement right
            # factor for move size
            movefactor = width / height
            amountx = (worldwidth * movedx) * movefactor
            amounty = (worldheight * movedy) * movefactor

            self.setManipulatorScale(ents)

            rightvec = mu.get_right(naali.getCamera())
            upvec = mu.get_up(naali.getCamera())

            rightvec *= amountx
            upvec *= amounty
            changevec = rightvec - upvec

            # group rotation
            if self.NAME=="RotationManipulator" and len(ents)>1:
                self.setCenterPointAndCenterVectors(ents)
                self._manipulate2(ents, amountx, amounty, changevec, self.entCenterVectors, self.centerPoint)
            else:            
                for ent in ents:
                    self._manipulate(ent, amountx, amounty, changevec)
                    self.controller.soundRuler(ent)

                if not self.manipulator is None:
                    if len(ents) > 0 and self.NAME!="FreeMoveManipulator":
                        placeable = ents[0].placeable
                        self.manipulator.ruler.DoDrag(placeable.Position, placeable.Orientation, placeable.Scale)
                
                if(self.manipulator!=None):
                    self.manipulator.ruler.UpdateRuler()
                
            if self.usesManipulator:
                self.moveTo(ents)
Esempio n. 6
0
    def setManipulatorScale(self, ents):
        if ents is None or len(ents) == 0: 
                return

        campos = naali.getCamera().placeable.position
        ent = ents[-1]
        entpos = ent.placeable.position
        length = (campos-entpos).length()
            
        v = self.MANIPULATORSCALE
        factor = length*.1
        newv = QVector3D(v) * factor
        try:
            self.manipulator.placeable.scale = newv
        except AttributeError:
            pass
Esempio n. 7
0
    def setManipulatorScale(self, ents):
        if ents is None or len(ents) == 0:
            return

        campos = naali.getCamera().placeable.position
        ent = ents[-1]
        entpos = ent.placeable.position
        length = (campos - entpos).length()

        v = self.MANIPULATORSCALE
        factor = length * .1
        newv = QVector3D(v) * factor
        try:
            self.manipulator.placeable.scale = newv
        except AttributeError:
            pass
Esempio n. 8
0
    def _renderimgurl(self, camposx=None, camposy=None, camposz=None, camortx=None, camorty=None, camortz=None, camortw=None):
        cament = naali.getCamera()
        p = cament.placeable
        orgpos = Vec(0, 0, 0)
        orgort = Quat(1, 0, 0, 0)

        if camposx is not None:
            pos = Vec(*(float(v) for v in [camposx, camposy, camposz]))
            p.Position = pos

        if camortx is not None:
            ort = Quat(*(float(v) for v in [camortw, camortx, camorty, camortz]))
            p.Orientation = ort

        baseurl, imgname = save_screenshot()

        p.Position = orgpos
        p.Orientation = orgort
        return baseurl, imgname
Esempio n. 9
0
    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
Esempio n. 10
0
    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
Esempio n. 11
0
    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(),
                          )
Esempio n. 12
0
    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(),
                          )
Esempio n. 13
0
 def update(self, t):
     if self.cam is None and self.scene is not None:
         cament = naali.getCamera()
         self.cam = cament
         r.switchCameraState() #supposes that FREECAM was off, turns it on.
Esempio n. 14
0
    
    hmm = r.takeScreenshot(path, pic)
    
if 0:
    print "Testing event sending, camera for now..."#   , r.SwitchCameraState
    hmm = r.sendEvent(r.SwitchCameraState)
    print "test done?", hmm

if 0:
    print "Testing camera swap..."
    hmm = r.switchCameraState()
    #print hmm
    
if 0: #get entity
    #idnum = new_id
    idnum = naali.getCamera().id
    print "Getting entity id", idnum,
    e = naali.getEntity(idnum)
    print "got:", e
    #print dir(r)
    #rotate(e)
    #move(e)

if 0: #test avatartracking, works :)
    try:
        a = naali.getUserAvatar()
    except ValueError:
        print "could find the user avatar"
    else:
        print "<:::",
        print "Avatar pos:", a.placeable.position,
Esempio n. 15
0
    def do_api_calls(self):
        yield "createMeshEntity"
        e = naali.createMeshEntity("axes.mesh")

        from PythonQt.QtGui import QVector3D, QQuaternion
        e.placeable.position = QVector3D(128, 128, 60)
        e.placeable.Scale = QVector3D(5, 5, 5)
        e.placeable.Orientation = QQuaternion(0, 0, 0, 1)
        r.removeEntity(e.Id)

        yield "EC_Touchable & EC_Highlight"
        for longname, shortname in [("EC_Touchable", 'touchable'),
                                    ("EC_Highlight", 'highlight')]:
            e = naali.getUserAvatar()
            e.GetOrCreateComponentRaw(longname)
            x = getattr(e, shortname)
            x.Show()
            x.Hide()
            assert x.IsVisible() == False

        yield "naali.createEntity"
        ent = naali.createEntity()
        print "new entity created:", ent

        yield "get camera FOV"
        fov = naali.getCamera().camera.GetVerticalFov()

        yield "avatar position"
        p = naali.getUserAvatar().placeable.position

        yield "avatar animation controller"
        naali.getUserAvatar().animationcontroller.EnableAnimation("Walk")

        yield "test sendChat"
        r.sendChat("test chat")

        yield "test logInfo"
        r.logInfo("test log message")

        #XXX deprecate
        yield "test camera yaw/itch"
        r.setCameraYawPitch(.1, .5)
        r.getCameraYawPitch()

        yield "test webview"
        import PythonQt
        wv = PythonQt.QtWebKit.QWebView()
        wv.show()

        yield "test dotscene loading"
        from localscene import loader
        loader.load_dotscene("pymodules/localscene/test.scene")

        yield "test dynamic component"
        ent = naali.getUserAvatar()
        ent.GetOrCreateComponentRaw("EC_DynamicComponent")
        print ent, type(ent)
        d = ent.EC_DynamicComponent
        d.CreateAttribute("real", 42.0)
        d.ComponentChanged(0)
        d.SetAttribute("real", 8.5)
        d.ComponentChanged(0)
        d.RemoveAttribute("real")
        d.ComponentChanged(0)

        yield "test javascript"
        cam = naali.getCamera()
        naali.runjs('print("Hello from JS! " + x)', {'x': naali.renderer})
        naali.runjs('print("Another hello from JS! " + x)',
                    {'x': naali.inputcontext})
        naali.runjs('print("Some camera! " + x)', {'x': cam.camera})
        #py objects are not qobjects. naali.runjs('print("Some camera, using naali :O ! " + x.getCamera())', {'x': naali})
        naali.runjs('print("Camera Entity " + x)', {'x': cam})
        naali.runjs('print("Camera placeable pos: " + pos)',
                    {'pos': cam.placeable.position})
        #not exposed yet. naali.runjs('print("QVector3D: " + new QVector3D())', {})
        #naali.runjs('var a = {"a": true, "b": 2};')
        #naali.runjs('print(a.a + ", " + a.b)')
        #naali.runjs('print(JSON.stringify(a))')
        #naali.runjs('print("1 + 1 == " + 1 + 1)')
        #naali.runjs('print("1 - 1 == " + 1 - 1)')
        print ", done."

        if 0:
            runjs('var b = new QPushButton;')
            runjs('b.text = "hep";')
            runjs('b.show();')
Esempio n. 16
0
    hmm = r.takeScreenshot(path, pic)

if 0:
    print "Testing event sending, camera for now..."  #   , r.SwitchCameraState
    hmm = r.sendEvent(r.SwitchCameraState)
    print "test done?", hmm

if 0:
    print "Testing camera swap..."
    hmm = r.switchCameraState()
    #print hmm

if 0:  #get entity
    #idnum = new_id
    idnum = naali.getCamera().id
    print "Getting entity id", idnum,
    e = naali.getEntity(idnum)
    print "got:", e
    #print dir(r)
    #rotate(e)
    #move(e)

if 0:  #test avatartracking, works :)
    try:
        a = naali.getUserAvatar()
    except ValueError:
        print "could find the user avatar"
    else:
        print "<:::",
        print "Avatar pos:", a.placeable.Position,
Esempio n. 17
0
    def do_api_calls(self):
        yield "createMeshEntity"
        e = naali.createMeshEntity("axes.mesh")

        from PythonQt.QtGui import QVector3D, QQuaternion
        e.placeable.position = QVector3D(128, 128, 60)
        e.placeable.Scale = QVector3D(5, 5, 5)
        e.placeable.Orientation = QQuaternion(0, 0, 0, 1)
        r.removeEntity(e.Id)

        yield "EC_Touchable & EC_Highlight"
        for longname, shortname in [("EC_Touchable", 'touchable'), ("EC_Highlight", 'highlight')]:
            e = naali.getUserAvatar()
            e.GetOrCreateComponentRaw(longname)
            x = getattr(e, shortname)
            x.Show()
            x.Hide()
            assert x.IsVisible() == False

        yield "naali.createEntity"
        ent = naali.createEntity()
        print "new entity created:", ent

        yield "get camera FOV"
        fov = naali.getCamera().camera.GetVerticalFov()
        
        yield "avatar position"
        p = naali.getUserAvatar().placeable.position

        yield "avatar animation controller"
        naali.getUserAvatar().animationcontroller.EnableAnimation("Walk")

        yield "test sendChat"
        r.sendChat("test chat")

        yield "test logInfo"
        r.logInfo("test log message")

        #XXX deprecate
        yield "test camera yaw/itch"
        r.setCameraYawPitch(.1, .5)
        r.getCameraYawPitch()
        
        yield "test webview"
        import PythonQt
        wv = PythonQt.QtWebKit.QWebView()
        wv.show()

        yield "test dotscene loading"
        from localscene import loader
        loader.load_dotscene("pymodules/localscene/test.scene")
    
        yield "test dynamic component"
        ent = naali.getUserAvatar()
        ent.GetOrCreateComponentRaw("EC_DynamicComponent")
        print ent, type(ent)
        d = ent.EC_DynamicComponent
        d.CreateAttribute("real", 42.0)
        d.ComponentChanged(0)
        d.SetAttribute("real", 8.5)
        d.ComponentChanged(0)
        d.RemoveAttribute("real")
        d.ComponentChanged(0)

        yield "test javascript"
        cam = naali.getCamera()
        naali.runjs('print("Hello from JS! " + x)', {'x': naali.renderer})
        naali.runjs('print("Another hello from JS! " + x)', {'x': naali.inputcontext})
        naali.runjs('print("Some camera! " + x)', {'x': cam.camera})
        #py objects are not qobjects. naali.runjs('print("Some camera, using naali :O ! " + x.getCamera())', {'x': naali})
        naali.runjs('print("Camera Entity " + x)', {'x': cam})
        naali.runjs('print("Camera placeable pos: " + pos)', {'pos': cam.placeable.position})
        #not exposed yet. naali.runjs('print("QVector3D: " + new QVector3D())', {})
        #naali.runjs('var a = {"a": true, "b": 2};')
        #naali.runjs('print(a.a + ", " + a.b)')
        #naali.runjs('print(JSON.stringify(a))')
        #naali.runjs('print("1 + 1 == " + 1 + 1)')
        #naali.runjs('print("1 - 1 == " + 1 - 1)')
        print ", done."

        if 0:
            runjs('var b = new QPushButton;')
            runjs('b.text = "hep";')
            runjs('b.show();')
Esempio n. 18
0
    
    hmm = r.takeScreenshot(path, pic)
    
if 0:
    print "Testing event sending, camera for now..."#   , r.SwitchCameraState
    hmm = r.sendEvent(r.SwitchCameraState)
    print "test done?", hmm

if 0:
    print "Testing camera swap..."
    hmm = r.switchCameraState()
    #print hmm
    
if 0: #get entity
    #idnum = new_id
    idnum = naali.getCamera().id
    print "Getting entity id", idnum,
    e = naali.getEntity(idnum)
    print "got:", e
    #print dir(r)
    #rotate(e)
    #move(e)

if 0: #test avatartracking, works :)
    try:
        a = naali.getUserAvatar()
    except ValueError:
        print "could find the user avatar"
    else:
        print "<:::",
        print "Avatar pos:", a.placeable.Position,
Esempio n. 19
0
 def update(self, t):
     if self.cam is None and self.scene is not None:
         cament = naali.getCamera()
         self.cam = cament
         r.switchCameraState()  # supposes that FREECAM was off, turns it on.