Problem with getAbsoluteCoordinates()

Started by fardke, May 26, 2008, 09:47:54 PM

Previous topic - Next topic

fardke

Hello,

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


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

JavaMan

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

fardke

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,

Melssj5

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

fardke

#4
We have changed our code and we are now doing that to pick an object :


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  ???

EgonOlsen

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.

fardke

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