compiled objects

Started by trisco, November 29, 2009, 06:07:03 PM

Previous topic - Next topic

trisco

Hey, me again, still doing modifications on that project. Hit a snatch though, whenever I compile an object Interact2d code will give problems (I need to compile the objects to use shaders btw)

For example, following code will still work:

//naar 3d coordinaten
    SimpleVector position = new SimpleVector(Interact2D.reproject2D3D(
            camera, buffer, x, y));
   
    //naar world space coordinaten
    position.matMul(camera.getBack().invert3x3());
    position.add(camera.getPosition());
   
    SimpleVector direction = position.calcSub(camera.getPosition()).normalize();
    float distance = world.calcMinDistance(position, direction, 10000);
   
    SimpleVector collisionPoint = new SimpleVector(direction);
    collisionPoint.scalarMul(distance);
    collisionPoint.add(position);
   
    if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK)
    {
   
    if(distance != Object3D.COLLISION_NONE)
    {




It will report a collision, however, when I request the ID of the polygon that has been hit the result is null

position = new SimpleVector(Interact2D.reproject2D3D(
                camera, buffer, x, y));
        int[] is = Interact2D.pickPolygon(world.getVisibilityList(), position, Interact2D.EXCLUDE_NOT_SELECTABLE);
        int t = Interact2D.getObjectID(is);


Any idea what is going wrong?

trisco

nvm, just saw in the javadoc that picking doesn't work on compiled objects. Any idea how i can get the same functionality using some other functions?

EgonOlsen

Yes, you can use the calcMinDistance that you are calling anyway for this. calcMinDistance triggers a CollisionEvent if a CollisionListener is assigned to the object...so just implement a CollisionListener (don't forget to let your requiresPolygonIDs() -impl return true), add it to all objects and you can get object and polygon id from the event.


trisco

perfect thanks, I was somewhat afraid I would have to use the GLU, but this is much cleaner :)

Wojtek

Quote from: EgonOlsen on November 29, 2009, 08:36:06 PM
Yes, you can use the calcMinDistance that you are calling anyway for this. calcMinDistance triggers a CollisionEvent if a CollisionListener is assigned to the object...so just implement a CollisionListener (don't forget to let your requiresPolygonIDs() -impl return true), add it to all objects and you can get object and polygon id from the event.

Hello Egon,

Can you please put the example code how to use World.calcMinDistanceAndObject3D() method instead of Interact2D.pickPolygon() for mouse handler?

I have tried something like this, but it does not seem to work correctly (ie. returns wrong object)

SimpleVector ray = Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
Object[] result = getWorld().calcMinDistanceAndObject3D(camera.getPosition(), ray, HORIZON_RADIUS);
return (Object3D) result[1];


Thanks,
Wojtek

EgonOlsen

reproject2D3D gives you the result in camera space. You have to transform it into world space first. Like so:


ray.matMul(cam.getBack().invert3x3());


Edit: I'll change the docs to make this clearer.

Wojtek


pritom057

still it does not work perfectly

I did this
//SimpleVector position = new SimpleVector(Interact2D.reproject2D3DWS(world.getCamera(), fb, (int) x,(int) y));
SimpleVector position = new SimpleVector(Interact2D.reproject2D3D(world.getCamera(), fb, (int)x,(int)y, 10.f));
   
    position.matMul(world.getCamera().getBack().invert3x3());
    position.add(world.getCamera().getPosition());
   
    Object[] result = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), position, .01F);


but the problem is it always returns the object which is neat from camera

I have also used reproject2D3DWS(..) to same thing happened
any idea how can we do this??

EgonOlsen

Please don't cross post. One post in the Android section should be sufficient.

pritom057

Sorry sir :)
Next time it would be happened...
But Sir I am not able to find the transparent background yet...
I think In the World class there should be a function that make the background transparent...
There is a Example in APIDemo of Android for transparent background.
Plz Update it and Upload the  JPCT-AE....Just like u did for pick 3d object into 2d co-ordinate
Thanks in advance....

EgonOlsen

I can only repeat myself: There's no need for this. All you have to do, is to clear with alpha, which is possible already. Plus you have to ensure that actually something IS behind the rendered scene...in your case the camera picture. How you do that is up to you and outside of the scope of the engine.

pritom057

clear with alpha???But how???
Thats what I want to know....
do you mean this???

RGBColor transp = new RGBColor(67,123,245,0);
fb.clear(transp );
world.renderScene(fb);
world.draw(fb);
fb.display();


But I am not getting the proper result..

EgonOlsen

Not quite. That's WITHOUT alpha (i.e. =0). More like so: RGBColor transp = new RGBColor(67,123,245,255);

pritom057

Ya Got it man thank u :)
I am very much happy to use this API....
thanks a lot.....

EgonOlsen

Because this is a common topic and the forum contains some wrong code for picking, i decided to add a page to the wiki: http://www.jpct.net/wiki/index.php/Picking