当前位置: 首页>>代码示例>>C++>>正文


C++ BodyPart类代码示例

本文整理汇总了C++中BodyPart的典型用法代码示例。如果您正苦于以下问题:C++ BodyPart类的具体用法?C++ BodyPart怎么用?C++ BodyPart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BodyPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

BodyPart * MDLReader::processBodyPart(std::istream * str, int offset)
{
    int              i;
    MDLBodyPart *    part;
    BodyPart *       partNode;
    Model *          modelNode;

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

    // Read it
    part = new MDLBodyPart;
    str->read((char *) part, sizeof(MDLBodyPart));

    // Create the body part node
    partNode = new BodyPart(part);

    // Process the models
    for (i = 0; i < part->num_models; i++)
    {
        // Process the model
        modelNode = processModel(str, offset + part->model_offset +
                                      (i * sizeof(MDLModel)));

        // Add the model to the body part
        partNode->addModel(modelNode);
    }

    // Return the new node
    return partNode;
}
开发者ID:yueying,项目名称:osg,代码行数:31,代码来源:MDLReader.cpp

示例2: getPartByUUID

void Body::makeDownstreamPartList(string part_uuid, std::vector<string>* child_list)
{
	boost::shared_ptr<Part> part = getPartByUUID(part_uuid);
	if (part == nullptr)
	{
		return;
	}

	//Part is an Organ: Add all connected organs to the list
	if (part->getType() == TYPE_ORGAN){
		Organ* o = static_cast<Organ*>(part.get());
		for (auto it = o->getConnectedOrgansRW()->begin(); it != o->getConnectedOrgansRW()->end(); it++)
		{
			child_list->push_back(*it);
			makeDownstreamPartList(*it, child_list);
		}
	}

	//Part is a BodyPart: Add all children to the list and call this function on them
	if (part->getType() == TYPE_BODYPART)
	{
		BodyPart* bp = static_cast<BodyPart*>(part.get());
		for (auto it = bp->getChildListRW()->begin(); it != bp->getChildListRW()->end(); it++)
		{
			child_list->push_back(*it);
			makeDownstreamPartList(*it, child_list);
		}
	}
}
开发者ID:bilwis,项目名称:RMD,代码行数:29,代码来源:Body.cpp

示例3: bound

int MailMessage::parseBodyParts(StringBuffer &rfcBody) {

    BodyPart part;
    // The boundary is the one defined in the headers preceded by
    // a newline and two hypens
    StringBuffer bound("\n--");
    bound += boundary;

    LOG.debug("parseBodyParts START");

    size_t nextBoundary = rfcBody.find(bound);
    getBodyPart(rfcBody, bound, body, nextBoundary, false);

    if (contentType.ifind("multipart/alternative") == StringBuffer::npos) {
        // If it's not multipart/alternative, get the other parts
        while( getBodyPart(rfcBody, bound, part, nextBoundary, true) ) {
            // some problem in the attachment?
            if( part.getContent() ) {
                attachments.add(part);
            }
            else LOG.error("Empty content in attachment.");
            part = BodyPart();
        }
    }

    LOG.debug("parseBodyParts END");
    return 0;
}
开发者ID:ruphy,项目名称:kfunambol,代码行数:28,代码来源:MailMessage.cpp

示例4: while

	BodyPart *BodyParts::getNextWeaponPart(bool &looped)
	{
		int len = static_cast<int>(mPartList.size());
		int startIndex = mAttackIndex;
		looped = false;
		if (startIndex < 0 || startIndex >= len)
		{
			startIndex = len - 1;
		}
		mAttackIndex++;
		if (mAttackIndex >= len)
		{
			mAttackIndex = 0;
		}

		BodyPart *result = nullptr;
		while (mAttackIndex != startIndex)
		{
			BodyPart *part = mPartList[mAttackIndex];
			// Has to be a weapon part and not currently holding something else.
			if (part->isWeaponPart() && !part->isHoldingOnto())
			{
				result = part;
				break;
			}
			mAttackIndex++;
			if (mAttackIndex >= len)
			{
				mAttackIndex = 0;
				looped = true;
			}
		}
		return result;
	}
开发者ID:astrellon,项目名称:Rouge,代码行数:34,代码来源:body_parts.cpp

