Exemple #1
0
void Level::addCuboid(const rapidxml::xml_node<> &cuboidNode)
{    
    osg::Vec3 from = getVectorFromXMLNode("position", cuboidNode);
    osg::Vec3 size = getVectorFromXMLNode("size", cuboidNode);
 
    Cuboid *cuboid = NULL;
    
    if(cuboidNode.first_attribute("type") != 0)
    {
        std::string type = cuboidNode.first_attribute("type")->value();

        if(type == "accelerate")
            cuboid = new AccelerationCuboid(from, size);
        else if(type == "decelerate")
            cuboid = new DecelerationCuboid(from, size);
    }

    if(cuboid == NULL)
    {
        cuboid = new Cuboid(from, size);
    }
	
    _level->addChild(cuboid->getNode());
    _collisionObjects.push_back(cuboid->getRigidBody());
    
    // save minimal x values for buckets of close y values
    // needed for detection whether player is falling to dead    
    int yBucketIndex = (int)((from.y() + size.y()) / 20.0f);
	
	while(_minZValues.size() <= yBucketIndex)
        _minZValues.push_back(from.z());
    
    // if current cuboid is lower then z -> adjust bucket value
    if(from.z() < _minZValues[yBucketIndex])
        _minZValues[yBucketIndex] = from.z();
}
Exemple #2
0
void parseItem( const rapidxml::xml_node<> &node, XmlTree *parent, XmlTree *result, const XmlTree::ParseOptions &options )
{
	*result = XmlTree( node.name(), node.value(), parent );
	for( const rapidxml::xml_node<> *item = node.first_node(); item; item = item->next_sibling() ) {
		XmlTree::NodeType type;
		switch( item->type() ) {
			case rapidxml::node_element:
				type = XmlTree::NODE_ELEMENT;
			break;
			case rapidxml::node_cdata: {
				if( options.getCollapseCData() ) {
					result->setValue( result->getValue() + item->value() );
					continue;
				}
				else {
					type = XmlTree::NODE_CDATA;
				}
			}
			break;						
			case rapidxml::node_comment:
				type = XmlTree::NODE_COMMENT;
			break;
			case rapidxml::node_doctype: {
				result->setDocType( item->value() );
				continue;
			}
			case rapidxml::node_data: {
				if( ! options.getIgnoreDataChildren() )
					type = XmlTree::NODE_DATA;
				else
					continue;
			}
			break;
			default:
				continue;
		}
		
		result->getChildren().push_back( unique_ptr<XmlTree>( new XmlTree ) );
		parseItem( *item, result, result->getChildren().back().get(), options );
		result->getChildren().back()->setNodeType( type );
	}

	for( rapidxml::xml_attribute<> *attr = node.first_attribute(); attr; attr = attr->next_attribute() )
		result->getAttributes().push_back( XmlTree::Attr( result, attr->name(), attr->value() ) );
}
Exemple #3
0
void Level::addTunnel(const rapidxml::xml_node<> &tunnelNode)
{
	osg::Node *tunnelModel = osgDB::readNodeFile(TUNNEL_MODEL_FILE);
	osg::PositionAttitudeTransform *tunnelTransform = new osg::PositionAttitudeTransform();
    osg::Vec3 position = getVectorFromXMLNode("position", tunnelNode);

	tunnelTransform->addChild(tunnelModel);
	tunnelTransform->setPosition(position);
	tunnelTransform->setScale(osg::Vec3f(1.0f, atof(tunnelNode.first_attribute("length")->value()), 1.0f));
	
	tunnelTransform->setNodeMask(RECEIVE_SHADOW_MASK);
	_level->addChild(tunnelTransform);
	
    /*
	btConvexTriangleMeshShape* mesh = osgbBullet::btConvexTriMeshCollisionShapeFromOSG(tunnelPat);

	btTransform shapeTransform;
	shapeTransform.setIdentity();
	cs->addChildShape(shapeTransform, mesh);
	*/
}
Exemple #4
0
//===========================================
// XmlNode::firstAttribute
//===========================================
inline XmlAttribute XmlNode::firstAttribute() const {
   if (isNull()) throw XmlException("Node is NULL", __FILE__, __LINE__);
   return XmlAttribute(m_doc, m_node->first_attribute(), m_file);
}