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 7597553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:11:04+00:00 2026-05-30T22:11:04+00:00

I keep looking up on the internet how to move from point A to

  • 0

I keep looking up on the internet how to move from point A to point B on an angle with a specified distance. When I tried to code it, however, the camera just gets messed up and I’m moving in random directions. I am using SDL/OpenGL with c++ and this is my player function. Right now, I’m trying to get the player to move forwards along the angle.

void player_action()
{

    if (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
            case SDL_MOUSEMOTION:
                {
                    player.rotxl = (screen->w)/2;
                    player.rotxd = event.motion.x - player.rotxl;
                    player.rotx = player.rotx + (player.rotxd/4);
                    if (player.rotx < 0)
                    {
                        player.rotx = player.rotx + 360;
                    };
                    if (player.rotx > 360)
                    {
                        player.rotx = player.rotx - 360;
                    }
                };
            break;

            case SDL_KEYDOWN:
                switch (event.key.keysym.sym)
                {
                    case SDLK_w:
                        {player.zvel = 8.0f;}; break;
                    case SDLK_a:
                        {player.xvel = 8.0f;}; break;
                    case SDLK_s:
                        {player.zvel = -8.0f;}; break;
                    case SDLK_d:
                        {player.xvel = -8.0f;}; break;
                    case SDLK_ESCAPE:
                        {running = false;}; break;
                    default: break;

                }; break;

            case SDL_KEYUP:
                switch(event.key.keysym.sym)
                {
                    case SDLK_w:
                        {player.zvel = 0.0f;}; break;
                    case SDLK_a:
                        {player.xvel = 0.0f;}; break;
                    case SDLK_s:
                        {player.zvel = 0.0f;}; break;
                    case SDLK_d:
                        {player.xvel = 0.0f;}; break;
                    default: break;
                };
            break;
        };

    };

    player.x = player.x + float(player.zvel*cos((double)player.rotx));
    player.z = player.z + float(player.zvel*sin((double)player.rotx));

    glRotatef(player.rotx, 0.0f, 1.0f, 0.0f);
    glTranslatef(player.x, player.y, player.z);

    SDL_WarpMouse((screen->w/2), (screen->h/2));
};
  • 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-05-30T22:11:06+00:00Added an answer on May 30, 2026 at 10:11 pm

    If I’m correct the math functions sin and cos both take angles in radians, not degrees as player.rotx seems to be. Try the following:

    player.x = player.x + float(player.zvel*cos((double)player.rotx*0.0174532925));
    player.z = player.z + float(player.zvel*sin((double)player.rotx*0.0174532925));
    

    We’re multiplying player.rotx by pi/180, which is how we convert degrees to radians.

    Not sure if this is your only problem, but it certainly appears to be one of them.

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

Sidebar

Related Questions

Looking to improve my IF statement, and I want to keep my code looking
I keep looking, but it seems like there's zero interest from compiler developers in
I am looking to keep track of people in my iPhone app - either
I'd like to use model binding to keep my controllers looking cleaner, you can
Keep in mind that I'm not looking for a list of current browsers to
I'm looking for a tool that keep GAC synchronized across different systems. when a
I'm looking for a way to keep the equivalent of persistent global variables in
I'm looking for a data structure (or structures) that would allow me keep me
Is there a way to keep a window inactive looking, even if it contains
I am looking at a website on the internet with the standard centered box

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.