예제 #1
0
void SpringSys::SetInitialBoneStates(Tab<Matrix3> boneTMs)
{
	for (int x = 0; x< GetParticles()->length(); x++)
	{
		SSParticle *p = GetParticle(x);
		for (int tmId = 0; tmId< boneTMs.Count(); tmId++)
		{
			for (int i=0;i<p->GetSprings()->length();i++)
			{
				if (tmId == p->GetSpring(i)->GetPointConstraint()->GetIndex())
				{
					if (tmId == 0) 
						p->GetSpring(i)->SetLength(Point3::Origin);
					else p->GetSpring(i)->SetLength( initPosTab[x] * Inverse(boneTMs[tmId]) );
					
					p->GetSpring(i)->GetPointConstraint()->SetPos(initPosTab[x]);
					p->GetSpring(i)->GetPointConstraint()->SetVel(Point3::Origin);
				}
			}
			if (frameCache.bone.length() <= tmId) 
			{
				SSConstraintPoint contBone = SSConstraintPoint(tmId);
				frameCache.bone.append(contBone);
			}
		}
		//frameCache.bone.SetCount(tmId+1);
	}
}
void CollisionSolver::SolveClothCollision(const D3DXVECTOR3& minBounds, 
                                          const D3DXVECTOR3& maxBounds)
{
    D3DPERF_BeginEvent(D3DCOLOR(), L"CollisionSolver::SolveClothCollision");

    assert(!m_cloth.expired());
    auto cloth = m_cloth.lock();
    auto& particles = cloth->GetParticles();

    for(unsigned int i = 0; i < particles.size(); ++i)
    {
        // Solve the particles against themselves
        for(unsigned int j = i+1; j < particles.size(); ++j)
        {
            SolveParticleCollision(particles[i]->GetCollisionMesh(), 
                particles[j]->GetCollisionMesh());
        }

        // Solve the particle against the eight scene walls
        const D3DXVECTOR3& particlePosition = particles[i]->GetPosition();
        D3DXVECTOR3 position(0.0, 0.0, 0.0);

        // Check for ground and roof collisions
        if(particlePosition.y <= maxBounds.y)
        {
            position.y = maxBounds.y-particlePosition.y;
        }
        else if(particlePosition.y >= minBounds.y)
        {
            position.y = minBounds.y-particlePosition.y;
        }

        // Check for left and right wall collisions
        if(particlePosition.x >= maxBounds.x)
        {
            position.x = maxBounds.x-particlePosition.x;
        }
        else if(particlePosition.x <= minBounds.x)
        {
            position.x = minBounds.x-particlePosition.x;
        }

        // Check for forward and backward wall collisions
        if(particlePosition.z >= maxBounds.z)
        {
            position.z = maxBounds.z-particlePosition.z;
        }
        else if(particlePosition.z <= minBounds.z)
        {
            position.z = minBounds.z-particlePosition.z;
        }

        particles[i]->MovePosition(position);
    }

    D3DPERF_EndEvent();
}
예제 #3
0
//--------------------------------------------------------------------
  std::string AEvent::PrintInfo() const
//--------------------------------------------------------------------
  { 
    std::stringstream s;
    s << " Event number " << GetEvtNum() << std::endl;
    s << " Event true energy " << GetTrueEventEnergy() << std::endl;
    s << " Event reco energy " << GetRecEventEnergy() << std::endl;
    s << " number of particles in event " << GetParticles().size() << std::endl;
    s << " +++list of particles+++++ " << std::endl;

    for (auto particle : GetParticles()) 
      s << particle->PrintInfo() << std::endl;

    for (auto particle : GetTTracks()) 
      s << particle->PrintInfo() << std::endl;

    return s.str();
  }
