Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9307697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:27:00+00:00 2026-06-19T00:27:00+00:00

I wrote a mouse function for the camera. It works good. But the only

  • 0

I wrote a mouse function for the camera.
It works good. But the only problem is at the start, when I do first move with mouse it jumps up-left and then it works good. I don’t understand why it happens.

Here the mouse function.

float lastx = 0.0;
float lasty = 0.0;

void mouseMovement(int x, int y) 
{
    lastx = (float)x - lastx;
    lasty = (float)y - lasty;

    if((float)x > lastx)
        Camera.RotateY((-lastx)*0.01);
    else
        Camera.RotateY(lastx*0.01);
    if((float)y > lasty)
        Camera.RotateX(lasty*0.01);
    else 
        Camera.RotateX(-lasty*0.01); 
    lastx = (float)x;
    lasty = (float)y;
    Display();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T00:27:01+00:00Added an answer on June 19, 2026 at 12:27 am

    I’m guessing, If you’re tracking all mouse movement you’ll need to either catch when the mouse enters or leaves the window, or simply discard any jumps larger than a certain amount.

    Let’s say that the mouse leaves the right edge of the window, and reenters the left edge of the window. The code you’ve shown is going to jump.

    Unless there’s a reason not to, I’d make the last variables static and add an if statement similar to this(not tested 🙂 )…

    void mouseMovement(int x, int y) 
    {
        static float lastx = 0.0;
        static float lasty = 0.0;
    
        lastx = (float)x - lastx;
        lasty = (float)y - lasty;
    
        if((abs((int)lastx)>10)||(abs((int)lasty)>10)
        {
            lastx = (float)x;
            lasty = (float)y;
            return;
        }
    
       //the rest remains the same
    

    The logic goes…
    Any event it sees, that isn’t near the last event it saw, just resets the variables and waits for another event.

    That really isn’t an elegant solution for a mouse control, but at this point in your coding it is probably understandable, and will do what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To do this I wrote a script that works fine but only for slow
I wrote a C# program that uses the mouse and it works perfectly. I
I wrote a AS3 class to make a Counter function. Click and hold mouse
I am using Hover indent plugin, This have only one function to combine mouse
I wrote a simple XML file and a DTD file including an entity, but
I wrote a function in jQuery that rotates a series of text blocks like
I am building a small app which captures mouse clicks. I wrote the prototype
I wrote a script which changes the source of an image upon mouse over
Hello So I started to write some function witch will do this(closer you move
I started learning Perl with the basics, then discovered and learned Moose, wrote an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.