# Simple orbit viewer using Chaser's template. Zoom. SOLVED

Hi there everyone! I’m trying to build a very simple orbit viewer using Chaser’s awesome camera/mouse/navigation/doeverything template (http://blenderartists.org/forum/showthread.php?t=159199).

The .blend file show where I’m stuck. I did a pic trying to explain what i think is missing, basically:

• Option 1: No restrictions along X and Y axis.
• Option 2: restrict 180 degrees along “Z” (to define a “ground like” plane).
• Zoom + / Zoom -
• Zoom max and Zoom Min.

Thank you very much,

Ortiz

### Attachments

SimpleViewer.blend (153 KB)

Hi Thorgal,

I’ve added Zoom using an IPO curve. See the attached file. My zoom method uses only logic bricks, but it could be converted to Python easily enough.

### Attachments

SimpleViewerWithZoom.blend (43.4 KB)

Simply awesome! Thank you so much! Can you tell us how properties “frame” and “factor” works? Would you recommend any math exercise to get how properties work? I really can’t understand how properties does the magic…

Do you have any clue about witch part of Chaser’s script controls the rotations limits?

I guess it is this one:

" #===============================
#=== Applying X Rotation ===
#===============================

# If we're not restricting the Y axis, and we're upside down,
# then we need to invert the X axis mouse movement.
if (not restrictY) and (not isUpright):
Xpivot.applyRotation([0, 0, -X], 0)
else:
Xpivot.applyRotation([0, 0, X], 0)

#===============================
#===   Applying Y Rotation   ===
#===============================
if restrictY:
# Y Axis is restricted

# Only allows movement while upright
if isUpright:
Ypivot.applyRotation([Y, 0, 0], 1)

# While not upright and you're facing down, allow you to look up again
elif isMovingUp and not isFacingUp:
Ypivot.applyRotation([Y, 0, 0], 1)

# While not upright and you're facing up, allow you to look down again
elif not isMovingUp and isFacingUp:
Ypivot.applyRotation([Y, 0, 0], 1)

else:
# Y Axis is now restricted
Ypivot.applyRotation([Y, 0, 0], 1)"

But i can’t deal with this matrix (?) without screwing the whole thing…Do you think it is just a matter of changing values inside this kind of structure >>> “([A, B, C], D)”?

Thank you again!

frame holds the value of the current frame of the camera’s IPO curve. Frame 1 is farthest away, frame 101 is closest (the minZoom and maxZoom properties). When the value of frame changes, the IPO curve is updated, so the camera’s position moves along the curve.

factor controls how large or small the steps are, which causes the zooming to be faster or slower. When you zoom in by one step, the value of factor is added to the value of frame. So if factor is 3.5 and frame is 1.0, then frame will become 4.5, and the camera’s frame in the IPO curve will be updated.

Yes. The portion of the script which controls the constraint is this:

ori = Ypivot.orientation

ZZ = ori[2][2]
isUpright = isPositive(ZZ)

If I understand your picture correctly, you want to change the constraint from the Z axis to the X axis. I do not understand the orientation matrix well enough to make that change. This is one of the reasons why I generally use IPO curves to set up a mouselook instead of motion actuators.

Yep! here goes another pic!

Thank you very much for the masterclass Blendenzo!

### Attachments

Hey Thorgal, I’m glad to see that you’re making use of the mouselook template.
I modified the part of the script that handled the Y restrictions, so now it works like in your pictures.

I made the changes to the version with Blendenzo’s zoom.

Let me know if you need any more help, or have any questions.
-Chaser

Chaser! Thank you sooooo much! You’re kind!

##################################
### ------ Mouse Script ------ ###
##################################
# By Chase Moskal

#====================
#===   Settings   ===
#====================

# X and Y Sensitivity
mxsens = 5.0
mysens = 5.0

# Invert X and/or Y axes?
invertX = 0
invertY = 0

# Restrict Y axis? (disallow looking upside-down?)
restrictY = 1

#=========================
#===   getting stuff   ===
#=========================

import GameLogic as gl
import Rasterizer
import mousetools

con = gl.getCurrentController()
own = con.owner
mousemove = con.sensors["mousemove"]

# For an FPS, set the player collision box to Xpivot,
# and set up an empty as the Y pivot.
Ypivot = own
Xpivot = own

#=================================
#===   mousetools initiation   ===
#=================================
if not mousetools.INIT:
mousetools.mouse = mousetools.MOUSE(mousemove)
mousetools.INIT = 1

#=================================
#===   Real Mouselook Action   ===
#=================================

# Little function to check if something
# is positive (&gt;=0)
def isPositive(x):
if x &gt;= 0.0:
return 1
return 0

# Shortcut to the mouse object
mouse = mousetools.mouse
# Hiding the mouse cursor
mouse.hide()

# mlook property enables/disables mouselook.
if own["mlook"]:

# Getting mouse movement...
Xmovement, Ymovement = mouse.getMovement()

# Converting sensitivity to lower terms
Xc = mxsens * 0.001
Yc = mysens * 0.001

# Getting the rotation values.
X = -float(Xmovement) * Xc
Y = float(Ymovement) * Yc

# Inversions
if invertX:
X *= -1
if invertY:
Y *= -1

# Getting orientation matrix
# information that will determine the
# mouselook Y restrictions.

isMovingUp = isPositive(Y) # checks if the mouse movement is currently up (1) or down (0)

ori = Ypivot.orientation

# Getting uprightness.
ZZ = ori[2][2] # Z axis' Z component
isUpright = isPositive(ZZ) # 1 means it's upright, 0 means it's upside-down.

# Getting the facing upness
YZ = ori[2][1] # Y axis' Z component
isFacingUp = isPositive(YZ)
# Imagine the user on a perfectly smooth floor that spans infinitely into the distance.
# isFacingUp tells you if the player is looking at the floor (0), or at the sky (1).

### ================================================ ###
### ========= THORGAL'S RESTRICTION SETUP ========== ###
### ================================================ ###
# The parts of the script below are customized for
# Thorgal's orbiter at http://blenderartists.org/forum/showthread.php?t=164161

#===============================
#===   Applying X Rotation   ===
#===============================

if not isUpright:
# If we're upside down,
# then we need to invert the X axis mouse movement.
Xpivot.applyRotation([0, 0, -X], 0)
else:
Xpivot.applyRotation([0, 0, X], 0)

#===============================
#===   Applying Y Rotation   ===
#===============================
if restrictY:
# Y Axis is restricted

# Only allows movement while facing downwards.
if not isFacingUp:
Ypivot.applyRotation([Y, 0, 0], 1)

# While not upright and you're facing down, allow you to look up again
elif isMovingUp and (not isUpright):
Ypivot.applyRotation([Y, 0, 0], 1)

# While not upright and you're facing up, allow you to look down again
elif not isMovingUp and isUpright:
Ypivot.applyRotation([Y, 0, 0], 1)

else:
# Y Axis is NOT restricted
Ypivot.applyRotation([Y, 0, 0], 1)