Thread: Projectiles in openGL(need help)

  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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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, 01: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, 11:18 AM
  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, 02:34 PM
  5. Opengl
    By kas2002 in forum Game Programming
    Replies: 1
    Last Post: 06-28-2002, 11:46 AM