~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to doc/python_api/alternative/examples/bge.render.py

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
 
2
# To use a mouse movement sensor "Mouse" and a 
 
3
# motion actuator to mouse look:
 
4
import bge.render
 
5
import bge.logic
 
6
 
 
7
# SCALE sets the speed of motion
 
8
SCALE=[1, 0.5]
 
9
 
 
10
co = bge.logic.getCurrentController()
 
11
obj = co.getOwner()
 
12
mouse = co.getSensor("Mouse")
 
13
lmotion = co.getActuator("LMove")
 
14
wmotion = co.getActuator("WMove")
 
15
 
 
16
# Transform the mouse coordinates to see how far the mouse has moved.
 
17
def mousePos():
 
18
        x = (bge.render.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
 
19
        y = (bge.render.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
 
20
        return (x, y)
 
21
 
 
22
pos = mousePos()
 
23
 
 
24
# Set the amount of motion: X is applied in world coordinates...
 
25
lmotion.setTorque(0.0, 0.0, pos[0], False)
 
26
# ...Y is applied in local coordinates
 
27
wmotion.setTorque(-pos[1], 0.0, 0.0, True)
 
28
 
 
29
# Activate both actuators
 
30
bge.logic.addActiveActuator(lmotion, True)
 
31
bge.logic.addActiveActuator(wmotion, True)
 
32
 
 
33
# Centre the mouse
 
34
bge.render.setMousePosition(bge.render.getWindowWidth()/2, bge.render.getWindowHeight()/2)
 
35