Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Need help with some basic trig that's eluding me (vectors and angles)

Author
Message
Giant_Jack
13
Years of Service
User Offline
Joined: 25th Jun 2009
Location:
Posted: 17th Dec 2011 01:45
I'm working on a concept that makes heavy use of rotating objects, and after I gave up trying to work with matrices for hitboxes because they're a pain to work with in DB, I decided to try a more interesting approach -- hitboxes built out of vectors that are calculated by angles relative to each other, rather than annoying matrix operations.

The results seem pretty good using this method, and they're much easier to work with, however I'm having a hard time drawing the first point at a proper distance from the center, of the box. It likes to end up in a weird position.

Maybe I'm using the wrong equation here, but I'm pretty sure the distance from the center of the box should be determined by A^2+B^2=C^2, then divide C/2. Nope.

It looks to be accurate if I draw the box with equal width and height, but making it's width larger than the height or vise versa skews the calculation.

My only idea of what's going wrong is that it may have something to do with the fact that the equations I'm using don't translate perfectly to DarkBasic's coordinate system where Y gets larger as it moves downward rather than the other way around.


What might I be doing wrong here?


LBFN
15
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 19th Dec 2011 01:49
Man, that seems like a lot of work to go to in order to rotate a tank. I would suggest ditching the trig / math idea and simply load or make an image, create a sprite and rotate it the way you want. You could search for threads on pixel perfect collision that should help you if sprite collision is inadequate.

If you are dead-set on using trig, look up threads by Neuro Fuzzy - he is an ace with trig.


Phaelax
DBPro Master
19
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Dec 2011 02:47
Use a UDT instead of multi-dimensional array, it'll make it 10x easier to read.

These lines confuse me:

Rem Object #1 scaled at 30x50 pixels
Scale#(1,1)=40
Scale#(1,2)=25


What are those numbers?

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Van B
Moderator
20
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2011 15:39
Do you really need to rotate on all axis at the same time though?

I mean, a turret will turn left and right, and it's really easy to get that working - but then the turret rises or lowers, and this would not be calculated based on trig. Know what I mean? - the turret has to allow for drop off, so perhaps it would be better to try calculating the trajectory and setting the turret X angle from that... leaving the Y angle calculation to ATANFULL.

Also, WRAPVALUE() will return the wrapped angle of the given value - neater than using an IF statement, as it allows for values >360 and <-360.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2022-12-06 03:09:26
Your offset time is: 2022-12-06 03:09:26