Author Topic: MouseMapper  (Read 4489 times)

Offline drounal

  • byte
  • *
  • Posts: 16
    • View Profile
MouseMapper
« on: May 27, 2006, 12:25:35 am »
Hey,
I'd like to make (and in fact I truly need for tomorrow) a MouseMapper. Here is my situation: I used the "car" example and tuned it by myself in order to create several cars instead of one (for example) or say that a given is "selected". Now I need a set of methods to be able to click somewhere in the windows and say "the car beneath my mouse is selected".

I ran through several posts that dealt with MouseMappers and got some code but I can't make it work with my own code. Help !!

L.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
MouseMapper
« Reply #1 on: May 27, 2006, 11:13:35 am »
For the MouseMapper, there is in the Paradroidz sources that you can have a look at (http://www.jpct.net/download/paradroidz_src.zip). The given mouse coords may then be used to pick the object in question by using the picking methods in Interact2D like so:

Code: [Select]

int[] res=Interact2D.pickPolygon(world.getVisibilityList(),                                               Interact2D.reproject2D3D(world.getCamera(), buffer, x, y));
if (res!=null) {
    obj=world.getObject(Interact2D.getObjectID(res));
}


The objects have to be made selectable to make this work, of course.

Offline drounal

  • byte
  • *
  • Posts: 16
    • View Profile
unfortunately ...
« Reply #2 on: May 27, 2006, 12:02:02 pm »
unfortunately, that's what I had been doing before ...

For the moment, I started over and :
-> copied MouseMapper in my src directory (using NetBeans)
-> removed "import naroth.config.*;"
-> tried to compile
-> got "cannot find Configuration"
-> imported Configuration.java
-> removed "package naroth.config;"
-> added a function in my CarTest.java file :

    public Object3D pickingObject(int mouseX, int mouseY, Camera camera, FrameBuffer buffer, World theWorld){
   SimpleVector ray=Interact2D.reproject2D3D(camera, buffer, mouseX, mouseY);
    int[] res=Interact2D.pickPolygon(theWorld.getVisibilityList(), ray);
   if (res!=null) {
       return theWorld.getObject(Interact2D.getObjectID(res));          
   }
    return null;
    }

now it compiles, but doesn't do anything at all ... what shall I do ?

Offline drounal

  • byte
  • *
  • Posts: 16
    • View Profile
added some stuff ...
« Reply #3 on: May 27, 2006, 12:20:48 pm »
I also added a few things :
-> a method to move a selected cube:
public void moveClick(Cube pointe) {
                 
      if (cubeleft) {
          pointe.turnLeft();
      }
      if (cuberight) {
         pointe.turnRight();
      }

     Matrix backUpTrans=pointe.getTranslationMatrix().cloneMatrix();


      if (cubeforward) {
         if (speed<15) {speed+=0.1f;}
         pointe.setSpeed(speed);
         pointe.moveForward();
      }
      if (cubeback) {
         if (speed>0) {speed-=0.3f;}
         if (speed<0) {speed=0;
         }
         pointe.setSpeed(speed);
         pointe.moveForward();
      }

      if (speed>=0 && !cubeback && !cubeforward) {
         speed-=0.075f;
         if (speed<0) {speed=0;}
         pointe.setSpeed(speed);
         pointe.moveForward();
      }

      boolean ok=pointe.place(terrain);
      if (!ok) {
         pointe.setTranslationMatrix(backUpTrans);
         speed=0;
         pointe.setSpeed(speed);
      } else {}  
   }

->its call in the gameLoop function:
                moveClick(MouseMapper.click);

-> something that is supposed to affect the cube beneath the mouse in a variable when clicking:
click=(Cube) pickingObject(getMouseX(), getMouseY(), CarTest.camera, CarTest.buffer, CarTest.theWorld);

does this seem correct to u ?
I get  Exception in thread "main" java.lang.NullPointerException when compiling concerning

     Matrix backUpTrans=pointe.getTranslationMatrix().cloneMatrix();

in the mouseClick function.


.... I feel a bit lost !

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
MouseMapper
« Reply #4 on: May 28, 2006, 03:52:47 pm »
If you're still having the problem, you may consider sending me your code (or a stripped test case) so i can see for myself. From the snippets you are posting (btw: please use the [ code ]-tag to format your sources when posting), it's hard to tell where the problem is.