本文整理汇总了Python中mathutils.Euler.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Euler.rotate方法的具体用法?Python Euler.rotate怎么用?Python Euler.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Euler
的用法示例。
在下文中一共展示了Euler.rotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eval_planet_rotation
# 需要导入模块: from mathutils import Euler [as 别名]
# 或者: from mathutils.Euler import rotate [as 别名]
def eval_planet_rotation(scn_name, obj_name, index=None, time=None):
"""Evaluate the planets rotation, used by driver.
scn_name = Name of a scene which contains the object
obj_name = Name of the object to simulate
index = index of the rotation channel,
usually only z-axis (index=2) changes
time = time when to calculate, if not given use current scene time
time is in seconds of the simulation
returns an Euler in mode ZYX or, if index given, an angle in radians
"""
scn = bpy.data.scenes.get(scn_name)
obj = bpy.data.objects.get(obj_name)
if not obj or not scn:
errmsg = "DRIVER ERROR: Invalid obj_name ({}) or scn_name ({})"
print(errmsg.format(obj_name, scn_name))
return 0
simscn = scn.sssim_scn
simrot = obj.sssim_rotation
# time = time in seconds, if None use current scene time
if time is None:
time = simscn.time
# rotation_period is also in seconds
rotation_period = simrot.rotation_period
if rotation_period != 0:
rot_z = 2 * pi * time / rotation_period
else:
# invalid input -> no rotation
rot_z = 0
tilt = simrot.axis_tilt
planet_rot = Euler((tilt, 0.0, 0.0), 'ZYX') # note that mode is 'ZYX'
# rotate around global (not local) z-axis
direction = simrot.axis_direction
planet_rot.rotate(Euler((0.0, 0.0, direction), 'XYZ'))
# rotate around local z-axis
# NOTE: we won't use planet_rot.rotate_axis('Z', rot_z) because then
# all rotations are between -180 and 180 and for the rotation around
# z we need a continous motion with increasing z values
planet_rot.z += rot_z
if simrot.relative_to_orbit and obj.sssim_obj.object_type == 'PLANET':
planet_rot = orbit_rotate(planet_rot, obj.sssim_orbit)
if index is None:
return planet_rot
else:
return planet_rot[index]
示例2: poll
# 需要导入模块: from mathutils import Euler [as 别名]
# 或者: from mathutils.Euler import rotate [as 别名]
import time
from rift import PyRift
from mathutils import Quaternion, Euler, Vector
# Functions
def poll():
bge.logic.rift.pollSensor()
bge.logic.rotation = Quaternion((bge.logic.rift.headPose[3], bge.logic.rift.headPose[4], bge.logic.rift.headPose[5], bge.logic.rift.headPose[6]))
bge.logic.position = Vector((bge.logic.rift.headPose[0],bge.logic.rift.headPose[1],bge.logic.rift.headPose[2]))
# Main
try:
eu = bge.logic.rotation.to_euler()
fix = Euler((-1.57, 0, 0), 'XYZ')
rot = Euler((-eu.z, eu.y, -eu.x), 'XYZ')
rot.rotate(fix)
bge.logic.prev_orientation = rot;
poll()
except:
bge.logic.rift = PyRift()
bge.logic.rift.connect()
scene_e = bge.logic.getCurrentScene()
cam_e = scene_e.active_camera
bge.logic.init_position = Vector((cam_e.localPosition[0],cam_e.localPosition[1],cam_e.localPosition[2]))
bge.logic.init_orientation = cam_e.localOrientation.to_euler()
eu = Euler()
fix = Euler((1.57, 0, 0), 'XYZ')