Exemplo n.º 1
0
def create(ship_position=(0, 0, 0)):
    """Create a HexShip entity."""
    # Initialize OGRE graphical representation.
    ship_id = entitysystem.create_entity()
    logging.debug("HexShip id: " + str(ship_id) + "   pos: (" +
                    str(ship_position[0]) + ", " +
                    str(ship_position[1]) + ", " +
                    str(ship_position[2]) + ")"
                  )

    ogre_entity = application.ogre_scene_manager.createEntity(
                          'ogreEntity-' + str(ship_id), 'HexCell.mesh')
    ogre_node = application.ogre_root_node.createChildSceneNode(
                          'ogreNode-' + str(ship_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(True)
    ogre_node.setScale(ogre.Vector3(1.0, 1.0, 1.0))
    entitysystem.add_component( ship_id,
                                entitysystem.ComponentTypes.Graphics,
                                ogre_node)

    # Initialize physics.
    collision_object = OgreBulletUtils.CollisionObject(application.bullet_world)
    collision_object.setShape(OgreBulletUtils.MeshInfo.createCylinderShape(
                                            ogre_entity,
                                            OgreBulletUtils.BulletShapes.CYLINDERZ))
    collision_object.setTransform(bullet.btVector3( ship_position[0],
                                                    ship_position[1],
                                                    ship_position[2]))
    collision_object.setMass(1.0)
    collision_object.setInertia(bullet.btVector3(0.0, 0.0, 0.0))
    collision_object.setMotion(ogre_entity.getParentSceneNode())
    entitysystem.add_component( ship_id,
                                entitysystem.ComponentTypes.Physics,
                                collision_object)
Exemplo n.º 2
0
def create(ship_position=(0, 0, 0)):
    """Create a HexShip entity."""
    # Initialize OGRE graphical representation.
    ship_id = entitysystem.create_entity()
    logging.debug("HexShip id: " + str(ship_id) + "   pos: (" +
                  str(ship_position[0]) + ", " + str(ship_position[1]) + ", " +
                  str(ship_position[2]) + ")")

    ogre_entity = application.ogre_scene_manager.createEntity(
        'ogreEntity-' + str(ship_id), 'HexCell.mesh')
    ogre_node = application.ogre_root_node.createChildSceneNode('ogreNode-' +
                                                                str(ship_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(True)
    ogre_node.setScale(ogre.Vector3(1.0, 1.0, 1.0))
    entitysystem.add_component(ship_id, entitysystem.ComponentTypes.Graphics,
                               ogre_node)

    # Initialize physics.
    collision_object = OgreBulletUtils.CollisionObject(
        application.bullet_world)
    collision_object.setShape(
        OgreBulletUtils.MeshInfo.createCylinderShape(
            ogre_entity, OgreBulletUtils.BulletShapes.CYLINDERZ))
    collision_object.setTransform(
        bullet.btVector3(ship_position[0], ship_position[1], ship_position[2]))
    collision_object.setMass(1.0)
    collision_object.setInertia(bullet.btVector3(0.0, 0.0, 0.0))
    collision_object.setMotion(ogre_entity.getParentSceneNode())
    entitysystem.add_component(ship_id, entitysystem.ComponentTypes.Physics,
                               collision_object)
Exemplo n.º 3
0
def create():
    """Create a procedural Terrain entity."""
    terrain_id = entitysystem.create_entity()
    logging.debug('Terrain id: ' + str(terrain_id))

    # Map the terrain onto an Ogre mesh
    width = height = 100
    offsetX = width / 2.0
    offsetY = height / 2.0
    terrain_object = ogre.ManualObject('Manual-' + str(terrain_id))
    terrain_object.estimateVertexCount(width * height)
    terrain_object.estimateIndexCount(width * height)

    # Generate heights and input the indices into OGRE.
    terrain_object.begin(
                        "Terrain_Azul",
                        ogre.RenderOperation.OT_TRIANGLE_LIST
                    )
    for row in range(height):
        for column in range(width):
            terrain_height = simplexnoise.scaled_octave_noise_2d(
                                3, 0.3, 0.05,    # Noise settings
                                -20, 0,          # Height range
                                column - offsetX,
                                row - offsetY
                            )
            terrain_object.position(
                                    column - offsetX,   # x
                                    terrain_height,     # y
                                    row - offsetY       # z
                                )
            #XXX: these normals are fake and will break lighting
            terrain_object.normal(0, 1, 0)
            terrain_object.colour(
                                    abs(terrain_height/20),
                                    abs(terrain_height/20),
                                    abs(terrain_height/20),
                                    1
                                )

    # Build a mesh of vertices.
    vertexID = 0
    for strip in range(height - 1):
        for quad in range(width - 1):
            terrain_object.quad(vertexID,             # top-left
                                vertexID + width,     # bottom-left
                                vertexID + width + 1, # bottom-right
                                vertexID + 1          # top-right
                                )
            vertexID += 1
        vertexID += 1
    terrain_object.end()

    # Attach mesh to OGRE scene.
    terrain_object.convertToMesh('Mesh-' + str(terrain_id))
    ogre_entity = application.ogre_scene_manager.createEntity(
                            'ogreEntity-' + str(terrain_id),
                            'Mesh-' + str(terrain_id)
                        )
    ogre_node = application.ogre_root_node.createChildSceneNode(
                            'ogreNode-' + str(terrain_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(False)
    entitysystem.add_component( terrain_id,
                                entitysystem.ComponentTypes.Graphics,
                                ogre_node)

    # Setup terrain collisions.
    collision_object = OgreBulletUtils.CollisionObject(application.bullet_world)
    triangle_mesh, collision_shape = OgreBulletUtils.MeshInfo.createTriMeshShape(ogre_entity)
    collision_object.setShape(collision_shape)
    collision_object.setMotion(None)
    entitysystem.add_component( terrain_id,
                                entitysystem.ComponentTypes.Physics,
                                (collision_object, triangle_mesh))
Exemplo n.º 4
0
def create():
    """Create a procedural Terrain entity."""
    terrain_id = entitysystem.create_entity()
    logging.debug('Terrain id: ' + str(terrain_id))

    # Map the terrain onto an Ogre mesh
    width = height = 100
    offsetX = width / 2.0
    offsetY = height / 2.0
    terrain_object = ogre.ManualObject('Manual-' + str(terrain_id))
    terrain_object.estimateVertexCount(width * height)
    terrain_object.estimateIndexCount(width * height)

    # Generate heights and input the indices into OGRE.
    terrain_object.begin("Terrain_Azul", ogre.RenderOperation.OT_TRIANGLE_LIST)
    for row in range(height):
        for column in range(width):
            terrain_height = simplexnoise.scaled_octave_noise_2d(
                3,
                0.3,
                0.05,  # Noise settings
                -20,
                0,  # Height range
                column - offsetX,
                row - offsetY)
            terrain_object.position(
                column - offsetX,  # x
                terrain_height,  # y
                row - offsetY  # z
            )
            #XXX: these normals are fake and will break lighting
            terrain_object.normal(0, 1, 0)
            terrain_object.colour(abs(terrain_height / 20),
                                  abs(terrain_height / 20),
                                  abs(terrain_height / 20), 1)

    # Build a mesh of vertices.
    vertexID = 0
    for strip in range(height - 1):
        for quad in range(width - 1):
            terrain_object.quad(
                vertexID,  # top-left
                vertexID + width,  # bottom-left
                vertexID + width + 1,  # bottom-right
                vertexID + 1  # top-right
            )
            vertexID += 1
        vertexID += 1
    terrain_object.end()

    # Attach mesh to OGRE scene.
    terrain_object.convertToMesh('Mesh-' + str(terrain_id))
    ogre_entity = application.ogre_scene_manager.createEntity(
        'ogreEntity-' + str(terrain_id), 'Mesh-' + str(terrain_id))
    ogre_node = application.ogre_root_node.createChildSceneNode(
        'ogreNode-' + str(terrain_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(False)
    entitysystem.add_component(terrain_id,
                               entitysystem.ComponentTypes.Graphics, ogre_node)

    # Setup terrain collisions.
    collision_object = OgreBulletUtils.CollisionObject(
        application.bullet_world)
    triangle_mesh, collision_shape = OgreBulletUtils.MeshInfo.createTriMeshShape(
        ogre_entity)
    collision_object.setShape(collision_shape)
    collision_object.setMotion(None)
    entitysystem.add_component(terrain_id, entitysystem.ComponentTypes.Physics,
                               (collision_object, triangle_mesh))