示例#1
0
 def _get_centre_position(self):
     return CubeSphereMap.get_sphere_position(self._centre_coords[0], 
                                              self._centre_coords[1], 
                                              self._face,
                                              self._sphere_parent.radius)
示例#2
0
    def update_sphere(self):
        
#        start = datetime.now()
        
        if (datetime.now() - self._last_time).total_seconds() > 0.1:
        
            if self._ui.track_camera:
            
                if self._camera is None:
                    self._camera = SceneManager.get_instance().current_scene.active_camera

                # Store the camera pos for access by the quad children
                self._camera_pos = self._camera.node_parent.transform.position - self.transform.position

                self._camera_pos_sc = CubeSphereMap.get_cube_coord(self._camera_pos.x, self._camera_pos.y, self._camera_pos.z) 
                
                self._line.line_to(self._camera_pos)


                if self._ui.planet_camera:
                    # Check if the camera has intersected the planet.
                    if self._camera_pos.magnitude() < (self._radius + self._max_height):
                        u = self._camera_pos_sc.x
                        v = self._camera_pos_sc.y
                        face = self._camera_pos_sc.face
                        self._camera.node_parent.transform.position = CubeSphereMap.get_sphere_position(u, v, face, (self._radius + self._max_height))

                
                # Reset the number of splits
                self._num_splits = 0
                #print "Resetting splits"
                
                # If the camera has moved a sufficient distance to warrant an update
    #            if self._last_camera_pos is None:
    #                self._last_camera_pos = self._camera_pos
    #            dist = self._last_camera_pos - self._camera_pos 
    #            if dist.magnitude() > 1.0:
                    
                # Calc the horizon
                altitude = self._camera_pos.magnitude()
                horizon_altitude = max([altitude-self.radius, self.max_height])
                self._horizon = math.sqrt(horizon_altitude * horizon_altitude + 2.0 * horizon_altitude * self._radius)
                
                if True:
                    # Update all of the sides of the cube/sphere
                    for child in self.transform.children:
                        if isinstance(child.node, SphereQuad):
                            child.node.update_surface()
                        
                self._last_camera_pos = self._camera_pos
                        
                self._last_time = datetime.now()
                
                # Update the UI with the camera pos
    #            self._ui.rel_camera_pos = self._camera_pos
    #            self._ui.camera_pos = self._camera_pos_sc

                if not self._camera_pos_sc is None:
                    pos = CubeSphereMap.get_sphere_vector(self._camera_pos_sc.x, self._camera_pos_sc.y, self._camera_pos_sc.face)
                    pos.normalize()
                    pos *= (self._radius / 1.9)
                    self._camera_gizmo.transform.position = pos
示例#3
0
    def _calc_corners(self):
        # Calculate the Cubic coordinates of this quad
        x0, y0, x1, y1, face = CubeSphereMap.get_address_bounds(self._name)

        self._corners = [x0, y0, x1, y1]
        self._centre_coords = CubeSphereMap.get_address_centre(self._name)
        self._quad_centres = [
                                CubeSphereMap.get_address_centre(self._name+'A'),
                                CubeSphereMap.get_address_centre(self._name+'B'),
                                CubeSphereMap.get_address_centre(self._name+'D'),
                                CubeSphereMap.get_address_centre(self._name+'C')
                             ]

        # if self._root:
        #     self._corners.append(0.0) #tl x
        #     self._corners.append(0.0) #tl y
        #     self._corners.append(1.0) #br x
        #     self._corners.append(1.0) #br y
        # else:
        #     parent_corners = self.transform.parent.node.corners
            
        #     if self._quad == QuadName.TL:
        #         self._corners.append(parent_corners[0])
        #         self._corners.append(parent_corners[1])
        #         self._corners.append(parent_corners[0] + (parent_corners[2] - parent_corners[0]) * 0.5 )
        #         self._corners.append(parent_corners[1] + (parent_corners[3] - parent_corners[1]) * 0.5 )
                
        #     elif self._quad == QuadName.TR:
        #         self._corners.append(parent_corners[0] + (parent_corners[2] - parent_corners[0]) * 0.5)
        #         self._corners.append(parent_corners[1])
        #         self._corners.append(parent_corners[2])
        #         self._corners.append(parent_corners[1] + (parent_corners[3] - parent_corners[1]) * 0.5 )
                
        #     elif self._quad == QuadName.BL:
        #         self._corners.append(parent_corners[0])
        #         self._corners.append(parent_corners[1] + (parent_corners[3] - parent_corners[1]) * 0.5)
        #         self._corners.append(parent_corners[0] + (parent_corners[2] - parent_corners[0]) * 0.5)
        #         self._corners.append(parent_corners[3])
                
            
        #     elif self._quad == QuadName.BR:
        #         self._corners.append(parent_corners[0] + (parent_corners[2] - parent_corners[0]) * 0.5)
        #         self._corners.append(parent_corners[1] + (parent_corners[3] - parent_corners[1]) * 0.5)
        #         self._corners.append(parent_corners[2])
        #         self._corners.append(parent_corners[3])
                
                
        # mid_x = (self._corners[2] - self._corners[0]) / 2
        # mid_y = (self._corners[3] - self._corners[1]) / 2
        
        # self._centre_coords = [(self._corners[0] + mid_x), (self._corners[1] + mid_y)]
        
        # self._quad_centres = [ [self._corners[0] + (mid_x/2), self._corners[1] + (mid_y/2)], #TL
        #                        [self._corners[2] - (mid_x/2), self._corners[1] + (mid_y/2)], #TR
        #                        [self._corners[2] - (mid_x/2), self._corners[3] - (mid_y/2)], #BR
        #                        [self._corners[0] + (mid_x/2), self._corners[3] - (mid_y/2)]  #BL
        #                      ]
        
        # Get world positions for centres of child quads
        self._child_pos = [CubeSphereMap.get_sphere_position(self._quad_centres[QuadName.TL][0],
                                                               self._quad_centres[QuadName.TL][1],
                                                               self._face,
                                                               self._sphere_parent.radius),
                             CubeSphereMap.get_sphere_position(self._quad_centres[QuadName.TR][0],
                                                               self._quad_centres[QuadName.TR][1],
                                                               self._face,
                                                               self._sphere_parent.radius),
                             CubeSphereMap.get_sphere_position(self._quad_centres[QuadName.BR][0],
                                                               self._quad_centres[QuadName.BR][1],
                                                               self._face,
                                                               self._sphere_parent.radius),
                             CubeSphereMap.get_sphere_position(self._quad_centres[QuadName.BL][0],
                                                               self._quad_centres[QuadName.BL][1],
                                                               self._face,
                                                               self._sphere_parent.radius),
                             ]