[原FPS]物理引擎/甘雨对狙
This commit is contained in:
1 parent
7d1b33af50
commit
6c0826138f
7 files changed
+308
-31
No files matched your search
+9
-5
@@ -161,9 +161,11 @@ func regionCubicContainPos(cubic *RegionCubic, pos *Vector3) bool {
|
||||
|
||||
// 检测一个点是否在球体内
|
||||
func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool {
|
||||
distance3D := math.Sqrt(float64(sphere.pos.X-pos.X)*float64(sphere.pos.X-pos.X) +
|
||||
float64(sphere.pos.Y-pos.Y)*float64(sphere.pos.Y-pos.Y) +
|
||||
float64(sphere.pos.Z-pos.Z)*float64(sphere.pos.Z-pos.Z))
|
||||
distance3D := math.Sqrt(
|
||||
float64(sphere.pos.X-pos.X)*float64(sphere.pos.X-pos.X) +
|
||||
float64(sphere.pos.Y-pos.Y)*float64(sphere.pos.Y-pos.Y) +
|
||||
float64(sphere.pos.Z-pos.Z)*float64(sphere.pos.Z-pos.Z),
|
||||
)
|
||||
if float32(distance3D) < sphere.radius {
|
||||
return true
|
||||
} else {
|
||||
@@ -173,8 +175,10 @@ func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool {
|
||||
|
||||
// 检测一个点是否在圆柱体内
|
||||
func regionCylinderContainPos(cylinder *RegionCylinder, pos *Vector3) bool {
|
||||
distance2D := math.Sqrt(float64(cylinder.pos.X-pos.X)*float64(cylinder.pos.X-pos.X) +
|
||||
float64(cylinder.pos.Z-pos.Z)*float64(cylinder.pos.Z-pos.Z))
|
||||
distance2D := math.Sqrt(
|
||||
float64(cylinder.pos.X-pos.X)*float64(cylinder.pos.X-pos.X) +
|
||||
float64(cylinder.pos.Z-pos.Z)*float64(cylinder.pos.Z-pos.Z),
|
||||
)
|
||||
if float32(distance2D) >= cylinder.radius {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package alg
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// Vector2 二维向量
|
||||
type Vector2 struct {
|
||||
X float32
|
||||
@@ -13,6 +17,16 @@ type Vector3 struct {
|
||||
Z float32
|
||||
}
|
||||
|
||||
// Vector2Magnitude 二维向量模长
|
||||
func Vector2Magnitude(v *Vector2) float32 {
|
||||
return float32(math.Sqrt(float64(v.X*v.X + v.Z*v.Z)))
|
||||
}
|
||||
|
||||
// Vector3Magnitude 三维向量模长
|
||||
func Vector3Magnitude(v *Vector3) float32 {
|
||||
return float32(math.Sqrt(float64(v.X*v.X + v.Y*v.Y + v.Z*v.Z)))
|
||||
}
|
||||
|
||||
// Vector2Add 二维向量加
|
||||
func Vector2Add(v1 *Vector2, v2 *Vector2) *Vector2 {
|
||||
v3 := new(Vector2)
|
||||
|
||||
Reference in new issue
Block a user