I worked out another aproach to this problem.
In simple words does it imitate the Ogre Raycast function.
In basics we have nearly everything we need.
We have our Camera Position in the World which can be retrieved with the
CameraX()
CameraY()
CameraZ()
Functions.
And we should know where the Camera is looking @.
( The values we give to CameraLookAt(X,Y,Z)
With this information we can create a Vector(StartPoint,Endpoint) where the Startpoint is the Camera Location and the Endpoint is where the Camera looks @.
Now we clone that vector and move both vector Points so the new vector is like Vector([Xstart+MouseOffset,Ystart+Mouseoffset,Zstart),[Xend+MouseOffset,Yend+Mouseoffset,Zend)
Along that vector we create a line/ray Entity+Mesh ( dont know how to describe it better ) with the lengt given by the maximum distence our picable objects are still rendered ( makes no sense to try to pick things we cant see ^^ )
Now we give our Ray a Physical Body with
EntityPhysicBody(#RayEntity, #PB_Entity_StaticBody)
and every pickable Object will get a suitable Physical Body.
When we do our Collission Check we can simply conpute the Object closest to the Camera which had a colission with our ray.
This object is the entity the user pointed on with his mouse.
Problems with this approach are
- we have to recompute the look@ Coordinates if we move the camera because we can set the value but cant retrieve the new value if we move our camera
- with a certain fov the approach wont work
- if the ray gets "out of the world" it will crash
But for things where the camera is always on a 2d plane and the angle to the ground is always the same ( like a 3d rts / rbs ) it should work fine to pick your units.
Still leaves the problem that we cant check colissions with the terrain so we cant order them to move to poin x/y ^^