Author Topic: compiled objects  (Read 8316 times)

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
compiled objects
« on: November 29, 2009, 06:07:03 pm »
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:

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

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: compiled objects
« Reply #1 on: November 29, 2009, 06:12:45 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #2 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.


Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: compiled objects
« Reply #3 on: November 29, 2009, 09:08:00 pm »
perfect thanks, I was somewhat afraid I would have to use the GLU, but this is much cleaner :)

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: compiled objects
« Reply #4 on: March 14, 2010, 12:07:01 am »
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)
Code: [Select]
SimpleVector ray = Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
Object[] result = getWorld().calcMinDistanceAndObject3D(camera.getPosition(), ray, HORIZON_RADIUS);
return (Object3D) result[1];

Thanks,
Wojtek

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #5 on: March 14, 2010, 09:20:30 pm »
reproject2D3D gives you the result in camera space. You have to transform it into world space first. Like so:

Code: [Select]
ray.matMul(cam.getBack().invert3x3());

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

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: compiled objects
« Reply #6 on: March 15, 2010, 07:11:09 pm »
Thanks!

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: compiled objects
« Reply #7 on: July 04, 2010, 04:17:26 pm »
still it does not work perfectly

I did this
Code: [Select]
//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??

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #8 on: July 04, 2010, 09:35:49 pm »
Please don't cross post. One post in the Android section should be sufficient.

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: compiled objects
« Reply #9 on: July 05, 2010, 06:42:32 am »
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....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #10 on: July 05, 2010, 07:34:05 am »
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.

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: compiled objects
« Reply #11 on: July 05, 2010, 08:21:03 am »
clear with alpha???But how???
Thats what I want to know....
do you mean this???
Code: [Select]

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #12 on: July 05, 2010, 09:01:23 am »
Not quite. That's WITHOUT alpha (i.e. =0). More like so:
Code: [Select]
RGBColor transp = new RGBColor(67,123,245,255);

Offline pritom057

  • byte
  • *
  • Posts: 27
    • View Profile
Re: compiled objects
« Reply #13 on: July 05, 2010, 09:06:01 am »
Ya Got it man thank u :)
I am very much happy to use this API....
thanks a lot.....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: compiled objects
« Reply #14 on: September 06, 2010, 09:57:53 pm »
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