Esempio n. 1
0
void DumpVisitor::ApplyLOD(LOD &l)
{
	ApplyNode(l);

	m_level++;
	for (unsigned int i = 0; i < l.GetNumChildren(); i++) {
		l.GetChildAt(i)->Accept(*this);
		m_lodStats.push_back(m_stats);
		memset(&m_stats, 0, sizeof(LodStatistics));
	}
	m_level--;
}
Esempio n. 2
0
void ScreenMVCullVisitor::apply(LOD& node)
{
    bool status = _cullingStatus;
    bool firstStatus = _firstCullStatus;

    if(isCulled(node))
    {
        _firstCullStatus = firstStatus;
        _cullingStatus = status;
        return;
    }

    // push the culling mode.
    pushCurrentMask();

    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if(node_state)
        pushStateSet(node_state);

    handle_cull_callbacks_and_traverse(node);

    // pop the node's state off the render graph stack.    
    if(node_state)
        popStateSet();

    // pop the culling mode.
    popCurrentMask();

    _firstCullStatus = firstStatus;
    _cullingStatus = status;
}
void CullVisitor::apply(LOD& node)
{
    if (isCulled(node)) return;

    // push the culling mode.
    pushCurrentMask();

    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if (node_state) pushStateSet(node_state);

    handle_cull_callbacks_and_traverse(node);

    // pop the node's state off the render graph stack.    
    if (node_state) popStateSet();

    // pop the culling mode.
    popCurrentMask();
}
Esempio n. 4
0
ref_ptr<Group> VTXReader::processModel(std::istream * str, int offset,
                                       Model * currentModel)
{
    int              i;
    VTXModel         model;
    float            lastDistance;
    float            distance;
    LOD *            lodNode = 0;
    ref_ptr<Group>   group;
    ref_ptr<Group>   result;

    // Seek to the model
    str->seekg(offset);

    // Read it
    str->read((char *) &model, sizeof(VTXModel));

    // If we have multiple LODs, create an LOD node for them
    if (model.num_lods > 1)
        lodNode = new LOD();

    // Initialize the distances
    lastDistance = 0.0;
    distance = 0.0;

    // Process the LODs
    for (i = 0; i < model.num_lods; i++)
    {
        // Process the LOD group, passing the current MDL model through
        group = processLOD(i, &distance, str,
                           offset + model.lod_offset +
                           (i * sizeof(VTXModelLOD)),
                           currentModel);

        // If this isn't the only LOD, add it to the LOD node
        if (model.num_lods > 1)
        {
            lodNode->addChild(group.get());

            // Fix the LOD distances
            if (distance < 0)
            {
                // Fix negative distance (my best guess is that these mean
                // for the LOD to never switch out)
                distance = 100000.0;
            }

            // Set the ranges on the previous LOD (now that we know the
            // switch point for this one)
            if (i > 0)
                lodNode->setRange(i-1, lastDistance, distance);

            lastDistance = distance;
        }
    }

    if (i > 1)
        lodNode->setRange(i-1, lastDistance, 100000.0);

    // Return either the LOD node or the single LOD group
    if (model.num_lods > 1)
        result = lodNode;
    else
        result = group;

    return result;
}
Esempio n. 5
0
void TerrainHeightState::update()
{
	if (getSceneManager() && getSceneManager()->getTerrain() && SculptorDecal_)
	{
		Vector2 pp = getSceneManager()->getPickingPoint();
		SculptorDecal_->setCenter(Vector4(pp.x, 0, pp.y, 1));
	}

	if (isKeyDown(VK_LBUTTON))
	{
		if (getSceneManager() && getSceneManager()->getTerrain())
		{
			Terrain* t = getSceneManager()->getTerrain();
			Vector4 center = SculptorDecal_->getCenter();
			LOD* d = getSceneManager()->getLOD();
			int n = d->getVerticesNumberOneSide();
			float radius = SculptorDecal_->getRadius();
			RectangleT rc;
			rc.left_ = center.x - radius;
			rc.right_ = center.x + radius;
			rc.bottom_ = center.z - radius;
			rc.top_ = center.z + radius;
			ChunkVec cs;
			getSceneManager()->getChunks(cs, getSceneManager()->getTerrainQuadTreeRoot(), rc);
			float radius2 = radius * radius;
			bool dirty = false;
			for (size_t i = 0; i != cs.size(); ++i)
			{
				Chunk* c0 = cs[i]; 
				c0->setSelected(true);
				for (int x = 0; x != n; ++x)
				for (int z = 0; z != n; ++z)
				{
					Vector2 p = c0->getWorldCoordination(x, z);
					float distance2 = (p.x - center.x)*(p.x - center.x) + (p.y - center.z)*(p.y - center.z);
					if (distance2 <= radius2)
					{
						dirty = true;
						float h = 0;
						if (getGlobal()->isSmoothAverage())
						{
							float left = c0->getHeightFromTopology(x - 1, z);
							float right = c0->getHeightFromTopology(x + 1, z);
							float bottom = c0->getHeightFromTopology(x, z - 1);
							float top = c0->getHeightFromTopology(x, z + 1);
							h = (c0->getHeightFromTopology(x, z) + left + right + bottom + top) / 5; 
							//
						}
						else
						{
							if (getGlobal()->isAbosoluteHeight())
							{
								h = getGlobal()->getAbsoluteHeight();
							}
							else
							{
								float r = cos(MATH_PI_Half * distance2/radius2);
								r = 1 - distance2/radius2;
								h = c0->getHeightFromTopology(x, z) + r * getSculptorStrength();
							}
							//
							if(0){
								float left = c0->getHeightFromTopology(x - 1, z);
								float right = c0->getHeightFromTopology(x + 1, z);
								float bottom = c0->getHeightFromTopology(x, z - 1);
								float top = c0->getHeightFromTopology(x, z + 1);
								h = (h + left + right + bottom + top) / 5; 
							}
						}
						//
						if (h > 255)
						{
							h = 255;
						}
						//
						c0->setHeightFromTopology(x, z, h);
					}
				}
				//
				c0->refreshHeight();
			}
			if (dirty)
			{
				QuadNode::calculateBoundingBox(getSceneManager()->getTerrainQuadTreeRoot());
			}
		}
	}
}