def _mainloopUpdate(self, dt): app.App._mainloopUpdate(self, dt) for w in self._windows: h3d.setNodeTransform(w.camera, self._x, self._y, self._z, self._rx, self._ry, 0, 1, 1, 1) if self._debugViewMode: h3d.setOption(h3d.Options.DebugViewMode, 1.0) else: h3d.setOption(h3d.Options.DebugViewMode, 0.0) if self._wireframeMode: h3d.setOption(h3d.Options.WireframeMode, 1.0) else: h3d.setOption(h3d.Options.WireframeMode, 0.0) key = pyglet.window.key curVel = self._velocity * dt if w.keyboard[key.LSHIFT]: curVel *= 5 if w.keyboard[key.W]: self._x -= sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y -= sin(-radians(self._rx)) * curVel self._z -= cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.S]: self._x += sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y += sin(-radians(self._rx)) * curVel self._z += cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.A]: self._x += sin(radians(self._ry - 90)) * curVel self._z += cos(radians(self._ry - 90)) * curVel if w.keyboard[key.D]: self._x += sin(radians(self._ry + 90)) * curVel self._z += cos(radians(self._ry + 90)) * curVel if w.keyboard[key._1]: self._weight += 2 * dt if self._weight > 1.0: self._weight = 1.0 if w.keyboard[key._2]: self._weight -= 2 * dt if self._weight < 0.0: self._weight = 0.0 break # we use only exactly ONE window if not self._freeze: self._animTime += dt h3d.setModelAnimParams(self._knight, 0, self._animTime * 24.0, self._weight) h3d.setModelAnimParams(self._knight, 1, self._animTime * 24.0, 1.0 - self._weight) count = h3d.findNodes(self._particleSystem, '', h3d.NodeTypes.Emitter) for i in range(count): h3d.advanceEmitterTime(h3d.getNodeFindResult(i), dt)
def graphic_update(self, cur_fps, ani_time, weight): if (PIWIO.key_clicked() and PIWIO.clicked_key() == Qt.Key_F5): self.__mode += 1 if PIWIO.key_clicked() and PIWIO.clicked_key() == Qt.Key_F3: self.change_render_mode(self.__render_mode + 1) if self.__mode > 0: name, _ = self.__rmode_dict[self.__render_mode] h3d.utils.showText("Pipeline: {}".format(name), 0.03, 0.24, 0.026, 1, 1, 1, self._h3dres.fontMat) if self.__mode == 3: self.__mode = 0 h3d.setModelAnimParams(self._knight, 0, ani_time, weight) h3d.setModelAnimParams(self._knight, 1, ani_time, 1.0 - weight) h3d.updateModel( self._knight, h3d.ModelUpdateFlags.Animation | h3d.ModelUpdateFlags.Geometry) count = h3d.findNodes(self._particleSystem, '', h3d.NodeTypes.Emitter) for i in range(count): h3d.updateEmitter(h3d.getNodeFindResult(i), 1.0 / cur_fps)
def update(self, dt): # Calculate distance to destination x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # On arrival choose a new destination for the next step if d <= 3.0: self.chooseDestination() x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # Calculate normalized attraction force to destination self.fx = x * 0.035 / d self.fz = z * 0.035 / d # Repulsion forces from other nearby particles for p in self.near: if p == self: continue x = self.px - p.px z = self.pz - p.pz d = x * x + z * z if d > dms: continue d = sqrt(d) # Use three zones with different repulsion strengths if d <= d1: s = m1 + t1 / d elif d <= d2: s = m2 + t2 / d else: s = m3 + t3 / d self.fx += x * s self.fz += z * s # Make movement frame rate independent dt *= 30 self.fx *= dt self.fz *= dt # Set new position self.px += self.fx self.pz += self.fz # Calculate orientation self.ox = (self.ox + self.fx) / 2 self.oz = (self.oz + self.fz) / 2 # Get rotation from orientation if self.oz == 0: ry = 0 else: ry = degrees(atan2(self.ox, self.oz)) # Update character scene node position h3d.setNodeTransform(self.node, self.px, 0.02, self.pz, 0, ry, 0, 1, 1, 1) # Update animation vel = sqrt(self.fx * self.fx + self.fz * self.fz) self.animTime += vel * 35.0 h3d.setModelAnimParams(self.node, 0, self.animTime, 1.0) h3d.updateModel( self.node, h3d.ModelUpdateFlags.Animation | h3d.ModelUpdateFlags.Geometry );
def update(self, dt): # Calculate distance to destination x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # On arrival choose a new destination for the next step if d <= 3.0: self.chooseDestination() x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # Calculate normalized attraction force to destination self.fx = x * 0.035 / d self.fz = z * 0.035 / d # Repulsion forces from other nearby particles for p in self.near: if p == self: continue x = self.px - p.px z = self.pz - p.pz d = x * x + z * z if d > dms: continue d = sqrt(d) # Use three zones with different repulsion strengths if d <= d1: s = m1 + t1 / d elif d <= d2: s = m2 + t2 / d else: s = m3 + t3 / d self.fx += x * s self.fz += z * s # Make movement frame rate independent dt *= 30 self.fx *= dt self.fz *= dt # Set new position self.px += self.fx self.pz += self.fz # Calculate orientation self.ox = (self.ox + self.fx) / 2 self.oz = (self.oz + self.fz) / 2 # Get rotation from orientation if self.oz == 0: ry = 0 else: ry = degrees(atan2(self.ox, self.oz)) # Update character scene node position h3d.setNodeTransform(self.node, self.px, 0.02, self.pz, 0, ry, 0, 1, 1, 1) # Update animation vel = sqrt(self.fx * self.fx + self.fz * self.fz) self.animTime += vel * 35.0 h3d.setModelAnimParams(self.node, 0, self.animTime, 1.0) h3d.updateModel( self.node, h3d.ModelUpdateFlags.Animation | h3d.ModelUpdateFlags.Geometry)