Commit Graph

38 Commits

Author SHA1 Message Date
Alex Szpakowski 3120a0e650 Goodbye 2013, hello 2014! 2014-01-03 17:28:58 -04:00
Alex Szpakowski 2ee869b0e8 Fixed some compiler warnings 2013-12-07 05:07:54 -04:00
Alex Szpakowski 1c8abc74aa Renamed love.math.g/setRandomState and rng:g/setState to love.math.g/setRandomSeed and rng:g/setSeed.
getRandomSeed now always returns the previously set random seed instead of the current (implementation-dependent) random state.
2013-12-01 21:25:27 -04:00
Alex Szpakowski cded0e4a3b Fixed a typo when love.math.triangulate errors 2013-11-05 15:17:54 -04:00
Alex Szpakowski 83d3eae1e7 Fixed error messages in Shader:send and love.math.newRandomGenerator to include the line number 2013-11-04 15:03:45 -04:00
Alex Szpakowski e2eb99a6af Added BezierCurve:getControlPointCount (resolves issue #759) 2013-10-11 02:53:53 -03:00
Alex Szpakowski bcee9a222b Made some float/int/unsigned char conversions explicit, fixed ParticleSystem:getColors, fixed love.mouse.isDown with x1 and x2 buttons 2013-09-26 00:36:50 -03:00
Alex Szpakowski 5de43a7207 The Vertex struct is now recognized as POD by C++, also fixed the name to be consistent with other love structs 2013-09-24 11:09:18 -03:00
Alex Szpakowski 8d5ddb9e34 Fixed some internal documentation (thanks to clang's -Wdocumentation) 2013-09-23 21:52:28 -03:00
Alex Szpakowski 06f2ec8e31 Renamed BezierCurve:eval to BezierCurve:evaluate (resolves issue #722) 2013-09-23 20:40:58 -03:00
Alex Szpakowski ffe0485173 Removed love.window.checkMode (resolves issue #653, invalidates issue #592).
Also fixed love.window.setMode to fail instead of bug out when trying to set a fullscreen mode which is too large for the monitor.
2013-09-19 18:13:52 -03:00
Alex Szpakowski 06f80d5c08 Fixed undefined behaviour when love exceptions are converted into Lua errors (resolves issue #729) 2013-09-05 23:17:29 -03:00
vrld 6b51c5aadc Fix issue #724: Bezier curve rendering/eval crashes with empty curves. 2013-08-29 08:31:58 +02:00
Alex Szpakowski ec9dec6b80 Replaced luax_newtype with luax_pushtype (and added luax_rawnewtype for the old functionality of luax_newtype.)
luax_pushtype keeps the object in a weak table and checks the table before creating a new userdata, so it re-uses the object's existing wrapper userdata if it can, whenever the object is pushed to Lua.

This fixes some subtle issues with love objects, where using them as keys in tables would not always work as expected (https://love2d.org/forums/viewtopic.php?f=4&t=39398&p=112388#p112415). It also decreases the amount of new Lua objects created, saving the garbage collector some work.
2013-08-29 00:40:06 -03:00
Alex Szpakowski 1375aaccb5 Renamed BezierCurve:move to BezierCurve:translate (resolves issue #723) 2013-08-28 19:10:18 -03:00
vrld 983496238f [BezierCurve] Add getDerivative(), move(), rotate() and scale(). 2013-08-21 21:44:31 +02:00
Alex Szpakowski 5c0066332f love.math.noise now returns values in the range of [0, 1] instead of [-1, 1] 2013-08-19 19:57:55 -03:00
Alex Szpakowski 50504d83a5 Missed an uncaught exception in newRandomGenerator
--HG--
branch : RandomGenerator-2
2013-08-04 17:20:14 -03:00
Alex Szpakowski 674ad9247a Added some checks for invalid numbers to love.math.setRandomState
--HG--
branch : RandomGenerator-2
2013-08-04 17:04:52 -03:00
Alex Szpakowski 0447d1e7c5 Changed love.math.randomnormal([mean], stddev) to love.math.randomNormal(stddev, [mean]);
Changed love.math.randomseed(seed) to love.math.setRandomState(state) and love.math.setRandomState(low, high). Added low, high = love.math.getRandomState().

love.math.setRandomState(state) can set the random state to an integer of up to 53 bits, love.math.setRandomState(low, high) can set the random state to a 64 bit integer by using the first argument as the lower 32 bits and the second argument as the higher 32 bits.
This allows for reliable setting and saving of the state of a RNG.

--HG--
branch : RandomGenerator-2
2013-08-01 18:32:44 -03:00
Alex Szpakowski 04ca33d127 Updated Xcode project with new bezier files 2013-05-12 17:04:56 -03:00
vrld aa4d96317f [bezier curve] add missing files 2013-05-12 22:01:12 +02:00
vrld 19eade843c Add support for Bezier curves of arbitrary degree.
New functions:

bezier = love.math.newBezierCurve(control-points)
degree = bezier:getDegree() -- degree = #control-points - 1
x,y = bezier:getControlPoint(pos) -- pos < 0 => string.sub semantics
bezier:setControlPoint(pos, x, y) -- pos < 0 => string.sub semantics
bezier:insertControlPoint(x,y, [pos = -1])
x,y = bezier:eval(t) -- 0 <= t <= 1
polyline = bezier:render([accuracy = 5]) -- returns a table of points

Example:

function love.load()
	b = love.math.newBezierCurve(10,10, 80,400, 380,400, 470,10)
end

function love.draw()
	if not curve then -- curve rendering is expensive-ish
		curve = b:render()
	end
	love.graphics.line(curve)
end
2013-05-12 21:57:06 +02:00
vrld d454be7025 Add love.math.isConvex()
Checks whether a given polygon is convex or not.
2013-05-12 13:00:08 +02:00
Alex Szpakowski 7ab3809165 Fixed Object:typeOf for love.physics objects new to 0.8.0, removed vestigial ColorMode code 2013-05-07 15:23:26 -03:00
Alex Szpakowski 63404f7097 Added love.graphics.getRendererInfo(infotype). Useful for creating more informative error reports and advanced debugging.
Returned string can be highly system-dependent, so don't rely on its output!

infotype can be "name", "version", "vendor", or "device"
2013-05-05 16:47:42 -03:00
Alex Szpakowski 3bf43dadd8 Renamed CompressedData:getNumMipmaps to CompressedData:getMipmapCount; Improved type-checking error messages for some functions which expect function arguments 2013-05-02 17:26:50 -04:00
Alex Szpakowski f8c7e2cab8 Code cleanup 2013-05-01 23:18:25 -07:00
Alex Szpakowski 9ccf013570 Added love.math.noise(x, [y, z, w]). Calculates the 1D, 2D, 3D or 4D Simplex noise value at a particular coordinate 2013-05-01 18:26:40 -07:00
vrld 71317c4359 Add Geometries (replaces Quads).
A Geometry is a collection of vertices describing a non self-intersecting
(simple) polygon. In addition to screen coordinates, the vertices have
attributes for texture coordinates (s,t) and color (r,g,b,a).

It can be used as a quad, to display distorted images, or anything in between.

Added:
^^^^^^

-- geometry from table, where table has the format:
-- info = {
-- {x,y, s,t, [r = 255, g = 255, b = 255, a = 255]}
-- {x,y, s,t, [r = 255, g = 255, b = 255, a = 255]}
-- ...
-- }
geom = love.graphics.newGeometry(info)

-- convenience wrapper for quads (same as before)
geom = love.graphics.newQuad(x,y, w,h, sw,sh)

-- retrieve vertex i (1-indexed)
x,y,s,t,r,g,b,a = geom:getVertex(i)

-- set vertex i (1-indexed)
geom:setVertex(i, x,y, s,t, [r,g,b,a])

-- flip geometry
geom:flip(x, y)


Renamed:
^^^^^^^^

love.graphics.drawq() -> love.graphics.drawg()


Removed:
^^^^^^^^

quad:setViewport()
quad:getViewport()
2013-04-21 18:53:13 +02:00
Alex Szpakowski bf6d1c258b Misc. code cosmetics and improvements 2013-04-18 02:14:35 -03:00
Alex Szpakowski d98e2cb40c Renamed randnormal to randomnormal
--HG--
branch : math-randobject
2013-04-15 14:57:20 -03:00
Alex Szpakowski 3046981fce Added love.math.newRandomGenerator. Returns a RNG object with its own seed and random methods.
--HG--
branch : math-randobject
2013-04-14 23:02:44 -03:00
vrld db86fa4b83 Make love.math.triangulate with any polygon winding order. 2013-03-14 17:21:13 +01:00
vrld 1a407a6af3 Make non-gcc compilers happy... 2013-03-13 23:09:25 +01:00
vrld ece4ff6472 Make love.math a singleton. Remove code duplication. Add love.math.triangulate.
love::math::Math is now a singleton, so other modules can use it via
love::math::Math::instance.


Removed duplicate implementations of various rng helper functions.
ParticleSystem now uses love::math::Math's RNG.


New function: love.math.triangulate(vertices)

Accepts a table or list of x/y coordinate pairs and returns a table of tables.
The inner tables are the triangles the polygon is composed of.

Works on all *simple* polygons, i.e. a closed chain of vertices that does not
intersect itself. Attempting to triangulate non-simple polygons is undefined
behavior - in the best case it throws an error, in the worst case it returns
an invalid triangulation.

Polygons must be ordered in *clockwise order* with respect to the love
coordinate system. Attempting to triangulate a ccw polygon will throw an
error.

Examples:

  triangles = love.math.triangulate(0,0, 1,1, 2,0, 2,2, 0,2)
  triangles == {
      {1,1, 2,0, 2,2},
      {1,1, 2,2, 0,2},
      {1,1, 0,2, 0,0},
  }

  triangles = love.math.triangulate({0,0, 1,1, 2,0, 2,2, 0,2})
  -- same as above

  triangles = love.math.triangulate(0,2, 2,2, 2,0, 1,1, 0,0)
  -- error - polygons is in counterclockwise order

  triangles = love.math.triangulate(0,0, 1,3, 2,0, 2,2, 0,2)
  -- undefined behavior - polygon intersects itself (because of edge 1,3)
2013-03-13 20:48:39 +01:00
vrld 4b8c6d236d Rename Math.{cpp,h} to ModMath.{cpp,h}.
Compilers can get confused and include Math.h and math.h (included by cmath).
2013-02-26 10:43:03 +01:00
vrld 5f586390d8 Add module love.math. Implements xorshift RNG.
Contains just a RNG for now, but may include other functionality (e.g.
transforms) later on.

New Functions:

-- as in the lua math library:
love.math.randomseed(number) -- set random seed
love.math.random()           -- get random number in [0:1) (uniformly distributed)
love.math.random(high)       -- get integer random number in [1:high]
love.math.random(low, high)  -- get integer random number in [low:high]

-- additional functions
love.math.randnormal()     -- get normally distributed number with zero mean
                           -- and unit variance
love.math.randnormal(o)    -- get normally distributed number with zero mean
                           -- and standard deviation `o`
love.math.randnormal(m, o) -- get normally distributed number with mean `m`
                           -- and standard deviation `o`
2013-02-25 18:32:54 +01:00