Example #1
0
void RayTracer::updateAABB(std::vector<Triangle>& triangles, Node& N)
{
	CalculateBB(triangles, N.box, N.startPrim, N.endPrim);
	if (N.leftChild != NULL)
		updateAABB(triangles, *N.leftChild);
	if (N.rightChild != NULL)
		updateAABB(triangles, *N.rightChild);
}
Example #2
0
Body::Body(ClosedShape *shape, std::vector<float> pointMasses, Vector2 &position, float angleInRadians, Vector2 &scale, bool kinematic)
{
	mDerivedAngle = 0.0f;
	mDerivedOmega = 0.0f;
	mLastAngle = 0.0f;

	mDerivedVel = Vector2::ZERO;

    mAABB = new AABB();
    mDerivedPos = position;
    mDerivedAngle = angleInRadians;
    mLastAngle = mDerivedAngle;
    mScale = scale;
    mMaterial = 0;
    mIsStatic = false;
    mKinematic = kinematic;

	mBitMaskX = new Bitmask();
	mBitMaskY = new Bitmask();

	PI = 3.14159f;

    setShape(shape);
    for (unsigned int i = 0; i < mPointMasses.size(); i++)
        ((PointMass*)mPointMasses[i])->Mass = pointMasses[i];

    updateAABB(0, true);
	Type = 1;
}
Example #3
0
void ckCdt::Ray::setPos(const ckVec& from, const ckVec& to)
{
    m_from = from;
    m_to = to;

    updateAABB();
}
Example #4
0
Body::Body(ClosedShape *shape, float massPerPoint, Vector2 position, float angleInRadians, Vector2 scale, bool kinematic)
{
	mDerivedAngle = 0.0f;
	mDerivedOmega = 0.0f;
	mLastAngle = 0.0f;

	mDerivedVel = Vector2::ZERO;

    mAABB =  new AABB();
    mDerivedPos = position;
    mDerivedAngle = angleInRadians;
    mLastAngle = mDerivedAngle;
    mScale = scale;
    mMaterial = 0;

	mBitMaskX = new Bitmask();
	mBitMaskY = new Bitmask();

	PI = 3.14159f;
	
	if(massPerPoint > 0.0f)
		mIsStatic = false;
	else
		mIsStatic  = true;

    mKinematic = kinematic;

    setShape(shape);
    for (int i = 0; i < mPointMassesC; i++)
		((PointMass*)mPointMasses[i])->Mass = massPerPoint;

    updateAABB(0, true);
	Type = 1;
}
Example #5
0
	void setSize(float size)
	{
		_size = size;
		updateAABB();
		_line.getVertices().resize(2);
		_line.getVertices()[0] = {0.0f, 0.0f};
		_line.getVertices()[1] = {_size, 0.0f};
		_line.update(Buffer::Usage::StaticDraw);
	}
