2023-02-18 03:51:43 +03:00
|
|
|
package gx
|
|
|
|
|
2023-02-18 09:11:09 +03:00
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
|
2023-02-18 03:51:43 +03:00
|
|
|
// Implements the camera component
|
|
|
|
// for the main window.
|
|
|
|
type Camera struct {
|
|
|
|
*Object
|
|
|
|
}
|
|
|
|
|
2023-02-18 09:11:09 +03:00
|
|
|
const (
|
|
|
|
Pi = math.Pi
|
|
|
|
)
|
|
|
|
|
2023-02-18 03:51:43 +03:00
|
|
|
// Returns the matrix satysfying camera
|
|
|
|
// position, scale and rotation to apply
|
|
|
|
// it to the objects to get the real
|
|
|
|
// transform to display on the screen.
|
2023-02-18 15:38:28 +03:00
|
|
|
func (c *Camera)RealMatrix(
|
|
|
|
e *Engine,
|
|
|
|
scale bool,
|
|
|
|
) Matrix {
|
2023-02-18 03:51:43 +03:00
|
|
|
g := &Matrix{}
|
|
|
|
|
2023-02-18 19:35:38 +03:00
|
|
|
|
|
|
|
if scale {
|
|
|
|
g.Scale(
|
|
|
|
c.Object.T.S.X,
|
|
|
|
c.Object.T.S.Y,
|
|
|
|
)
|
|
|
|
}
|
2023-02-18 03:51:43 +03:00
|
|
|
|
|
|
|
g.Translate(
|
|
|
|
-c.Object.T.P.X,
|
2023-02-18 09:11:09 +03:00
|
|
|
c.Object.T.P.Y,
|
2023-02-18 03:51:43 +03:00
|
|
|
)
|
2023-02-18 15:38:28 +03:00
|
|
|
g.Rotate(-c.Object.T.R)
|
|
|
|
|
|
|
|
g.Translate(
|
|
|
|
c.Object.T.RA.X,
|
|
|
|
-c.Object.T.RA.Y,
|
|
|
|
)
|
2023-02-18 03:51:43 +03:00
|
|
|
|
|
|
|
return *g
|
|
|
|
}
|
|
|
|
|