Example #1
0
//turn the robot toward the greatest source of light, as read from the photocells
void turnTowardLight()
{
    cds mostlight = readLights();
    int largest, last = 0;
    int allcds[4];
    allcds[0] = mostlight.Fleft;
    allcds[1] = mostlight.Fright;
    allcds[2] = mostlight.Bleft;
    allcds[3] = mostlight.Bright;
    for(int i = 0; i < 4; i++)
    {
        if(allcds[i] > last)
        {
            largest = i;
        }
        last = allcds[i];
    }

    if(largest == 0)
    {
        turn(20, 'l');
    }
    else if(largest == 1)
    {
        turn(20, 'r');
    }
    else if(largest == 2)
    {
        turn(160, 'l');
    }
    else if(largest == 3)
    {
        turn(160, 'r');
    }
}
Example #2
0
bool LevelReader::readObjects(XMLElement* map, LevelData& data) const
{
	XMLElement* objectgroup = map->FirstChildElement("objectgroup");

	const char* textAttr;
	while (objectgroup != nullptr)
	{
		textAttr = nullptr;
		textAttr = objectgroup->Attribute("name");
		if (textAttr == nullptr)
		{
			g_logger->logError("LevelReader", "XML file could not be read, no objectgroup->name attribute found.");
			return false;
		}

		std::string name = textAttr;

		if (name.find("levelexits") != std::string::npos)
		{
			if (!readLevelExits(objectgroup, data)) return false;
		}
		else if (name.find("enemies") != std::string::npos)
		{
			if (!readEnemies(objectgroup, data)) return false;
		}
		else if (name.find("chests") != std::string::npos)
		{
			if (!readChestTiles(objectgroup, data)) return false;
		}
		else if (name.find("light") != std::string::npos)
		{
			if (!readLights(objectgroup, data)) return false;
		}
		else
		{
			g_logger->logError("LevelReader", "Objectgroup with unknown name found in level.");
			return false;
		}

		objectgroup = objectgroup->NextSiblingElement("objectgroup");
	}
	return true;
}
	//---------------------------------------------------------------------------------
	void MeshAndBspLoadContext::load(const DataStreamExPtr& _dataStream)
	{
		clear();
		mDataStream = _dataStream;

		Progress& progress = Progress::getSingleton();
		progress.setRange(0, 100);

		// Read version and size of entire MeshAndBsp.
		readMeshAndBspHeader();

		// Read mesh
		MshFileLoadContext::load(_dataStream);
		progress.setPosition(5);

		// Read BSP
		bool finish = false;
		while(!finish)
		{
			Chunk chunk(mDataStream);
			switch(chunk.getID())
			{
				case 0xC000: readBspInfo(chunk); break;
				case 0xC010: readPolygonIndices(chunk); break;
				case 0xC040: readBspNodes(chunk); break;
				case 0xC045: readLights(chunk); break;
				case 0xC050: readSectors(chunk); break;
				case 0xC0FF: finish = true; break;
			}
		}
		progress.setPosition(10);

		// Remove excess polygons
		countPolygonUsesInLod0();
		removePolygonsNotUsedInLod0();

		// Log statistics
		logStatistics();
	}
void XmlParser::loadFromXml(const char * fileName, int * argc, char ** argv) {
    XmlFile xmlFile(fileName);
    XmlDocument doc;
    doc.parse<0>(xmlFile.data());
    int W, H;

    XmlNode * rtNode = doc.first_node("ge");

    /*** Read window information ***/
    XmlNode * windowNode = rtNode->first_node("window");
    if (windowNode) {
        // Try to read window name
        XmlNode * name;
        xmlElement(name, windowNode);

        // Read width and height
        XmlNode * width, *height;
        xmlElement(width, windowNode);
        xmlElement(height, windowNode);

        W = atoi(width->value());
        H = atoi(height->value());

        // Set window parameters
        GameWindow::setWindow((name) ? name->value() : "GE", W, H);
    } else {
        W = 512;
        H = 512;

        GameWindow::setWindow("GE", W, H);
    }
    // Init gamewindow and light
    GameWindow::init(argc, argv);
    Light::init();
    Material::init();
    Input::init();
    GBuffer::init(W,H);
    // Load noise texture
    glActiveTexture(GL_TEXTURE11);
    LoadTexBMP("textures/noise.bmp");
    /*** Read Scene ***/
    // Reference to scene node
    XmlNode * sceneNode = rtNode->first_node("scene");
    // Instantiate scene    
    Scene * scene = new Scene();
    // Instantiate renderer
    Renderer * renderer = new Renderer();
    // Set renderer
    GameWindow::setRenderer(renderer);
    renderer->setScene(scene);

	// Create camera
	Camera * camera = new Camera();
	// Set camera
	renderer->setCamera(camera);
	camera->setAspectRatio(W/H);

	// Read Camera
	XmlNode * cameraNode = rtNode->first_node("camera");
	if (cameraNode) {
		readModel(camera, cameraNode->first_node("model"));
//		// Set position
//		XmlNode * position = cameraNode->first_node("position");
//		if (position) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, position);
//			xmlAttribute(y, position);
//			xmlAttribute(z, position);
//			camera->setPosition(atof(x->value()), atof(y->value()), atof(z->value()));
//		}
//
//		// Set direction
//		XmlNode * direction= cameraNode->first_node("direction");
//		if (direction) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, direction);
//			xmlAttribute(y, direction);
//			xmlAttribute(z, direction);
//			camera->setDirection(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}
//
//
//		// Set direction
//		XmlNode * up = cameraNode->first_node("up");
//		if (up) {
//			// Get coordinates
//			XmlAttr * x, *y, *z;
//			xmlAttribute(x, up);
//			xmlAttribute(y, up);
//			xmlAttribute(z, up);
//			camera->setUp(atof(x->value()), atof(y->value()),
//					atof(z->value()));
//		}

		// Read scripts
		XmlNode * scriptsNode = cameraNode->first_node("scripts");
		readScripts(scene, camera, scriptsNode);
	}

    // Light shadow map must be initialized after renderer has a camera
    Light::initShadowMap(renderer->createShaderProg("shaders/shadow.vert", "shaders/shadow.frag"));

    // Read objects
    XmlNode * objectsNode = sceneNode->first_node("objects");
    if (objectsNode) {
        // Read all cubes
        XmlNode * cubeNode = objectsNode->first_node("cube");
        readCubes(renderer, scene, cubeNode);

        // Read all mesh from scene
        XmlNode * meshNode = objectsNode->first_node("mesh");
        readMeshs(renderer, scene, meshNode);
        
    } else {
        printf("No objects\n");
    }

    // Read Lights
    XmlNode * lights = sceneNode->first_node("lights");
    readLights(scene, lights);
}