void CHuman::Update(float fElapsedTime)
{
	CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}
}
Example #2
0
void CGuard::Update(float fElapsedTime)
{

	if(CheckForPlayer())
	{
		ComputeMovement(fElapsedTime);
		this->addTime(fElapsedTime);
		CBase::Update(fElapsedTime);
	}
	else
		CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}

	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1))
	{
		IsUndead = true;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" );
	}
	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2))
	{
		IsUndead = false;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" );
	}
}
Example #3
0
void CBurnBot::CollisionResponse(IBaseObject* pObj)
{
	int nType = pObj->GetID();

	Sphere tempSphere = pObj->GetSphere();
	D3DXVECTOR3 V = tempSphere.m_Center - this->GetSphere().m_Center;
	float Mag = D3DXVec3Length(&V);
	float Distance = tempSphere.m_Radius + GetSphere().m_Radius;
	float X = Distance/Mag + EPISILON;
	V = V * X;
	D3DXMATRIX tempMat = pObj->GetMatrix();
	if(nType == OBJ_TUNNEL)
		tempMat._43 *= 0.85f;
	D3DXMATRIX tempSetMat = GetMatrix();
	tempSetMat._41 = tempMat._41 - V.x;
	tempSetMat._43 = tempMat._43 - V.z;
	this->SetMatrix(tempSetMat);


	if( nType == OBJ_PLAYER )
	{
		if(!m_bCloseToTarget)
		{
			m_bCloseToTarget = true;
			m_fExplodeTimer = BURN_CHARGETIME;
			SetBeingHit(BURNEXPLODE);
			WwiseNS::PlaySFX(WwiseNS::EVENT_SOUND_BURNALERT);
			ChangeAnimation(0);
		}
	}
}
Example #4
0
bool CBurnBot::CheckCollision(IBaseObject* pObj)
{
	if(pObj == this)
		return false;

	if(!pObj->GetAlive())
		return false;

	if(!GetAlive())
		return false;

	int nType = pObj->GetID();

	bool bAvoid = nType == OBJ_SMASH || nType == OBJ_SPIDER || nType >= OBJ_VAT && nType <= OBJ_BARREL || nType == OBJ_BOSSINV || nType == OBJ_INVERSION;

	if( bAvoid )
		Utilities::CheckAvoid(this, pObj);

	if(nType >= OBJ_TRASH && nType <= OBJ_AIFIST ||  nType == OBJ_PLAYER ||  nType >= OBJ_VAT && nType <= OBJ_BARREL
		|| nType == OBJ_INVERSION || OBJ_TUNNEL)
	{
		if(SphereToSphere(GetSphere(), pObj->GetSphere()))
		{
			if(OBJ_TUNNEL)
				CollisionResponse(pObj);
			else
				AddToReactVector(pObj);
			//CollisionResponse(pObj);
			return true;
		}
	}

	return false;
}
Example #5
0
//-----------------------------------------------------------------------------
// Name: Bound::GetMaxRadius
// Desc: Computes the maximum radius of the bound.
//-----------------------------------------------------------------------------
FLOAT Bound::GetMaxRadius() const
{
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
        {
            float Radius = GetSphere().Radius;
            return Radius;
        }

        case Bound::Frustum_Bound:
        {
            FLOAT MaxZ = abs( GetFrustum().Far - GetFrustum().Near );
            FLOAT MaxX = abs( GetFrustum().LeftSlope * GetFrustum().Far - GetFrustum().RightSlope * GetFrustum().Far );
            FLOAT MaxY = abs( GetFrustum().TopSlope * GetFrustum().Far - GetFrustum().BottomSlope * GetFrustum().Far );
            return max( MaxZ, max( MaxX, MaxY ) );
        }

        case Bound::OBB_Bound:
        {
            XMVECTOR v = XMVector3Length( XMLoadFloat3( &( GetObb().Extents ) ) );
            return XMVectorGetX( v );
        }
        case Bound::AABB_Bound:
        {
            XMVECTOR v = XMVector3Length( XMLoadFloat3( &( GetAabb().Extents ) ) );
            return XMVectorGetX( v );
        }
        case Bound::No_Bound:
            break;
    }

    return 0.0f;
}
Example #6
0
void CBuilding3::Collapse(float timeinseconds, float fallingspeed)
{
   m_TimeStartedCollapse = g_time;

   const Sphere* pObjectSphere = GetSphere();
   float Building3Radius = pObjectSphere->Radius; 

   m_TimeEndCollapse = m_TimeStartedCollapse + abs((Building3Radius / fallingspeed)* 1.3f);

   m_FallingSpeed = fallingspeed;

   m_CurBuilding3State = FALLING;

   m_Building3Falling = g_ParticleManager.ObtainSystem();

   if(OnlyOnce)
   {
      if(GameMain.m_CurrentBuildingCom == GameMain.COM_BUILDINGNONE)
         GameMain.m_CurrentBuildingCom = GameMain.COM_BUILDINGDEAD;
      OnlyOnce = false;
   }

   CObjFrame TempFrame;
   TempFrame = *GetFrame(0);
   TempFrame.MoveUp(-Building3Radius * 0.6f);
   CVector3f Building3Base = *TempFrame.GetPosition();

   if(m_Building3Falling)
   {
      m_Building3Falling->m_IsBuilding = true;
      g_ParticleManager.CreateSystem(m_Building3Falling, Building3Base, NULL, g_ParticleManager.BUILDING_FALLING, LOD_BOTH, 200.0f, 500.0f);
   }
   else
    bool debug = true;
}
Example #7
0
static errcode GetObject(FILE * dfile, SceneHandle scene) {
  char objtype[80];
 
  fscanf(dfile, "%s", objtype);
  if (!stringcmp(objtype, "END_SCENE")) {
    return PARSEEOF; /* end parsing */
  }
  if (!stringcmp(objtype, "TEXDEF")) {
    return GetTexDef(dfile);
  }	
  if (!stringcmp(objtype, "TEXALIAS")) {
    return GetTexAlias(dfile);
  }
  if (!stringcmp(objtype, "BACKGROUND")) {
    return GetBackGnd(dfile);
  }
  if (!stringcmp(objtype, "CYLINDER")) {
    return GetCylinder(dfile);
  }
  if (!stringcmp(objtype, "FCYLINDER")) {
    return GetFCylinder(dfile);
  }
  if (!stringcmp(objtype, "POLYCYLINDER")) {
    return GetPolyCylinder(dfile);
  }
  if (!stringcmp(objtype, "SPHERE")) {
    return GetSphere(dfile);
  }
  if (!stringcmp(objtype, "PLANE")) {
    return GetPlane(dfile);
  }
  if (!stringcmp(objtype, "RING")) {
    return GetRing(dfile);
  }
  if (!stringcmp(objtype, "BOX")) {
    return GetBox(dfile);
  }
  if (!stringcmp(objtype, "SCALARVOL")) {
    return GetVol(dfile);
  }
  if (!stringcmp(objtype, "TRI")) {
    return GetTri(dfile);
  }
  if (!stringcmp(objtype, "STRI")) {
    return GetSTri(dfile);
  }
  if (!stringcmp(objtype, "LIGHT")) {
    return GetLight(dfile);
  }
  if (!stringcmp(objtype, "SCAPE")) {
    return GetLandScape(dfile);
  }
  if (!stringcmp(objtype, "TPOLYFILE")) {
    return GetTPolyFile(dfile);
  }

  fprintf(stderr, "Found bad token: %s expected an object type\n", objtype);
  return PARSEBADSYNTAX;
}
    void DiSphereColliderControllerObj::InitPropertyTable()
    {
        InitBasePropertyTable();
        
        DiPropertyGroup* g = DI_NEW DiPropertyGroup("Sphere Collider");
        
        g->AddProperty("Radius",          DI_NEW DiFloatProperty([&](){ return GetSphere()->GetRadius(); },
                                                                 [&](float& val){ GetSphere()->SetRadius(val);}));
        
        g->AddProperty("Inner Collision", DI_NEW DiBoolProperty([&](){ return GetSphere()->IsInnerCollision(); },
                                                                [&](bool& val){ GetSphere()->SetInnerCollision(val);}));
        
        g->CreateUI();
        
        mPropGroups.push_back(g);

    }
