Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
lumlune
Prole
Posts: 12
Joined: Fri May 02, 2014 9:50 pm

bartbes wrote:Only love.thread is loaded in a thread, and to require files normally, you also need to load love.filesystem, so start off with

Code: Select all

require "love.filesystem"
and it should work from then on.
This did it, thank you.
mickeyjm
Party member
Posts: 237
Joined: Thu Dec 29, 2011 11:41 am

I've been learning how to use opengl recently and I noticed that opengl rotates in degrees while love uses radians. Is there a reason that this is the case? Because if anything I would expect the hardware accelerated functions (i.e. opengl) to use radians, as they are more useful in mathematics, while the (for lack of a better word) "simpler" functions (i.e. love) to use degrees as they are what is taught first at school.
Your screen is very zoomed in...
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

How would I go about serialising C data? I am currently using the FFI library to create a structure that I store lots of data in, and being able to save it is crucial.
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

How can I find the angle of AOB, O being the vertex ?
I searched and found this:

Code: Select all

math.cosh(dot(toVect(O,B),toVect(O,A))
and

Code: Select all

math.cosh((dist(O.x,O.y,A.x,A.y)^2 + dist(O.x,O.y,B.x,B.y)^2 - dist(A.x,A.y,B.x,B.y)^2)/(2*dist(O.x,O.y,A.x,A.y)*dist(O.x,O.y,B.x,B.y)))
But when I test either of these functions with three point which the angle should be 90 ({0,0},{1,0},{0,1}), I get 1.
So I added *90 to the end of both calculations but when I tested for a 45º angle ({0,0},{1,1},{1,0}) I got 138.877...

So I'm wondering if anyone here knows of a way to do this.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

As in A and B being the points, and O being the connecting point?

Code: Select all

function GetAngle( Ax, Ay, Ox, Oy, Bx, By )
-- Using law of Cosines: C ^ 2 = A ^ 2 + B ^ 2 - 2 * A * B * Cos( C )
-- C ^ 2 - A ^ 2 - B ^ 2 = -2 * A * B * Cos( C )
-- ( C ^ 2 - A ^ 2 - B ^ 2 ) / ( -2 * A * B ) = Cos( C )
-- Cos -1( C ) [a.k.a. math.acos in Lua] = ( C ^ 2 - A ^ 2 - B ^ 2 ) / ( -2 * A * B )
-- C = math.acos( ( A ^ 2 + B ^ 2 - C ^ 2 ) / ( 2 * A * B ) )
local function Distance( x1, y1, x2, y2 ) return math.sqrt( ( ( x2 - x1 ) ^ 2 + ( y2 - y1 ) ^ 2 ) ) end
local A = Distance( Bx, By, Ox, Oy )
local B = Distance( Ax, Ay, Ox, Oy )
local C = Distance( Ax, Ay, Bx, By )

return math.acos( ( A ^ 2 + B ^ 2 - C ^ 2 ) / ( 2 * A * B ) )
end
Edit: This will return the radians, not degrees.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
slime
Solid Snayke
Posts: 2954
Joined: Mon Aug 23, 2010 6:45 am
Contact:

mickeyjm wrote:I've been learning how to use opengl recently and I noticed that opengl rotates in degrees while love uses radians. Is there a reason that this is the case? Because if anything I would expect the hardware accelerated functions (i.e. opengl) to use radians, as they are more useful in mathematics, while the (for lack of a better word) "simpler" functions (i.e. love) to use degrees as they are what is taught first at school.
All the OpenGL functions which used degrees have been deprecated and removed over the years. The few non-deprecated functions which take angles use radians (e.g. sin/cos/etc. in GLSL.)

Functions in computers (including Lua's math library: math.sin, math.cos, math.atan2, etc.) almost always deal in radians. Lua also includes the math.rad and math.deg functions for quick conversions.
Since functions in Lua's standard library deal in radians, it makes even more sense for LÖVE's functions to do the same.
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

davisdude wrote:As in A and B being the points, and O being the connecting point?

Code: Select all

function GetAngle( Ax, Ay, Ox, Oy, Bx, By )
-- Using law of Cosines: C ^ 2 = A ^ 2 + B ^ 2 - 2 * A * B * Cos( C )
-- C ^ 2 - A ^ 2 - B ^ 2 = -2 * A * B * Cos( C )
-- ( C ^ 2 - A ^ 2 - B ^ 2 ) / ( -2 * A * B ) = Cos( C )
-- Cos -1( C ) [a.k.a. math.acos in Lua] = ( C ^ 2 - A ^ 2 - B ^ 2 ) / ( -2 * A * B )
-- C = math.acos( ( A ^ 2 + B ^ 2 - C ^ 2 ) / ( 2 * A * B ) )
local function Distance( x1, y1, x2, y2 ) return math.sqrt( ( ( x2 - x1 ) ^ 2 + ( y2 - y1 ) ^ 2 ) ) end
local A = Distance( Bx, By, Ox, Oy )
local B = Distance( Ax, Ay, Ox, Oy )
local C = Distance( Ax, Ay, Bx, By )

return math.acos( ( A ^ 2 + B ^ 2 - C ^ 2 ) / ( 2 * A * B ) )
end
Edit: This will return the radians, not degrees.
Thank you so much, by looking at your code I found out that I was using the wrong cos function, I wrote cosh instead of acos.
Thanks again LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

No problem. GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

How would I go about making a directory in 'Documents' ? I'm on Windows, of course.
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact: