Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pixel
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nproject
pixel
Commits
45c2dd9b
Commit
45c2dd9b
authored
8 years ago
by
faiface
Browse files
Options
Downloads
Patches
Plain Diff
add InvMat3, Project and Unproject methods to Transform
parent
9a7a73b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
transform.go
+26
-0
26 additions, 0 deletions
transform.go
with
26 additions
and
0 deletions
transform.go
+
26
−
0
View file @
45c2dd9b
...
...
@@ -98,6 +98,22 @@ func (t Transform) Rotate(angle float64) Transform {
return
t
}
// Project transforms a vector by a transform.
func
(
t
Transform
)
Project
(
v
Vec
)
Vec
{
mat
:=
t
.
Mat3
()
vec
:=
mgl32
.
Vec3
{
float32
(
v
.
X
()),
float32
(
v
.
Y
()),
1
}
pro
:=
mat
.
Mul3x1
(
vec
)
return
V
(
float64
(
pro
.
X
()),
float64
(
pro
.
Y
()))
}
// Unproject does the inverse operation to Project.
func
(
t
Transform
)
Unproject
(
v
Vec
)
Vec
{
mat
:=
t
.
InvMat3
()
vec
:=
mgl32
.
Vec3
{
float32
(
v
.
X
()),
float32
(
v
.
Y
()),
1
}
unp
:=
mat
.
Mul3x1
(
vec
)
return
V
(
float64
(
unp
.
X
()),
float64
(
unp
.
Y
()))
}
// Mat3 returns a transformation matrix that satisfies previously set transform properties.
func
(
t
Transform
)
Mat3
()
mgl32
.
Mat3
{
mat
:=
mgl32
.
Ident3
()
...
...
@@ -108,6 +124,16 @@ func (t Transform) Mat3() mgl32.Mat3 {
return
mat
}
// InvMat3 returns an inverse transformation matrix to the matrix returned by Mat3 method.
func
(
t
Transform
)
InvMat3
()
mgl32
.
Mat3
{
mat
:=
mgl32
.
Ident3
()
mat
=
mat
.
Mul3
(
mgl32
.
Translate2D
(
float32
(
t
.
anc
.
X
()),
float32
(
t
.
anc
.
Y
())))
mat
=
mat
.
Mul3
(
mgl32
.
Scale2D
(
float32
(
1
/
t
.
sca
.
X
()),
float32
(
1
/
t
.
sca
.
Y
())))
mat
=
mat
.
Mul3
(
mgl32
.
Rotate3DZ
(
float32
(
-
t
.
rot
)))
mat
=
mat
.
Mul3
(
mgl32
.
Translate2D
(
float32
(
-
t
.
pos
.
X
()),
float32
(
-
t
.
pos
.
Y
())))
return
mat
}
// Camera is a convenience function, that returns a Transform that acts like a camera.
// Center is the position in the world coordinates, that will be projected onto the center of the screen.
// One unit in world coordinates will be projected onto zoom pixels.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment