Преглед изворни кода

rm more fenced codeblocks;

bjorn пре 2 година
родитељ
комит
7acaec8b9e
8 измењених фајлова са 180 додато и 272 уклоњено
  1. 11 23
      guides/3D_Models.md
  2. 12 16
      guides/Callbacks.md
  3. 52 66
      guides/Controllers.md
  4. 1 3
      guides/Game_Distribution.md
  5. 59 89
      guides/How_to_Lua.md
  6. 10 12
      guides/Introduction.md
  7. 22 38
      guides/Simple_Shapes.md
  8. 13 25
      guides/Sound.md

+ 11 - 23
guides/3D_Models.md

@@ -13,32 +13,24 @@ Create the Model
 To load a model into LÖVR, we can use the `lovr.graphics.newModel` function.  It takes a string with
 the name of the model file and returns an object representing the model.
 
-```
-model = lovr.graphics.newModel('assets/duck.dae')
-```
+    model = lovr.graphics.newModel('assets/duck.dae')
 
 Create the Texture
 ---
 
 Creating textures is really similar to creating models:
 
-```
-texture = lovr.graphics.newTexture('assets/duck.png')
-```
+    texture = lovr.graphics.newTexture('assets/duck.png')
 
 We can apply a texture to a model using `Model:setTexture`.  The colon syntax in Lua is used when
 you're calling a function on an object.
 
-```
-model:setTexture(texture)
-```
+    model:setTexture(texture)
 
 It is also possible to create and set the texture while creating the model, using the second
 parameter to `lovr.graphics.newModel`:
 
-```
-model = lovr.graphics.newModel('assets/duck.dae', 'assets/duck.png')
-```
+    model = lovr.graphics.newModel('assets/duck.dae', 'assets/duck.png')
 
 Rendering the Model
 ---
@@ -46,9 +38,7 @@ Rendering the Model
 To draw a model, call `:draw` on it.  It takes a position (x, y, z), a scale, and a rotation
 (angle/axis).
 
-```
-model:draw(x, y, z, size, angle, axisX, axisY, axisZ)
-```
+    model:draw(x, y, z, size, angle, axisX, axisY, axisZ)
 
 You may need to adjust the size/position of the model, depending on how it was exported.
 
@@ -57,15 +47,13 @@ Putting it all together
 
 Here's the complete program for loading and rendering a 3D model:
 
-```
-function lovr.load()
-  model = lovr.graphics.newModel('assets/model.obj', 'assets/texture.png')
-end
+    function lovr.load()
+      model = lovr.graphics.newModel('assets/model.obj', 'assets/texture.png')
+    end
 
-function lovr.draw()
-  model:draw(0, 0, 0, 1)
-end
-```
+    function lovr.draw()
+      model:draw(0, 0, 0, 1)
+    end
 
 The rotation parameters for `model:draw` were left out for simplicity.  The model and texture were
 put in a folder called `assets`.

+ 12 - 16
guides/Callbacks.md

@@ -52,19 +52,17 @@ the virtual world.  Usually we'll do things like draw 3D models or render visual
 
 Here's a simple example to help explain things better:
 
-```
-function lovr.load()
-  cubeSize = 0
-end
+    function lovr.load()
+      cubeSize = 0
+    end
 
-function lovr.update()
-  cubeSize = cubeSize + .0001
-end
+    function lovr.update()
+      cubeSize = cubeSize + .0001
+    end
 
-function lovr.draw()
-  lovr.graphics.cube('line', 0, 1, 0, size)
-end
-```
+    function lovr.draw()
+      lovr.graphics.cube('line', 0, 1, 0, size)
+    end
 
 This program will draw a cube in the middle of the play area, and make it get bigger and bigger over
 time.  In lovr.load we define a variable to keep track of the size of the cube.  In lovr.update we
@@ -87,11 +85,9 @@ can base the speed on real world time.  There is a single function parameter pas
 called `dt`, which stands for **delta time**.  It represents the amount of time that has passed
 since the last call to lovr.update.  Try changing the lovr.update function to this:
 
-```
-function lovr.update(dt)
-  cubeSize = cubeSize + dt * .5
-end
-```
+    function lovr.update(dt)
+      cubeSize = cubeSize + dt * .5
+    end
 
 How is this different?  Instead of adding .001 to the cube size every time lovr.update is called,
 we're basing that number on actual time values.  A computer that's only able to call lovr.update 10

+ 52 - 66
guides/Controllers.md

@@ -11,24 +11,20 @@ Discovering Controllers
 The VR functionality in LÖVR is all in the `lovr.headset` module.  To get the number of connected
 controllers, use `lovr.headset.getControllerCount`.
 
