ebiten/geom.go

82 lines
2.3 KiB
Go
Raw Normal View History

// Copyright 2014 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2014-12-09 15:16:04 +01:00
2014-12-09 14:09:22 +01:00
package ebiten
import (
2016-10-31 16:13:19 +01:00
"github.com/hajimehoshi/ebiten/internal/affine"
2014-12-09 14:09:22 +01:00
)
// GeoMDim is a dimension of a GeoM.
2016-10-31 16:13:19 +01:00
const GeoMDim = affine.GeoMDim
2014-12-09 14:09:22 +01:00
// A GeoM represents a matrix to transform geometry when rendering an image.
2014-12-26 03:31:20 +01:00
//
// The initial value is identity.
type GeoM struct {
2016-10-31 16:13:19 +01:00
impl affine.GeoM
2015-01-03 14:54:01 +01:00
}
2014-12-14 14:05:44 +01:00
// Element returns a value of a matrix at (i, j).
func (g *GeoM) Element(i, j int) float64 {
2017-01-19 04:07:31 +01:00
return g.impl.Elements()[i*affine.GeoMDim+j]
}
2014-12-14 14:05:44 +01:00
// Concat multiplies a geometry matrix with the other geometry matrix.
2016-02-15 15:08:10 +01:00
// This is same as muptiplying the matrix other and the matrix g in this order.
2014-12-29 11:04:18 +01:00
func (g *GeoM) Concat(other GeoM) {
2016-10-31 16:13:19 +01:00
g.impl.Concat(other.impl)
2014-12-09 14:09:22 +01:00
}
// Add is deprecated as of 1.5.0-alpha.
2016-12-19 19:05:30 +01:00
// Note that this doesn't make sense as an operation for affine matrices.
2014-12-29 11:04:18 +01:00
func (g *GeoM) Add(other GeoM) {
2016-10-31 16:13:19 +01:00
g.impl.Add(other.impl)
2014-12-25 20:22:06 +01:00
}
2015-02-18 03:04:23 +01:00
// Scale scales the matrix by (x, y).
2015-01-03 10:35:44 +01:00
func (g *GeoM) Scale(x, y float64) {
2016-10-31 16:13:19 +01:00
g.impl.Scale(x, y)
2015-01-03 10:35:44 +01:00
}
2015-02-18 03:04:23 +01:00
// Translate translates the matrix by (x, y).
2015-01-03 10:35:44 +01:00
func (g *GeoM) Translate(tx, ty float64) {
2016-10-31 16:13:19 +01:00
g.impl.Translate(tx, ty)
2015-01-03 10:35:44 +01:00
}
2016-02-15 15:08:10 +01:00
// Rotate rotates the matrix by theta.
2015-01-05 02:30:33 +01:00
func (g *GeoM) Rotate(theta float64) {
2016-10-31 16:13:19 +01:00
g.impl.Rotate(theta)
2015-01-05 02:30:33 +01:00
}
2014-12-26 02:33:50 +01:00
// SetElement sets an element at (i, j).
func (g *GeoM) SetElement(i, j int, element float64) {
2016-10-31 16:13:19 +01:00
g.impl.SetElement(i, j, element)
2014-12-09 14:09:22 +01:00
}
2016-05-14 13:43:36 +02:00
// ScaleGeo is deprecated as of 1.2.0-alpha. Use Scale instead.
func ScaleGeo(x, y float64) GeoM {
2016-10-31 16:13:19 +01:00
return GeoM{affine.ScaleGeo(x, y)}
2014-12-09 14:09:22 +01:00
}
2016-05-14 13:43:36 +02:00
// TranslateGeo is deprecated as of 1.2.0-alpha. Use Translate instead.
func TranslateGeo(tx, ty float64) GeoM {
2016-10-31 16:13:19 +01:00
return GeoM{affine.TranslateGeo(tx, ty)}
2014-12-09 14:09:22 +01:00
}
2016-05-14 13:43:36 +02:00
// RotateGeo is deprecated as of 1.2.0-alpha. Use Rotate instead.
func RotateGeo(theta float64) GeoM {
2016-10-31 16:13:19 +01:00
return GeoM{affine.RotateGeo(theta)}
2014-12-09 14:09:22 +01:00
}