Is there something like screentoworld worldtoscreen?

Are there somewhere hidden inside jme methods for

Vector3f screentoworld(Point);

Point worldtoscreen(Vector3f)?



Cause I hope so, I have no idea how to calculate that myself :confused:

yes indeed, I want to use this, to draw a prediction where to shoot to hit a enemy on the screen.



Stays the qeustion for the other way round:



cam.getWorldCoordinates(screenPosition, zPos)



is the funktion, but I have problems to understand waht the javadoc wants to tell me the zPos is needed for ?

Well, a location on the screen can only have one z-depth (that of the screen, zero) or one that you define by using the zPos variable :slight_smile:

Thinking about it again, its just that simple the other way 'round, was a bit of a quick post, sorry.



I suppose since the cameras view goes out like a pyramid from one spot, if you click on the screen and have a zPos of zero, no matter where you click you get the same spot in space. I think the zPos is kind of the "height" of that pyramid. So you get different spots in space when you have a zPos of -1 because your screen represents the base of a pyramid with height 1 in the 3d-space…

So i kinda imagine a sphere with zpos radius around the campos?  thats bad, cause i need to get a worldposition from a underlying object,

kinda like a aimpos that is the point where you are lookig at (but needs to work anywhere on the screen not just the middle(if nothing is there the maxium distance would be something like farfrustum that it gives back)):confused:



As a example imagine a static camera where objects in 3d are flying around that you want to shoot down, by clicking(shooting)  at them. The main problem here is to caculate where you clicked at.

Suppose you were writing your post while I was writing mine, but no sphere, but a pyramid / rectangle in space.

Maybe this is what you want?



camera.getScreenCoordinates(mySpatial.getLocalTranslation());

Pretty sure the zpos here relates to the far point (the "height" of the frustrum).



E.g.



Projecting a Ray from 2D Screen Coordinates



If it were as you described heh, we'd have a big problem in graphics. Good thing that we can take the inverse of a matrix :wink: (although we lose information as we go from 3D to 2D, which is why we need that zpos value, to get back to 3D).

Well stays still the problem how can I determine the Worldposition where my mouse is over, when I shoot.

Actually I have absolutly no idea how to do this :confused:

It cannot work. The one spot you hover the mouse over is a ray in the 3d-space you will always have to decide which point on the ray you mean. Take a look at the mousepicking examples. Its just that: create a ray from the camera position and the click position and see what it collides with.

Well seems like this is more complicated than I thought :confused:



At least I know that it si possible, in the Source-Engine there is a utility that gives you the position of whatever object is at a specified position on the screen. Seems like I have to download the whole Source-SDK if i want to implement this and look how they did it.

Empire Phoenix said:

Well seems like this is more complicated than I thought :/

At least I know that it si possible, in the Source-Engine there is a utility that gives you the position of whatever object is at a specified position on the screen. Seems like I have to download the whole Source-SDK if i want to implement this and look how they did it.


You sure? TestTrianglePick in jmetest.Intersections is exactly what you're looking for (gets a screen to world coordinate, then uses a ray to find triangles on that pick). The other test, TestPick doesn't actually use screen to world, but the camera location + direction for its ray casting (e.g. like its a FPS) though.

As I understand your problem, you want to be able to click on objects, and identify them right? Well the above test classes do just that, both on the spatial level, as well as the triangle level. Or was there something else?