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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:27:27+00:00 2026-05-16T17:27:27+00:00

Here is what I’m trying to do. I’m trying to make a bullet out

  • 0

Here is what I’m trying to do. I’m trying to make a bullet out of the center of the screen. I have an x and y rotation angle. The problem is the Y (which is modified by rotation on the x) is really not working as intended. Here is what I have.

 float yrotrad, xrotrad;

    yrotrad = (Camera.roty / 180.0f * 3.141592654f);
    xrotrad = (Camera.rotx / 180.0f * 3.141592654f);
    Vertex3f Pos;

// get camera position
    pls.x = Camera.x;
    pls.y = Camera.y;
    pls.z = Camera.z;


    for(float i = 0; i < 60; i++)
    {


    //add the rotation vector

        pls.x += float(sin(yrotrad)) ;
        pls.z -= float(cos(yrotrad)) ;
        pls.y += float(sin(twopi - xrotrad));

    //translate camera coords to cube coords
        Pos.x = ceil(pls.x / 3);
        Pos.y = ceil((pls.y) / 3);
        Pos.z = ceil(pls.z / 3);

        if(!CubeIsEmpty(Pos.x,Pos.y,Pos.z)) //remove first cube that made contact
        {
            delete GetCube(Pos.x,Pos.y,Pos.z);
            SetCube(0,Pos.x,Pos.y,Pos.z);
            return;
        }
    }

This is almost identical to how I move the player, I add the directional vector to the camera then find which cube the player is on. If I remove the pls.y += float(sin(twopi - xrotrad)); then I clearly see that on the X and Z, everything is pointing as it should. When I add pls.y += float(sin(twopi - xrotrad)); then it almost works, but not quite, what I observed from rendering out spheres of the trajector is that the furthur up or down I look, the more offset it becomes rather than stay alligned to the camera’s center. What am I doing wrong?

Thanks

What basically happens is very difficult to explain, I’d expect the bullet at time 0 to always be at the center of the screen, but it behaves oddly. If i’m looking straight at the horizon to +- 20 degrees upward its fine but then it starts not following any more.

I set up my matrix like this:

void CCubeGame::SetCameraMatrix()
{

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glRotatef(Camera.rotx,1,0,0);
    glRotatef(Camera.roty,0,1,0);
    glRotatef(Camera.rotz,0,0,1);

    glTranslatef(-Camera.x , -Camera.y,-Camera.z );
}

and change the angle like this:

void CCubeGame::MouseMove(int x, int y)
{
    if(!isTrapped)
        return;

    int diffx = x-lastMouse.x; 
    int diffy = y-lastMouse.y; 

    lastMouse.x = x; 
    lastMouse.y = y;
    Camera.rotx += (float) diffy * 0.2; 
    Camera.roty += (float) diffx * 0.2; 
    if(Camera.rotx > 90)
    {
        Camera.rotx = 90;
    }

    if(Camera.rotx < -90)
    {
        Camera.rotx = -90;
    }

    if(isTrapped)
    if (fabs(ScreenDimensions.x/2 - x) > 1 || fabs(ScreenDimensions.y/2 - y) > 1) {
        resetPointer();
    }

}
  • 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-16T17:27:28+00:00Added an answer on May 16, 2026 at 5:27 pm

    You need to scale X and Z by cos(xradrot). (In other words, multiply by cos(xradrot)).

    Imagine you’re pointing straight down the Z axis but looking straight up. You don’t want the bullet to shoot down the Z axis at all, this is why you need to scale it. (It’s basically the same thing that you’re doing between X and Z, but now doing it on the XZ vector and Y.)

    pls.x += float(sin(yrotrad)*cos(xrotrad)) ;
    pls.z -= float(cos(yrotrad)*cos(xrotrad)) ;
    pls.y += float(sin(twopi - xrotrad));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem : I have a post controller with the action create.
Here's a problem I ran into recently. I have attributes strings of the form
Here is what I am trying to achieve in PHP: I have this string:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is my problem...I have a page that loads a list of clients and
Here is an example: I have a file 1.js, which has some functions. I
Here's my proposed (very simplified to illustrate the problem space) design for a C#
Here's the basic setup: I have a thin bar at the top of a
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:

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.