57 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package vec4
 | 
						|
 | 
						|
import (
 | 
						|
	"zworld/plugin/math"
 | 
						|
	"zworld/plugin/math/random"
 | 
						|
	"zworld/plugin/math/vec2"
 | 
						|
	"zworld/plugin/math/vec3"
 | 
						|
)
 | 
						|
 | 
						|
// New returns a new vec4 from its components
 | 
						|
func New(x, y, z, w float32) T {
 | 
						|
	return T{x, y, z, w}
 | 
						|
}
 | 
						|
 | 
						|
// Extend a vec3 to a vec4 by adding a W component
 | 
						|
func Extend(v vec3.T, w float32) T {
 | 
						|
	return T{v.X, v.Y, v.Z, w}
 | 
						|
}
 | 
						|
 | 
						|
// Extend2 a vec2 to a vec4 by adding the Z and W components
 | 
						|
func Extend2(v vec2.T, z, w float32) T {
 | 
						|
	return T{v.X, v.Y, z, w}
 | 
						|
}
 | 
						|
 | 
						|
// Dot returns the dot product of two vectors.
 | 
						|
func Dot(a, b T) float32 {
 | 
						|
	return a.X*b.X + a.Y*b.Y + a.Z*b.Z + a.W*b.W
 | 
						|
}
 | 
						|
 | 
						|
// Random vector, not normalized.
 | 
						|
func Random(min, max T) T {
 | 
						|
	return T{
 | 
						|
		random.Range(min.X, max.X),
 | 
						|
		random.Range(min.Y, max.Y),
 | 
						|
		random.Range(min.Z, max.Z),
 | 
						|
		random.Range(min.W, max.W),
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func Min(a, b T) T {
 | 
						|
	return T{
 | 
						|
		X: math.Min(a.X, b.X),
 | 
						|
		Y: math.Min(a.Y, b.Y),
 | 
						|
		Z: math.Min(a.Z, b.Z),
 | 
						|
		W: math.Min(a.W, b.W),
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func Max(a, b T) T {
 | 
						|
	return T{
 | 
						|
		X: math.Max(a.X, b.X),
 | 
						|
		Y: math.Max(a.Y, b.Y),
 | 
						|
		Z: math.Max(a.Z, b.Z),
 | 
						|
		W: math.Max(a.W, b.W),
 | 
						|
	}
 | 
						|
}
 |