-```
-function lovr.load()
-  print(lovr.headset.getControllerCount())
-end
-```
+    function lovr.load()
+      print(lovr.headset.getControllerCount())
+    end
 
 There are two callbacks related to Controllers: `lovr.controlleradded` and `lovr.controllerremoved`.
 Using them, you can determine when controllers are connected and disconnected:
 
-```
-function lovr.controlleradded(controller)
-  print('Now there are ' .. lovr.headset.getControllerCount() .. ' controllers.')
-end
+    function lovr.controlleradded(controller)
+      print('Now there are ' .. lovr.headset.getControllerCount() .. ' controllers.')
+    end
 
-function lovr.controllerremoved(controller)
-  print('Now there are ' .. lovr.headset.getControllerCount() .. ' controllers.')
-end
-```
+    function lovr.controllerremoved(controller)
+      print('Now there are ' .. lovr.headset.getControllerCount() .. ' controllers.')
+    end
 
 Often, controllers need to be moved around a bit for them to be recognized, so make sure you add
 code in those callbacks to keep your list of controllers up to date.
@@ -41,12 +37,10 @@ Position and Orientation
 
 To retrieve the position of a controller, use `Controller:getPosition`:
 
-```
-controllers = lovr.headset.getControllers()
-for i, controller in ipairs(controllers) do
-  print(controller:getPosition())
-end
-```
+    controllers = lovr.headset.getControllers()
+    for i, controller in ipairs(controllers) do
+      print(controller:getPosition())
+    end
 
 The `ipairs` function returns an iterator that can be used in a `for` loop.  This lets you run a
 chunk of code on each item in a list.  Here, we're printing out the position of each controller.
