Ejemplo n.º 1
0
    def build_world(self):
        # Labels
        #space.nodes["Text_Message"].string = [_("Touch all targets in order, man.")]

        # Sounds
        self.pop_sound = Sound("sounds/pop.wav", copies=3, intensity=0.5)

        # Gather target materials
        self.default_target_material = space.nodes["Material_DefaultTarget"]
        self.next_target_material = space.nodes["Material_NextTarget"]

        self.target_infos = []

        for i in range(NUMBER_OF_TARGETS):
            target = X3DFileNode("target.hgt")
            self.add_child(target)

            # Position the target according to the corresponding
            # empty in the scene.
            transform = target.find("Transform_TargetEmpty")
            empty_transform = space.nodes["Transform_BubbleEmpty.%03d" % i]
            transform.translation = empty_transform.translation

            appearance = target.find("Appearance_TargetHaptic")
            toggle = target.find("ToggleGroup_TargetHaptic")

            if i == 0:
                appearance.material = self.next_target_material.h3dNode
                #toggle.graphicsOn = True
                toggle.hapticsOn = True
            else:
                appearance.material = self.default_target_material.h3dNode
                #toggle.graphicsOn = False
                toggle.hapticsOn = False


            # Create target info
            target_info = {
                'target_id': i,
                'appearance': appearance,
                'done': False,
                'original_position': transform.translation,
                'toggle': toggle,
            }

            self.target_infos.append(target_info)

            # Bind touch
            evt = Event()
            evt.target_info = target_info

            bl = MFBoolListener(
                onTrue=self.touch_target,
                callbackObject=evt
            )

            target.find("Mesh_TargetHaptic").h3dNode.isTouched.routeNoEvent(bl)
Ejemplo n.º 2
0
    def add_mug(self, plate_info, color_index):
        assert (plate_info["base_plate"])
        assert (not plate_info["occupied"])
        #print "Adding color mug", color_index

        plate_info["occupied"] = True

        mug = X3DFileNode("mug.hgt")
        self.add_child(mug)

        mug.find("ToggleGroup_HapticMug").graphicsOn = False

        toggle = mug.find("ToggleGroup_MugEmpty")

        transform = mug.find("Transform_MugEmpty")
        transform.translation = plate_info['transform'].translation

        appearance = mug.find("Appearance_MugModel")
        appearance.material = space.nodes["Material_Mug%d" %
                                          color_index].h3dNode

        mesh = mug.find("Mesh_HapticMug")

        grabObject = self.grabber.register(
            transform=transform,
            toggle=toggle,
        )

        mug_info = {
            'color_index': color_index,
            'transform': transform,
            'appearance': appearance,
            'grabObject': grabObject,
            'toggle': toggle,
            'plate_info': plate_info,
            'finished': False,
        }
        evt = Event()
        evt.mug_info = mug_info
        bl = MFBoolListener(
            onTrue=self.touch_mug,
            callbackObject=evt,
        )
        mesh.h3dNode.isTouched.routeNoEvent(bl)

        plate_info["mug_info"] = mug_info
Ejemplo n.º 3
0
    def build_world(self):
        # Labels
        space.nodes["Text_Message"].string = [_("Touch all targets in order (1-2-3 ...)")]

        # Sounds
        self.correct_sound = Sound("sounds/correct.wav", copies=3, intensity=0.5)
        self.wrong_sound = Sound("sounds/wrong.wav", copies=3, intensity=0.5)

        # Gather target materials
        self.default_target_material = space.nodes["Material_DefaultTarget"]
        self.correct_target_material = space.nodes["Material_CorrectTarget"]
        self.wrong_target_material = space.nodes["Material_WrongTarget"]

        self.target_infos = []

        for i in range(NUMBER_OF_TARGETS):
            target = X3DFileNode("target.hgt")
            self.add_child(target)

            # Make the haptic part invisible
            target.find("ToggleGroup_TargetHaptic").graphicsOn = False

            # Set the label
            if ALPHANUMERIC_SEQUENCE:
                if i % 2 == 0:
                    label = str((i / 2) + 1)
                else:
                    label = chr(ord('A') + (i / 2))
            else:
                label = str(i + 1)
            target.find("Text_TargetLabel").string = [label]

            # Set outline appearance to default color (black)
            appearance = target.find("Appearance_TargetOutline")
            appearance.material = self.default_target_material.h3dNode

            # Position the target according to the corresponding
            # empty in the scene.
            transform = target.find("Transform_TargetEmpty")
            empty_transform = space.nodes["Transform_CircleEmpty.%03d" % i]
            transform.translation = empty_transform.translation

            # Create target info
            target_info = {
                'appearance': appearance,
                'done': False,
                'original_position': transform.translation,
                'target_id': i,
                'touched_this_round': False,
            }

            self.target_infos.append(target_info)

            # Bind touch
            evt = Event()
            evt.target_info = target_info

            bl = MFBoolListener(
                onTrue=self.touch_target,
                callbackObject=evt
            )

            target.find("Mesh_TargetHaptic").h3dNode.isTouched.routeNoEvent(bl)
