Exemple #1
0
func getLookAtMatrix() gls.Mat4 {
	lookDir := latpt.Copy()
	lookDir.Minus(getCamPos())
	lookDir.Normalize()
	updir.Normalize()

	rightDir := gls.Cross(lookDir, updir)
	rightDir.Normalize()
	perpUpDir := gls.Cross(rightDir, lookDir)

	rotMat := gls.Identity()
	rotMat.SetCol(0, gls.NewVec4(rightDir, 0))
	rotMat.SetCol(1, gls.NewVec4(perpUpDir, 0))
	rotMat.SetCol(2, gls.NewVec4(lookDir.Neg(), 0))

	/*log.Println("updir: ", updir)
	log.Println("rightdir: ", rightDir)
	log.Println("perpupdir: ",perpUpDir)
	log.Println("lookdir: ", lookDir)
	log.Println(rotMat)
	*/
	rotMat.Transpose()
	//log.Println(rotMat)

	transMat := gls.Identity()
	camPos := getCamPos()
	transMat.SetCol(3, gls.NewVec4(camPos.Neg(), 1))
	//log.Println(transMat)
	if true {
		return rotMat.Times(transMat)
	}
	//transMat = gls.Identity()
	return transMat

}
Exemple #2
0
Fichier : main.go Projet : vron/fm
func display() {
	gl.ClearColor(0.19, 0.19, 0.21, 0)
	gl.ClearDepth(1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(theProgram)

	// Temporarily set the cam t clip
	id := gls.Identity()

	trans := getLookAtMatrix()
	//	log.Println(trans)
	gls.UniformMatrix4fv(wtcm_unif, 1, false, trans)

	gls.UniformMatrix4fv(mtwm_unif, 1, false, id)

	// And here we do the actual rendering

	// Generate a name for vufferobj and store it
	gl.GenBuffers(1, &positionBufferObject)
	// Bind it to a target
	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)

	// Conver all nodes to a long array of vertexes!
	i := 0
	// TODO: Fix this, based on 4 per eleemnts
	vpos := make([]float32, len(elements)*4*4)
	elms := make(map[uint32]mS, len(elements))
	// Note that the order here is undefined!
	ii := 0
	for k, v := range elements {
		elms[k] = mS{ii, len(v.Nodes())}
		for _, vv := range v.Nodes() {
			ii++
			vpos[i] = float32(nodes[vv][0])
			i++
			vpos[i] = float32(nodes[vv][1])
			i++
			vpos[i] = float32(nodes[vv][2])
			i++
			vpos[i] = 1.0
			i++
		}
	}
	/*
		for _, v := range nodes {
			vpos[i] = float32(v[0])
			i++
			vpos[i] = float32(v[1])
			i++
			vpos[i] = float32(v[2])
			i++
		}
	*/
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(32/8*len(vpos)), (gl.Pointer)(&vpos[0]), gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)
	gl.EnableVertexAttribArray(0)
	gl.VertexAttribPointer(0, 4, gl.FLOAT, gl.FALSE, 0, (gl.Pointer)(nil))

	/*	for _,v := range elms {

		}
	*/
	for _, v := range elms {
		gl.DrawArrays(gl.LINE_LOOP, gl.Int(v.Start), gl.Sizei(v.Length))
	}

	// Draw Coordinate acis
	/*for i := 9; i < 9+2*5; i += 2 {
		gl.DrawArrays(gl.LINE_STRIP, gl.Int(i), 2)
	}*/
}