Hello Guest

mouse input, noob question

  • 12 Replies
  • 13718 Views
mouse input, noob question
« on: May 22, 2007, 02:44:27 »
hi! i was wondering... i wanna drag an object on the screen... how can i code that?

on mouse down .. how do i get position of the mouse? for example.. if i were to open a drawer.....

*

Offline Matzon

  • *****
  • 2242
Re: mouse input, noob question
« Reply #1 on: May 22, 2007, 05:04:57 »
search for opengl mouse picking

Re: mouse input, noob question
« Reply #2 on: May 30, 2007, 22:49:28 »
i tried it and even used nehe.gamedev.net Lesson32 as a tutorial... but it won't work...

on Lesson32 i used the selection() function and instead of drawTargets i changed it to renderMovables() which renders a drawer... i loaded a name to it also.  but i just realized that it won't draw unless i clicked the mouse.. so i clicked the mouse and nothing happened....

i kind of  understand mouse picking in openGL but i dont know how to implement it on lwjgl.... i've been trying to work on it for a week and nothing's happened.. i need this done asap (or else i won't graduate *sob*)

*

Offline Matzon

  • *****
  • 2242
Re: mouse input, noob question
« Reply #3 on: May 31, 2007, 05:03:13 »
odd, http://lwjgl.org/forum/index.php/topic,700.0.html says that lesson32 works ...
Since it seems to be a general issue - does ANYONE have a picking example or tutorial - to put on the wiki?

*

Offline bobjob

  • ****
  • 394
  • LWJGL: WOW SO GOOD
Re: mouse input, noob question
« Reply #4 on: May 31, 2007, 08:53:03 »
here is a basic mouse menu example
http://users.on.net/~bobjob/mouseMenu.zip

I modified it to drag the two buttons in the middle.
« Last Edit: May 31, 2007, 11:21:43 by bobjob »

Re: mouse input, noob question
« Reply #5 on: June 01, 2007, 01:09:40 »
does anyone have a tutorial / code on mouse dragging / picking which is written in java and not C? thanks!

Re: mouse input, noob question
« Reply #6 on: June 01, 2007, 18:47:18 »
i tried to see if any hits were processed...

GL11.glRenderMode(GL11.GL_SELECT);

      GL11.glInitNames();                                              // Initializes The Name Stack
      GL11.glPushName(0);                                              // Push 0 (At Least One Entry) Onto The Stack

      GL11.glMatrixMode(GL11.GL_PROJECTION);                                // Selects The Projection Matrix
      GL11.glPushMatrix();                                             // Push The Projection Matrix
      GL11.glLoadIdentity();                                           // Resets The Matrix

      // This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is.
      GLU.gluPickMatrix((float) mouse_x, (float) (viewport[3] - mouse_y), 1.0f, 1.0f, viewport);

      // Apply The Perspective Matrix
      GLU.gluPerspective(45.0f, (float) (viewport[2] - viewport[0]) / (float) (viewport[3] - viewport[1]), 0.1f, 100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);                                 // Select The Modelview Matrix
      renderMovables();                                              // Render The Targets To The Selection Buffer
      GL11.glMatrixMode(GL11.GL_PROJECTION);                                // Select The Projection Matrix
      GL11.glPopMatrix();                                              // Pop The Projection Matrix
      GL11.glMatrixMode(GL11.GL_MODELVIEW);                                 // Select The Modelview Matrix
      hits = GL11.glRenderMode(GL11.GL_RENDER);                               // Switch To Render Mode, Find Out How Many
     
      if(hits > 0)
         System.out.println("there are some hits");
      else
         System.out.println("no hits");



and in renderMovables()
    {  GL11.glLoadIdentity();

        // adjust camera position according to arrow key events
        setCameraPosition();

        // shift and rotate entire scene (opposite to  "camera" position)
        GL11.glRotatef(lookupdown, 1f, 0, 0);
        GL11.glRotatef((360.0f-cameraRotation), 0, 1f, 0);   // first rotate around y axis

        GL11.glTranslatef( -cameraPos[0], -cameraPos[1], -cameraPos[2]); 
      GL11.glLoadName(DRAWER);
     renderDrawer();
}


i tried it and it said "no hits" :(

if anybody could help that'd be awesome. (one more week before graduation)

*

Offline Matzon

  • *****
  • 2242
Re: mouse input, noob question
« Reply #7 on: June 01, 2007, 20:36:35 »
from IRC:
Quote
  • he's could look for mouse pressed down event, and fix the component to the mouse position until a mouse button released event is released
  • he is also not creating the selection buffer with glSelectBuffer - so no object can be recorded

Re: mouse input, noob question
« Reply #8 on: June 01, 2007, 20:50:13 »
i'm sorry i forgot to add this piece of code at the top

      int viewport[] = new int[4];

      IntBuffer temp = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asIntBuffer();
      temp.order();
      GL11.glGetInteger(GL11.GL_VIEWPORT, temp);
      temp.get(viewport);
      temp = ByteBuffer.allocateDirect(2048).asIntBuffer();
      GL11.glSelectBuffer(temp);                                // Tell OpenGL To Use Our Array For Selection
      temp.get(buffer);



also.. i get hits now.. except it's not at the place where i want it to be....

Re: mouse input, noob question
« Reply #9 on: June 04, 2007, 01:11:49 »
tutorials in java/lwjgl? anybody?

*

Offline Matzon

  • *****
  • 2242
Re: mouse input, noob question
« Reply #10 on: June 04, 2007, 05:58:11 »
try joining #lwjgl on freenode - maybe some more people to help there.

Re: mouse input, noob question
« Reply #11 on: June 05, 2007, 02:02:54 »
try joining #lwjgl on freenode - maybe some more people to help there.

uhm.. how do i do that?

*

Offline bobjob

  • ****
  • 394
  • LWJGL: WOW SO GOOD
Re: mouse input, noob question
« Reply #12 on: June 05, 2007, 03:25:57 »
do you know how IRC channels work?

if not download mIRC  (type mIRC in google)

once you have done that, connect for the freenode server
you may have to add the server, file - select server - add
{
 Description: FreeNode
 IRC: irc.freenode.net
}
then connect to the server

then connect to the #lwjgl channel
« Last Edit: June 05, 2007, 03:32:30 by bobjob »