Esempio n. 1
0
bool HitableList::boundingBox(float aTime0, float aTime1, AABB &aBox) const
{
	// calculate the enclosing bounding box of the entire list
	if (mList.empty())
	{
		return false;
	}
	AABB tempBox;
	bool firstTrue = mList.at(0)->boundingBox(aTime0, aTime1, tempBox);
	if (!firstTrue)
	{
		return false;
	}
	else
	{
		aBox = tempBox;
	}
	for (size_t i = 1; i < mList.size(); ++i)
	{
		if (mList.at(i)->boundingBox(aTime0, aTime1, tempBox))
		{
			aBox = enclosingBox(aBox, tempBox);
		}
		else
		{
			return false;
		}
	}
	return true;
}
Esempio n. 2
0
//----------------------------------------------------------------------------------
// BVH node
BVHNode::BVHNode(const HitableListRef &aList, float aTime0, float aTime1)
{
	size_t n = aList->list().size();
	
	// pick an axis to sort along
	int axis = static_cast<int>(3.0f * randFloat());

	// sort along the chosen axis
	switch (axis)
	{
	case 0:	// x
		std::sort(aList->list().begin(), aList->list().end(), comparator(0));
		break;
	case 1: // y
		std::sort(aList->list().begin(), aList->list().end(), comparator(1));
		break;
	case 2: // z
		std::sort(aList->list().begin(), aList->list().end(), comparator(2));
		break;
	default:
		break;
	}

	if (n == 1) // one element
	{
		mLeft = mRight = aList->list().at(0);
	}
	if (n == 2) // two elements
	{
		mLeft = aList->list().at(0);
		mRight = aList->list().at(1);
	}
	else // split in half
	{
		size_t half_size = aList->list().size() / 2;
		std::vector<HitableRef> lowerHalf(aList->list().begin(), aList->list().begin() + half_size);
		std::vector<HitableRef> upperHalf(aList->list().begin() + half_size, aList->list().end());

		HitableListRef low = HitableList::create(lowerHalf);
		HitableListRef high = HitableList::create(upperHalf);

		mLeft = create(low, aTime0, aTime1);
		mRight = create(high, aTime0, aTime1);
	}

	AABB boxLeft;
	AABB boxRight;
	if (!mLeft->boundingBox(aTime0, aTime1, boxLeft) || !mRight->boundingBox(aTime0, aTime1, boxRight))
	{
		std::cerr << "No bounding box in BVH node constructor." << std::endl;
	}
	mBox = enclosingBox(boxLeft, boxRight);
}
Esempio n. 3
0
bool MovingSphere::boundingBox(float aTime0, float aTime1, AABB &aBox) const
{
	// the bounding box of a moving sphere must enclose the sphere's
	// entire range of motion, i.e. from it's center at time 0 to it's
	// center at time 1
	auto box0 = AABB(mCenter0 - glm::vec3(mRadius),	// min
					 mCenter0 + glm::vec3(mRadius));// max
	auto box1 = AABB(mCenter1 - glm::vec3(mRadius),	// min
					 mCenter1 + glm::vec3(mRadius));// max
	aBox = enclosingBox(box0, box1);
	return true;
}
Esempio n. 4
0
void RenderLayerModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
    RenderElement::styleDidChange(diff, oldStyle);
    updateFromStyle();

    if (requiresLayer()) {
        if (!layer() && layerCreationAllowedForSubtree()) {
            if (s_wasFloating && isFloating())
                setChildNeedsLayout();
            createLayer();
            if (parent() && !needsLayout() && containingBlock()) {
                layer()->setRepaintStatus(NeedsFullRepaint);
                // There is only one layer to update, it is not worth using |cachedOffset| since
                // we are not sure the value will be used.
                layer()->updateLayerPositions(0);
            }
        }
    } else if (layer() && layer()->parent()) {
#if ENABLE(CSS_COMPOSITING)
        if (oldStyle->hasBlendMode())
            layer()->parent()->dirtyAncestorChainHasBlendingDescendants();
#endif
        setHasTransformRelatedProperty(false); // All transform-related propeties force layers, so we know we don't have one or the object doesn't support them.
        setHasReflection(false);
        // Repaint the about to be destroyed self-painting layer when style change also triggers repaint.
        if (layer()->isSelfPaintingLayer() && layer()->repaintStatus() == NeedsFullRepaint)
            repaintUsingContainer(containerForRepaint(), layer()->repaintRect());
        layer()->removeOnlyThisLayer(); // calls destroyLayer() which clears m_layer
        if (s_wasFloating && isFloating())
            setChildNeedsLayout();
        if (s_hadTransform)
            setNeedsLayoutAndPrefWidthsRecalc();
    }

    if (layer()) {
        layer()->styleChanged(diff, oldStyle);
        if (s_hadLayer && layer()->isSelfPaintingLayer() != s_layerWasSelfPainting)
            setChildNeedsLayout();
    }

    bool newStyleIsViewportConstrained = style().hasViewportConstrainedPosition();
    bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportConstrainedPosition();
    if (newStyleIsViewportConstrained != oldStyleIsViewportConstrained) {
        if (newStyleIsViewportConstrained && layer())
            view().frameView().addViewportConstrainedObject(this);
        else
            view().frameView().removeViewportConstrainedObject(this);
    }

#if ENABLE(CSS_SCROLL_SNAP)
    const RenderStyle& newStyle = style();
    if (oldStyle && scrollSnapContainerRequiresUpdateForStyleUpdate(*oldStyle, newStyle)) {
        if (RenderLayer* renderLayer = layer()) {
            renderLayer->updateSnapOffsets();
            renderLayer->updateScrollSnapState();
        } else if (isBody() || isDocumentElementRenderer()) {
            FrameView& frameView = view().frameView();
            frameView.updateSnapOffsets();
            frameView.updateScrollSnapState();
            frameView.updateScrollingCoordinatorScrollSnapProperties();
        }
    }
    if (oldStyle && oldStyle->scrollSnapCoordinates() != newStyle.scrollSnapCoordinates()) {
        const RenderBox* scrollSnapBox = enclosingBox().findEnclosingScrollableContainer();
        if (scrollSnapBox && scrollSnapBox->layer()) {
            const RenderStyle& style = scrollSnapBox->style();
            if (style.scrollSnapType() != ScrollSnapType::None) {
                scrollSnapBox->layer()->updateSnapOffsets();
                scrollSnapBox->layer()->updateScrollSnapState();
                if (scrollSnapBox->isBody() || scrollSnapBox->isDocumentElementRenderer())
                    scrollSnapBox->view().frameView().updateScrollingCoordinatorScrollSnapProperties();
            }
        }
    }
#endif
}
Esempio n. 5
0
 void Chart::draw(GraphLib::GraphRenderer *renderer)
 {
     draw(renderer, enclosingBox());
 }