Graphics Programs Reference
In-Depth Information
xRotator = viewRot.owner
zRotator = baseMover.owner
# read the current X rotation of the xRotator object ("derived"
object)
xCurrentRot = xRotator.orientation.to_euler().x
# if the current x rotation of the object is outside the allowed
range…
if xCurrentRot < MIN_ANGLE or xCurrentRot > MAX_ANGLE:
# check to see if the excess is above or below and save the
appropriate max in refAngle
if xCurrentRot > MAX_ANGLE: refAngle = MAX_ANGLE
elif xCurrentRot < MIN_ANGLE: refAngle = MIN_ANGLE
# calculate how much to rotate the object to get it back into
the allowed range of values
deltaXCurrentRot = refAngle - xCurrentRot
# apply the correction to the x component of the rotation
xRotator.applyRotation([deltaXCurrentRot, 0, 0], 1)
# if the click sensor sent a positive pulse and it isn't being
held from a previous click…
if click.positive and not obj['hold']:
# remember the click is being held down by setting the hold
property to True
obj['hold'] = True
# remember where in the screen the click happened. Notice
these two properties are being created on-the-fly in this script.
obj['centerX'] = click.position[0]
obj['centerY'] = click.position[1]
# hide the mouse pointer
hideMousePointer()
# in case the condition for the previous if wasn't evaluated to
"true", let's check if the sensor sending the positive pulse is
the unclick sensor, if so…
elif unclick.positive:
# … remember that the mouse button was released
obj['hold'] = False
# turn off the actuators that were rotating the camera in the
scene. If they are not explicitly deactivated, the camera could
keep moving after the user releases the mouse button
cont.deactivate(viewRot)
cont.deactivate(baseMover)
# show the mouse pointer to indicate to the user the camera
isn't being moved
showMousePointer()
# if the pointer is being moved and the mouse button is held down…
 
Search WWH ::




Custom Search