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


Python TransformState.makePosHpr方法代码示例

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


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

示例1: setup

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()
    self.debugNP.node().showWireframe(True)
    self.debugNP.node().showConstraints(True)
    self.debugNP.node().showBoundingBoxes(False)
    self.debugNP.node().showNormals(False)

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Box A
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    bodyA = BulletRigidBodyNode('Box A')
    bodyNP = self.worldNP.attachNewNode(bodyA)
    bodyNP.node().addShape(shape)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(-3, 0, 4)

    visNP = loader.loadModel('models/box.egg')
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)

    self.world.attachRigidBody(bodyA)

    # Box B
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    bodyB = BulletRigidBodyNode('Box B')
    bodyNP = self.worldNP.attachNewNode(bodyB)
    bodyNP.node().addShape(shape)
    bodyNP.node().setMass(1.0)
    bodyNP.node().setDeactivationEnabled(False)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(0, 0, 0)

    visNP = loader.loadModel('models/box.egg')
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)

    self.world.attachRigidBody(bodyB)

    # Slider
    frameA = TransformState.makePosHpr(Point3(2, 0, 0), Vec3(0, 0, 45))
    frameB = TransformState.makePosHpr(Point3(0, -3, 0), Vec3(0, 0, 0))

    slider = BulletSliderConstraint(bodyA, bodyB, frameA, frameB, True)
    slider.setDebugDrawSize(2.0)
    slider.setLowerLinearLimit(0)
    slider.setUpperLinearLimit(6)
    slider.setLowerAngularLimit(-60)
    slider.setUpperAngularLimit(60)
    self.world.attachConstraint(slider)
开发者ID:Changuito,项目名称:juan_example,代码行数:60,代码来源:11_SliderConstraint.py

示例2: setup

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
    self.debugNP.show()
    self.debugNP.node().showWireframe(True)
    self.debugNP.node().showConstraints(True)
    self.debugNP.node().showBoundingBoxes(False)
    self.debugNP.node().showNormals(False)

    self.world = BulletWorld()
    self.world.setGravity(Vec3(0, 0, -9.81))
    self.world.setDebugNode(self.debugNP.node())

    # Box A
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    bodyA = BulletRigidBodyNode('Box A')
    bodyNP = self.worldNP.attachNewNode(bodyA)
    bodyNP.node().addShape(shape)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(-2, 0, 4)

    visNP = loader.loadModel('models/box.egg')
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)

    self.world.attachRigidBody(bodyA)

    # Box B
    shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))

    bodyB = BulletRigidBodyNode('Box B')
    bodyNP = self.worldNP.attachNewNode(bodyB)
    bodyNP.node().addShape(shape)
    bodyNP.node().setMass(1.0)
    bodyNP.node().setDeactivationEnabled(False)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(0, 0, 0)

    visNP = loader.loadModel('models/box.egg')
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)

    self.world.attachRigidBody(bodyB)

    # Cone
    frameA = TransformState.makePosHpr(Point3(0, 0, -2), Vec3(0, 0, 90))
    frameB = TransformState.makePosHpr(Point3(-5, 0, 0), Vec3(0, 0, 0))

    cone = BulletConeTwistConstraint(bodyA, bodyB, frameA, frameB)
    cone.setDebugDrawSize(2.0)
    cone.setLimit(30, 45, 170, softness=1.0, bias=0.3, relaxation=8.0)
    self.world.attachConstraint(cone)
开发者ID:Changuito,项目名称:juan_example,代码行数:57,代码来源:13_ConeTwistConstraint.py

