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

bge.types.KX_Camera.rst « bge_types « rst « python_api « doc - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c8c68fc05158d28403f93acdc0f68c0149109cd (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
KX_Camera(KX_GameObject)
========================

base class --- :class:`KX_GameObject`

.. class:: KX_Camera(KX_GameObject)

   A Camera object.

   .. data:: INSIDE

      See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`

   .. data:: INTERSECT

      See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`

   .. data:: OUTSIDE

      See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`

   .. attribute:: lens

      The camera's lens value.

      :type: float

   .. attribute:: fov

      The camera's field of view value.

      :type: float

   .. attribute:: ortho_scale

      The camera's view scale when in orthographic mode.

      :type: float

   .. attribute:: near

      The camera's near clip distance.

      :type: float

   .. attribute:: far

      The camera's far clip distance.

      :type: float

   .. attribute:: shift_x

      The camera's horizontal shift.

      :type: float

   .. attribute:: shift_y

      The camera's vertical shift.

      :type: float

   .. attribute:: perspective

      True if this camera has a perspective transform, False for an orthographic projection.

      :type: boolean

   .. attribute:: frustum_culling

      True if this camera is frustum culling.

      :type: boolean

   .. attribute:: projection_matrix

      This camera's 4x4 projection matrix.

      .. note::
      
         This is the identity matrix prior to rendering the first frame (any Python done on frame 1). 

      :type: 4x4 Matrix [[float]]

   .. attribute:: modelview_matrix

      This camera's 4x4 model view matrix. (read-only).

      :type: 4x4 Matrix [[float]]

      .. note::
      
         This matrix is regenerated every frame from the camera's position and orientation. Also, this is the identity matrix prior to rendering the first frame (any Python done on frame 1).

   .. attribute:: camera_to_world

      This camera's camera to world transform. (read-only).

      :type: 4x4 Matrix [[float]]

      .. note::
      
         This matrix is regenerated every frame from the camera's position and orientation.

   .. attribute:: world_to_camera

      This camera's world to camera transform. (read-only).

      :type: 4x4 Matrix [[float]]

      .. note::
         
         Regenerated every frame from the camera's position and orientation.

      .. note::
      
         This is camera_to_world inverted.

   .. attribute:: useViewport

      True when the camera is used as a viewport, set True to enable a viewport for this camera.

      :type: boolean

   .. method:: sphereInsideFrustum(centre, radius)

      Tests the given sphere against the view frustum.

      :arg centre: The centre of the sphere (in world coordinates.)
      :type centre: list [x, y, z]
      :arg radius: the radius of the sphere
      :type radius: float
      :return: :data:`~bge.types.KX_Camera.INSIDE`, :data:`~bge.types.KX_Camera.OUTSIDE` or :data:`~bge.types.KX_Camera.INTERSECT`
      :rtype: integer

      .. note::

         When the camera is first initialized the result will be invalid because the projection matrix has not been set.

      .. code-block:: python

         from bge import logic
         cont = logic.getCurrentController()
         cam = cont.owner
         
         # A sphere of radius 4.0 located at [x, y, z] = [1.0, 1.0, 1.0]
         if (cam.sphereInsideFrustum([1.0, 1.0, 1.0], 4) != cam.OUTSIDE):
             # Sphere is inside frustum !
             # Do something useful !
         else:
             # Sphere is outside frustum

   .. method:: boxInsideFrustum(box)

      Tests the given box against the view frustum.

      :arg box: Eight (8) corner points of the box (in world coordinates.)
      :type box: list of lists
      :return: :data:`~bge.types.KX_Camera.INSIDE`, :data:`~bge.types.KX_Camera.OUTSIDE` or :data:`~bge.types.KX_Camera.INTERSECT`

      .. note::
      
         When the camera is first initialized the result will be invalid because the projection matrix has not been set.

      .. code-block:: python

         from bge import logic
         cont = logic.getCurrentController()
         cam = cont.owner

         # Box to test...
         box = []
         box.append([-1.0, -1.0, -1.0])
         box.append([-1.0, -1.0,  1.0])
         box.append([-1.0,  1.0, -1.0])
         box.append([-1.0,  1.0,  1.0])
         box.append([ 1.0, -1.0, -1.0])
         box.append([ 1.0, -1.0,  1.0])
         box.append([ 1.0,  1.0, -1.0])
         box.append([ 1.0,  1.0,  1.0])
         
         if (cam.boxInsideFrustum(box) != cam.OUTSIDE):
           # Box is inside/intersects frustum !
           # Do something useful !
         else:
           # Box is outside the frustum !
           
   .. method:: pointInsideFrustum(point)

      Tests the given point against the view frustum.

      :arg point: The point to test (in world coordinates.)
      :type point: 3D Vector
      :return: True if the given point is inside this camera's viewing frustum.
      :rtype: boolean

      .. note::
      
         When the camera is first initialized the result will be invalid because the projection matrix has not been set.

      .. code-block:: python

         from bge import logic
         cont = logic.getCurrentController()
         cam = cont.owner

         # Test point [0.0, 0.0, 0.0]
         if (cam.pointInsideFrustum([0.0, 0.0, 0.0])):
           # Point is inside frustum !
           # Do something useful !
         else:
           # Box is outside the frustum !

   .. method:: getCameraToWorld()

      Returns the camera-to-world transform.

      :return: the camera-to-world transform matrix.
      :rtype: matrix (4x4 list)

   .. method:: getWorldToCamera()

      Returns the world-to-camera transform.

      This returns the inverse matrix of getCameraToWorld().

      :return: the world-to-camera transform matrix.
      :rtype: matrix (4x4 list)

   .. method:: setOnTop()

      Set this cameras viewport ontop of all other viewport.

   .. method:: setViewport(left, bottom, right, top)

      Sets the region of this viewport on the screen in pixels.

      Use :data:`bge.render.getWindowHeight` and :data:`bge.render.getWindowWidth` to calculate values relative to the entire display.

      :arg left: left pixel coordinate of this viewport
      :type left: integer
      :arg bottom: bottom pixel coordinate of this viewport
      :type bottom: integer
      :arg right: right pixel coordinate of this viewport
      :type right: integer
      :arg top: top pixel coordinate of this viewport
      :type top: integer

   .. method:: getScreenPosition(object)

      Gets the position of an object projected on screen space.

      .. code-block:: python

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

      :arg object: object name or list [x, y, z]
      :type object: :class:`KX_GameObject` or 3D Vector
      :return: the object's position in screen coordinates.
      :rtype: list [x, y]

   .. method:: getScreenVect(x, y)

      Gets the vector from the camera position in the screen coordinate direction.

      :arg x: X Axis
      :type x: float
      :arg y: Y Axis
      :type y: float
      :rtype: 3D Vector
      :return: The vector from screen coordinate.

      .. code-block:: python

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

   .. method:: getScreenRay(x, y, dist=inf, property=None)

      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.

      :arg x: X Axis
      :type x: float
      :arg y: Y Axis
      :type y: float
      :arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
      :type dist: float
      :arg property: property name that object must have; can be omitted => detect any object
      :type property: string
      :rtype: :class:`KX_GameObject`
      :return: the first object hit or None if no object or object does not match prop

      .. code-block:: python

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