2023-02-18 03:51:43 +03:00
|
|
|
package gx
|
|
|
|
|
|
|
|
// Implements the camera component
|
|
|
|
// for the main window.
|
|
|
|
type Camera struct {
|
2023-05-04 19:31:33 +03:00
|
|
|
T Transform
|
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-05-04 19:31:33 +03:00
|
|
|
// (Should implement buffering it so we do not
|
|
|
|
// need to calculate it each time for each object. )
|
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(
|
2023-05-04 19:31:33 +03:00
|
|
|
c.T.S.X,
|
|
|
|
c.T.S.Y,
|
2023-02-18 19:35:38 +03:00
|
|
|
)
|
|
|
|
}
|
2023-02-18 03:51:43 +03:00
|
|
|
|
|
|
|
g.Translate(
|
2023-05-04 19:31:33 +03:00
|
|
|
-c.T.P.X,
|
|
|
|
c.T.P.Y,
|
2023-02-18 03:51:43 +03:00
|
|
|
)
|
2023-05-04 19:31:33 +03:00
|
|
|
g.Rotate(-c.T.R)
|
2023-02-18 15:38:28 +03:00
|
|
|
|
|
|
|
g.Translate(
|
2023-05-04 19:31:33 +03:00
|
|
|
c.T.RA.X,
|
|
|
|
-c.T.RA.Y,
|
2023-02-18 15:38:28 +03:00
|
|
|
)
|
2023-02-18 03:51:43 +03:00
|
|
|
|
|
|
|
return *g
|
|
|
|
}
|
|
|
|
|