Пример #1
0
    def update(self, task=None):
        """
        Updates position of sounds in the 3D audio system. Will be called automatically
        in a task.
        """
        # Update the positions of all sounds based on the objects
        # to which they are attached
        
        # The audio manager is not active so do nothing
        if hasattr(self.audio_manager, "getActive"):
            if self.audio_manager.getActive()==0:
                return Task.cont
        
        for known_object in self.sound_dict.keys():
            tracked_sound = 0
            while tracked_sound < len(self.sound_dict[known_object]):
                sound = self.sound_dict[known_object][tracked_sound]
                pos = known_object.getPos(self.root)
                vel = self.getSoundVelocity(sound)
                sound.set3dAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2])
                tracked_sound += 1

        # Update the position of the listener based on the object
        # to which it is attached
        if self.listener_target:
            pos = self.listener_target.getPos(self.root)
            forward = self.listener_target.getRelativeVector(self.root, Vec3.forward())
            up = self.listener_target.getRelativeVector(self.root, Vec3.up())
            vel = self.getListenerVelocity()
            self.audio_manager.audio3dSetListenerAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], forward[0], forward[1], forward[2], up[0], up[1], up[2]) 
        else:
            self.audio_manager.audio3dSetListenerAttributes(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
        return Task.cont
Пример #2
0
 def onCenterTrackball(self, evt = None):
   """Center the trackball, like 'c' does in pview."""
   gbv = render.getBounds();
   # Determine the bounding sphere around the object.
   if gbv.isInfinite(): return
   if gbv.isEmpty(): return
   
   # The BoundingVolume might be a sphere (it's likely), but since it
   # might not, we'll take no chances and make our own sphere.
   sphere = BoundingSphere(gbv.getApproxCenter(), 0.0)
   if (not sphere.extendBy(gbv)): return
   
   radius = 50.0
   
   # Loop through the windows/viewports
   for w in WindowManager.windows:
     # Choose a suitable distance to view the whole volume in our frame.
     # This is based on the camera lens in use.
     fov = w.camLens.getFov();
     distance = radius / tan(deg2Rad(min(fov[0], fov[1]) / 2.0));
     
     # Ensure the far plane is far enough back to see the entire object.
     idealFarPlane = distance + radius * 1.5;
     w.camLens.setFar(max(w.camLens.getDefaultFar(), idealFarPlane));
     
     # And that the near plane is far enough forward.
     w.camLens.setNear(min(w.camLens.getDefaultNear(), radius - sphere.getRadius()))
     
     w.trackball.node().setOrigin(sphere.getCenter())
     w.trackball.node().setPos(Vec3.forward() * distance)
     
     # Also set the movement scale on the trackball to be consistent
     # with the size of the model and the lens field-of-view.
     w.trackball.node().setForwardScale(distance * 0.006)
Пример #3
0
    def update(self, task=None):
        if hasattr(self.audio_manager, 'getActive'):
            if self.audio_manager.getActive() == 0:
                return Task.cont

        for known_object in self.sound_dict.keys():
            tracked_sound = 0
            while tracked_sound < len(self.sound_dict[known_object]):
                sound = self.sound_dict[known_object][tracked_sound]
                pos = known_object.getPos(self.root)
                vel = self.getSoundVelocity(sound)
                sound.set3dAttributes(pos[0], pos[1], pos[2], vel[0], vel[1],
                                      vel[2])
                tracked_sound += 1

        if self.listener_target:
            pos = self.listener_target.getPos(self.root)
            forward = self.listener_target.getRelativeVector(
                self.root, Vec3.forward())
            up = self.listener_target.getRelativeVector(self.root, Vec3.up())
            vel = self.getListenerVelocity()
            self.audio_manager.audio3dSetListenerAttributes(
                pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], forward[0],
                forward[1], forward[2], up[0], up[1], up[2])
        else:
            self.audio_manager.audio3dSetListenerAttributes(
                0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
        return Task.cont
Пример #4
0
    def onCenterTrackball(self, evt=None):
        """Center the trackball, like 'c' does in pview."""
        gbv = render.getBounds()
        # Determine the bounding sphere around the object.
        if gbv.isInfinite(): return
        if gbv.isEmpty(): return

        # The BoundingVolume might be a sphere (it's likely), but since it
        # might not, we'll take no chances and make our own sphere.
        sphere = BoundingSphere(gbv.getApproxCenter(), 0.0)
        if (not sphere.extendBy(gbv)): return

        radius = 50.0

        # Loop through the windows/viewports
        for w in WindowManager.windows:
            # Choose a suitable distance to view the whole volume in our frame.
            # This is based on the camera lens in use.
            fov = w.camLens.getFov()
            distance = radius / tan(deg2Rad(min(fov[0], fov[1]) / 2.0))

            # Ensure the far plane is far enough back to see the entire object.
            idealFarPlane = distance + radius * 1.5
            w.camLens.setFar(max(w.camLens.getDefaultFar(), idealFarPlane))

            # And that the near plane is far enough forward.
            w.camLens.setNear(
                min(w.camLens.getDefaultNear(), radius - sphere.getRadius()))

            w.trackball.node().setOrigin(sphere.getCenter())
            w.trackball.node().setPos(Vec3.forward() * distance)

            # Also set the movement scale on the trackball to be consistent
            # with the size of the model and the lens field-of-view.
            w.trackball.node().setForwardScale(distance * 0.006)
Пример #5
0
    def update(self, task=None):
        """
        Updates position of sounds in the 3D audio system. Will be called automatically
        in a task.
        """
        # Update the positions of all sounds based on the objects
        # to which they are attached

        # The audio manager is not active so do nothing
        if hasattr(self.audio_manager, "getActive"):
            if self.audio_manager.getActive()==0:
                return Task.cont

        for known_object in self.sound_dict.keys():
            tracked_sound = 0
            while tracked_sound < len(self.sound_dict[known_object]):
                sound = self.sound_dict[known_object][tracked_sound]
                pos = known_object.getPos(self.root)
                vel = self.getSoundVelocity(sound)
                sound.set3dAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2])
                tracked_sound += 1

        # Update the position of the listener based on the object
        # to which it is attached
        if self.listener_target:
            pos = self.listener_target.getPos(self.root)
            forward = self.listener_target.getRelativeVector(self.root, Vec3.forward())
            up = self.listener_target.getRelativeVector(self.root, Vec3.up())
            vel = self.getListenerVelocity()
            self.audio_manager.audio3dSetListenerAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], forward[0], forward[1], forward[2], up[0], up[1], up[2])
        else:
            self.audio_manager.audio3dSetListenerAttributes(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
        return Task.cont
    def enterNormal(self):
        self.notify.debug('enterNormal')
        self.setAnimState('Catching', 1.0)
        if self.isLocal:
            self.activity.orthoWalk.start()

        self.toon.lerpLookAt(Vec3.forward() + Vec3.up(),
                             time=0.20000000000000001,
                             blink=0)
Пример #7
0
    def update(self, task = None):
        if hasattr(self.audio_manager, 'getActive'):
            if self.audio_manager.getActive() == 0:
                return Task.cont
        for known_object in self.sound_dict.keys():
            tracked_sound = 0
            while tracked_sound < len(self.sound_dict[known_object]):
                sound = self.sound_dict[known_object][tracked_sound]
                pos = known_object.getPos(self.root)
                vel = self.getSoundVelocity(sound)
                sound.set3dAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2])
                tracked_sound += 1

        if self.listener_target:
            pos = self.listener_target.getPos(self.root)
            forward = self.listener_target.getRelativeVector(self.root, Vec3.forward())
            up = self.listener_target.getRelativeVector(self.root, Vec3.up())
            vel = self.getListenerVelocity()
            self.audio_manager.audio3dSetListenerAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2], forward[0], forward[1], forward[2], up[0], up[1], up[2])
        else:
            self.audio_manager.audio3dSetListenerAttributes(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1)
        return Task.cont
 def exitNormal(self):
     self.setAnimState('off', 1.0)
     if self.isLocal:
         self.activity.orthoWalk.stop()
     self.toon.lerpLookAt(Vec3.forward(), time=0.2, blink=0)
 def enterNormal(self):
     self.notify.debug('enterNormal')
     self.setAnimState('Catching', 1.0)
     if self.isLocal:
         self.activity.orthoWalk.start()
     self.toon.lerpLookAt(Vec3.forward() + Vec3.up(), time=0.2, blink=0)
Пример #10
0
 def exitNormal(self):
     self.setAnimState('off', 1.0)
     if self.isLocal:
         self.activity.orthoWalk.stop()
     self.toon.lerpLookAt(Vec3.forward(), time=0.2, blink=0)