Ejemplo n.º 4
0
    def build_world(self):
        self.force_field = hgn.ForceField()
        self.add_child(self.force_field)

        self.left_bucket_material = space.nodes["Material_LeftBucket"]
        self.right_bucket_material = space.nodes["Material_RightBucket"]

        self.fish_texture = hgn.ImageTexture(url="textures/fish0.jpg")

        # Fish
        self.fish_info = {}
        for i in range(self.fish_count):
            fishModel = X3DFileNode("fish0.x3d")
            fishShadow = X3DFileNode("fish_shadow.hgt")

            self.add_child(fishModel)
            dynamicTransform = fishModel.find("DynamicTransform_Fish")
            dynamicTransform.orientation = Rotation(1, 0, 0, 90 * DEG2RAD)
            dynamicTransform.orientation = Rotation(0, 0, 1, random.random() * math.pi) * dynamicTransform.orientation
            transform = fishModel.find("Transform_Fish")

            fish_appearance = fishModel.find("FISH_APPEARANCE")
            fish_appearance.texture = self.fish_texture.h3dNode

            foo = 0.02
            fish_x = (i / float(self.fish_count)) * (2 * foo) - foo

            fish_z = -0.10 + i * 0.0045
            transform.translation = Vec3f(fish_x, 0, fish_z)

            toggle = fishModel.find("ToggleGroup_Fish")

            dynamicTransform.add_child(fishShadow)
            fishShadow.find("Transform_Plane").translation = Vec3f(0, -0.11 - fish_z + i * 0.001, 0)
            grabObject = self.grabber.register(
                transform=transform,
                toggle=toggle,
            )

            info = {
                'fishId': i,
                'transform': transform,
                'grabObject': grabObject,
                'dynamicTransform': dynamicTransform,
                'transformInfo': fishModel.find("TransformInfo_Fish"),
                'swimming': True,
                'bumpTime': None,
                'toggle': toggle,
                'shadowToggle': fishShadow.find("ToggleGroup_Plane"),
            }
            self.fish_info[i] = info
            evt = Event()
            evt.info = info

            bl = MFBoolListener(
                onTrue=self.touch_fish,
                callbackObject = evt,
            )
            fishModel.find("TouchSphere").h3dNode.isTouched.routeNoEvent(bl)

        # Touching the aquarium glass
        bl = MFBoolListener(
            onTrue=self.touch_aquarium_glass,
            callbackObject = evt,
        )
        space.nodes["Mesh_InnerAquariumGlass"].h3dNode.isTouched.routeNoEvent(bl)

        bl = MFBoolListener(
            onTrue=self.touch_outer_aquarium_glass,
            callbackObject = evt,
        )
        space.nodes["Mesh_OuterAquariumGlass"].h3dNode.isTouched.routeNoEvent(bl)

        # Touching the enemies
        for i in range(self.number_of_enemies):
            evt = Event()
            evt.info = {
                'flasher': self.enemy_flashers[i]
            }
            bl = MFBoolListener(
                onTrue=self.touch_enemy,
                callbackObject = evt,
            )
            space.nodes["Mesh_EnemySphere.%03d" % i].h3dNode.isTouched.routeNoEvent(bl)
            space.nodes["ToggleGroup_EnemySphere.%03d" % i].graphicsOn = False
Ejemplo n.º 5
0
 def load_stylus_file(self, filename):
     stylus = X3DFileNode(filename)
     self.set_stylus(stylus.h3dNode)
Ejemplo n.º 6
0
 def load_stylus(self, stylusId):
     stylusPath = os.path.join(hgt.STYLUS_PATH, stylusId, 'stylus.hgt')
     stylus = X3DFileNode(stylusPath)
     self.set_stylus(stylus.h3dNode)
Ejemplo n.º 7
0
    def build_world(self):
        self.feedback_label = FeedbackLabel(
            topnode=self.node,
            text=space.nodes["Text_FeedbackLabel"],
            transform=space.nodes["Transform_FeedbackLabel"],
            material=space.nodes["Material_FeedbackLabel"],
            toggle=space.nodes["ToggleGroup_FeedbackLabel"],
        )

        self.button_infos = []

        self.button_material = space.nodes["Material_BingoButton"]
        self.pressed_button_material = space.nodes[
            "Material_BingoButtonPressed"]
        self.completed_button_material = space.nodes[
            "Material_BingoButtonCompleted"]
        self.bingo_button_material = space.nodes["Material_BingoButtonBingo"]

        space.nodes["Transform_ButtonAnchor"].scale = self.grid_scale * Vec3f(
            1, 1, 1)

        # Center buttons about x = 0
        c = ((self.square_size - 1) * self.button_spacing) / 2.0
        centering_vector = Vec3f(-c, 0, 0)

        for col in range(self.square_size):
            for row in range(self.square_size):
                index = col * self.square_size + row

                bb = X3DFileNode("bingobutton.hgt")
                space.nodes["Transform_ButtonAnchor"].add_child(bb)

                transform = bb.find("Transform_BingoButtonEmpty")
                mesh = bb.find("Mesh_BingoButtonMesh")
                appearance = bb.find("Appearance_BingoButton")
                appearance.material = self.button_material.h3dNode

                label = bb.find("Text_BingoLabel")

                # Put the button in position and mark it
                transform.translation += Vec3f(col * self.button_spacing,
                                               row * self.button_spacing,
                                               0) + centering_vector
                number = self.sequence[index]
                label.string = [str(number)]

                # Button touch listener
                info = {
                    'pressed': False,
                    'found': False,
                    'appearance': appearance,
                    'number': number,
                    'transform': transform,
                    'row': row,
                    'col': col,
                    'index': index,
                    'bingoed': False,
                }
                evt = Event()
                evt.info = info
                self.button_infos.append(info)
                bl = MFBoolListener(
                    onTrue=self.touch_button,
                    callbackObject=evt,
                )
                self.save_ref(bl)
                mesh.h3dNode.isTouched.routeNoEvent(bl)