コード例 #1
0
void VertexClosestJointInfo::calcShortestDistance(){
	// calc closest influence
	MDagPath closestInfluence;
	MVector pointPos(this->vertPosition());
	static_cast<ClosestJointGeometryInfo *>(&this->geometry)->influenceFinder.findClosestInfluence(pointPos,closestInfluence,
		static_cast<WeightsByClosestJoint * >(this->geometry.engine)->useIntersectionRanking);


	this->initializeSecondaryWeightsBuffers();

	// write weights now
	double *prevWeight = this->skinWeights;
	double *currWeight = this->nextSkinWeights;
	for (size_t i=0,count=this->geometry.numVertWeights();i<count;i++,currWeight++,prevWeight++){
		
		
		MDagPath currPath;
		if (!this->geometry.getLogicalInfluencePath(geometry.inflPhysicalToLogical[i],currPath))
			continue;
		
		if (currPath==closestInfluence){
			// in special case, when influence is locked, but still is the closest one,
			// it gets it's current weight + all free weight
			*currWeight = this->geometry.inflLocked[i]?*prevWeight+this->totalFreeWeight:this->totalFreeWeight;
		}
		else {
			*currWeight = this->geometry.inflLocked[i]?*prevWeight:0.0;
		}
	}

	this->swapWeightsBuffers();


}
コード例 #2
0
ファイル: debugging.cpp プロジェクト: Adrian-Revk/openmw
ManualObject *Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid)
{
    ManualObject *result = mSceneMgr->createManualObject();
    const float height = POINT_MESH_BASE * sqrtf(2);

    result->begin(PATHGRID_POINT_MATERIAL, RenderOperation::OT_TRIANGLE_STRIP);

    bool first = true;
    uint32 startIndex = 0;
    for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin();
        it != pathgrid->mPoints.end();
        it++, startIndex += 6)
    {
        Vector3 pointPos(it->mX, it->mY, it->mZ);

        if (!first)
        {
            // degenerate triangle from previous octahedron
            result->index(startIndex - 4); // 2nd point of previous octahedron
            result->index(startIndex); // start point of current octahedron
        }

        result->position(pointPos + Vector3(0, 0, height)); // 0
        result->position(pointPos + Vector3(-POINT_MESH_BASE, -POINT_MESH_BASE, 0)); // 1
        result->position(pointPos + Vector3(POINT_MESH_BASE, -POINT_MESH_BASE, 0)); // 2
        result->position(pointPos + Vector3(POINT_MESH_BASE, POINT_MESH_BASE, 0)); // 3
        result->position(pointPos + Vector3(-POINT_MESH_BASE, POINT_MESH_BASE, 0)); // 4
        result->position(pointPos + Vector3(0, 0, -height)); // 5

        result->index(startIndex + 0);
        result->index(startIndex + 1);
        result->index(startIndex + 2);
        result->index(startIndex + 5);
        result->index(startIndex + 3);
        result->index(startIndex + 4);
        // degenerates
        result->index(startIndex + 4);
        result->index(startIndex + 5);
        result->index(startIndex + 5);
        // end degenerates
        result->index(startIndex + 1);
        result->index(startIndex + 4);
        result->index(startIndex + 0);
        result->index(startIndex + 3);
        result->index(startIndex + 2);

        first = false;
    }

    result->end();

    result->setVisibilityFlags (RV_Debug);

    return result;
}
コード例 #3
0
ファイル: mob.cpp プロジェクト: BenCastricum/scummvm
int PrinceEngine::getMob(Common::Array<Mob> &mobList, bool usePriorityList, int posX, int posY) {

	Common::Point pointPos(posX, posY);

	int mobListSize;
	if (usePriorityList) {
		mobListSize = _mobPriorityList.size();
	} else {
		mobListSize = mobList.size();
	}

	for (int mobNumber = 0; mobNumber < mobListSize; mobNumber++) {
		Mob *mob = nullptr;
		if (usePriorityList) {
			mob = &mobList[_mobPriorityList[mobNumber]];
		} else {
			mob = &mobList[mobNumber];
		}

		if (mob->_visible) {
			continue;
		}

		int type = mob->_type & 7;
		switch (type) {
		case 0:
		case 1:
			//normal_mob
			if (!mob->_rect.contains(pointPos)) {
				continue;
			}
			break;
		case 3:
			//mob_obj
			if (mob->_mask < kMaxObjects) {
				int nr = _objSlot[mob->_mask];
				if (nr != 0xFF) {
					Object &obj = *_objList[nr];
					Common::Rect objectRect(obj._x, obj._y, obj._x + obj._width, obj._y + obj._height);
					if (objectRect.contains(pointPos)) {
						Graphics::Surface *objSurface = obj.getSurface();
						byte *pixel = (byte *)objSurface->getBasePtr(posX - obj._x, posY - obj._y);
						if (*pixel != 255) {
							break;
						}
					}
				}
			}
			continue;
			break;
		case 2:
		case 5:
			//check_ba_mob
			if (!_backAnimList[mob->_mask].backAnims.empty()) {
				int currentAnim = _backAnimList[mob->_mask]._seq._currRelative;
				Anim &backAnim = _backAnimList[mob->_mask].backAnims[currentAnim];
				if (backAnim._animData != nullptr) {
					if (!backAnim._state) {
						Common::Rect backAnimRect(backAnim._currX, backAnim._currY, backAnim._currX + backAnim._currW, backAnim._currY + backAnim._currH);
						if (backAnimRect.contains(pointPos)) {
							int phase = backAnim._showFrame;
							int phaseFrameIndex = backAnim._animData->getPhaseFrameIndex(phase);
							Graphics::Surface *backAnimSurface = backAnim._animData->getFrame(phaseFrameIndex);
							byte pixel = *(byte *)backAnimSurface->getBasePtr(posX - backAnim._currX, posY - backAnim._currY);
							if (pixel != 255) {
								if (type == 5) {
									if (mob->_rect.contains(pointPos)) {
										break;
									}
								} else {
									break;
								}
							}
						}
					}
				}
			}
			continue;
			break;
		default:
			//not_part_ba
			continue;
			break;
		}

		if (usePriorityList) {
			return _mobPriorityList[mobNumber];
		} else {
			return mobNumber;
		}
	}
	return -1;
}
コード例 #4
0
ファイル: leaf.cpp プロジェクト: gaoyakun/atom3d
void LeafModel::updateLeafCards (ATOM_Node *treeNode)
{
	const float overlapEpsl = 0.1f;

	leaves.resize (0);

	ATOM_BBox bbox;
	bbox.beginExtend ();
	// compute leaf bounding box
	for (unsigned i = 0; i < treeNode->getNumChildren(); ++i)
	{
		const ATOM_Matrix4x4f &matrixTest = treeNode->getChild (i)->getO2T ();
		ATOM_Vector3f center(matrixTest.m30, matrixTest.m31, matrixTest.m32);
		float radius = matrixTest.m00;
		bbox.extend (center + ATOM_Vector3f(-radius,  radius, -radius));
		bbox.extend (center + ATOM_Vector3f(-radius,  radius,  radius));
		bbox.extend (center + ATOM_Vector3f(-radius, -radius, -radius));
		bbox.extend (center + ATOM_Vector3f(-radius, -radius,  radius));
		bbox.extend (center + ATOM_Vector3f( radius,  radius, -radius));
		bbox.extend (center + ATOM_Vector3f( radius,  radius,  radius));
		bbox.extend (center + ATOM_Vector3f( radius, -radius, -radius));
		bbox.extend (center + ATOM_Vector3f( radius, -radius,  radius));
	}

	ATOM_Vector3f bboxBounds = bbox.getMax() - bbox.getMin ();
	float interval = bboxBounds.x * bboxBounds.y * bboxBounds.z / density;
	interval = ATOM_pow (interval, 0.333f);

	unsigned dimX = bboxBounds.x / interval + 1;
	unsigned dimY = bboxBounds.y / interval + 1;
	unsigned dimZ = bboxBounds.z / interval + 1;

	// test points
	float leafWidth = width;
	float leafHeight = height;
	for (unsigned i = 0; i < dimX; ++i)
		for (unsigned j = 0; j < dimY; ++j)
			for (unsigned k = 0; k < dimZ; ++k)
			{
				ATOM_Vector3f pointPos(interval * i, interval * j, interval * k);
				pointPos += bbox.getMin();

				bool contains = false;
				for (unsigned s = 0; s < treeNode->getNumChildren(); ++s)
				{
					const ATOM_Matrix4x4f &matrixTestAgainst = treeNode->getChild(s)->getO2T ();
					ATOM_Vector3f center(matrixTestAgainst.m30, matrixTestAgainst.m31, matrixTestAgainst.m32);
					float radius = matrixTestAgainst.m00;
					float dist = (center - pointPos).getLength();
					if (dist <= radius)
					{
						contains = true;
						break;
					}
				}
				if (contains)
				{
					if (randomRange > 0.f)
					{
						float rx = float(rand())/float(RAND_MAX) - 0.5f;
						float ry = float(rand())/float(RAND_MAX) - 0.5f;
						float rz = float(rand())/float(RAND_MAX) - 0.5f;
						pointPos += ATOM_Vector3f(rx * randomRange, ry * randomRange, rz * randomRange);
					}

					float widthV = sizeV * (float(rand())/float(RAND_MAX));
					float heightV = widthV * (height / width);
					addLeafCards (&pointPos, 1, flip ? (rand() < RAND_MAX / 2) : false, widthV, heightV);
				}
			}
}
コード例 #5
0
qreal DrawingPolyItem::pointY(int index) const
{
	return pointPos(index).y();
}
コード例 #6
0
osg::ref_ptr<osg::Geometry> Pathgrid::createPathgridPoints(const ESM::Pathgrid *pathgrid)
{
    osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;

    const float height = POINT_MESH_BASE * sqrtf(2);

    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::ref_ptr<osg::UShortArray> indices = new osg::UShortArray;

    bool first = true;
    unsigned short startIndex = 0;
    for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin();
        it != pathgrid->mPoints.end();
        ++it, startIndex += 6)
    {
        osg::Vec3f pointPos(MWMechanics::PathFinder::MakeOsgVec3(*it));

        if (!first)
        {
            // degenerate triangle from previous octahedron
            indices->push_back(startIndex - 4); // 2nd point of previous octahedron
            indices->push_back(startIndex); // start point of current octahedron
        }

        float pointMeshBase = static_cast<float>(POINT_MESH_BASE);

        vertices->push_back(pointPos + osg::Vec3f(0, 0, height)); // 0
        vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, -pointMeshBase, 0)); // 1
        vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, -pointMeshBase, 0)); // 2
        vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, pointMeshBase, 0)); // 3
        vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, pointMeshBase, 0)); // 4
        vertices->push_back(pointPos + osg::Vec3f(0, 0, -height)); // 5

        indices->push_back(startIndex + 0);
        indices->push_back(startIndex + 1);
        indices->push_back(startIndex + 2);
        indices->push_back(startIndex + 5);
        indices->push_back(startIndex + 3);
        indices->push_back(startIndex + 4);
        // degenerates
        indices->push_back(startIndex + 4);
        indices->push_back(startIndex + 5);
        indices->push_back(startIndex + 5);
        // end degenerates
        indices->push_back(startIndex + 1);
        indices->push_back(startIndex + 4);
        indices->push_back(startIndex + 0);
        indices->push_back(startIndex + 3);
        indices->push_back(startIndex + 2);

        first = false;
    }

    geom->setVertexArray(vertices);

    geom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, indices->size(), &(*indices)[0]));

    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f));
    geom->setColorArray(colors, osg::Array::BIND_OVERALL);

    return geom;
}