@@ -55,14 +49,12 @@ Similarly, you can get the orientation of a controller (in angle-axis representa
 `Controller:getOrientation`.  We can combine these two functions to draw cubes at the position of
 the player's hands:
 
-```
-function lovr.draw()
-  controllers = lovr.headset.getControllers()
-  x, y, z = controller:getPosition()
-  angle, ax, ay, az = controller:getOrientation()
-  lovr.graphics.cube('line', x, y, z, .2, angle, ax, ay, az)
-end
-```
+    function lovr.draw()
+      controllers = lovr.headset.getControllers()
+      x, y, z = controller:getPosition()
+      angle, ax, ay, az = controller:getOrientation()
+      lovr.graphics.cube('line', x, y, z, .2, angle, ax, ay, az)
+    end
 
 Let's replace that cube with a realistic model of the controller.
 
@@ -74,44 +66,40 @@ automatically have a texture applied.  Drawing the model with the position and o
 controller object greatly increases the feeling of presence of an application.  Here's an example
 that keeps track of the list of controllers and draws their models:
 
-```
-function refreshControllers()
-  controllers = lovr.headset.getControllers()
-  controllerModels = {}
-  for i, controller in ipairs(controllers) do
-    controllerModels[i] = controller:newModel()
-  end
-end
-
-function lovr.load()
-  refreshControllers()
-end
-
-function lovr.controlleradded()
-  refreshControllers()
-end
-
-function lovr.controllerremoved()
-  refreshControllers()
-end
-
-function lovr.draw()
-  for i, controller in ipairs(controllers) do
-    x, y, z = controller:getPosition()
-    angle, ax, ay, az = controller:getOrientation()
-    controllerModels[i]:draw(x, y, z, 1, angle, ax, ay, az)
-  end
-end
-```
+    function refreshControllers()
+      controllers = lovr.headset.getControllers()
+      controllerModels = {}
+      for i, controller in ipairs(controllers) do
+        controllerModels[i] = controller:newModel()
+      end
+    end
+
+    function lovr.load()
+      refreshControllers()
+    end
+
+    function lovr.controlleradded()
+      refreshControllers()
+    end
+
+    function lovr.controllerremoved()
+      refreshControllers()
+    end
+
+    function lovr.draw()
+      for i, controller in ipairs(controllers) do
+        x, y, z = controller:getPosition()
+        angle, ax, ay, az = controller:getOrientation()
+        controllerModels[i]:draw(x, y, z, 1, angle, ax, ay, az)
+      end
+    end
 
 Controller Input
 ---
 
 To determine if a button on the controller is pressed, use `Controller:isDown`:
 
-```
-print(controller:isDown('menu'))
-```
+    print(controller:isDown('menu'))
 
 The first parameter is a string with the name of a button, which can be `system`, `menu`, `grip`,
 or `touchpad`.  The return value is a "boolean": either `true` or `false` depending on whether or
@@ -130,12 +118,10 @@ vibrate for, in seconds.  Currently, Vive controllers can only vibrate for durat
 seconds.  To create longer or stronger vibrations, call the function over a period of several
 frames.
 
-```
-function lovr.update(dt)
-  if controller:getAxis('trigger') == 1 then
-    controller:vibrate(.002)
-  end
-end
-```
+    function lovr.update(dt)
+      if controller:getAxis('trigger') == 1 then
+        controller:vibrate(.002)
+      end
+    end
 
 That's all for controllers.  The next guide is about <a data-key="Sound">Sound</a>.

+ 1 - 3
guides/Game_Distribution.md

@@ -24,9 +24,7 @@ file in the same folder as `lovr.exe`.  Next, press Windows + R and type `cmd.ex
 command prompt.  From there, type `cd C:\Users\Cena\Desktop\lovr`, or wherever the LÖVR folder is.
 Finally, use the following command to create the executable:
 
-```
-copy /b lovr.exe+MyGame.lovr MyGame.exe
-```
+    copy /b lovr.exe+MyGame.lovr MyGame.exe
 
 On unix systems, the `cat` utility can be used to concatenate the `lovr` file with `lovr.exe`.
 

+ 59 - 89
guides/How_to_Lua.md

@@ -20,23 +20,19 @@ Printing
 You can use `print` to print out numbers and text.  It doesn't print things out using your printer,
 but will "print" text to the output so you can see it.  Try it:
 
-```
-print('hey')
-print(5)
-```
+    print('hey')
+    print(5)
 
 Math
 ---
 
 Lua is really good at math.  You can use it like a basic calculator.  Try some of these examples:
 
-```
-print(5 + 5)
-print(3 - 2)
-print(2 * (7 - 8))
-print(1 + .5)
-print((2 ^ 5) - 16 / 3)
-```
+    print(5 + 5)
+    print(3 - 2)
+    print(2 * (7 - 8))
+    print(1 + .5)
+    print((2 ^ 5) - 16 / 3)
 
 Variables
 ---
@@ -44,46 +40,36 @@ Variables
 Variables are like little mailboxes that can hold things inside of them.  Each one has a name.  To
 make a variable we type its name, type an equals sign, and then type the value, like this:
 
-```
-a = 3
-b = 1
-```
+    a = 3
+    b = 1
 
 So now the variable named `a` holds the value 3 inside of it.  If we print out a variable, we see
 the value it contains, not its name:
 
-```
-print(a)
-print(b)
-print(a + b)
-```
+    print(a)
+    print(b)
+    print(a + b)
 
 The names of variable are _case sensitive_, so `a` and `A` are two different variables.  We change
 the value of a variable at any time, and even use other variables when we do it:
 
-```
-a = 3
-b = 1
-c = a + b
-b = 7
-print(a, b, c)
-```
+    a = 3
+    b = 1
+    c = a + b
+    b = 7
+    print(a, b, c)
 
 You can tell `print` to print multiple things using commas.  Pretty neato.  Variables can also hold
 strings, which is a fancy way of saying text.  To make a string, you just put some text inside
 quotes:
 
-```
-a = 'woah'
-print(a)
-```
+    a = 'woah'
+    print(a)
 
 Lua also lets you assign multiple variables at once:
 
-```
-a, b = 1, 2
-print(a, b)
-```
+    a, b = 1, 2
+    print(a, b)
 
 Functions
 ---
@@ -92,12 +78,10 @@ Functions let you wrap up a chunk of code and give it a name.  This can be usefu
 organized in a big file, or it can be useful to save typing if you want to do the same thing many
 times.  Let's write a function that adds one to a variable and then prints it:
 
-```
-function addOne()
-  a = a + 1
-  print(a)
-end
-```
+    function addOne()
+      a = a + 1
+      print(a)
+    end
 
 We typed `function` then typed the name of the function and put parentheses after it.  Then we
 wrote the code we want to run whenenver the function is run.  Finally, we typed `end` to tell Lua
@@ -107,33 +91,29 @@ If you run this code, you'll notice that nothing gets printed out!  This is beca
 function does not actually run it.  To run a function you type the name of the function followed
 by parentheses:
 
-```
-function addOne()
-  a = a + 1
-  print(a)
-end
+    function addOne()
+      a = a + 1
+      print(a)
+    end
 
-a = 0
-addOne()
-addOne()
-addOne()
-addOne()
-addOne()
-```
+    a = 0
+    addOne()
+    addOne()
+    addOne()
+    addOne()
+    addOne()
 
 There we go.  Now our function is getting "called" and the code inside it is getting run!
 
 We can also give a function inputs.  To do that we just add variable names into the function
 definition:
 
-```
-function sayHello(name)
-  print('hello', name)
-end
+    function sayHello(name)
+      print('hello', name)
+    end
 
-sayHello('adele')
-sayHello('yall')
-```
+    sayHello('adele')
+    sayHello('yall')
 
 Because we put the `name` variable in parentheses, the code in the `sayHello` function can now use
 the `name` variable.  Note that `name` is a temporary variable that can only be used inside the
@@ -142,13 +122,11 @@ function.
 A function can also output values using `return`.  This can be used to put the result of a function
 in a variable.  Here's an example:
 
-```
-function double(number)
-  return number * 2
-end
+    function double(number)
+      return number * 2
+    end
 
-print(double(10))
-```
+    print(double(10))
 
 We don't have to put the result into a variable though, we can directly print it out.  In this
 example, the output of `double` is used as the input of `print`.
@@ -160,10 +138,8 @@ In Lua, you can write a _comment_ by using `--`.  If you put a comment, then the
 will be ignored.  It's a useful tool that lets you write explanations for your code so you can
 remember what's going on:
 
-```
--- This variable contains my favorite color
-color = 'purple'
-```
+    -- This variable contains my favorite color
+    color = 'purple'
 
 Nil
 ---
@@ -179,33 +155,27 @@ Lastly, here are a few features of Lua called "control flow".  Normally lines of
 order, one after another, but control flow lets you change that.  For example, then `if` statement
 let you conditinally run lines of code:
 
-```
-if 5 > 3 then
-  print('ok cool five is greater than three')
-else
-  print('wait what')
-end
-```
+    if 5 > 3 then
+      print('ok cool five is greater than three')
+    else
+      print('wait what')
+    end
 
 The `while` statement lets you run a segment of code over and over again until some condition is
 met:
 
-```
-i = 0
-while i < 5 do
-  i = i + 1
-  print(i)
-end
-```
+    i = 0
+    while i < 5 do
+      i = i + 1
+      print(i)
+    end
 
 Finally, the `for` statement is similar to `while`, but is a little more concise if you want to run
 a piece of code a certain number of times:
 
-```
-for i = 1, 5 do
-  print(i)
-end
-```
+    for i = 1, 5 do
+      print(i)
+    end
 
 It automatically does the `i = i + 1` and the `i < 5` part from the previous example.
 

+ 10 - 12
guides/Introduction.md

@@ -24,18 +24,16 @@ Example
 What does LÖVR look like?  Here's a simple example that draws a cube at the position of each
 motion controller:
 
-```
-function lovr.load()
-  controllers = lovr.headset.getControllers()
-end
-
-function lovr.draw()
-  for i, controller in pairs(controllers) do
-    local x, y, z = controller:getPosition()
-    lovr.graphics.cube('line', x, y, z, .2, controller:getOrientation())
-  end
-end
-```
+    function lovr.load()
+      controllers = lovr.headset.getControllers()
+    end
+
+    function lovr.draw()
+      for i, controller in pairs(controllers) do
+        local x, y, z = controller:getPosition()
+        lovr.graphics.cube('line', x, y, z, .2, controller:getOrientation())
+      end
+    end
 
 Onward!
 ---

+ 22 - 38
guides/Simple_Shapes.md

@@ -16,48 +16,38 @@ darkish blue.  Note that the color will remain active until it's changed again.
 Points
 ---
 
-```
-lovr.graphics.points(x, y, z)
-```
+    lovr.graphics.points(x, y, z)
 
 This draws a single point at an x, y, z position in 3D space.  If you try it out and draw a point at
 `(0, 0, 0)`, the point will be **really** hard to see because it's only 1 pixel big!  To change
 this, have a look at the `lovr.graphics.setPointSize` function.  You can also draw more than one
 point by passing in more point coordinates after the first.  Finally, you can also pass in a table:
 
-```
-local points = {
-  0, 0, 0,
-  1, 1, 1
-}
+    local points = {
+      0, 0, 0,
+      1, 1, 1
+    }
 
-lovr.graphics.points(points)
-```
+    lovr.graphics.points(points)
 
 Lines
 ---
 
-```
-lovr.graphics.line(x1, y1, z1, x2, y2, z2, ...)
-```
+    lovr.graphics.line(x1, y1, z1, x2, y2, z2, ...)
 
 This function draws lines between points.  Here's how you would draw a square on the floor:
 
-```
-lovr.graphics.line(
-  -1, 0, -1,
-  -1, 0,  1,
-   1, 0,  1,
-   1, 0, -1
-)
-```
+    lovr.graphics.line(
+      -1, 0, -1,
+      -1, 0,  1,
+       1, 0,  1,
+       1, 0, -1
+    )
 
 Triangles
 ---
 
-```
-lovr.graphics.triangle(mode, x1, y1, z1, x2, y2, z2, x3, y3, z3)
-```
+    lovr.graphics.triangle(mode, x1, y1, z1, x2, y2, z2, x3, y3, z3)
 
 This function draws a triangle from the specified 3 points.  `mode` can either be `line` for a
 wireframe triangle or `fill` for a solid triangle.
@@ -67,9 +57,7 @@ Planes
 
 A plane is a flat rectangle.  They can be used for simple floors and walls.
 
-```
-lovr.graphics.plane(mode, x, y, z, size, nx, ny, nz)
-```
+    lovr.graphics.plane(mode, x, y, z, size, nx, ny, nz)
 
 This draws a plane `size` meters big centered at `(x, y, z)`.  To control the direction the plane
 is facing, you gotta specify a _normal_ vector.  The normal vector is a direction specified using
@@ -82,9 +70,7 @@ Cubes
 
 Finally, cubes, the pinnacle of primitives.
 
-```
-lovr.graphics.cube(mode, x, y, z, size, angle, ax, ay, az)
-```
+    lovr.graphics.cube(mode, x, y, z, size, angle, ax, ay, az)
 
 This function draws a cube.  You can draw it as a wireframe or as a filled cube using the `mode`
 parameter, similar to triangles and planes.  The `x`, `y`, and `z` parameters control the position.
@@ -100,15 +86,13 @@ Bonus!!
 Planes and cubes can have **textures** applied to them.  Here's how you would draw a plane on the
 ground with a ground texture applied to it:
 
-```
-function lovr.load()
-  texture = lovr.graphics.newTexture('ground.png')
-end
+    function lovr.load()
+      texture = lovr.graphics.newTexture('ground.png')
+    end
 
-function lovr.draw()
-  lovr.graphics.plane(texture, 0, 0, 0, 2, 0, 1, 0)
-end
-```
+    function lovr.draw()
+      lovr.graphics.plane(texture, 0, 0, 0, 2, 0, 1, 0)
+    end
 
 For this to work, put an image named `ground.png` in the same folder that `main.lua` is in.
 

+ 13 - 25
guides/Sound.md

@@ -11,40 +11,30 @@ Sound functionality can be accessed via the `lovr.audio` module.  To play a soun
 create a `Source` object by calling `lovr.audio.newSource`.  Currently, only `.ogg` files are
 supported.
 
-```
-source = lovr.audio.newSource('airhorn.ogg')
-```
+    source = lovr.audio.newSource('airhorn.ogg')
 
 Once the source is created, you can call a few functions on the source to control its playback:
 
-```
-source:play()   -- Play the source
-source:pause()  -- Pause the source
-source:resume() -- Resume a paused source
-source:rewind() -- Rewind a source, playing it from the beginning
-source:stop()   -- Stop a source
-```
+    source:play()   -- Play the source
+    source:pause()  -- Pause the source
+    source:resume() -- Resume a paused source
+    source:rewind() -- Rewind a source, playing it from the beginning
+    source:stop()   -- Stop a source
 
 You can also get whether or not a source is in a particular state:
 
-```
-source:isPlaying()
-source:isPaused()
-source:isStopped()
-```
+    source:isPlaying()
+    source:isPaused()
+    source:isStopped()
 
 You can set the volume and pitch of a source (even while it's playing):
 
-```
-source:setVolume(.5) -- Volume can be between 0 and 1
-source:setPitch(2)   -- The default pitch is 1
-```
+    source:setVolume(.5) -- Volume can be between 0 and 1
+    source:setPitch(2)   -- The default pitch is 1
 
 Finally, you can control whether or not a source loops, which can be useful for background music:
 
-```
-source:setLooping(loop) -- true or false
-```
+    source:setLooping(loop) -- true or false
 
 Spatial Audio
 ---
@@ -53,9 +43,7 @@ LÖVR supports spatial audio, which means that sounds can be positioned in 3D sp
 positioned, they will be slightly distorted to make it sound as if they are coming from their
 location in the virtual world!  To position a source, use `Source:setPosition`:
 
-```
-source:setPosition(1.3, 2, -4.2)
-```
+    source:setPosition(1.3, 2, -4.2)
 
 Note that only mono sounds can be spatialized in this way.