Ejemplo n.º 1
0
def CalcDesiredPlayerHeading(heading):
    """
    The players movement is 8 directional relative to the facing direction of the
    camera. We need to work out as a worldspace yaw the direction the player should be
    moving in.
    
    heading - 3D vector represents the control inputs. 
            z, is forward and backwards. 
            x, is left and right.
    """
    headingYaw = mathCommon.GetYawAngleFromDirectionVector(heading)
    activeCamera = sm.GetService('cameraClient').GetActiveCamera()
    cameraYaw = -activeCamera.yaw
    desiredYaw = cameraYaw + headingYaw
    return desiredYaw
Ejemplo n.º 2
0
 def UpdateMovement(self):
     debug = sm.GetService('debugRenderClient')
     yaw = geo2.QuaternionRotationGetYawPitchRoll(
         self.entityRef.position.rotation)[0]
     velYaw = mathCommon.GetYawAngleFromDirectionVector(self.entVel)
     angle = mathCommon.GetLesserAngleBetweenYaws(yaw, velYaw)
     headingToApply = self.entityRef.movement.physics.velocity
     speed = geo2.Vec3Length((headingToApply[0], 0.0, headingToApply[2]))
     self.SetControlParameter('Speed', speed)
     moveState = self.entityRef.GetComponent('movement').moveState
     self.SetControlParameter('Moving',
                              int(moveState.GetStaticStateIndex() > 0))
     immed = moveState.GetImmediateRotation()
     if immed != 0.0:
         self.SetControlParameter('TurnAngle', immed / math.pi)
     else:
         self.SetControlParameter('TurnAngle', 0.0)
Ejemplo n.º 3
0
 def Update(self, controller):
     if hasattr(controller.entityRef, 'aiming'):
         debugBoneName = 'fj_eyeballLeft'
         gazeAtEntityID = self.aimingClient.GetTargetEntityID(controller.entityRef, const.aiming.AIMING_VALID_TARGET_GAZE_ID)
         if gazeAtEntityID:
             gazeAtEntity = self.entityService.FindEntityByID(gazeAtEntityID)
             if gazeAtEntity:
                 sensorPos = geo2.Vector(*controller.entityRef.position.position)
                 sensorPos = sensorPos + self.perceptionClient.GetSensorOffset(controller.entityRef)
                 focusPos = geo2.Vector(*gazeAtEntity.position.position)
                 focusPos = focusPos + self.perceptionClient.GetSensorOffset(gazeAtEntity)
                 headTransform = controller.animationNetwork.GetBoneTransform(debugBoneName)
                 if headTransform is None:
                     return
                 headTranslation, headRotation = headTransform
                 useBlendToHeadBone = False
                 if useBlendToHeadBone:
                     workPos = geo2.Vec3Subtract(focusPos, controller.entPos)
                     entRotInvQuat = geo2.QuaternionInverse(controller.entRot)
                     entRotInvQuat = geo2.QuaternionNormalize(entRotInvQuat)
                     workPos = geo2.QuaternionTransformVector(entRotInvQuat, workPos)
                     workPos = geo2.Vec3Subtract(workPos, headTranslation)
                     headRotInvQuat = geo2.QuaternionInverse(headRotation)
                     headRotInvQuat = geo2.QuaternionNormalize(headRotInvQuat)
                     workPos = geo2.QuaternionTransformVector(headRotInvQuat, workPos)
                     relativeLookAtYaw = mathCommon.GetYawAngleFromDirectionVector(workPos)
                     relativeLookAtPitch = mathCommon.GetPitchAngleFromDirectionVector(workPos)
                 else:
                     sensorToFocusVec = geo2.Vec3Subtract(focusPos, sensorPos)
                     yawToFocus = mathCommon.GetYawAngleFromDirectionVector(sensorToFocusVec)
                     pitchToFocus = mathCommon.GetPitchAngleFromDirectionVector(sensorToFocusVec)
                     entityYaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(controller.entRot)
                     relativeLookAtYaw = yawToFocus - entityYaw
                     relativeLookAtPitch = pitchToFocus
                 relativeLookAtYaw = math.fmod(relativeLookAtYaw, 2 * math.pi)
                 relativeLookAtPitch = math.fmod(relativeLookAtPitch, 2 * math.pi)
                 if relativeLookAtYaw < 0:
                     relativeLookAtYaw = relativeLookAtYaw + 2 * math.pi
                 if relativeLookAtPitch < 0:
                     relativeLookAtPitch = relativeLookAtPitch + 2 * math.pi
                 if relativeLookAtYaw > math.pi:
                     relativeLookAtYaw = relativeLookAtYaw - 2 * math.pi
                 if relativeLookAtPitch > math.pi:
                     relativeLookAtPitch = relativeLookAtPitch - 2 * math.pi
                 if geo2.Vec3LengthSq(controller.entityRef.movement.physics.velocity) > 0.0:
                     maxYaw = MAXIMUM_HEAD_LOOK_ANGLE_YAW_MOVING
                     maxPitch = MAXIMUM_HEAD_LOOK_ANGLE_PITCH_MOVING
                 else:
                     maxYaw = MAXIMUM_HEAD_LOOK_ANGLE_YAW
                     maxPitch = MAXIMUM_HEAD_LOOK_ANGLE_PITCH
                 if abs(relativeLookAtYaw) < maxYaw and abs(relativeLookAtPitch) < maxPitch:
                     controller.SetControlParameter('Aim_X', -relativeLookAtYaw)
                     controller.SetControlParameter('Aim_Y', -relativeLookAtPitch)
                     controller.SetControlParameter('HeadLookWeight', 1)
                     aimingManager = self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID)
                     if aimingManager.IsDebugRendering():
                         self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID).SetDebugUsedParams(controller.entityRef.entityID, relativeLookAtYaw, -relativeLookAtPitch, maxYaw, maxPitch, headTranslation, headRotation)
                     return
         controller.SetControlParameter('HeadLookWeight', 0)
         aimingManager = self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID)
         if aimingManager.IsDebugRendering():
             translation, orientation = controller.entityRef.animation.updater.network.GetBoneTransform(debugBoneName)
             self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID).SetDebugUsedParams(controller.entityRef.entityID, -99, -99, MAXIMUM_HEAD_LOOK_ANGLE_YAW, MAXIMUM_HEAD_LOOK_ANGLE_PITCH, translation, orientation)
Ejemplo n.º 4
0
def GetYawFromDirection(sourcePos, targetPos):
    targetVec = geo2.Vec3Subtract(targetPos, sourcePos)
    return mathCommon.GetYawAngleFromDirectionVector(geo2.Vector(*targetVec))
Ejemplo n.º 5
0
def CalcDesiredPlayerHeading(heading):
    headingYaw = mathCommon.GetYawAngleFromDirectionVector(heading)
    activeCamera = sm.GetService('cameraClient').GetActiveCamera()
    cameraYaw = -activeCamera.yaw
    desiredYaw = cameraYaw + headingYaw
    return desiredYaw