summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-31 14:28:13 -0500
committersanine-a <sanine.not@pm.me>2020-10-31 14:28:13 -0500
commit3dca6a336c9fd54b0847249b5771d39141daa3ae (patch)
tree4e237b47352189504a070350776caecb8d126788 /demo
parent50d8b05f588d019a8a5ae1a76d22677b10553167 (diff)
fix bug in FPS camera update()
Diffstat (limited to 'demo')
-rw-r--r--demo/FPSCamera.lua2
-rw-r--r--demo/checkerboard.pngbin0 -> 55549 bytes
-rw-r--r--demo/main.lua36
3 files changed, 32 insertions, 6 deletions
diff --git a/demo/FPSCamera.lua b/demo/FPSCamera.lua
index 7182638..7ee3cf8 100644
--- a/demo/FPSCamera.lua
+++ b/demo/FPSCamera.lua
@@ -22,8 +22,8 @@ camera.projection = Matrix.Mat4.perspective(math.rad(90),
function camera:update(dt)
local M = Matrix.Mat4.eye()
- M:rotate(Vector.Vec3.ZERO, self.basis.x, math.rad(self.pitch))
M:rotate(Vector.Vec3.ZERO, Vector.Vec3.Y_UNIT, math.rad(self.yaw))
+ M:rotate(Vector.Vec3.ZERO, Vector.Vec3.X_UNIT, math.rad(self.pitch))
self.basis = M:basis()
movement = Vector.Vec3.new()
diff --git a/demo/checkerboard.png b/demo/checkerboard.png
new file mode 100644
index 0000000..73a239d
--- /dev/null
+++ b/demo/checkerboard.png
Binary files differ
diff --git a/demo/main.lua b/demo/main.lua
index 81f7354..9ca08be 100644
--- a/demo/main.lua
+++ b/demo/main.lua
@@ -1,30 +1,57 @@
local Vector = require('Vector')
local Matrix = require('Matrix')
local FPSCamera = require('FPSCamera')
+FPSCamera.movement_speed = 5
local model = Matrix.Mat4.eye()
+model:rotate(Vector.Vec3.ZERO, Vector.Vec3.Y_UNIT, math.pi)
+model:translate(Vector.Vec3.new{0,0,-2})
+print(model)
honey.input.key.bind(honey.input.key.escape, honey.exit)
+local tex = honey.texture.new()
+honey.texture.load(tex, 'checkerboard.png', false)
+honey.texture.use(tex, 0)
+
local vertex_shader = [[
#version 330 core
layout(location = 0) in vec3 position;
+layout(location = 1) in vec3 normal;
+layout(location = 2) in vec2 uv;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
+out vec3 Position;
+out vec3 Normal;
+out vec2 UV;
+
void main()
{
- gl_Position = projection * view * vec4(position.xyz, 1);
+ gl_Position = projection * view * model * vec4(position.xyz, 1);
+ Position = gl_Position.xyz;
+ Normal = normal;
+ UV = uv;
} ]]
local fragment_shader = [[
#version 330 core
-uniform vec4 base_color;
+
+in vec3 Position;
+in vec3 Normal;
+in vec2 UV;
+
+uniform float time;
+uniform sampler2D tex;
out vec4 color;
-void main() { color = base_color; } ]]
+
+void main() {
+ vec2 texture_coords = UV + (0.01 * time * vec2(1,1));
+ color = vec4(texture(tex, texture_coords).xyz, 1);
+} ]]
local shader = honey.shader.new(vertex_shader, fragment_shader)
local plane = honey.mesh.load('Suzanne.obj')[1]
@@ -37,7 +64,6 @@ local total_time = 0
function honey.update(dt)
total_time = total_time + dt
- color1:lerp(color2, 0.5*(math.sin(math.pi*total_time)+1), color)
FPSCamera:update(dt)
end
@@ -46,6 +72,6 @@ function honey.draw()
honey.shader.set_mat4(shader, 'model', model.array)
honey.shader.set_mat4(shader, 'view', FPSCamera.view.array)
honey.shader.set_mat4(shader, 'projection', FPSCamera.projection.array)
- honey.shader.set_vec4(shader, "base_color", color.array)
+ honey.shader.set_float(shader, 'time', total_time)
honey.mesh.draw(plane, shader)
end