Ejemplo n.º 1
0
    def _gen_verts(self, address):
        bound_min_x, bound_min_z, bound_max_x, bound_max_z, face = CubeSphereMap.get_address_bounds(address)

        verts = []
        noise_x = []

        h_height = self._max_height / 2.0

        for i in xrange(self._increments + 1):
            #c = i * (1.0 / self._increments)
            c = (i * ( (bound_max_x - bound_min_x) / float(self._increments) ) ) + bound_min_x
            nv = []

            noise_y = []
            for j in xrange(self._increments + 1):
                #r = j * ( 1.0 / self._increments )
                r = (j * ( (bound_max_z - bound_min_z) / float(self._increments) ) ) + bound_min_z
                
                p = CubeSphereMap.get_sphere_vector(c, r, face) * self._radius
                
                n = Vector3()#c, r, -1) * self._radius
                if True:
                
                    u = c
                    v = r
                    u = (u * 2.0) - 1.0
                    v = (v * 2.0) - 1.0
                    if face == CubeSphereMap.BACK:
                        n = Vector3(-u, -v, -1) * self._radius
                    elif face == CubeSphereMap.LEFT:
                        n = Vector3(-1, -v, u) * self._radius
                    elif face == CubeSphereMap.RIGHT:
                        n = Vector3(1, -v, -u) * self._radius
                    elif face == CubeSphereMap.TOP:
                        n = Vector3(u, 1, v) * self._radius
                    elif face == CubeSphereMap.BOTTOM:
                        n = Vector3(u, -1, -v) * self._radius
                    elif face == CubeSphereMap.FRONT:
                        n = Vector3(u, -v, 1) * self._radius
                else:
                # Adjust the surface level using noise
                    n = p.copy()

                # if face == CubeSphereMap.RIGHT:
                #     n.x = self._radius
                # elif face == CubeSphereMap.LEFT:
                #     n.x = -self._radius
                # elif face == CubeSphereMap.TOP:
                #     n.y = self._radius
                # elif face == CubeSphereMap.BOTTOM:
                #     n.y = -self._radius
                # elif face == CubeSphereMap.FRONT:
                #     n.z = self._radius
                # elif face == CubeSphereMap.BACK:
                #     n.z = -self._radius

                frac = self._get_noise(n)
                
                # if i == 0 and j == 0:
                #     frac = 5.0
                # if i == self._increments and j == self._increments:
                #     frac = 10.0

                # if j in [4, 6, 8, 20, 25, 30]:
                #     frac = 1
                # else:
                #     frac = -1

                # if i in [5,6,20,21]:
                #     frac = 1

                #noise.append(frac)
                noise_y.append(frac)

                nv.append(frac)
                #h = noise * self._max_height
                h = (frac * h_height ) + h_height
                
                # Increase the surface vector by the noise value
                n = p.normalized()
                n *= h

                p += n

                verts.append((p.x, p.y, p.z))
            # s = ""
            # for n in nv:
            #     s += "\t%0.3f," % n
            # print s
            noise_x.append(noise_y)
        return verts, noise_x
Ejemplo n.º 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