示例3: create_colliders

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
def create_colliders(root, pose_rig, joints_config):
    for node, parent in pose_rig.exposed_joints:
        if node.getName() not in joints_config:
            continue

        joint_config = joints_config[node.getName()]
        if "joints" not in joint_config:
            continue

        joints = joint_config["joints"]
        if len(joints) == 0:
            continue

        mass = joint_config["mass"] if "mass" in joint_config else 1

        box_rb = BulletRigidBodyNode(node.getName())
        box_rb.setMass(1.0)
        # box_rb.setLinearDamping(0.2)
        # box_rb.setAngularDamping(0.9)
        # box_rb.setFriction(1.0)
        # box_rb.setAnisotropicFriction(1.0)
        # box_rb.setRestitution(0.0)

        for joint in joints:
            child_node, child_parent = next(
                (child_node, child_parent)
                for child_node, child_parent in pose_rig.exposed_joints
                if child_node.getName() == joint
            )

            pos = child_node.getPos(child_parent)
            width = pos.length() / 2.0
            scale = Vec3(3, width, 3)

            shape = BulletBoxShape(scale)

            quat = Quat()
            lookAt(quat, child_node.getPos(child_parent), Vec3.up())
            if len(joints) > 1:
                transform = TransformState.makePosHpr(child_node.getPos(child_parent) / 2.0, quat.getHpr())
            else:
                transform = TransformState.makeHpr(quat.getHpr())

            box_rb.addShape(shape, transform)

        box_np = root.attachNewNode(box_rb)

        if len(joints) > 1:
            pos = node.getPos(pose_rig.actor)
            hpr = node.getHpr(pose_rig.actor)
            box_np.setPosHpr(root, pos, hpr)
        else:
            box_np.setPos(child_parent, child_node.getPos(child_parent) / 2.0)
            box_np.lookAt(child_parent, child_node.getPos(child_parent))

        yield box_np
开发者ID:BarkingMouseStudio,项目名称:python-experiments,代码行数:58,代码来源:physics_utils.py

示例4: __init__

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
 def  __init__(self,info):
   
   # animation base setup
   self.character_info_ = info   
   size = Vec3(info.width, AnimationActor.DEFAULT_WIDTH , info.height)
   AnimatableObject.__init__(self,info.name,size,info.mass)    
   self.animation_root_np_.setPos(Vec3(0,0,0))
   
       # constraints
   self.left_constraint_ = None
   self.right_constraint_ = None
   self.selected_constraint_ = None
   
   # removing default shapes from rigid body
   shapes = self.node().getShapes()
   for shape in shapes:
     self.node().removeShape(shape)
   
   # adding capsule shape
   radius = 0.5*size.getX()
   height = size.getZ() - 2.0*radius  # height of cylindrical part only
   height = height if height >= 0 else 0.0
   bullet_shape = BulletCapsuleShape(radius, height, ZUp)
   bullet_shape.setMargin(GameObject.DEFAULT_COLLISION_MARGIN)
   self.node().addShape(bullet_shape,TransformState.makePos(Vec3(0,0,0.5*size.getZ()))) # box bottom center coincident with the origin
   self.node().setMass(self.character_info_.mass)
   self.node().setLinearFactor((1,1,1)) 
   self.node().setAngularFactor((0,0,0)) 
   self.setCollideMask(CollisionMasks.NO_COLLISION)    
   
   #  setting bounding volume
   min = LPoint3(-0.5*size.getX(),-0.5*size.getY(),0)
   max = LPoint3(0.5*size.getX(),0.5*size.getY(),size.getZ())
   self.node().setBoundsType(BoundingVolume.BT_box)    
   self.node().setBounds(BoundingBox(min,max))
   
   # setting origin ghost nodes
   rel_pos = Vec3(-GameObject.ORIGIN_XOFFSET,0,info.height/2)
   self.left_origin_gn_ = self.attachNewNode(BulletGhostNode(self.getName() + '-left-origin'))
   self.left_origin_gn_.node().addShape(BulletSphereShape(GameObject.ORIGIN_SPHERE_RADIUS),TransformState.makePosHpr(rel_pos,Vec3.zero()))
   self.left_origin_gn_.node().setIntoCollideMask(CollisionMasks.ACTION_TRIGGER_0 if not self.isFacingRight() else CollisionMasks.NO_COLLISION)
   
   rel_pos = Vec3(GameObject.ORIGIN_XOFFSET,0,info.height/2)
   self.right_origin_gn_ = self.attachNewNode(BulletGhostNode(self.getName() + '-right-origin'))
   self.right_origin_gn_.node().addShape(BulletSphereShape(GameObject.ORIGIN_SPHERE_RADIUS),TransformState.makePosHpr(rel_pos,Vec3.zero()))
   self.right_origin_gn_.node().setIntoCollideMask(CollisionMasks.ACTION_TRIGGER_0 if self.isFacingRight() else CollisionMasks.NO_COLLISION)
   
   # character status
   self.state_data_ = CharacterStateData()
   
   # state machine
   self.sm_ = StateMachine()     
   
   # motion commander
   self.motion_commander_ = MotionCommander(self)
   
   # set id
   self.setObjectID(self.getName())
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:60,代码来源:character_base.py

