func (q *Quad) Apply(t glm.Mat4d) Quad { return Quad{ q.Center, //t.Mul4x1(q.Center), t.Mul4x1(q.Normal), t.Mul4x1(q.PlaneV), q.Scale, //t.Mul4x1(q.Scale), } }
func DrawModel(mv glm.Mat4d, model *Model, modelview gl.UniformLocation, vertexAttribute gl.AttributeLocation, vao gl.VertexArrayObject) { mv2 := mv.Mul4(model.Transform) gl.UniformMatrix4fv(modelview, 1, gl.FALSE, MatArray(mv2)) for _, geo := range model.Geometry { DrawGeometry(geo, vertexAttribute, vao) } for _, child := range model.Children { DrawModel(mv2, child, modelview, vertexAttribute, vao) } }
func (r *Receiver) DrawModel(mv glm.Mat4d, model *gtk.Model, lines bool) { mv2 := mv.Mul4(model.Transform) gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv2)) for _, geo := range model.Geometry { r.DrawGeometry(geo, r.SceneLoc.Position, lines) } for _, child := range model.Children { r.DrawModel(mv2, child, lines) } }
func (p *Player) Transform(m glm.Mat4d) { p.Position = m.Mul4x1(p.Position) p.Velocity = m.Mul4x1(p.Velocity) r := gtk.RotationComponent(m) // fmt.Println("r",r) q := gtk.Quaternion(r) // fmt.Println("q", q) p.Orientation = q.Mul(p.Orientation) p.OrientationH = q.Mul(p.OrientationH) }
func RotationComponent(m glm.Mat4d) glm.Mat3d { m2 := glm.Ident3d() j := 0 for i := 0; i < 3; i++ { v := glm.Vec4d{} v[i] = 1 vt := m.Mul4x1(v) for k := 0; k < 3; k++ { m2[j] = vt[k] j++ } } return m2 }
func (r *Receiver) DrawPortalScene(mv glm.Mat4d, stencilLevel int, depth int) { s := gtk.Stencil if depth == 0 { if stencilLevel > 0 { gl.Enable(gl.CLIP_DISTANCE0) } s.Enable().Mask(stencilLevel) r.DrawModel(mv, r.Data.Scene, false) s.Disable() gl.Disable(gl.CLIP_DISTANCE0) } else { s.Enable().Mask(stencilLevel).NoDraw() r.DrawModel(mv, r.Data.Scene, false) s.DepthLE().Increment() gl.Enable(gl.CULL_FACE) r.DrawModel(mv, r.Data.Portal, false) if r.Constants.Debug { r.DrawModel(mv, r.Data.Portal, true) } gl.Disable(gl.CULL_FACE) s.Draw().Keep() if stencilLevel > 0 { gl.Enable(gl.CLIP_DISTANCE0) } r.DrawModel(mv, r.Data.Scene, false) if r.Constants.Debug { gl.Uniform1f(r.SceneLoc.Glow, 1) s.Mask(stencilLevel + 1) r.DrawModel(mv, r.Data.Portal, true) gl.Uniform1f(r.SceneLoc.Glow, 0) } gl.Disable(gl.CLIP_DISTANCE0) //scene drawn at stencil level //portal are at level 1 r.StepDown(stencilLevel + 1) r.Shaders.UseProgram(PROGRAM_SCENE) s.Enable().Depth().DepthLE().Mask(stencilLevel) //scene is at stencil level for i, portal := range r.Portals { s.NoDraw().Increment() gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv)) gl.Enable(gl.CULL_FACE) r.DrawGeometry(r.Data.Portal.Geometry[i], r.SceneLoc.Position, false) gl.Disable(gl.CULL_FACE) s.Draw().Keep() //need to clear the depth buffer on stencil level1 r.Shaders.UseProgram(PROGRAM_FILL) s.NoDraw().DepthAlways().Mask(stencilLevel + 1) // color := gtk.DebugPallet.Pick(i) // gl.Uniform4fv(r.FillLoc.Color, 1, &color[0]) r.DrawGeometry(r.Data.Fill, r.FillLoc.Position, false) r.Shaders.UseProgram(PROGRAM_SCENE) s.Enable().Depth().DepthLE().Mask(stencilLevel) gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(portal.Portalview)) w1 := mv.Mul4(portal.Transform) r.DrawPortalScene(w1, stencilLevel+1, depth-1) r.StepDown(stencilLevel + 1) r.Shaders.UseProgram(PROGRAM_SCENE) s.Enable().Depth().DepthLE().Mask(stencilLevel) } s.Disable() } }