Example #1
0
func (d *DrawImage) rebuildModel(display *Display) {
	if len(d.vertex) != 2 {
		d.vertex = make([][]float32, 2)
		d.uv = make([][]float32, 2)
	}

	modelM := glm.NewIdentityMatrix4()
	d.mvp = display.vp.Mul(modelM)

	d.vertex[0] = scale(10, []float32{
		-1, -1, 0,
		-1, 1, 0,
		1, 1, 0,
	})
	d.uv[0] = []float32{
		1, 0.5,
		1, 0.5,
		1, 0.5,
	}

	d.vertex[1] = scale(10, []float32{
		1, 1, 0,
		1, -1, 0,
		-1, -1, 0,
	})
	d.uv[1] = []float32{
		1, 0.5,
		1, 0.5,
		1, 0.5,
	}
}
Example #2
0
File: main.go Project: andrebq/exp
func prepareModelViewProjection(width, height float32) *glm.Matrix4 {
	modelM := glm.NewIdentityMatrix4()
	// this is just 2d, so ignore the camera matrix
	// camera at 0,0,1 (could be anything > 0 )
	// looking at 0,0,0
	// with the +Y is the Up vector
	//
	// could be replaced by a Identity matrix, but keeping this here
	// since it make easier to turn the world upside down
	viewM := glm.NewLookAtMatrix4(
		glm.Vector3{0, 0, 1},
		glm.Vector3{0, 0, 0},
		glm.Vector3{0, -1, 0})

	// in order to keep things simple,
	// the 2d projection uses the center of screen as the point 0,0
	// ie, the (top,left) == (-width/2, heiht/2)
	projection := glm.NewOrthoMatrix4(-width/2, width/2, -height/2, height/2, 0, 100)

	return projection.Mul(viewM).Mul(modelM)
}