Main Menu

Interact2D

Started by AGP, January 16, 2018, 08:38:03 PM

Previous topic - Next topic

AGP

I'm trying to make a little level editor. Right now, all it will do is to allow you to position some enemies by clicking on the 3d map. I'm not very interested in the y coordinate, because they will place themselves relative to the floor's height). But the following code always places the enemiies in the same (marked) spot:
https://www.dropbox.com/s/r73iukqn0wdtcjs/LE.jpg?dl=0


     public void mouseClicked(MouseEvent e) {
Point p = e.getPoint();
SimpleVector p3d = Interact2D.reproject2D3DWS(camera, buffer, p.x, p.y);
System.out.println("p3d: "+p3d);
p3d.y = -2000f;
objects[numberOfObjects++] = Primitives.getCube(100f);
objects[numberOfObjects-1].build();
objects[numberOfObjects-1].translate(p3d);
theWorld.addObject(objects[numberOfObjects-1]);
     }

EgonOlsen

That method assumes the z coordinate to be 1. I don't think that's what you want here. Either set it to the proper value or use the resulting vector as a direction vector and calculate the intersection point with the ground plane in some other way.

AGP

I have x and y in screen coordinates, so about which z are you talking? And could you show me a snippet?

EgonOlsen

The z is the depth of your plane in 3d.

AGP

I don't need the height in wordspace. Only the x and the z.

EgonOlsen

But you need it to make the transition from 2d to 3d. You can't just make up the missing third component, you have to specify it. That's why there is this variant of the method that takes x,y in screen space and the depth in world space.

AGP

So how do I get the plane's z in cameraspace?

AGP

I went with the mouse-follow demo and ray-cast. It's working but, academically, I'd still like to know how to make use of the method which takes the camera z value.

EgonOlsen

#8
You have to transform 2d space into 3d. Each point in 2d corresponds to an unlimited number of points in 3d, so you have to assume some point in 3d as fixed. And because we are talking about casting a day in camera space, that point has to be in camera space.
There might not be many uses for this method signature, but I added it later, so there had to be at least one.