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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:23:47+00:00 2026-06-14T16:23:47+00:00

I am using OpenGL to create the 3D space. I have a spaceship which

  • 0

I am using OpenGL to create the 3D space.
I have a spaceship which can fire lasers.

Up until now I have had it so that the lasers will simply to deeper into the Z-axis once fired.
But I am attempting to make a proper aiming system with crosshairs so that you can aim and shoot in any direction, but I have not been successfull in trying to update the laser’s path.

I have a directional vector based off the lasers end tip and start tip, which is gotten from the aiming.

How should I update the laser’s X,Y,Z values (or vectors) properly so that it looks natural?

  • 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-14T16:23:49+00:00Added an answer on June 14, 2026 at 4:23 pm

    I think I see.

    Let’s say you start with the aiming direction as a 3D vector, call it “aimDir”. Then in your update loop add all 3 (x, y and z) to the projectile “position”. (OK, at the speed of light you wouldn’t actually see any movement, but I think I see what you’re going for here).

    void OnUpdate( float deltaT )
    {
        // "move" the laser in the aiming direction, scaled by the amount of time elapsed
        // since our last update (you probably want another scale factor here to control
        // how "fast" the laser appears to move)
    
        Vector3 deltaLaser = deltaT * aimDir;  // calc 3d offset for this frame
        laserEndpoint += deltaLaser;           // add it to the end of the laser
    }
    

    then in the render routine draw the laser from the firing point to the new endpoint:

    void OnRender()
    {
        glBegin(GL_LINES);
        glVertex3f( gunPos.x, gunPos.Y, gunPos.z );
        glVertex3f( laserEndPoint.x, laserEndPoint.y, laserEndPoint.z );
        glEnd();
    }
    

    I’m taking some liberties because I don’t know if you’re using glut, sdl or what. But I’m sure you have at least an update function and a render function.

    Warning, just drawing a line from the gun to the end of the laser might be disappointing visually, but it will be a critical reference for adding better effects (particle systems, bloom filter, etc.). A quick improvement might be to make the front of the laser (line) a bright color and the back black. And/or make multiple lines like a machine gun. Feel free to experiment 😉

    Also, if the source of the laser is directly in front of the viewer you will just see a dot! So you may want to cheat a bit and fire from just below or to the right of the viewer and then have in fire slightly up or in. Especially if you have one one each side (wing?) that appear to converge as in conventional machine guns.

    Hope that’s helpful.

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

Sidebar

Related Questions

So I have a cylinder in openGL which I've created not using gluCylinder but
I'm using glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, n, 100) to create 100 cylinders in OpenGL. Now I
I have been using OpenGL 3.0 and one of the things that has me
I'm using opengl and trying to create a first person camera. All examples use
I've created an OpenGL ES game which is being rendered using a GLKView on
Using OpenGL ES I am rendering a simple cube class that draws it at
I need to create good looking lightning using OpenGL ES 1.1 (iPhone) and was
Im trying to create a spinning square inside of xcode using opengl but instead
I'm trying to create a go board using opengl. To do this, I'm trying
I am trying to create a live wallpaper using opengl (<2.0). I imported and

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.