Author Topic: Rotation  (Read 3933 times)

0 Members and 1 Guest are viewing this topic.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #15 on: May 13, 2011, 02:54:08 PM »
So, over to some new... I found a way to do it, my uncle(he's been doing some coding too :D) told me..

Explaining it simple with pictures...


(Don't worry, it will contain Cos and Sin...)

It will be hard to make, but thats the theory... And annikk, the tutorials sucks :/ Why don't you explain(I 've learnt almost everything from you :P)?

EDIT: Or maybe a simplier version:

You have a line for the unit that search, the line will be as long as the distance between the two units(Pythagoras Theorem) and then when that lines end is close to the coords of the unit it search for, it will say that THIS is the angle... That makes it all much more simplier, I can even see the code in my head(literally D:)...

EDIT 2: It works, not totally propperly, because it isn't recognizing it in some areas... but it works! :D

Code: (Code for facing angle) [Select]
function FindFacingAngle(x1,y1,x2,y2)

local XDIFF = (x1-x2)^2
local YDIFF = (y1-y2)^2

local Distance = math.abs(math.sqrt(XDIFF+YDIFF))

for i = 1,360 do
local CurAngle = (i/360)*(math.pi*2)
if x1 + math.cos(CurAngle)*Distance >= x2-Distance/(math.pi*2) and x1 + math.cos(CurAngle)*Distance <= x2+Distance/(math.pi*2) and y1 + math.sin(CurAngle)*Distance >= y2-Distance/(math.pi*2) and y1 + math.sin(CurAngle)*Distance <= y2+Distance/(math.pi*2) then
return(i)
else
if i == 360 then

return(i)

end
end
end

end

Yeah, I know it is very resource consumpting, but you can remove that by making some if's and stuff to check if the angle has been changed(or simply if the unit is a target and the x/y coords are changed :P)
« Last Edit: May 13, 2011, 03:27:38 PM by Aino »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #16 on: May 13, 2011, 03:58:38 PM »
Maybe not so resource consumting as i thought?



That is 11x11 which is 121 models, and then 121x360 which is 43560(+sqrt(pythagoras)) calculations per DRAW! so, it's very silent and I guess that if you use the function correctly, you won't need 121 of them at the same time per draw :P
« Last Edit: May 13, 2011, 04:51:14 PM by Aino »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Rotation
« Reply #17 on: May 13, 2011, 06:40:19 PM »
...on the asteroid.

It has the highlight that they get when you hover over them.

Also, the squarer end of all the models/sprites are popinting to the centre.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #18 on: May 13, 2011, 10:10:58 PM »
O.o

Well, you see that they point that way, thats' what I made... it rotates toward the mouse :D

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #19 on: May 14, 2011, 10:01:15 AM »
Need help, again...

This is about finding the shortest turn, but if you didn't understand what I meant:



So, any advice?

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Rotation
« Reply #20 on: May 14, 2011, 01:13:22 PM »
Do you have a property for the rotation of the whatever-it-is-that-you-want-to-turn?

If so, how does it work, and where is 0 degrees?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #21 on: May 14, 2011, 01:31:12 PM »
0 Degree would be at the absolute right side of the sircle, and 90 would be straight DOWN and so on :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Rotation
« Reply #22 on: May 20, 2011, 09:54:06 AM »
I'll try to help with this properly now.


First of all lets be clear about what the problem is.



Asteroid O is facing toward Asteroid A.  We wish to rotate it such that it is facing Asteroid B instead.

We already know the coordinates of Asteroids O, A, and B.

How to find the angle?



Let me know if this is indeed what you are trying to calculate Aino.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #23 on: May 20, 2011, 09:56:44 AM »
Yes Annikk, yes...

Thats indeed what I need help with, cause the current one is very inaccurate when it comes to accurate stuff :/
« Last Edit: May 20, 2011, 10:00:49 AM by Aino »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Rotation
« Reply #24 on: May 20, 2011, 11:04:51 AM »
You can calculate the angle using the following formula:


Tan Angle = (Am - Bm) / (1 + (Am * Bm))


Two steps will be required to turn this formula into something useful.

First, we need to find out what Am and Bm are.

Second, we need that "Tan" to be on the right-hand side, leaving just the "angle" on the left hand side.



"m" refers to the "slope" of the lines.

To calculate the slope of the line between points O and A, we use the following:

Am = (Ay - Oy) / (Ax - Ox)

We can fill those out already.  Ay = 200, Oy = 0, Ax = 300, Ox = 0.

So we can fill those values in:
Am = (200 - 0) / (300 - 0)
Am = 200 / 300
Am = 0.666666


I have to go out for a couple hours now.  Aino, can you use this example to calculate Bm.  I'll check it when I get back, and continue with the explanation.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #25 on: May 20, 2011, 11:17:55 AM »
Thanks for the stuff, finally :P

I'm currently "away" myself, can't do any coding... But as soon as I can I'll test it :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Rotation
« Reply #26 on: May 20, 2011, 01:16:14 PM »
Slacker :P  We're not finished yet you know!

Anyway, here's Bm:


Bm = (By - Oy) / (Bx - Ox)

We can fill those out already.  By = -300, Oy = 0, Bx = 0, Ox = 0.

So we can fill those values in:
Bm = (-300 - 0) / (0 - 0)
Bm = -300 / 0
Bm = Infinity


w00t, divided by zero.


Bear with me, I'll find a better method to do this.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Rotation
« Reply #27 on: May 20, 2011, 02:43:09 PM »
Ok here's my awesome guide.

































I made this with some help from this guide.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Rotation
« Reply #28 on: May 20, 2011, 04:11:57 PM »
Beware the ambiguous case [thunder rumbles].

http://en.wikipedia.org/wiki/Law_of_cosines#Applications   Last paragraph of the Applications section, though I don't think it applies in this case.


Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #29 on: May 20, 2011, 06:48:34 PM »
aww, it includews a sqrt :/