Example #1
0
// Distance to Plane(Point?)?  WTF IS THIS!?
func d2p(tmat mathgl.Mat4, point, ray mathgl.Vec3) float32 {
	var mat mathgl.Mat4
	mat.Assign(&tmat)
	var sub mathgl.Vec3
	sub.X = mat[12]
	sub.Y = mat[13]
	sub.Z = mat[14]
	mat[12], mat[13], mat[14] = 0, 0, 0
	point.Subtract(&sub)
	point.Scale(-1)
	ray.Normalize()
	dist := point.Dot(mat.GetForwardVec3())

	var forward mathgl.Vec3
	forward.Assign(mat.GetForwardVec3())
	cos := float64(forward.Dot(&ray))
	return dist / float32(cos)
}
Example #2
0
func (hv *HouseViewer) Drag(dx, dy float64) {
	v := mathgl.Vec3{X: hv.fx, Y: hv.fy}
	vx := mathgl.Vec3{1, -1, 0}
	vx.Normalize()
	vy := mathgl.Vec3{1, 1, 0}
	vy.Normalize()
	vx.Scale(float32(dx) / hv.zoom * 2)
	vy.Scale(float32(dy) / hv.zoom * 2)
	v.Add(&vx)
	v.Add(&vy)
	if hv.bounds.on {
		hv.fx = clamp(v.X, hv.bounds.min.x, hv.bounds.max.x)
		hv.fy = clamp(v.Y, hv.bounds.min.y, hv.bounds.max.y)
	} else {
		hv.fx, hv.fy = v.X, v.Y
	}
	hv.target_on = false
	hv.target_zoom_on = false
}
Example #3
0
func (rv *RoomViewer) Drag(dx, dy float64) {
	v := mathgl.Vec3{X: rv.fx, Y: rv.fy}
	vx := mathgl.Vec3{1, -1, 0}
	vx.Normalize()
	vy := mathgl.Vec3{1, 1, 0}
	vy.Normalize()
	vx.Scale(float32(dx) / rv.zoom * 2)
	vy.Scale(float32(dy) / rv.zoom * 2)
	v.Add(&vx)
	v.Add(&vy)
	rv.fx, rv.fy = v.X, v.Y
	rv.makeMat()
}