Example #1
0
void	Sprinkler::InitParticle(Particle& out)
{
	out.initialColor		=	D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	out.initialPos			=	D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	out.initialSize			=	Helper::GetRandomFloat(10.0f, 20.0f);
	out.initialTime			=	m_fTime;
	D3DXVECTOR3 minVec(-1.0f, -1.0f, -1.0f);
	D3DXVECTOR3 maxVec(1.0f, 1.0f, 1.0f);
	Helper::GetRandomVector(out.initialVelocity, minVec, maxVec);
	out.lifeTime			=	Helper::GetRandomFloat(10.5f, 10.8f);
	out.mass				=	Helper::GetRandomFloat(0.8f, 1.2f);
};
Example #2
0
	BoundingBox Mesh::createBoundingBox(vector<Vertex> &vertices, vector<int> &indices)
	{
		Vector3f maxVec(static_cast<float>(INT_MAX));
		Vector3f minVec(static_cast<float>(INT_MIN));
		BoundingBox b(maxVec, minVec);

		for (size_t i = 0; i < indices.size(); i++)
		{
			b.extend(vertices[indices[i]].getPosition());
		}

		return b;
	}
Example #3
0
void Game::StartGame()
{
    const int NUM_ASTEROIDS = 10;
    Vector3 minVec(-512.0f, -384.0f, 0.0f);
    Vector3 maxVec(512.f, 384.f, 0.0f);
    for (int i = 0; i < NUM_ASTEROIDS; i++){
        auto ast = Asteroid::Spawn(*this);
        ast->SetPosition(Random::GetVector(minVec,maxVec));
        ast->SetScale(0.75f);
    }
    mShip = Ship::Spawn(*this);
    mShip->SetRotation(Math::PiOver2);
}
Example #4
0
	BoundingBox Mesh::createBoundingBox(vector<Vertex> &vertices, vector<int> &indices, Matrix4f &worldTransform)
	{
		Vector3f maxVec(static_cast<float>(INT_MAX));
		Vector3f minVec(static_cast<float>(INT_MIN));
		BoundingBox b(maxVec, minVec);

		Vector3f *tmpVecs = new Vector3f[indices.size()];
		for (size_t i = 0; i < indices.size(); i++)
		{
			tmpVecs[i] = vertices[indices[i]].getPosition().transform(worldTransform);
			b.extend(tmpVecs[i]);
		}
		delete[] tmpVecs;

		return b;
	}
