示例#1
0
    def setup(self):
        super(GameControllerNode, self).setup()
        # set up
        window = WindowNode(name='window', parent=self)
        window.open()
        window.make_context_current()

        gl.init()
        err = gl.getError()
        if err:
            print("WINDOW OPEN ERROR:", err)

        scene = SceneNode(name='scene', parent=window) # scenenode.SceneNode(name='scene')

        debugdraw_renderer = debugdraw.RendererNode(name='debugdraw_renderer', parent=scene)
        sprite_renderer = spritenode.RendererNode(name="sprite_renderer", parent=scene)

        camera_transform = transformnode.TransformNode3D(name='camera_transform', parent=scene, m=Mat4.Translation(Vec3(0.0, 0.0, 3.0)))
        camera = debugdraw.CameraNode(name='camera', parent=camera_transform)
        camera.make_current()
        camera_controller = CameraController(input_map=InputMap(), parent=camera_transform)

        grid = debugdraw.ShapeNode.Grid(1.0, 100, 100, name='grid', parent=scene)
        aabb = AABB3()
        aabb.include_point(Vec3(0.0, 0.0, 0.0))
        aabb.include_point(Vec3(1.0, 2.0, 3.0))
        box = debugdraw.ShapeNode.AABB3(aabb, parent=scene, mode=gl.TRIANGLES)

        window.on('key', self.key_callback)

        gl.enable(gl.DEPTH_TEST)
        gl.enable(gl.BLEND)
        gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
示例#2
0
    def setup(self):
        super(GameControllerNode, self).setup()
        # set up
        window = WindowNode(name='window', parent=self)
        window.open()
        window.make_context_current()

        gl.init()
        err = gl.getError()
        if err:
            print("WINDOW OPEN ERROR:", err)

        scene = physicsnode.SceneNode(name='scene', parent=window) # scenenode.SceneNode(name='scene')

        debugdraw_renderer = debugdraw.RendererNode(name='debugdraw_renderer', parent=scene)
        sprite_renderer = spritenode.RendererNode(name="sprite_renderer", parent=scene)

        camera_transform = transformnode.TransformNode3D(name='camera_transform', parent=scene, m=Mat4.Translation(Vec3(0.0, 0.0, 3.0)))
        camera = debugdraw.CameraNode(name='camera', parent=camera_transform)
        camera.make_current()
        # camera_controller = CameraController(input_map=InputMap(), parent=camera_transform)

        # create_wheelchair_guy(scene)
        create_ship(scene)

        window.on('key', self.key_callback)

        gl.enable(gl.DEPTH_TEST)
        gl.enable(gl.BLEND)
        gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
