Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/bbredesen/vkm
VKM is a simple vector and matrix math package written in Go, inspired by glm, and targeting 3D graphics programing.
VKM is specifically targeted at 3D graphics and is NOT inteded to be an
all-purpose vector math or linear algebra package. It includes some variant types like Pt2
and
Vec3
for convenience, but the primary matrix math functions rely on homogenous 3D
vectors and points.
While this module can be used in any Go program wanting to work with 3D transformations, it was built to use with go-vk, a Go language binding for the Vulkan graphics API.
See the GoDoc for the full API.
VKM defines three primary types: Pt
, Vec
, and Matrix
. All three are stored
in column-major order and are fundamentally arrays of [4]float32
. (Note: this explicitly means static arrays and not
slices.)
We use float32
, and not Go's default 64-bit floating point type, because Vulkan (generally) uses 32-bit
floats on the GPU. As a consequence, and rather than constantly forcing float32 type casts, VKM uses the chewxy/math32 package for float32 operations and constants.
You can generate a simple tranformation with the NewMat__
variants:
import "github.com/bbredesen/vkm"
// ...
transVec := vkm.NewVec(-1, -2, -3)
transMat := vkm.NewMatTranslate(transVec)
Rotations are measured in radians by default, but each rotation function has a "Deg" variant to use degrees. Rotation angles will scale with the length of the axis vector, so be sure to normalize the vector first:
import "github.com/chewxy/math32"
// ...
axisVec := vkm.NewVec(1, 1, 1).Normalize()
aRotationMat := vkm.NewMatRotate(axisVec, math32.Pi)
Matrix multiplication happens in the order written when you directly call
MultM
, MultV
, or MultP
. The following code has the apparent
effect of rotating the world before translating:
transformMat := myTranslationMat.MultM(myRotationMat)
Transformations can be chained, as long as you have a matrix to start from. In this example, we apply a translation of -5 in the X direction, rotate around the Y axis by 45 degrees counterclockwise, and then translate by +5 in the X direction:
transVec := NewVec(-5, 0, 0)
m := Identity().
Translate(transVec).
RotateYDeg(-45).
Translate(transVec.Invert())
When written in this form, we apply transformations in the order they are written. In practice, the code is actually right-multiplying each subsequent transformation, as in the previous example.
All math in this library is currently writing in pure Go. Performance could benefit from using SIMD extensions on Intel/AMD CPUs, which will require writing those functions in assembly.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.