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


Python TransformState.make_pos方法代码示例

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


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

示例1: update

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import make_pos [as 别名]
    def update(self, dt):
        dt = min(dt, 0.2) # let's just temporarily assume that if we're getting less than 5 fps, dt must be wrong.
        yaw = self.movement['left'] + self.movement['right']
        self.rotate_by(yaw * dt * 60, 0, 0)
        walk = self.movement['forward'] + self.movement['backward']
        start = self.position()
        cur_pos_ts = TransformState.make_pos(self.position() + self.head_height)

        if self.on_ground:
            friction = DEFAULT_FRICTION
        else:
            friction = AIR_FRICTION

        #to debug walk cycle (stay in place)
        #riction = 0

        speed = walk
        pos = self.position()
        self.move_by(0, 0, speed)
        direction = self.position() - pos
        newpos, self.xz_velocity = Friction(direction, friction).integrate(pos, self.xz_velocity, dt)
        self.move(newpos)

        # Cast a ray from just above our feet to just below them, see if anything hits.
        pt_from = self.position() + Vec3(0, 1, 0)
        pt_to = pt_from + Vec3(0, -1.1, 0)
        result = self.world.physics.ray_test_closest(pt_from, pt_to, MAP_COLLIDE_BIT | SOLID_COLLIDE_BIT)

        # this should return 'on ground' information
        self.skeleton.update_legs(walk, dt, self.world.scene, self.world.physics)

        if self.y_velocity.get_y() <= 0 and result.has_hit():
            self.on_ground = True
            self.crouch_impulse = self.y_velocity.y
            self.y_velocity = Vec3(0, 0, 0)
            self.move(result.get_hit_pos())
            self.skeleton.left_leg_on_ground = True
            self.skeleton.right_leg_on_ground = True
        else:
            self.on_ground = False
            current_y = Point3(0, self.position().get_y(), 0)
            y, self.y_velocity = self.integrator.integrate(current_y, self.y_velocity, dt)
            self.move(self.position() + (y - current_y))

        if self.crouching and self.skeleton.crouch_factor < 1:
            self.skeleton.crouch_factor += (dt*60)/10
            self.skeleton.update_legs(0, dt, self.world.scene, self.world.physics)
        elif not self.crouching and self.skeleton.crouch_factor > 0:
            self.skeleton.crouch_factor -= (dt*60)/10
            self.skeleton.update_legs(0, dt, self.world.scene, self.world.physics)

        #if self.crouch_impulse < 0:

        goal = self.position()
        adj_dist = abs((start - goal).length())
        new_pos_ts = TransformState.make_pos(self.position() + self.head_height)

        sweep_result = self.st_result(cur_pos_ts, new_pos_ts)
        count = 0
        while sweep_result.has_hit() and count < 10:
            moveby = sweep_result.get_hit_normal()
            self.xz_velocity = -self.xz_velocity.cross(moveby).cross(moveby)
            moveby.normalize()
            moveby *= adj_dist * (1 - sweep_result.get_hit_fraction())
            self.move(self.position() + moveby)
            new_pos_ts = TransformState.make_pos(self.position() + self.head_height)
            sweep_result = self.st_result(cur_pos_ts, new_pos_ts)
            count += 1

        if self.energy > WALKER_MIN_CHARGE_ENERGY:
            if self.left_gun_charge < 1:
                self.energy -= WALKER_ENERGY_TO_GUN_CHARGE[0]
                self.left_gun_charge += WALKER_ENERGY_TO_GUN_CHARGE[1]
            else:
                self.left_gun_charge = math.floor(self.left_gun_charge)

            if self.right_gun_charge < 1:
                self.energy -= WALKER_ENERGY_TO_GUN_CHARGE[0]
                self.right_gun_charge += WALKER_ENERGY_TO_GUN_CHARGE[1]
            else:
                self.right_gun_charge = math.floor(self.right_gun_charge)

        if self.energy < 1:
            self.energy += WALKER_RECHARGE_FACTOR * (dt)

        if self.player:
            self.sights.update(self.left_barrel_joint, self.right_barrel_joint)
开发者ID:airvoss,项目名称:pavara,代码行数:89,代码来源:walker.py

示例2: update

