示例#1
0
int SquareObstacle::getDistance(int x, int y, int angle) const
{
    int min_dist = World::INVALID_DISTANCE;

    Geo::Point src = Geo::Point(x, y);
    Geo::Line line = Geo::Line( src, 1.0, Geo::convert_radian(angle) );
    double radian = line.angle();

    std::vector<Geo::Line> edge_list = getEdgeList();

    for(unsigned int i = 0; i < edge_list.size(); i++)
    {
        Geo::Line edge = edge_list.at(i);

        if(!Geo::intersects_l(edge, line))
            continue;

        Geo::Point tgt = Geo::intersection_l(edge, line);

        if(!isInArea(tgt))
            continue;

        if(!Geo::equals(radian, Geo::angle(src, tgt)))
            continue;

        int distance = static_cast<int>(Geo::distance(src, tgt));

        if( min_dist == World::INVALID_DISTANCE || distance < min_dist)
            min_dist = distance;
    }

    return min_dist;
}
示例#2
0
Node::~Node() {
    // remove all edges too while deleting the node.
    Edge* edge = getEdgeList();
    Edge* tmp;
    while(edge != NULL) {
        tmp = edge->getNext();
        delete edge;
        edge = NULL;
        edge = tmp;
    }
}
示例#3
0
CoinPackedVector * 
VrpModel::getSolution(const double *sol)
{
    // Transform to sparse vector from dense array.
    int varnum = solver()->getNumCols();
    std::vector<VrpVariable *>vars = getEdgeList();
    double etol = etol_;
    int *indices = new int[varnum];
    double *values = new double[varnum]; /* n */
    int i, cnt = 0;
    
    assert(varnum == edgenum_);
    
    for (i = 0; i < varnum; i++){
        if (sol[i] > etol || sol[i] < -etol){ // Store nonzero
            indices[cnt] = vars[i]->getIndex();
            values[cnt++] = sol[i];
        }
    }
    
    return(new CoinPackedVector(varnum, cnt, indices, values, false));
}
示例#4
0
	//-----------------------------------------------------------------------------
	ShadowCaster::ShadowRenderableListIterator
	ManualObject::getShadowVolumeRenderableIterator(
		ShadowTechnique shadowTechnique, const Light* light,
		HardwareIndexBufferSharedPtr* indexBuffer,
		bool extrude, Real extrusionDistance, unsigned long flags)
	{
		assert(indexBuffer && "Only external index buffers are supported right now");		

        EdgeData* edgeList = getEdgeList();
        if (!edgeList)
        {
            return ShadowRenderableListIterator(
                mShadowRenderables.begin(), mShadowRenderables.end());
        }

		// Calculate the object space light details
		Vector4 lightPos = light->getAs4DVector();
		Matrix4 world2Obj = mParentNode->_getFullTransform().inverseAffine();
		lightPos = world2Obj.transformAffine(lightPos);


		// Init shadow renderable list if required (only allow indexed)
		bool init = mShadowRenderables.empty() && mAnyIndexed;

		EdgeData::EdgeGroupList::iterator egi;
		ShadowRenderableList::iterator si, siend;
		ManualObjectSectionShadowRenderable* esr = 0;
		SectionList::iterator seci;
		if (init)
			mShadowRenderables.resize(edgeList->edgeGroups.size());

		siend = mShadowRenderables.end();
		egi = edgeList->edgeGroups.begin();
		seci = mSectionList.begin();
		for (si = mShadowRenderables.begin(); si != siend; ++seci)
		{
            // Skip non-indexed geometry
            if (!(*seci)->getRenderOperation()->useIndexes)
            {
                continue;
            }

			if (init)
			{
				// Create a new renderable, create a separate light cap if
				// we're using a vertex program (either for this model, or
				// for extruding the shadow volume) since otherwise we can
				// get depth-fighting on the light cap
				MaterialPtr mat = (*seci)->getMaterial();
				mat->load();
				bool vertexProgram = false;
				Technique* t = mat->getBestTechnique(0, *seci);
				for (unsigned short p = 0; p < t->getNumPasses(); ++p)
				{
					Pass* pass = t->getPass(p);
					if (pass->hasVertexProgram())
					{
						vertexProgram = true;
						break;
					}
				}
				*si = OGRE_NEW ManualObjectSectionShadowRenderable(this, indexBuffer,
					egi->vertexData, vertexProgram || !extrude);
			}
			// Get shadow renderable
			esr = static_cast<ManualObjectSectionShadowRenderable*>(*si);
			HardwareVertexBufferSharedPtr esrPositionBuffer = esr->getPositionBuffer();
			// Extrude vertices in software if required
			if (extrude)
			{
				extrudeVertices(esrPositionBuffer,
					egi->vertexData->vertexCount,
					lightPos, extrusionDistance);

			}

            ++si;
            ++egi;
		}
		// Calc triangle light facing
		updateEdgeListLightFacing(edgeList, lightPos);

		// Generate indexes and update renderables
		generateShadowVolume(edgeList, *indexBuffer, light,
			mShadowRenderables, flags);


		return ShadowRenderableListIterator(
			mShadowRenderables.begin(), mShadowRenderables.end());


	}
示例#5
0
	//---------------------------------------------------------------------
	bool ManualObject::hasEdgeList()
	{
		return getEdgeList() != 0;
	}
示例#6
0
void VrpModel::createNet(CoinPackedVector *vec)
{
   n_->createNet(vec, demand_, getEdgeList(), etol_, vertnum_);
}