示例#1
0
    def updateClients(self):
        self.updateDone = False
        if not self.updateLock.acquire(False):
            return

        # build message to send
        message = []
        for (body, geom) in self.body_geom:
            item = {}
            # real bodies (boxes, spheres, ...)
            if body != None:
                # transform (rotate, translate) body accordingly
                item["position"] = body.getPosition()
                item["rotation"] = body.getRotation()
                if hasattr(body, "color"):
                    item["color"] = body.color

                # switch different geom objects
                if type(geom) == ode.GeomBox:
                    # cube
                    item["type"] = "GeomBox"
                    item["scale"] = geom.getLengths()
                elif type(geom) == ode.GeomSphere:
                    # sphere
                    item["type"] = "GeomSphere"
                    item["radius"] = geom.getRadius()

                elif type(geom) == ode.GeomCCylinder:
                    # capped cylinder
                    item["type"] = "GeomCCylinder"
                    item["radius"] = geom.getParams()[0]
                    item["length"] = geom.getParams()[1] - 2 * item["radius"]

                elif type(geom) == ode.GeomCylinder:
                    # solid cylinder
                    item["type"] = "GeomCylinder"
                    item["radius"] = geom.getParams()[0]
                    item["length"] = geom.getParams()[1]
                else:
                    # TODO: add other geoms here
                    pass

            else:
                # no body found, then it must be a plane (we only draw planes)
                if type(geom) == ode.GeomPlane:
                    # plane
                    item["type"] = "GeomPlane"
                    item["normal"] = geom.getParams()[0]  # the normal vector to the plane
                    item["distance"] = geom.getParams()[1]  # the distance to the origin

            message.append(item)

        # Listen for clients
        self.server.listen()
        if self.server.clients > 0:
            # If there are clients send them the new data
            self.server.send(message)
        time.sleep(0.02)
        self.updateLock.release()
        self.updateDone = True
示例#2
0
    def updateClients(self):
        self.updateDone = False      
        if not self.updateLock.acquire(False): 
            return
        
        # build message to send
        message = []
        for (body, geom) in self.body_geom:
            item = {}
            # real bodies (boxes, spheres, ...)
            if body != None:
                # transform (rotate, translate) body accordingly
                item['position'] = body.getPosition()
                item['rotation'] = body.getRotation()
                if hasattr(body, 'color'): item['color'] = body.color
                
                # switch different geom objects
                if type(geom) == ode.GeomBox:
                    # cube
                    item['type'] = 'GeomBox'
                    item['scale'] = geom.getLengths()
                elif type(geom) == ode.GeomSphere:
                    # sphere
                    item['type'] = 'GeomSphere'
                    item['radius'] = geom.getRadius()

                elif type(geom) == ode.GeomCCylinder:
                    # capped cylinder
                    item['type'] = 'GeomCCylinder'
                    item['radius'] = geom.getParams()[0]
                    item['length'] = geom.getParams()[1] - 2*item['radius']

                elif type(geom) == ode.GeomCylinder:
                        # solid cylinder
                        item['type'] = 'GeomCylinder'
                        item['radius'] = geom.getParams()[0]
                        item['length'] = geom.getParams()[1]         
                else:
                    # TODO: add other geoms here
                    pass

            else:
                # no body found, then it must be a plane (we only draw planes)
                if type(geom) == ode.GeomPlane:
                    # plane
                    item['type'] = 'GeomPlane'
                    item['normal'] = geom.getParams()[0] # the normal vector to the plane
                    item['distance'] = geom.getParams()[1] # the distance to the origin
            
            message.append(item)
        
        # Listen for clients
        self.server.listen()
        if self.server.clients > 0: 
            # If there are clients send them the new data
            self.server.send(message)
        time.sleep(0.02)
        self.updateLock.release()
        self.updateDone=True
示例#3
0
    def updateClients(self):
        self.updateDone = False

        if not self.updateLock.acquire(False):
            return

        # build message to send
        message = {}

        for body, geom in self.body_geom:
            item = {}

            item_name = ''

            if body != None:
                item_name = body.name

                if item_name in self.invisible_bodies:
                    continue

                item_pos = body.getPosition()
                item_rot = body.getRotation()

                # Try to find this body from the previous message. See if
                # the item exists and has changed. If it is modified, then
                # the item must be sent. If not, it is implied that the body
                # has not changed.
                if item_name in self.prev_message:
                    # The item has been sent before
                    prev_item = self.prev_message[item_name]

                    # See if the item has been modified
                    if (prev_item['position'] == item_pos and
                            prev_item['rotation'] == item_rot):
                        # The item has not changed. Don't add it to the message
                        continue

                # The item wasn't in the previous message or has been altered.
                # Send the new info to the viewer

                # transform (rotate, translate) body accordingly
                item['position'] = item_pos
                item['rotation'] = item_rot

                if hasattr(body, 'color'):
                    item['color'] = body.color

                # switch different geom objects
                if type(geom) == ode.GeomBox:
                    # cube
                    item['type'] = 'box'
                    item['scale'] = geom.getLengths()
                elif type(geom) == ode.GeomSphere:
                    # sphere
                    item['type'] = 'sphere'
                    item['radius'] = geom.getRadius()

                elif type(geom) == ode.GeomCCylinder:
                    # capped cylinder
                    item['type'] = 'ccylinder'
                    item['radius'] = geom.getParams()[0]
                    item['length'] = geom.getParams()[1] - 2 * item['radius']

                elif type(geom) == ode.GeomCylinder:
                    # solid cylinder
                    item['type'] = 'cylinder'
                    item['radius'] = geom.getParams()[0]
                    item['length'] = geom.getParams()[1]
            else:
                item_name = geom.name

                # See if the item exists in the previous message. If so, the
                # viewer is already aware of it.
                if item_name in self.prev_message:
                    continue

                # no body found, then it must be a plane (we only draw planes)
                if type(geom) == ode.GeomPlane:
                    item['type'] = 'plane'
                    item['normal'] = geom.getParams()[0] # the normal vector to the plane
                    item['distance'] = geom.getParams()[1] # the distance to the origin

            message[item_name] = item

        # Listen for clients
        self.server.listen()
        if self.server.clients > 0:
            # If there are clients send them the new data
            self.server.send(message)

        # Store the message items in their current positions and rotations
        self.prev_message = message

        self.updateLock.release()
        self.updateDone = True

        return