示例5: create_constraints

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
def create_constraints(root, joint_pairs, offset_scale):
    for joint_config, parent, child in joint_pairs:
        rb_parent = parent.node()
        rb_child = child.node()

        extents_parent = rb_parent.get_shape(0).getHalfExtentsWithMargin()
        extents_child = rb_child.get_shape(0).getHalfExtentsWithMargin()

        if "offset_parent" in joint_config:
            offset_parent = Point3(joint_config["offset_parent"])
        else:
            offset_parent = (0, 1, 0)
            offset_parent_x, offset_parent_y, offset_parent_z = offset_parent
            offset_parent = Point3(
                offset_parent_x * extents_parent.getX(),
                offset_parent_y * extents_parent.getY(),
                offset_parent_z * extents_parent.getZ(),
            )

        if "offset_child" in joint_config:
            offset_child = Point3(*joint_config["offset_child"])
        else:
            offset_child = (0, -1, 0)
            offset_child_x, offset_child_y, offset_child_z = offset_child
            offset_child = Point3(
                offset_child_x * extents_child.getX(),
                offset_child_y * extents_child.getY(),
                offset_child_z * extents_child.getZ(),
            )

        offset_parent = offset_parent * offset_scale
        offset_child = offset_child * offset_scale

        if joint_config["type"] == "hinge":
            axis_parent = Vec3(*joint_config["axis_parent"])
            axis_child = Vec3(*joint_config["axis_child"])

            constraint = BulletHingeConstraint(
                rb_parent, rb_child, offset_parent, offset_child, axis_parent, axis_child
            )

            if "limit" in joint_config:
                low, high = joint_config["limit"]
                softness = 1.0
                bias = 0.3
                relaxation = 1.0
                constraint.setLimit(low, high, softness, bias, relaxation)
        elif joint_config["type"] == "cone":
            frame_parent = TransformState.makePosHpr(offset_parent, Vec3(90, 0, 0))
            frame_child = TransformState.makePosHpr(offset_child, Vec3(90, 0, 0))

            constraint = BulletConeTwistConstraint(rb_parent, rb_child, frame_parent, frame_child)

            swing1, swing2, twist = joint_config["limit"]
            constraint.setLimit(swing1, swing2, twist)
        elif joint_config["type"] == "spherical":
            constraint = BulletSphericalConstraint(rb_parent, rb_child, offset_parent, offset_child)

        # constraint.setDebugDrawSize(1.0)

        yield constraint
开发者ID:BarkingMouseStudio,项目名称:python-experiments,代码行数:63,代码来源:physics_utils.py

示例6: setupObstacleThree

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
 def setupObstacleThree(self, pos, scale, turn):
   # Box A
   shape = BulletBoxShape(Vec3(0.1, 0.1, 0.1))
   
   bodyA = BulletRigidBodyNode('Box A')
   bodyA.setRestitution(1.0)
   bodyNP = self.worldNP.attachNewNode(bodyA)
   bodyNP.node().addShape(shape)
   bodyNP.setCollideMask(BitMask32.allOn())
   bodyNP.setPos(pos)
   bodyNP.setHpr(turn)
   
   visNP = loader.loadModel('media/models/box.egg')
   visNP.setScale(Vec3(0.1, 0.1, 0.1)*2*scale)
   visNP.clearModelNodes()
   visNP.reparentTo(bodyNP)
   
   self.world.attachRigidBody(bodyA)
   
   #Box B
   shape = BulletBoxShape(Vec3(0.1,0.1,0.1))
   
   bodyB = BulletRigidBodyNode('Box B')
   bodyB.setRestitution(1.0)
   bodyNP = self.worldNP.attachNewNode(bodyB)
   bodyNP.node().addShape(shape)
   bodyNP.setCollideMask(BitMask32.allOn())
   bodyNP.setPos(pos)
   bodyNP.setHpr(turn)
   
   visNP = loader.loadModel('media/models/box.egg')
   visNP.setScale(Vec3(0.1,0.1,0.1)*2*scale)
   visNP.clearModelNodes()
   visNP.reparentTo(bodyNP)
   
   self.world.attachRigidBody(bodyB)
   
   # Slider
   frameA = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
   frameB = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
   
   slider = BulletSliderConstraint(bodyA, bodyB, frameA, frameB, True)
   slider.setDebugDrawSize(2.0)
   slider.setLowerLinearLimit(0)
   slider.setUpperLinearLimit(12)
   slider.setLowerAngularLimit(-90)
   slider.setUpperAngularLimit(-85)
   self.world.attachConstraint(slider)
   
   # Box C
   shape = BulletBoxShape(Vec3(1, 3, 0.1))
   
   bodyC = BulletRigidBodyNode('Box C')
   bodyC.setRestitution(1.0)
   bodyNP = self.worldNP.attachNewNode(bodyC)
   bodyNP.node().addShape(shape)
   bodyNP.node().setMass(0.1)
   bodyNP.node().setDeactivationEnabled(False)
   bodyNP.setCollideMask(BitMask32.allOn())  
   bodyNP.setPos(Vec3(pos.getX() + 3, pos.getY() - 4, pos.getZ()))
   bodyNP.setHpr(turn)
   
   visNP = loader.loadModel('media/models/box.egg')
   visNP.setScale(Vec3(1, 3, 0.1)*2*scale)
   visNP.clearModelNodes()
   visNP.reparentTo(bodyNP)
   
   self.world.attachRigidBody(bodyC)
   
   bodyNP.node().setLinearVelocity(-100)
   
   # Slider
   frameA = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
   frameB = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
   
   slider = BulletSliderConstraint(bodyA, bodyC, frameA, frameB, True)
   slider.setDebugDrawSize(2.0)
   slider.setLowerLinearLimit(2)
   slider.setUpperLinearLimit(6)
   slider.setLowerAngularLimit(-90)
   slider.setUpperAngularLimit(-85)
   self.world.attachConstraint(slider)