Example #9
0
//-----------------------------------------------------------------------------
// Name: Bound::operator*
// Desc: transforms the bound by the current matrix
//-----------------------------------------------------------------------------
Bound Bound::operator*( CXMMATRIX World ) const
{
    //$OPTIMIZE: store matrix decomposed    
    XMVECTOR Translation = World.r[3];
    FLOAT Scale = XMVectorGetX( XMVector3Length( World.r[2] ) );
    XMVECTOR Rotation = XMQuaternionNormalize( XMQuaternionRotationMatrix( World ) );

    // switch based off this bounds type and call the correct
    // bound transform function
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
        {
            Sphere WorldSphere = GetSphere();
            TransformSphere( &WorldSphere,
                             &WorldSphere,
                             Scale,
                             Rotation,
                             Translation );
            return Bound( WorldSphere );
        }
        case Bound::Frustum_Bound:
        {
            Frustum WorldFrustum = GetFrustum();
            TransformFrustum( &WorldFrustum,
                              &WorldFrustum,
                              Scale,
                              Rotation,
                              Translation );
            return Bound( WorldFrustum );
        }
        case Bound::OBB_Bound:
        {
            OrientedBox WorldObb = GetObb();
            TransformOrientedBox( &WorldObb,
                                  &WorldObb,
                                  Scale,
                                  Rotation,
                                  Translation );
            return Bound( WorldObb );
        }
        case Bound::AABB_Bound:
        {
            AxisAlignedBox WorldAabb = GetAabb();
            TransformAxisAlignedBox( &WorldAabb,
                                     &WorldAabb,
                                     Scale,
                                     Rotation,
                                     Translation );
            return Bound( WorldAabb );
        }
        case Bound::No_Bound:
            return Bound();
    }

    return Bound();
}
Example #10
0
VOID Bound::Merge( const Bound& Other )
{
    Sphere OtherSphere;
    OtherSphere.Center = Other.GetCenter();
    OtherSphere.Radius = Other.GetMaxRadius();

    if( m_Type == Bound::No_Bound )
    {
        SetSphere( OtherSphere );
        return;
    }

    Sphere ThisSphere;
    if( m_Type != Bound::Sphere_Bound )
    {
        // convert this bound into a sphere
        ThisSphere.Center = GetCenter();
        ThisSphere.Radius = GetMaxRadius();
    }
    else
    {
        ThisSphere = GetSphere();
    }

    XMVECTOR vThisCenter = XMLoadFloat3( &ThisSphere.Center );
    XMVECTOR vOtherCenter = XMLoadFloat3( &OtherSphere.Center );
    XMVECTOR vThisToOther = XMVectorSubtract( vOtherCenter, vThisCenter );
    XMVECTOR vDistance = XMVector3LengthEst( vThisToOther );

    FLOAT fCombinedDiameter = XMVectorGetX( vDistance ) + ThisSphere.Radius + OtherSphere.Radius;
    if( fCombinedDiameter <= ( ThisSphere.Radius * 2 ) )
    {
        SetSphere( ThisSphere );
        return;
    }
    if( fCombinedDiameter <= ( OtherSphere.Radius * 2 ) )
    {
        SetSphere( OtherSphere );
        return;
    }

    XMVECTOR vDirectionNorm = XMVector3Normalize( vThisToOther );

    XMVECTOR vRadius = XMVectorSet( ThisSphere.Radius, OtherSphere.Radius, 0, 0 );
    XMVECTOR vThisRadius = XMVectorSplatX( vRadius );
    XMVECTOR vOtherRadius = XMVectorSplatY( vRadius );
    XMVECTOR vCombinedDiameter = vThisRadius + vDistance + vOtherRadius;
    XMVECTOR vMaxDiameter = XMVectorMax( vCombinedDiameter, vThisRadius * 2 );
    vMaxDiameter = XMVectorMax( vMaxDiameter, vOtherRadius * 2 );
    XMVECTOR vMaxRadius = vMaxDiameter * 0.5f;
    ThisSphere.Radius = XMVectorGetX( vMaxRadius );
    vMaxRadius -= vThisRadius;
    XMVECTOR vCombinedCenter = vThisCenter + vMaxRadius * vDirectionNorm;
    XMStoreFloat3( &ThisSphere.Center, vCombinedCenter );
    SetSphere( ThisSphere );
}
Example #11
0
void CSmashBot::CollisionResponse(IBaseObject* pObj)
{
	int nType = pObj->GetID();

	if(nType == OBJ_SMASH || nType == OBJ_SPIDER || nType == OBJ_INVERSION || nType == OBJ_TUNNEL)
	{
		Sphere tempSphere = pObj->GetSphere();
		D3DXVECTOR3 V = tempSphere.m_Center - this->GetSphere().m_Center;
		float Mag = D3DXVec3Length(&V);
		float Distance = tempSphere.m_Radius + GetSphere().m_Radius;
		float X = Distance/Mag + EPISILON;
		V = V * (X + 0.015f);
		D3DXMATRIX tempMat = pObj->GetMatrix();
		D3DXMATRIX tempSetMat = GetMatrix();
		if(nType == OBJ_TUNNEL)
			tempMat._43 *= 0.85f;
		tempSetMat._41 = tempMat._41 - V.x;
		tempSetMat._43 = tempMat._43 - V.z;
		this->SetMatrix(tempSetMat);
	}

	if(nType == OBJ_PLAYER)
	{
		//m_bIsSmashing = true;
		Sphere tempSphere = ((CPlayerObject*)pObj)->GetSphere();
		D3DXVECTOR3 V =  this->GetSphere().m_Center - tempSphere.m_Center;
		float Mag = D3DXVec3Length(&V);
		float Distance = tempSphere.m_Radius + GetSphere().m_Radius;
		float X = Distance/Mag + EPISILON;
		V = V * (X + 0.025f);
		D3DXMATRIX tempMat = pObj->GetMatrix();
		D3DXMATRIX tempSetMat = GetMatrix();
		tempMat._41 = tempSetMat._41 - V.x;
		tempMat._43 = tempSetMat._43 - V.z;
		pObj->SetMatrix(tempMat);
	}

	if(nType >= OBJ_VAT && nType <= OBJ_BARREL)
		pObj->SetHealth(0);


	// TODO - UPDATE DAMAGE AS WEAPON GET DAMAGE WHEN WEPS ADDED
}
Example #12
0
	bool    BoundingSphere::IsIntersect( BoundingVolume * pBound )
	{
		switch ( pBound->GetBoundType() )
		{
		case Bounding_Box:
			{
				IntrBox3Sphere3f kIntr( ( (BoundingBox *) pBound )->GetBox(), GetSphere() );
				return kIntr.Test();
				break;
			}
		case Bounding_Sphere:
			{
				IntrSphere3Sphere3f kIntr( ( (BoundingSphere *) pBound )->GetSphere(), GetSphere() );
				return kIntr.Test();
				break;
			}
		default:
			break;
		}

		return false;
	}
