Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Rasterizer.py « PyDoc « gameengine « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a2d6408ac908fe43e3726945b06a5e314895810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# $Id$
"""
Documentation for the Rasterizer module.

Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
	# To use a mouse movement sensor "Mouse" and a 
	# motion actuator to mouse look:
	import Rasterizer
	import GameLogic

	# SCALE sets the speed of motion
	SCALE=[1, 0.5]
	
	co = GameLogic.getCurrentController()
	obj = co.getOwner()
	mouse = co.getSensor("Mouse")
	lmotion = co.getActuator("LMove")
	wmotion = co.getActuator("WMove")
	
	# Transform the mouse coordinates to see how far the mouse has moved.
	def mousePos():
		x = (Rasterizer.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
		y = (Rasterizer.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
		return (x, y)
	
	pos = mousePos()
	
	# Set the amount of motion: X is applied in world coordinates...
	lmotion.setTorque(0.0, 0.0, pos[0], False)
	# ...Y is applied in local coordinates
	wmotion.setTorque(-pos[1], 0.0, 0.0, True)
	
	# Activate both actuators
	GameLogic.addActiveActuator(lmotion, True)
	GameLogic.addActiveActuator(wmotion, True)
	
	# Centre the mouse
	Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)

@group Material Types: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
@var KX_TEXFACE_MATERIAL: Materials as defined by the texture face settings.
@var KX_BLENDER_MULTITEX_MATERIAL: Materials approximating blender materials with multitexturing.
@var KX_BLENDER_GLSL_MATERIAL: Materials approximating blender materials with GLSL.

"""

def getScreenPosition(arg):
	"""
	Gets the position of an object projected on screen space.

	Example:
	# For an object in the middle of the screen, coord = [0.5,0.5]
	coord = Rasterizer.getScreenPosition(object)

	@param arg: L{KX_GameObject}, object name or list [x, y, z]
	@rtype: list [x, y]
	@return: the object's position in screen coordinates.
	"""
def getScreenVect(x, y):
	"""
	Gets the vector from the camera position in the screen coordinate direction.

	Example:
	# Gets the vector of the camera front direction:
	m_vect = Rasterizer.getScreenVect(0.5,0.5)

	@type x: float
	@type y: float
	@rtype: 3d vector
	@return: the vector from a screen coordinate.
	"""
def getScreenRay(x, y, dist, property):
	"""
	Look towards a screen coordinate (x,y) and find first object hit within dist that matches prop.
	The ray is similar to KX_GameObject->rayCastTo.

	Example:
	# Gets an object with a property "wall" in front of the camera within a distance of 100:
	target = Rasterizer.getScreenRay(0.5,0.5,100,"wall")

	@type x: float
	@type y: float
	@param dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
	@type dist: float
	@param prop: property name that object must have; can be omitted => detect any object
	@type prop: string
	@rtype: L{KX_GameObject}
	@return: the first object hit or None if no object or object does not match prop
	"""
def getWindowWidth():
	"""
	Gets the width of the window (in pixels)
	
	@rtype: integer
	"""
def getWindowHeight():
	"""
	Gets the height of the window (in pixels)
	
	@rtype: integer
	"""
def makeScreenshot(filename):
	"""
	Writes a screenshot to the given filename.
	
	If filename starts with // the image will be saved relative to the current directory.
	If the filename contains # it will be replaced with the frame number.
	
	The standalone player saves .png files. It does not support colour space conversion 
	or gamma correction.
	
	When run from Blender, makeScreenshot supports Iris, IrisZ, TGA, Raw TGA, PNG, HamX, and Jpeg.
	Gamma, Colourspace conversion and Jpeg compression are taken from the Render settings panels.
	
	@type filename: string
	"""

def enableVisibility(visible):
	"""
	Doesn't really do anything...
	"""

def showMouse(visible):
	"""
	Enables or disables the operating system mouse cursor.
	
	@type visible: boolean
	"""

def setMousePosition(x, y):
	"""
	Sets the mouse cursor position.
	
	@type x: integer
	@type y: integer
	"""

def setBackgroundColor(rgba):
	"""
	Sets the window background colour.
	
	@type rgba: list [r, g, b, a]
	"""

def setMistColor(rgb):
	"""
	Sets the mist colour.
	
	@type rgb: list [r, g, b]
	"""

def setMistStart(start):
	"""
	Sets the mist start value.  Objects further away than start will have mist applied to them.
	
	@type start: float
	"""

def setMistEnd(end):
	"""
	Sets the mist end value.  Objects further away from this will be coloured solid with
	the colour set by setMistColor().
	
	@type end: float
	"""
	
def setEyeSeparation(eyesep):
	"""
	Sets the eye separation for stereo mode.
	
	@param eyesep: The distance between the left and right eye.
	@type eyesep: float
	"""

def getEyeSeparation():
	"""
	Gets the current eye separation for stereo mode.
	
	@rtype: float
	"""
	
def setFocalLength(focallength):
	"""
	Sets the focal length for stereo mode.
	
	@param focallength: The focal length.  
	@type focallength: float
	"""

def getFocalLength():
	"""
	Gets the current focal length for stereo mode.
	
	@rtype: float
	"""

def setMaterialMode(mode):
	"""
	Set the material mode to use for OpenGL rendering.
	
	@type mode: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
	@note: Changes will only affect newly created scenes.
	"""

def getMaterialMode(mode):
	"""
	Get the material mode to use for OpenGL rendering.
	
	@rtype: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
	"""

def setGLSLMaterialSetting(setting, enable):
	"""
	Enables or disables a GLSL material setting.
	
	@type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
	@type enable: boolean
	"""

def getGLSLMaterialSetting(setting, enable):
	"""
	Get the state of a GLSL material setting.
	
	@type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
	@rtype: boolean
	"""

def drawLine(fromVec,toVec,color):
	"""
	Draw a line in the 3D scene.
	
	@param fromVec: the origin of the line
	@type fromVec: list [x, y, z]
	@param toVec: the end of the line
	@type toVec: list [x, y, z]
	@param color: the color of the line
	@type color: list [r, g, b]
	"""