本文整理汇总了Golang中github.com/go-gl/mathgl/mgl32.Perspective函数的典型用法代码示例。如果您正苦于以下问题:Golang Perspective函数的具体用法?Golang Perspective怎么用?Golang Perspective使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Perspective函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: onStart
func onStart(glctx gl.Context, sz size.Event) {
log.Printf("creating GL program")
var err error
keystate = map[touch.Sequence]int{}
program, err = glutil.CreateProgram(glctx, vertexShader, fragmentShader)
if err != nil {
log.Printf("error creating GL program: %v", err)
return
}
glctx.Enable(gl.DEPTH_TEST)
position = glctx.GetAttribLocation(program, "position")
texCordIn = glctx.GetAttribLocation(program, "texCordIn")
color = glctx.GetUniformLocation(program, "color")
drawi = glctx.GetUniformLocation(program, "drawi")
projection = glctx.GetUniformLocation(program, "projection")
camera = glctx.GetUniformLocation(program, "camera")
loadTexture(glctx)
glctx.UseProgram(program)
projectionMat := mgl32.Perspective(mgl32.DegToRad(75.0), float32(1), 0.5, 40.0)
glctx.UniformMatrix4fv(projection, projectionMat[:])
cameraMat := mgl32.LookAtV(mgl32.Vec3{0.5, 0, 1.5}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
glctx.UniformMatrix4fv(camera, cameraMat[:])
board = NewBoard(glctx, float32(0.05), 10)
numKeys := len(board.bigKeys) + len(board.smallKeys)
InitializeSound(numKeys)
}
示例2: drawLoop
//
// Draw Loop Function
// This function gets called on every update.
//
func drawLoop(glw *wrapper.Glw) {
// Sets the Clear Color (Background Color)
gl.ClearColor(0.0, 0.0, 0.0, 1.0)
// Clears the Window
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
// Enables Depth
gl.Enable(gl.DEPTH_TEST)
// Sets the Shader program to Use
gl.UseProgram(shaderProgram)
// Define the model transformations for the cube
cube.ResetModel()
cube.Translate(x+0.5, y, z)
cube.Scale(scale, scale, scale) //scale equally in all axis
cube.Rotate(-angle_x, mgl32.Vec3{1, 0, 0}) //rotating in clockwise direction around x-axis
cube.Rotate(-angle_y, mgl32.Vec3{0, 1, 0}) //rotating in clockwise direction around y-axis
cube.Rotate(-angle_z, mgl32.Vec3{0, 0, 1}) //rotating in clockwise direction around z-axis
// Define the model transformations for our sphere
sphere.ResetModel()
sphere.Translate(-x-0.5, 0, 0)
sphere.Scale(scale/3.0, scale/3.0, scale/3.0) //scale equally in all axis
sphere.Rotate(-angle_x, mgl32.Vec3{1, 0, 0}) //rotating in clockwise direction around x-axis
sphere.Rotate(-angle_y, mgl32.Vec3{0, 1, 0}) //rotating in clockwise direction around y-axis
sphere.Rotate(-angle_z, mgl32.Vec3{0, 0, 1}) //rotating in clockwise direction around z-axis
// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
var Projection mgl32.Mat4 = mgl32.Perspective(30.0, aspect_ratio, 0.1, 100.0)
// Camera matrix
var View mgl32.Mat4 = mgl32.LookAtV(
mgl32.Vec3{0, 0, 4}, // Camera is at (0,0,4), in World Space
mgl32.Vec3{0, 0, 0}, // and looks at the origin
mgl32.Vec3{0, 1, 0}, // Head is up (set to 0,-1,0 to look upside-down)
)
// Send our uniforms variables to the currently bound shader,
gl.Uniform1ui(colourmodeUniform, uint32(colourmode))
gl.UniformMatrix4fv(viewUniform, 1, false, &View[0])
gl.UniformMatrix4fv(projectionUniform, 1, false, &Projection[0])
// Draws the Cube
gl.UniformMatrix4fv(modelUniform, 1, false, &cube.Model[0])
cube.Draw()
// Draw our sphere
gl.UniformMatrix4fv(modelUniform, 1, false, &sphere.Model[0])
sphere.DrawSphere()
gl.DisableVertexAttribArray(0)
gl.UseProgram(0)
/* Modify our animation variables */
angle_x += angle_inc_x
angle_y += angle_inc_y
angle_z += angle_inc_z
}
示例3: onPaint
func onPaint(glctx gl.Context, sz size.Event) {
glctx.Viewport(0, 0, sz.WidthPx, sz.HeightPx)
glctx.ClearColor(0.5, 0.5, 0.5, 1)
glctx.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
glctx.UseProgram(program)
projectionMtx = mgl32.Perspective(45, float32(width)/float32(height), 0.1, 100)
arcBallMtx := arcball.getMtx()
glctx.UniformMatrix4fv(projection, projectionMtx[:])
glctx.UniformMatrix4fv(view, arcBallMtx[:])
glctx.BindBuffer(gl.ARRAY_BUFFER, triBuf)
glctx.EnableVertexAttribArray(position)
glctx.EnableVertexAttribArray(color)
glctx.EnableVertexAttribArray(normals)
vertSize := 4 * (coordsPerVertex + colorPerVertex + normalsPerVertex)
glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, vertSize, 0)
glctx.VertexAttribPointer(color, colorPerVertex, gl.FLOAT, false, vertSize, 4*coordsPerVertex)
glctx.VertexAttribPointer(normals, normalsPerVertex, gl.FLOAT, false, vertSize, 4*(coordsPerVertex+colorPerVertex))
glctx.DepthMask(true)
glctx.Uniform3fv(lightPos, light.Pos[:])
glctx.Uniform3fv(lightIntensity, light.Intensities[:])
for _, k := range piano.Keys {
glctx.Uniform4fv(tint, k.Color[:])
mtx := k.GetMtx()
normMat := mtx.Mat3().Inv().Transpose()
glctx.UniformMatrix3fv(normalMatrix, normMat[:])
glctx.UniformMatrix4fv(model, mtx[:])
glctx.DrawArrays(gl.TRIANGLES, 0, len(triangleData)/vertSize)
}
modelMtx := mgl32.Ident4()
modelMtx = modelMtx.Mul4(mgl32.Translate3D(worldPos.X(), worldPos.Y(), worldPos.Z()))
modelMtx = modelMtx.Mul4(mgl32.Scale3D(0.5, 0.5, 0.5))
/*
glctx.Uniform4fv(tint, red[:])
// Disable depthmask so we dont get the pixel depth of the cursor cube
glctx.DepthMask(false)
glctx.UniformMatrix4fv(model, modelMtx[:])
glctx.DepthMask(true)
*/
glctx.DisableVertexAttribArray(position)
glctx.DisableVertexAttribArray(color)
glctx.DisableVertexAttribArray(normals)
fps.Draw(sz)
}
示例4: renderCallback
func renderCallback(delta float64) {
gl.Viewport(0, 0, int32(app.Width), int32(app.Height))
gl.ClearColor(0.196078, 0.6, 0.8, 1.0) // some pov-ray sky blue
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
// make the projection and view matrixes
projection := mgl.Perspective(mgl.DegToRad(60.0), float32(app.Width)/float32(app.Height), 1.0, 200.0)
view := app.CameraRotation.Mat4()
view = view.Mul4(mgl.Translate3D(-app.CameraPos[0], -app.CameraPos[1], -app.CameraPos[2]))
// draw the cube
cube.Node.Draw(projection, view)
// draw all of the bullets
for _, bullet := range bullets {
bullet.Node.Draw(projection, view)
}
// draw the backboard
backboard.Node.Draw(projection, view)
// draw the ground
ground.Draw(projection, view)
//time.Sleep(10 * time.Millisecond)
}
示例5: Load
// Load loads and sets up the model
func (m *Model) Load(fileName string) {
m.loadFile(fileName)
shader := sm.Shader{VertSrcFile: m.data.VertShaderFile, FragSrcFile: m.data.FragShaderFile, Name: fmt.Sprintf("%s:%s", m.data.VertShaderFile, m.data.FragShaderFile)}
program, err := m.shaders.LoadProgram(shader, false)
if err != nil {
return
}
m.currentProgram = program
gl.UseProgram(m.currentProgram)
m.projection = mgl32.Perspective(mgl32.DegToRad(45.0), float32(windowWidth)/windowHeight, 0.1, 10.0)
m.projectionUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("projection\x00"))
gl.UniformMatrix4fv(m.projectionUniform, 1, false, &m.projection[0])
m.camera = mgl32.LookAtV(mgl32.Vec3{3, 3, 3}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
m.cameraUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("camera\x00"))
gl.UniformMatrix4fv(m.cameraUniform, 1, false, &m.camera[0])
m.modelUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("model\x00"))
gl.UniformMatrix4fv(m.modelUniform, 1, false, &m.model[0])
m.textureUniform = gl.GetUniformLocation(m.currentProgram, gl.Str("tex\x00"))
gl.Uniform1i(m.textureUniform, 0)
gl.BindFragDataLocation(m.currentProgram, 0, gl.Str("outputColor\x00"))
// Load the texture
m.textures.LoadTexture(m.data.TextureFile, m.data.TextureFile)
// Configure the vertex data
gl.GenVertexArrays(1, &m.vao)
gl.BindVertexArray(m.vao)
var vbo uint32
gl.GenBuffers(1, &vbo)
gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
gl.BufferData(gl.ARRAY_BUFFER, len(m.data.Verts)*4, gl.Ptr(m.data.Verts), gl.STATIC_DRAW)
vertAttrib := uint32(gl.GetAttribLocation(m.currentProgram, gl.Str("vert\x00")))
gl.EnableVertexAttribArray(vertAttrib)
gl.VertexAttribPointer(vertAttrib, 3, gl.FLOAT, false, m.data.VertSize*4, gl.PtrOffset(0)) // 4:number of bytes in a float32
texCoordAttrib := uint32(gl.GetAttribLocation(m.currentProgram, gl.Str("vertTexCoord\x00")))
gl.EnableVertexAttribArray(texCoordAttrib)
gl.VertexAttribPointer(texCoordAttrib, 2, gl.FLOAT, true, m.data.VertSize*4, gl.PtrOffset(3*4)) // 4:number of bytes in a float32
if m.data.Indexed {
var indices uint32
gl.GenBuffers(1, &indices)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices)
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, len(m.data.Indices)*4, gl.Ptr(m.data.Indices), gl.STATIC_DRAW)
}
gl.BindVertexArray(0)
}
示例6: SetPerspective
func SetPerspective(width, height int) {
Projection := mathgl.Perspective(mathgl.DegToRad(45.0), float32(width/height), 0.1, 100.0)
viewM = mathgl.LookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
projectionM = Projection
gl.Disable(gl.CULL_FACE)
gl.Enable(gl.DEPTH_TEST)
}
示例7: Draw
func (e *Engine) Draw(c size.Event) {
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LESS)
gl.ClearColor(0.5, 0.8, 0.8, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.UseProgram(e.shader.program)
gl.Uniform3fv(e.shader.lightdir, []float32{0.5, 0.6, 0.7})
m := mgl32.Perspective(1.3, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
gl.UniformMatrix4fv(e.shader.projectionmatrix, m[:])
eye := mgl32.Vec3{0, 0, 0.2}
center := mgl32.Vec3{0, 0, 0}
up := mgl32.Vec3{0, 1, 0}
m = mgl32.LookAtV(eye, center, up)
gl.UniformMatrix4fv(e.shader.viewmatrix, m[:])
m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, 1, 0})
gl.UniformMatrix4fv(e.shader.modelmatrix, m[:])
m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, -1, 0})
gl.UniformMatrix4fv(e.shader.lightmatrix, m[:])
coordsPerVertex := 3
for _, obj := range e.shape.Objs {
gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
gl.EnableVertexAttribArray(e.shader.vertCoord)
gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)
texCoordsPerVertex := 2
gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
gl.EnableVertexAttribArray(e.shader.texcoord)
gl.VertexAttribPointer(e.shader.texcoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)
gl.BindBuffer(gl.ARRAY_BUFFER, obj.normal)
gl.EnableVertexAttribArray(e.shader.normal)
gl.VertexAttribPointer(e.shader.normal, 3, gl.FLOAT, false, 12, 0)
gl.BindTexture(gl.TEXTURE_2D, obj.tex)
gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)
gl.DisableVertexAttribArray(e.shader.texcoord)
gl.DisableVertexAttribArray(e.shader.normal)
gl.DisableVertexAttribArray(e.shader.vertCoord)
}
debug.DrawFPS(c)
}
示例8: Draw
func (e *Engine) Draw(c size.Event) {
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LESS)
gl.ClearColor(0.2, 0.2, 0.2, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.UseProgram(e.shader.program)
m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
gl.UniformMatrix4fv(e.shader.projection, m[:])
eye := mgl32.Vec3{0, 0, 8}
center := mgl32.Vec3{0, 0, 0}
up := mgl32.Vec3{0, 1, 0}
m = mgl32.LookAtV(eye, center, up)
gl.UniformMatrix4fv(e.shader.view, m[:])
m = mgl32.HomogRotate3D(float32(e.touchLoc.X/c.WidthPt-0.5)*3.14*2, mgl32.Vec3{0, 1, 0})
gl.UniformMatrix4fv(e.shader.modelx, m[:])
m = mgl32.HomogRotate3D(float32(e.touchLoc.Y/c.HeightPt-0.5)*3.14, mgl32.Vec3{1, 0, 0})
gl.UniformMatrix4fv(e.shader.modely, m[:])
coordsPerVertex := 3
for _, obj := range e.shape.Objs {
gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
gl.EnableVertexAttribArray(e.shader.vertCoord)
gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)
if obj.useuv == true {
gl.Uniform1i(e.shader.useuv, 1)
texCoordsPerVertex := 2
gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
gl.EnableVertexAttribArray(e.shader.vertTexCoord)
gl.VertexAttribPointer(e.shader.vertTexCoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)
gl.BindTexture(gl.TEXTURE_2D, obj.tex)
} else {
gl.Uniform1i(e.shader.useuv, 0)
gl.Uniform4f(e.shader.color, obj.color[0], obj.color[1], obj.color[2], obj.color[3])
}
gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)
if obj.useuv {
gl.DisableVertexAttribArray(e.shader.vertTexCoord)
}
gl.DisableVertexAttribArray(e.shader.vertCoord)
}
debug.DrawFPS(c)
}
示例9: EngineLoop
//TestLoop is a method that initiate the game
func EngineLoop(window *glfw.Window) {
mat := mgl32.Perspective(mgl32.DegToRad(45.0), float32(graphics.WIDTH)/graphics.HEIGHT, 0.1, 100.0).Mul4(mgl32.Translate3D(0.0, 0.0, -5.0))
shader, err := mvcShader.CreateMVCShader()
if err != nil {
panic(err)
}
mesh := cubeMesh.CreateVertexArray()
newEngine := Engine{mat: mat, shader: shader.BlankShader, mesh: mesh, BaseEngine: BaseEngine{run: true, window: window}}
mesh.SetPos(newEngine.shader)
newEngine.loop(&newEngine)
}
示例10: Display
func (me *test) Display(c *Core) {
me.o1.Draw(c)
me.o2.Draw(c)
projection := mgl32.Perspective(mgl32.DegToRad(Fov), float32(WindowWidth)/WindowHeight, Near, Far)
view := mgl32.LookAtV(mgl32.Vec3{3, 3, 3}, mgl32.Vec3{0, 0, 0}, mgl32.Vec3{0, 1, 0})
model := mgl32.Ident4()
MVP := projection.Mul4(view).Mul4(model)
gl.UniformMatrix4fv(mvpLoc, 1, false, &MVP[0])
gl.Uniform1i(TexLoc, 0)
}
示例11: GetMouseVector
func (c *Camera) GetMouseVector(windowSize mgl32.Vec2, mouse mgl32.Vec2) mgl32.Vec3 {
v, err := mgl32.UnProject(
mgl32.Vec3{mouse.X(), windowSize.Y() - mouse.Y(), 0.5},
mgl32.LookAtV(c.Translation, c.Lookat, c.Up),
mgl32.Perspective(mgl32.DegToRad(c.Angle), windowSize.X()/windowSize.Y(), c.Near, c.Far),
0, 0, int(windowSize.X()), int(windowSize.Y()),
)
if err == nil {
return v.Sub(c.Translation).Normalize()
} else {
log.Println("Error converting camera vector: ", err)
}
return c.Lookat
}
示例12: Draw
func (e *Engine) Draw(c event.Config) {
since := time.Now().Sub(e.started)
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LESS)
gl.ClearColor(0, 0, 0, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.UseProgram(e.shader.program)
// Setup MVP
var m mgl.Mat4
m = mgl.Perspective(0.785, float32(c.Width/c.Height), 0.1, 10.0)
gl.UniformMatrix4fv(e.shader.projection, m[:])
m = mgl.LookAtV(
mgl.Vec3{3, 3, 3}, // eye
mgl.Vec3{0, 0, 0}, // center
mgl.Vec3{0, 1, 0}, // up
)
gl.UniformMatrix4fv(e.shader.view, m[:])
m = mgl.HomogRotate3D(float32(since.Seconds()), mgl.Vec3{0, 1, 0})
gl.UniformMatrix4fv(e.shader.model, m[:])
// Draw our shape
gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)
gl.EnableVertexAttribArray(e.shader.vertCoord)
gl.VertexAttribPointer(e.shader.vertCoord, e.shape.coordsPerVertex, gl.FLOAT, false, 20, 0) // 4 bytes in float, 5 values per vertex
gl.EnableVertexAttribArray(e.shader.vertTexCoord)
gl.VertexAttribPointer(e.shader.vertTexCoord, e.shape.texCoordsPerVertex, gl.FLOAT, false, 20, 12)
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, e.shape.texture)
gl.DrawArrays(gl.TRIANGLES, 0, e.shape.vertexCount)
gl.DisableVertexAttribArray(e.shader.vertCoord)
//debug.DrawFPS(c)
}
示例13: CreateCamera
func CreateCamera(x, y, z, width, height, fov, near, far float32) *Camera {
cam := &Camera{
Transform: CreateTransform(x, y, z),
Width: width,
Height: height,
Ratio: float32(width) / float32(height),
Fov: fov,
Near: near,
Far: far,
Projection: mgl.Perspective(mgl.DegToRad(fov), width/height, near, far),
//Projection: mgl.Ortho(-width/2,width/2,-height/2,height/2,-100,100),
}
/* do an initial update at t=0 to initialize vectors */
cam.Update(0.0)
return cam
}
示例14: Loop
func Loop() bool {
if !llgl.EventLoop() {
return false
}
ratio := llgl.ResizeViewport()
if ratio != 0 {
state.projection = mgl.Perspective(mgl.DegToRad(45.0), ratio, 0.1, 10.0)
glstate.projectionUL.SetMat4(state.projection)
}
state.angle += 0.001
state.model = mgl.HomogRotate3D(float32(state.angle), mgl.Vec3{1, 0, 0})
glstate.modelUL.SetMat4(state.model)
llgl.Clear()
for i := 0; i < 1*10; i++ {
llgl.DrawTriangleArray(0, int32(len(state.data)/5))
}
fpsCounter.TickAndLog()
llgl.SwapBuffers()
return true
}
示例15: SetPerspective
// Perspective computes the projection matrix and saves it
func (c *EulerCamera) SetPerspective(fovy, aspect, near, far float32) {
c.projection = mgl.Perspective(fovy, aspect, near, far)
}