Author Topic: Problem with getAbsoluteCoordinates()  (Read 3393 times)

Offline fardke

  • byte
  • *
  • Posts: 10
    • View Profile
Problem with getAbsoluteCoordinates()
« on: May 26, 2008, 09:47:54 pm »
Hello,

I have a problem with the following getAbsoluteCoordinates() function (it wat posted on the forum) :

Code: [Select]
public SimpleVector getAbsoluteCoordinate(Camera camera, FrameBuffer buffer, int x, int y, Object3D object) {
SimpleVector rezult = null;
if (camera != null && buffer != null) {
    SimpleVector rayTemp = Interact2D.reproject2D3D(camera, buffer, x, y);
    rayTemp.normalize();

    Matrix orient = camera.getBack();
    float[] dump = orient.getDump();
    SimpleVector ray = new SimpleVector();
    ray.x = dump[0] * rayTemp.x + dump[1] * rayTemp.y + dump[2] * rayTemp.z + dump[3] * 1;
    ray.y = dump[4] * rayTemp.x + dump[5] * rayTemp.y + dump[6] * rayTemp.z + dump[7] * 1;
    ray.z = dump[8] * rayTemp.x + dump[9] * rayTemp.y + dump[10] * rayTemp.z + dump[11] * 1;
    float distance = object.rayIntersectsAABB(camera.getPosition(), ray, true);

    if (distance != Object3D.RAY_MISSES_BOX) {
    //rezult = new SimpleVector(camera.getPosition());
    ray.scalarMul(distance);
    rezult=new SimpleVector(ray);
    //rezult.add(ray);
    }
    else{
    rezult = new SimpleVector(SimpleVector.ORIGIN);
    }
    }
    return rezult;
} // getAbsoluteCoordinate()


I have a level with objects on it and i want to select an object to move it. So, when i click on the level, i call getAbsoluteCoordinates() with each objet in my list (the parameter object in the function) and if it returns something (something different than the origin vector), it means that an object has been found.

The problem is that it is not very accurate (sometimes i even have to click outside the object  :o). The more the camera is far and the more it is not accurate.

I absolutely don't know if it comes from my object that is not at the position i see it or if it comes from the coordinates returned by the function.


Help me please  ???

Thank you very much

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Problem with getAbsoluteCoordinates()
« Reply #1 on: May 27, 2008, 03:58:29 am »
I was using the Interact2D classes, and it seems that when you click on an object if it isn't large "enough" its not registered. I'm not sure why this is.

One thing is that you want to check your framebuffer. Check the documentation that says about 2x, 4x sampling modes

Jman

Offline fardke

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Problem with getAbsoluteCoordinates()
« Reply #2 on: May 27, 2008, 03:32:42 pm »
The 2x and 4x sampling mode are for the openGL renderer only. We are using the software renderer.

We made bigger objects and it was better but still not accurate. We want to keep small objects because we have a lot of objects in our level.

Help me  ???


Thanks,

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Problem with getAbsoluteCoordinates()
« Reply #3 on: May 27, 2008, 04:29:50 pm »
I guess it depends on a List of visual p̣ligons vislist or something. if it is too far then it is present on the list to be rendered or something like that. I guess that Only Egon can answer this accurately.
Nada por ahora

Offline fardke

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Problem with getAbsoluteCoordinates()
« Reply #4 on: May 27, 2008, 04:42:09 pm »
We have changed our code and we are now doing that to pick an object :

Code: [Select]
SimpleVector rayTemp = Interact2D.reproject2D3D(camera, buffer, e.getX(), e.getY());
int[] tableau = Interact2D.pickPolygon(theWorld.getVisibilityList(), rayTemp);

if(tableau!=null){
selected = theWorld.getObject(Interact2D.getObjectID(tableau));
selected.setTexture("red");
}

But the problem is the same. All the objects are visible and selectable (in the vislist list) but we still have to click a little bit outside the object to select it. it is still not accurate (the same unaccuracy than with getAbsoluteCoordinates()).


i guess we have to wait for egon  ???
« Last Edit: May 27, 2008, 05:31:27 pm by fardke »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Problem with getAbsoluteCoordinates()
« Reply #5 on: May 27, 2008, 06:24:11 pm »
Maybe your screen coordinates don't match the framebuffer coordinates? If you are, for example, rendering directly into a frame, the borders and the title bar will cover some parts of the buffer.

Offline fardke

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Problem with getAbsoluteCoordinates()
« Reply #6 on: May 27, 2008, 06:54:45 pm »
Wow thank you very much!
it works great when we removed the getInsets() and setSize() of the JFrame and also when we use it in fullscreen.

thanks again  :D