### Author Topic: Interact2D  (Read 602 times)

#### AGP

• Posts: 1615
##### Interact2D
« on: January 16, 2018, 08:38:03 pm »
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

Code: [Select]
`     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

• Posts: 11924
##### Re: Interact2D
« Reply #1 on: January 17, 2018, 08:03:48 am »
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

• Posts: 1615
##### Re: Interact2D
« Reply #2 on: January 17, 2018, 09:29:51 pm »
I have x and y in screen coordinates, so about which z are you talking? And could you show me a snippet?

#### EgonOlsen

• Posts: 11924
##### Re: Interact2D
« Reply #3 on: January 18, 2018, 11:01:41 am »
The z is the depth of your plane in 3d.

#### AGP

• Posts: 1615
##### Re: Interact2D
« Reply #4 on: January 18, 2018, 09:47:20 pm »
I don't need the height in wordspace. Only the x and the z.

#### EgonOlsen

• Posts: 11924
##### Re: Interact2D
« Reply #5 on: January 19, 2018, 08:35:06 am »
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

• Posts: 1615
##### Re: Interact2D
« Reply #6 on: January 19, 2018, 06:52:08 pm »
So how do I get the plane's z in cameraspace?

#### AGP

• Posts: 1615
##### Re: Interact2D
« Reply #7 on: January 20, 2018, 06:26:31 am »
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.