Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
125 lines
3.8 KiB
C++
125 lines
3.8 KiB
C++
#ifndef __CCOLLISION_H__
|
|
#define __CCOLLISION_H__
|
|
#include <d3dx8.h>
|
|
#include "matrix.h"
|
|
class triangle {
|
|
public:
|
|
D3DXVECTOR3 a;
|
|
D3DXVECTOR3 b;
|
|
D3DXVECTOR3 c;
|
|
D3DXVECTOR3 normal;
|
|
triangle() {
|
|
a.x = a.y = a.z = 0.0f;
|
|
b.x = b.y = b.z = 0.0f;
|
|
c.x = c.y = c.z = 0.0f;
|
|
normal.x = normal.y = normal.z = 0.0f;
|
|
}
|
|
|
|
};
|
|
|
|
enum CCOLLISIONSIDE {
|
|
CCOLLISIONFRONTSIDE,
|
|
CCOLLISIONBACKSIDE,
|
|
CCOLLISIONONSIDE
|
|
};
|
|
|
|
////////////////////////////////////////////
|
|
// sphere triangle collision detection //
|
|
////////////////////////////////////////////
|
|
|
|
class CCollisionUnit { // collision test unit
|
|
public:
|
|
D3DXVECTOR3 m_UnitPos; // unit 위치;
|
|
|
|
D3DXVECTOR3 m_UnitBeforePos;
|
|
float m_NearDistPolytoSphere; // 최소거리 위치의 polygon 거리
|
|
|
|
|
|
D3DXVECTOR3 m_UnitVelocity; // unit 속도
|
|
D3DXVECTOR3 m_UnitRad; // unit sphere 반지름
|
|
|
|
bool m_bCollision; // collision detection 유/무
|
|
bool m_bError; // float error
|
|
int m_Index;
|
|
D3DXVECTOR3 m_SphereCollisionPoint; // unit sphere 상의 충돌점
|
|
D3DXVECTOR3 m_TriangleCollisionPoint; // 충돌 일어난 triangle 상의 충돌 점
|
|
|
|
D3DXVECTOR3 m_PlaneOrigin;
|
|
D3DXVECTOR3 m_PlaneNormal;
|
|
|
|
CCollisionUnit() {
|
|
m_UnitPos.x = m_UnitPos.y = m_UnitPos.z = 0.0f;
|
|
m_UnitVelocity.x = m_UnitVelocity.y = m_UnitVelocity.z = 0.0f;
|
|
m_UnitRad.x= m_UnitRad.y = m_UnitRad.z = 1.0f;
|
|
|
|
m_bCollision = false;
|
|
m_bError = false;
|
|
|
|
m_SphereCollisionPoint.x = m_SphereCollisionPoint.y = m_SphereCollisionPoint.z = 0.0f;
|
|
m_TriangleCollisionPoint.x = m_TriangleCollisionPoint.y = m_TriangleCollisionPoint.z = 0.0f;
|
|
m_UnitBeforePos.x = m_UnitBeforePos.y = m_UnitBeforePos.z = 0.0f;
|
|
m_NearDistPolytoSphere = -1.0f;
|
|
|
|
m_PlaneOrigin.x = m_PlaneOrigin.y = m_PlaneOrigin.z = 0.0f;
|
|
m_PlaneNormal.x = m_PlaneNormal.y = m_PlaneNormal.z = 0.0f;
|
|
|
|
m_Index = -1;
|
|
|
|
}
|
|
~CCollisionUnit() {}
|
|
|
|
};
|
|
class NewCCollisionDetection {
|
|
public:
|
|
|
|
CCollisionUnit *object;
|
|
triangle *faces;
|
|
triangle col;
|
|
D3DXVECTOR3 m_LocalPos;
|
|
D3DXVECTOR3 m_LocalVelocityNormalize;
|
|
|
|
matrix m_LocalInvPosMatrix;
|
|
matrix m_LocalInvRotMatrix;
|
|
|
|
float m_LocalVelocityLength;
|
|
|
|
int m_FaceNum;
|
|
|
|
int m_bs;
|
|
int m_fs;
|
|
|
|
|
|
NewCCollisionDetection();
|
|
~NewCCollisionDetection();
|
|
|
|
D3DXVECTOR3 GetDistanceClosetPointOnLine(D3DXVECTOR3 pos,D3DXVECTOR3 a,D3DXVECTOR3 b); // 라인위의 충돌 점 구하기
|
|
D3DXVECTOR3 GetDistanceClosetPointOnTriangle(D3DXVECTOR3 pos,D3DXVECTOR3 a,D3DXVECTOR3 b,D3DXVECTOR3 c); // triangle 위의 충돌점 구하기
|
|
void SetLocalVector(float x,float y,float z,float vx,float vy,float vz,float length,matrix pos,matrix rot);
|
|
|
|
bool CheckCollisionSphere(D3DXVECTOR3 pos,D3DXVECTOR3 spherecenter,float sphererad); // sphere과의 충돌 체크
|
|
bool CheckInTriangle(D3DXVECTOR3 pos,D3DXVECTOR3 a,D3DXVECTOR3 b,D3DXVECTOR3 c); // triangle 과의 충돌 체크
|
|
|
|
float RayCollisionPlane(D3DXVECTOR3 rcenter,D3DXVECTOR3 rfwd,
|
|
D3DXVECTOR3 plane,D3DXVECTOR3 plane_normal);
|
|
float RayCollisionSphere(D3DXVECTOR3 rcenter,D3DXVECTOR3 rfwd,
|
|
D3DXVECTOR3 sphercenter,float sphererad);
|
|
|
|
D3DXVECTOR3 SlidePolygonVector(D3DXVECTOR3 Velocity,D3DXVECTOR3 PlaneNormal); // 슬라이드 벡터 생성
|
|
|
|
CCOLLISIONSIDE ClassifyPoint(D3DXVECTOR3 point, D3DXVECTOR3 plane, D3DXVECTOR3 plane_normal); // point가 plane의 앞인지 뒤인지
|
|
//bool CollisionCheck(D3DXVECTOR3 pos,D3DXVECTOR3 rad,D3DXVECTOR3 velocity,triangle *polylist,int facenum,bool &col);
|
|
bool CollisionCheck(CCollisionUnit *,int facenum);
|
|
|
|
D3DXVECTOR3 Check(D3DXVECTOR3 pos,D3DXVECTOR3 rad,D3DXVECTOR3 vel,D3DXVECTOR3 gravity);
|
|
void SetMeshInfo(triangle *polygon,int facenum);
|
|
float GetHeight(float x,float y,float z);
|
|
|
|
D3DXVECTOR3 Collision(D3DXVECTOR3 pos,D3DXVECTOR3 velocity);
|
|
|
|
D3DXVECTOR3 SetVectorEllipsoidSpace(D3DXVECTOR3 vector,D3DXVECTOR3 spacerad);
|
|
bool CheckPointInSphere(D3DXVECTOR3 point,D3DXVECTOR3 scenter,float srad);
|
|
void SetVectorLength(D3DXVECTOR3 &vec,float veclength);
|
|
|
|
};
|
|
#endif
|