Example #1
0
func initScene() {
	halfW, halfH := float32(Width)*0.5, float32(Height)*0.5

	Projection = mgl.Ortho2D(-halfW, halfW, -halfH, halfH).Mul4(
		mgl.Translate3D(-halfW, -halfH, 0))

	ModelView = mgl.Ident4f().Mul4(mgl.Scale3D(100, 100, 0))
	MVP <- Projection.Mul4(ModelView)

	gl.Disable(gl.DEPTH_TEST)
	gl.DepthMask(false)

	program := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(uint(program))
	uMVP = gl.GetUniformLocation(program, "uMVP")
	attrPos = gl.GetAttribLocation(program, "pos")
	attrColor = gl.GetAttribLocation(program, "color")

	gl.EnableVertexAttribArray(uint(attrPos))
	gl.EnableVertexAttribArray(uint(attrColor))
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.VertexAttribPointer(uint(attrPos), 2, gl.FLOAT, false, 0, uintptr(gl.Void(&POSITION[0])))
	gl.VertexAttribPointer(uint(attrColor), 4, gl.FLOAT, false, 0, uintptr(gl.Void(&COLOR[0])))

}
Example #2
0
func reshape(w *glfw.Window, width, height int) {
	gl.Viewport(0, 0, width, height)
	halfW, halfH := float32(width)*0.5, float32(height)*0.5
	Projection = mgl.Ortho2D(-halfW, halfW, -halfH, halfH).Mul4(
		mgl.Translate3D(-halfW, -halfH, 0))

	go func(m mgl.Mat4f) { MVP <- m }(Projection.Mul4(ModelView))
}
Example #3
0
func keyEvent(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
	switch key {
	case glfw.KeyEscape:
		w.SetShouldClose(true)
	case glfw.KeyLeft:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(-0.1, 0, 0))
		}
	case glfw.KeyRight:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DY(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0.1, 0, 0))
		}
	case glfw.KeyUp:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, 0.1, 0))
		}
	case glfw.KeyDown:
		if mods == glfw.ModShift {
			ModelView = ModelView.Mul4(mgl.HomogRotate3DX(-5))
		} else {
			ModelView = ModelView.Mul4(mgl.Translate3D(0, -0.1, 0))
		}
	case glfw.KeyMinus:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, -0.1))
	case glfw.KeyEqual:
		ModelView = ModelView.Mul4(mgl.Translate3D(0, 0, 0.1))
	}
	go func(m mgl.Mat4f) { MVP <- m }(Projection.Mul4(ModelView))

}
Example #4
0
func (w *World) SetCamera(x, y, z float32) {
	// set the view matrix
	// w.view = mathgl.LookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
	w.view = mathgl.Translate3D(-x, -y, -z)
}