?
Solved

Mouselook in OpenGL

Posted on 2005-05-04
9
Medium Priority
?
1,489 Views
Last Modified: 2013-12-06
I'm trying to get some sort of mouselook (like in most fps games), working in openGL, I'm  trying to do this through the gluLookAt() function, but so far haven’t come across any guides for it online, so I don't really know what functions are available.
Some information on available functions and some code would be really nice. I already have the 3d environment set up, if you need to know anything more about the situation, please ask.

Thanks alot.
0
Comment
Question by:DriftRS
  • 6
  • 3
9 Comments
 
LVL 3

Expert Comment

by:Barca
ID: 13933142
0
 

Author Comment

by:DriftRS
ID: 13933381
ok thanks for that, I can get started but there are still a few problems with that code, mainly that it uses start_mouse_drag() which I believe requires the mouse button to be held down, are there any functions which do the same thing but don't require the mouse to be held? Secondly, I'm not sure we can use this windows.h, I'd assume it's only for setting up the environment, but if not, can you tell me what it is for? And lastly we can't use object oriented code, (we have to use C, I should have said that before) although that shouldn't be a problem, I can probably modify it myself.

Thanks again, I've nearly got this sorted out :D
0
 
LVL 3

Expert Comment

by:Barca
ID: 13934929
mainly that it uses start_mouse_drag() which I believe requires the mouse button to be held down, are there any functions which do the same thing but don't require the mouse to be held?

you can use
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKey);

void specialKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT :
break;
case GLUT_KEY_RIGHT :
break;
}
}

void keyboard(unsigned char key,int x, int y){
switch(key){
case 'r':
break;
}


-------------
windows.h

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_windows..h_and_strict_type_checking.asp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
Barca earned 510 total points
ID: 13935216
take a look,

/* This program illustrates the use of the glut library for
interfacing with a Window System */

/* The program opens a window, clears it to black,
then draws a box at the location of the mouse each time the
left button is clicked. The right button exits the program

The program also reacts correctly when the window is
moved or resized by clearing the new window to black*/

#include <glut.h>

/* globals */

GLsizei wh = 500, ww = 500; /* initial window size */
GLfloat size = 6.0;   /* half side length of square */


void drawSquare(int x, int y)
{

        y=wh-y;
        glColor3ub( (char) rand()%256, (char) rand()%256, (char) rand()%256);
        glBegin(GL_POLYGON);
                glVertex2f(x+size, y+size);
               glVertex2f(x-size, y+size);
                glVertex2f(x-size, y-size);
             glVertex2f(x+size, y-size);
        glEnd();
        glFlush();
}


/* rehaping routine called whenever window is resized
or moved */

void myReshape(GLsizei w, GLsizei h)
{

/* adjust clipping box */

         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();

/* adjust viewport and clear */

      glViewport(0,0,w,h);
    glClearColor (0, 0, 0, 0.0);
         glClear(GL_COLOR_BUFFER_BIT);
         glFlush();

/* set global size for use by drawing routine */

      ww = w;
         wh = h;
}

void myinit(void)
{

         glViewport(0,0,ww,wh);

/* Pick 2D clipping window to match size of screen window
This choice avoids having to scale object coordinates
each time window is resized */

         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         glOrtho(0.0, (GLdouble) ww , 0.0, (GLdouble) wh , -1.0, 1.0);

 /* set clear color to black and clear window */

         glClearColor (0.0, 0.0, 0.0, 1.0);
      glClear(GL_COLOR_BUFFER_BIT);
      glFlush();

}

 void mouse(int btn, int state, int x, int y)
 {
    if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
            exit(0);
      if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
            drawSquare(x,y);

 }


/* display callback required by GLUT 3.0 */

void display(void)
{
      glClear(GL_COLOR_BUFFER_BIT);
      glFlush();
}

int main(int argc, char** argv)
{

         glutInit(&argc,argv);
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
      glutInitWindowSize(500,500);
      glutCreateWindow("square");
         myinit ();
         glutReshapeFunc (myReshape);
         glutMouseFunc (mouse);
         glutPassiveMotionFunc(drawSquare);
      glutDisplayFunc(display);

         glutMainLoop();

}
0
 
LVL 3

Expert Comment

by:Barca
ID: 13935294
finally
you can use object oriented code
0
 
LVL 3

Expert Comment

by:Barca
ID: 13935436
i mean you can write your program in object oriented way
0
 

Author Comment

by:DriftRS
ID: 13944483
Ok thanks again guys, I'll look through the responses and see if I can get any to work. The trouble though is that these examples still require the button to be clicked, though I havn't yet taken a good look at them, so maybe they can be modified. If anyone has any example code which allows you to move the mouse and simply responds how it was moved, that would be perfect, someone before mentioned a function "passive" something or other which works with the mouse and returns how much it's moved in what direction or something which could be useful is someone knows how to use it for this purpose. (I forget the functions full name and how it works)

Thanks again, and keep in mind I can't use C++, thus no object oriented code :(
0
 
LVL 3

Expert Comment

by:Barca
ID: 13945327
glutPassiveMotionFunc();

there is a sample in my third reply
0
 

Author Comment

by:DriftRS
ID: 13995034
lol well, I still don't have a proper example of mouselook, and I doubt I'll get one, so I've decided to make somthing else. So I'll just accept your answere then. You did help me to work out how the mouse functions work anyway, so thanks for that.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question