本文整理汇总了Python中Input.camInput方法的典型用法代码示例。如果您正苦于以下问题:Python Input.camInput方法的具体用法?Python Input.camInput怎么用?Python Input.camInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input.camInput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Input [as 别名]
# 或者: from Input import camInput [as 别名]
def main():
import bge
import math
import mathutils
import TMath
import Input
import Config as C
logic = bge.logic
cont = logic.getCurrentController()
own = cont.owner
sce = logic.getCurrentScene()
#get the camera's target player object
player = sce.objects[C.Follow]
#get the camera's and player's orientations
pOrient = player.worldOrientation
cOrient = own.worldOrientation
#get the input vector for manual camera control
input = Input.camInput()
inputVec = input[0]
#this variable tells the script whether to use auto or manual mode
manual = (not input[1])
#create a manual angle variable if there is none (to store the manually adjusted vertical angle of cam)
#Initialize it to the value of the 'Angle' property
if not 'ManualAngle' in own:
own['ManualAngle'] = C.Angle
mAngle = own['ManualAngle']
prevAngle = mAngle
#Toggle between auto and manual mode
if not manual:
#set manual angle equal to 'Angle' property in auto mode(in which case it isn't really manual)
mAngle = C.Angle
#player adjustment of the vertical angle in manual mode
if manual == True:
#modify the manual angle based on the vertical axis of the camera input vector
mAngle += C.ManualTurnSpeed * inputVec[1]
#Clamp the angle to within the defined range, to stop the user from doing crazy camera inversions.
if mAngle > C.AngleLimitUp:
mAngle = C.AngleLimitUp
if mAngle < C.AngleLimitDown:
mAngle = C.AngleLimitDown
#This stores the difference between the current and previous vertical angles (to be used later)
#The .9 multiplier just makes the camera's movements a bit more stable
differenceAngle = .9 * (mAngle - prevAngle)
#Store the manual angle in the 'ManualAngle' property
own['ManualAngle'] = mAngle
###Setting The Cam's Orientation###
#Rotate player orientation by 90 degrees (around X) plus the manual angle to create a target orientation
#that is later interpolated with the current oreintation
rotmat = mathutils.Matrix.Rotation(math.pi*0.5 - mAngle, 3, 'X')
#target orientation
tOrient = pOrient * rotmat
if manual == True:
#When manual control is active, this stops the camera from matching the player's z-axis rotation.
#This means the cam won't automatically follow behind-the-back anymore.
#However, the cool thing is that, if the player actually tilts sideways (due to gravity-bending madness),
#or if the camera gets thrown off-kilter, it will right itself to be rightside-up relative to the player.
#This is kind of hackish. It'd be better to only follow the x and y-axis rotations in the first place (but hard and tedious to code!)
tVec = TMath.VecToPlane(tOrient.col[2],pOrient.col[0],pOrient.col[1])
cVec = TMath.VecToPlane(cOrient.col[2],pOrient.col[0],pOrient.col[1])
rotmat2 = TMath.VecToVecMatrix(cVec,tVec)
tOrient = rotmat2 * tOrient
#Generate turn speed factor to stop turning when player is facing towards camera, among other things
#The factor is just 1(meaning no modification to the turn speed) when manual mode is on
Fac = 1
#when manual mode is off, the factor is determined like so
if manual == False:
CamProj = TMath.VecToPlane(cOrient.col[2], pOrient.col[0], pOrient.col[1])
TargetProj = TMath.VecToPlane(tOrient.col[2], pOrient.col[0], pOrient.col[1])
Fac = CamProj.dot(TargetProj)
if Fac >= 0:
Fac = 1
else:
Fac += 1
if Fac < 0:
Fac = 0
Fac *= 8
if Fac > 1:
Fac = 1
##Interpolate between old and new cam orientation##
#In manual mode...
if manual == True:
#.........这里部分代码省略.........