Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualAstado89

Posted 25 March 2013 - 08:38 AM

Hi Danicco,

 

thanks a lot for your reply.

 

Trying to keep the mouse in the center of the screen seemed to be the best solution to me. But the camera wont move fluently anymore because the function glutwarppointer is called every time the mouse is moved.

 

But I got another idea after 3 months of thinking smile.png

 

Now the mouse jumps back to the center of the screen every time it reaches the edges.

 

My solution is as follows:

 

I got a class that controls the OpenGL device functions.

The class is called inside the glut function and given the parameters.

Heres the function prototype.

-(void)mousepassivenotion:(int)_x y:(int)_y;

 

 

Inside the class I save the old point of the mouse within 2 int variables.

When I move the mouse the old and new values are given to my camera class.

-(void)movetomousemotionx:(int)_x y:(int)_y xold:(int)_xold yold:(int)_yold {
    if (_xold-_x < 500) {
        NSLog(@"%d %d : %d %d",_x, _x, _xold, _yold);
        if (_xold > _x) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        }
        else if (_x > _xold) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        }
        if (_yold > _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];
        }
        else if (_yold < _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];
        }
    }
} 

 

 

In the first line i check if the difference between old and new is bigger than 500 in the horizontal(x) axis.

I may add the y-axis too. This is because after glutwarppointer the function glutpassivemotion is called and the difference is bigger than 500 and is ignored. Then I call my surroungviewpoint function with the rotation radius.

Heres my surroundviewpoint function.

-(void)surroundviewpoint:(NSNumber *)_rotation {
    glPushMatrix();
    glLoadMatrixd(Systemmatrix);
    glTranslated(0, 0, -distance);
    glRotated(-topdown, 1, 0, 0);
    glRotated(_rotation.floatValue, 0, 1, 0);
    glRotated(topdown, 1, 0, 0);
    glTranslated(0, 0, distance);
    glGetDoublev(GL_MODELVIEW_MATRIX, Systemmatrix);
    glPopMatrix();
}

 

 

So now the mouse is pointing at the center of the screen.

There is only one more point. When you turn the camera around and reach the edge you can notice for a second that the mouse is not moving.

So I tried calling my camera function manually after calling glutwarppointer and parameterize as the new point the center and as the old point the center minus the original difference.

int dif[2];
dif[0] = _x-x; //x is the old value
dif[1] = _y-y; //y is the old value
x = windowwidth/2-dif[0];
y = windowheight/2-dif[1];

glutWarpPointer(windowwidth, windowheight);

[camera movetomousemotionx:x+dif[0] y:y+dif[1] xold:x yold:y];

But still you can notice it.

 

Sorry for that much code but I wanted others to be able to solve the problem reading the post. smile.png


#1Astado89

Posted 24 March 2013 - 12:52 AM

Hi Danicco,

 

thanks a lot for your reply.

 

Trying to keep the mouse in the center of the screen seemed to be the best solution to me. But the camera wont move frequently anymore because the function glutwarppointer is called every time the mouse is moved.

 

But I got another idea after 3 months of thinking :)

 

Now the mouse jumps back to the center of the screen every time it reaches the edges.

 

My solution is as follows:

 

I got a class that controls the OpenGL device functions.

The class is called inside the glut function and given the parameters.

Heres the function prototype.

-(void)mousepassivenotion:(int)_x y:(int)_y;

 

 

Inside the class I save the old point of the mouse within 2 int variables.

When I move the mouse the old and new values are given to my camera class.

-(void)movetomousemotionx:(int)_x y:(int)_y xold:(int)_xold yold:(int)_yold {
    if (_xold-_x < 500) {
        NSLog(@"%d %d : %d %d",_x, _x, _xold, _yold);
        if (_xold > _x) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        }
        else if (_x > _xold) {
            [self performSelectorOnMainThread:@selector(surroundviewpoint:) withObject:[NSNumber numberWithInt:(_xold-_x)
            /mousesensivity] waitUntilDone:YES];
        }
        if (_yold > _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];
        }
        else if (_yold < _y) {
            [self performSelectorOnMainThread:@selector(overviewviewpoint:) withObject:[NSNumber numberWithInt:(_y-_yold)
            /mousesensivity] waitUntilDone:YES];
        }
    }
} 

 

 

In the first line i check if the difference between old and new is bigger than 500 in the horizontal(x) axis.

I may add the y-axis too. This is because after glutwarppointer the function glutpassivemotion is called and the difference is bigger than 500 and is ignored. Then I call my surroungviewpoint function with the rotation radius.

Heres my surroundviewpoint function.

-(void)surroundviewpoint:(NSNumber *)_rotation {
    glPushMatrix();
    glLoadMatrixd(Systemmatrix);
    glTranslated(0, 0, -distance);
    glRotated(-topdown, 1, 0, 0);
    glRotated(_rotation.floatValue, 0, 1, 0);
    glRotated(topdown, 1, 0, 0);
    glTranslated(0, 0, distance);
    glGetDoublev(GL_MODELVIEW_MATRIX, Systemmatrix);
    glPopMatrix();
}

 

 

So now the mouse is pointing at the center of the screen.

There is only one more point. When you turn the camera around and reach the edge you can recognize for a second that the mouse is not moving.

So I tried calling my camera function manually after calling glutwarppointer and parameterize as the new point the center and as the old point the center minus the original difference.

int dif[2];
dif[0] = _x-x; //x is the old value
dif[1] = _y-y; //y is the old value
x = windowwidth/2-dif[0];
y = windowheight/2-dif[1];

glutWarpPointer(windowwidth, windowheight);

[camera movetomousemotionx:x+dif[0] y:y+dif[1] xold:x yold:y];

 

But still you can recognize it.

 

Sorry for that much code but I wanted others to be able to solve the problem reading the post. :)


PARTNERS