예제 #4
0
void VParticleWallmarkGroup::FillCache()
{
  VParticleWallmark* p = (VParticleWallmark *)GetParticles();
  const int iCount = GetNumOfParticles();
  for (int i=0;i<iCount && m_iCacheCount<MAX_WALLMARK_CACHE_SIZE;i++,p++)
    if (!p->IsValid())
      m_iCacheIndex[m_iCacheCount++] = i;

  m_bHasFreeParticles = m_iCacheCount>0;
}
예제 #5
0
void VParticleWallmarkGroup::RemoveWallmark(VParticleWallmark *p)
{
  m_bHasFreeParticles = true;
  m_bBBoxValid = false;
  p->valid = 0;
  VParticleWallmark* pFirst = (VParticleWallmark *)GetParticles();
  int iIndex = (int)(p - pFirst);
  VASSERT(iIndex>=0 && iIndex<GetNumOfParticles());
  if (m_iCacheCount<MAX_WALLMARK_CACHE_SIZE)
    m_iCacheIndex[m_iCacheCount++] = iIndex;
}
예제 #6
0
void VParticleWallmarkGroup::TickFunction(float dtime)
{
  VParticleWallmark* p = (VParticleWallmark *)GetParticles();
  const int iCount = GetNumOfParticles();
  int iHighWater = -1;
  for (int i=0;i<iCount;i++,p++)
    if (p->IsValid())
    {
      p->TickFunction(dtime);
      iHighWater = i;
    }
  m_iHighWaterMark = iHighWater+1;
  if (!m_bBBoxValid)
    RecomputeBoundingBox();
/* DEBUG rendering:
  if (m_BoundingBox.IsValid())
    Vision::Game.DrawBoundingBox(m_BoundingBox, VColorRef(100,200,255,255));
    */
}
예제 #7
0
 bool JankyTargeting::ProcessOneImage(void)
{
	 PIDTurret.Enable();
	 numValidBogies = 0;
	 if (GetImage()==true)
	{
		 numImagesProcessed++;
		 smarty->PutInt("Images Processed", numImagesProcessed);
		 
		 if (DoImageProcessing()==true)
			if (GetParticles()==true)
			{
				for (int i=0 ; i<vPAR->size() && i<3 ; i++)
				{
					par = &(*vPAR)[i];
					if (par->particleArea < MIN_PARAREA)
						break;
					GetValues();
					if (rect_score > MIN_SCORE)
					{	
						bogies[numValidBogies].BogeyBRCX=BRcenterx;
						bogies[numValidBogies].BogeyBRCY=BRcentery;
						bogies[numValidBogies].BogeyTop=par->boundingRect.top;
						bogies[numValidBogies].BogeyLeft=par->boundingRect.left;
						bogies[numValidBogies].BogeyVD=visualdistance;
						bogies[numValidBogies].BogeyPMCX=par->center_mass_x;
						bogies[numValidBogies].BogeyPMCY=par->center_mass_y;
						bogies[numValidBogies].BogeySCORE=rect_score;
						//bogies[numValidBogies].BogeyRATIO=aspect_ratio;						

						numValidBogies ++;
					}
				}
				PrintBogey();
			}													
	}
	else
		return false;
	
	delete vPAR;
	delete samwise;
}
예제 #8
0
VParticleWallmark* VParticleWallmarkGroup::TryGetFreeParticle()
{
  if (!m_bHasFreeParticles) // early out
    return NULL;
  VParticleWallmark* pArray = (VParticleWallmark *)GetParticles();
  while (m_iCacheCount>0)
  {
    m_iCacheCount--;
    int iIndex = m_iCacheIndex[m_iCacheCount];
    VParticleWallmark& p(pArray[iIndex]);
    if (p.IsValid())
      continue;
    m_iHighWaterMark = hkvMath::Max(m_iHighWaterMark,iIndex+1);
    m_bBBoxValid = false;
    p.valid = true;
    p.m_pOwner = this;
    return &p;
  }

  FillCache();
  return TryGetFreeParticle(); // can return NULL
}
예제 #9
0
void VParticleWallmarkGroup::RecomputeBoundingBox()
{
  VParticleWallmark* p = (VParticleWallmark *)GetParticles();
  hkvAlignedBBox oldBBox = m_BoundingBox; 
  m_BoundingBox.setInvalid();
  for (int i=0;i<m_iHighWaterMark;i++,p++)
    if (p->IsValid())
      p->InflateBoundingBox(m_BoundingBox);

  if (m_BoundingBox.isValid())
  {
    // actually all other tests are too error-prone for frequently resizing boxes
    if (m_spVisObj==NULL)
      m_spVisObj = new VisVisibilityObjectAABox_cl(VISTESTFLAGS_FRUSTUMTEST|VISTESTFLAGS_ACTIVE);
    m_spVisObj->SetActivate(TRUE);

    // build visibility assignment on our own. automatic update is too error prone by going through portals
    if (oldBBox!=m_BoundingBox)
    {
      m_spVisObj->SetWorldSpaceBoundingBox(m_BoundingBox);
      VisObject3DVisData_cl *pVisData = m_spVisObj->GetVisData();
      pVisData->SetAutomaticUpdate(false);
      VisVisibilityZone_cl *pZones[4096];
      const int iVisCount = Vision::GetSceneManager()->FindVisibilityZones(m_BoundingBox,pZones,4096);
      pVisData->UpdateNodeList(iVisCount,pZones);
    }
    SetVisibilityObject(m_spVisObj);
    SetVisibleBitmask(0xffffffff);
  }
  else
  {
    if (m_spVisObj)
      m_spVisObj->SetActivate(FALSE);
    SetVisibleBitmask(0);
  }
  m_bBBoxValid = true;
}