Esempio n. 1
0
// Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.
// param degrees The angle in degrees.
// return This matrix for the purpose of chaining operations.
func (self *Affine2) setToRotation(degrees float32) *Affine2 {
	cos := utils.CosDeg(degrees)
	sin := utils.SinDeg(degrees)

	self.m00 = cos
	self.m01 = -sin
	self.m02 = 0
	self.m10 = sin
	self.m11 = cos
	self.m12 = 0
	return self
}
Esempio n. 2
0
// Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied,
// as they are position within the world.
//
// @return vertices scaled, rotated, and offset by the polygon position.
func (self *Polygon) GetTransformedVertices() []float32 {
	if !self.dirty {
		return self.worldVertices
	}
	self.dirty = false
	var localVertices []float32
	copy(localVertices, self.localVertices)
	if self.worldVertices == nil || len(self.worldVertices) != len(localVertices) {
		self.worldVertices = make([]float32, len(localVertices))
	}

	var worldVertices []float32
	copy(worldVertices, self.worldVertices)
	positionX := self.X
	positionY := self.Y
	originX := self.OriginX
	originY := self.OriginY
	scaleX := self.ScaleX
	scaleY := self.ScaleY
	scale := scaleX != 1 || scaleY != 1
	rotation := self.Rotation
	cos := utils.CosDeg(rotation)
	sin := utils.SinDeg(rotation)
	n := len(localVertices)
	for i := 0; i < n; i += 2 {
		x := localVertices[i] - originX
		y := localVertices[i+1] - originY

		// scale if needed
		if scale {
			x *= scaleX
			y *= scaleY
		}

		// rotate if needed
		if rotation != 0 {
			oldX := x
			x = cos*x - sin*y
			y = sin*oldX + cos*y
		}

		worldVertices[i] = positionX + x + originX
		worldVertices[i+1] = positionY + y + originY
	}
	return worldVertices
}
Esempio n. 3
0
// Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
// param degrees The angle in degrees
// return This matrix for the purpose of chaining.
func (self *Affine2) Rotate(degrees float32) *Affine2 {
	if degrees == 0 {
		return self
	}

	cos := utils.CosDeg(degrees)
	sin := utils.SinDeg(degrees)

	tmp00 := self.m00*cos + self.m01*sin
	tmp01 := self.m00*-sin + self.m01*cos
	tmp10 := self.m10*cos + self.m11*sin
	tmp11 := self.m10*-sin + self.m11*cos

	self.m00 = tmp00
	self.m01 = tmp01
	self.m10 = tmp10
	self.m11 = tmp11
	return self
}
Esempio n. 4
0
// Sets this matrix to a concatenation of translation, rotation and scale. It is a more efficient form for:
// <code>idt().translate(x, y).rotate(degrees).scale(scaleX, scaleY)</code>
// param x The translation in x.
// param y The translation in y.
// param degrees The angle in degrees.
// param scaleX The scale in y.
// param scaleY The scale in x.
// return This matrix for the purpose of chaining operations.
func (self *Affine2) SetToTrnRotScl(x, y, degrees, scaleX, scaleY float32) *Affine2 {
	self.m02 = x
	self.m12 = y

	if degrees == 0 {
		self.m00 = scaleX
		self.m01 = 0
		self.m10 = 0
		self.m11 = scaleY
	} else {
		sin := utils.SinDeg(degrees)
		cos := utils.CosDeg(degrees)

		self.m00 = cos * scaleX
		self.m01 = -sin * scaleY
		self.m10 = sin * scaleX
		self.m11 = cos * scaleY
	}
	return self
}
Esempio n. 5
0
// Premultiplies this matrix with a (counter-clockwise) rotation matrix.
// param degrees The angle in degrees
// return This matrix for the purpose of chaining.
func (self *Affine2) PreRotate(degrees float32) *Affine2 {
	if degrees == 0 {
		return self
	}

	cos := utils.CosDeg(degrees)
	sin := utils.SinDeg(degrees)

	tmp00 := cos*self.m00 - sin*self.m10
	tmp01 := cos*self.m01 - sin*self.m11
	tmp02 := cos*self.m02 - sin*self.m12
	tmp10 := sin*self.m00 + cos*self.m10
	tmp11 := sin*self.m01 + cos*self.m11
	tmp12 := sin*self.m02 + cos*self.m12

	self.m00 = tmp00
	self.m01 = tmp01
	self.m02 = tmp02
	self.m10 = tmp10
	self.m11 = tmp11
	self.m12 = tmp12
	return self
}
Esempio n. 6
0
func (self *Matrix3) SetToRotationAxisDeg(axis *Vector3, degrees float32) *Matrix3 {
	return self.SetToRotationAxis(axis, utils.CosDeg(degrees), utils.SinDeg(degrees))
}