本文整理汇总了Python中Physics.world方法的典型用法代码示例。如果您正苦于以下问题:Python Physics.world方法的具体用法?Python Physics.world怎么用?Python Physics.world使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Physics
的用法示例。
在下文中一共展示了Physics.world方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteAllObjects
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def deleteAllObjects(self):
"""Delete all objects: characters, rigid bodies, snapshots, etc."""
if self._followedCharacter is not None :
self._followedCharacter = None
self._cameraFollowCharacter = False
self._cameraObservable.notifyObservers()
self._characters = []
self._controllerList.clear()
import Physics
Physics.world().destroyAllObjects()
self.deleteAllSnapshots()
示例2: addCharacter
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def addCharacter(self, character):
"""Adds a character to the application and the world"""
import Physics
if PyUtils.sameObjectInList(character, self._characters) :
raise KeyError ('Cannot add the same character twice to application.')
Physics.world().addArticulatedFigure( character )
self._characters.append( character )
if self._followedCharacter is None :
self._followedCharacter = character
self._cameraFollowCharacter = True
self._cameraObservable.notifyObservers()
self._characterObservable.notifyObservers()
示例3: load
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def load(self):
assert not self._loaded, "Cannot load scenario twice!"
self._loaded = True
# Create the rigid bodies for the main staircase
orientation = PyUtils.angleAxisToQuaternion( (self._angle,(0,1,0)) )
size = MathLib.Vector3d( self._staircaseWidth, self._riserHeight, self._threadDepth )
pos = PyUtils.toPoint3d( self._position ) + MathLib.Vector3d( 0, -self._riserHeight/2.0, 0 )
delta = MathLib.Vector3d(size)
delta.x = 0
delta = orientation.rotate( delta )
for i in range(self._stepCount):
box = PyUtils.RigidBody.createBox( size, pos = pos + delta * (i+1), locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
# Create the rigid bodies for both ramps
rampHeights = ( self._leftRampHeight, self._rightRampHeight )
deltaRamp = MathLib.Vector3d(self._staircaseWidth/2.0,0,0)
deltaRamp = orientation.rotate( deltaRamp )
deltaRamps = (deltaRamp, deltaRamp * -1)
for deltaRamp, rampHeight in zip( deltaRamps, rampHeights ):
if rampHeight is None: continue
deltaRamp.y = rampHeight/2.0
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + delta , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + (delta * self._stepCount) , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
deltaRamp.y = rampHeight
rampOrientation = orientation * PyUtils.angleAxisToQuaternion( (math.atan2(self._riserHeight, self._threadDepth), (-1,0,0)) )
rampLen = self._stepCount * math.sqrt( self._riserHeight*self._riserHeight + self._threadDepth*self._threadDepth )
box = PyUtils.RigidBody.createBox( (0.04,0.02,rampLen), pos = pos + deltaRamp + (delta * ((self._stepCount+1) * 0.5)) , locked = True, orientation=rampOrientation )
Physics.world().addRigidBody(box)
示例4: simulationStep
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def simulationStep(self):
"""Performs a single simulation step"""
# TODO Quite hacky
if self._kinematicMotion:
import KeyframeEditor
from MathLib import Trajectory3dv
try:
pc = self._posableCharacter
traj = self._stanceFootToSwingFootTrajectory
except AttributeError:
pc = self._posableCharacter = KeyframeEditor.PosableCharacter.PosableCharacter(self.getCharacter(0),self.getController(0))
traj = self._stanceFootToSwingFootTrajectory = Trajectory3dv()
traj.addKnot(0,Vector3d(-0.13,0,-0.4))
traj.addKnot(0.5,Vector3d(-0.13,0.125,0))
traj.addKnot(1,Vector3d(-0.13,0,0.4))
self._phase = 0
self._stance = Core.LEFT_STANCE
stanceToSwing = traj.evaluate_catmull_rom(self._phase)
if self._stance == Core.RIGHT_STANCE:
stanceToSwing.x = stanceToSwing.x * -1
pc.updatePose( self._phase, stanceToSwing, self._stance, True )
self._phase += 0.00069
if self._phase >= 1.0:
self._phase = 0
if self._stance == Core.LEFT_STANCE:
self._stance = Core.RIGHT_STANCE
else:
self._stance = Core.LEFT_STANCE
return
world = Physics.world()
controllers = self._controllerList._objects
contactForces = world.getContactForces()
for controller in controllers :
controller.performPreTasks(self._dt, contactForces)
world.advanceInTime(self._dt)
contactForces = world.getContactForces()
for controller in controllers :
if controller.performPostTasks(self._dt, contactForces) :
step = Vector3d (controller.getStanceFootPos(), controller.getSwingFootPos())
step = controller.getCharacterFrame().inverseRotate(step);
v = controller.getV()
phi = controller.getPhase()
if self._printStepReport:
print "step: %3.5f %3.5f %3.5f. Vel: %3.5f %3.5f %3.5f phi = %f" % ( step.x, step.y, step.z, v.x, v.y, v.z, phi)
示例5: draw
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def draw(self):
"""Draw the content of the world"""
world = Physics.world()
glEnable(GL_LIGHTING)
if self._drawCollisionVolumes:
world.drawRBs(Physics.SHOW_MESH|Physics.SHOW_CD_PRIMITIVES)
else:
world.drawRBs(Physics.SHOW_MESH|Physics.SHOW_COLOURS)
# world.drawRBs(Physics.SHOW_MESH|Physics.SHOW_CD_PRIMITIVES)
glDisable(GL_LIGHTING);
if self._drawShadows:
self._glCanvas.beginShadows()
world.drawRBs(Physics.SHOW_MESH)
self._glCanvas.endShadows()
示例6: _restore
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def _restore(self, restoreControllerParams = True):
"""Restores this snapshot, does sets it as active. Should only be called by SnapshotBranch."""
if self._activeIndex >= 0 :
# Make sure the selected branch is deactivated
self._childBranches[self._activeIndex]._deactivate()
# Restore the world
world = Physics.world()
world.setState( self._worldState )
# Restore the controllers
app = wx.GetApp()
assert app.getControllerCount() == len(self._controllers), "Controller list doesn't match snapshot!"
for i in range(app.getControllerCount()):
controller = app.getController(i)
controllerState, wrappedController = self._controllers[i]
if restoreControllerParams :
controller.beginBatchChanges()
try: wrappedController.fillObject(controller)
finally: controller.endBatchChanges()
controller.setControllerState( controllerState )
self.notifyObservers()
示例7: __init__
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def __init__(self, parentBranch):
"""Takes a shot of a world, add it to the specified branch."""
super(Snapshot,self).__init__()
self._time = time.localtime()
# Save the world
world = Physics.world()
self._worldState = Utils.DynamicArrayDouble()
world.getState( self._worldState )
# Save the controllers
app = wx.GetApp()
self._controllers = []
for i in range(app.getControllerCount()):
controller = app.getController(i)
controllerState = Core.SimBiControllerState()
controller.getControllerState( controllerState )
self._controllers.append( (controllerState, PyUtils.wrapCopy( controller )) )
self._parentBranch = parentBranch
self._childBranches = []
self._activeIndex = -1
示例8: __init__
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
def __init__(self, appTitle="Simbicon Application",
fps = 30.0,
dt = 1/2000.0,
glCanvasSize=wx.DefaultSize,
size=wx.DefaultSize, redirect=False, filename=None,
useBestVisual=False, clearSigInt=True, showConsole=True):
"""
appTitle is the window title
fps is the desired number of frames per seconds
dt is the desired simulation timestep
:see: wx.BasicApp.__init__`
"""
wx.App.__init__(self, redirect, filename, useBestVisual, clearSigInt)
# No annoying error logging window
wx.Log.SetActiveTarget(wx.LogStderr())
import UI
# Setup the main window style
style = wx.DEFAULT_FRAME_STYLE
if size == wx.DefaultSize :
size = wx.GetDisplaySize()
size.height *= 0.75
size.width *= 0.75
if glCanvasSize == wx.DefaultSize :
style |= wx.MAXIMIZE
# Setup the environment for the python interactive console
consoleEnvironment = {
"wx" : wx,
"Physics" : Physics,
"Utils" : Utils }
exec "from MathLib import *\n" + \
"app = wx.GetApp()\n" + \
"from PyUtils import load" in consoleEnvironment, consoleEnvironment
# Create the main window
self._frame = UI.MainWindow(None, -1, appTitle, size = size, style = style,
fps = fps, glCanvasSize = glCanvasSize,
showConsole = showConsole,
consoleEnvironment = consoleEnvironment)
# Define GL callbacks
self._glCanvas = self._frame.getGLCanvas()
self._glCanvas.addDrawCallback( self.draw )
self._glCanvas.addPostDrawCallback( self.postDraw )
self._glCanvas.addOncePerFrameCallback( self.advanceAnimation )
self._glCanvas.setDrawAxes(False)
self._glCanvas.setPrintLoad(True)
self._glCanvas.setCameraTargetFunction( self.cameraTargetFunction )
# Get the tool panel
self._toolPanel = self._frame.getToolPanel()
# Show the application
self._frame.Show()
# Set-up starting state
self._dt = dt
self._drawShadows = True
self._simulationSecondsPerSecond = 1 # 1 = real time, 2 = twice real time, 1/2 = half real time
self._animationRunning = False
self._cameraFollowCharacter = False
self._drawCollisionVolumes = False
self._followedCharacter = None # Pointer to focused character
self._captureScreenShots = False
self._printStepReport = True
self._screenShotNumber = 0
self._worldOracle = Core.WorldOracle()
self._worldOracle.initializeWorld( Physics.world() )
self._kinematicMotion = False
# Set-up starting list of characters and controllers
self._characters = []
# Define the observables
self._controllerList = ObservableList()
self._characterObservable = PyUtils.Observable()
self._animationObservable = PyUtils.Observable()
self._cameraObservable = PyUtils.Observable()
self._optionsObservable = PyUtils.Observable()
self._curveList = ObservableList()
self._snapshotTree = SnapshotBranch()
示例9:
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
'''
Created on 2009-09-03
@author: beaudoin
'''
import Proxy
import Member
import Physics, Core, wx
cls = Physics.ArticulatedFigure
ArticulatedFigure = Proxy.create( cls, loader = Physics.world().addArticulatedFigure,
members = [
Member.Basic( str, 'name', 'UnnamedArticulatedFigure', cls.getName, cls.setName ),
Member.Object( 'root', None, cls.getRoot, cls.setRoot ),
Member.ObjectList( 'arbs', None, cls.getArticulatedRigidBody, cls.getArticulatedRigidBodyCount, cls.addArticulatedRigidBody ),
Member.ObjectList( 'joints', None, cls.getJoint, cls.getJointCount, cls.addJoint )
] )
cls = Core.Character
Character = Proxy.create( cls, parent = ArticulatedFigure, loader = wx.GetApp().addCharacter )
示例10: getGroundCoeffs
# 需要导入模块: import Physics [as 别名]
# 或者: from Physics import world [as 别名]
"""DUMMY! Meshes are forgotten."""
return None
def getGroundCoeffs(object):
return (object.getGroundSoftness(), object.getGroundPenalty())
def setGroundCoeffs(object, value):
return object.setODEGroundCoefficients(*value)
cls = Physics.RigidBody
RigidBody = Proxy.create(
cls,
loader=Physics.world().addRigidBody,
members=[
Member.Basic(str, "name", "UnnamedRigidBody", cls.getName, cls.setName),
Member.Basic(list, "meshes", None, getMeshes, setMeshes),
Member.Basic(float, "mass", 1.0, cls.getMass, cls.setMass),
Member.Vector3d("moi", (1.0, 1.0, 1.0), cls.getMOI, cls.setMOI),
Member.ObjectList(
"cdps",
None,
cls.getCollisionDetectionPrimitive,
cls.getCollisionDetectionPrimitiveCount,
cls.addCollisionDetectionPrimitive,
),
Member.Point3d("pos", (0.0, 0.0, 0.0), cls.getCMPosition, cls.setCMPosition),
Member.Vector3d("vel", (0.0, 0.0, 0.0), cls.getCMVelocity, cls.setCMVelocity),
Member.Quaternion("orientation", (0.0, (1.0, 0.0, 0.0)), cls.getOrientation, cls.setOrientation),