local Rotation = (r/360)*(3.1415*2)
for i = ModelPartStart[id],ModelPartEnd[id] do
DrawX = xpos + (math.cos(Rotation)*ModelPartX[i])
DrawY = ypos + (math.sin(Rotation)*ModelPartY[i])
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
function FindAngle(x1,y1,x2,y2,x3,y3)
local AO = ((x1-x2)^2)+((y1-y2)^2)
local AB = ((x2-x3)^2)+((y2-y3)^2)
local BO = ((x3-x1)^2)+((y3-y1)^2)
local CosCalc = math.cos((AO+BO-AB)/(2*math.sqrt(AO*BO)))
print(CosCalc)
end
-- Assuming a clockwise turn is a positive turn, then
function TurnDirection(Ax, Ay, Bx, By, Ox, Oy)
TurnDirectionMultiplier = -1
if Ax > Bx then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
if Ay > Oy then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
if By > Oy then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
function FindAngle(Ox,Oy,Ax,Ay,Bx,By)
local AOx = Ox - Ax
local AOy = Oy - Ay
local BOx = Ox - Bx
local BOy = Oy - By
local AB = (AOx*BOx)+(AOy*BOy)
local LenghtOA = math.sqrt(AOx^2+AOy^2)
local LenghtOB = math.sqrt(BOx^2+BOy^2)
local CosAngle = AB / (LenghtOA*LenghtOB)
TurnDirectionMultiplier = -1
if Ax > Bx then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
if Ay > Oy then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
if By > Oy then
break
else
TurnDirectionMultiplier = TurnDirectionMultiplier * -1
end
return(math.deg(math.acos(CosAngle))*TurnDirectionMultiplier)
end
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
local dx = posx-GetMouseY()
local dy = posy-GetMouseX()
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