This did it, thank you.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 withand it should work from then on.Code: Select all
require "love.filesystem"
"Questions that don't deserve their own thread" thread
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: "Questions that don't deserve their own thread" thread
Re: "Questions that don't deserve their own thread" thread
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...
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: "Questions that don't deserve their own thread" thread
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
Re: "Questions that don't deserve their own thread" thread
How can I find the angle of AOB, O being the vertex ?
I searched and found this:
and
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.
I searched and found this:
Code: Select all
math.cosh(dot(toVect(O,B),toVect(O,A))
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)))
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
As in A and B being the points, and O being the connecting point?
Edit: This will return the radians, not degrees.
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
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: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: "Questions that don't deserve their own thread" thread
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.)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.
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
Re: "Questions that don't deserve their own thread" thread
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.davisdude wrote:As in A and B being the points, and O being the connecting point?Edit: This will return the radians, not degrees.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
Thanks again
Re: "Questions that don't deserve their own thread" thread
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
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: "Questions that don't deserve their own thread" thread
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
The only place where you are allowed to write is %appdata%/yourgame.Whatthefuck wrote:How would I go about making a directory in 'Documents' ? I'm on Windows, of course.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests