Author Topic: Interact2D  (Read 370 times)

Offline AGP

  • quad
  • ******
  • Posts: 1575
    • View Profile
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]);
     }

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11853
    • View Profile
    • http://www.jpct.net
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.

Offline AGP

  • quad
  • ******
  • Posts: 1575
    • View Profile
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?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11853
    • View Profile
    • http://www.jpct.net
Re: Interact2D
« Reply #3 on: January 18, 2018, 11:01:41 am »
The z is the depth of your plane in 3d.

Offline AGP

  • quad
  • ******
  • Posts: 1575
    • View Profile
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.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11853
    • View Profile
    • http://www.jpct.net
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.

Offline AGP

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

Offline AGP

  • quad
  • ******
  • Posts: 1575
    • View Profile
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.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11853
    • View Profile
    • http://www.jpct.net
Re: Interact2D
« Reply #8 on: January 20, 2018, 11:35:00 am »
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.
« Last Edit: January 20, 2018, 11:37:55 am by EgonOlsen »