Simple relative positioning question
OK, so I''ve got a 2D ship on the screen which rotates, done that, thats easy. Its then supposed to fire a laser, I need that laser to appear at the front of the ship.
Currently I just set the lasers start coordinates to the same as the ships x and y (centre of the ship) but I could do with it appearing at the front-centre of the ship.
I know this is an elementary question, but I''ve been sat here for ages trying to work it out and I give up.
Could someone just give me some matrices I can use to do the transformation, or a formula or something?
The ships got angle, x, y, width and height member variables.
Cheers.
Dave.
Currently studying BSc Computer Science at the University of Nottingham, England
Dave.
Assuming the ship is facing forward, and the center is at (0,0), the front would be (0, height/2). If you know how to multiply matrices, multiply the followign
[ 0 ] [ cos(theta) sin(theta) ]
[ h/2] [ -sin(theta) cos(theta) ]
That will give you the new position, assuming the center is (0,0). I''m not sure how your coordinate system is setup, but if the center is not (0,0), then you take the calculated coordinates, (x1, y1) and add it to the center. So you''d get (x1+x, y1+y).
[ 0 ] [ cos(theta) sin(theta) ]
[ h/2] [ -sin(theta) cos(theta) ]
That will give you the new position, assuming the center is (0,0). I''m not sure how your coordinate system is setup, but if the center is not (0,0), then you take the calculated coordinates, (x1, y1) and add it to the center. So you''d get (x1+x, y1+y).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement