From 7ac233be8abc405cc997f032c9ab146c2ab8ea89 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Thu, 23 Apr 2009 00:49:38 +0000 Subject: BGE Rasterizer methods to handle Screen Space - (getScreenPosition, getScreenVect, getScreenRay) getScreenPosition(obj): - Gets the position of an object projected on screen space. getScreenVect(x, y): - Gets the vector from the camera position in the screen coordinate direction. 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 a call to KX_GameObject->rayCastTo from the KX_Camera object. Patch [#18589] test files can be found there. Patch reviewed by Campbell --- source/gameengine/PyDoc/KX_GameObject.py | 2 +- source/gameengine/PyDoc/Rasterizer.py | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'source/gameengine/PyDoc') diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 21ddf439924..abdd4c3eda1 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -82,7 +82,7 @@ class KX_GameObject: # (SCA_IObject) @ivar isValid: Retuerns fails when the object has been removed from the scene and can no longer be used. @type isValid: bool """ - def endObject(visible): + def endObject(): """ Delete this object, can be used inpace of the EndObject Actuator. The actual removal of the object from the scene is delayed. diff --git a/source/gameengine/PyDoc/Rasterizer.py b/source/gameengine/PyDoc/Rasterizer.py index 6a67cdcc71b..3a2d6408ac9 100644 --- a/source/gameengine/PyDoc/Rasterizer.py +++ b/source/gameengine/PyDoc/Rasterizer.py @@ -44,6 +44,49 @@ Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement M """ +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) -- cgit v1.2.3