Example #6
0
void GfxTerrain::recreate()
{
    ResizableData data(48);

    float *v0 = (float *)data.getData();
    float *v1 = v0 + 3;
    float *v2 = v1 + 3;
    float *v3 = v2 + 3;

    v0[0] = 0.0f;
    v0[1] = 0.0f;
    v0[2] = 0.0f;

    v1[0] = chunkSize;
    v1[1] = 0.0f;
    v1[2] = 0.0f;

    v2[0] = chunkSize;
    v2[1] = 0.0f;
    v2[2] = chunkSize;

    v3[0] = 0.0f;
    v3[1] = 0.0f;
    v3[2] = chunkSize;
/*
    float size = sizeInChunks * chunkSize;

    for (size_t x = 0; x < sizeInChunks; ++x)
    {
        for (size_t z = 0; z < sizeInChunks; ++z)
        {
            float *v0 = (float *)((uint8_t *)data.getData() + (x+z*sizeInChunks) * 48);
            float *v1 = v0 + 3;
            float *v2 = v1 + 3;
            float *v3 = v2 + 3;

            Position3D chunkPos(float(x*chunkSize) - size/2,
                                0.0f,
                                float(z*chunkSize) - size/2);

        }
    }*/

    GfxMeshAttrib attrib;
    attrib.type = GfxMeshAttribType::Position;
    attrib.dataType = GfxMeshAttribDataType::F32_3;
    attrib.data = data;
    mesh->setAttribute(attrib);

    mesh->numVertices = 4;

    updateAABB();
}
Example #7
0
	void Group::computeAABB()
	{
		if ((!boundingBoxEnabled)||(pool.getNbActive() == 0))
		{
			AABBMin.set(0.0f,0.0f,0.0f);
			AABBMax.set(0.0f,0.0f,0.0f);
			return;
		}

		const float maxFloat = std::numeric_limits<float>::max();
		AABBMin.set(maxFloat,maxFloat,maxFloat);
		AABBMax.set(-maxFloat,-maxFloat,-maxFloat);

		Pool<Particle>::iterator endIt = pool.end();
		for (Pool<Particle>::iterator it = pool.begin(); it != endIt; ++it)
			updateAABB(*it);
	}
Example #8
0
void Group::computeAABB()
{

	boundingBoxAABB.vcMin.Set(0.0f,0.0f,0.0f);
	boundingBoxAABB.vcMax.Set(0.0f,0.0f,0.0f);
	boundingBoxAABB.vcCenter.Set(0.0f,0.0f,0.0f);

	if( !boundingBoxEnabled || (pool.getSizeOfActive() == 0) )
	{
		return;
	}


	Particle* endIt = pool.end();
	for( Particle* it = pool.begin(); it < endIt; ++it )
		updateAABB(*it);
}
Example #9
0
	void Group::launchParticle(Particle& p,std::vector<EmitterData>::iterator& emitterIt,unsigned int& nbManualBorn)
	{
		if (nbManualBorn == 0)
		{
			emitterIt->emitter->emit(p);
			if (--emitterIt->nbParticles == 0)
				++emitterIt;
		}
		else
		{
			CreationData creationData = creationBuffer.front();

			if (creationData.zone != NULL)
				creationData.zone->generatePosition(p,creationData.full);
			else
				p.position() = creationData.position;

			if (creationData.emitter != NULL)
				creationData.emitter->generateVelocity(p);
			else
				p.velocity() = creationData.velocity;

			popNextManualAdding(nbManualBorn);
		}

		// Resets old position (fix 1.04.00)
		p.oldPosition() = p.position();

		// first parameter interpolation 
		// must be here so that the velocity has already been initialized
		p.interpolateParameters();

		if (fbirth != NULL)
			(*fbirth)(p);

		if (boundingBoxEnabled)
			updateAABB(p);

		if (distanceComputationEnabled)
			p.computeSqrDist();
	}
Example #10
0
	bool attacker::update(vector<Floekr2T::skill>& skills)
	{
		static Floekr2T::skill *temp;
		static f2Point offset;
		static f2Point point;

		
		if(completeWalk == true)
			return live;

		//获取下一拐点
		point = trace.getNextPoint(currentPoint);
		direction = point - position;
		direction.normalize();
		direction *= velocity;

		//更新位置信息
		position += direction;

		updateAABB(position);

		if(position == point)
		{
			//按照路径循坏走
			currentPoint = (currentPoint+1) % trace.getSumPoint();
			//if(++currentPoint == trace.getSumPoint())
				//completeWalk = true;
		}

		//AABB判断是否与技能碰撞
		for(int i=0; i<skills.size(); i++)
		{
			temp = &skills[i];

			////得到技能和攻击者之间的位移
			//offset = position - temp->position;

			////两者的AABB区域存在碰撞
			//if(abs(offset.x*2) < width + temp->width && 
			//	abs(offset.y*2) < height + temp->height)
			//{
			//	live = false;
			//	//直接跳出检测
			//	return live;
			//}

			//判定当前attacker与当前skill有无碰撞
			temp->live = !AABBandAABB(temp->aabb);

			//技能与攻击者发生碰撞
			if(temp->live == false)
			{
				//扣除伤害
				HP -= temp->damage;
				if(HP <= 0 && live == true)
					live = false;

				int j=0;
				//迭代找到元素并删除
				for(vector<Floekr2T::skill>::iterator it=skills.begin(); it!=skills.end(); )
				{
					if(j == i)
					{
						it = skills.erase(it);
						break;
					}
					else
					{
						++j;
						++it;
					}
				}
			}

			//只有在非存活状态才直接跳出
			if(!live)
				return live;
		}
		//static f2Point oldDirection;
		////若没有走到拐点
		//if(oldDirection == direction)
		//	return live;

		return live;
	}
