3d->2d Conversion? Mass selection RTS style in general

is there a way to get 3d->2d conversion? (hopefully with the exception of ray casting from/to EVERY SELECTABLE OBJECT to the camera) as I have implemented drag selection with a 2d game before



the progress with ray casting- get every objects and cast a ray between the camera and each selectable objects, and I got up to the ray casting itself and the frustum but then STUCK at converting the points… :frowning:

What do you mean exactly with 3d->2d conversion? (I take it looking down on the playing field doen’t cut it for you)

Wait, are you sure you don’t mean 2D → 3D? As in you have a 2D RTS game right now that you would like to convert to 3D in jME3?



I just think it’s a little strange to ask about a 3D to 2D conversion in a practically 3D exclusive development hub. If you are indeed looking for a 3D->2D conversion, you might be better off asking your question in a 2D game engine community.

No. no no. I meant for selection purposes: converting 3d to 2d coordinates for drag selection

You might want to look here for the jME1 discussion of the topic

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/mouse-drag-picking-mass-selection-how-to-implement

It can only be a ray, think about it, there is absolutely no way that the z coordinate could be determined without casting a ray to check for collisions except its static or its known before (e.g. top-down view on a heightmap).

normen said:
It can only be a ray, think about it, there is absolutely no way that the z coordinate could be determined without casting a ray to check for collisions except its static or its known before (e.g. top-down view on a heightmap).

Actually, i devised a trick when I was building an isometric '3D' map in Slick2D. It involved remembering the last '3d' object you draw under your mouse pointer (which would be on top). I guess doing that here would mean hacking the renderer or building a shader or something.

If you want to box-select you can 'draw' a selection cube through the Terrain plane and take the Y coordinate of the terrain. Should work if you have a single layer terrain.

One of my thought was to create a polygon using the rays (from each corners of the rectangle) that intersects with the terrain, but then in a hilly terrain that method would leave uncovered spots…

That’s sorta what I was thinking when I first read this topic.



first click and hold → get ray contact point on terrain

drag and release button → get another ray contact point on the terrain at the release point



average the two values heights, in otherwords if one point was at height 2 and the other at height 4, then the middle is 3.



These two coordinates are now on the same plane, so if you create a box/cube, it will be aligned up and down on the Y axis at least.



Then make the box/cube from those two points, with some arbitrary height in both directions y, so it spans vertically (eliminating missed units you may have wanted)… That’s the part I’m ??? about… Could just make it a huge value if it’s an RTS on a single plane (no orbital crap. I remember some wacky RTS game from the late 90’s that had 3 planes of combat - underground, ground, and air… Only reason I bring this up ;p)



Now intersect this magic box with your selectables and the result should = win?



Like you said, it’s going to leave uncovered spots if it’s just a flat polygon… HOWEVER, you may want to think about using a polygon as a display while the player drags the mouse around as the magic box/cube selection will likely look weird as hell to a casual gamer (or really freakin’ cool, I dunno, I’m not hip ;p).



Hope something in there might be useful…

~FlaH

I read some info about the 3d projection from several sites in Google, but then the new problem is how to use the camera: I got the idea that the screen is something like the near frustum of the camera, but then how can one get the distance between the actual camera and the near frustum?

Um… how about using a box and do an in-bounds check against a particular scene graph node.



Thus, the 3d to 2d conversion has taken place… amen.

I do an rts-like game. I sotre my units position in a Vector2f, using a getHeightAt(Vector2f) function to get their y component for translation and speed calculations.

For selection, get ray intersection with your map at the 2 corners of your selection area. Construct rectangle out of it. The 3d coord → 2d coord you mentioned is then reduced to discarding the y component of the intersection points…

Check if any unit are inside. I’d recommend using some kind of spatial index to store your units positions.

There are plenty of posts talking about that matter on the forum.