示例#3
0
    def setup(self):
        super(GameControllerNode, self).setup()
        # set up
        window = WindowNode(name='window', parent=self)
        window.open()
        window.make_context_current()

        gl.init()
        err = gl.getError()
        if err:
            print("WINDOW OPEN ERROR:", err)

        scene = SceneNode(name='scene', parent=window) # scenenode.SceneNode(name='scene')

        debugdraw_renderer = debugdraw.RendererNode(name='debugdraw_renderer', parent=scene)
        sprite_renderer = spritenode.RendererNode(name="sprite_renderer", parent=scene)

        camera_transform = transformnode.TransformNode3D(name='camera_transform', parent=scene, m=Mat4.Translation(Vec3(0.0, 0.0, 3.0)))
        camera = debugdraw.CameraNode(name='camera', parent=camera_transform)
        camera.make_current()
        # camera_controller = CameraController(input_map=InputMap(), parent=camera_transform)

        window.on('key', self.key_callback)

        gl.enable(gl.DEPTH_TEST)
        gl.enable(gl.BLEND)
        gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

        updater = BoundsUpdater(parent=scene, name='updater')


        b0 = BodyNode(position=(0.0, -1.0), velocity=(0.0, 0.1), angle=0.0, angular_velocity=0.0, name="body0", parent=scene)
        b1 = BodyNode(position=(0.0, 1.0), velocity=(0.0, -0.1), angle=0.0, angular_velocity=0.0, name="body1", parent=scene)

        shape = CircleShapeNode(radius=0.1, center=(0.0, 0.0), name='shap0', parent=b0)
        shape_debugdraw = debugdraw.ShapeNode.Circle(radius=0.1, center=shape.center, nverts=8, name='draw_shape0', parent=shape)

        shape = CircleShapeNode(radius=0.1, center=(0.0, 0.0), name='shape1', parent=b1)
        shape_debugdraw = debugdraw.ShapeNode.Circle(radius=0.1, center=shape.center, nverts=8, name='draw_shape1', parent=shape)

        return

        # random scene
        NVERTS = 8
        for i in range(5):
            ANGULAR_VELOCITY = 2.0
            body = BodyNode(
                position=(random.uniform(-1.0, 1.0), random.uniform(-1.0, 1.0)),
                velocity=(random.uniform(-0.1, 0.1), random.uniform(-0.1, 0.1)), 
                angle=random.uniform(-math.pi, math.pi),
                angular_velocity=random.uniform(-ANGULAR_VELOCITY*math.pi, ANGULAR_VELOCITY*math.pi),
                name='body%s' % i,
                parent=scene
            )

            for j in range(3):
                if random.uniform(0.0, 1.0) < 1.0:
                    shape = CircleShapeNode(radius=0.1, center=(random.uniform(-0.2, 0.2), random.uniform(-0.2, 0.2)), name='shape%i'%j, parent=body)
                    shape_debugdraw = debugdraw.ShapeNode.Circle(radius=0.1, center=shape.center, nverts=NVERTS, name='draw_shape%i'%j, parent=shape)
                else:
                    transform = Transform(Vec2(random.uniform(-0.2, 0.2), random.uniform(-0.2, 0.2)), random.uniform(-math.pi, math.pi))
                    w = random.uniform(0.1, 0.2) * 0.5
                    h = random.uniform(0.1, 0.2) * 0.5
                    vertices = [Vec2(w, h), Vec2(-w, h), Vec2(-w, -h), Vec2(w, -h)]
                    radius = 0.1
                    nverts = 20
                    step = math.pi * 2.0 / nverts
                    center = Vec2()
                    #vertices = [Vec2(math.cos(step*i)*radius+center.x, math.sin(step*i)*radius+center.y) for i in range(nverts)]
                    vertices = [transform.apply(v) for v in vertices]
                    shape = PolygonShapeNode(vertices, name='shape%i'%j, parent=body)
                    m = math.pi * radius * radius
                    print("M:", shape.compute_mass(), m, m * 0.5 * math.pi * radius * radius)
                    color = (1.0, 1.0, 1.0)
                    #draw_vertices = [(Vec3(v.x, v.y, 0.0), color) for v in vertices]
                    draw_vertices = []
                    for i, v in enumerate(vertices):
                        v0 = vertices[(i-1)%len(vertices)]
                        draw_vertices.append((Vec3(v0.x, v0.y, 0.0), color))
                        draw_vertices.append((Vec3(v.x, v.y, 0.0), color))
                    shape_debugdraw = debugdraw.ShapeNode(vertices=draw_vertices, name='draw_shape%i'%j, parent=body)
示例#4
0
	def testWindowSize(self):
		window = WindowNode()
		window.open()
		window.window_size = (640, 480)
		self.assertEqual(window.window_size, (640, 480))
示例#5
0
	def testSetWindowSize(self):
		window = WindowNode()
		window.open()
		window.set_window_size(640, 480)
		self.assertEqual(window.get_window_size(), (640, 480))
示例#6
0
	def testClose(self):
		window = WindowNode()
		window.open()
		window.close()
		self.assertEqual(window.window, None)
示例#7
0
	def testOpen(self):
		window = WindowNode()
		window.open()
		self.assertEqual(window.get_window_size(), WindowNode.DEFAULT_RESOLUTION)