Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm drawing my ship by the following code and wanted to draw a missile at the tip of the ship, so that when I click spacebar it fires that missile. I don't know if what I'm doing is correct or not. Is that the "correct" way to do the job of drawing a missile then firing it by a space bar? or there is a "better" way? Is the transformation correct here, I mean writing hard coded values and just stick the missile at the tip of the ship by trial and error?

void Ship::Draw( )




void Bullet::Draw(int x, int y)
share|improve this question
Can you edit your question to include a question? Thanks. – Byte56 Jul 30 '12 at 21:07
up vote 0 down vote accepted

I am not certain if I exactly understand this question, and I do not know OpenGL. That being said, my interpretetion here is that you are trying to draw the missile dependant on the ship's position, similarely to determining where to create a bullet object from a gun, when it is not directly in its center, and is offset either a direct amount from the center on one axis, or on both. (further changing this when set object rotates).

First, I am personally a fan using variables over hard-coded (magic, perhaps) numbers. First, allows easier modification if you change it, and, well, I think might be easier to work with, but your choice. For exampple, let's say each logic frame, you incriment the ship's position. If you suddenly decide to change the speed from, say, 3 to 4, using hard-coded numbers you need to change all of them. Or, you could have them all use speed, and just change the value of speed. This might be useful if said variables change during runtime, something which hard coded numbers cannot, but perhaps a runtime transformation works just as well.

As per positioning it, I know you can find the translation on each axis given a speed and direction, where the speed is length of the hypothesis and direction is an angle, where you can then use trigenometry to determine the actual incriments. Using this, you could, say, find a point relative from the ship where you want the missile, and position it accordingly.

Is this what you were looking for?

share|improve this answer

To get the position, assume you have a vec3 that hold the position of the ship. All what you have to do is to set the position of the bullet to that vec3 of the player.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.