clickable object


27-07-2006 12:49:41

i would to click on an object in the 3d space and when mouse has pressed i'd like it hide. how can i do it? i'd read all the framelistener's tutorial but i haven't find what i would like to do
thank you for help


28-07-2006 08:34:24

this is the code that put the pawns on the chessboard:

for index in xrange(0, len(ListaLoc)):
entity = sceneManager.createEntity('pedina%d' % index, 'sfera.mesh')
#in x,y,z ci vanno le coordinate di ListaLoc
Lista = ListaLoc[index]
x = Lista[0]
y = Lista[1]
z = Lista[2]


28-07-2006 09:44:15

Here is a sample of 3d mouse picking in C++, it should get you started ... Tutorial_3


28-07-2006 09:52:33

There's a pyogre version based on that tutorial. It's for pyogre 1.2 and uses pycegui but you should be able to strip out what you need. ... rev=0&sc=0

In particular check the CEGUIFrameListener:

self.raySceneQuery = sceneManager.createRayQuery(ogre.Ray(self.mCamera.position, ogre.Vector3.NEGATIVE_UNIT_Y))


mouseRay = self.mCamera.getCameraToViewportRay( evt.x, evt.y)
self.raySceneQuery.ray = mouseRay

for queryResult in self.raySceneQuery.execute():


30-07-2007 21:40:11

Hello... That tutorial is no longer up, or at least it won't open for me, and I'm trying to figure out how to select objects in python-ogre as well.... any help would be greatly appreciated.

Thanks all!


30-07-2007 22:41:30

The demos/OgreNewt/Demo_xxraycasting demo has an example of this you could use as well



31-07-2007 14:11:00

def mousePickingObjects(self, (x, y)):
"""Mouse picking function-
Input: Screen Location of a point (x, y);
Generate a camera-to-viewport ray perpendicular to the screen plane and do a ray query.
Return: the objects on the ray """
#Get screen location x, y converted into a ratio (from 0 to 1)
screenX = float(x)/self.window.width
screenY = float(y)/self.window.height
#Create a ray which starts from the 3D point represented by the point (x, y) on the screen plane
mouseRay =, screenY)
#create a mouse picker
mousePicker = self.sceneManager.createRayQuery(mouseRay)
#set the ray to the ray we created
mousePicker.ray = mouseRay
#tell the query that the result should be sorted by the distance the ray travelled before hitting an object
return mousePicker.execute()


03-09-2007 07:15:01

So are there any other relatively easy ways to do this?

OgreNewt kinda works, but I can't get the body to rotate properly in order for it to work for me. So basically I get to mousepick the model at its original orientation even tho it should be rotating around. That said I didn't reattach the body after I created it, so maybe thats causing this issue? Attached it was messing up the code I currently have in to move players.

As for using the ogre .createRayQuery, evidentally I'm not actually using a SceneManager, I'm using a DefaultSceneManager, which doesn't seem to work properly. I can execute fine, as long as theres nothing that I'll hit, when I attempt to actually click on a MovableObject I get an error:

File "C:\Solution1\Solution1\", line 2646, in handle_mouse_land
TypeError: 'NoneType' object is not callable


03-09-2007 08:11:06

Ahh, it appears I'm was just having Quaternion issues.

The way I'm drawing meshes now uses three scene nodes.

ModelOrientation (Allows use of models which may be oriented on seperate axes).

Rotation + Model Orientation = Headache...


08-03-2008 09:26:11

I'm using CEGUI mouse cursor and selecting entities. This works in many cases, but when two objects are intersecting, yet one is clearly behind or smaller than the other, the partially occluded and further away entity is returned. No other entity appears in the results.

The mouse picker returned an error in Python-Ogre. So I'm using the ray scene query listener workaround.

class RaySceneQueryListener( ogre.RaySceneQueryListener ):
'''Work around to mouse-pick 3D object.

>>> application = alphabet_ogre_application()
>>> listener = RaySceneQueryListener()

# TODO: DEBUG proper order
# TODO: Prevent CEGUI unit test from crashing.
###>>> cursor = CEGUI.MouseCursor.getSingleton()
###>>> x, y = cursor.getPosition().d_x, cursor.getPosition().d_y
###>>> listener.getCoords(application, x, y)
def __init__( self ):
super( RaySceneQueryListener, self ).__init__()
self.result_list = []
self.ray = None
self.query = application.sceneManager.createRayQuery(ogre.Ray())

def get_entity( self, application, x, y ):
w = float( x ) / application.renderWindow.width
h = float( y ) / application.renderWindow.height

self.ray =, h)
self.query.setRay( self.ray )
self.query.setSortByDistance( True )
self.result_list = []
self.query.execute( self )
return self.result_list
def queryResult( self, entity, distance ):
self.result_list.append( (entity, self.ray.getPoint(distance)) )

Is my queryResult valid? Can you tell me what I'm doing wrong? I read that Ogre does not support exact geometry, but I'm dealing with axis-aligned boxes, which are PT_CUBEs that have been scaled. I am showing the bounding box of the mouse ray's intersection and can see that nonintersecting nodes select nearest as desired, yet intersecting AABB geometry has anomalous selections.

I tried mousePicker code below, but received the error below, which is why I adopted the workaround above:

>>> mousePickingObjects(application, (application.cursor.getPosition().d_x, application.cursor.getPosition().d_y))
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 17, in mousePickingObjects
ArgumentError: Python argument types in
did not match C++ signature:
execute(struct DefaultRaySceneQuery_wrapper {lvalue}, class Ogre::RaySceneQueryListener * listener)
execute(class Ogre::DefaultRaySceneQuery {lvalue}, class Ogre::RaySceneQueryListener * listener)