Files
Client/GameTools/Zallad3D SceneClass/CollisionDetection.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
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>
2025-11-29 20:17:20 +09:00

2871 lines
93 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// CollisionDetection.cpp: implementation of the CCollisionDetection class.
//
//////////////////////////////////////////////////////////////////////
#include "CollisionDetection.h"
#include "SceneManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define PLANE_BACKSIDE 0x000001
#define PLANE_FRONT 0x000010
#define ON_PLANE 0x000100
//Check!!
DWORD ClassifyPoint(vector3 point,vector3 p0,vector3 pN)
{
vector3 dir=p0-point;
float d=dir*pN;
if(d<-0.001f)
return PLANE_FRONT;
else
if(d>0.001f)
return PLANE_BACKSIDE;
return ON_PLANE;
}
//Check!!
float IntersectRaySphere(vector3 rO,vector3 rV,vector3 sO,float sR)
{
vector3 Q=sO-rO;
float c=Q.GetLens();
float v=Q*rV;
float d=sR*sR - (c*c-v*v);
if(d<0.0f)return (-1.0f);
return v-sqrtf(d);
}
//Check!!
float IntersectRayPlane(vector3 rOrigin,vector3 rVector,vector3 pOrigin,vector3 pNormal)
{
float d=-(pNormal*pOrigin);
float numer=(pNormal*rOrigin)+d;
float denom=pNormal*rVector;
if(denom==0.0f)
return -1.0f;
return -(numer/denom);
}
//Check!!
bool CheckPointInTriangle(vector3 point,vector3 a,vector3 b,vector3 c)
{
float fTotal_Angle=0.0f;
vector3 v1=point-a;
vector3 v2=point-b;
vector3 v3=point-c;
v1.Normalize();
v2.Normalize();
v3.Normalize();
fTotal_Angle+=acos(v1*v2);
fTotal_Angle+=acos(v2*v3);
fTotal_Angle+=acos(v3*v1);
if(fabs(fTotal_Angle-2.0f*3.14159f) <= 0.005f)
return true;
return false;
}
//Check!!
vector3 ClosestPointOnLine(vector3 &a,vector3 &b,vector3 &p)
{
vector3 c=p-a;
vector3 V=b-a;
float d=V.GetLens();
V.Normalize();
float t=V*c;
if(t<0.0f)return a;
if(t>d)return b;
V=V*t;
return a+V;
}
//Check!!
vector3 ClosestPointOnTriangle(vector3 a,vector3 b,vector3 c,vector3 p)
{
vector3 Rab=ClosestPointOnLine(a,b,p);
vector3 Rbc=ClosestPointOnLine(b,c,p);
vector3 Rca=ClosestPointOnLine(c,a,p);
vector3 vecForLens;
vecForLens=p-Rab;
float dAB=vecForLens.GetLens();
vecForLens=p-Rbc;
float dBC=vecForLens.GetLens();
vecForLens=p-Rca;
float dCA=vecForLens.GetLens();
float min=dAB;
vector3 result =Rab;
if( dBC < min )
{
min=dBC;
result=Rbc;
}
if( dCA < min )
{
result=Rca;
}
return result;
}
/*
vector3 ClosestPointOnPerimeter(vector3 *Poly,vector3 &p,vector3 &e0,vector3 &e1,bool &edgeFlag)
{
bool bFound=false;
bool bEdge;
float fClosestDistance=0.0f;
vector3 vecClosestPoint(0.0f,0.0f,0.0f);
vector3 vecClosestP0,vecClosestP1;
int index;
vector3 vecForLens;
vector3 Rab=ClosestPointOnLine(Poly[0],Poly[1],p,bEdge);
vecForLens=Rab-p;
if(vecForLens.GetLens() < fClosestDistance ||!bFound)
{
fClosestDistance=vecForLens.GetLens();
vecClosestPoint=Rab;
vecClosestP0=Poly[0];
vecClosestP1=Poly[1];
edgeFlag=bEdge;
bFound=true;
index=0;
}
vector3 Rbc=ClosestPointOnLine(Poly[1],Poly[2],p,bEdge);
vecForLens=Rbc-p;
if(vecForLens.GetLens() < fClosestDistance ||!bFound)
{
fClosestDistance=vecForLens.GetLens();
vecClosestPoint=Rbc;
vecClosestP0=Poly[1];
vecClosestP1=Poly[2];
edgeFlag=bEdge;
bFound=true;
index=1;
}
vector3 Rca=ClosestPointOnLine(Poly[2],Poly[0],p,bEdge);
vecForLens=Rca-p;
if(vecForLens.GetLens() < fClosestDistance ||!bFound)
{
fClosestDistance=vecForLens.GetLens();
vecClosestPoint=Rca;
vecClosestP0=Poly[2];
vecClosestP1=Poly[0];
edgeFlag=bEdge;
bFound=true;
index=2;
}
if(!edgeFlag)
{
index=index+1 > 3 ? 0 : index+1;
e0=Poly[index];
e1=Poly[index];
}
else
{
e0=vecClosestP0;
e1=vecClosestP1;
}
return vecClosestPoint;
}
*/
/*
bool CheckPointInSphere(vector3 point,vector3 sO,float sR)
{
vector3 vecForLens=point-sO;
float d=vecForLens.GetLens();
if(d<=sR)return true;
return false;
}
*/
/*
bool isEmbedde(vector3 &vecPos,vector3 &vecMostInner,vector3 *vecPoly)
{
vector3 vecNormal=(vecPoly[1]-vecPoly[0])^(vecPoly[2]-vecPoly[0]);
vecNormal.Normalize();
float fPlaneDistance=IntersectRayPlane(vecPos,-vecNormal,vecPoly[0],vecNormal);
if( fPlaneDistance > 1.0f-0.05f) return false;
vecMostInner= vecPos-vecNormal*fPlaneDistance;
// If the closest point on the plane is within the polygon, the polygon is embedded
if(!CheckPointInTriangle(vecMostInner,vecPoly[0],vecPoly[1],vecPoly[2]))
{
ClosestPointOnTriangle(vecPoly[0],vecPoly[1],vecPoly[2],vecMostInner);
vector3 vecInter=vecMostInner-vecPos;
if(vecInter.GetLens() > 1.0f-0.05f)
return false;
}
return true;
}
*/
/*
bool UnitSphereIntersection(vector3 &vecCenter,vector3 &vecOrigin,vector3 &vecDir,float &time)
{
vector3 q=vecCenter-vecOrigin;
float c=q.GetLens();
vector3 vecNormalDir=vecDir;
vecNormalDir.Normalize();
float v=q*vecNormalDir;
float d=1.0f - (c*c-v*v);
if(d<0.0f)
{
time=0.0f;
return false;
}
time=v-sqrtf(d);
return true;
}
*/
CCollisionDetection::CCollisionDetection()
{
m_vecRadius.x=40.0f;
m_vecRadius.y=85.0f;
m_vecRadius.z=40.0f;
m_vecMinMove=vector3(-10000000.0f,0.0f,-10000000.0f);
m_vecMaxMove=vector3(10000000.0f,0.0f,10000000.0f);
m_fMinYBound = -123.0f;
m_fMaxYBound = -123.0f;
m_bHeightGradient = false;
}
CCollisionDetection::~CCollisionDetection()
{
}
//DEL vector3 CCollisionDetection::Detect(vector3 vecPos,int &Detection)
//DEL {
//DEL Detection=0;
//DEL float fViewHeight;
//DEL vector3 vecOldPos;
//DEL vecOldPos=vecPos;
//DEL
//DEL vecPos=DetectHouse(vecPos);
//DEL if( vecPos.x == vecOldPos.x &&
//DEL vecPos.y == vecOldPos.y &&
//DEL vecPos.z == vecOldPos.z)
//DEL {
//DEL float GroundHeight=m_HeightField->GetHeight(vecPos);
//DEL fViewHeight=vecPos.y;
//DEL if(GroundHeight+m_fRad > fViewHeight)
//DEL {
//DEL fViewHeight=GroundHeight+m_fRad;
//DEL }
//DEL else
//DEL {
//DEL if(fViewHeight-10.0f > GroundHeight+m_fRad )
//DEL {
//DEL fViewHeight-=10.0f;
//DEL }
//DEL else
//DEL {
//DEL fViewHeight=GroundHeight+m_fRad;
//DEL }
//DEL
//DEL }
//DEL vecPos.y=fViewHeight;
//DEL vecPos=DetectHouse(vecPos);
//DEL return vecPos;
//DEL }
//DEL return vecPos;
//DEL }
//DEL vector3 CCollisionDetection::DetectHouse(vector3 vecPos)
//DEL {
//DEL vector3 vecHousePos,vecHouseInter,vecInHousePos;
//DEL float fHouseInter;
//DEL matrix matInv,matInHousePos;
//DEL for(int cSector=0;cSector<LSIZEX*LSIZEY;cSector++)
//DEL {
//DEL for(int cHouse=0;cHouse<m_HeightField->m_SectorScene[cSector].m_HouseObjectNode.num;cHouse++)
//DEL {
//DEL vecHousePos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM.GetLoc();
//DEL vecHouseInter=vecHousePos-vecPos;
//DEL fHouseInter=vecHouseInter.GetLens();
//DEL if( m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree &&
//DEL fHouseInter<MAX_HOUSECOLLISION)
//DEL {
//DEL matInv.Inverse(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM);
//DEL matInHousePos.Translation(vecPos);
//DEL matInHousePos=matInHousePos*matInv;
//DEL vecInHousePos=matInHousePos.GetLoc();
//DEL List<PolyNode*> CollPoly;
//DEL
//DEL for(int cNode=0;cNode<m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->m_pOctree->m_PolyList.num;cNode++)
//DEL m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->m_pOctree->m_PolyList[cNode]->m_used=0;
//DEL
//DEL m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->m_pOctree->m_PolyList.num=0;
//DEL m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->m_pOctree->CullSphere(vecInHousePos,m_fRad,CollPoly);
//DEL
//DEL if(CollPoly.num>0)
//DEL {
//DEL vector3 vecIntersect[6];
//DEL int cIntersect;
//DEL vector3 *vecPoly[3];
//DEL vector3 vecSphere[3];
//DEL for(int i=0;i<CollPoly.num;i++)
//DEL {
//DEL cIntersect=0;
//DEL /*
//DEL vecPoly[0]=*CollPoly[i]->m_vecPoly[0];
//DEL vecPoly[1]=*CollPoly[i]->m_vecPoly[1];
//DEL vecPoly[2]=*CollPoly[i]->m_vecPoly[2];
//DEL */
//DEL
//DEL /*
//DEL vecSphere[0]=*CollPoly[i]->m_vecPoly[0];
//DEL vecSphere[1]=*CollPoly[i]->m_vecPoly[1];
//DEL vecSphere[2]=*CollPoly[i]->m_vecPoly[2];
//DEL if(CIntersection::PolygonSphere(vecInHousePos,m_fRad,vecSphere,vecIntersect,cIntersect)==3)
//DEL {
//DEL vector3 n=(vecSphere[1]-vecSphere[0])^(vecSphere[2]-vecSphere[0]);
//DEL n.Normalize();
//DEL vector3 vecForLens=vecInHousePos-vecIntersect[0];
//DEL float fLens=vecForLens.GetLens();
//DEL vecInHousePos=vecInHousePos+(m_fRad-fLens)*n;
//DEL matInHousePos.Translation(vecInHousePos);
//DEL matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
//DEL vecPos=matInHousePos.GetLoc();
//DEL }
//DEL */
//DEL vecPoly[0]=CollPoly[i]->m_vecPoly[0];
//DEL vecPoly[1]=CollPoly[i]->m_vecPoly[1];
//DEL vecPoly[2]=CollPoly[i]->m_vecPoly[2];
//DEL vector3 vecDownInter;
//DEL float fInter;
//DEL if(CIntersection::PolygonRay(vecInHousePos,vecInHousePos+vector3(0.0f,-1.0f,0.0f)*m_fRad,vecPoly,fInter)==1)
//DEL {
//DEL vecDownInter=vecInHousePos+vector3(0.0f,-1.0f,0.0f)*fInter;
//DEL if(vecInHousePos.y-m_fRad <= vecDownInter.y)
//DEL {
//DEL vecInHousePos.y=vecDownInter.y+m_fRad;
//DEL matInHousePos.Translation(vecInHousePos);
//DEL matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
//DEL vecPos=matInHousePos.GetLoc();
//DEL }
//DEL }
//DEL //int InterMethod=CIntersection::PolygonSphere(vecInHousePos,m_fRad,vecPoly,vecIntersect,cIntersect);
//DEL /*
//DEL if(InterMethod==1)
//DEL {
//DEL for(int cInter=0;cInter<cIntersect;cInter++)
//DEL {
//DEL //if( vecInHousePos.y<=vecIntersect[cInter].y+m_fRad)
//DEL if(vecInHousePos.y >= vecIntersect[cInter].y)
//DEL {
//DEL vecInHousePos.y=vecIntersect[cInter].y+m_fRad;
//DEL matInHousePos.Translation(vecInHousePos);
//DEL matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
//DEL vecPos=matInHousePos.GetLoc();
//DEL }
//DEL }
//DEL }
//DEL */
//DEL /*
//DEL if(InterMethod==2)
//DEL {
//DEL Detection=1;
//DEL for(int cInter=0;cInter<cIntersect;cInter++)
//DEL {
//DEL vector3 vecInterXZ;
//DEL vecInterXZ.y=0.0f;
//DEL vecInterXZ.x=vecIntersect[cInter].x-vecInHousePos.x;
//DEL vecInterXZ.z=vecIntersect[cInter].z-vecInHousePos.z;
//DEL Detection=0;
//DEL float fUp=sqrtf(50.0f*50.0f-vecInterXZ.GetLens()*vecInterXZ.GetLens());
//DEL if( vecInHousePos.y <= vecIntersect[cInter].y + fUp)
//DEL {
//DEL
//DEL if( vecPoly[0].y <= vecInHousePos.y &&
//DEL vecPoly[1].y <= vecInHousePos.y &&
//DEL vecPoly[2].y <= vecInHousePos.y)
//DEL
//DEL {
//DEL vecInHousePos.y=vecIntersect[cInter].y+fUp;
//DEL fMoveY=1.0f;
//DEL matInHousePos.Translation(vecInHousePos);
//DEL matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
//DEL vecPos=matInHousePos.GetLoc();
//DEL Detection=0;
//DEL }
//DEL }
//DEL fMoveY=1.0f;
//DEL }
//DEL
//DEL }
//DEL //if(cIntersect>0)
//DEL // fMoveY=1.0f;
//DEL */
//DEL CollPoly[i]->m_used=0;
//DEL }
//DEL }
//DEL //
//DEL }
//DEL }
//DEL }
//DEL return vecPos;
//DEL }
void CCollisionDetection::CheckHouseCollision()
{
vector3 p[3];
vector3 vecNormal;
vector3 v1,v2;
float fHeight=m_HeightField->GetHeight(m_vecSourcePoint);
if((fHeight+m_vecRadius.y > m_vecSourcePoint.y))
{
CCollisionList AddNode;
AddNode.m_CollisionType=CT_TERRAIN;
AddNode.m_vecIntersectionPoint=vector3(m_vecSourcePoint.x,fHeight,m_vecSourcePoint.z);
AddNode.m_fDistance=abs(fHeight-m_vecSourcePoint.y);
m_CollisionList.Add(AddNode);
}
//*
for(int cSector=0;cSector<m_HeightField->GetLSizeX()*m_HeightField->GetLSizeY();cSector++)
{
bool bCollision=false;
if(m_CollisionDetectionDetail)
{
if( (m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z-SECTORSIZE ) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x&&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x&&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z-SECTORSIZE ) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z-SECTORSIZE ) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x-SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z+SECTORSIZE ) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x&&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x&&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z+SECTORSIZE ) ||
(m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z+SECTORSIZE ) )
{
bCollision=true;
}
}
else
{
if( m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE > m_vecSourcePoint.x &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE > m_vecSourcePoint.z)
{
bCollision=true;
}
}
if(bCollision)
{
for(int cHouse=0;cHouse<m_HeightField->m_SectorScene[cSector].m_HouseObjectNode.num;cHouse++)
{
vector3 vecHousePos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM.GetLoc();
vector3 vecHouseInterLens=vecHousePos-m_vecSourcePoint;
if( (m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree &&
vecHouseInterLens.GetLens() < m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_fRad) ||
(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree &&
m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOutHouseObject==NULL &&
vecHouseInterLens.GetLens() < 1000.0f))
{
matrix matInv;
matInv.Inverse(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM);
matrix matInHousePos;
matInHousePos.Translation(m_vecSourcePoint);
matInHousePos=matInHousePos*matInv;
vector3 vecInHousePos=matInHousePos.GetLoc();
vector3 vecSource=matInHousePos.GetLoc();
matrix matInvRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInvRot._41=0.0f;
matInvRot._42=0.0f;
matInvRot._43=0.0f;
matInv.Inverse(matInvRot);
vector3 vecVelocity=m_vecVelocity.Normalized();
matrix matInHouseRot;
matInHouseRot.Translation(vecVelocity);
matInHouseRot=matInHouseRot*matInv;
vecVelocity=matInHouseRot.GetLoc();
List<PolyNode*> CollPoly;
//m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->m_pOctree->CullSphere(vecInHousePos,85.0f,CollPoly);
m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->m_pOctree->CullSphere(vecInHousePos,585.0f,CollPoly);
if(strstr(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_strInName,"innercastle_in.r3s"))
{
bool bFlag = false;
vector3 vecMin;
vector3 vecMax;
if(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject)
{
// InHouse<73><65> bound box Get
m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_HouseObject->CalcBox(vecMin,vecMax,1);
/*vecMin.x += 800.0f;
vecMin.z += 800.0f;
vecMax.x -= 800.0f;
vecMax.z -= 800.0f;
*/
if( (vecSource.x >= vecMin.x) && (vecSource.y >= vecMin.y) && (vecSource.z >= vecMin.z) )
{
if( (vecSource.x <= vecMax.x) && (vecSource.y <= vecMax.y) && (vecSource.z <= vecMax.z) )
{
CSceneManager::SetInViewHouseScene(m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]);
CSceneManager::SetInView(true);
bFlag = true;
}
}
}
if(!bFlag)
{
CSceneManager::SetInViewHouseScene(NULL);
CSceneManager::SetInView(false);
}
}
vector3 vecCheckDir;
float fAngle;
for(int cPoly=0;cPoly<CollPoly.num;cPoly++)
{
CollPoly[cPoly]->m_used=0;
p[0]=(CollPoly[cPoly]->m_vecPoly[0]);
p[1]=(CollPoly[cPoly]->m_vecPoly[1]);
p[2]=(CollPoly[cPoly]->m_vecPoly[2]);
v1=p[1]-p[0];
v2=p[2]-p[1];
vecNormal=v1^v2;
vecNormal.Normalize();
float fIntersection;
// <20>ؿ<EFBFBD> <20>˻<EFBFBD>
vecCheckDir.x=0.0f;
vecCheckDir.y=1.0f;
vecCheckDir.z=0.0f;
fAngle=vecCheckDir*vecNormal;
if(vecNormal==vecCheckDir)
fAngle=1.0f;
// fAngle=3.14159f;
//if(fAngle < 0.0f)
// fAngle=-fAngle;
if(fAngle > 0.5f)
{
if(CIntersection::PointFromPlane(vecNormal,p[0],vecSource)>=m_vecRadius.y)
continue;
if(CIntersection::PolygonRay(vecSource,vecSource+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x,
vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x,
vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x,
vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x,
vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
}
else
{
if(CIntersection::PointFromPlane(vecNormal,p[0],vecSource)>=m_vecRadius.x)
continue;
float fRate=vecVelocity*vecNormal;
//if(fRate>= 0.0f)
// continue;
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,1.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.707f,0.0f,0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.707f,0.0f,0.707f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-0.707f,0.0f,0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(-0.707f,0.0f,0.707f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.707f,0.0f,-0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.707f,0.0f,-0.707f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-0.707f,0.0f,-0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(-0.707f,0.0f,-0.707f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(1.0f,0.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(-1.0f,0.0f,0.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,0.0f,1.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.0f,0.0f,-1.0f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
}
}
}
}
}
}
//*/
}
vector3 CCollisionDetection::GetPosition(vector3 vecPos, vector3 vecVelocity,vector3 vecBeforePos,CollisionType &CT,bool ChrCollision)
{
vector3 vecScaledPosition,vecScaledVelocity;
vector3 vecFinalPosition;
//vecVelocity.y=-20.0f;
m_CollisionDetectionDetail=ChrCollision;
vecScaledPosition=vecPos;
vecScaledVelocity=vecVelocity;
m_vecSourcePoint=vecPos;
m_vecVelocity=vecVelocity;
bool bOutMovePos=false;
if(vecPos.x < m_vecMinMove.x)
{
vecPos.x=m_vecMinMove.x;
bOutMovePos=true;
}
if(vecPos.z < m_vecMinMove.z)
{
vecPos.z=m_vecMinMove.z;
bOutMovePos=true;
}
if(vecPos.x > m_vecMaxMove.x)
{
vecPos.x=m_vecMaxMove.x;
bOutMovePos=true;
}
if(vecPos.z > m_vecMaxMove.z)
{
vecPos.z=m_vecMaxMove.z;
bOutMovePos=true;
}
if(bOutMovePos)
return vecPos;
vector3 m_vecMinMove,m_vecMaxMove;
if(!CSceneManager::GetInView())
CheckSectorHeightCollision();
/*
m_vecSourcePoint.x=m_vecSourcePoint.x/m_vecRadius.x;
m_vecSourcePoint.y=m_vecSourcePoint.y/m_vecRadius.y;
m_vecSourcePoint.z=m_vecSourcePoint.z/m_vecRadius.z;
m_vecVelocity.x=m_vecVelocity.x/m_vecRadius.x;
m_vecVelocity.y=m_vecVelocity.y/m_vecRadius.y;
m_vecVelocity.z=m_vecVelocity.z/m_vecRadius.z;
*/
CT=CT_NONE;
vector3 vecMovePoint=CollideWithWorld(m_vecSourcePoint, m_vecVelocity,vecBeforePos,0,CT,ChrCollision);
/*
if(CT==CT_CHRSIDE)
{
return vecPos;
}
*/
/*
if(CT==CT_TERRAIN)
{
List<vector3> vecHeightList;
m_HeightField->GetHeightFieldShadowPoly(vecMovePoint,vecHeightList);
vector3 v[3];
vector3 vecNormal,vecCompareNormal;
float fLens;
float fAngle;
vecCompareNormal=vector3(0.0f,1.0f,0.0f);
for(int cPoly=0;cPoly<vecHeightList.num/3;cPoly++)
{
v[0]=vecHeightList[cPoly*3+0];
v[1]=vecHeightList[cPoly*3+1];
v[2]=vecHeightList[cPoly*3+2];
if(CIntersection::PolygonRay(vector3(vecMovePoint.x,0.0f,vecMovePoint.z),vector3(vecMovePoint.x,120000.0f,vecMovePoint.z),v,fLens))
{
vecNormal=(v[1]-v[0])^(v[2]-v[1]);
vecNormal.Normalize();
fAngle=vecNormal*vecCompareNormal;
fAngle=acosf(fAngle);
if(fAngle> ((3.14159/180.0f)*35.0f))
{
return vecPos;
}
}
}
}
*/
/*
bool bUpper=false;
if(vecPos.y<vecMovePoint.y)
{
if(!CheckSectorWater(vecMovePoint,true))
return vecPos;
}
else
{
if(!CheckSectorWater(vecMovePoint,false))
return vecPos;
}
*/
/*
if(vecMovePoint.y <= 100.0f)
{
float fHeight=m_HeightField->GetHeight(vecPos);
return vector3(vecPos.x,fHeight+m_vecRadius.y,vecPos.z);
//return vecPos;
}
//vecMovePoint.y=100.0f;
*/
if(!CSceneManager::GetInView())
{
if(CheckSectorWater(vecMovePoint,false))
{
CT=CT_WATER;
}
}
ZoneBoundApply(vecMovePoint,CT); // Zone Y Bound <20><><EFBFBD><EFBFBD>
// epsilon <20><><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
vector3 vecEpsilon = vecMovePoint - vecBeforePos;
if(fabs(vecEpsilon.x + vecEpsilon.z) <= 1.0)
if((vecEpsilon.GetLens() <= 10.0f) &&(CT == CT_NONE || CT == CT_SIDE|| CT == CT_BOTTOM))
return vecBeforePos;
/**/
return vecMovePoint;
}
vector3 CCollisionDetection::CollideWithWorld(vector3 vecPos, vector3 vecVelocity,vector3 vecBeforePos,int Depth,CollisionType &CT,bool ChrCollision)
{
if((++Depth) == 6)
{
return vecBeforePos;
}
vecPos+=vecVelocity;
m_vecVelocity=vecVelocity;
m_vecSourcePoint=vecPos;
m_CollisionList.num=0;
float TmpHeight=m_vecRadius.y;
//m_vecRadius.y*=1.9f;
if(CSceneManager::m_pBspScene)
CheckBspCollision();
else
CheckHouseCollision();
if(!CSceneManager::GetInView())
{
if(ChrCollision)
{
CheckSectorMeshCollision();
CheckSectorPlantCollision();
}
}
//CheckSectorHeightCollision();
if(ChrCollision)
CheckCharacterCollision(true);
else
CheckCharacterCollision(false);
m_vecRadius.y=TmpHeight;
if(m_CollisionList.num==0)
{
//vector3 vecNewPos=vecPos-vecVelocity;
//return vecNewPos;
CT=CT_NONE;
return vecPos;
}
if(m_CollisionList.num)
{
for(int i=0;i<m_CollisionList.num;i++)
{
if(m_CollisionList[i].m_CollisionType == CT_SIDE)
{
/*
vector3 vecNewPos=vecPos-vecVelocity;
bWallCollision=true;
return vecNewPos;
*/
int MinIndex=i;
for(int cCollisionList=0;cCollisionList<m_CollisionList.num;cCollisionList++)
{
if(m_CollisionList[cCollisionList].m_fDistance<m_CollisionList[MinIndex].m_fDistance)
{
if(m_CollisionList[cCollisionList].m_CollisionType == CT_SIDE)
MinIndex=cCollisionList;
}
}
vector3 vecVelNormal=vecVelocity;
vecVelNormal.Normalize();
vector3 vecMoveDir=(vecVelNormal+m_CollisionList[MinIndex].m_vecPlaneNormal);
vector3 vecNewPos=vecPos-vecVelocity;
float fBackInter=CIntersection::PointFromPlane(m_CollisionList[MinIndex].m_vecPlaneNormal,
m_CollisionList[MinIndex].m_vecPlanePoint,vecPos);
vector3 vecUp=(m_vecRadius.x + 2.0f - fBackInter)*m_CollisionList[MinIndex].m_vecPlaneNormal;
// 03.09.08 <20><><EFBFBD><EFBFBD>
/* if(fBackInter > m_vecRadius.x - 0.01)
break;
*/
vector3 vecUnit = vector3(0.0f,1.0f,0.0f);
vector3 vecUnit2 = vecUp;
vecUnit2.Normalize();
float fUnit = vecUnit * vecUnit2;
if(fUnit <= -0.5f)
{
//CT=CT_BOTTOM;
CT = CT_SIDE;
return vecBeforePos;
}
CT=CT_SIDE;
//return vecNewPos+(vecPos+vecUp-vecNewPos);
//vector3 vel=(vecPos+vecUp-vecNewPos);
vecUp+=vecPos;
vector3 vecNewVelocity=(vecUp-vecNewPos);
//vecNewVelocity=vecNewVelocity/2.0f;
return CollideWithWorld(vecNewPos,vecNewVelocity,vecBeforePos,Depth,CT,ChrCollision);
//return vecNewPos+vecUp;
//return CollideWithWorld(vecNewPos,(vecPos+vecUp)-vecNewPos,Depth,bWallCollision);
//return CollideWithWorld(vecPos,vecUp,Depth,CT);
//return vecNewPos;
/*
m_CollisionList[i].m_vecIntersectionPoint;
return vecNewPos;
*/
}
/*
if(m_CollisionList[i].m_CollisionType == CT_CHRSIDE)
{
CT=CT_CHRSIDE;
return vecPos;
}
*/
}
float fMinDistance=1000000000.0f;
int MinIndex=-1;
for(i=0;i<m_CollisionList.num;i++)
{
if( m_CollisionList[i].m_fDistance<fMinDistance && m_CollisionList[i].m_CollisionType==CT_BOTTOM ||
m_CollisionList[i].m_fDistance<fMinDistance && m_CollisionList[i].m_CollisionType==CT_TERRAIN)
{
fMinDistance=m_CollisionList[i].m_fDistance;
MinIndex=i;
CT=m_CollisionList[i].m_CollisionType;
}
}
if(MinIndex==-1)
{
vector3 vecNewPos=vecPos-vecVelocity;
return vecNewPos;
}
m_vecSourcePoint=m_CollisionList[MinIndex].m_vecIntersectionPoint+vector3(0.0f,m_vecRadius.y,0.0f);
return m_CollisionList[MinIndex].m_vecIntersectionPoint+vector3(0.0f,m_vecRadius.y,0.0f);
}
return m_vecSourcePoint;
}
void CCollisionDetection::CheckSectorMeshCollision()
{
vector3 vecBoundBox[8];
vector3 vecPolyTest[3];
vector3 vecPlaneNormal;
matrix matTrans;
float fIntersection;
WORD wCollisionIndices[]=
{
4,1,0,
1,4,5,
5,3,1,
3,5,7,
7,2,3,
2,7,6,
6,0,2,
0,6,4,
4,5,6,
5,6,7
};
vector3 vecDirection[8];
vecDirection[0]=vector3(0.707f,0.0f,0.707f);
vecDirection[1]=vector3(0.707f,0.0f,-0.707f);
vecDirection[2]=vector3(-0.707f,0.0f,0.707f);
vecDirection[3]=vector3(-0.707f,0.0f,-0.707f);
vecDirection[4]=vector3(1.0f,0.0f,0.0f);
vecDirection[5]=vector3(-1.0f,0.0f,0.0f);
vecDirection[6]=vector3(0.0f,0.0f,1.0f);
vecDirection[7]=vector3(0.0f,0.0f,-1.0f);
vector3 vecLens;
//for(int cSector=0;cSector<m_LSizeX*m_LSizeY;cSector++)
for(int cSector=0;cSector<m_HeightField->GetLSizeX()*m_HeightField->GetLSizeY();cSector++)
{
if( m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x &&
m_vecSourcePoint.x < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_vecSourcePoint.z < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE)
{
for(int cObject=0;cObject<m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode.num;cObject++)
{
vecLens=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_TM.GetLoc()-m_vecSourcePoint;
if(vecLens.GetLens() > 1000.0f)
continue;
if(strstr(m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_strObjectName,"ZXC") ||
strstr(m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_strObjectName,"zxc")
)
continue;
vecBoundBox[0].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.x;
vecBoundBox[0].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.y;
vecBoundBox[0].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.z;
vecBoundBox[1].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.x;
vecBoundBox[1].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.y;
vecBoundBox[1].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.z;
vecBoundBox[2].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.x;
vecBoundBox[2].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.y;
vecBoundBox[2].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.z;
vecBoundBox[3].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.x;
vecBoundBox[3].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.y;
vecBoundBox[3].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.z;
vecBoundBox[4].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.x;
vecBoundBox[4].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.y;
vecBoundBox[4].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.z;
vecBoundBox[5].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.x;
vecBoundBox[5].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.y;
vecBoundBox[5].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.z;
vecBoundBox[6].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMinBox.x;
vecBoundBox[6].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.y;
vecBoundBox[6].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.z;
vecBoundBox[7].x=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.x;
vecBoundBox[7].y=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.y;
vecBoundBox[7].z=m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_vecMaxBox.z;
for(int i=0;i<8;i++)
{
matTrans.Translation(vecBoundBox[i]);
matTrans=matTrans*m_HeightField->m_SectorScene[cSector].m_ObjectSceneNode[cObject]->m_AccumulateTM;
vecBoundBox[i]=matTrans.GetLoc();
}
//
//vecPolyTest[0]=vecBoundBox[4];
//vecPolyTest[1]=vecBoundBox[0];
//vecPolyTest[2]=vecBoundBox[1];
vector3 vecVelocity=m_vecVelocity.Normalized();
vecVelocity.y=0.0f;
vecVelocity.Normalize();
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecBoundBox[wCollisionIndices[cIndices*3+1]];
vecPolyTest[2]=vecBoundBox[wCollisionIndices[cIndices*3+2]];
vector3 vecNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecNormal.Normalize();
for(i=0;i<8;i++)
{ // 9.26 <20><><EFBFBD><EFBFBD>(vector3 <20><><EFBFBD><EFBFBD>)
/*vecVelocity.y = -1.0f;
float fRate=vecVelocity*vecNormal;
if(fRate>= 0.0f)
continue;*/
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
}
}
}
for(cIndices=8;cIndices<10;cIndices++)
{
vecPolyTest[0]=vecBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecBoundBox[wCollisionIndices[cIndices*3+1]];
vecPolyTest[2]=vecBoundBox[wCollisionIndices[cIndices*3+2]];
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
vecPolyTest,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vector3(0.0f,-1.0f,0.0f)*fIntersection;
AddNode.m_vecPlaneNormal=vector3(0.0f,1.0f,0.0f);
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
/*
if(CIntersection::PolygonRay(m_vecSourcePoint+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x,
m_vecSourcePoint+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y;
AddNode.m_vecPlaneNormal=vector3(0.0f,1.0f,0.0f);
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(m_vecSourcePoint+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x,
m_vecSourcePoint+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
vecPolyTest,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y;
AddNode.m_vecPlaneNormal=vector3(0.0f,1.0f,0.0f);
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(m_vecSourcePoint+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x,
m_vecSourcePoint+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y;
AddNode.m_vecPlaneNormal=vector3(0.0f,1.0f,0.0f);
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(m_vecSourcePoint+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x,
m_vecSourcePoint+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y;
AddNode.m_vecPlaneNormal=vector3(0.0f,1.0f,0.0f);
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
*/
}
}
break;
}
}
}
void CCollisionDetection::CheckSectorPlantCollision()
{
vector3 vecInSectorPos;
int nTreeIndexX,nTreeIndexZ;
int nCheckTreeIndexX[4],nCheckTreeIndexZ[4];
vector3 vecBoundBox[8];
vector3 vecTransBoundBox[8];
vector3 vecMinBox,vecMaxBox;
vecMinBox=vector3(-150.0f,0.0f,-150.0f);
vecMaxBox=vector3(150.0f,400.0f,150.0f);
vecBoundBox[0].x=vecMinBox.x;
vecBoundBox[0].y=vecMinBox.y;
vecBoundBox[0].z=vecMinBox.z;
vecBoundBox[1].x=vecMaxBox.x;
vecBoundBox[1].y=vecMinBox.y;
vecBoundBox[1].z=vecMinBox.z;
vecBoundBox[2].x=vecMinBox.x;
vecBoundBox[2].y=vecMinBox.y;
vecBoundBox[2].z=vecMaxBox.z;
vecBoundBox[3].x=vecMaxBox.x;
vecBoundBox[3].y=vecMinBox.y;
vecBoundBox[3].z=vecMaxBox.z;
vecBoundBox[4].x=vecMinBox.x;
vecBoundBox[4].y=vecMaxBox.y;
vecBoundBox[4].z=vecMinBox.z;
vecBoundBox[5].x=vecMaxBox.x;
vecBoundBox[5].y=vecMaxBox.y;
vecBoundBox[5].z=vecMinBox.z;
vecBoundBox[6].x=vecMinBox.x;
vecBoundBox[6].y=vecMaxBox.y;
vecBoundBox[6].z=vecMaxBox.z;
vecBoundBox[7].x=vecMaxBox.x;
vecBoundBox[7].y=vecMaxBox.y;
vecBoundBox[7].z=vecMaxBox.z;
WORD wCollisionIndices[]=
{
4,1,0,
1,4,5,
5,3,1,
3,5,7,
7,2,3,
2,7,6,
6,0,2,
0,6,4
};
vector3 vecPolyTest[3];
vector3 vecPlaneNormal;
float fTransY;
float fIntersection;
vector3 vecDirection[8];
vecDirection[0]=vector3(0.707f,0.0f,0.707f);
vecDirection[1]=vector3(0.707f,0.0f,-0.707f);
vecDirection[2]=vector3(-0.707f,0.0f,0.707f);
vecDirection[3]=vector3(-0.707f,0.0f,-0.707f);
vecDirection[4]=vector3(1.0f,0.0f,0.0f);
vecDirection[5]=vector3(-1.0f,0.0f,0.0f);
vecDirection[6]=vector3(0.0f,0.0f,1.0f);
vecDirection[7]=vector3(0.0f,0.0f,-1.0f);
//for(int cSector=0;cSector<m_LSizeX*m_LSizeY;cSector++)
for(int cSector=0;cSector<m_HeightField->GetLSizeX()*m_HeightField->GetLSizeY();cSector++)
{
if( m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x &&
m_vecSourcePoint.x < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_vecSourcePoint.z < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE)
{
vecInSectorPos.x=m_vecSourcePoint.x-m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41;
vecInSectorPos.z=m_vecSourcePoint.z-m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43;
nTreeIndexX=vecInSectorPos.x/LINTERVAL;
nTreeIndexZ=vecInSectorPos.z/LINTERVAL;
nCheckTreeIndexX[0]=nTreeIndexX;
nCheckTreeIndexZ[0]=nTreeIndexZ;
if(nTreeIndexX==SECTORSX-1)
{
nCheckTreeIndexX[1]=-1;
nCheckTreeIndexZ[1]=-1;
}
else
{
nCheckTreeIndexX[1]=nTreeIndexX+1;
nCheckTreeIndexZ[1]=nTreeIndexZ;
}
if(nTreeIndexZ==SECTORSX-1)
{
nCheckTreeIndexX[2]=-1;
nCheckTreeIndexZ[2]=-1;
}
else
{
nCheckTreeIndexX[2]=nTreeIndexX;
nCheckTreeIndexZ[2]=nTreeIndexZ+1;
}
if(nTreeIndexX==SECTORSX-1 || nTreeIndexZ==SECTORSX-1)
{
nCheckTreeIndexX[3]=-1;
nCheckTreeIndexZ[3]=-1;
}
else
{
nCheckTreeIndexX[3]=nTreeIndexX+1;
nCheckTreeIndexZ[3]=nTreeIndexZ+1;
}
for(int i=0;i<4;i++)
{
if( nCheckTreeIndexX[i]!=-1 &&
//m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_AlreadyPutPlant[nCheckTreeIndexX[i]+nCheckTreeIndexZ[i]*SECTORSX]!=-1)
m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_usDetailTree[nCheckTreeIndexX[i]+nCheckTreeIndexZ[i]*SECTORSX]!=0xff)
{
//fTransY=m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_vecPlantPosition[m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_AlreadyPutPlant[nCheckTreeIndexX[i]+nCheckTreeIndexZ[i]*SECTORSX]].y;
fTransY=m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_pHeight[nCheckTreeIndexX[i]+nCheckTreeIndexZ[i]*SECTORSX];
//m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_vecPlantPosition[m_HeightField->m_SectorScene[cSector].m_TreeObjectNode.m_pHeight;
for(int cVertex=0;cVertex<8;cVertex++)
{
vecTransBoundBox[cVertex]=vecBoundBox[cVertex]+vector3(nCheckTreeIndexX[i]*LINTERVAL+m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41,
fTransY,
nCheckTreeIndexZ[i]*LINTERVAL+m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43);
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
for(int cDir=0;cDir<8;cDir++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[cDir]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[cDir]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
}
}
}
}
}
break;
}
}
}
void CCollisionDetection::CheckCharacterCollision(bool bChrMode)
{
vector3 vecLens,vecChrPos,vecPos;
float fLens;
vecPos=m_vecSourcePoint;
vecPos.y -= 85.0f;
//vecPos.y=0.0f;
if(bChrMode)
{
/*
CSceneManager::m_CharacterManager.m_CharacterList[0]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecChrPos.y=0.0f;
vecLens=vecPos-vecChrPos;
fLens=vecLens.GetLens();
if(fLens < m_vecRadius.x*2.0f)
{
CCollisionList AddNode;
AddNode.m_fDistance=fLens-m_vecRadius.x;
AddNode.m_vecPlaneNormal=vecLens;
AddNode.m_vecPlaneNormal.Normalize();
AddNode.m_vecPlanePoint=vecChrPos+AddNode.m_vecPlaneNormal*(m_vecRadius.x);
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
}
*/
for(int nChr=1;nChr<CSceneManager::m_CharacterManager.m_CharacterList.num;nChr++)
{
if(CSceneManager::m_CharacterManager.m_CharacterList[nChr].m_bCollisionDetectAble)
{
CSceneManager::m_CharacterManager.m_CharacterList[nChr].m_pChrmodel->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
//vecChrPos.y=0.0f;
vecLens=vecPos-vecChrPos;
fLens=vecLens.GetLens();
if(fLens < m_vecRadius.x*2.0f)
{
CCollisionList AddNode;
/// <20><EFBFBD><ECBCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>б<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>̰<EFBFBD>( 2000.0f )<29><> <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>
AddNode.m_fDistance=(fLens-m_vecRadius.x) + 2000.0f;
AddNode.m_vecPlaneNormal=vecLens;
AddNode.m_vecPlaneNormal.Normalize();
AddNode.m_vecPlanePoint= vecChrPos+AddNode.m_vecPlaneNormal*(m_vecRadius.x);
AddNode.m_CollisionType= CT_SIDE ;
m_CollisionList.Add(AddNode);
}
}
else
{
int a=0;
}
}
}
else
{
//for(int cChr=0;cChr<CSceneManager::m_CharacterManager.m_CharacterList.num;cChr++)
//{
// if(cChr==m_SelfChr)
// continue;
/*
if(CSceneManager::m_CharacterManager.m_CharacterList.num>0)
{
CSceneManager::m_CharacterManager.m_CharacterList[0]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecChrPos.y=0.0f;
vecLens=vecPos-vecChrPos;
fLens=vecLens.GetLens();
if(fLens < m_vecRadius.x*2.0f)
{
CCollisionList AddNode;
AddNode.m_fDistance=fLens-m_vecRadius.x;
AddNode.m_vecPlaneNormal=vecLens;
AddNode.m_vecPlaneNormal.Normalize();
AddNode.m_vecPlanePoint=vecChrPos+AddNode.m_vecPlaneNormal*(m_vecRadius.x);
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
}
}
*/
}
/*
vecLens=m_vecSourcePoint-vecChrPos;
if(vecLens.GetLens() > 500.0f)
continue;
for(int i=0;i<8;i++)
{
vecTransBoundBox[i]=vecBoundBox[i]+vecChrPos;
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_CHRSIDE;
m_CollisionList.Add(AddNode);
}
}
}
}
*/
/*
CSceneManager::m_CharacterManager.m_CharacterList[0]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecLens=m_vecSourcePoint-vecChrPos;
if(vecLens.GetLens() > 500.0f)
return;
for(int i=0;i<8;i++)
{
vecTransBoundBox[i]=vecBoundBox[i]+vecChrPos;
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_CHRSIDE;
m_CollisionList.Add(AddNode);
}
}
}
*/
/*
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.707f,0.0f,0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInHousePos.Translation(vecSource+vector3(0.707f,0.0f,0.707f)*fIntersection);
matInHousePos=matInHousePos*m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
AddNode.m_vecIntersectionPoint=matInHousePos.GetLoc();
matrix matInHouseRot=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHouseRot._41=matInHouseRot._42=matInHouseRot._43=0.0f;
matInHousePos.Translation(vecNormal);
matInHousePos=matInHousePos*matInHouseRot;
AddNode.m_vecPlaneNormal=matInHousePos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=m_HeightField->m_SectorScene[cSector].m_HouseObjectNode[cHouse]->m_AccumulateTM;
matInHousePos.Translation(p[0]);
matWorldPos=matInHousePos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
*/
/*
vector3 vecBoundBox[8],vecTransBoundBox[8];
vector3 vecPolyTest[3];
vector3 vecPlaneNormal;
matrix matTrans;
float fIntersection;
WORD wCollisionIndices[]=
{
4,1,0,
1,4,5,
5,3,1,
3,5,7,
7,2,3,
2,7,6,
6,0,2,
0,6,4
};
vector3 vecDirection[8];
vecDirection[0]=vector3(0.707f,0.0f,0.707f);
vecDirection[1]=vector3(0.707f,0.0f,-0.707f);
vecDirection[2]=vector3(-0.707f,0.0f,0.707f);
vecDirection[3]=vector3(-0.707f,0.0f,-0.707f);
vecDirection[4]=vector3(1.0f,0.0f,0.0f);
vecDirection[5]=vector3(-1.0f,0.0f,0.0f);
vecDirection[6]=vector3(0.0f,0.0f,1.0f);
vecDirection[7]=vector3(0.0f,0.0f,-1.0f);
vector3 vecMaxBox,vecMinBox;
vecMaxBox=vector3(-60.0f,0.0f,-60.0f);
vecMinBox=vector3(60.0f,200.0f,60.f);
vecBoundBox[0].x=vecMinBox.x;
vecBoundBox[0].y=vecMinBox.y;
vecBoundBox[0].z=vecMinBox.z;
vecBoundBox[1].x=vecMaxBox.x;
vecBoundBox[1].y=vecMinBox.y;
vecBoundBox[1].z=vecMinBox.z;
vecBoundBox[2].x=vecMinBox.x;
vecBoundBox[2].y=vecMinBox.y;
vecBoundBox[2].z=vecMaxBox.z;
vecBoundBox[3].x=vecMaxBox.x;
vecBoundBox[3].y=vecMinBox.y;
vecBoundBox[3].z=vecMaxBox.z;
vecBoundBox[4].x=vecMinBox.x;
vecBoundBox[4].y=vecMaxBox.y;
vecBoundBox[4].z=vecMinBox.z;
vecBoundBox[5].x=vecMaxBox.x;
vecBoundBox[5].y=vecMaxBox.y;
vecBoundBox[5].z=vecMinBox.z;
vecBoundBox[6].x=vecMinBox.x;
vecBoundBox[6].y=vecMaxBox.y;
vecBoundBox[6].z=vecMaxBox.z;
vecBoundBox[7].x=vecMaxBox.x;
vecBoundBox[7].y=vecMaxBox.y;
vecBoundBox[7].z=vecMaxBox.z;
vector3 vecLens;
vector3 vecChrPos;
/*
if(bChrMode)
{
for(int cChr=0;cChr<CSceneManager::m_CharacterManager.m_CharacterList.num;cChr++)
{
if(cChr==m_SelfChr)
continue;
CSceneManager::m_CharacterManager.m_CharacterList[cChr]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecLens=m_vecSourcePoint-vecChrPos;
if(vecLens.GetLens() > 500.0f)
continue;
for(int i=0;i<8;i++)
{
vecTransBoundBox[i]=vecBoundBox[i]+vecChrPos;
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
vector3 v1=vecPolyTest[1]-vecPolyTest[0];
vector3 v2=vecPolyTest[2]-vecPolyTest[1];
vector3 vecNormal=v1^v2;
vecNormal.Normalize();
float fAngle=vecDirection[i]*vecNormal;
fAngle=acosf(fAngle);
if(fAngle>=(3.14159f/2.0f))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_CHRSIDE;
m_CollisionList.Add(AddNode);
}
}
}
}
}
/*
CSceneManager::m_CharacterManager.m_CharacterList[0]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecLens=m_vecSourcePoint-vecChrPos;
if(vecLens.GetLens() > 500.0f)
return;
for(int i=0;i<8;i++)
{
vecTransBoundBox[i]=vecBoundBox[i]+vecChrPos;
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_CHRSIDE;
m_CollisionList.Add(AddNode);
}
}
}
}
else
{
for(int cChr=1;cChr<CSceneManager::m_CharacterManager.m_CharacterList.num;cChr++)
{
if(cChr==m_SelfChr)
continue;
CSceneManager::m_CharacterManager.m_CharacterList[cChr]->GetPosition(vecChrPos.x,vecChrPos.y,vecChrPos.z);
vecLens=m_vecSourcePoint-vecChrPos;
if(vecLens.GetLens() > 500.0f)
continue;
for(int i=0;i<8;i++)
{
vecTransBoundBox[i]=vecBoundBox[i]+vecChrPos;
}
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecTransBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecTransBoundBox[wCollisionIndices[cIndices*3+2]];
vecPolyTest[2]=vecTransBoundBox[wCollisionIndices[cIndices*3+1]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_CHRSIDE;
m_CollisionList.Add(AddNode);
}
}
}
}
}
*/
}
bool CCollisionDetection::CheckSectorWater(vector3 vecPos,bool bUpper)
{
for(int cSector=0;cSector<m_HeightField->GetLSizeX()*m_HeightField->GetLSizeY();cSector++)
{
if( m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41 <= m_vecSourcePoint.x &&
m_vecSourcePoint.x < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._41+SECTORSIZE &&
m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43 <= m_vecSourcePoint.z &&
m_vecSourcePoint.z < m_HeightField->m_SectorScene[cSector].m_AccumulateTM._43+SECTORSIZE)
{
if(m_HeightField->m_SectorScene[cSector].m_MapWater)
{
if(m_HeightField->m_SectorScene[cSector].m_MapWater->m_fWaterHeight - 180.0f > vecPos.y-100)
{
return true;
/*
if(bUpper)
return true;
return false;
*/
}
return false;
//return true;
}
return false;
//return true;
}
}
return false;
}
void CCollisionDetection::CheckBspCollision()
{
if(CSceneManager::m_pBspScene && CSceneManager::m_pBspScene->m_HouseObject->m_pBspObject)
{
CBspScene *pBsp=CSceneManager::m_pBspScene->m_HouseObject->m_pBspObject;
matrix matBspTM=CSceneManager::m_pBspScene->m_AccumulateTM;
matrix matInvTM,matTM;
matTM.Translation(m_vecSourcePoint);
matInvTM.Inverse(CSceneManager::m_pBspScene->m_AccumulateTM);
matTM=matTM*matInvTM;
pBsp->CullCollisionPoly(matTM.GetLoc());
vector3 vecSource=matTM.GetLoc();
DSurface *ds;
int nCount=0;
List<vector3> CollPoly;
for(int i=0;i<pBsp->m_nDrawSurfaces;i++)
{
if(pBsp->m_SurfaceInc[i]==1)
{
ds=&pBsp->m_DrawSurfaces[i];
if(ds->m_SurfaceType!=0)
continue;
for(int cIndices=0;cIndices<ds->m_nIndex;cIndices++)
{
CollPoly.Add( pBsp->m_DrawVerts[ds->m_FirstVert+pBsp->m_DrawIndex[ds->m_FirstIndex+cIndices]].v );
}
}
}
vector3 vecNormal;
vector3 p[3];
vector3 v1,v2;
vector3 vecCheckDir;
float fAngle;
matrix matInBspPos;
for(int cPoly=0;cPoly<CollPoly.num/3;cPoly++)
{
p[0].x=CollPoly[cPoly*3+0].x;
p[0].y=CollPoly[cPoly*3+0].z;
p[0].z=CollPoly[cPoly*3+0].y;
p[1].x=CollPoly[cPoly*3+2].x;
p[1].y=CollPoly[cPoly*3+2].z;
p[1].z=CollPoly[cPoly*3+2].y;
p[2].x=CollPoly[cPoly*3+1].x;
p[2].y=CollPoly[cPoly*3+1].z;
p[2].z=CollPoly[cPoly*3+1].y;
v1=p[1]-p[0];
v2=p[2]-p[1];
vecNormal=v1^v2;
vecNormal.Normalize();
vecNormal=-vecNormal;
float fIntersection;
vecCheckDir=vector3(0.0f,1.0f,0.0f);
fAngle=vecCheckDir*vecNormal;
if(vecNormal==vecCheckDir)
fAngle=1.0f;
if(fAngle>0.5f)
{
if(CIntersection::PolygonRay(vecSource,vecSource+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,p,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x,
vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x,
vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x,
vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
if(CIntersection::PolygonRay(vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x,
vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x+vector3(0.0f,-1.0f,0.0f)*m_vecRadius.y,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,-1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_BOTTOM;
m_CollisionList.Add(AddNode);
continue;
}
}
else
{
if(CIntersection::PointFromPlane(vecNormal,p[0],vecSource)>=m_vecRadius.x)
continue;
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,1.0f,0.0f)*m_vecRadius.y,p,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,1.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.707f,0.0f,0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.707f,0.0f,0.707f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-0.707f,0.0f,0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(-0.707f,0.0f,0.707f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.707f,0.0f,-0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.707f,0.0f,-0.707f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-0.707f,0.0f,-0.707f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(-0.707f,0.0f,-0.707f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(1.0f,0.0f,0.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(1.0f,0.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(-1.0f,0.0f,0.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(-1.0f,0.0f,0.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,0.0f,1.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,0.0f,1.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
if( CIntersection::PolygonRay(vecSource,
vecSource+vector3(0.0f,0.0f,-1.0f)*m_vecRadius.x,
p,
fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
matInBspPos.Translation(vecSource+vector3(0.0f,0.0f,-1.0f)*fIntersection);
matInBspPos=matInBspPos*matBspTM;
AddNode.m_vecIntersectionPoint=matInBspPos.GetLoc();
matrix matInBspRot=matBspTM;
matInBspRot._41=matInBspRot._42=matInBspRot._43=0.0f;
matInBspPos.Translation(vecNormal);
matInBspPos=matInBspPos*matInBspRot;
AddNode.m_vecPlaneNormal=matInBspPos.GetLoc();
AddNode.m_CollisionType=CT_SIDE;
matrix matWorldPos=matBspTM;
matInBspPos.Translation(p[0]);
matWorldPos=matInBspPos*matWorldPos;
AddNode.m_vecPlanePoint=matWorldPos.GetLoc();
m_CollisionList.Add(AddNode);
continue;
}
}
}
}
}
void CCollisionDetection::CheckSectorHeightCollision()
{
m_bHeightGradient = false;
List<vector3> vecHeightList;
m_HeightField->GetHeightFieldShadowPoly(m_vecSourcePoint,vecHeightList);
vector3 v[6];
vector3 vecNormal,vecCompareNormal,vecMove;
float fLens;
float fAngle;
vecCompareNormal=vector3(0.0f,1.0f,0.0f);
float fHeight=m_HeightField->GetHeight(m_vecSourcePoint);
float fMoveFactor;
if(fHeight+m_vecRadius.y < m_vecSourcePoint.y)
{
return;
}
else
{
m_vecSourcePoint.y=fHeight+m_vecRadius.y;
}
bool bCheckHeight=false;
for(int cPoly=0;cPoly<vecHeightList.num/3;cPoly++)
{
v[0]=vecHeightList[cPoly*3+0];
v[1]=vecHeightList[cPoly*3+1];
v[2]=vecHeightList[cPoly*3+2];
if(CIntersection::PolygonRay(vector3(m_vecSourcePoint.x,0.0f,m_vecSourcePoint.z),vector3(m_vecSourcePoint.x,120000.0f,m_vecSourcePoint.z),v,fLens))
{
bCheckHeight=true;
vecNormal=(v[1]-v[0])^(v[2]-v[1]);
vecNormal.Normalize();
fAngle=vecNormal*vecCompareNormal;
fAngle=acosf(fAngle);
/* if(fAngle> ((3.14159/180.0f)*40.0f))
{
vecMove=vecNormal-vecCompareNormal;
vecMove.Normalize();
fMoveFactor=fabsf(vecMove.y);
vecMove.y=0.0f;
vecMove=vecMove*fMoveFactor*38.0f;
m_vecVelocity+=vecMove;
}*/
if(fAngle> ((3.14159/180.0f)*38.0f))
{
vecMove=vecNormal-vecCompareNormal;
vecMove.Normalize();
if(vecMove.y > 0.0f)
vecMove.y *= -1.0f;
fMoveFactor=fabsf(vecMove.y);
//vecMove.y=0.0f;
vecMove=vecMove*fMoveFactor*35.0f;
m_vecVelocity+=vecMove;
m_vecVelocity.y = -8.0f;
m_bHeightGradient = true;
}
}
/*
vecNormal=(v[1]-v[0])^(v[2]-v[1]);
vecNormal.Normalize();
fAngle=vecNormal*vecCompareNormal;
fAngle=acosf(fAngle);
if(fAngle> ((3.14159/180.0f)*35.0f))
{
/*
v[3]=v[0]+vector3(0.0f,300.0f,0.0f);
v[4]=v[1]+vector3(0.0f,300.0f,0.0f);
v[5]=v[2]+vector3(0.0f,300.0f,0.0f);
vector3 vecPolyTest[3],vecPlaneNormal;
float fIntersection;
vecPolyTest[0]=v[0];
vecPolyTest[1]=v[1];
vecPolyTest[2]=v[3];
for(int i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
vecPolyTest[0]=v[3];
vecPolyTest[1]=v[4];
vecPolyTest[2]=v[1];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
vecPolyTest[0]=v[1];
vecPolyTest[1]=v[2];
vecPolyTest[2]=v[4];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
vecPolyTest[0]=v[4];
vecPolyTest[1]=v[5];
vecPolyTest[2]=v[2];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
vecPolyTest[0]=v[2];
vecPolyTest[1]=v[0];
vecPolyTest[2]=v[5];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
vecPolyTest[0]=v[5];
vecPolyTest[1]=v[3];
vecPolyTest[2]=v[0];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
return;
}
}
}
/*
if(CIntersection::PolygonRay(vector3(vecMovePoint.x,0.0f,vecMovePoint.z),vector3(vecMovePoint.x,120000.0f,vecMovePoint.z),v,fLens))
{
vecNormal=(v[1]-v[0])^(v[2]-v[1]);
vecNormal.Normalize();
fAngle=vecNormal*vecCompareNormal;
fAngle=acosf(fAngle);
if(fAngle> ((3.14159/180.0f)*35.0f))
{
return vecPos;
}
}
*/
}
if(bCheckHeight==false)
{
}
}
void CCollisionDetection::CheckInHouseObject(CHouseObject *pHouse,matrix matParent)
{
vector3 vecBoundBox[8];
vector3 vecPolyTest[3];
vector3 vecPlaneNormal;
matrix matTrans;
float fIntersection;
WORD wCollisionIndices[]=
{
4,1,0,
1,4,5,
5,3,1,
3,5,7,
7,2,3,
2,7,6,
6,0,2,
0,6,4
};
vector3 vecDirection[8];
vecDirection[0]=vector3(0.707f,0.0f,0.707f);
vecDirection[1]=vector3(0.707f,0.0f,-0.707f);
vecDirection[2]=vector3(-0.707f,0.0f,0.707f);
vecDirection[3]=vector3(-0.707f,0.0f,-0.707f);
vecDirection[4]=vector3(1.0f,0.0f,0.0f);
vecDirection[5]=vector3(-1.0f,0.0f,0.0f);
vecDirection[6]=vector3(0.0f,0.0f,1.0f);
vecDirection[7]=vector3(0.0f,0.0f,-1.0f);
vector3 vecLens;
matrix matTM;
for(int cObject=0;cObject<pHouse->m_ObjectList.num;cObject++)
{
matTM=pHouse->m_ObjectList[cObject]->m_TM*matParent;
vecLens=matTM.GetLoc()-m_vecSourcePoint;
if(vecLens.GetLens() > 300.0f)
continue;
vecBoundBox[0].x=pHouse->m_ObjectList[cObject]->m_vecMinBox.x;
vecBoundBox[0].y=pHouse->m_ObjectList[cObject]->m_vecMinBox.y;
vecBoundBox[0].z=pHouse->m_ObjectList[cObject]->m_vecMinBox.z;
vecBoundBox[1].x=pHouse->m_ObjectList[cObject]->m_vecMaxBox.x;
vecBoundBox[1].y=pHouse->m_ObjectList[cObject]->m_vecMinBox.y;
vecBoundBox[1].z=pHouse->m_ObjectList[cObject]->m_vecMinBox.z;
vecBoundBox[2].x=pHouse->m_ObjectList[cObject]->m_vecMinBox.x;
vecBoundBox[2].y=pHouse->m_ObjectList[cObject]->m_vecMinBox.y;
vecBoundBox[2].z=pHouse->m_ObjectList[cObject]->m_vecMaxBox.z;
vecBoundBox[3].x=pHouse->m_ObjectList[cObject]->m_vecMaxBox.x;
vecBoundBox[3].y=pHouse->m_ObjectList[cObject]->m_vecMinBox.y;
vecBoundBox[3].z=pHouse->m_ObjectList[cObject]->m_vecMaxBox.z;
vecBoundBox[4].x=pHouse->m_ObjectList[cObject]->m_vecMinBox.x;
vecBoundBox[4].y=pHouse->m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
vecBoundBox[4].z=pHouse->m_ObjectList[cObject]->m_vecMinBox.z;
vecBoundBox[5].x=pHouse->m_ObjectList[cObject]->m_vecMaxBox.x;
vecBoundBox[5].y=pHouse->m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
vecBoundBox[5].z=pHouse->m_ObjectList[cObject]->m_vecMinBox.z;
vecBoundBox[6].x=pHouse->m_ObjectList[cObject]->m_vecMinBox.x;
vecBoundBox[6].y=pHouse->m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
vecBoundBox[6].z=pHouse->m_ObjectList[cObject]->m_vecMaxBox.z;
vecBoundBox[7].x=pHouse->m_ObjectList[cObject]->m_vecMaxBox.x;
vecBoundBox[7].y=pHouse->m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
vecBoundBox[7].z=pHouse->m_ObjectList[cObject]->m_vecMaxBox.z;
for(int i=0;i<8;i++)
{
matTrans.Translation(vecBoundBox[i]);
matTrans=matTrans*matTM;
vecBoundBox[i]=matTrans.GetLoc();
}
//
//vecPolyTest[0]=vecBoundBox[4];
//vecPolyTest[1]=vecBoundBox[0];
//vecPolyTest[2]=vecBoundBox[1];
bool bAlready=false;
for(int cIndices=0;cIndices<8;cIndices++)
{
vecPolyTest[0]=vecBoundBox[wCollisionIndices[cIndices*3+0]];
vecPolyTest[1]=vecBoundBox[wCollisionIndices[cIndices*3+1]];
vecPolyTest[2]=vecBoundBox[wCollisionIndices[cIndices*3+2]];
for(i=0;i<8;i++)
{
if(CIntersection::PolygonRay(m_vecSourcePoint,m_vecSourcePoint+vecDirection[i]*m_vecRadius.x,vecPolyTest,fIntersection))
{
CCollisionList AddNode;
AddNode.m_fDistance=fIntersection;
AddNode.m_vecIntersectionPoint=m_vecSourcePoint+vecDirection[i]*fIntersection;
AddNode.m_vecPlanePoint=vecPolyTest[0];
vecPlaneNormal=(vecPolyTest[1]-vecPolyTest[0])^(vecPolyTest[2]-vecPolyTest[1]);
vecPlaneNormal.Normalize();
AddNode.m_vecPlaneNormal=vecPlaneNormal;
AddNode.m_CollisionType=CT_SIDE;
m_CollisionList.Add(AddNode);
bAlready=true;
break;
}
}
if(bAlready)
break;
}
}
}
// Zone Bound func (Zone Info <20><><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> setting)
void CCollisionDetection::SetZoneBound(float fMin,float fMax) {
m_fMinYBound = fMin;
m_fMaxYBound = fMax;
}
void CCollisionDetection::ZoneBoundApply(vector3 &vecPoint,CollisionType &CT) {
if(m_fMinYBound != -123.0f)
if(vecPoint.y <= m_fMinYBound) {
vecPoint.y = m_fMinYBound;
CT = CT_BOTTOM; // <20>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD> setting
}
if(m_fMaxYBound != -123.0f)
if(vecPoint.y >= m_fMaxYBound)
vecPoint.y = m_fMaxYBound;
}