Author Topic: Rotation  (Read 3903 times)

0 Members and 1 Guest are viewing this topic.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Rotation
« Reply #60 on: July 27, 2011, 09:13:14 PM »
Occam's Razor, etc.  :>

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #61 on: July 27, 2011, 09:15:03 PM »
Yes, it is done :)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #62 on: July 30, 2011, 05:36:22 PM »


I just saw that Atan2 calculates angles between two points x.x

Just do math.atan2(x2-x1,y1-y2) and it should work, it works together with math.sin/cos since it returns negative to positive pi >.<

And as we know, be is the circle, you can use pi*2 in sin/cos to get a circle instead of using negative, but negative works just as well :)

I've been experiementing alot with trigonometry :o


Going to test it now, solving the most ancient programming question I've had in my mind since I started with math...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #63 on: July 30, 2011, 05:54:51 PM »
Results Test 1:

Weird that this code halflike works:

Code: [Select]
function LevelSetup()
Globals.G.Asteroids=0
Globals.G.EnemyFactionsMin=0
Globals.G.EnemyFactionsMax=0
Globals.Asteroids.SpawnCap=0
SetBackdropColour(0,0,0)

a = AddAsteroid(0,0)
a.Radius = 50
a.Owner = 1
a.TreeCap = 1
a:AddSeedlings(10)

posx = -100
posy = -100

end

function LevelLogic()

end

function GetMouseX()

return(GetCameraX()+(((GetMouseScreenX()-(GetScreenWidth()/2)))*GetCameraZoom()))

end

function GetMouseY()

return(GetCameraY()+(((GetMouseScreenY()-GetScreenHeight()/2))*GetCameraZoom()))

end

function LevelDraw()

local dx = posx-GetMouseY()
local dy = posy-GetMouseX()

local atan2 = math.atan2(dx,dy)
local dist = math.sqrt((dx^2)+(dy^2))

DrawLine(posx,posy,posx+math.cos(atan2-math.pi)*dist,posy+math.sin(atan2-math.pi)*dist,1,1,1,1,1,1,1,1,5)

end

Because of:

Code: [Select]
local dx = posx-GetMouseY()
local dy = posy-GetMouseX()

Where the values are switched, WTH?

Though it only work on perfectly similar positions, like (-100,-100) or (100,100) :P

Test 2 soon, I'm gonna get to the bottom of this seed!

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #64 on: July 30, 2011, 06:15:29 PM »
Attempt 2, succesful!

Code: [Select]
function LevelSetup()
Globals.G.Asteroids=0
Globals.G.EnemyFactionsMin=0
Globals.G.EnemyFactionsMax=0
Globals.Asteroids.SpawnCap=0
SetBackdropColour(0,0,0)

a = AddAsteroid(0,0)
a.Radius = 50
a.Owner = 1
a.TreeCap = 1
a:AddSeedlings(10)

posx = -100
posy = -100

end

function LevelLogic()

end

function GetMouseX()

return(GetCameraX()+(((GetMouseScreenX()-(GetScreenWidth()/2)))*GetCameraZoom()))

end

function GetMouseY()

return(GetCameraY()+(((GetMouseScreenY()-GetScreenHeight()/2))*GetCameraZoom()))

end

function LevelDraw()

local dx = posx-GetMouseX()
local dy = posy-GetMouseY()

local atan2 = math.atan2(dx,dy)
local atan22 = math.atan2(dy,dx)
local dist = math.sqrt((dx^2)+(dy^2))

DrawLine(posx,posy,posx+math.cos(atan2-(atan22/2))*dist,posy+math.sin(atan2-(atan22/2))*dist,0,1,0,1,1,1,1,1,5)
DrawLine(posx,posy,posx+math.cos(atan2-atan22)*dist,posy+math.sin(atan2-atan22)*dist,1,0,0,1,1,1,1,1,5)
DrawLine(posx,posy,posx+math.cos(atan2)*dist,posy+math.sin(atan2)*dist,1,1,1,1,0,1,0,1,5)
DrawLine(posx,posy,posx+math.cos(atan22-math.pi)*dist,posy+math.sin(atan22-math.pi)*dist,1,1,1,1,1,0,0,1,5)
DrawText(atan2,GetMouseX(),GetMouseY(),1,25)

end

!!

My life is complete!!

I love using memes :D

Edit:

Uploaded the complete file without extra arrows, it should work! :)
« Last Edit: July 30, 2011, 06:22:23 PM by Aino »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Rotation
« Reply #65 on: July 30, 2011, 07:03:09 PM »
I realize I've solved alot of problems, of my own(coding wise), with three lines of code o.o

The three can be compressed to one even :D

This is so awesome ;D