void CalculateNormals(irr::core::array<video::S3DVertex>& vertices,	irr::core::array<u16>& indices)
{
	for (unsigned int i = 0; i < vertices.size(); i++)
	{
		vertices[i].Normal = Vector3_Zero;
	}

	u32 size = indices.size();
	for (unsigned int i = 0; i < size / 3; i++)
	{
		int index1 = indices[i * 3];
        int index2 = indices[i * 3 + 1];
        int index3 = indices[i * 3 + 2];

		Vector3 side1 = vertices[index2].Pos - vertices[index1].Pos;
        Vector3 side2 = vertices[index3].Pos - vertices[index1].Pos;
		Vector3 normal = side1.crossProduct(side2);

        vertices[index1].Normal += normal;
        vertices[index2].Normal += normal;
        vertices[index3].Normal += normal;
	}

	for (unsigned int i = 0; i < vertices.size(); i++)
	{
		vertices[i].Normal.normalize();
	}
}
Ejemplo n.º 2
0
// Pack rectangles into box with dimensions sizeOfPackxsizeOfPack. Packed outputs new rectangles
void CRectPacker::pack(const irr::core::array<irr::core::rect<irr::u32> > &rects, irr::core::array<irr::core::array<SPacked>> &packed, irr::u32 sizeOfPack) {
	clear();
	mPackSize = sizeOfPack;
	for (int x = 0; x < rects.size(); x++) {
		SRect addRect;
		addRect.pos = rects[x];
		addRect.id = x;
		addRect.packed = false;
		mRects.push_back(addRect);
	}
	mRects.sort();

	while (mNumPacked < mRects.size()) {
		SRect empty;
		empty.id = -1;
		empty.children[0] = -1;
		empty.children[1] = -1;
		empty.pos = irr::core::rect<irr::u32>(0,0,mPackSize,mPackSize);
		int oldSize = mPacks.size();
		mPacks.push_back(empty);
		mRoots.push_back(oldSize);
		fill(oldSize);
	}


	
	for (int x = 0; x < mRoots.size(); x++) {
		irr::core::array<SPacked> arr;
		packed.push_back(arr);
		packed[x].clear();
		addPackToArray(mRoots[x],packed[x]);
	}
}
Ejemplo n.º 3
0
//! Create Scene
void CtfPlugIn::open(){
  irr::scene::ISceneManager* SMgr = 0;
  irr::scene::ISceneNode* SRoot = 0;
  if(irrPointers.SMgr){
    SMgr = irrPointers.SMgr;
    SRoot = irrPointers.SMgr->getRootSceneNode();
#ifdef useIrrExtensions13
    //! Create "ground plane"
    if(nGround) irrPointers.SMgr->addToDeletionQueue(nGround);
    nGround = irrPointers.SMgr->addGridSceneNode();
    nGround->setPosition(irr::core::vector3df(0,0,0));
    nGround->setAccentlineColor(nGround->getGridColor());
#endif
  }
  resetCount = 0;
  // create the seeker ("hero"/"attacker")
  ctfSeeker = new CtfSeeker(SMgr, SRoot);
  all.push_back(ctfSeeker);
  // create the specified number of enemies,
  // storing pointers to them in an array.
  for(int i = 0; i < maxEnemyCount; i++){
    ctfEnemies[i] = new CtfEnemy(SMgr, SRoot);
    all.push_back(ctfEnemies[i]);
  }
  lstObstacleMesh.clear();
  CtfBase::obstacleCount = -1;
  CtfBase::initializeObstacles();

  setInfoText(Text2);
}
Ejemplo n.º 4
0
//! Clear Scene
void MapDrivePlugIn::close(){
#ifdef useIrrExtensions13
  if(nGround) irrPointers.SMgr->addToDeletionQueue(nGround);
  nGround = NULL;
#endif
  vehicles.clear();
  irrPointers.SMgr->addToDeletionQueue(vehicle);
  lstObstacleMesh.clear();
}
Ejemplo n.º 5
0
// Find a good area to pack rects into. If the area of the rects divided by the area of the nearest power of two calculated is above a certain tolerance, the size is doubled
irr::core::dimension2du CMeshCombiner::findOptimalPackingArea(irr::core::array<irr::core::rect<irr::u32> > rectangles) {
	irr::u32 totalArea = 0;
	for (int x = 0; x < rectangles.size(); x++) {
		totalArea += rectangles[x].getArea();
	}
	irr::u32 smallestDimension = ceil(sqrtf(totalArea));
	irr::u32 closestPowerOfTwo = pow(2.0f,ceil(logf(smallestDimension)/logf(2)));
	if ((irr::f32)smallestDimension/(irr::f32)closestPowerOfTwo > mSizingTolerance)
		closestPowerOfTwo *= 2;
	return irr::core::dimension2du(closestPowerOfTwo,closestPowerOfTwo);
}
Ejemplo n.º 6
0
// Fill arrays with packs from root
void CRectPacker::addPackToArray(int pack, irr::core::array<SPacked> &addArray) const {
	if (isPackValid(pack)) {
		if (mPacks[pack].id != -1) {

			SPacked packed;
			packed.id = mPacks[pack].id;
			packed.pos = mPacks[pack].pos;
			addArray.push_back(packed);
			if (mPacks[pack].children[0] != -1)
				addPackToArray(mPacks[pack].children[0], addArray);
			if (mPacks[pack].children[1] != -1)
				addPackToArray(mPacks[pack].children[1], addArray);
		}
	}
}
Ejemplo n.º 7
0
//! Clear Scene
void CtfPlugIn::close(){
#ifdef useIrrExtensions13
  if(nGround) irrPointers.SMgr->addToDeletionQueue(nGround);
  nGround = NULL;
#endif
  // delete seeker
  irrPointers.SMgr->addToDeletionQueue(ctfSeeker);
  ctfSeeker = NULL;
  // delete each enemy
  for(int i = 0; i < maxEnemyCount; i++){
    irrPointers.SMgr->addToDeletionQueue(ctfEnemies[i]);
    ctfEnemies[i] = NULL;
  }
  // clear the group of all vehicles
  all.clear();
  // delete obstacles
  while(CtfBase::obstacleCount > 0) CtfBase::removeOneObstacle();
  CtfBase::obstacleCount = -1;
  lstObstacleMesh.clear();
}
Ejemplo n.º 8
0
    CRunner() : IRunner(L"IrrOde Testbed") {
      m_pReceiver=NULL;
      m_iActive=0;
      m_iRet=0;

      m_aStates.push_back(new CMenuState      (m_pDevice,this,&m_aStates));
      m_aStates.push_back(new CTestHelloWorld (m_pDevice,this));
      m_aStates.push_back(new CTestCloneRemove(m_pDevice,this));
      m_aStates.push_back(new CTestBoxPile    (m_pDevice,this));
      m_aStates.push_back(new CTestTrigger    (m_pDevice,this));
      m_aStates.push_back(new CTestSlipstream (m_pDevice,this));
      //m_aStates.push_back(new CTestFastMoving (m_pDevice,this));
      m_aStates.push_back(new CTestHeli       (m_pDevice,this));
      m_aStates.push_back(new CTestPlane      (m_pDevice,this));
      m_aStates.push_back(new CTestCar        (m_pDevice,this));
      m_aStates.push_back(new CTestTank       (m_pDevice,this));
      m_aStates.push_back(new CTestCapsule    (m_pDevice,this));

      m_pDevice->setEventReceiver(this);
    }