Exemple #1
0
Sphere::Sphere(const Sphere& s){
    c = s.c;
    r = s.r;
    material(s.material);
    material.directScale = 1.0;
    calculateBBox();
}
Exemple #2
0
Sphere::Sphere(){
    c(0, 0, 0);
    r = 0.0;
    RGBAPixel tempColor(0,255,0);
    material(tempColor, 1, 1);
    material.directScale = 1.0;
    calculateBBox();
}
Exemple #3
0
Sphere::Sphere(const Point3D& p, const double radius){
    c(p);
    r = radius;
    RGBAPixel tempColor(0,255,0);
    material(tempColor, 1, 1);
    material.directScale = 0.2;
    calculateBBox();
}
Exemple #4
0
const BoundingBox BezierCurve::calculateBBox() const
{
	BoundingBox b;
	const unsigned ns = numSegments();
    for(unsigned i=0; i < ns; i++)
		b.expandBy(calculateBBox(i));
	return b;
}
Exemple #5
0
bool ATetrahedronMesh::intersectBox(unsigned icomponent, const BoundingBox & box)
{
    BoundingBox tbox = calculateBBox(icomponent);
    if(!tbox.intersect(box)) return false;
    
    Vector3F * p = points();
	unsigned * v = tetrahedronIndices(icomponent);
    return gjk::IntersectTest::evaluateTetrahedron(p, v);
}
Exemple #6
0
// #419begin #type=3 #src=http://www.raytracegroundup.com/downloads/
Sphere& Sphere::operator= (Sphere& rhs){
    if (this == &rhs)
        return (*this);
    
    GeometricObject::operator= (rhs);
    
    c = rhs.c;
    r = rhs.r;
    material(rhs.material);
    calculateBBox();
    
    return (*this);
}
Exemple #7
0
bool BezierCurve::intersectBox(const BoundingBox & box)
{
    BoundingBox ab = calculateBBox();

    if(!ab.intersect(box)) return false;
    
	const unsigned ns = numSegments();
    for(unsigned i=0; i < ns; i++) {
        BezierSpline sp;
        getSegmentSpline(i, sp);   
        if(intersectBox(sp, box)) return true;
    }
	
	return false;
}
Exemple #8
0
bool BezierCurve::intersectTetrahedron(const Vector3F * tet)
{
    BoundingBox tbox;
    tbox.expandBy(tet[0]);
	tbox.expandBy(tet[1]);
	tbox.expandBy(tet[2]);
	tbox.expandBy(tet[3]);
	
    BoundingBox ab = calculateBBox();

    if(!ab.intersect(tbox)) return false;
    
	const unsigned ns = numSegments();
    for(unsigned i=0; i < ns; i++) {
        BezierSpline sp;
        getSegmentSpline(i, sp);   
        if(intersectTetrahedron(sp, tet, tbox)) return true;
    }
	
	return false;
}
void CitySceneGenerator::generate(Scene* scene) {
	auto renderer = scene->renderer();
	auto material = std::make_shared<PhongMaterial>(renderer);
	material->setShader(renderer->shaderManager()->getGlslProgram("phong"));

	PhongMaterialData materialData = { glm::vec4(0.0f, 0.1f, 0.0f, 1.0f), 
		glm::vec4(0.8f, 0.3f, 0.1f, 1.0f), glm::vec4(0.3f, 0.3f, 0.3f, 1.0f), 5.0f };

	material->properties()->setData(materialData);
	material->properties()->flushData();

	auto mesh = std::make_shared<Mesh>();
	mesh->setPrimitiveType(PrimitiveType::TriangleList);

	size_t buildingVerticesCount = sizeof(buildingVertices) / sizeof(*buildingVertices);
	std::vector<char> vertices(reinterpret_cast<const char*>(buildingVertices), 
		reinterpret_cast<const char*>(buildingVertices) + sizeof(buildingVertices));
	std::vector<VertexElement> layout = {
		VertexElement(3, VertexElementType::Float),
		VertexElement(3, VertexElementType::Float)
	};
	mesh->loadVertices(vertices, buildingVerticesCount, layout);

	size_t buildingIndicesCount = sizeof(buildingIndices) / sizeof(*buildingIndices);
	std::vector<uint32_t> indices(reinterpret_cast<const unsigned*>(buildingIndices), 
		reinterpret_cast<const unsigned*>(buildingIndices) + buildingIndicesCount);
	mesh->loadIndices(indices);

	size_t numBuildings = 1000;
	float citySize = 500.0f;
	float minBuildingSize = 10.0f;
	float maxBuildingSize = 60.0f;
	float minHeightToWidthRatio = 8.0f;
	float maxHeightToWidthRatio = 16.0f;

	std::uniform_real_distribution<float> angleDist(0.0f, 360.0f);
	std::uniform_real_distribution<float> positionDist(-citySize, citySize);
	std::uniform_real_distribution<float> canonicalDist;

	std::vector<std::shared_ptr<BaseSceneObject>> buildings;
	for (size_t i = 0; i < numBuildings; i++) {
		auto building = std::make_shared<Building>(mesh, material);

		// set random position
		glm::mat4 model = glm::translate(glm::mat4(1.0f),
			glm::vec3(positionDist(m_rng), positionDist(m_rng), 0.0f)
		);

		// rotate around z with random angle
		model = glm::rotate(model, angleDist(m_rng), glm::vec3(0.0f, 0.0f, 1.0f));

		glm::vec3 scale;
		// multiplying uniform distribution will generate beta distribution
		scale.x = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng)
			* (maxBuildingSize - minBuildingSize) + minBuildingSize;
		scale.y = scale.x;
		scale.z = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * scale.x
			* (maxHeightToWidthRatio - minHeightToWidthRatio) + minHeightToWidthRatio;
		model = glm::scale(model, scale);

		building->setModelMatrix(model);
		building->calculateBBox();

		buildings.push_back(building);
	}

	scene->setStaticGeometry(std::move(buildings));
}
Exemple #10
0
Sphere::Sphere(const Point3D& p, const double radius, const Material& _material, PNG* _texture) : GeometricObject(_material, false, _texture){
    c(p);
    r = radius;
    material.directScale = 1.0;
    calculateBBox();
}
Exemple #11
0
const Vector3F Geometry::boundingCenter() const
{
	BoundingBox box = calculateBBox();
	return box.center();
}