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.....
search for opengl mouse picking
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*)
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?
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.
does anyone have a tutorial / code on mouse dragging / picking which is written in java and not C? thanks!
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)
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
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....
tutorials in java/lwjgl? anybody?
try joining #lwjgl on freenode - maybe some more people to help there.
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?
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