found an easier and better way :) with much much less processing

tested and working well
Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
GreYFoXGTi 2010-08-31 15:19:01 +02:00
parent 3c0cfb73a4
commit 4dcf0d8d3b
4 changed files with 25 additions and 51 deletions

View file

@ -30,31 +30,7 @@ void CDoor::Close()
bool CDoor::HitCharacter()
{
vec2 At;
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, m_To, 1.f, At, 0);
if(Hit)
{
Hit->m_Doored = true;
vec2 Points[38];
Hit = 0;
for(int i=0;i<38;i++)
{
Points[i].x = m_Pos.x * (1 - (i/37.0)) + m_To.x * (i / 37.0);
Points[i].y = m_Pos.y * (1 - (i/37.0)) + m_To.y * (i / 37.0);
//if(i == 0 || i == 37 || i == 19) dbg_msg("CLight","(%d)\nPos(%f,%f)\nTo(%f,%f)\nPoint(%f,%f)",i,m_Pos.x,m_Pos.y,m_To.x,m_To.y,Points[i].x,Points[i].y);
}
for(int i = 0; i < 38; i++)
{
Hit = GameServer()->m_World.IntersectCharacter(Points[i], Points[i+1], 1.f, At, 0);
if(Hit)
Hit->m_Doored = true;
Hit = 0;
/*Hit = GameServer()->m_World.IntersectCharacter(Points[i+1], Points[i], 1.f, At, 0);
if(Hit)
Hit->m_Doored = true;
Hit = 0;*/
}
}
GameServer()->m_World.IntersectCharacters(m_Pos, m_To, 1.f, 0);
return true;
}

View file

@ -27,31 +27,7 @@ CLight::CLight(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length)
bool CLight::HitCharacter()
{
vec2 At;
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, m_To, 1.f, At, 0);
if(Hit)
{
Hit->Freeze(Server()->TickSpeed()*3);
vec2 Points[38];
Hit = 0;
for(int i=0;i<38;i++)
{
Points[i].x = m_Pos.x * (1 - (i/37.0)) + m_To.x * (i / 37.0);
Points[i].y = m_Pos.y * (1 - (i/37.0)) + m_To.y * (i / 37.0);
//if(i == 0 || i == 37 || i == 19) dbg_msg("CLight","(%d)\nPos(%f,%f)\nTo(%f,%f)\nPoint(%f,%f)",i,m_Pos.x,m_Pos.y,m_To.x,m_To.y,Points[i].x,Points[i].y);
}
for(int i = 0; i < 38; i++)
{
Hit = GameServer()->m_World.IntersectCharacter(Points[i], Points[i+1], 1.f, At, 0);
if(Hit)
Hit->Freeze(Server()->TickSpeed()*3);
Hit = 0;
/*Hit = GameServer()->m_World.IntersectCharacter(Points[i+1], Points[i], 1.f, At, 0);
if(Hit)
Hit->Freeze(Server()->TickSpeed()*3);
Hit = 0;*/
}
}
GameServer()->m_World.IntersectCharacters(m_Pos, m_To, 1.f, 1);
return true;
}

View file

@ -198,6 +198,17 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v
return pClosest;
}
void CGameWorld::IntersectCharacters(vec2 Pos0, vec2 Pos1, float Radius, int Type)
{
CCharacter *p = (CCharacter *)FindFirst(NETOBJTYPE_CHARACTER);
for(; p; p = (CCharacter *)p->TypeNext())
{
vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, p->m_Pos);
float Len = distance(p->m_Pos, IntersectPos);
if(Len < p->m_ProximityRadius+Radius)
(Type)?p->Freeze(Server()->TickSpeed()*3):p->m_Doored = true;
}
}
CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotThis)
{

View file

@ -65,13 +65,24 @@ public:
Function: interserct_CCharacter
Finds the closest CCharacter that intersects the line.
Arguments:
pos0 - Start position
pos2 - End position
radius - How for from the line the CCharacter is allowed to be.
Type - cdoor=0 clight=1
*/
void IntersectCharacters(vec2 Pos0, vec2 Pos1, float Radius, int Type);
/*
Function: InterserctCharacters
Finds the CCharacters that intersects the line. // made for types lasers=1 and doors=0
Arguments:
pos0 - Start position
pos2 - End position
radius - How for from the line the CCharacter is allowed to be.
new_pos - Intersection position
notthis - Entity to ignore intersecting with
Returns:
Returns a pointer to the closest hit or NULL of there is no intersection.
*/