本文整理汇总了Python中srctools.Vec.rotate_by_str方法的典型用法代码示例。如果您正苦于以下问题:Python Vec.rotate_by_str方法的具体用法?Python Vec.rotate_by_str怎么用?Python Vec.rotate_by_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Vec
的用法示例。
在下文中一共展示了Vec.rotate_by_str方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: res_rand_inst_shift
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import rotate_by_str [as 别名]
def res_rand_inst_shift(inst: Entity, res: Property) -> None:
"""Randomly shift a instance by the given amounts.
The positions are local to the instance.
"""
(
min_x, max_x,
min_y, max_y,
min_z, max_z,
seed,
) = res.value # type: float, float, float, float, float, float, str
set_random_seed(inst, seed)
offset = Vec(
random.uniform(min_x, max_x),
random.uniform(min_y, max_y),
random.uniform(min_z, max_z),
)
offset.rotate_by_str(inst['angles'])
origin = Vec.from_str(inst['origin'])
origin += offset
inst['origin'] = origin
示例2: flag_angles
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import rotate_by_str [as 别名]
def flag_angles(inst: Entity, flag: Property):
"""Check that a instance is pointed in a direction.
The value should be either just the angle to check, or a block of
options:
- `Angle`: A unit vector (XYZ value) pointing in a direction, or some
keywords: `+z`, `-y`, `N`/`S`/`E`/`W`, `up`/`down`, `floor`/`ceiling`, or `walls` for any wall side.
- `From_dir`: The direction the unrotated instance is pointed in.
This lets the flag check multiple directions
- `Allow_inverse`: If true, this also returns True if the instance is
pointed the opposite direction .
"""
angle = inst['angles', '0 0 0']
if flag.has_children():
targ_angle = flag['direction', '0 0 0']
from_dir = flag['from_dir', '0 0 1']
if from_dir.casefold() in DIRECTIONS:
from_dir = Vec(DIRECTIONS[from_dir.casefold()])
else:
from_dir = Vec.from_str(from_dir, 0, 0, 1)
allow_inverse = srctools.conv_bool(flag['allow_inverse', '0'])
else:
targ_angle = flag.value
from_dir = Vec(0, 0, 1)
allow_inverse = False
normal = DIRECTIONS.get(targ_angle.casefold(), None)
if normal is None:
return False # If it's not a special angle,
# so it failed the exact match
inst_normal = from_dir.rotate_by_str(angle)
if normal == 'WALL':
# Special case - it's not on the floor or ceiling
return not (inst_normal == (0, 0, 1) or inst_normal == (0, 0, -1))
else:
return inst_normal == normal or (
allow_inverse and -inst_normal == normal
)
示例3: res_add_overlay_inst
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import rotate_by_str [as 别名]
def res_add_overlay_inst(inst: Entity, res: Property):
"""Add another instance on top of this one.
Values:
File: The filename.
Fixup Style: The Fixup style for the instance. '0' (default) is
Prefix, '1' is Suffix, and '2' is None.
Copy_Fixup: If true, all the $replace values from the original
instance will be copied over.
move_outputs: If true, outputs will be moved to this instance.
offset: The offset (relative to the base) that the instance
will be placed. Can be set to '<piston_top>' and
'<piston_bottom>' to offset based on the configuration.
'<piston_start>' will set it to the starting position, and
'<piston_end>' will set it to the ending position.
of piston platform handles.
angles: If set, overrides the base instance angles. This does
not affect the offset property.
fixup/localfixup: Keyvalues in this block will be copied to the
overlay entity.
If the value starts with $, the variable will be copied over.
If this is present, copy_fixup will be disabled.
"""
angle = res["angles", inst["angles", "0 0 0"]]
overlay_inst = vbsp.VMF.create_ent(
classname="func_instance",
targetname=inst["targetname", ""],
file=resolve_inst(res["file", ""])[0],
angles=angle,
origin=inst["origin"],
fixup_style=res["fixup_style", "0"],
)
# Don't run if the fixup block exists..
if srctools.conv_bool(res["copy_fixup", "1"]):
if "fixup" not in res and "localfixup" not in res:
# Copy the fixup values across from the original instance
for fixup, value in inst.fixup.items():
overlay_inst.fixup[fixup] = value
conditions.set_ent_keys(overlay_inst.fixup, inst, res, "fixup")
if res.bool("move_outputs", False):
overlay_inst.outputs = inst.outputs
inst.outputs = []
if "offset" in res:
folded_off = res["offset"].casefold()
# Offset the overlay by the given distance
# Some special placeholder values:
if folded_off == "<piston_start>":
if srctools.conv_bool(inst.fixup["$start_up", ""]):
folded_off = "<piston_top>"
else:
folded_off = "<piston_bottom>"
elif folded_off == "<piston_end>":
if srctools.conv_bool(inst.fixup["$start_up", ""]):
folded_off = "<piston_bottom>"
else:
folded_off = "<piston_top>"
if folded_off == "<piston_bottom>":
offset = Vec(z=srctools.conv_int(inst.fixup["$bottom_level"]) * 128)
elif folded_off == "<piston_top>":
offset = Vec(z=srctools.conv_int(inst.fixup["$top_level"], 1) * 128)
else:
# Regular vector
offset = Vec.from_str(conditions.resolve_value(inst, res["offset"]))
offset.rotate_by_str(inst["angles", "0 0 0"])
overlay_inst["origin"] = (offset + Vec.from_str(inst["origin"])).join(" ")
return overlay_inst
示例4: res_camera
# 需要导入模块: from srctools import Vec [as 别名]
# 或者: from srctools.Vec import rotate_by_str [as 别名]
def res_camera(inst: Entity, res: Property):
"""Result for the camera component.
"""
conf = res.value
normal = Vec(0, 0, 1).rotate_by_str(inst['angles'])
if normal.z != 0:
# Can't be on floor/ceiling!
inst.remove()
return
base_yaw = math.degrees(math.atan2(normal.y, normal.x)) % 360
inst['angles'] = '0 {:g} 0'.format(base_yaw)
inst_name = inst['targetname']
try:
[target] = inst.map.by_target[inst_name + '-target'] # type: Entity
except ValueError:
# No targets with that name
inst.remove()
return
for trig in inst.map.by_class['trigger_catapult']: # type: Entity
if trig['targetname'].startswith(inst_name):
trig.remove()
target_loc = Vec.from_str(target['origin'])
target.remove() # Not needed...
BULLSYE_LOCS[target_loc.as_tuple()] += 1
base_loc = Vec.from_str(inst['origin'])
# Move three times to position the camera arms and lens.
yaw_pos = Vec(conf['yaw_off']).rotate_by_str(inst['angles'])
yaw_pos += base_loc
pitch, yaw, _ = (target_loc - yaw_pos).to_angle()
inst.map.create_ent(
classname='func_instance',
targetname=inst['targetname'],
file=conf['yaw_inst'],
angles='0 {:g} 0'.format(yaw),
origin=yaw_pos,
)
pitch_pos = Vec(conf['pitch_off'])
pitch_pos.rotate(yaw=yaw)
pitch_pos.rotate_by_str(inst['angles'])
pitch_pos += yaw_pos
inst.map.create_ent(
classname='func_instance',
targetname=inst['targetname'],
file=conf['pitch_inst'],
angles='{:g} {:g} 0'.format(pitch, yaw),
origin=pitch_pos,
)
cam_pos = Vec(conf['cam_off'])
cam_pos.rotate(pitch=pitch, yaw=yaw)
cam_pos += pitch_pos
# Recompute, since this can be slightly different if the camera is large.
cam_angles = (target_loc - cam_pos).to_angle()
ALL_CAMERAS.append(Camera(inst, res.value, cam_pos, cam_angles))