Author Topic: shortest distance  (Read 4379 times)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
shortest distance
« on: November 14, 2008, 11:10:48 pm »
On one of the threads there was mentioned a shortest distance function, however, I can't seem to find it in the docs.  I did a search, but it's not working or I'm not remembering correctly.
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: shortest distance
« Reply #1 on: November 14, 2008, 11:21:23 pm »
Shortest distance between what?

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: shortest distance
« Reply #2 on: November 15, 2008, 12:40:22 am »
From a point to a point, I think.  We were talking about mouse picking and polygons and how to get the exact position by using shortest distance.  Now that i think about it, though, I guess I wouldn't know the point.  I would only know the polygon and be able to find the position of the vertices.  Anyway, it was your idea so i was hoping you could explain it again.

Also, what about reproject2d3d?  Would that work to find the point of contact?
« Last Edit: November 15, 2008, 01:05:08 am by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: shortest distance
« Reply #3 on: November 15, 2008, 02:30:11 am »
I am using the following code to interact with Object3Ds via the mouse.  Maybe this is what you need.  Requires the Object3D you want to be able to click on to use setCollisionMode( Object3D.COLLISION_CHECK_OTHERS )

Code: [Select]
    public void mousePressed( MouseEvent e )
    {
        // Get the mouse's coordinates on the applet window:
        int x = e.getX();
        int y = e.getY();
       
        // Get the 3D coordinates in Camera space:
        SimpleVector position = new SimpleVector( Interact2D.reproject2D3D(
                                                       camera, buffer, x, y ) );
        // Convert the coordinates to World space:
        position.matMul( camera.getBack().invert3x3() );
        position.add( camera.getPosition() );
       
        // Determine the direction from the camera position to the click point:
        SimpleVector direction = position.calcSub( camera.getPosition() ).normalize();
       
        // Calculate the distance to whatever was clicked on:
        float distance = world.calcMinDistance( position, direction, 10000 );
       
        // Check if we clicked on something:
        if( distance != Object3D.COLLISION_NONE )
        {
            // Calculate the exact 3D coordinates for the point that was clicked:
            SimpleVector collisionPoint = new SimpleVector( direction );
            collisionPoint.scalarMul( distance );
            collisionPoint.add( position );

            // TODO: do something.  collisionPoint is the exact 3D coordinate.
        }
    }


Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: shortest distance
« Reply #4 on: November 15, 2008, 03:07:27 am »
Hey thanks.  I'll play around with it.  It's a good starting point anyway since I have no idea what I'm doing right now.
click here->Fireside 7 Games<-