Beispiel #1
0
    def _create(self, scene, shape_type, shape_props, mass, center_of_mass, 
                inertia, position, orientation):
        # Create Collision Object
        # TODO: Improve collision support
        col = None
        if shape_type == 'box':
            size = sim.OgreVector3(shape_props['size'])
            col = OgreNewt.Box(scene.world, size)
        elif shape_type == 'cylinder':
            col = OgreNewt.Cylinder(scene.world, shape_props['radius'], 
                                    shape_props['height'])
        elif shape_type == 'mesh':
            # Fix this by later (we shouldn't need a node!!!)
            name = 'TREE_HACK' + str(Body._tree_mesh_hack)
            Body._tree_mesh_hack += 1
            mesh_name = shape_props['mesh_name']
            scale = sim.OgreVector3(shape_props.get('mesh_scale',
                                                    Ogre.Vector3(1,1,1)))
            
            tree_ent = scene.scene_mgr.createEntity(name, mesh_name)

            # Need extra node, for scaling error
            temp_node = \
                scene.scene_mgr.getRootSceneNode().createChildSceneNode()
            temp_node.attachObject(tree_ent)
            temp_node.setVisible(False)
            temp_node.setScale(scale)
            
            col = OgreNewt.TreeCollision(scene.world, temp_node, True)
            # When this works remove and destory our node temporary node!!
        else:
            raise PhysicsError, '"%s" is not a valid shape type' % shape_type
        
        self._body = scene.world.create_body(self, col, mass, center_of_mass,
                                             inertia, position, orientation)
Beispiel #2
0
    def load(self, data_object):
        #Visual.load(self, data_object)
        # Remove me when scene node parenting issue is fixed
        scene, parent, kml_node = data_object
        Object.load(self, (parent, kml_node))

        gfx_node = kml_node['Graphical']
        mesh = gfx_node['mesh']
        material = gfx_node['material']
        scale = sim.OgreVector3(gfx_node['scale'])

        position, orientation = parse_position_orientation(kml_node)
        self._force_pos = sim.OgreVector3(position)

        direction = sim.OgreVector3(kml_node['direction'])
        min_force = kml_node['min_force']
        max_force = kml_node['max_force']
        Thruster._create(self, scene, direction, min_force, max_force, mesh,
                         material, position, orientation, scale)
Beispiel #3
0
    def load(self, data_object):
        """
        @type  data_object: tuple
        @param data_object: (scene, parent, kml_node)
        """
        scene, parent, node = data_object

        # Load Object based values
        Object.load(self, (parent, node))

        gfx_node = node['Graphical']
        mesh = gfx_node['mesh']
        material = gfx_node.get('material', None)
        scale = sim.OgreVector3(gfx_node.get('scale', Ogre.Vector3(1, 1, 1)))

        # Handle special mesh generation
        if mesh.startswith('PLANE'):
            if ':' in mesh:
                mesh = mesh.split(':')[1]
            else:
                mesh = 'Plane' + str(Visual._plane_count)

            norm = gfx_node['normal']
            width = gfx_node['width']
            height = gfx_node['height']
            upvec = gfx_node.get('upvec', Ogre.Vector3.UNIT_Y)
            utile = gfx_node.get('utile', 1)
            vtile = gfx_node.get('vtile', 1)

            plane = Ogre.Plane(norm, 0)
            group_name = gfx_node.get(
                'group', Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)

            xsegments = int(width)
            ysegments = int(height)

            Ogre.MeshManager.getSingletonPtr().createPlane(mesh, \
                group_name, plane, width, height, upVector = upvec,
                uTile = utile, vTile = vtile, xsegments = xsegments,
                ysegments = ysegments)
            Visual._plane_count += 1

        # Orientation defaults: IDENTITY, Position: (0,0,0)
        position, orientation = parse_position_orientation(node)
        Visual._create(self, scene, mesh, material, position, orientation,
                       scale)

        # Check visibility
        if not gfx_node.get('visible', True):
            self._node.setVisible(False)
