当前位置: 首页>>代码示例>>Python>>正文


Python Solver.setObjects方法代码示例

本文整理汇总了Python中solver.Solver.setObjects方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.setObjects方法的具体用法?Python Solver.setObjects怎么用?Python Solver.setObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solver.Solver的用法示例。


在下文中一共展示了Solver.setObjects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: World

# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import setObjects [as 别名]
class World(Thread):


    def __init__(self, controlwindow):
        super(World, self).__init__()
        
        self.objects = {}           # dictionary holding the objects
        self.cw = controlwindow
        self.loader = Loader()
        self.solver = Solver(self.objects)
        self.condition = Condition()
        self.paused = True
        self.end = False
        self.show_vectors = False
        self.make_trail = False
        self.t = 0                  # time
        self.count = 0              # used to count updates per second value
        self.speed = 0              # simulation speed in updates/second
        self.acceleration_gain = 1  # gain value that is used to adjust acceleration vector lengths
        self.acceleration_scale = 1
        self.velocity_scale = 1
        self.errors = 0             # error flag, ControlWindow checks this for errors when loading a new simulation
        self.lock = Lock()
        self.time_elapsed = 0       # amount of seconds simulated
        self.reference = None       # camera reference object
        
    def run(self):
        while not self.end:
            self.waitRequest()
            if not self.paused:
                self.update()

    def waitRequest(self):
        if self.paused:
            try:
                with self.condition:
                    #print "Waiting.."
                    self.condition.wait()
                    #print "Continuing.."
            except KeyboardInterrupt:
                self.paused = False
    
    def startSimulation(self):
        self.paused = False
        with self.condition:
            self.condition.notify()

    def stopSimulation(self):
        self.paused = True
            
    
    def update(self):
        if self.objects:
            try:
                self.solver.integrate(self.lock)
                self.time_elapsed += self.solver.dt
            except CollisionError as err:
                print err       
                self.paused = True  # if a collision happens, pause simulation
                self.cw.reportCollision(str(err))
            if self.t+1.0>=clock():
                self.count+=1
            else:
                #print self.count, ' /s'
                self.speed = self.count
                self.count=0
                self.t=clock()

            if self.reference is not None:
                scene.center = self.reference.position

    def setReference(self, reference):
        if reference is not None:
            self.reference = self.objects[reference]
            scene.center = self.reference.position
        else:
            self.reference = None
            scene.center = vector(0,0,0)

    def close(self):
        self.paused = False
        self.end = True
        with self.condition:
            self.condition.notify()
    
    def addObject(self, astronomical_object, name):
        self.lock.acquire()
        if name in self.objects:
            del self.objects[name]
        self.objects[name] = astronomical_object
        self.solver.setObjects(self.objects)
        self.lock.release()

    def getTimeStep(self):
        return self.solver.dt

    def setTimeStep(self, dt):
        self.solver.dt = float(dt)

    #def getObject(self, name):
#.........这里部分代码省略.........
开发者ID:jannekem,项目名称:aksimulaattori2012,代码行数:103,代码来源:world.py


注:本文中的solver.Solver.setObjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。