Business programmer with questions about graphics

Started by
4 comments, last by Spoonbender 18 years, 10 months ago
Hi. I have a lot of experience with c++, perl, and databases, but not counting my qbasic days, the only graphics I have ever really worked with are interfaces, and I am interested in getting into game development, so I have a few questions about some things that have been bothering me, if anyone would be up for pointing me in the right direction. First off, I will admit that I have not touched any type of real geometry in years, but I am willing to go back and brush up. I just have a few questions, about things I have no idea how to do. First, could someone possibly point me to a tutorial on how to work with degrees to do things like: If I have an object at an x/y position, say, the player character, and I want to track everything to another x/y position, say a mouse click, how could I determine what angle it would be? By angle, I mean what values if added onto the x and y coordiantes get to the mouse click, so I could track a bullet or something to it. I could just use a line() function, but that wouldn't give me any control. I have an idea of how to do this, such as calculating the radius out from the player character, but so far I don't have anything solid. For that specific problem I could probably find a messy way to do it by calculating it based on its x and y distance, but I know there is almost certainly an easier way using sine and cosine. I have googled around a bit and haven't found anything too helpful. Could someone possibly point me to a tutorial on this? Cheers.
Advertisement
Buy this book, it got me going....

Advanced 3D Game programming with DirectX 9.0
Peter Walsh, Wordware Publishing

Its concise, short and yet very descriptive. It covers everything.
No bombs, No guns, just an army of game creators...
Well, I think the specific answer to your question is as follows:

theta = arctan((x2-x1)/(y2-y1))

You have to watch out for y2 = y1 (divide by zero) and you may need to add/subtract pi radians depending on the signs involved.

If you're rusty on geometry the above may not make a lot of sense. It's a bit difficult to explain this kind of thing without diagrams. But really, KNOW YOUR GEOMETRY. A good grasp of vector and matrix maths is pretty much vital to good 3D programming. Trigonometry (which is what this problem is) doesn't come up as much but it does help to know about it, and how the trig functions relate to dot and cross product (vector maths).
Quote:Original post by ZQJ
Well, I think the specific answer to your question is as follows:

theta = arctan((x2-x1)/(y2-y1))

You have to watch out for y2 = y1 (divide by zero) and you may need to add/subtract pi radians depending on the signs involved.

If you're rusty on geometry the above may not make a lot of sense. It's a bit difficult to explain this kind of thing without diagrams. But really, KNOW YOUR GEOMETRY. A good grasp of vector and matrix maths is pretty much vital to good 3D programming. Trigonometry (which is what this problem is) doesn't come up as much but it does help to know about it, and how the trig functions relate to dot and cross product (vector maths).



I guess am going to have to go dig up my old textbooks from school :/

Thanks for the tip though.
Right now I am working on a 2d space shooter.. I have come quite far actually.
Writing it in Java while I learn Java.
I have arrays of polymophic badguy objects that are completely self contained, everything from ai, collision detection, and they even return images of themselves to be drawn onto the main canvas.
The game "works", you can move a ship around shooting at other ships and they shoot at you, but everything is moving in solid directions of up, down, left or right.

I guess I am just going to confront this the hard way and hit the books.
Oops, forgot to login.
That was me, tralk.
Quote:Original post by Anonymous Poster
I guess I am just going to confront this the hard way and hit the books.

Hehe, good luck with it. And remember, Google is your friend. It's amazing how many tutorials and explanations you can find there... :)

This topic is closed to new replies.

Advertisement