Ejemplo n.º 1
0
//==============================================================================
void Octree::calcAabb(U i, U j, U k, const Aabb& paabb, Aabb& out) const
{
	const Vec3& min = paabb.getMin();
	const Vec3& max = paabb.getMax();
	Vec3 d = (max - min) / 2.0;

	Vec3 omin;
	omin.x() = min.x() + d.x() * i;
	omin.y() = min.y() + d.y() * j;
	omin.z() = min.z() + d.z() * k;

	Vec3 omax = omin + d;

	// Scale the AABB with looseness
	F32 tmp0 = (1.0 + looseness) / 2.0;
	F32 tmp1 = (1.0 - looseness) / 2.0;
	Vec3 nomin = tmp0 * omin + tmp1 * omax;
	Vec3 nomax = tmp0 * omax + tmp1 * omin;

	// Crop to fit the parent's AABB
	for(U n = 0; n < 3; ++n)
	{
		if(nomin[n] < min[n])
		{
			nomin[n] = min[n];
		}

		if(nomax[n] > max[n])
		{
			nomax[n] = max[n];
		}
	}

	out = Aabb(nomin, nomax);
}
Ejemplo n.º 2
0
Archivo: bvh.hpp Proyecto: bssrdf/Ariel
 BvhNode(){
     m_bounds = Aabb();
     m_referenceOffset = 0;
     m_numberOfReferences = 0;
     m_left = 0;
     m_right = 0;
 }
Ejemplo n.º 3
0
		/*!
		 * \brief Tests for intersection with another Aabb
		 * \return TRUE If this Aabb intersects with \p other. Otherwise FALSE.
		 * 
		 * TODO: Implement correct/faster collision detection methods for
		 *       collisions between different types of bounding volumes.
		 */
		bool Aabb::collidesWith(const BoundingVolume& other) const {
			if (other.getVolumeType() == getVolumeType()) {
				const BoundingVolume* otherPointer = &other;
				const Aabb* aabbPointer = static_cast<const Aabb*>(otherPointer);
				return collidesWithInternal(*aabbPointer);
			}
			return collidesWithInternal(Aabb(other.getSurroundingAabbMin(),
											 other.getSurroundingAabbMax()));
		}
