Esempio n. 1
0
func (r *Receiver) Init(window *glfw.Window) {
	r.Window = window
	r.LoadConfiguration("gameconf.json")
	gtk.Bind(&r.Data)
	r.Shaders = gtk.NewShaderLibrary()
	r.Shaders.LoadProgram(ProgramScene, "scene.v.glsl", "scene.f.glsl")
	r.Shaders.BindProgramLocations(ProgramScene, &r.SceneLoc)
	gtk.PanicOnError()

	r.Data.Projection = glm.Ident4d()
	r.Data.Cameraview = glm.Ident4d()

	r.Data.Scene = gtk.EmptyModel("root")
	model, err := gtk.LoadSceneAsModel("drivetrain.dae")
	if err != nil {
		panic(err)
	}
	r.Data.Scene.AddChild(model)
	r.Data.Car, _ = model.FindModelWithName("Car")
	grid := gtk.EmptyModel("Grid")
	grid.AddGeometry(gtk.Grid(100))
	r.Data.Scene.AddChild(grid)

	r.Car = sim.NewCar()
	r.ResetKeyBindingDefaults()

	r.UIState = UIState{
		sim.Controls{},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.QuatIdentd(),
		10,
	}
}
Esempio n. 2
0
func (r *Receiver) Init(window *glfw.Window) {
	r.Window = window
	r.LoadConfiguration("gameconf.json")
	r.Invalid = true
	gtk.Bind(&r.Data)
	// var err error
	// err = gtk.LoadTexture(r.Data.Tex0, "tex4.png")
	// panicOnErr(err)
	// err = gtk.LoadTexture(r.Data.Tex1, "tex3.png")
	// panicOnErr(err)

	r.Shaders = gtk.NewShaderLibrary()
	r.Shaders.LoadProgram(PROGRAM_SCENE, "scene.v.glsl", "scene.f.glsl")
	r.Shaders.LoadProgram(PROGRAM_FILL, "fill.v.glsl", "fill.f.glsl")
	r.Shaders.BindProgramLocations(PROGRAM_SCENE, &r.SceneLoc)
	r.Shaders.BindProgramLocations(PROGRAM_FILL, &r.FillLoc)
	gtk.PanicOnError()

	r.Data.Projection = glm.Ident4d()
	r.Data.Cameraview = glm.Ident4d()
	r.Data.Inception = glm.Ident4d()

	r.Data.Scene = gtk.EmptyModel("root")
	r.LoadScene("portal.dae")

	quadElements := gtk.MakeElements(portal.QuadElements)
	r.Data.Scene.AddGeometry(NewPlane("plane1", portal.Quad{
		glm.Vec4d{0, 0, 0, 1},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.Vec4d{10, 10, 1, 0},
	},
		quadElements,
	))
	r.Data.Fill = NewPlane("plane1", portal.Quad{
		glm.Vec4d{0, 0, 0, 1},
		glm.Vec4d{0, 0, 1, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.Vec4d{1, 1, 1, 0},
	},
		quadElements,
	)

	// r.Portals = append(r.Portals, CreatePortals()...)
	r.Data.Portal = gtk.EmptyModel("portals")
	for i, p := range r.Portals {
		r.Data.Portal.AddGeometry(NewPlane(fmt.Sprintf("portal_%d", i), p.EventHorizon, quadElements))
	}
	r.Player = Player{
		glm.Vec4d{0, 1, 0, 1},
		glm.Vec4d{0, 0, 0, 0},
		glm.Vec4d{0, 1, 0, 0},
		glm.Vec4d{1, 0, 0, 0},
		glm.QuatIdentd(),
		glm.QuatIdentd(),
	}
}
Esempio n. 3
0
func EmptyModel(name string) *Model {
	return &Model{
		name,
		glm.Ident4d(),
		glm.Ident4d(),
		[]*Geometry{},
		[]*Model{},
		nil,
	}
}
Esempio n. 4
0
func (r *Receiver) Draw(window *glfw.Window) {
	// fmt.Println("render", r.SimulationTime.Elapsed)
	bg := gtk.SoftBlack
	gl.ClearColor(bg[0], bg[1], bg[2], bg[3])
	gl.Enable(gl.DEPTH_TEST)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	r.Shaders.UseProgram(PROGRAM_FILL)
	gl.Uniform4fv(r.FillLoc.Color, 1, &gtk.SkyBlue[0])
	gl.Uniform1f(r.FillLoc.Depth, gl.Float(r.Constants.PlayerViewFar))
	r.Shaders.UseProgram(PROGRAM_SCENE)
	gl.Uniform1f(r.SceneLoc.ElapsedSeconds, gl.Float(r.SimulationTime.Elapsed))
	gl.Uniform1f(r.SceneLoc.Glow, 0)
	gl.UniformMatrix4fv(r.SceneLoc.Projection, 1, gl.FALSE, gtk.MatArray(r.Data.Projection))
	gl.UniformMatrix4fv(r.SceneLoc.Cameraview, 1, gl.FALSE, gtk.MatArray(r.Data.Cameraview))
	gl.UniformMatrix4fv(r.SceneLoc.Inception, 1, gl.FALSE, gtk.MatArray(r.Data.Inception))
	mv := glm.Ident4d()
	gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(mv))
	gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv))
	// gtk.AttachTexture(r.SceneLoc.Tex0, gl.TEXTURE0, gl.TEXTURE_2D, r.Data.Tex0)
	// gtk.AttachTexture(r.SceneLoc.Tex1, gl.TEXTURE1, gl.TEXTURE_2D, r.Data.Tex1)
	gtk.PanicOnError()

	r.DrawPortalScene(mv, 0, 1)
	r.Invalid = false
}
Esempio n. 5
0
func NodeTransform(node *collada.Node) glm.Mat4d {
	transform := glm.Ident4d()
	for _, matrix := range node.Matrix {
		v := matrix.F()
		transform = transform.Mul4(glm.Mat4d{
			v[0], v[1], v[2], v[3],
			v[4], v[5], v[6], v[7],
			v[8], v[9], v[10], v[11],
			v[12], v[13], v[14], v[15],
		}.Transpose())
	}
	for _, translate := range node.Translate {
		v := translate.F()
		transform = transform.Mul4(glm.Translate3Dd(v[0], v[1], v[2]))
	}
	for _, rotation := range node.Rotate {
		v := rotation.F()
		transform = transform.Mul4(glm.HomogRotate3Dd(v[3]*math.Pi/180, glm.Vec3d{v[0], v[1], v[2]}))
	}
	for _, scale := range node.Scale {
		v := scale.F()
		transform = transform.Mul4(glm.Scale3Dd(v[0], v[1], v[2]))
	}
	return transform
}
Esempio n. 6
0
func (r *Receiver) Draw(window *glfw.Window) {
	bg := gtk.SoftBlack
	gl.ClearColor(bg[0], bg[1], bg[2], bg[3])
	gl.Enable(gl.DEPTH_TEST)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

	r.Shaders.UseProgram(ProgramScene)
	gl.UniformMatrix4fv(r.SceneLoc.Projection, 1, gl.FALSE, gtk.MatArray(r.Data.Projection))
	gl.UniformMatrix4fv(r.SceneLoc.Cameraview, 1, gl.FALSE, gtk.MatArray(r.Data.Cameraview))
	gtk.PanicOnError()
	gtk.DrawModel(glm.Ident4d(), r.Data.Scene, r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
	// p := r.Data.Scene.Children[0].Transform.Mul4x1(r.Car.Center)
	// m := glm.Translate3Dd(math.Ceil(p[0]/5)*5,0,math.Ceil(p[2]/5)*5)
	// gtk.DrawModel(m, r.Data.Scene.Children[1], r.SceneLoc.Worldview, r.SceneLoc.Position, r.Data.Vao)
}
Esempio n. 7
0
func RotationBetweenNormals(n1, n2 glm.Vec4d) glm.Mat4d {
	axis := Cross3D(n1, n2)
	dot := n1.Dot(n2)
	if !NearZero(axis) {
		angle := math.Acos(dot)
		return glm.HomogRotate3Dd(angle, axis.Normalize())
	} else if dot < 0 {
		for e := 0; e < 3; e++ {
			v := glm.Vec4d{}
			v[e] = 1
			cross := Cross3D(n1, v)
			if !NearZero(cross) {
				return glm.HomogRotate3Dd(math.Pi, cross.Normalize())
			}
		}
		panic(fmt.Sprintln("no orthogonal axis found for normal", n1))
	}
	return glm.Ident4d()
}