Jump to content

So I'm currently doing a program for fun that may or may not turn into something much larger later on. 

The current premise is to be able to move around on the x-z plane and look around 3D. 

But my passive mouse function requires me to click every time I move the mouse to get it to register that there is movement. Shouldn't passive mouse functions auto-grab this data without a click?

I don't seem to have it when I don't have the glutWarpPointer function inside of it, so I'm assuming that is what the problem is at the moment, but I'm not sure. Any ideas?

 

I'm also having issues with the image being clipped. Any ideas on how to fix that? 

 

 

Sorry for not making the code collapsible, I don't know how to do that, but here's the current code.

 

#include <windows.h>#include <iostream>#include <math.h>#include <gl/GL.h>#include <gl/GLU.h>#include "glut.h"using namespace std;int winid = 0;float yVals[50][50]; //Not used at this time, will be used for testing.const float pi = 3.141592653;float pheta = 0; //Horizontal movement based on lookfloat phi = pi / 2;float speed = .25;float eyeX = 15;float eyeY = 0;float eyeZ = 15;float lookY = 0;void reEye(){  gluLookAt(eyeX, eyeY, eyeZ, eyeX + 50 * sin(phi), lookY, eyeZ + 50 * cos(phi), 0, 1, 0);}void myInit(){  glClearColor(0.0, 0.0, 0.0, 0.0);}void drawGrid(){   for (int x = -150; x <= 150; x++)  {    for (int y = -150; y <= 150; y++)    {      if ((x + y) % 2 == 0)        glColor3ub(255, 0, 0);      else        glColor3ub(0, 255, 0);      glBegin(GL_POLYGON);      {        glVertex3i(x, 0, y);        glVertex3i(x+1, 0, y);        glVertex3i(x+1, 0, y+1);        glVertex3i(x, 0, y+1);        glVertex3i(x, 0, y);      }      glEnd();    }  }}void drawFloor(){}void myDisplay(void){  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // z-buffering  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  //glutSetCursor(GLUT_CURSOR_NONE); //Hides cursor  reEye(); //Resets the eye location after movement of any kind has occured.  drawGrid(); //Draws the test grid  drawFloor(); //Draws the floor; does nothing right now.  glFlush(); //Refresh the screen}void myKeyboard(unsigned char key, int x, int y){  //     a: display/hide axis  //     f: display/hide grid  //     *: display all polygons  //     +: itterated through polygons  //       //     z/x: zoom  //     1/2: rotate horizontal  //     7/8: rotate verticle  //  //     .: reset  //     p: change perspectiveswitch (key){  case 'w':  eyeX += speed*cos(pheta);  eyeZ += speed*sin(pheta);  break;  case 'a':  eyeX += speed*cos(pheta + pi / 2);  eyeZ += speed*sin(pheta + pi / 2);  break;  case 's':  eyeX -= speed*cos(pheta);  eyeZ -= speed*sin(pheta);  break;case 'd':  eyeX -= speed*cos(pheta + pi / 2);  eyeZ -= speed*sin(pheta + pi / 2);  break;}  glutPostRedisplay();}void myMotion(int x, int y){  lookY += (y - 350) / 10; //Changes the y value of Y on lookat  phi += (x - 350) / 250; //Changes the phi for where to lookat  glutWarpPointer(350, 350); //Keeps mouse at middle after movement  glutPostRedisplay(); //Reloads the image}int main(){  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); //z-buffering  glutInitWindowSize(700, 700); //Window size  glutInitWindowPosition(100, 100); //Location on the screen  winid = glutCreateWindow("Alpha"); //Names window  glEnable(GL_DEPTH_TEST); //Allows 3D  myInit(); //Initializes the screen  glutDisplayFunc(myDisplay); //Display function  glutKeyboardFunc(myKeyboard); //Keyboard input  glutPassiveMotionFunc(myMotion); //Mouse movement  glutMainLoop(); //Keeps the display running  return 0;}

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to comment
https://linustechtips.com/topic/486335-opengl-passive-mouse-movement-bug/
Share on other sites

Link to post
Share on other sites

use the 

code tag

to make your code readable (it's the blue angle brackets in the editor toolpane thingy)

Pro Tip: don't use flash when taking pictures of your build; use a longer exposure instead. Prop up your camera with something (preferably a tripod) if necessary.

if you use retarded/autistic/etc to mean stupid please gtfo

Link to post
Share on other sites

use the 

code tag

to make your code readable (it's the blue angle brackets in the editor toolpane thingy)

There you go.

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to post
Share on other sites

No answers? Well crap D:

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×