Ejemplo n.º 4
0
//Update AABB according to its shape member and primitive hierarchy
void Primitive::updateAabb()
{
  m_aabb.updateAabb(Aabb(m_shape->AABBmin(), m_shape->AABBmax()));
  for (int i = 0; i < m_primitive_count; ++i)
  {
    m_primitives[i]->updateAabb();
    m_aabb.updateAabb(m_primitives[i]->aabb());
  }
}
Ejemplo n.º 5
0
Aabb Aabb::SplitAlongZ(float startU, float endU) const {
  Vec3f nmin, nmax;

  nmin = InterpolateLinear(m_min, Vec3f(m_min[0], m_min[1], m_max[2]),
                              startU);
  nmax = InterpolateLinear(Vec3f(m_max[0], m_max[1], m_min[2]), m_max, endU);

  return Aabb(nmin, nmax);
}
Ejemplo n.º 6
0
Primitive::Primitive(boost::shared_ptr<ShapeInterface> _shape, boost::shared_ptr<Material> _material)
{
  m_shape = _shape;
  m_material = _material;
  m_primitive_count = 0;

  m_transform <<
  1, 0, 0, 0,
  0, 1, 0, 0,
  0, 0, 1, 0,
  0, 0, 0, 1;

  m_aabb.updateAabb(Aabb(m_shape->AABBmin(), m_shape->AABBmax()));
}
Ejemplo n.º 7
0
//==============================================================================
Aabb Aabb::getTransformed(const Transform& trf) const
{
	Mat3x4 absM;
	for(U i = 0; i < 12; ++i)
	{
		absM[i] = absolute(trf.getRotation()[i]);
	}

	Vec4 center = (m_min + m_max) * 0.5;
	Vec4 extend = (m_max - m_min) * 0.5;

	Vec4 newC = trf.transform(center);
	Vec4 newE = Vec4(absM * (extend * trf.getScale()), 0.0);

	return Aabb(newC - newE, newC + newE);
}
Ejemplo n.º 8
0
//==============================================================================
void ConvexHullShape::computeAabb(Aabb& aabb) const
{
	ANKI_ASSERT(m_points);
	
	Vec3 mina(MAX_F32);
	Vec3 maxa(MIN_F32);
	const Vec4* points = m_points;
	const Vec4* end = m_points + m_pointsCount;
	for(; points != end; ++points)
	{
		Vec4 o = (m_trfIdentity) ? *points : m_trf.transform(*points);
		for(U i = 0; i < 3; ++i)
		{
			mina[i] = min(mina[i], o[i]);
			maxa[i] = max(maxa[i], o[i]);
		}
	}

	aabb = Aabb(mina.xyz0(), maxa.xyz0());
}
Ejemplo n.º 9
0
    /*!
     * TODO: Implement correct/faster collision detection methods for
     *       collisions between different types of bounding volumes.
     */
    bool BoundingSphere::collidesWith(const BoundingVolume& other) const {
        if (other.getVolumeType() == BV_TYPE_SPHERE) {
            const BoundingSphere& otherSphere = (const BoundingSphere&) other;

            real distance = (getCenterVector() - otherSphere.getCenterVector()).dotProduct();
            real radii = (mRadius + otherSphere.getRadius()) * (mRadius + otherSphere.getRadius());

            //std::cout << "2. Distanz : " << distance << "     2. radius: " << radii << std::endl;
            
            if (distance > radii) {
                return 0;
            } else {
                //std::cout << "Kollision" << std::endl;
                return 1;
            }
        } else {
            Aabb thisAabb(getSurroundingAabbMin(), getSurroundingAabbMax());
            return
                thisAabb.collidesWith(
                    Aabb(other.getSurroundingAabbMin(),
                         other.getSurroundingAabbMax()));
        }
    }
Ejemplo n.º 10
0
xPointLight::xPointLight(const TString128 & name)
	: xObj(name)
{
	Position = Vec3::Zero;
	Diffuse = Color4::White;
	Specular = Color4::Black;

	Range = 20;

	mLight = World::Instance()->CreateLight(name);
	mNode = World::Instance()->CreateSceneNode();

	mNode->Attach(mLight);

	mNode->GetFlag().SetFlags(PICK_Flag);

	mLight->SetBounds(Aabb(-1, -1, -1, 1, 1, 1), Sphere(0, 0, 0, 1));
	mLight->SetType(LT_POINT);
	
	Technique * tech = xApp::Instance()->GetHelperShaderLib()->GetTechnique("PointLight");
	mBillboard = BillboardManager::Instance()->Create(tech);

	mBillboard->SetWidth(5);
	mBillboard->SetHeight(5);

	Material * mat = mBillboard->GetMaterial();

	mat->SetDepthWrite(false);
	mat->SetBlendMode(BM_ALPHA_BLEND);
	mat->SetDiffuseMap("Editor\\PointLight.png");

	mNode->Attach(mBillboard);

	SetScale(Range);
	SetDiffuse(Diffuse);
	SetSpecular(Specular);
}
Ejemplo n.º 11
0
	Mesh * PS_MeshSet::_createCone(bool up)
	{
		Float3 offset = mCenter;
		int rings = (mRings + 3) / 4;
		int segments = mSegments;
		float radius = mRadius;
		float height = mHeight;

		if (rings < 1)
			return NULL;

		Mesh * pMesh = new Mesh;
		SubMesh * sm = pMesh->NewSubMesh();

		float h1 = up ? 0 : height;
		float h2 = up ? height : 0;

		int iVertexCount = 1 + (rings * 4 + 1);
		int iIndexCount = rings * 4 * 3;
		int iPrimCount = iIndexCount / 3;

		d_assert(iIndexCount < 65536);

		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);
		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::TEXCOORD0, eVertexType::FLOAT2);

		VertexBufferPtr buffer = HWBufferManager::Instance()->NewVertexBuffer(20, iVertexCount);

		float * vert = (float *)buffer->Lock(eLockFlag::WRITE);
		{
			float r_step = (PI2 / (rings * 4));
			float d_step = (radius * 2 / rings);
			float u_step = 1 / (float)rings;
			float v_step = u_step;
			float x, z;
			float rads = -PI * 0.25f;

			*vert++ = 0 + offset.x;
			*vert++ = h1 + offset.x;
			*vert++ = 0 + offset.z;
			*vert++ = 0.5f;
			*vert++ = 0.5f;

			// top
			for (int i = 0; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 0;

				rads += r_step;
			}

			// right
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = 1;
				*vert++ = i * v_step;

				rads += r_step;
			}

			// bottom
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = 1 - i * u_step;
				*vert++ = 1;

				rads += r_step;
			}

			// left
			for (int i = 1; i <= rings; ++i)
			{
				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = h2 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = 0;
				*vert++ = 1 - i * u_step;

				rads += r_step;
			}
		}
		buffer->Unlock();

		IndexBufferPtr ibuffer = HWBufferManager::Instance()->NewIndexBuffer(iIndexCount);
		short * indices = (short *)ibuffer->Lock(eLockFlag::WRITE);
		{
			for (short i = 0; i < rings * 4; ++i)
			{
				*indices++ = i + 1;
				*indices++ = 0;
				*indices++ = i + 2;
			}
		}
		ibuffer->Unlock();

		sm->GetRenderOp()->vertexBuffers[0] = buffer;
		sm->GetRenderOp()->indexBuffer = ibuffer;
		sm->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;
		sm->GetRenderOp()->primCount = iPrimCount;

		sm->GetMaterial()->cullMode = eCullMode::NONE;
		sm->GetMaterial()->maps[eMapType::DIFFUSE] = RenderHelper::Instance()->GetWhiteTexture();

		pMesh->SetLocalAabb(Aabb(Float3(-radius, 0, -radius) + offset, Float3(radius, height, radius) + offset));

		return pMesh;
	}
