Old 01-16-2017, 08:57 PM   #1
Human being with feelings
Lokasenna's Avatar
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 4,213
Default API: gfx.arc is 90 degrees off

gfx.arc isn't using the same reference angle as Lua's trig functions. The lines in the image below were drawn using the same angle as the arc's endpoints. As you can see, the arc is 90 degrees away from where it should be.

It's not a difficult thing to fix - just add 0.5 to the rad values when you draw an arc - but it's a prime candidate for the Nitpick forum. If we'd rather not fix it due to the havoc it would wreak on existing scripts, at minimum I'd like to see a note added to the API documentation so nobody else has to waste an hour figuring out why their code was all messed up like I just did.


local name, w, h = "", 258, 258

local x, y = reaper.GetMousePosition()
x, y = x - (w / 2) - 8, y - (h / 2) - 30

local ox, oy = w / 2, h / 2

local angle_a = -0.25 * math.pi
local angle_b = 0.25 * math.pi
local r = 96

function Main()
	local quit = gfx.getchar()
	if quit == -1 or quit == 27 then return 0 end

	gfx.set(0.2, 1, 0.2, 1)
	local ax = ox + r * math.cos(angle_a)
	local ay = oy + r * math.sin(angle_a)
	gfx.line(ox, oy, ax, ay)
	local bx = ox + r * math.cos(angle_b)
	local by = oy + r * math.sin(angle_b)
	gfx.line(ox, oy, bx, by)
	gfx.set(1, 0.2, 0.2, 1)

	gfx.arc(ox, oy, r, angle_a, angle_b, 1)


gfx.init(name, w, h, 0, x, y)
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack

Last edited by Lokasenna; 01-16-2017 at 09:11 PM.
Lokasenna is online now   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 04:37 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.