Beispiel #1
0
	void Collider::rotate(const Quaternion& rotation)
	{
		m_transform.q = rotation * m_transform.q;
		calculateAABB();

		if (m_pBody)
			m_pBody->calculateTree();
	}
Beispiel #2
0
	void Collider::setOrientation(const Quaternion& q)
	{
		m_transform.q = q;
		calculateAABB();

		if (m_pBody)
			m_pBody->calculateTree();
	}
Beispiel #3
0
	void Collider::setTransform(const Transform& t)
	{
		m_transform = t;
		calculateAABB();

		if (m_pBody)
			m_pBody->calculateTree();
	}
Beispiel #4
0
void Light::incRadius(float increment)
{
    assert(m_alwaysUpdate);

    m_radius += increment;

    calculateAABB();
    treeUpdate();
}
Beispiel #5
0
void Light::setRadius(float radius)
{
    assert(m_alwaysUpdate);

    m_radius = radius;

    calculateAABB();
    treeUpdate();
}
	ActorDynamic::ActorDynamic(){
		aType = ActorType::DYNAMIC;
		v3Velocity = glm::vec3(0);
		v3Friction = glm::vec3(0.0f);
		v3Damping = glm::vec3(0.1f);
		// Add our Line from oldpos to new pos
		Line *l = new Line();
		addShape(l);
		Actor::update(0);
		bActive = true;
		calculateAABB();
	}
Beispiel #7
0
	Collider::Collider(const ColliderDescription& descr)
		: m_pBody(nullptr),
		m_transform(descr.transform),
		m_pMaterial(descr.material),
		m_shape(descr.shape),
		m_sensor(descr.isSensor),
		m_pUserData(nullptr),
		m_next(nullptr),
		m_collisionGroup(0),
		m_collisionFilter(0)
	{
		calculateMassProperties();
		calculateAABB();
	}
	// This function finds all IndexedFaceSet whitin a group and find the min and max
	void calculateAABB(Group *group, Vec3f* min, Vec3f * max) {
		max->set(-BIG,-BIG,-BIG);
		min->set(BIG,BIG,BIG);

		vector<Group*> stack;
		Group* curgroup;
		stack.push_back(group);
		IndexedFaceSet *faceset=0;
		Vec3f submax;
		Vec3f submin;

		while (!stack.empty()) {
			curgroup=stack.back();
			stack.pop_back();
			for(vector<Drawable*>::iterator i=curgroup->children.begin();i!=curgroup->children.end();++i) {
				if (Group* gr=dynamic_cast<Group*>(*i)) 
					stack.push_back(gr);
		
				if (Shape* sh=dynamic_cast<Shape*>(*i))  {
					faceset=dynamic_cast<IndexedFaceSet*>(sh->geometry);
				}
				if (faceset!=0) {
					calculateAABB(faceset,&submin,&submax);
					// Maximum
					if ((submax)[0]>(*max)[0])
						(*max)[0]=(submax)[0];
					if ((submax)[1]>(*max)[1])
						(*max)[1]=(submax)[1];
					if ((submax)[2]>(*max)[2])
						(*max)[2]=(submax)[2];
					// Minimum
					if ((submin)[0]<(*min)[0])
						(*min)[0]=(submin)[0];
					if ((submin)[1]<(*min)[1])
						(*min)[1]=(submin)[1];
					if ((submin)[2]<(*min)[2])
						(*min)[2]=(submin)[2];
					faceset=0;
				}
			}
		}
	}
	void Actor::addShape(Shape* a_Shape){
		vShapes.push_back(a_Shape);
		a_Shape->updateModel(&m4Model);
		calculateAABB();
	}
Beispiel #10
0
	bool HGrid::queryShape(ShapePtr shape, const Transform& transform, ShapeQueryCallBack callback, void* userData)
	{

		m_tick++;

		int occupiedLevelsMask = m_occupiedLevelsMask;

		AABB aabb = calculateAABB(shape, transform);

		vec3 pos = aabb.c;
		float radius = length(aabb.e);

		bool hit = false;

		float size = MIN_CELL_SIZE;
		for (int level = 0; level < MAX_LEVELS;
			size *= CELL_TO_CELL_RATIO, occupiedLevelsMask >>= 1, ++level)
		{
			if (occupiedLevelsMask == 0)
				break;

			if ((occupiedLevelsMask & 1) == 0)
				continue;

			float ooSize = 1.0f / size;

			int x1, y1, z1, x2, y2, z2;

			float delta = radius + size*SPHERE_TO_CELL_RATIO + FLT_EPSILON*size;

			x1 = (int)floorf((pos.x - delta) * ooSize);
			y1 = (int)floorf((pos.y - delta) * ooSize);
			z1 = (int)floorf((pos.z - delta) * ooSize);

			x2 = (int)ceilf((pos.x + delta) * ooSize);
			y2 = (int)ceilf((pos.y + delta) * ooSize);
			z2 = (int)ceilf((pos.z + delta) * ooSize);

			for (int x = x1; x <= x2; ++x)
			{
				for (int y = y1; y <= y2; ++y)
				{
					for (int z = z1; z <= z2; ++z)
					{
						int bucket = calculateBucketID(x, y, z, level);
						if (m_timeStamp[bucket] == m_tick)
							continue;
						m_timeStamp[bucket] = m_tick;

						for (uint32 i = 0; i < m_objectBucket[bucket].size(); ++i)
						{
							Body* body = m_objectBucket[bucket][i].id->pBody;

							if (!body->queryShape(shape,transform, callback, userData))
								return true;
							else hit = true;
						}

					}
				}
			}
		}
		return hit;
	}