void CExplodingBullet::Update(float fDelta)
{
	float fRadius = GetSphere().m_Radius;
	fRadius += fDelta * m_fSpeed;

	if( fRadius > m_fMaxRadius )
	{
		CGame::GetInstance()->GetOF()->Destroy(this);
		SetAlive(false);
		m_lEnemies.clear();
		return;
	}

	SetRadius(fRadius);
}
Example #14
0
bool CConvoy::IsAtCurrentWaypoint()
{
   bool Result = false;

   CVector3f Waypt = *(m_Waypoints[m_CurrentWaypointIndex].m_Frame.GetPosition());
   CVector3f UnitPos = GetSphere()->Center;

   Waypt.y = 0.0f;
   UnitPos.y = 0.0f;

   float Dist = DistanceSquare(&Waypt, &UnitPos);

   if (Dist < 30.0f * 30.0f)
      Result = true;

   return Result;
}
Example #15
0
//-----------------------------------------------------------------------------
// Name: Bound::Collide
// Desc: collides this bound with a frustum
//-----------------------------------------------------------------------------
BOOL Bound::Collide( const Frustum& Frustum ) const
{
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
            return ( BOOL )IntersectSphereFrustum( &GetSphere(), &Frustum );
        case Bound::Frustum_Bound:
            return ( BOOL )IntersectFrustumFrustum( &GetFrustum(), &Frustum );
        case Bound::OBB_Bound:
            return ( BOOL )IntersectOrientedBoxFrustum( &GetObb(), &Frustum );
        case Bound::AABB_Bound:
            return ( BOOL )IntersectAxisAlignedBoxFrustum( &GetAabb(), &Frustum );
        case Bound::No_Bound:
            return TRUE;
    }

    return FALSE;
}
Example #16
0
//-----------------------------------------------------------------------------
// Name: Bound::Collide
// Desc: collides this bound with a sphere
//-----------------------------------------------------------------------------
BOOL Bound::Collide( const Sphere& Sphere ) const
{
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
            return IntersectSphereSphere( &GetSphere(), &Sphere );
        case Bound::Frustum_Bound:
            return ( BOOL )IntersectSphereFrustum( &Sphere, &GetFrustum() );
        case Bound::OBB_Bound:
            return IntersectSphereOrientedBox( &Sphere, &GetObb() );
        case Bound::AABB_Bound:
            return IntersectSphereAxisAlignedBox( &Sphere, &GetAabb() );
        case Bound::No_Bound:
            return TRUE;
    }

    return FALSE;
}
Example #17
0
//-----------------------------------------------------------------------------
// Name: Bound::GetCenter
// Desc: Gets the center of the bound.
//-----------------------------------------------------------------------------
XMFLOAT3 Bound::GetCenter() const
{
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
            return *( ( XMFLOAT3* )&GetSphere().Center );
        case Bound::Frustum_Bound:
            return *( ( XMFLOAT3* )&GetFrustum().Origin );
        case Bound::OBB_Bound:
            return *( ( XMFLOAT3* )&GetObb().Center );
        case Bound::AABB_Bound:
            return *( ( XMFLOAT3* )&GetAabb().Center );
        case Bound::No_Bound:
            break;
    }

    return XMFLOAT3( 0.0f, 0.0f, 0.0f );
}
Example #18
0
//-----------------------------------------------------------------------------
// Name: Bound::Collide
// Desc: collides this bound with an obb
//-----------------------------------------------------------------------------
BOOL Bound::Collide( const OrientedBox& Obb ) const
{
    // switch on bound type and call the correct intersection function
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
            return IntersectSphereOrientedBox( &GetSphere(), &Obb );
        case Bound::Frustum_Bound:
            return ( BOOL )IntersectOrientedBoxFrustum( &Obb, &GetFrustum() );
        case Bound::OBB_Bound:
            return IntersectOrientedBoxOrientedBox( &GetObb(), &Obb );
        case Bound::AABB_Bound:
            return IntersectAxisAlignedBoxOrientedBox( &GetAabb(), &Obb );
        case Bound::No_Bound:
            return TRUE;
    }

    return FALSE;
}
Example #19
0
CGameObject* CEnemy::GetWhoIsAroundMe2(float Size)
{
   CGameObject* firstAllyInProximity = NULL;
   CGameObject* currentCloseGuy;
   CGameObject* currentObj = g_CollisionAvoidanceList;

   if (g_CollisionAvoidanceList == NULL)
      return NULL;

   const Sphere* es = GetSphere();
   Sphere MySphere = *es;

   MySphere.Radius = Size;

   do 
   {
      if (currentObj == this)
      {
         currentObj = currentObj->m_CollisionAvoidanceListNext;
         continue;
      }

      if (SphereToSphere(&MySphere, currentObj->GetSphere()))
      {
         if (firstAllyInProximity == NULL)
         {
            firstAllyInProximity = currentObj;
            currentCloseGuy  = currentObj;
         }
         else
         {
            currentCloseGuy->m_GuyNextToMe = currentObj;
            currentCloseGuy = currentObj;
         }
      }

   	currentObj = currentObj->m_CollisionAvoidanceListNext;

   } while(currentObj != NULL);

   return firstAllyInProximity;
}
Example #20
0
/*****************************************
generate a SVM classification problem
input: the average activation matrix array, the number of blocks, the blocks, the current voxel id, the number of training samples, the location info
output: the SVM problem described in the libSVM recognizable format
******************************************/
SVMProblem* GetSearchlightSVMProblem(RawMatrix** avg_matrices, Trial* trials, int curVoxel, int nTrainings, Point* pts)
{
  SVMProblem* prob = new SVMProblem();
  prob->l = nTrainings;
  prob->y = new double[nTrainings];
  prob->x = new SVMNode*[nTrainings];
  int nVoxels = avg_matrices[0]->row;
  int* voxels = GetSphere(curVoxel, nVoxels, pts);
  int nSphereVoxels = 33;
  #pragma omp parallel for
  for (int i=0; i<nTrainings; i++)
  {
    //cout<<trials[i].tid<<" "<<trials[i].sid<<" "<<trials[i].label<<" "<<trials[i].sc<<" "<<trials[i].ec<<endl;
    prob->y[i] = trials[i].label;
    prob->x[i] = new SVMNode[nSphereVoxels+1];
    int sid = trials[i].sid;
    int j;
    for (j=0; j<nSphereVoxels; j++)
    {
      prob->x[i][j].index = j+1;
      int col = avg_matrices[sid]->col;
      int offset = trials[i].tid_withinsubj;
      if (voxels[j]!=-1)
      {
        prob->x[i][j].value = avg_matrices[sid]->matrix[voxels[j]*col+offset];
      }
      else
      {
        prob->x[i][j].value = 0;
      }
      //cout<<voxels[j]; getchar();
    }
    prob->x[i][j].index = -1;
  }
  delete[] voxels;
  return prob;
}
static errcode GetObject(parsehandle * ph, SceneHandle scene) {
  char objtype[256];
 
  if (fscanf(ph->ifp, "%s", objtype) == EOF) {
    return PARSEEOF;
  }
  if (!stringcmp(objtype, "TRI")) {
    return GetTri(ph, scene);
  }
  if (!stringcmp(objtype, "STRI")) {
    return GetSTri(ph, scene);
  }
  if (!stringcmp(objtype, "VCSTRI")) {
    return GetVCSTri(ph, scene);
  }
  if (!stringcmp(objtype, "SPHERE")) {
    return GetSphere(ph, scene);
  }
  if (!stringcmp(objtype, "FCYLINDER")) {
    return GetFCylinder(ph, scene);
  }
  if (!stringcmp(objtype, "RING")) {
    return GetRing(ph, scene);
  }
  if (!stringcmp(objtype, "POLYCYLINDER")) {
    return GetPolyCylinder(ph, scene);
  }
  if (!stringcmp(objtype, "CYLINDER")) {
    return GetCylinder(ph, scene);
  }
  if (!stringcmp(objtype, "PLANE")) {
    return GetPlane(ph, scene);
  }
  if (!stringcmp(objtype, "BOX")) {
    return GetBox(ph, scene);
  }
  if (!stringcmp(objtype, "SCALARVOL")) {
    return GetVol(ph, scene);
  }
  if (!stringcmp(objtype, "TEXDEF")) {
    return GetTexDef(ph, scene);
  }	
  if (!stringcmp(objtype, "TEXALIAS")) {
    return GetTexAlias(ph);
  }
  if (!stringcmp(objtype, "LIGHT")) {
    return GetLight(ph, scene);
  }
  if (!stringcmp(objtype, "DIRECTIONAL_LIGHT")) {
    return GetDirLight(ph, scene);
  }
  if (!stringcmp(objtype, "SPOTLIGHT")) {
    return GetSpotLight(ph, scene);
  }
  if (!stringcmp(objtype, "SCAPE")) {
    return GetLandScape(ph, scene);
  }
  if (!stringcmp(objtype, "CAMERA")) {
    return GetCamera(ph, scene);
  }
  if (!stringcmp(objtype, "TPOLYFILE")) {
    return GetTPolyFile(ph, scene);
  }
  if (!stringcmp(objtype, "MGFFILE")) {
#ifdef USELIBMGF
    return GetMGFFile(ph, scene);
#else
    printf("MGF File Parsing is not available in this build.\n");
    return PARSEBADSYNTAX;
#endif
  }
  if (!stringcmp(objtype, "#")) {
    int c;
    while (1) {
      c=fgetc(ph->ifp);
      if (c == EOF || c == '\n')    /* eat comment text */
        return PARSENOERR;
    } 
  }
  if (!stringcmp(objtype, "BACKGROUND")) {
    return GetBackGnd(ph, scene);
  }
  if (!stringcmp(objtype, "FOG")) {
    return GetFog(ph, scene);
  }
  if (!stringcmp(objtype, "INCLUDE")) {
    char includefile[FILENAME_MAX];
    fscanf(ph->ifp, "%s", includefile);
    return ReadIncludeFile(ph, includefile, scene);
  }
  if (!stringcmp(objtype, "START_CLIPGROUP")) {
    return GetClipGroup(ph, scene);
  }
  if (!stringcmp(objtype, "END_CLIPGROUP")) {
    return GetClipGroupEnd(ph, scene);
  }
  if (!stringcmp(objtype, "END_SCENE")) {
    return PARSEEOF; /* end parsing */
  }

  PrintSyntaxError(ph, "an object or other declaration", objtype);

  return PARSEBADSYNTAX;
}
Example #22
0
void CEnemy::TargetEnemy()
{
   CGameObject* pCurrentObj = GetWhoIsAroundMe2(400.0f);
   CGameObject* pFirstGuy = pCurrentObj;

   m_CurrentTarget = &g_Player;

   float Dist = DistanceSquare(&(GetSphere()->Center), &(g_Player.GetSphere()->Center));
   float TempDist;

   if (pCurrentObj != NULL)
   {
      do 
      {  
         switch(pCurrentObj->GetType())
         {
            case OBJ_BUILDING:
            case OBJ_BUILDING2:
            case OBJ_BUILDING3:
            {
               TempDist = DistanceSquare(&(GetSphere()->Center), &(pCurrentObj->GetSphere()->Center));
               if (TempDist < Dist)
               {
                  m_CurrentTarget = pCurrentObj;
                  Dist = TempDist;
               }

               break;
            };

            case OBJ_FTURRET:
            {
               TempDist = DistanceSquare(&(GetSphere()->Center), &(pCurrentObj->GetSphere()->Center));
               if (TempDist < Dist)
               {
                  m_CurrentTarget = pCurrentObj;
                  Dist = TempDist;
               }
               break;
            };

            case OBJ_CONVOY:
            {
               TempDist = DistanceSquare(&(GetSphere()->Center), &(pCurrentObj->GetSphere()->Center));
               if (TempDist < Dist)
               {
                  m_CurrentTarget = pCurrentObj;
                  Dist = TempDist;
               }
               break;
            };

            default:
               break;
         };

         pCurrentObj = pCurrentObj->m_GuyNextToMe;

      } while (pCurrentObj != NULL);
   }

   ClearWhoIsAroundMe(pFirstGuy);
}
Example #23
0
int CConvoy::TargetRelativePosition()
{
   int TargetPosition = 0;
     
   const Sphere* pMySphere = GetSphere();

   CVector3f TargetOrigin;
   CVector3f MyOrigin;
   CVector3f PToP;
   CVector3f MyLookAt;
   CVector3f Result;

   TargetOrigin   = *(m_Waypoints[m_CurrentWaypointIndex].m_Frame.GetPosition());

   MyOrigin    = pMySphere->Center;

   const CObjFrame* Frame = GetFrame(0);

   Ray         ShotTrajectory;
   Sphere TargetSphere;

   TargetSphere.Center = TargetOrigin;

   float       Scale = 1.0f;

   float       Dist = DistanceSquare(&MyOrigin, &TargetOrigin);
/*
   if (Dist > 100.0f * 100.0f)
   {
      Scale = Dist / 100.0f * 100.0f ;

      if (Scale > 5.0f)
         Scale = 5.0f;
   }
   */

   TargetSphere.Radius = 40.0f * Scale;

   Frame->GetPosition(&(ShotTrajectory.Origin));
   Frame->GetForward(&(ShotTrajectory.Direction));

   Vec3fNormalize(&(ShotTrajectory.Direction), &(ShotTrajectory.Direction));   

   if (RayToSphere(&ShotTrajectory, &TargetSphere))
      return TargetPosition;

   Vec3fSubtract(&PToP, &TargetOrigin, &MyOrigin);
   Frame->GetForward(&MyLookAt);

   MyLookAt.y = 0.0f;
   PToP.y = 0.0f;

   Vec3fCrossProduct(&Result, &MyLookAt, &PToP);

   if (Result.y > 0.0f)
      TargetPosition = 1;
   else if (Result.y < 0.0f)
      TargetPosition = -1;

   return TargetPosition;
}
Example #24
0
void CSmashBot::TakeDamage(IBaseObject* _pIn) 
{
	if(_pIn->GetID() == OBJ_POOL)
	{
		SetHealth(GetHealth() - ((CMoltenPool*)_pIn)->GetDamage());
		SetWasHit(true);
		return;
	}
	else if (_pIn->GetID() == OBJ_TURRET)
	{
		SetHealth(GetHealth() - ((CTurret*)_pIn)->GetDamage());
		SetWasHit(true);
		return;
	}

	if( _pIn->GetID() == OBJ_BULLET_EXP )
	{
		if(((CBullet*)_pIn)->GetType() == SPECIALBULLET)
			SetHealth(0.0f);
		else
			SetHealth(GetHealth() - ((CBullet*)_pIn)->GetDamage());
		SetWasHit(true);
		return;
	}

	if( m_bIsSmashing )
	{
		SetHealth(GetHealth() - ((CBullet*)_pIn)->GetDamage());
		SetWasHit(true);
	}
	else
	{
		if( _pIn->GetID() == OBJ_BULLET_BEAM || _pIn->GetID() == OBJ_BULLET_TESLA )
		{
			SetHealth(GetHealth() - ((CBullet*)_pIn)->GetDamage()*.5f);
			SetWasHit(true);
			return;
		}
		D3DXVECTOR3 d3dMyZ(GetMatrix()._31, GetMatrix()._32, GetMatrix()._33);
		D3DXVECTOR3 d3dIn(_pIn->GetMatrix()._41, _pIn->GetMatrix()._42, _pIn->GetMatrix()._43);
		D3DXVECTOR3 d3dToTarget = d3dIn - D3DXVECTOR3(GetMatrix()._41, GetMatrix()._42, GetMatrix()._43);
		float fDot = D3DXVec3Dot(&d3dMyZ, &d3dToTarget);

		if( fDot < 0.0f)
		{
			SetHealth(GetHealth() - ((CBullet*)_pIn)->GetDamage());
			SetWasHit(true);
			CGameplayState::GetInstance()->GetFX()->CreateEffect(EFFECT_BULLETHIT,_pIn->GetMatrix());
		}
		else
		{
			float fSafe = GetSphere().m_Radius * GetSphere().m_Radius + ((CBullet*)_pIn)->GetSphere().m_Radius * ((CBullet*)_pIn)->GetSphere().m_Radius + .5f;
			D3DXVECTOR3 d3dFinal = *(D3DXVECTOR3*)&_pIn->GetMatrix()[12], d3dToBullet = *(D3DXVECTOR3*)&_pIn->GetMatrix()[12] - *(D3DXVECTOR3*)&GetMatrix()[12];
			if( D3DXVec3LengthSq(&d3dToBullet) > fSafe )
			{
				D3DXVECTOR3 d3dDir;
				D3DXVec3Normalize(&d3dDir, &d3dToBullet);
				d3dDir *= GetSphere().m_Radius;
				d3dFinal = *(D3DXVECTOR3*)&GetMatrix()[12] + d3dDir;
			}
			D3DXMATRIX d3dMat = GetMatrix();
			d3dMat[12]=d3dFinal.x;
			d3dMat[13]=d3dFinal.y;
			d3dMat[14]=d3dFinal.z;
			CGameplayState::GetInstance()->GetFX()->CreateEffect(EFFECT_INVULSPARK,d3dMat);
		}
	}
}
Example #25
0
void CBuilding3::Update(void)
{
   if(m_CurBuilding3State == FALLING)
   {
      static bool moveright = false;

      MoveUp(m_FallingSpeed * g_FrameTime, 0);

      if(moveright)
      {
         MoveRight(10.0f * g_FrameTime, 0);
         moveright = false;
      }
      else
      {
         MoveRight(-(10.0f * g_FrameTime), 0);
         moveright = true;
      }

      if((m_TimeEndCollapse - g_time) <= 2.0f)
      {
         if(!(FSOUND_IsPlaying(m_pBuildingFallingSFX->m_Channel)))
         {
            // Make main weapon sound
            m_pBuildingFallingSFX->Play3DAudio(60, 10000.0f, 300);
            CVector3f position;
	         GetPosition(&position, 0);
            CVector3f velocity(0.0f, 0.0f, 0.0f);
            m_pBuildingFallingSFX->UpdateSound(position, velocity);
         }
      }

      if((m_TimeEndCollapse - g_time) <= 1.0f)
      {     
         if(m_Building3Falling)
            m_Building3Falling->m_UpdateFlag = ONLY_UPDATE;  

         m_CurBuilding3State = EXPLODE;

         const Sphere* pObjectSphere = GetSphere();
         float Building3Radius = pObjectSphere->Radius; 
   
         m_Building3Explode = g_ParticleManager.ObtainSystem();

         CObjFrame TempFrame;
         TempFrame = *GetFrame(0);
         TempFrame.MoveUp(Building3Radius * 0.5f);
         CVector3f Building3Top = *TempFrame.GetPosition();

         if(m_Building3Explode)
            g_ParticleManager.CreateSystem(m_Building3Explode, Building3Top, NULL, g_ParticleManager.BUILDING_EXPLODE, LOD_BOTH);
      }
   }

   else if(m_CurBuilding3State == EXPLODE)
   {
      MoveUp(m_FallingSpeed * g_FrameTime, 0);

      if(moveright)
      {
         MoveRight(10.0f * g_FrameTime, 0);
         moveright = false;
      }
      else
      {
         MoveRight(-(10.0f * g_FrameTime), 0);
         moveright = true;
      }

      m_RenderObj.m_Material.m_Diffuse.a -= 1.0f * g_FrameTime;
      m_RenderObj.m_Material.m_Ambient.a -= 1.0f * g_FrameTime;

       if(g_time >= m_TimeEndCollapse)
         Die();
   }

   CGameObject::Update();
}
Example #26
0
bool CSmashBot::CheckCollision(IBaseObject* pObj)
{
	if(pObj == this)
		return false;

	int nType = pObj->GetID();

	if(nType == OBJ_SMASH || nType == OBJ_SPIDER || nType == OBJ_INVERSION || nType == OBJ_TUNNEL)
	{
		if(SphereToSphere(this->GetSphere(), pObj->GetSphere()))
		{
			if( m_bIsSmashing == false || nType == OBJ_INVERSION || OBJ_TUNNEL)
			{
				AddToReactVector(pObj);
				//CollisionResponse(pObj);
				return true;
			}
		}
	}
	if(nType == OBJ_PIT)
	{
		Sphere tempSphere = GetSphere();
		tempSphere.m_Radius = 10.0f;
		if(SphereToAABB(tempSphere,((CDeathPit*)pObj)->GetAABB()))
		{
			((CDeathPit*)pObj)->SetTrapCloseTimer(2.0f);
			if(((CDeathPit*)pObj)->GetTrapIsOpen())
			{
				((CDeathPit*)pObj)->SetIsTrapOpen(false);
				((CDeathPit*)pObj)->ChangeAnimation(1);
			}
			return true;
		}
	}
	if(nType == OBJ_PLAYER)
	{
		if(SphereToSphere(this->GetSphere(), ((CPlayerObject*)pObj)->GetSphere()))
		{
			//m_bIsSmashing = true;
			AddToReactVector(pObj);
			//CollisionResponse(pObj);
			return true;
		}
	}
	if(nType == OBJ_CONVEYOR)
	{
		if(SphereToAABB(GetSphere(), ((CConveyor*)pObj)->GetAABB()))
		{
			pObj->AddToReactVector(this);
			//pObj->CollisionResponse(this);
			return true;
		}
	}
	if(nType >= OBJ_VAT && nType <= OBJ_BARREL)
	{
		if(SphereToSphere(GetSphere(),pObj->GetSphere()))
		{
			//AddToReactVector(this);
			CollisionResponse(pObj);
			return true;
		}
	}

	return false;
}
bool CExplodingBullet::CheckCollision(IBaseObject* pObj)
{
	if( !GetAlive() || !pObj->GetAlive())
		return false;

	int nType = pObj->GetID();

	switch(m_nType)
	{
	case SPECIALBULLET:
		{
			if( nType == OBJ_BULLET_ENEMY || nType > OBJ_PLAYER && nType <= OBJ_AIFIST || 
				nType >= OBJ_VAT && nType <= OBJ_BARREL || nType == OBJ_INVERSION || nType == OBJ_BOSSINV || nType == OBJ_BOSSTURRET)
			{
				std::list<IBaseObject*>::iterator iter;

				for( iter = m_lEnemies.begin(); iter != m_lEnemies.end(); ++iter )
				{
					if( (*iter) == pObj )
						return false;
				}

				if( SphereToSphere(GetSphere(), pObj->GetSphere()))
				{
					m_lEnemies.push_back(pObj);
					CollisionResponse(pObj);
					CEffect* pEffect = CGameplayState::GetInstance()->GetFX()->CreateEffect(EFFECT_SPECIALHIT,pObj->GetMatrix());
					if(pEffect)
						pEffect->SetColors((D3DXCOLOR)GetColor());
					return true;
				}
			}
		}
		break;
	case SMASHBULLET:
		{
			if( nType == OBJ_PLAYER || nType == OBJ_TRASH )
			{
				if( SphereToSphere(GetSphere(), pObj->GetSphere()))
				{
					CollisionResponse(pObj);
					return true;
				}
			}
		}
		break;
	case BARRELBULLET:
		{
			if( nType == OBJ_PLAYER || nType >= OBJ_TRASH && nType <= OBJ_STEAM)
			{
				if( SphereToSphere(GetSphere(), pObj->GetSphere()))
				{
					CollisionResponse(pObj);
					return true;
				}
			}
			else if( nType == OBJ_BARREL)
			{
				if( SphereToSphere(GetSphere(), pObj->GetSphere()))
				{
					pObj->CollisionResponse(this);
					return true;
				}
			}
		}
		break;
	case INVERSION_BULLET:
		{
			if(nType == OBJ_PLAYER)
			{
				if(SphereToSphere(GetSphere(), pObj->GetSphere()))
				{
					CollisionResponse(pObj);
					return true;
				}
			}
		}
	}
	return false;
}