Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
I'm working again some more on my Programming ship battle game, and I'm working on the laser system. This is how the laser works:
------------------ |
||
jestermax![]() Member Posts: 1064 From: Ontario, Canada Registered: 06-21-2006 |
what are you using as your algorithm? it sounds like just need some old y=mx+b stuff | ||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
The algorithm is my problem, and what I need. Unfortunetly the most advanced math I get in school is the Metric system, and graphing. So I've got to learn what I can off the net. ------------------ |
||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
your path would just be the reverse (negative) of how you do it for 0... ie. pathY = pathY * -1; // simple reverse the pathY (if - make +, if + make -)... ------------------ |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Okay, how do I calculate if someone is within the path? It'd be at angle 22.5 BTW. I just checked your formula, it appears to be, dist * Abs(angle) But that can't be right. because that would mean the end X,Y would be if starting from 400,300 would be -6,750. Would you mind going into a bit more depth? ------------------ [This message has been edited by Mene-Mene (edited February 21, 2007).] |
||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
What kind of shapes are in the path? Are they rectangles? Polygons? Pixels? How are you doing your level map? If they are rects or polygons you will have to track the line intersections. If pixels, I believe you will have to do a ray trace. ------------------ |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
The obsticles are images. I'll redescribe my problem. I know how to calculate the Additions to X and y. Y = Y - (Sine of (Angle - 90) * Distance) and X = X - (Cosine of (Angle - 90) * Distance). My problem I'm realizing is my distance formula requires the X and Y coordinates. ------------------ |
||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
Are you planning on doing bounding box (or bounding circle), or pixel perfect collisions? ------------------ |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
bounding box. ------------------ |
||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
Your best bet is to compute the intersection of the laser's line with the lines of each of the bounding boxes. Here is a pretty cool line intersection algorithm google produced. Its written in C so you will have to port it to BM. (Good Practice http://www.whisqu.se/per/docs/math28.htm ------------------ |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Finally got around to converting it, some of the things didn't quite crossover, and the variables are terribly labled, (not that I'm not as bad) all the names are the same as I didn't quite understand it. here's the BM code:
The things that didn't crossover well were the matrixes, the setting of an infinity variable, and pointers. Another problem is its all good and well in all, but it doesn't return any result, how am I too know what to input, and what means I had a collision? Here's the original:
------------------ I reserve the full right to change my views/theories at any time. [This message has been edited by Mene-Mene (edited March 01, 2007).] |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
My big problem also is where is my X and Y? How am I to find out what the X and Y are? ------------------ I reserve the full right to change my views/theories at any time. |
||
Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
The X and Y of what, Mene? | ||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
First, good job on porting it. As for the matrix, that is a flaw in their posting system. the word matrix is a part of the previous line's comment. // the inverse of the determinant of the coefficient matrix so, m1 and m2 are simply floats, but good job recognizing that as a potential type. FYI, what tipped me off to it was that det_inv is followed by a comma not a semi. Anyhoo. It takes two points(x,y) to plot a line. x0,y0 is a point of one of the lines x1,y1 is the other point of that line. (x2,y2),(x3,y3) are the two points for the other line. BTW, these are infinite lines, not line segments with end points. I don't know if you noticed, but the function doesn't return true if the lines intersect and false if they don't. It returns *where* they intersect. Which could be an advantage for you since you probably want an explosion at the point where they intersect. The pointers they are using are actually the function's result. In other words xi and yi are the point on the screen where the lines intersect. The coder is using pointers to pass back two values by changing the variables pointed to by *xi,*yi. That's all I've got time for right now. God Bless! ------------------ |
||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
Ugh, actually as I was looking through this code some more, its really not what you are looking for. You need a line segment intersection snippet. Here, try this for a starter.
------------------ [This message has been edited by samw3 (edited March 02, 2007).] |
||
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
I'm being a bit pesky, and thanks for the code, but it isn't quite what I need. I've got an infinate line of which I only know the angle, and the starting points. It starts at say 0,300 and has an Angle of 90. I know that it will end up at the edge of the screen: 800,300. But if it has 89 I won't know. Sine and Cosine won't work because I don't know the distance. and they were built for a circle. ------------------ I reserve the full right to change my views/theories at any time. |
||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
Well, let me make sure I got it right. Now, assuming an 800x600 screen with 0,0 in the top left corner. The line segments you want to test for laser shot 1 are: The line segments you want to test for laser shot 2 are: So to test if any laser shot hits anything, calculate your laser segment (x1,y1,x2,y2) and test it against all the lines in your level (walls, screen borders). In the example above there would be 8 tests, 4 for the screen boundaries, 4 for the wall (each side) Is this what you are wanting to do? P.S. If you are using a tile based map you could test the rectangle(four lines) of each tile that is solid. ------------------ |