• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Astado89

OpenGL mouse handling

3 posts in this topic

Hi together,

 

sorry if I made the topic wrong, but I'm new to this forum.

 

I'm currently writing on a little game which is supposed to be a third person game.

So I created a camera to rotate around the character.

So good so far. My issue is that the mouse reaches the corners of my display and the camera stops rotating.

 

I tried working with glutwarppointer to warp my pointer back to the center of the screen.

But it triggers my camera to rotate back, because the glutpassivemousefunc is called.

 

I tried using a BOOL to keed the camera moving just when its false and tried

 

mouselock = true;

glutwarppointer(windowwidth/2, window height/2);

mouselock = false;

 

but it still triggers the camera.

 does anyone got any ideas?

 

Just so you know I'm working with Mac OS X Mountainlion and Xcode.

 

Any help is very much appreceated.

Edited by Astado89
0

Share this post


Link to post
Share on other sites

Have you tried using the MacOS' function to set the mouse position?

 

Then you can check if you reached the screen.width, if it did, keep increasing the rotation, but moving the mouse back to the edge (thus locking it on screen). Or like 3ds max, you could set it to the other side of the window as if it did a 360...

 

Not sure if this is updated, but here's the idea: http://hints.macworld.com/article.php?story=2008051406323031

Edited by Danicco
0

Share this post


Link to post
Share on other sites

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

Edited by Astado89
0

Share this post


Link to post
Share on other sites

Ok now I got it fixed!

 

after glutwarppointer is called the mouse is suppressed for a short amount of time.

This also occurred using the CGWarpMouseCursorPosition function.

 

So these are not to be used in a game.

 

Instead use

CGEventRef event = CGEventCreateMouseEvent(Nil, kCGEventMouseMoved, CGPointMake(windowwidth/2, windowheight/2), 
                   kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, event);

 

This moves the mouse to the middle without creating any interference.

Edited by Astado89
0

Share this post


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
Sign in to follow this  
Followers 0