# 需要导入模块: from panda3d.core import TransformState [as 别名]
# 或者: from panda3d.core.TransformState import make_pos [as 别名]
    def update(self, world, dt):
        dirty = self.mouse_dirty
        old_pos = self.node.get_pos()
        h = self.node.get_h()
        new_velocity = self.velocity + (world.gravity * dt)

        if self.resting:
            if not (self.motion['forward'] ^ self.motion['backward']):
                self.motor_power /= 1.5
                if abs(self.motor_power) < 0.05:
                    self.motor_power = 0.0
            elif self.motion['forward']:
                self.motor_power = min(max(self.motor_power, 0) + (dt / self.WALK_ACCEL), 1.0)
            elif self.motion['backward']:
                self.motor_power = max(min(self.motor_power, 0) - (dt / self.WALK_ACCEL), -1.0)
        else:
            self.motor_power /= 1.5
            if abs(self.motor_power) < 0.05:
                self.motor_power = 0.0

        if not (self.motion['left'] ^ self.motion['right']):
            self.turn_power /= 1.25
            if abs(self.turn_power) < 0.05:
                self.turn_power = 0.0
        elif self.motion['left']:
            self.turn_power = min(max(self.turn_power, 0) + (dt / self.TURN_ACCEL), 1.0)
        elif self.motion['right']:
            self.turn_power = max(min(self.turn_power, 0) - (dt / self.TURN_ACCEL), -1.0)

        # Dampen the turn motor while walking.
        self.turn_power /= ((abs(self.motor_power) * self.TURN_DAMPER) + 1.0)

        if (abs(self.turn_power) + abs(self.motor_power)) > 0:
            dirty = True
        h += self.TURN_SPEED * dt * self.turn_power
        self.node.set_h(h)

        if self.motor_power != 0:
            # Panda's heading starts along the Y axis, so we need to rotate 90 degrees to start along X.
            x = math.cos(math.radians(h + 90)) * self.WALK_SPEED * self.motor_power
            y = math.sin(math.radians(h + 90)) * self.WALK_SPEED * self.motor_power
            new_velocity.set_x(x)
            new_velocity.set_y(y)
        else:
            new_velocity.set_x(0)
            new_velocity.set_y(0)

        new_pos = old_pos + (new_velocity * dt)

        # Cast a ray below our feet to determine if we're resting on an object.
        start = new_pos + Vec3(0, 0, 1.5)
        end = new_pos + Vec3(0, 0, -2.0)
        result = world.physics.ray_test_closest(start, end, Collision.SOLID)
        if result.has_hit():
            self.resting = True
            new_velocity.set_z(0)
            new_pos.set_z(result.hit_pos.z + 1.52)
        else:
            self.resting = False

        count = 0
        max_tries = 3
        shape = self.body.get_shape(0)
        from_ts = TransformState.make_pos(old_pos)
        to_ts = TransformState.make_pos(new_pos)
        result = world.physics.sweep_test_closest(shape, from_ts, to_ts, Collision.SOLID, 0)
        while result.has_hit() and count < max_tries:
            normal = result.hit_normal
            slide = 1.0 - result.hit_fraction - 0.01
            # First, move us back out of contact with whatever we hit.
            direction = new_pos - old_pos
            old_pos = old_pos + (direction * (result.hit_fraction - 0.01))

            # This is a safety check to make sure we actually moved out of the collision.
            to_ts = TransformState.make_pos(old_pos)
            result = world.physics.sweep_test_closest(shape, from_ts, to_ts, Collision.SOLID, 0)
            if result.has_hit():
                print("UH OH")

            # Adjust the velocity to be along the plane perpendicular to the normal of the hit.
            new_velocity = -new_velocity.cross(normal).cross(normal)
            if new_velocity.z < 0.01:
                self.resting = True
                new_velocity.set_z(0)

            # Now try to slide along that plane the rest of the way.
            new_pos = old_pos + (new_velocity * dt * slide)
            from_ts = TransformState.make_pos(old_pos)
            to_ts = TransformState.make_pos(new_pos)
            result = world.physics.sweep_test_closest(shape, from_ts, to_ts, Collision.SOLID, 0)
            if result.hit_fraction < 0.0001:
                print("NO ROOM TO SLIDE", result.node, result.hit_normal, new_velocity, slide)
                break
            count += 1
        if count >= max_tries:
            new_pos = old_pos
            print("FAIL", normal, new_velocity, result.hit_fraction)

        if new_velocity.length() < 0.001:
            new_velocity = Vec3()
#.........这里部分代码省略.........
开发者ID:dcwatson,项目名称:pavara,代码行数:103,代码来源:player.py


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