Example #11
0
	bool Group::update(float deltaTime)
	{
		unsigned int nbManualBorn = nbBufferedParticles;
		unsigned int nbAutoBorn = 0;

		bool hasActiveEmitters = false;	

		// Updates emitters
		activeEmitters.clear();
		std::vector<Emitter*>::const_iterator endIt = emitters.end();
		for (std::vector<Emitter*>::const_iterator it = emitters.begin(); it != endIt; ++it)
		{
			if ((*it)->isActive())
			{
				int nb = (*it)->updateNumber(deltaTime);
				if (nb > 0)
				{
					EmitterData data = {*it,nb};
					activeEmitters.push_back(data);
					nbAutoBorn += nb;
				}
			}

			hasActiveEmitters |= !((*it)->isSleeping());
		}
		std::vector<EmitterData>::iterator emitterIt = activeEmitters.begin();

		unsigned int nbBorn = nbAutoBorn + nbManualBorn;

		// Inits bounding box
		if (boundingBoxEnabled)
		{
			const float maxFloat = std::numeric_limits<float>::max();
			AABBMin.set(maxFloat,maxFloat,maxFloat);
			AABBMax.set(-maxFloat,-maxFloat,-maxFloat);
		}

		// Prepare modifiers for processing
		activeModifiers.clear();
		for (std::vector<Modifier*>::iterator it = modifiers.begin(); it != modifiers.end(); ++it)
		{
			(*it)->beginProcess(*this);
			if ((*it)->isActive())
				activeModifiers.push_back(*it);
		}

		// Updates particles
		for (size_t i = 0; i < pool.getNbActive(); ++i)
		{
			if ((pool[i].update(deltaTime))||((fupdate != NULL)&&((*fupdate)(pool[i],deltaTime))))
			{
				if (fdeath != NULL)
					(*fdeath)(pool[i]);

				if (nbBorn > 0)
				{
					pool[i].init();
					launchParticle(pool[i],emitterIt,nbManualBorn);
					--nbBorn;
				}
				else
				{
					particleData[i].sqrDist = 0.0f;
					pool.makeInactive(i);
					--i;
				}
			}
			else
			{
				if (boundingBoxEnabled)
					updateAABB(pool[i]);

				if (distanceComputationEnabled)
					pool[i].computeSqrDist();
			}
		}

		// Terminates modifiers processing
		for (std::vector<Modifier*>::iterator it = modifiers.begin(); it != modifiers.end(); ++it)
			(*it)->endProcess(*this);

		// Emits new particles if some left
		for (int i = nbBorn; i > 0; --i)
			pushParticle(emitterIt,nbManualBorn);

		// Sorts particles if enabled
		if ((sortingEnabled)&&(pool.getNbActive() > 1))
			sortParticles(0,pool.getNbActive() - 1);

		if ((!boundingBoxEnabled)||(pool.getNbActive() == 0))
		{
			AABBMin.set(0.0f,0.0f,0.0f);
			AABBMax.set(0.0f,0.0f,0.0f);
		}

		return (hasActiveEmitters)||(pool.getNbActive() > 0);
	}
