/*
 * Test if a ray hits sphere.
 */
inline static BOOL RayHitsSphere(
  const FLOAT3D &vStart,
  const FLOAT3D &vEnd,
  const FLOAT3D &vSphereCenter,
  const FLOAT fSphereRadius,
  FLOAT &fDistance)
{
  const FLOAT3D vSphereCenterToStart = vStart - vSphereCenter;
  const FLOAT3D vStartToEnd          = vEnd - vStart;
  // calculate discriminant for intersection parameters
  const FLOAT fP = ((vStartToEnd%vSphereCenterToStart)/(vStartToEnd%vStartToEnd));
  const FLOAT fQ = (((vSphereCenterToStart%vSphereCenterToStart)
    - (fSphereRadius*fSphereRadius))/(vStartToEnd%vStartToEnd));
  const FLOAT fD = fP*fP-fQ;
  // if it is less than zero
  if (fD<0) {
    // no collision will occur
    return FALSE;
  }
  // calculate intersection parameters
  const FLOAT fSqrtD = sqrt(fD);
  const FLOAT fLambda1 = -fP+fSqrtD;
  const FLOAT fLambda2 = -fP-fSqrtD;
  // use lower one
  const FLOAT fMinLambda = Min(fLambda1, fLambda2);
  // calculate distance from parameter
  fDistance = fMinLambda*vStartToEnd.Length();
  return TRUE;
}
Esempio n. 2
0
CTString GetItemValue(CEntity *pen, INDEX iColumn, INDEX &iFormat)
{
  ASSERT(pen!=NULL);
  if(pen==NULL) return CTString("");
  CEntityClass *pecEntityClass = pen->GetClass();
  CDLLEntityClass *pdllecDllEntityClass = pecEntityClass->ec_pdecDLLClass;
  FLOAT3D vOrigin = pen->GetPlacement().pl_PositionVector;
  ANGLE3D vAngles = pen->GetPlacement().pl_OrientationAngle;
  CTString strResult="";
  iFormat=PDF_STRING;
  
  switch( iColumn)
  {
  case COLUMN_ID:
  {
    strResult.PrintF("%d", pen->en_ulID);
    iFormat=PDF_INDEX;
    break;
  }
  case COLUMN_CLASS:
  {
    strResult=pdllecDllEntityClass->dec_strName;
    break;
  }
  case COLUMN_NAME:
  {
    strResult=pen->GetName();
    break;
  }
  case COLUMN_DESCRIPTION:
  {
    strResult=pen->GetDescription();
    break;
  }
  case COLUMN_SECTOR_NAME:
  {
    CBrushSector *pbsc = pen->GetFirstSectorWithName();
    if( pbsc!=NULL)
    {
      strResult=pbsc->bsc_strName;
    }
    break;
  }
  case COLUMN_X:
  {
    strResult.PrintF("%g", vOrigin(1));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_Y:
  {
    strResult.PrintF("%g", vOrigin(2));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_Z:
  {
    strResult.PrintF("%g", vOrigin(3));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_H:
  {
    strResult.PrintF("%g", vAngles(1));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_P:
  {
    strResult.PrintF("%g", vAngles(2));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_B:
  {
    strResult.PrintF("%g", vAngles(3));
    iFormat=PDF_FLOAT;
    break;
  }
// 강동민 수정 시작
	case COLUMN_MOBINDEX:		
		{
			if(pen->IsEnemy())
			{	
				CEntityProperty &epPropertyMobType = *(pen->PropertyForTypeAndID(CEntityProperty::EPT_INDEX, 91));		// Zone Flag
				INDEX iEnemyType = ENTITYPROPERTY( &*pen, epPropertyMobType.ep_slOffset, INDEX);

				strResult.PrintF("%d", iEnemyType);
				iFormat=PDF_INDEX;
			}
			break;
		}
	case COLUMN_REGEN:
		{
			if(pen->IsEnemy())
			{
				CEntityProperty &epPropertyRegenTime = *(pen->PropertyForTypeAndID(CEntityProperty::EPT_INDEX, 21));		// Zone Flag
				INDEX iRegenSec = ENTITYPROPERTY( &*pen, epPropertyRegenTime.ep_slOffset, INDEX);

				strResult.PrintF("%d", iRegenSec);
				iFormat=PDF_INDEX;
			}
			break;
		}
// 강동민 수정 끝
	case COLUMN_RAIDOBJ:
		{
			if (pen->GetRaidObject())
			{
				strResult = CTString("RaidObject");
			}
			break;
		}
  case COLUMN_DISTANCE:
  {
    if( _penForDistanceSort != NULL)
    {
      FLOAT3D vSelectedOrigin = _penForDistanceSort->GetPlacement().pl_PositionVector;
      FLOAT3D fDistance = vOrigin-vSelectedOrigin;
      strResult.PrintF("%g", fDistance.Length());
      iFormat=PDF_FLOAT;
    }
    break;
  }
  case COLUMN_SPAWN_FLAGS:
  {
    strResult.PrintF("0x%08X", pen->GetSpawnFlags());
    break;
  }
  // entity properties
  default:
  {
    CDLLEntityClass *pdecDLLClass = pen->GetClass()->ec_pdecDLLClass;
    // for all classes in hierarchy of this entity
    INDEX iPropertyOrder=0;
    for(;pdecDLLClass!=NULL; pdecDLLClass = pdecDLLClass->dec_pdecBase)
    {
      // for all properties
      for(INDEX iProperty=0; iProperty<pdecDLLClass->dec_ctProperties; iProperty++)
      {
        CEntityProperty *pepProperty = &pdecDLLClass->dec_aepProperties[iProperty];
        if( pepProperty->ep_strName!=CTString(""))
        {
          if( iPropertyOrder==iColumn-COLUMN_PROPERTY_START)
          {
            strResult=GetPropertyValue(pen, pepProperty, iFormat);
            return strResult;
          }
          iPropertyOrder++;
        }
      }
    }
  }
  }
  return strResult;
}
CTString GetItemValue(CEntity *pen, INDEX iColumn, INDEX &iFormat)
{
  ASSERT(pen!=NULL);
  if(pen==NULL) return CTString("");
  CEntityClass *pecEntityClass = pen->GetClass();
  CDLLEntityClass *pdllecDllEntityClass = pecEntityClass->ec_pdecDLLClass;
  FLOAT3D vOrigin = pen->GetPlacement().pl_PositionVector;
  ANGLE3D vAngles = pen->GetPlacement().pl_OrientationAngle;
  CTString strResult="";
  iFormat=PDF_STRING;
  
  switch( iColumn)
  {
  case COLUMN_INDEX:
  {
    INDEX iIndex=dcEntities.GetIndex(pen);
    strResult.PrintF("%d", FLOAT(iIndex));
    iFormat=PDF_INDEX;
    break;
  }
  case COLUMN_CLASS:
  {
    strResult=pdllecDllEntityClass->dec_strName;
    break;
  }
  case COLUMN_NAME:
  {
    strResult=pen->GetName();
    break;
  }
  case COLUMN_DESCRIPTION:
  {
    strResult=pen->GetDescription();
    break;
  }
  case COLUMN_SECTOR_NAME:
  {
    CBrushSector *pbsc = pen->GetFirstSectorWithName();
    if( pbsc!=NULL)
    {
      strResult=pbsc->bsc_strName;
    }
    break;
  }
  case COLUMN_X:
  {
    strResult.PrintF("%g", vOrigin(1));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_Y:
  {
    strResult.PrintF("%g", vOrigin(2));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_Z:
  {
    strResult.PrintF("%g", vOrigin(3));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_H:
  {
    strResult.PrintF("%g", vAngles(1));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_P:
  {
    strResult.PrintF("%g", vAngles(2));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_B:
  {
    strResult.PrintF("%g", vAngles(3));
    iFormat=PDF_FLOAT;
    break;
  }
  case COLUMN_DISTANCE:
  {
    if( _penForDistanceSort != NULL)
    {
      FLOAT3D vSelectedOrigin = _penForDistanceSort->GetPlacement().pl_PositionVector;
      FLOAT3D fDistance = vOrigin-vSelectedOrigin;
      strResult.PrintF("%g", fDistance.Length());
      iFormat=PDF_FLOAT;
    }
    break;
  }
  case COLUMN_SPAWN_FLAGS:
  {
    strResult.PrintF("0x%08X", pen->GetSpawnFlags());
    break;
  }
  // entity properties
  default:
  {
    CDLLEntityClass *pdecDLLClass = pen->GetClass()->ec_pdecDLLClass;
    // for all classes in hierarchy of this entity
    INDEX iPropertyOrder=0;
    for(;pdecDLLClass!=NULL; pdecDLLClass = pdecDLLClass->dec_pdecBase)
    {
      // for all properties
      for(INDEX iProperty=0; iProperty<pdecDLLClass->dec_ctProperties; iProperty++)
      {
        CEntityProperty *pepProperty = &pdecDLLClass->dec_aepProperties[iProperty];
        if( pepProperty->ep_strName!=CTString(""))
        {
          if( iPropertyOrder==iColumn-COLUMN_PROPERTY_START)
          {
            strResult=GetPropertyValue(pen, pepProperty, iFormat);
            return strResult;
          }
          iPropertyOrder++;
        }
      }
    }
  }
  }
  return strResult;
}