Ejemplo n.º 12
0
	Mesh * PS_MeshSet::_createClinder()
	{
		Float3 offset = mCenter;
		int rings = mRings;
		float radius = mRadius;
		float height = mHeight;

		if (rings < 1)
			return NULL;

		Mesh * pMesh = new Mesh;
		SubMesh * sm = pMesh->NewSubMesh();

		int iVertexCount = (rings + 1) * 2;
		int iIndexCount = rings * 6;
		int iPrimCount = iIndexCount / 3;

		d_assert(iIndexCount < 65536);

		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);
		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::TEXCOORD0, eVertexType::FLOAT2);

		VertexBufferPtr buffer = HWBufferManager::Instance()->NewVertexBuffer(20, iVertexCount);

		float * vert = (float *)buffer->Lock(eLockFlag::WRITE);
		{
			float r_step = (2 * PI / rings);
			float u_step = 1 / (float)rings;
			float x, z, rads;

			for (int i = 0; i <= rings; ++i)
			{
				rads = i * r_step;

				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = 0 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 1;

				*vert++ = x + offset.x;
				*vert++ = height + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 0;
			}
		}
		buffer->Unlock();

		IndexBufferPtr ibuffer = HWBufferManager::Instance()->NewIndexBuffer(iIndexCount);
		short * indices = (short *)ibuffer->Lock(eLockFlag::WRITE);
		{
			for (short i = 0; i < rings; ++i)
			{
				int j = i * 2;

				*indices++ = j;
				*indices++ = j + 1;
				*indices++ = j + 2;

				*indices++ = j + 2;
				*indices++ = j + 1;
				*indices++ = j + 3;
			}
		}
		ibuffer->Unlock();

		sm->GetRenderOp()->vertexBuffers[0] = buffer;
		sm->GetRenderOp()->indexBuffer = ibuffer;
		sm->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;
		sm->GetRenderOp()->primCount = iPrimCount;

		sm->GetMaterial()->cullMode = eCullMode::NONE;
		sm->GetMaterial()->maps[eMapType::DIFFUSE] = RenderHelper::Instance()->GetWhiteTexture();

		pMesh->SetLocalAabb(Aabb(Float3(-radius, 0, -radius) + offset, Float3(radius, height, radius) + offset));

		return pMesh;
	}