开发者ID:MarcusKhoo,项目名称:RonnieRacer,代码行数:84,代码来源:RonnieRacer.py

示例7: setupObstacleFour

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import makePosHpr [as 别名]
  def setupObstacleFour(self, pos, scale, turn):
    #Start Here
    # Box A
    shape = BulletBoxShape(Vec3(0.01, 0.01, 0.01) * scale)
    bodyA = BulletRigidBodyNode('Box A')
    bodyNP = self.worldNP.attachNewNode(bodyA)
    bodyNP.node().addShape(shape)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(pos.getX(), pos.getY(), pos.getZ() + 4) #(0, 0, 4)

    visNP = loader.loadModel('media/models/box.egg')
    visNP.setScale(Vec3(0.01, 0.01, 0.01)*2*scale)
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)

    self.world.attachRigidBody(bodyA)

    # Box B
    shape = BulletSphereShape(0.5*scale)

    bodyB = BulletRigidBodyNode('Sphere B')
    bodyNP = self.worldNP.attachNewNode(bodyB)
    bodyNP.node().addShape(shape)
    bodyNP.node().setMass(10.0)
    bodyNP.node().setDeactivationEnabled(False)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(pos.getX(), pos.getY(), pos.getZ() + 5) #(0, 0, 0.001)

    visNP = loader.loadModel('media/models/ball.egg')
    visNP.clearModelNodes()
    visNP.setScale(1.25*scale)
    visNP.reparentTo(bodyNP)
    
    bodyNP.node().setLinearVelocity(100)

    self.world.attachRigidBody(bodyB)

    # Cone
    frameA = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 90))
    frameB = TransformState.makePosHpr(Point3(2, 0, 0)*scale, Vec3(0, 0, 0))

    cone = BulletConeTwistConstraint(bodyA, bodyB, frameA, frameB)
    cone.setDebugDrawSize(2.0)
    cone.setLimit(30, 90, 270, softness=1.0, bias=0.3, relaxation=10.0)
    self.world.attachConstraint(cone)
    
    # Box C
    shape = BulletBoxShape(Vec3(0.1, 0.1, 1)*scale)

    bodyC = BulletRigidBodyNode('Box C')
    bodyNP = self.worldNP.attachNewNode(bodyC)
    bodyNP.node().addShape(shape)
    bodyNP.node().setDeactivationEnabled(False)
    bodyNP.setCollideMask(BitMask32.allOn())
    bodyNP.setPos(pos.getX(), pos.getY(), pos.getZ() + 3)
    
    self.world.attachRigidBody(bodyC)

    visNP = loader.loadModel('media/models/box.egg')
    visNP.setScale(Vec3(0.1, 0.1, 1)*2*scale)
    visNP.clearModelNodes()
    visNP.reparentTo(bodyNP)
开发者ID:MarcusKhoo,项目名称:RonnieRacer,代码行数:64,代码来源:RonnieRacer.py


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