|
Post by Nicky Peter Hollyoake on Sept 1, 2008 10:35:04 GMT -5
I'm trying to get what angle an object is from another angle.
Example ..
Dim Spr(1)
Spr(0) = NewSprite(12): SprSetPos(100, 200): SprSetColor(1, 0, 0) Spr(1) = NewSprite(12): SprSetPos(100, 100): SprSetColor(0, 1, 0)
The green object from the red object is 0 degrees, or 360 degress. The red object from the green object is 180 degrees. I've tryed a few things but don't know how i'll caculate this.
- Nicky
|
|
|
Post by Darkjester on Sept 1, 2008 10:38:22 GMT -5
Are you trying this for collision? I'm thinking Geometry should do it. But ill need to know what exactly you need to do
|
|
|
Post by Nicky Peter Hollyoake on Sept 1, 2008 10:40:30 GMT -5
Are you trying this for collision? I'm thinking Geometry should do it. But ill need to know what exactly you need to do Collision, yes. Its actually for circle collisions, I can do it already, but finding the angle between 2 circles I can make a better collision. The sprites was just an example. - Nicky
|
|
|
Post by Darkjester on Sept 1, 2008 10:52:16 GMT -5
May i see the code? Maybe it just requires a mod?
|
|
|
Post by Nicky Peter Hollyoake on Sept 1, 2008 15:22:43 GMT -5
I ain't really got a code at the moment I've had a few test codes, but I never kept them. Maybe if you have even a rough idea maybe it can help.
- Nicky
|
|
|
Post by Darkjester on Sept 1, 2008 16:03:41 GMT -5
Ill check some common method for collision.
|
|
|
Post by Nicky Peter Hollyoake on Sept 2, 2008 18:51:44 GMT -5
Have you found a solution? I came across something, not 100% come across it though, but the "Atn2" helps. Some like ...
Atn2(X/X1, Y/Y1) * M_PI
Theres more to it, but I have no idea. ;D
Help?
|
|
|
Post by Darkjester on Sept 2, 2008 22:01:55 GMT -5
Close still trying to figure it out. So you want to find what angle is from a previous or angle on an angle? If its angle from a previous then i might be onto something.
|
|
|
Post by Nicky Peter Hollyoake on Sept 3, 2008 5:29:10 GMT -5
I want to find the angle between 2 circles, its saves me doing a 360 check everytime I want to check for collision.
|
|
|
Post by andrian on Sept 3, 2008 7:08:52 GMT -5
you mean the angle between their centers?
|
|
|
Post by matthew on Sept 3, 2008 7:10:33 GMT -5
I found a Pool game written in Blitz Basic, it features a Function for calculating collisions. (The following code is in Blitz Basic.) Function angle%(x1#,y1#,x2#,y2#) Local angle%=ATan2(x2-x1,y2-y1) Return 180-angle End Function
|
|
|
Post by andrian on Sept 3, 2008 12:46:13 GMT -5
hey, can you send me the code for that?
|
|
|
Post by Nicky Peter Hollyoake on Sept 3, 2008 14:41:32 GMT -5
you mean the angle between their centers? Yes. I found a Pool game written in Blitz Basic, it features a Function for calculating collisions. (The following code is in Blitz Basic.) Function angle%(x1#,y1#,x2#,y2#) Local angle%=ATan2(x2-x1,y2-y1) Return 180-angle End Function
Thanks, I test this code. Dim Spr(1)
Spr(0) = NewSprite(12): SprSetPos(100, 200): SprSetColor(1, 0, 0) Spr(1) = NewSprite(12): SprSetPos(100, 100): SprSetColor(0, 1, 0)
Function Angle(x1#,y1#,x2#,y2#) Dim angle# = ATN2(x2#-x1#, y2#-y1#) Return 180-Angle# EndFunction
'Test Print Angle(SprX(Spr(0)), SprY(Spr(0)), SprX(Spr(1)), SprY(Spr(1))) This does not work, it returns '176', maybe I made it wrong? I didn't get quite "AngleEnd" whats this? - Nicky
|
|
|
Post by Darkjester on Sept 3, 2008 14:55:51 GMT -5
Here ya go returns 180!! Just used the wrong ATN func! ;D Dim Spr(1) Spr(0) = NewSprite(12): SprSetPos(100, 200): SprSetColor(1, 0, 0) Spr(1) = NewSprite(12): SprSetPos(100, 100): SprSetColor(0, 1, 0) Function Angle(x1#,y1#,x2#,y2#) Dim angle# = ATNd(x2#-x1#) Return 180-Angle# EndFunction 'Test Print Angle(SprX(Spr(0)), SprY(Spr(0)), SprX(Spr(1)), SprY(Spr(1)))
|
|
|
Post by matthew on Sept 3, 2008 17:06:14 GMT -5
hey, can you send me the code for that? Yeah sure, the full program can be found on this page. You might also want to check out the collision code in this, it's a 2D Pool game written by Tom back in 2004. I'm not sure but maybe the Blitz Basic program used Radians to calculate angles which is why it was giving incorrect results at first?
|
|