Beispiel #4
0
    def update(self, time_since_last_frame):
        forceToApply = self._force
        # You can thrust in the water
        if self._node._getDerivedPosition().z > 0:
            forceToApply = 0

        force = sim.OgreVector3(self.direction) * forceToApply
        self.parent.add_local_force(force, self._force_pos)

        # Redraw force lines
        self._thrust_line.estimateVertexCount(1)
        self._thrust_line.estimateIndexCount(1)
        self._thrust_line.beginUpdate(0)
        self._draw_thrust_line(forceToApply)
        self._thrust_line.end()
Beispiel #5
0
    def __init__(self,
                 name,
                 scene,
                 position,
                 offset,
                 orientation,
                 near_clip=0.5):
        offset = sim.OgreVector3(offset)

        self._camera = scene.scene_mgr.createCamera(name)
        self._camera.nearClipDistance = near_clip
        self._camera.setFixedYawAxis(False)

        # Place the camera out in front at the needed distance
        self._camera.position = (offset.length(), 0, 0)

        # Make it face back toward zero
        self._camera.lookAt((0, 0, 0))

        # Account for the odd up vector difference between our and Ogre's
        # default coordinate systems
        self._camera.roll(Ogre.Degree(90))

        # Apply custom rotation if desired
        self._camera.rotate(orientation)

        # Allows easier movement of camera
        self._node = scene.scene_mgr.getRootSceneNode().createChildSceneNode()
        self._node.position = (0, 0, 0)
        self._node.attachObject(self._camera)

        # Rotate the node to place the camera in its desired offset position
        # Do the in plane rotation, then up rotation to keep the cameras up
        # facing the proper way
        inPlane = Ogre.Vector3(offset.x, offset.y, 0)
        if inPlane.length() != 0:
            self._node.rotate(self._camera.position.getRotationTo(inPlane))
        else:
            # The camera is directly above or below
            self._camera.roll(Ogre.Degree(180))
            inPlane = Ogre.Vector3.UNIT_X
        self._node.rotate(inPlane.getRotationTo(offset), Ogre.Node.TS_WORLD)

        # position camera
        self._node.position = position
Beispiel #6
0
    def _create(self, scene, direction, min_force, max_force, mesh, material,
                position, orientation, scale):
        self.direction = direction
        self.min_force = min_force
        self.max_force = max_force
        # Uncomment when python ogre gets updated
        # Reparent self to node
        #        parent_node = self._node.getParentSceneNode()
        #        parent_node.removeChild(self._node)
        #        self.parent._node.addChild(self._node)
        #
        entity = scene.scene_mgr.createEntity(self.name, mesh)
        entity.setMaterialName(material)

        self._node = self.parent._node.createChildSceneNode()
        self._node.attachObject(entity)

        pscale = self.parent._node.getScale()
        iscale = Ogre.Vector3((1 / pscale.x), (1 / pscale.y), (1 / pscale.z))

        if scale != Ogre.Vector3(1, 1, 1):
            self._node.setScale(scale * iscale)

        self._node.position = sim.OgreVector3(position) * iscale
        self._node.orientation = orientation

        self._thrust_line = scene.scene_mgr.createManualObject(self.name +
                                                               "manual")
        self._thrust_line.dynamic = True

        self._thrust_line.estimateVertexCount(1)
        self._thrust_line.estimateIndexCount(1)
        self._thrust_line.begin("BaseRedNoLighting",
                                Ogre.RenderOperation.OT_LINE_STRIP)
        self._draw_thrust_line(self._force)
        self._thrust_line.end()

        self._node.attachObject(self._thrust_line)
Beispiel #7
0
 def fset(self, torque):
     self._torque = sim.OgreVector3(torque)
Beispiel #8
0
 def fset(self, force):
     self._force = sim.OgreVector3(force)
Beispiel #9
0
 def fset(self, gravity):
     self._gravity = sim.OgreVector3(gravity)
Beispiel #10
0
 def _make_force_pos_pair(force, pos):
     return (sim.OgreVector3(force), sim.OgreVector3(pos))