Ejemplo n.º 13
0
	Mesh * PS_MeshSet::_createSphere()
	{
		Float3 offset = mCenter;
		int rings = mRings;
		int segments = mSegments;
		float radius = mRadius;

		if (rings < 1 || segments < 1)
			return NULL;

		Mesh * pMesh = new Mesh;
		SubMesh * sm = pMesh->NewSubMesh();

		int iVertexCount = (rings + 1) * (segments + 1);
		int iIndexCount = rings * segments * 6;
		int iPrimCount = iIndexCount / 3;

		d_assert(iIndexCount < 65536);

		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);
		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::TEXCOORD0, eVertexType::FLOAT2);

		VertexBufferPtr buffer = HWBufferManager::Instance()->NewVertexBuffer(20, iVertexCount);

		float * vert = (float *)buffer->Lock(eLockFlag::WRITE);
		{
			float fTileRingAngle = (PI / rings);
			float fTileSegAngle = (PI * 2 / segments);
			float u_step = 1 / (float)rings;
			float v_step = 1 / (float)segments;
			float r;
			short i, j;
			Float3 pos;

			for (i = 0; i <= rings; ++i)
			{
				r = radius * Math::Sin(i * fTileRingAngle);
				pos.y = radius * Math::Cos(i * fTileRingAngle);

				for (j = 0; j <= segments; ++j)
				{
					pos.x = r * Math::Cos(j * fTileSegAngle);
					pos.z = r * Math::Sin(j * fTileSegAngle);

					*vert++ = pos.x + offset.x;
					*vert++ = pos.y + offset.y;
					*vert++ = pos.z + offset.z;
					*vert++ = i * u_step;
					*vert++ = j * v_step;
				}

			}
		}
		buffer->Unlock();

		IndexBufferPtr ibuffer = HWBufferManager::Instance()->NewIndexBuffer(iIndexCount);
		short * indices = (short *)ibuffer->Lock(eLockFlag::WRITE);
		{
			short row = 0, row_n = 0;
			short i, j;

			for (i = 0; i < rings; ++i)
			{
				row_n = row + segments + 1;

				for (j = 0; j < segments; ++j)
				{
					*indices++ = row + j;
					*indices++ = row + j + 1;
					*indices++ = row_n + j;

					*indices++ = row_n + j;
					*indices++ = row + j + 1;
					*indices++ = row_n + j + 1;
				}

				row += segments + 1;
			}
		}
		ibuffer->Unlock();

		sm->GetRenderOp()->vertexBuffers[0] = buffer;
		sm->GetRenderOp()->indexBuffer = ibuffer;
		sm->GetRenderOp()->primCount = iPrimCount;
		sm->GetRenderOp()->primType= ePrimType::TRIANGLE_LIST;

		sm->GetMaterial()->maps[eMapType::DIFFUSE] = RenderHelper::Instance()->GetWhiteTexture();

		pMesh->SetLocalAabb(Aabb(Float3(-radius, -radius, -radius) + offset, Float3(radius, radius, radius) + offset));

		return pMesh;
	}
Ejemplo n.º 14
0
void Frustum::ExtractAabb(Aabb *box) const {
  *box = Aabb();
  for (int k=0; k<8; k++) {
    box->Add(m_conners[k]);
  }
}
Ejemplo n.º 15
0
Aabb Projection::GetAabb() const {
  return Aabb(Vec3f(m_left, m_bottom, -m_farD),
              Vec3f(m_farRight, m_farTop, -m_nearD));
}
Ejemplo n.º 16
0
Aabb^ GimBvhTreeNode::Bound::get()
{
	return gcnew Aabb(&_native->m_bound);
}
Ejemplo n.º 17
0
	Aabb Sphere::GetAabb(void)const
	{
		return Aabb( center, Float3(radius, radius, radius) );
	}