Long version:
Hello guys, I am now Trying to select objects with the click of the mouse.
I managed to do it using the physics system, creating a very small object of size 1x1 and placing it where the mouse is clicked, the problem is that the information is handled in other function (the physics event handler), this may lead to some very confusing code.
Reading through the API documentation I found this OObox module, but I could not find how to create one, so I took the one frommy 1x1 object and tried to use the orxObject_BoxPick to pick the objects under the mouse. Still it always return the 1x1 object. Is there any easy way to find which object I clicked on?
Short version:
Is there any easy way to find which object I clicked on?
Thanks in advance.
Comments
It's called orxObject_Pick(Pos). The position you give it is in world space and orx will return the first object under that position (so the first object whose Z coordinate is >= Pos.Z).
To get the world coordinate from the screen space one (mouse position is in screen space), simply call orxRender_GetWorldPosition().
If it returns orxNULL, it means your mouse position is either-offscreen or isn't inside any viewport.
There's an example of this transformation in the tutorial #5: viewport & camera.
orxOBOX is a POD structure that you can initialize with a call to orxOBox_2DSet(), or simply sets its member yourself.
The GetWorldPosition I was already using, I saw in the API docs the other day, really useful.
About the OBOX, the API docs say that this function (as wall as all the ones of the module) is static, is the API wrong?
As for the OBox API, all the functions are static inline, yes, I'm not sure what you mean by the API being wrong.
Here's the function is in a header hence defined everywhere the header is included. orx.h includes all the public headers so this function will be defined basically everywhere.
Were the compiler to decide it doesn't want to inline the function, a local version (to the translation unit) will be stored.
If the function wasn't static and didn't get inlined, all the translation modules using it would have their own public copy, leading to a symbol conflict at link time. Here the static keyword ensures that this will never happen, if the code doesn't get inline, the local version will not be public and there won't be any symbol clash at link time.