LWJGL Forum

Programming => OpenGL => Topic started by: bisquit on May 22, 2007, 02:44:27

Title: mouse input, noob question
Post by: bisquit 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.....
Title: Re: mouse input, noob question
Post by: Matzon on May 22, 2007, 05:04:57
search for opengl mouse picking
Title: Re: mouse input, noob question
Post by: bisquit 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*)
Title: Re: mouse input, noob question
Post by: Matzon 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?
Title: Re: mouse input, noob question
Post by: bobjob on May 31, 2007, 08:53:03
here is a basic mouse menu example
http://users.on.net/~bobjob/mouseMenu.zip (http://users.on.net/~bobjob/mouseMenu.zip)

I modified it to drag the two buttons in the middle.
Title: Re: mouse input, noob question
Post by: palody 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!
Title: Re: mouse input, noob question
Post by: bisquit 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)
Title: Re: mouse input, noob question
Post by: Matzon 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
Title: Re: mouse input, noob question
Post by: bisquit 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....
Title: Re: mouse input, noob question
Post by: palody on June 04, 2007, 01:11:49
tutorials in java/lwjgl? anybody?
Title: Re: mouse input, noob question
Post by: Matzon on June 04, 2007, 05:58:11
try joining #lwjgl on freenode - maybe some more people to help there.
Title: Re: mouse input, noob question
Post by: palody on June 05, 2007, 02:02:54
Quote from: Matzon on June 04, 2007, 05:58:11
try joining #lwjgl on freenode - maybe some more people to help there.

uhm.. how do i do that?
Title: Re: mouse input, noob question
Post by: bobjob 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