示例5: GuiObjectLink

void Body::buildPartList(std::vector<GuiObjectLink*>* list, Part* p, int depth)
{
	//debug_print("Depth: %i, Part: %s \n", depth, p->getId());
	if (p->getType() == PartType::TYPE_ORGAN)
	{
		//Append to end of list "gui_list_indent_char [times depth] ORGAN_NAME"
		std::string str = "";

		for (int i = 0; i <= depth; i++)
		{
			str.append(gui_list_indent_char);
		}

		str.append(p->getName());

		list->push_back(
			new GuiObjectLink(
			p->getUUID(),
			new ColoredText(str, part_gui_list_color_organ)
			)
			);

		return;
	}
	if (p->getType() == PartType::TYPE_BODYPART)
	{
		//Append to end of list "gui_list_indent_char [times depth] BODYPART_NAME"
		BodyPart *bp = (BodyPart*)p;
		std::string str = "";

		for (int i = 0; i <= depth; i++)
		{
			str.append(gui_list_indent_char);
		}

		str.append(bp->getName());

		list->push_back(
			new GuiObjectLink(
			bp->getUUID(),
			new ColoredText(str, part_gui_list_color_bodypart)
			)
			);

		//Call this function on all children of the BodyPart
		for (auto it = bp->getChildListRW()->begin(); it != bp->getChildListRW()->end(); it++)
		{
			boost::shared_ptr<Part> part = getPartByUUID(*it);
			if (part == nullptr) { continue; }
			buildPartList(list, part.get(), depth + 1);
		}

		bp = nullptr;

		return;
	}

	debug_error("ERROR: Tried to call recursive part list building function on invalid Part* (neither TYPE_BODYPART nor TYPE_ORGAN)!\n");
	return;
}
开发者ID:bilwis,项目名称:RMD,代码行数:60,代码来源:Body.cpp

示例6: getLinkedParts

	base::ReturnCode BodyParts::getLinkedParts(BodyPart *linkedTo, PartList &result) const
	{
		if (!linkedTo)
		{
			return base::NULL_PARAMETER;
		}
		if (!hasBodyPart(linkedTo))
		{
			return base::BODY_PART_NOT_FOUND;
		}

		for (size_t i = 0; i < mPartList.size(); i++)
		{
			BodyPart *part = mPartList[i];
			if (part == linkedTo)
			{
				continue;
			}
			if (part->getCanHoldOnto() == linkedTo)
			{
				result.push_back(part);
			}
		}
		return base::SUCCESS;
	}
开发者ID:astrellon,项目名称:Rouge,代码行数:25,代码来源:body_parts.cpp

示例7: getLength

	//
	//	add a number of parts
	//
	void Serpent::addParts(int numParts )
	{
		int partsToAdd = numParts;
		if( partsToAdd <= 0 )
		{
			return;
		}

		//	se adauga parti pana la limita maxima

		if( getLength() + numParts > maxlength )
		{
			partsToAdd = maxlength - getLength();
		}

		for( int i=0; i<partsToAdd; i++ )
		{
			BodyPart * myBodyPart = new BodyPart();
			myBodyPart->setSize( spawnBodyPartSize );
			System::Diagnostics::Trace::WriteLine("Adding bodypart; size=" + spawnBodyPartSize.x + "," + spawnBodyPartSize.y );

			bodyParts.add( myBodyPart );

			this->onAddedBodyPart();
		}
	}
开发者ID:dezGusty,项目名称:serpents-net,代码行数:29,代码来源:Serpent.cpp

示例8: getBodyPart

	Item *BodyParts::getItemOnPart(const char *partName) const
	{
		BodyPart *part = getBodyPart(partName);
		if (part)
		{
			return part->getEquippedItem();
		}
		return nullptr;
	}
开发者ID:astrellon,项目名称:Rouge,代码行数:9,代码来源:body_parts.cpp

示例9: loadConnectionTransform

    void Creature::loadConnectionTransform(const BodyPart& body, const Constraint& constraint, btTransform & trans) {
        if (body.getId() == constraint.getIdBodyA()) {
            Constraint::locateConnectionOrigin(body, constraint.getConnectionA(), trans);
        } else {

            assert(body.getId() == constraint.getIdBodyB());
            Constraint::locateConnectionOrigin(body, constraint.getConnectionB(), trans);
        }
        trans = body.getRigidBody()->getCenterOfMassTransform() * trans;
    }
