Example #1
0
    def Set_Perspective(self,
                        camname,
                        follow_module_name=False,
                        follow_position=[1.5, 0.75, 0],
                        follow_distance=0,
                        cycle=False,
                        cycle_laptime=4,
                        follow_height=0.5):
        '''Sets the camera perspective configuration for the simulation. Available perspectives depend on the MiroEnvironment used.'''
        self.follow_distance = follow_distance
        self.follow_height = follow_height
        if cycle:
            self.cycle = True
            self.cycle_angle = -2 * np.pi / cycle_laptime
        if camname == 'follow_default':
            if not follow_module_name:
                print(
                    'Camera Error: Input a module name to use follow perspective, using default'
                )
            else:
                if follow_module_name in self.modules:
                    self.follow_default = True
                    self.followmod = self.modules[follow_module_name]
                    self.cam_to_obs = -np.array(follow_position)
                    self.obs_pos = self.followmod.GetCenterOfMass()
                    self.cam_pos = self.obs_pos - self.cam_to_obs
                    if follow_distance > 0:
                        self.cam_to_obs = self.cam_to_obs / np.linalg.norm(
                            self.cam_to_obs) * follow_distance
                else:
                    print(
                        'Camera Error: "' + follow_module_name +
                        '" is not a recognized module and cannot be followed, using default'
                    )
        elif camname in self.camviews:
            cam = self.camviews[camname]
            self.cam_pos = np.array(cam['pos'])
            self.cam_to_obs = np.array(cam['dir']) / np.linalg.norm(
                np.array(cam['dir']))
            self.cam_to_obs = self.cam_to_obs * cam['lah']
            self.obs_pos = self.cam_pos + self.cam_to_obs
        else:
            if cycle:
                print('Camera Error: "' + camname +
                      '" is not a recognized camera position, cycling default')
            else:
                print('Camera Error: "' + camname +
                      '" is not a recognized camera position, using default')

        MiroAPI.SetCamera(self.system_list, self.cam_pos, self.obs_pos)
Example #2
0
    def Set_Camera(self):
        '''This sets the camera during simulation. For internal usage when the simulation is being run, 
        use SetPerspective to configure the camera before running the simulation.'''
        if self.freecam:
            return
        if self.cycle:
            self.cam_to_obs = MiroAPI.rotateVector(self.cam_to_obs,
                                                   self.cycle_angle / self.fps,
                                                   [0, 1, 0],
                                                   rotDegrees=False)
            self.cam_to_obs = (49 * self.cam_to_obs +
                               self.followmod.GetCenterOfMassVelocity()) / 50
            self.cam_to_obs = self.cam_to_obs / np.linalg.norm(self.cam_to_obs)
            self.cam_pos = self.obs_pos - self.cam_to_obs
            MiroAPI.SetCamera(self.system_list, self.cam_pos, self.obs_pos)

        if self.follow_default:

            if np.linalg.norm(self.followmod.GetCenterOfMassVelocity()) > 1e-2:

                #oldest working
                #cam_to_obs[0] = cam_to_obs[0] * np.cos(self.follow_angle)
                #cam_to_obs[1] = cam_to_obs[0] * np.sin(self.follow_angle)
                #cam_to_obs[2] = cam_to_obs[2] * np.cos(self.follow_angle)
                self.obs_pos = (12 * self.obs_pos +
                                self.followmod.GetCenterOfMass()) / 13
                self.cam_up = (9 * self.cam_up + np.array([0, 1, 0])) / 10

                cam_to_obs = (
                    self.followmod.GetCenterOfMassVelocity() /
                    np.linalg.norm(self.followmod.GetCenterOfMassVelocity()))
                cam_to_obs *= self.follow_distance
                cam_pos = self.obs_pos - self.cam_to_obs
                cam_pos[1] += self.follow_height

                self.cam_pos = (9 * self.cam_pos +
                                cam_pos) / 10  # good val = 1/2
                MiroAPI.SetCamera(self.system_list, self.cam_pos, self.obs_pos,
                                  self.cam_up)

                cam_to_obs = (49 * self.cam_to_obs + cam_to_obs) / (49 + 1)

                self.cam_to_obs = cam_to_obs

        if self.camera_sweep:
            i = self.sweepstep
            sweep_divs = 100
            self.cam_pos = (
                (sweep_divs - i) * self.sweep_cam[self.sweepnr - 1] +
                (i) * self.sweep_cam[self.sweepnr]) / sweep_divs
            self.obs_pos = (
                (sweep_divs - i) * self.sweep_obs[self.sweepnr - 1] +
                (i) * self.sweep_obs[self.sweepnr]) / sweep_divs
            MiroAPI.SetCamera(self.system_list, self.cam_pos, self.obs_pos)
            self.sweepstep += 1
            if self.sweepstep > sweep_divs:
                self.sweepstep = 0
                self.sweepnr += 1
            if self.sweepnr >= self.sweepsteps:
                self.camera_sweep = False

        if not self.cycle and not self.follow:
            return