Example #12
0
ckCdt::Ray::Ray()
{
    m_from = m_to = ckVec::ZERO;

    updateAABB();
}
Example #13
0
bool Group::update(float deltaTimeInSeconds)
{
	uint32 nbManualBorn = NumOfBufferedParticles;
	uint32 nbAutoBorn = 0;

	bool hasActiveEmitters = false;

	// Updates emitters
	activeEmitters.clear();

	Emitter** endIt = emitters.end();
	for( Emitter** it = emitters.begin(); it < endIt; ++it )
	{
		if( (*it)->isActive() )
		{
			uint32 nb = (*it)->updateNumber(deltaTimeInSeconds);
			if( nb > 0 )
			{
				EmitterData data = {*it, nb};
				activeEmitters.add(data);
				nbAutoBorn += nb;
			}
		}

		hasActiveEmitters |= !((*it)->isSleeping());
	}

	EmitterData* emitterIt = activeEmitters.begin();

	uint32 nbBorn = nbAutoBorn + nbManualBorn;

	// Inits bounding box
	if(boundingBoxEnabled)
	{
		boundingBoxAABB.vcMin.Set(0, 0, 0);
		boundingBoxAABB.vcMax.Set(0, 0, 0);
		boundingBoxAABB.vcCenter.Set(0, 0, 0);
	}

	// Prepare modifiers for processing
	activeModifiers.clear();
	for( Modifier** it = modifiers.begin(); it < modifiers.end(); ++it )
	{
		(*it)->beginProcess(*this);
		if( (*it)->isActive() )
			activeModifiers.add(*it);
	}

	// Updates particles
	for( uint32 i = 0; i < pool.getSizeOfActive(); ++i )
	{
		if( pool[i].update(deltaTimeInSeconds) || ((fupdate != NULL) && ((*fupdate)(pool[i], deltaTimeInSeconds))) )
		{
			if( fdeath != NULL )
				(*fdeath)(pool[i]);

			if( nbBorn > 0 )
			{
				pool[i].init();
				launchParticle(pool[i], emitterIt, nbManualBorn);
				--nbBorn;
			}
			else
			{
				particleData[i].sqrDist = 0.0f;
				pool.makeInactive(i);
				--i;
			}
		}
		else
		{
			if( boundingBoxEnabled )
				updateAABB(pool[i]);

			if( distanceComputationEnabled )
				pool[i].computeSqrDist();
		}
	}

	// Terminates modifiers processing
	for( Modifier** it = modifiers.begin(); it < modifiers.end(); ++it )
		(*it)->endProcess(*this);

	// Emits new particles if some left
	for( uint32 i = nbBorn; i > 0; --i )
		pushParticle(emitterIt, nbManualBorn);

	// Sorts particles if enabled
	if( sortingEnabled && (pool.getSizeOfActive() > 1) )
		sortParticles(0, pool.getSizeOfActive() - 1);

	if( !boundingBoxEnabled || (pool.getSizeOfActive() == 0) )
	{
		boundingBoxAABB.vcMin.Set(0, 0, 0);
		boundingBoxAABB.vcMax.Set(0, 0, 0);
		boundingBoxAABB.vcCenter.Set(0, 0, 0);
	}

	return hasActiveEmitters || (pool.getSizeOfActive() > 0);
}
	void AxisAlignedBBSystem::OnEntityUpdate(LibCommon::Entity* ent, Components::IComponent*) {
        updateAABB(ent);
        auto aabb = ent->Get<Components::AxisAlignedBB>();
		NotifyUpdate(ent, aabb);
	}
 void AxisAlignedBBSystem::OnEntityAdd(LibCommon::Entity* e) {
     updateAABB(e);
     auto aabb = e->Get<Components::AxisAlignedBB>();
     NotifyUpdate(e, aabb);
 }
Example #16
0
void RayTracer::updateAABBs(std::vector<Triangle>& triangles)
{
	if (m_root != NULL)
		updateAABB(triangles, *m_root);
}