开发者ID:jcrada,项目名称:jcrada-creatures,代码行数:10,代码来源:Creature.cpp

示例10: evalute_BodyPart

std::string evalute::evalute_BodyPart(Watch* watch)
{
    std::string name = watch->MemberName;
    std::string result = "";
    BodyPart* part = boost::get<BodyPart*>(watch->Object);

    if( name == "MaxKindleLevel") result = FloatToStr(part->getMaxKindleLevel());
    else if( name == "MaxDampness") result = FloatToStr(part->getMaxDampness());
    else if( name == "AcceptsCord") result = BoolToStr(part->getAcceptsCord());
    else if( name == "Name") result = part->getName();

    if(result == "") result = "Can't evalute";
    return result;
}
开发者ID:Phosfor,项目名称:Themisto,代码行数:14,代码来源:EvaluteFunctions.cpp

示例11: getUiInspector

    void MainWindow::showBodyDetails( const Creature& creature, const BodyPart& body ) {
        getUiInspector().lst_body_details->addItem(QString(
                body.getName().c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  Mass: " + TO_STRING(body.getMass())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  Torque: " + TO_STRING(body.getMaxTorque())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                std::string("  Size").c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [x]: " + TO_STRING(body.getSizeX())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [y]: " + TO_STRING(body.getSizeY())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [z]: " + TO_STRING(body.getSizeZ())).c_str()));
        //Angles

        BodyPart* parent = body.getParentId() == Creature::B_NONE
                ? NULL : &creature.getBodyPart(body.getParentId());
        if (parent) {
            getUiInspector().lst_body_details->addItem(QString(
                    ("  Parent: " + parent->getName()).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(std::string("  Angles:").c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   XY:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::XY,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   YZ:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::YZ,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   ZX:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::ZX,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
        }
    }
开发者ID:jcrada,项目名称:jcrada-creatures,代码行数:40,代码来源:OldMainWindowCreature.cpp

示例12: getBodyPart

/**
 * Get the next bodypart from the message body string.
 *
 * @param rfcBody  (in)  - message content
 * @param boundary (in)  - mime boundary string
 * @param ret      (out) - parsed BodyPart
 * @param next     (i/o) - offset of the new boundary
 * @param isAttach (in)  - says if the current body part is an attachment or not
 */
static bool getBodyPart(StringBuffer &rfcBody, StringBuffer &boundary,
                       BodyPart &ret, size_t &next, bool isAttach)
{
    LOG.debug("getBodyPart START");
    StringBuffer newline;

    // The part starts on the next line
    size_t begin = findNewLine(rfcBody, next);
    if (begin == StringBuffer::npos)
       return false;
    // find the end of the part
    next = rfcBody.find(boundary, begin);
    if (next == StringBuffer::npos)
       return false;
    // get the part
    StringBuffer part = rfcBody.substr(begin, next-begin);
    // If it is a multipart alternative part, get the text part only.
    // check only until the first new line not on all the message (it could be
    // a message inside another message)
    size_t headers_len = getHeadersLen(part, newline);
    StringBuffer headers_part = part.substr(0, headers_len);
    if (headers_part.ifind("Content-Type: multipart/alternative") != StringBuffer::npos) {
        if(part.ifind("Content-Type: multipart/alternative") != StringBuffer::npos) {
            size_t b_pos = part.ifind("boundary=");
            if( b_pos != StringBuffer::npos ) {
                size_t begin = part.find("=\"", b_pos) + 2 ;
                size_t end = part.find("\"", begin) ;

                StringBuffer inner_boundary("\n--");
                inner_boundary += part.substr( begin, end-begin );

                begin = part.find(inner_boundary, end);
                begin += inner_boundary.length();
                end = part.find(inner_boundary, begin);
                if (begin != StringBuffer::npos && end != StringBuffer::npos) {
                    part = part.substr(begin, end-begin);
                    LOG.debug("Bodypart is multipart/alternative: "
                        "getting first alternative only: \n%s\n", part.c_str() );
                }
            }
        }
    }

    // Split headers and body
    size_t hdrlen = getHeadersLen(part, newline);

    // Get headers
    StringBuffer headers = part.substr(0, hdrlen);

    // Join header parts using \t or 8 blank
    StringBuffer joinlinetab("\t");
    headers.replaceAll(joinlinetab, " ");
    StringBuffer joinlinespaces(newline);
    joinlinespaces+=" ";  // 8 blanks
    headers.replaceAll(joinlinespaces, " ");

    ArrayList lines;
    const StringBuffer *line;

    // parse the bodypart headers
    headers.split(lines, newline);

    for ( line=(StringBuffer *)lines.front();
          line;
          line=(StringBuffer *)lines.next() ) {
        if( *line == "\r" )
            continue;
        // The first empty line marks the end of the header section
        //if( line->empty() ){
        //    break;
        //}
        // Process the headers
        if( line->ifind(MIMETYPE) == 0 ) {  // it must at the beginning
            ret.setMimeType(getTokenValue(line, MIMETYPE));
            if (line->ifind(CT_NAME) != StringBuffer::npos) {
                ret.setName(MailMessage::decodeHeader(getTokenValue(line, CT_NAME,false)));
            }
            if (line->ifind(CT_CHARSET) != StringBuffer::npos ) {
                ret.setCharset(getTokenValue(line, CT_CHARSET));
            }
        }   
        else if( line->ifind(DISPOSITION) == 0 ) {
            ret.setDisposition( getTokenValue(line, DISPOSITION));
            if (line->ifind(CD_FILENAME) != StringBuffer::npos ) {
                ret.setFilename( MailMessage::decodeHeader(  getTokenValue(line, CD_FILENAME, false) ) );
            }
        }

        else if( line->ifind(ENCODING) == 0 ) {
            ret.setEncoding( getTokenValue(line, ENCODING));
        }
//.........这里部分代码省略.........
开发者ID:ruphy,项目名称:kfunambol,代码行数:101,代码来源:MailMessage.cpp

示例13: is


//.........这里部分代码省略.........
			else if (!strcmp(_name,"blood_flow")){ blood_flow = atof(attr->value()); }
			else if (!strcmp(_name,"resistance")){ resistance = atof(attr->value()); }
			else if (!strcmp(_name,"impairment")){ impairment = atof(attr->value()); }
		}

		debug_print("Read Tissue:\n\tID: %s \n\tName: %s \n\tBlood Flow: %f \n\tResistance: %f \n\tImpairment: %f\n",
				id, name, blood_flow, resistance, impairment);

		//Create a new Tissue and store the shared pointer to it in the tissue map
		boost::shared_ptr<Tissue> t_tissue(new Tissue(id, name, pain, blood_flow, resistance, impairment));
		tissue_map->insert(std::pair<std::string, boost::shared_ptr<Tissue>>(std::string(id), t_tissue));
	}

	//###BODYPART DATA###

	//maps for child linking and organ linking
	//K: UUID of the child, V: UUID of the parent
	std::map<string, string>* child_map = new std::map<string, string>();
	//K: UUID of the organ, V: IID(!) of its connector
	std::map<string, string>* organ_link_map = new std::map<string, string>();

	//Load the bodypart data (First first_node() is "body_def", 
	// data starts with the second level "body" 
	xml_node<> *body = doc.first_node()->first_node("body");
	string root_uuid = enter(body->first_node(), child_map, organ_link_map);

	//Destroy the XML data in memory
	delete[] buffer;

	//Build IID<->UUID map, which is required for linking 
	makeIdMap();

	//Link children and organs
	for (std::map<string, string>::iterator ch_it = child_map->begin();
		ch_it != child_map->end(); ch_it++) 
	{
		if (getPartByUUID(ch_it->first) == nullptr)
		{
			debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
				ch_it->first.c_str());
			return nullptr;
		}
		if (getPartByUUID(ch_it->second) == nullptr)
		{
			debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
				ch_it->second.c_str());
			return nullptr;
		}
		
		BodyPart* parent = dynamic_cast<BodyPart*>(getPartByUUID(ch_it->second).get());
		if (parent == nullptr) 
		{
			debug_error("ERROR during body part linking: Casting from Part* to BodyPart* on Part %s failed!\n",
				ch_it->second.c_str());
			return nullptr;
		}

		parent->addChild(ch_it->first);
	}

	for (std::map<string, string>::iterator or_it = organ_link_map->begin();
		or_it != organ_link_map->end(); or_it++)
	{
		if (getPartByUUID(or_it->first) == nullptr)
		{
			debug_error("ERROR during body part linking: Part UUID %s was requested, but is not in part map!\n",
				or_it->first.c_str());
			return nullptr;
		}
		if (getPartByIID(or_it->second) == nullptr)
		{
			debug_error("ERROR during body part linking: Part IID %s was requested, but is not in part map!\n",
				or_it->second.c_str());
			return nullptr;
		}
		Part* temp = getPartByIID(or_it->second).get();
		Organ* connector = dynamic_cast<Organ*>(temp);
		if (connector == nullptr){
			debug_error("ERROR during body part linking: Casting from Part* to Organ* on Part %s failed!\n",
				or_it->second.c_str());
			return nullptr;
		}
		connector->addConnectedOrgan(or_it->first);
	}

	//Successfully parsed the body definition file!
	//Return the address of the newly created body part.
	return root_uuid;

	} catch (std::exception& e) {
		debug_error("ERROR: %s \n", e.what());
		return NULL;
	}
	catch (bdef_parse_error& pe) {
		debug_error("ERROR: %s \n", pe.what());
		return NULL;
	}

	return NULL;
}
开发者ID:bilwis,项目名称:RMD,代码行数:101,代码来源:Body.cpp

示例14: while

string Body::enter(rapidxml::xml_node<> *node, std::map<string, string>* child_map, std::map<string, string>* organ_link_map) {
	using namespace rapidxml;

	int organ_count, bodyparts, it;
	xml_node<> *temp;
	xml_node<> **organ_node_list;

	char *id = nullptr, *name = nullptr, *_name = nullptr;
	float surface = 0.0f;

	//Make a count of the body_part nodes in this node and parse all standard
	// nodes for the bodypart of this node
	temp = node->first_node();
	bodyparts = 0;
	while (temp != nullptr){
		_name = temp->name();

		if (!strcmp(_name, "body_part")) { bodyparts++; }

		if (!strcmp(_name, "id")) { id = temp->value(); }
		if (!strcmp(_name, "name")) { name = temp->value(); }
		if (!strcmp(_name, "surface")) { surface = atof(temp->value()); }


		temp = temp->next_sibling();
	}

	//if any of the mandatory vars for bodyparts are NULL, ERROR!
	if (id == nullptr || name == nullptr){
		throw new bdef_parse_error("Not all mandatory BodyPart variables defined!", node);
	}

	//make the bodypart, make the pointer to it shared and store it in the part_map
	BodyPart* bp = new BodyPart((string)id, (string)name, surface, this);

	boost::shared_ptr<BodyPart> p (bp);

	part_map->insert(
		std::pair<std::string, boost::shared_ptr<Part>>(
		bp->getUUID(), boost::static_pointer_cast<Part>(p)));

	//reset temporary variables for reuse with the organs
	id = nullptr; name = nullptr;

	//DEBUG: Print new BodyPart
	debug_print("New BodyPart created: \n\tID: %s \n\tName: %s \n\tSurface: %f\n",
			bp->getId().c_str(), bp->getName().c_str(), bp->getSurface());

	//If there are no body_part nodes...
	if (bodyparts == 0){
		//...there must be organs instead!
		// variables
		Organ **organs;
		xml_attribute<> *attr;
		xml_node<> *tdef_node;

		char *connector = nullptr;
		bool symmetrical = false;

		it = 0;

		//  temp vars for tissue definitions
		char *tdef_id, *tdef_custom_id, *tdef_name;
		float tdef_hit_prob;

		tissue_def *tdefs = nullptr;
		int tdef_count = 0, tdef_it = 0;


		//Reset back to the first node in the given node
		temp = node->first_node();

		//scan for organ nodes in the given node
		organ_count = 0;
		while (temp != nullptr){
			if (!strcmp(temp->name(),"organ")) { organ_count++; }
			temp = temp->next_sibling();
		}

		//If there are no organs AND no bodyparts, ERROR!
		if (organ_count == 0){
			throw bdef_parse_error("No body part and no organ definition!", node);
		}

		//compile a list of nodes holding the organ definitions
		//and parse the remaining nodes to make the bodypart
		organ_node_list = new xml_node<>*[organ_count];
		temp = node->first_node();

		while (temp != nullptr){
			_name = temp->name();

			if (!strcmp(_name,"organ")) {
				organ_node_list[it] = temp;
				it++;
			}

			temp = temp->next_sibling();
		}

//.........这里部分代码省略.........
开发者ID:bilwis,项目名称:RMD,代码行数:101,代码来源:Body.cpp

示例15: getBodyPart

    void Creature::calculateMaxTorque() {
        double gravity = Math::abs(BulletSimulator::getSingleton().getWorld().getGravity().y());
        int terminal[getNumberOfBodyParts()];
        for (int i = 0; i < getNumberOfBodyParts(); ++i) {
            terminal[i] = 0;
            getBodyPart(i).setMaxTorque(0.0);
        }
        //Determinar nodos terminales (sum == 1)
        for (int i = 0; i < getNumberOfConstraints(); ++i) {
            assert(getConstraint(i).getIdBodyA() < getNumberOfBodyParts() &&
                    getConstraint(i).getIdBodyA() >= 0);
            assert(getConstraint(i).getIdBodyB() < getNumberOfBodyParts() &&
                    getConstraint(i).getIdBodyB() >= 0);
            //            if (!getBodyPart(getConstraint(i).getIdBodyA()).isRoot()) {
            ++terminal[getConstraint(i).getIdBodyA()];
            //            }
            //            if (!getBodyPart(getConstraint(i).getIdBodyB()).isRoot()) {
            ++terminal[getConstraint(i).getIdBodyB()];
            //            }
        }
        for (int e = 0; e < getNumberOfBodyParts(); ++e) {
            if (terminal[e] != 1) continue;
            int count = 0;
            BodyPart * body = &getBodyPart(e);
            std::vector<BodyPart*> extremities;
            while (body != &getRoot() && count++ < getNumberOfBodyParts()) {
                extremities.push_back(body);
                body = &getBodyPart(body->getParentId());
            }
            extremities.push_back(body);

            double arm_length = 0.0;
            btTransform trans;
            btVector3 center_of_mass;
            btVector3 connection;
            // A  0  B  1  C  2  Root  3
            // |-----|-----|-----|-----|
            for (int i = extremities.size() - 2; i >= 0; --i) {
                //                DEBUG(extremity[i]->getName() + " ; " + extremity[i+1]->getName());
                Constraint* constraint = getConstraint(*extremities[i], *extremities[i + 1]);
                assert(constraint);
                center_of_mass = extremities[i]->getRigidBody()->getCenterOfMassPosition();
                loadConnectionTransform(*extremities[i], *constraint, trans);
                connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
                arm_length = (center_of_mass - connection).length();
                //                BDEBUG("arm=" + TO_STRING(arm_length));
                extremities[i]->addMaxTorque(arm_length * extremities[i]->getMass() * gravity);

                for (int j = i - 1; j >= 0; --j) {
                    constraint = getConstraint(*extremities[j], *extremities[i]);
                    if (!constraint) {
                        //                        DEBUG("NOT FOUND: " + extremity[i]->getName() + " ; " + extremity[i + 1]->getName());

                        continue;
                    }
                    //                    DEBUG("FOUND (" + constraint->getName() + "): " + extremity[i]->getName() + " ; " + extremity[i + 1]->getName());
                    assert(constraint);
                    center_of_mass = extremities[i]->getRigidBody()->getCenterOfMassPosition();
                    loadConnectionTransform(*extremities[i], *constraint, trans);
                    connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
                    arm_length += (center_of_mass - connection).length();

                    center_of_mass = extremities[j]->getRigidBody()->getCenterOfMassPosition();
                    loadConnectionTransform(*extremities[j], *constraint, trans);
                    connection = btVector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
                    arm_length += (center_of_mass - connection).length();

                    extremities[i]->addMaxTorque(arm_length * extremities[j]->getMass() * gravity);
                }
            }
        }
    }
开发者ID:jcrada,项目名称:jcrada-creatures,代码行数:72,代码来源:Creature.cpp


注:本文中的BodyPart类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。