-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollision.cpp
More file actions
33 lines (26 loc) · 879 Bytes
/
Copy pathCollision.cpp
File metadata and controls
33 lines (26 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "pch.h"
#include "Collision.h"
using namespace DirectX::SimpleMath;
//∞----------------------------------------------------∞
//∞*func:球と球の当たり判定
//∞*arg:球A、球B(Sphere型)
//∞*return:当たっていたらtrue、当たっていなかったらfalse
//∞----------------------------------------------------∞
bool CheckSphere2Sphere(const Sphere& sphereA, const Sphere& sphereB)
{
//球AとNの中心座標の差を計算する
Vector3 sub = sphereB.Center - sphereA.Center;
//三平方の定理でベクトルの長さを計算する
//差分ベクトルの長さは、2点間の距離
float distanceSquare = sub.x * sub.x + sub.y * sub.y + sub.z * sub.z;
//半径の和の2乗
float radiusSquare;
radiusSquare = sphereA.Radius + sphereB.Radius;
radiusSquare = radiusSquare * radiusSquare;
//距離が半径の和より大きければ当たっていない
if (distanceSquare > radiusSquare)
{
return false;
}
return true;
}