Projectiles in openGL(need help)

This is a discussion on Projectiles in openGL(need help) within the C++ Programming forums, part of the General Programming Boards category; I want to launch a projectile in openGL where when I click my left mouse button, it would shoot a ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    135

    Projectiles in openGL(need help)

    I want to launch a projectile in openGL where when I click my left mouse button, it would shoot a sphere to the position where I am facing. BUt I already confused about the distance to launch. I use this code to launch projectile but my program crashed.
    Code:
    void CProjectile::render()
    {
    	glPushMatrix();
    	glColor3f(1,1,0);
    		glTranslatef(theCamera-> Forward.x  - theCamera-> Position.x  , theCamera->Forward.y - theCamera-> Position.y, theCamera-> Forward.z - theCamera->Position.z);
    			drawSphere();
    	glPopMatrix();
    }
    
    void CProjectile::drawSphere()
    {
    	glSolidSphere(10,10,10);
    }
    thePosition is the position of the camera, Forward is the direction I am looking in the camera, am I done it wrong. Please help. Thank you.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    What do you mean shoot a sphere to the position you are facing? The facing is the look vector of your camera. If you fire a projectile down the look vector it will fire in the direction the camera is facing.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    135
    How to code like that using the look vector?

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Projectile.velVector = Camera.Look
    Projectile.speed = <some_scalar>

    Projectile.position += Projectile.velVector * Projectile.speed * frameDelta;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2010, 02:26 PM
  2. OpenGL Quesiton: Does Windows XP, Vista still at OpenGL 1.1?
    By indigo0086 in forum Game Programming
    Replies: 8
    Last Post: 05-21-2007, 12:18 PM
  3. Replies: 5
    Last Post: 02-12-2006, 08:42 PM
  4. OpenGL, texturing...and...more OpenGL
    By Sunny in forum Game Programming
    Replies: 2
    Last Post: 07-08-2002, 03:34 PM
  5. Opengl
    By kas2002 in forum Game Programming
    Replies: 1
    Last Post: 06-28-2002, 12:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21