def _update_obj(self, entity: Entity, state: PhysicsState, origin: Entity) -> None: # update planet objects self._obj.pos = entity.screen_pos(origin) / self._scale_factor self._obj.axis = calc.angle_to_vpy(entity.heading) # update label objects self._label.text = self._label_text(entity) self._label.pos = entity.screen_pos(origin) / self._scale_factor
def _update_obj(self, entity: Entity, state: PhysicsState, origin: Entity) -> None: # update planet objects self._obj.pos = entity.screen_pos(origin) self._obj.axis = calc.angle_to_vpy(entity.heading) # update label objects self._label.text = self._label_text(entity) self._label.pos = entity.screen_pos(origin) # update landing graphic objects self._update_landing_graphic(self._small_landing_graphic, entity, state.craft_entity()) self._update_landing_graphic(self._large_landing_graphic, entity, state.craft_entity())
def _create_obj(self, entity: Entity, origin: Entity, texture: Optional[str]) -> vpython.compound: """Creates the habitat, and also a new minimap scene and habitat.""" assert texture is not None habitat = self._create_hab(entity, texture) habitat.pos = entity.screen_pos(origin) main_scene = vpython.canvas.get_selected() self._minimap_canvas = vpython.canvas(width=200, height=150, userspin=False, userzoom=False, up=common.DEFAULT_UP, forward=common.DEFAULT_FORWARD) self._minimap_canvas.append_to_caption( # The element styling will be removed at runtime. This just hides # this helptext during startup. "<span class='helptext' style='display: none'>" "This small 'minimap' shows the Habitat's orientation. The red " "arrow represents the Hab's velocity relative to the reference, " "and the gray arrow points to position of the reference." "</span>") self._small_habitat = self._create_hab(entity, texture) self._ref_arrow = vpython.arrow(color=vpython.color.gray(0.5)) self._velocity_arrow = vpython.arrow(color=vpython.color.red) main_scene.select() self._broken: bool = False return habitat
def _create_obj(self, entity: Entity, origin: Entity, texture: Optional[str]) -> vpython.sphere: assert texture is not None earth = self._create_earth(entity, texture) earth.pos = entity.screen_pos(origin) earth.clouds.pos = earth.pos return earth
def _create_obj(self, entity: Entity, origin: Entity, texture: Optional[str]) -> vpython.sphere: return vpython.sphere(pos=entity.screen_pos(origin), axis=calc.angle_to_vpy(entity.heading), up=DEFAULT_UP, forward=DEFAULT_FORWARD, radius=entity.r, make_trail=True, retain=10000, texture=texture, bumpmap=vpython.bumpmaps.gravel, shininess=Planet.SHININIESS)
def _create_obj(self, entity: Entity, origin: Entity, texture: Optional[str]) -> vpython.sphere: return vpython.sphere( pos=entity.screen_pos(origin), axis=calc.angle_to_vpy(entity.heading), up=vpython.vector(0, 0, 1), # So the planet doesn't intersect the landing graphic radius=entity.r * 0.9, make_trail=True, retain=10000, texture=texture, bumpmap=vpython.bumpmaps.gravel, shininess=Planet.SHININIESS)
def _create_obj(self, entity: Entity, origin: Entity, texture: Optional[str]) -> vpython.sphere: main_body = vpython.box() side_panels = vpython.box(height=2, width=0.5, length=0.6) obj = vpython.compound([main_body, side_panels], make_trail=True, texture=texture, bumpmap=vpython.textures.gravel) obj.pos = entity.screen_pos(origin) obj.axis = calc.angle_to_vpy(entity.heading) obj.length = entity.r * 2 obj.height = entity.r * 2 obj.width = entity.r * 2 # A compound object doesn't actually have a radius, but we need to # monkey-patch this for when we recentre the camera, to determine the # relevant_range of the space station obj.radius = entity.r return obj
def _create_obj(self, entity: Entity, origin: Entity, texture_path: Optional[str]) -> vpython.sphere: ship = vpython.cone(pos=vpython.vector(5, 0, 0), axis=vpython.vector(5, 0, 0), radius=3) entrance = vpython.extrusion( path=[vpython.vec(0, 0, 0), vpython.vec(4, 0, 0)], shape=[ vpython.shapes.circle(radius=3), vpython.shapes.rectangle(pos=[0, 0], width=0.5, height=0.5) ], pos=vpython.vec(3, 0, 0)) docking_arm = vpython.extrusion( path=[ vpython.vec(0, 0, 0), vpython.vec(1.5, 0, 0), vpython.vec(1.5, 0.5, 0) ], shape=[vpython.shapes.circle(radius=0.03)]) obj = vpython.compound([ship, entrance, docking_arm], make_trail=True, texture=vpython.textures.metal, bumpmap=vpython.bumpmaps.gravel) obj.pos = entity.screen_pos(origin) obj.axis = calc.angle_to_vpy(entity.heading) obj.length = entity.r * 2 obj.height = entity.r * 2 obj.width = entity.r * 2 # A compound object doesn't actually have a radius, but we need to # monkey-patch this for when we recentre the camera, to determine the # relevant_range of the space station obj.radius = entity.r return obj
def _update_obj(self, entity: Entity, state: PhysicsState, origin: Entity): super()._update_obj(entity, state, origin) self._obj.boosters.pos = self._obj.pos self._obj.boosters.axis = self._obj.axis # Attach the parachute to the forward cone of the habitat. self._obj.parachute.pos = ( self._obj.pos + calc.angle_to_vpy(entity.heading) * entity.r * 0.8) parachute_is_visible = ((state.craft == entity.name) and state.parachute_deployed) if parachute_is_visible: drag = calc.drag(state) drag_mag = np.inner(drag, drag) for parachute in [self._obj.parachute, self._small_habitat.parachute]: if not parachute_is_visible or drag_mag < 0.00001: # If parachute_is_visible == False, don't show the parachute. # If the drag is basically zero, don't show the parachute. parachute.visible = False continue if drag_mag > 0.1: parachute.width = self.PARACHUTE_RADIUS * 2 parachute.height = self.PARACHUTE_RADIUS * 2 else: # Below a certain threshold the parachute deflates. parachute.width = self.PARACHUTE_RADIUS parachute.height = self.PARACHUTE_RADIUS parachute.axis = -vpython.vec(*drag, 0) parachute.visible = True if not self._broken and entity.broken: # We weren't broken before, but looking at new data we realize # we're now broken. Change the habitat texture. new_texture = self._obj.texture.replace('Habitat.jpg', 'Habitat-broken.jpg') assert new_texture != self._obj.texture, \ f'{new_texture!r} == {self._obj.texture!r}' self._obj.texture = new_texture self._small_habitat.texture = new_texture self._broken = entity.broken elif self._broken and not entity.broken: # We were broken before, but we've repaired ourselves somehow. new_texture = self._obj.texture.replace('Habitat-broken.jpg', 'Habitat.jpg') assert new_texture != self._obj.texture, \ f'{new_texture!r} == {self._obj.texture!r}' self._obj.texture = new_texture self._small_habitat.texture = new_texture self._broken = entity.broken # Set reference and target arrows of the minimap habitat. same = state.reference == entity.name default = vpython.vector(0, 0, -1) ref_arrow_axis = (entity.screen_pos(state.reference_entity()).norm() * entity.r * -1.2) v = entity.v - state.reference_entity().v velocity_arrow_axis = \ vpython.vector(*v, 0).norm() * entity.r self._ref_arrow.axis = default if same else ref_arrow_axis self._velocity_arrow.axis = default if same else velocity_arrow_axis self._small_habitat.axis = self._obj.axis self._small_habitat.boosters.axis = self._obj.axis # Invisible-ize the SRBs if we ran out. if state.srb_time == common.SRB_EMPTY and self._obj.boosters.visible: self._obj.boosters.visible = False self._small_habitat.boosters.visible = False