Example #5
0
void GameMode::BeginPlay()
{
    const int NUM_ASTEROIDS = 500;
    Vector3 minVec(-5000.f, -5000.f, -5000.f);
    Vector3 maxVec(5000.f, 5000.f, 5000.f);
    for (int i = 0; i < NUM_ASTEROIDS; i++) {
        auto ast = Asteroid::Spawn(GetGame());
        ast->SetPosition(Random::GetVector(minVec,maxVec));
        ast->SetScale(0.75f);
    }
    mShip = Ship::Spawn(GetGame());
    mArrow = Arrow::Spawn(GetGame());
    mArrow->SetPlayer(mShip);
    SpawnCheckpoint();

    mHUD = HUD::Spawn(GetGame());
    GetGame().GetGameTimers().SetTimer(mHandle, this, &GameMode::CountDown, 1.0f, true);
    mHUD->UpdateTime(time);
    mHUD->UpdateScore(score);
}
Example #6
0
//初始化粒子
void SnowParticle::ResetParticle(Particle* particle)
{
	particle->age = 0.0f;
	particle->isLive = true;
	particle->lifeTime = GetRandomFloat(2.0f, 10.0f);
	particle->color = D3DCOLOR_RGBA(rand() % 255, rand() % 255, rand() % 255, rand() % 255);
	particle->colorFade = D3DXCOLOR(D3DCOLOR_RGBA(0, 0, 0, 0));
	
	D3DXVECTOR3 minVec(0, 50, 0);
	D3DXVECTOR3 maxVec(50, 70, 50);
	D3DXVECTOR3 pos;
	GetRandomVector(&pos, &minVec, &maxVec);
	particle->position = pos;
	particle->initVelocity = D3DXVECTOR3(GetRandomFloat(0, 1.0f),
		GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(0.0f, 1.0f));

	particle->velocity = D3DXVECTOR3(GetRandomFloat(-1.0f, 1.0f),
		GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(-1.0f, 1.0f));

}
Example #7
0
//------------------------------------------------------------------------
// Purpose  : Initialize particle
//------------------------------------------------------------------------
void	DiwaliPaus::InitParticle(Particle& out)
{
	// Randomize Color
	D3DXVECTOR3	minCol(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 maxCol(1.0f, 1.0f, 1.0f);
	D3DXVECTOR3 outCol;
	Helper::GetRandomVector(outCol, minCol, maxCol);
	out.initialColor		=	D3DXCOLOR(outCol.x, outCol.y, outCol.z, 1.0f);
	
	out.initialPos			=	D3DXVECTOR3(0.0f, 100.0f, 0.0f);
	out.initialSize			=	Helper::GetRandomFloat(10.0f, 20.0f);
	out.initialTime			=	m_fTime;

	// Randomize Velocity
	D3DXVECTOR3 minVec(-1.5f, 10.0f, -1.5f);
	D3DXVECTOR3 maxVec(1.5f, 20.0f, 1.5f);
	Helper::GetRandomVector(out.initialVelocity, minVec, maxVec);

	out.lifeTime			=	Helper::GetRandomFloat(5.0f, 7.0f);
	out.mass				=	Helper::GetRandomFloat(0.8f, 1.2f);
};
Example #8
0
	Vec4 minVec(const Vec4 &u, const Vec4 &v)
	{
		return Vec4(minVec(u.x, v.x), minVec(u.y, v.y), minVec(u.z, v.z), minVec(u.w, v.w));
	}
Example #9
0
	Vec3 minVec(const Vec3 &u, const Vec3 &v)
	{
		return Vec3(minVec(u.x, v.x), minVec(u.y, v.y), minVec(u.z, v.z));
	}
Example #10
0
	Vec2 minVec(const Vec2 &u, const Vec2 &v)
	{
		return Vec2(minVec(u.x, v.x), minVec(u.y, v.y));
	}
Example #11
0
	Vec1 minVec(const Vec1 &u, const Vec1 &v)
	{
		return Vec1(minVec(u.x, v.x));
	}
Example #12
0
//compute min ratngs per user/ item, also can pass set of ignored user-item
//pairs
void genStats(gk_csr_t *mat, 
    std::vector<std::unordered_set<int>> uISetIgnore,
    std::string opPrefix) {
  
  int nUsers = mat->nrows;
  int nItems = mat->ncols;
  int nnz = 0, igNNZ = 0;
  std::vector<int> uItemCount(nUsers, 0);
  std::vector<int> uItemIgCount(nUsers, 0);
  std::vector<int> iUserCount(nItems, 0);
  std::vector<int> iUserIgCount(nItems, 0);

  for  (int u = 0; u < mat->nrows; u++) {
    for (int ii = mat->rowptr[u]; ii < mat->rowptr[u+1]; ii++) {
      int item = mat->rowind[ii];
      uItemCount[u] += 1;
      iUserCount[item] += 1;
      nnz++;
      //check if given user item pair should be ignore
      auto search = uISetIgnore[u].find(item);
      if (search == uISetIgnore[u].end()) {
        //not found in ignore set
        uItemIgCount[u] += 1;
        iUserIgCount[item] += 1;
      } else {
        igNNZ++;
       }
    } 
  }
  
  int minUserRatCount = minVec(uItemCount);
  int maxUserRatCount = maxVec(uItemCount);
  int minItemRatCount = minVec(iUserCount);
  int maxItemRatCount = maxVec(iUserCount);

  std::cout << "\nnUsers: " << nUsers;
  std::cout << "\nnItems: " << nItems;
  std::cout << "\nNNZ: " << nnz;
  std::cout << "\nmin nratings per user: "******" opPrefix: " << opPrefix;
  std::cout << "\nmax nratings per user: "******" opPrefix: " << opPrefix;
  std::cout << "\nmin nratings per item: " << minItemRatCount 
    << " opPrefix: " << opPrefix;
  std::cout << "\nmax nratings per item: " << maxItemRatCount 
    << " opPrefix: " << opPrefix;

  int minUserIgRatCount = minVec(uItemIgCount);
  int maxUserIgRatCount = maxVec(uItemIgCount);
  int minItemIgRatCount = minVec(iUserIgCount);
  int maxItemIgRatCount = maxVec(iUserIgCount);

  std::cout << "\nmin nratings per user after ig: " << minUserIgRatCount 
    << " opPrefix: " << opPrefix;
  std::cout << "\nmax nratings per user after ig: " << maxUserIgRatCount 
    << " opPrefix: " << opPrefix;
  std::cout << "\nmin nratings per item after ig: " << minItemIgRatCount 
    << " opPrefix: " << opPrefix;
  std::cout << "\nmax nratings per item after ig: " << maxItemIgRatCount 
    << " opPrefix: " << opPrefix;
  
  int nUsersWithMinRatcount = 0;
  int nUsersWithMaxRatcount = 0;
  for (int i = 0; i < uItemIgCount.size(); i++) {
    if (uItemIgCount[i] == minUserIgRatCount) {
      nUsersWithMinRatcount++;
    }
    if (uItemIgCount[i] == maxUserIgRatCount) {
      nUsersWithMaxRatcount++;
    }
  }

  std::cout << "\nnUsers with minRatcount(" << minUserIgRatCount << "): " 
    << nUsersWithMinRatcount << " opPrefix: " << opPrefix;
  std::cout << "\nnUsers with maxRatcount(" << maxUserIgRatCount << "): " 
    << nUsersWithMaxRatcount << " opPrefix: " << opPrefix;
  
  int nItemsWithMinRatCount = 0;
  int nItemsWithMaxRatcount = 0;
  for (int i = 0; i < iUserIgCount.size(); i++) {
    if (iUserIgCount[i] == minItemIgRatCount) {
      nItemsWithMinRatCount++;
    }
    if (iUserIgCount[i] == maxItemIgRatCount) {
      nItemsWithMaxRatcount++;
    }
  }

  std::cout << "\nnItems with minRatCount(" << minItemIgRatCount << "): "
    << nItemsWithMinRatCount << " opPrefix: " << opPrefix;
  std::cout << "\nnItems with maxRatCount(" << maxItemIgRatCount << "): "
    << nItemsWithMaxRatcount << " opPrefix: " << opPrefix;
}