本文整理汇总了Golang中github.com/go-gl/mathgl/mgl32.Scale3D函数的典型用法代码示例。如果您正苦于以下问题:Golang Scale3D函数的具体用法?Golang Scale3D怎么用?Golang Scale3D使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Scale3D函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ToSpritesheetFrame
func (c SpritesheetFrameConfig) ToSpritesheetFrame() *SpritesheetFrame {
var (
texX = c.textureX / c.textureOriginalW
texY = c.textureY / c.textureOriginalH
texW = c.textureW / c.textureOriginalW
texH = c.textureH / c.textureOriginalH
)
var (
texMove = mgl32.Translate3D(texX, -texH-texY, 0.0)
texScale = mgl32.Scale3D(texW, texH, 1.0)
texRotate = mgl32.HomogRotate3DZ(mgl32.DegToRad(0))
texAdj = texMove.Mul4(texScale).Mul4(texRotate).Transpose()
)
var (
ptScale = mgl32.Scale3D(c.sourceW/c.pxPerUnit, c.sourceH/c.pxPerUnit, 1.0)
ptAdj = ptScale.Transpose()
)
return &SpritesheetFrame{
Frame: FrameConfig{
PointAdjustment: ptAdj,
TextureAdjustment: texAdj,
},
Width: c.sourceW / c.pxPerUnit,
Height: c.sourceH / c.pxPerUnit,
}
}
示例2: Update
/* Update transform matrix and right/up/forward vectors */
func (t *Transform) Update(dt float32) {
// todo: avoid recalculating unless something has changed
/* Update transform */
rad := t.Rotation.Mul(math.Pi / 180.0) // translate rotaiton to radians
rotation := mgl.AnglesToQuat(rad[0], rad[1], rad[2], mgl.XYZ).Mat4()
scaling := mgl.Scale3D(t.Scale[0], t.Scale[1], t.Scale[2])
translation := mgl.Translate3D(t.Position[0], t.Position[1], t.Position[2])
/* New transform matrix: S * R * T */
//m := scaling.Mul4(rotation.Mul4(translation))
m := translation.Mul4(rotation.Mul4(scaling))
/* Grab axis vectors from transformation matrix */
t.Right[0] = m[4*0+0] // first column
t.Right[1] = m[4*1+0]
t.Right[2] = m[4*2+0]
t.Up[0] = m[4*0+1] // second column
t.Up[1] = m[4*1+1]
t.Up[2] = m[4*2+1]
t.Forward[0] = -m[4*0+2] // third column
t.Forward[1] = -m[4*1+2]
t.Forward[2] = -m[4*2+2]
/* Update transformation matrix */
t.Matrix = m
}
示例3: TestStackMultiPush
func TestStackMultiPush(t *testing.T) {
stack := NewTransformStack()
scale := mgl32.Scale3D(2, 2, 2)
rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
trans := mgl32.Translate3D(4, 5, 6)
stack.Push(trans)
stack.Push(rot)
if !stack.Peek().ApproxEqualThreshold(trans.Mul4(rot), 1e-4) {
t.Errorf("Stack does not multiply first two pushes correctly")
}
stack.Push(scale)
if !stack.Peek().ApproxEqualThreshold(trans.Mul4(rot).Mul4(scale), 1e-4) {
t.Errorf("Stack does not multiple third push correctly")
}
stack.Unwind(2)
stack.Push(scale)
if !stack.Peek().ApproxEqualThreshold(trans.Mul4(scale), 1e-4) {
t.Errorf("Unwinding and multiplying does not work correctly")
}
}
示例4: ExampleRebase
func ExampleRebase() {
parent1 := NewTransformStack()
scale := mgl32.Scale3D(2, 2, 2)
rot := mgl32.HomogRotate3DY(mgl32.DegToRad(90))
trans := mgl32.Translate3D(5, 5, 5)
parent1.Push(trans)
parent1.Push(rot)
parent1.Push(scale)
parent2 := parent1.Copy()
trans2 := mgl32.Translate3D(1, 1, 1)
rot2 := mgl32.HomogRotate3DX(mgl32.DegToRad(45))
parent1.Push(trans2)
parent1.Push(rot2)
// Replay the pushes the changes from parent1 after the copy onto parent2, as if
// they had been done on parent2 instead
parent2, err := Rebase(parent1, 4, parent2)
if err != nil {
panic(err)
}
// Now parent2 and parent 1 should be the same!
fmt.Println(parent2.Peek().ApproxEqualThreshold(parent1.Peek(), 1e-4))
// Output: true
}
示例5: 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)
}
示例6: GetTransformMat4
// GetTransformMat4 creates a transform matrix: scale * transform
func (r *Renderable) GetTransformMat4() mgl.Mat4 {
scaleMat := mgl.Scale3D(r.Scale[0], r.Scale[1], r.Scale[2])
transMat := mgl.Translate3D(r.Location[0], r.Location[1], r.Location[2])
localRotMat := r.LocalRotation.Mat4()
rotMat := r.Rotation.Mat4()
modelTransform := rotMat.Mul4(transMat).Mul4(localRotMat).Mul4(scaleMat)
return modelTransform
}
示例7: SetScale
func (t *Text) SetScale(s float32) (changed bool) {
if s > t.ScaleMax || s < t.ScaleMin {
return
}
changed = true
t.Scale = s
t.scaleMatrix = mgl32.Scale3D(s, s, s)
return
}
示例8: TextTransform
func (this *TextRenderer) TextTransform(vertex mathgl.Vec4) mathgl.Vec4 {
// apply font transforms
scale := float32(this.size) / 100.0
t := mathgl.Translate3D(curTotWidth, 0, 0).Mul4x1(vertex)
t = mathgl.Scale3D(scale, scale, 1).Mul4x1(t)
return t
}
示例9: AddScale
func (t *Text) AddScale(s float32) (changed bool) {
if s < 0 && t.Scale <= t.ScaleMin {
return
}
if s > 0 && t.Scale >= t.ScaleMax {
return
}
changed = true
t.Scale += s
t.scaleMatrix = mgl32.Scale3D(t.Scale, t.Scale, t.Scale)
return
}
示例10: DrawRectangle
func (c Context) DrawRectangle(x, y, w, h float32, color Color) {
gl.UseProgram(c.program)
model := mgl32.Translate3D(x, y, 0).Mul4(mgl32.Scale3D(w, h, 0))
modelUniform := gl.GetUniformLocation(c.program, gl.Str("model\x00"))
gl.UniformMatrix4fv(modelUniform, 1, false, &model[0])
colorArray := []float32{color.B, color.G, color.R}
colorUniform := gl.GetUniformLocation(c.program, gl.Str("color\x00"))
gl.Uniform4fv(colorUniform, 1, &colorArray[0])
gl.DrawArrays(gl.TRIANGLES, 0, 6)
}
示例11: GetMtx
func (k PianoKey) GetMtx() mgl32.Mat4 {
axis := mgl32.Vec3{1, 0, 0}
keyLen := float32(2.0)
if !k.white {
keyLen = 1.0
}
modelMtx := mgl32.Ident4()
modelMtx = modelMtx.Mul4(mgl32.Translate3D(k.Pos[0], k.Pos[1], k.Pos[2]-2))
modelMtx = modelMtx.Mul4(mgl32.HomogRotate3D(k.Angle, axis))
modelMtx = modelMtx.Mul4(mgl32.Translate3D(0, 0, keyLen))
modelMtx = modelMtx.Mul4(mgl32.Scale3D(0.5, 0.5, keyLen))
return modelMtx
}
示例12: Render
// Render renders the bitmap with the center at given position
func (renderable *SimpleBitmapRenderable) Render(context *RenderContext, icons []PlacedIcon) {
gl := renderable.gl
renderable.withShader(func() {
renderable.setMatrix(renderable.viewMatrixUniform, context.ViewMatrix())
renderable.setMatrix(renderable.projectionMatrixUniform, context.ProjectionMatrix())
gl.EnableVertexAttribArray(uint32(renderable.vertexPositionAttrib))
gl.BindBuffer(opengl.ARRAY_BUFFER, renderable.vertexPositionBuffer)
gl.VertexAttribOffset(uint32(renderable.vertexPositionAttrib), 3, opengl.FLOAT, false, 0, 0)
gl.EnableVertexAttribArray(uint32(renderable.uvPositionAttrib))
gl.BindBuffer(opengl.ARRAY_BUFFER, renderable.uvPositionBuffer)
gl.VertexAttribOffset(uint32(renderable.uvPositionAttrib), 3, opengl.FLOAT, false, 0, 0)
textureUnit := int32(0)
gl.ActiveTexture(opengl.TEXTURE0 + uint32(textureUnit))
gl.BindTexture(opengl.TEXTURE_2D, renderable.paletteTexture.Handle())
gl.Uniform1i(renderable.paletteUniform, textureUnit)
textureUnit = 1
gl.ActiveTexture(opengl.TEXTURE0 + uint32(textureUnit))
gl.Uniform1i(renderable.bitmapUniform, textureUnit)
for _, icon := range icons {
x, y := icon.Center()
u, v := icon.Icon().UV()
width, height := renderable.limitedSize(icon)
modelMatrix := mgl.Ident4().
Mul4(mgl.Translate3D(x, y, 0.0)).
Mul4(mgl.Scale3D(width, height, 1.0))
renderable.setMatrix(renderable.modelMatrixUniform, &modelMatrix)
var uv = []float32{
0.0, 0.0, 0.0,
u, 0.0, 0.0,
u, v, 0.0,
u, v, 0.0,
0.0, v, 0.0,
0.0, 0.0, 0.0}
gl.BindBuffer(opengl.ARRAY_BUFFER, renderable.uvPositionBuffer)
gl.BufferData(opengl.ARRAY_BUFFER, len(uv)*4, uv, opengl.STATIC_DRAW)
gl.BindTexture(opengl.TEXTURE_2D, icon.Icon().Handle())
gl.DrawArrays(opengl.TRIANGLES, 0, 6)
}
gl.BindTexture(opengl.TEXTURE_2D, 0)
})
}
示例13: NewTextureRenderable
// NewTextureRenderable returns a new instance of a texture renderable
func NewTextureRenderable(gl opengl.OpenGl, positionX, positionY float32, displaySize float32,
paletteTexture graphics.Texture, bitmapTexture graphics.Texture) *TextureRenderable {
vertexShader, err1 := opengl.CompileNewShader(gl, opengl.VERTEX_SHADER, textureVertexShaderSource)
defer gl.DeleteShader(vertexShader)
fragmentShader, err2 := opengl.CompileNewShader(gl, opengl.FRAGMENT_SHADER, textureFragmentShaderSource)
defer gl.DeleteShader(fragmentShader)
program, _ := opengl.LinkNewProgram(gl, vertexShader, fragmentShader)
if err1 != nil {
fmt.Fprintf(os.Stderr, "Failed to compile shader 1:\n", err1)
}
if err2 != nil {
fmt.Fprintf(os.Stderr, "Failed to compile shader 2:\n", err2)
}
renderable := &TextureRenderable{
gl: gl,
program: program,
modelMatrix: mgl.Ident4().
Mul4(mgl.Translate3D(positionX, positionY, 0.0)).
Mul4(mgl.Scale3D(displaySize, displaySize, 1.0)),
vertexArrayObject: gl.GenVertexArrays(1)[0],
vertexPositionBuffer: gl.GenBuffers(1)[0],
vertexPositionAttrib: gl.GetAttribLocation(program, "vertexPosition"),
modelMatrixUniform: gl.GetUniformLocation(program, "modelMatrix"),
viewMatrixUniform: gl.GetUniformLocation(program, "viewMatrix"),
projectionMatrixUniform: gl.GetUniformLocation(program, "projectionMatrix"),
paletteTexture: paletteTexture,
paletteUniform: gl.GetUniformLocation(program, "palette"),
bitmapTexture: bitmapTexture,
bitmapUniform: gl.GetUniformLocation(program, "bitmap")}
renderable.withShader(func() {
gl.BindBuffer(opengl.ARRAY_BUFFER, renderable.vertexPositionBuffer)
limit := float32(1.0)
var vertices = []float32{
0.0, 0.0, 0.0,
limit, 0.0, 0.0,
limit, limit, 0.0,
limit, limit, 0.0,
0.0, limit, 0.0,
0.0, 0.0, 0.0}
gl.BufferData(opengl.ARRAY_BUFFER, len(vertices)*4, vertices, opengl.STATIC_DRAW)
})
return renderable
}
示例14: NewFloor
func NewFloor(shader Shader, reflected ...Drawable) Drawable {
floor := NewStaticShape()
floor.vertices = floorVertices
floor.normals = floorNormals
floor.Buffer()
flipped := mgl.Scale3D(1, -1, 1)
return &Floor{
Node: Node{
Shape: floor,
transform: &flipped,
shader: shader,
},
reflected: reflected,
}
}
示例15: GetUpdatedModel
func (this *Transform) GetUpdatedModel() mathgl.Mat4 {
Model := this.model
Model = Model.Mul4(mathgl.Translate3D(float32(this.X), float32(this.Y), float32(this.Z)))
// Model = Model.Mul4(mathgl.HomogRotate3DZ(float32(s.rot)))
// Model = Model.Mul4(mathgl.HomogRotate3D(s.Rot, mathgl.Vec3{s.XR, s.YR, s.ZR}))
// Euler rotation is easy.. no quaternions yet.. what a pain.
Model = Model.Mul4(mathgl.Rotate3DX(this.XR * this.Rot).Mat4())
Model = Model.Mul4(mathgl.Rotate3DY(this.YR * this.Rot).Mat4())
Model = Model.Mul4(mathgl.Rotate3DZ(this.ZR * this.Rot).Mat4())
Model = Model.Mul4(mathgl.Scale3D(float32(this.XS), float32(this.YS), float32(this.ZS)))
return Model
}