Page 5 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Jul 19, 2014 9:16 am
by lumlune
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Jul 19, 2014 10:43 am
by mickeyjm
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Tue Jul 22, 2014 11:35 am
by Whatthefuck
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Tue Jul 22, 2014 10:54 pm
by Ranguna259
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Wed Jul 23, 2014 1:12 am
by davisdude
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Wed Jul 23, 2014 1:39 am
by slime
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.

Re: "Questions that don't deserve their own thread" thread

Posted: Wed Jul 23, 2014 2:14 am
by Ranguna259
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 :D

Re: "Questions that don't deserve their own thread" thread

Posted: Wed Jul 23, 2014 2:35 am
by davisdude
No problem. :D

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Aug 01, 2014 9:42 pm
by Whatthefuck
How would I go about making a directory in 'Documents' ? I'm on Windows, of course.

Re: "Questions that don't deserve their own thread" thread

Posted: Fri Aug 01, 2014 10:18 pm
by undef
Whatthefuck wrote:How would I go about making a directory in 'Documents' ? I'm on Windows, of course.
The only place where you are allowed to write is %appdata%/yourgame.