Ejemplo n.º 1
0
Archivo: animnode.c Proyecto: HJvT/hat
/**
 * Attempt to read an atom constructor type node at a certain offset.
 *
 * @param  hatFile The file to read the node from.
 * @param  offset  The offset where the start of the node should be.
 * @return A node construct containing the read values.
 */
node* readAtomConstructor(FILE *hatFile, unsigned long offset)
{
    int  argIndex;
    char tag;
    node *newNode = (node *)malloc(sizeof(node));
    
    newNode->nodeType = AtomConstructor;
    newNode->offset = offset;
    
    setFilePos(hatFile, offset);
    tag = readByte(hatFile);
    newNode->params.atomConstructor.module = readPointer(hatFile);
    newNode->params.atomConstructor.filePos = readPosition(hatFile);
    readPosition(hatFile);  /* skip position end */
    newNode->params.atomConstructor.fix = readFixPri(hatFile);
    newNode->params.atomConstructor.arity = readArity(hatFile);
    newNode->params.atomConstructor.name = readString(hatFile);
    if (newNode->params.atomConstructor.hasFields = hasFields(tag))
    {
        newNode->params.atomConstructor.args = (unsigned long *)malloc(newNode->params.atomConstructor.arity * sizeof(unsigned long));
        for (argIndex = 0; argIndex < newNode->params.atomConstructor.arity; argIndex++)
        {
            newNode->params.atomConstructor.args[argIndex] = readPointer(hatFile);
        }
    }
    
    return newNode;
}
Ejemplo n.º 2
0
Archivo: animnode.c Proyecto: HJvT/hat
node* readSrcPos(FILE *hatFile, unsigned long offset)
{
    node *newNode = (node *)malloc(sizeof(node));
    
    newNode->nodeType = SrcPos;
    newNode->offset = offset;
    
    setFilePos(hatFile, offset);
    newNode->params.srcPos.module = readPointer(hatFile);
    newNode->params.srcPos.filePos = readPosition(hatFile);
    readPosition(hatFile);  /* skip position end */

    return newNode;
}
Ejemplo n.º 3
0
	//------------------------------------------------------------------------------------
	ToolOperation* CameraPositionTool::activate(const Any& _toolParameter)
	{
		const ToolParam& tp = any_cast<ToolParam>(_toolParameter);
		if(tp.store)
		{
			World* world = WorldManager::getSingleton().getActiveWorld();
			if(world)
			{
				Camera* camera = world->getCamera();
				savePosition( tp.index, camera->getPosition(), camera->getOrientation());
				updateMenuItems();
			}
		}
		else
		{
			Vector3 position;
			Quaternion rotation;
			readPosition(tp.index, position, rotation);
			World* world = WorldManager::getSingleton().getActiveWorld();
			Camera* camera = world->getCamera();
			camera->setPosition(position);
			camera->setOrientation(rotation);
		}
		return nullptr;
	}
Ejemplo n.º 4
0
//#################################################################
//
// void dynamixels::readPositionALL(void)
//     
//
//#################################################################
void dynamixels::readPositionALL(void)
{
	for (int i=0; i<MAXIMUM_NUMBER_DYNAMIXELS && ID_array[i] != 0; i++)
	{
		readPosition(i);
	}
}
Ejemplo n.º 5
0
Archivo: animnode.c Proyecto: HJvT/hat
node* readAtomVariable(FILE *hatFile, unsigned long offset)
{
    node *newNode = (node *)malloc(sizeof(node));
    char tag;
    
    newNode->nodeType = AtomVariable;
    newNode->offset = offset;
    
    setFilePos(hatFile, offset);
    tag = readByte(hatFile);
    newNode->params.atomVariable.local = localDef(tag);
    newNode->params.atomVariable.module = readPointer(hatFile);
    newNode->params.atomVariable.filePos = readPosition(hatFile);
    readPosition(hatFile);  /* skip position end */
    newNode->params.atomVariable.fix = readFixPri(hatFile);
    newNode->params.atomVariable.arity = readArity(hatFile);
    newNode->params.atomVariable.name = readString(hatFile);
    
    return newNode;
}
Ejemplo n.º 6
0
void ASIEAF::GetFocusParams()
{
    if (readPosition())
        IDSetNumber(&FocusAbsPosNP, nullptr);

    if (readReverse())
        IDSetSwitch(&FocusReverseSP, nullptr);

    if (readBeep())
        IDSetSwitch(&BeepSP, nullptr);
}
Ejemplo n.º 7
0
void
NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) {
    // get the id, report an error if not given or empty...
    myCurrentJunction.node = 0;
    myCurrentJunction.intLanes.clear();
    myCurrentJunction.response.clear();
    bool ok = true;
    std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
    if (!ok) {
        return;
    }
    if (id[0] == ':') { // internal node
        return;
    }
    SumoXMLNodeType type = attrs.getNodeType(ok);
    if (ok) {
        if (type == NODETYPE_DEAD_END_DEPRECATED || type == NODETYPE_DEAD_END) {
            // dead end is a computed status. Reset this to unknown so it will
            // be corrected if additional connections are loaded
            type = NODETYPE_UNKNOWN;
        }
    } else {
        WRITE_WARNING("Unknown node type for junction '" + id + "'.");
    }
    Position pos = readPosition(attrs, id, ok);
    NBNetBuilder::transformCoordinates(pos, true, myLocation);
    NBNode* node = new NBNode(id, pos, type);
    if (!myNodeCont.insert(node)) {
        WRITE_ERROR("Problems on adding junction '" + id + "'.");
        delete node;
        return;
    }
    myCurrentJunction.node = node;
    SUMOSAXAttributes::parseStringVector(attrs.get<std::string>(SUMO_ATTR_INTLANES, 0, ok, false), myCurrentJunction.intLanes);
    // set optional radius
    if (attrs.hasAttribute(SUMO_ATTR_RADIUS)) {
        node->setRadius(attrs.get<SUMOReal>(SUMO_ATTR_RADIUS, id.c_str(), ok));
    }
    // handle custom shape
    if (attrs.getOpt<bool>(SUMO_ATTR_CUSTOMSHAPE, 0, ok, false)) {
        node->setCustomShape(attrs.get<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok));
    }
    if (myCustomShapeMaps.count(id) > 0) {
        NBNode::CustomShapeMap customShapes = myCustomShapeMaps[id];
        for (NBNode::CustomShapeMap::const_iterator it = customShapes.begin(); it != customShapes.end(); ++it) {
            node->setCustomLaneShape(it->first, it->second);
        }
    }
    if (type == NODETYPE_RAIL_SIGNAL || type == NODETYPE_RAIL_CROSSING) {
        // both types of nodes come without a tlLogic
        myRailSignals.insert(id);
    }
}
Ejemplo n.º 8
0
int VTDRPositionRecord::Read(const char* buf)
{
	PositionRecord* ptrRec = (PositionRecord*) buf;
	tStart = ToSystime(ptrRec->vStart);
	for (int i = 0; i < 60; i++)
	{
		readPosition(ptrRec->record[i].pos, Longititude[i], Latitude[i],
				Altitude[i]);
		Speed[i] = ptrRec->record[i].speed;
	}
	return sizeof(*ptrRec);
}
Ejemplo n.º 9
0
/* A helper function for mergeBlock(), below.  Merge the position lists
 * pointed to by m->in and pBlockReader.
 * If the merge matches, write [iDocid] to m->pOut; if m->pOut
 * has positions then write all matching positions as well. */
static void mergePosList(DocListMerge *m, sqlite_int64 iDocid,
                  DocListReader *pBlockReader){
  int block_pos = readPosition(pBlockReader);
  int in_pos = readPosition(&m->in);
  int match = 0;
  while( block_pos!=-1 || in_pos!=-1 ){
    if( block_pos-m->iOffset==in_pos ){
      if( !match ){
        docListAddDocid(m->pOut, iDocid);
        match = 1;
      }
      if( m->pOut->iType >= DL_POSITIONS ){
        docListAddPos(m->pOut, in_pos);
      }
      block_pos = readPosition(pBlockReader);
      in_pos = readPosition(&m->in);
    } else if( in_pos==-1 || (block_pos!=-1 && block_pos-m->iOffset<in_pos) ){
      block_pos = readPosition(pBlockReader);
    } else {
      in_pos = readPosition(&m->in);
    }
  }
  if( m->pOut->iType >= DL_POSITIONS && match ){
    docListAddEndPos(m->pOut);
  }
}
Ejemplo n.º 10
0
bool NStep::updateProperties()
{
    if (isConnected())
    {
        // Read these values before defining focuser interface properties
        readPosition();
        readSpeedInfo();
    }

    INDI::Focuser::updateProperties();

    if (isConnected())
    {
        if (readTemperature())
            defineNumber(&TemperatureNP);

        bool rc = getStartupValues();

        // Settings
        defineNumber(&MaxSpeedNP);
        defineSwitch(&CompensationModeSP);
        defineSwitch(&PrimeManualSP);
        defineNumber(&CompensationSettingsNP);
        defineSwitch(&SteppingModeSP);
        defineNumber(&SteppingPhaseNP);
        defineSwitch(&CoilStatusSP);

        if (rc)
            LOG_INFO("NStep is ready.");
        else
            LOG_WARN("Failed to query startup values.");
    }
    else
    {
        if (TemperatureNP.s == IPS_OK)
            deleteProperty(TemperatureNP.name);

        deleteProperty(MaxSpeedNP.name);
        deleteProperty(CompensationModeSP.name);
        deleteProperty(PrimeManualSP.name);
        deleteProperty(CompensationSettingsNP.name);
        deleteProperty(SteppingModeSP.name);
        deleteProperty(SteppingPhaseNP.name);
        deleteProperty(CoilStatusSP.name);
    }

    return true;
}
Ejemplo n.º 11
0
void PlayerShip::fire()
{
	Vector2D position(readPosition());
	position.x_ += 16.0F + (cos(deg2rad(getAngle())));
	position.y_ -= (sin(deg2rad(getAngle())));
	
	EntitySystem& entitySystem(EntitySystem::instance());
	Bullet* const bullet(entitySystem.add<Bullet>("Movable"));
	entitySystem.addToList(bullet, "Renderable");
	bullet->setGraphicObject(new SDLGraphicObject);
	bullet->writePosition() = position;
	bullet->writeGraphicObject<SDLGraphicObject>().load("data/shot.bmp");
	bullet->setAngle(getAngle());
	bullet->setSpeed(600.0F);
	bullet->fire();
}
Ejemplo n.º 12
0
void ASIEAF::TimerHit()
{
    if (!isConnected())
    {
        SetTimer(POLLMS);
        return;
    }

    bool rc = readPosition();
    if (rc)
    {
        if (fabs(lastPos - FocusAbsPosN[0].value) > 5)
        {
            IDSetNumber(&FocusAbsPosNP, nullptr);
            lastPos = FocusAbsPosN[0].value;
        }
    }

    rc = readTemperature();
    if (rc)
    {
        if (fabs(lastTemperature - TemperatureN[0].value) >= 0.1)
        {
            IDSetNumber(&TemperatureNP, nullptr);
            lastTemperature = TemperatureN[0].value;
        }
    }

    if (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY)
    {
        if (!isMoving())
        {
            FocusAbsPosNP.s = IPS_OK;
            FocusRelPosNP.s = IPS_OK;
            IDSetNumber(&FocusAbsPosNP, nullptr);
            IDSetNumber(&FocusRelPosNP, nullptr);
            lastPos = FocusAbsPosN[0].value;
            LOG_INFO("Focuser reached requested position.");
        }
    }

    SetTimer(POLLMS);
}
Ejemplo n.º 13
0
void
NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) {
    // get the id, report an error if not given or empty...
    bool ok = true;
    std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
    if (!ok) {
        return;
    }
    if (id[0] == ':') { // internal node
        return;
    }
    SumoXMLNodeType type = NODETYPE_UNKNOWN;
    std::string typeS = attrs.getStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok);
    if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
        type = SUMOXMLDefinitions::NodeTypes.get(typeS);
        if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type
            type = NODETYPE_DEAD_END;
        }
    } else {
        WRITE_WARNING("Unknown node type '" + typeS + "' for junction '" + id + "'.");
    }
    Position pos = readPosition(attrs, id, ok);
    NILoader::transformCoordinates(pos, true, myLocation);
    // the network may have been built with the option "plain.keep-edge-shape" this
    // makes accurate reconstruction of legacy networks impossible. We ought to warn about this
    std::string shapeS = attrs.getStringReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, false);
    if (shapeS != "") {
        PositionVector shape = GeomConvHelper::parseShapeReporting(
                                   shapeS, attrs.getObjectType(), id.c_str(), ok, false);
        shape.push_back_noDoublePos(shape[0]); // need closed shape
        if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD
            // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos)));
            mySuspectKeepShape = true;
        }
    }
    NBNode* node = new NBNode(id, pos, type);
    if (!myNodeCont.insert(node)) {
        WRITE_ERROR("Problems on adding junction '" + id + "'.");
        delete node;
        return;
    }
}
Ejemplo n.º 14
0
void
NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) {
    // get the id, report an error if not given or empty...
    bool ok = true;
    std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
    if (!ok) {
        return;
    }
    if (id[0] == ':') { // internal node
        return;
    }
    SumoXMLNodeType type = attrs.getNodeType(ok);
    if (ok) {
        if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type
            type = NODETYPE_DEAD_END;
        }
    } else {
        WRITE_WARNING("Unknown node type for junction '" + id + "'.");
    }
    Position pos = readPosition(attrs, id, ok);
    NILoader::transformCoordinates(pos, true, myLocation);
    // the network may have non-default edge geometry.
    // accurate reconstruction of legacy networks is not possible. We ought to warn about this
    if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
        PositionVector shape = attrs.getShapeReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, true);
        if (shape.size() > 0) {
            shape.push_back_noDoublePos(shape[0]); // need closed shape
            if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD
                // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos)));
                mySuspectKeepShape = true;
            }
        }
    }
    NBNode* node = new NBNode(id, pos, type);
    if (!myNodeCont.insert(node)) {
        WRITE_ERROR("Problems on adding junction '" + id + "'.");
        delete node;
        return;
    }
}
Ejemplo n.º 15
0
bool
MPTreeMgr::readInput( const char * node , const char * pl , const char * net )
{
   Node * pNd1 , * pNd2;
   int arg1 , arg2 , move;

	cout << " >  readInput() : start reading input data\n";
	if ( !readNode     ( node )   )      return false;
	if ( !readPosition ( pl   )   )      return false;
	if ( !readNet      ( net  )   )      return false;
   buildInitMPTree();
   
   while ( !packMPTree() ) {
      pNd1 = pNd2 = NULL;
      arg1 = arg2 = -1;
      move = rand() % 4;
      perturbMPTree( &pNd1 , &pNd2 , &arg1 , &arg2 , move );
   }
   
   initCost();
	return true;
}
Ejemplo n.º 16
0
//#################################################################
//
// void dynamixels::setPositionALL(int desired_position)
//
//#################################################################
void dynamixels::setPositionALL(uint32_t desired_position)
{
	for(int i=0; i<MAXIMUM_NUMBER_DYNAMIXELS;i++) // CORRECT
  	{
  		if (ID_array[i] == 0)
  			break;
		// Write goal position
		setPosition(i, desired_position);
	}

	uint32_t lowerLimit = desired_position - POSITION_THRESHOLD;
	uint32_t upperLimit = desired_position + POSITION_THRESHOLD;
	if ((int) desired_position - POSITION_THRESHOLD < DXL_MINIMUM_POSITION_VALUE)
		lowerLimit = DXL_MINIMUM_POSITION_VALUE;
	if ((int) desired_position + POSITION_THRESHOLD > DXL_MAXIMUM_POSITION_VALUE)
		upperLimit = DXL_MAXIMUM_POSITION_VALUE;

	uint32_t position;
	bool inPlace = true;
  	for(int i=0; i<MAXIMUM_NUMBER_DYNAMIXELS;i++)
	{
		if (ID_array[i] == 0)
		{
			if (!inPlace)
			{
				i = 0;
				inPlace = true;
			}
			else 
				break;
		}
		
		position = 0;
		position = readPosition(i);
		inPlace = inPlace && (position < upperLimit && position > lowerLimit);
		// printf("ID: %d, POSITION: %d %d %d\n", ID_array[i], position, upperLimit, lowerLimit); // CORRECT
	}
}
Ejemplo n.º 17
0
// ---
QGAMES::GraphicalPolyline* QGAMES::ObjectBuilder::readGraphicalPolyline (TiXmlElement* e)
{
	int id = -1;
	std::string color (__NULL_STRING__);
	QGAMES::Positions ptions;
	std::map <std::string, std::string> pties;
	e -> Attribute (__QGAMES_POLYATTRID__, &id);
	color = e -> Attribute (__QGAMES_POLYATTRCOLOR__);
	assert (id != -1);

	for (TiXmlElement* groupElement = e -> FirstChildElement ();
		groupElement != NULL; groupElement = groupElement -> NextSiblingElement ())
	{
		if (strcmp (groupElement -> Value (), __QGAMES_POLYPOINTBLOCK__) == 0)
			ptions.push_back (readPosition (groupElement));
		if (strcmp (groupElement -> Value (), __QGAMES_ATTRSBLOCK__) == 0)
			pties = readPropertiesSection (groupElement);
	}

	// Create the graphical object....
	return (createGraphycalPolyline 
		(id, QGAMES::Position::_cero, ptions, QGAMES::Color (color), pties));
}
Ejemplo n.º 18
0
/* Merge one block of an on-disk doclist into a DocListMerge. */
static void mergeBlock(DocListMerge *m, DocList *pBlock){
  DocListReader blockReader;
  assert( pBlock->iType >= DL_POSITIONS );
  readerInit(&blockReader, pBlock);
  while( !readerAtEnd(&blockReader) ){
    sqlite_int64 iDocid = readDocid(&blockReader);
    if( m->in.pDoclist!=NULL ){
      while( 1 ){
        if( readerAtEnd(&m->in) ) return;  /* nothing more to merge */
        if( peekDocid(&m->in)>=iDocid ) break;
        skipDocument(&m->in);
      }
      if( peekDocid(&m->in)>iDocid ){  /* [pIn] has no match with iDocid */
        skipPositionList(&blockReader);  /* skip this docid in the block */
        continue;
      }
      readDocid(&m->in);
    }
    /* We have a document match. */
    if( m->in.pDoclist==NULL || m->in.pDoclist->iType < DL_POSITIONS ){
      /* We don't need to do a poslist merge. */
      docListAddDocid(m->pOut, iDocid);
      if( m->pOut->iType >= DL_POSITIONS ){
        /* Copy all positions to the output doclist. */
        while( 1 ){
          int pos = readPosition(&blockReader);
          if( pos==-1 ) break;
          docListAddPos(m->pOut, pos);
        }
        docListAddEndPos(m->pOut);
      } else skipPositionList(&blockReader);
      continue;
    }
    mergePosList(m, iDocid, &blockReader);
  }
}
Ejemplo n.º 19
0
static void mergeBlock(DocListMerge *m, DocList *pBlock){
  DocListReader blockReader;
  assert( pBlock->iType >= DL_POSITIONS );
  readerInit(&blockReader, pBlock);
  while( !readerAtEnd(&blockReader) ){
    sqlite_int64 iDocid = readDocid(&blockReader);
    if( m->in.pDoclist!=NULL ){
      while( 1 ){
        if( readerAtEnd(&m->in) ) return;  
        if( peekDocid(&m->in)>=iDocid ) break;
        skipDocument(&m->in);
      }
      if( peekDocid(&m->in)>iDocid ){  
        skipPositionList(&blockReader);  
        continue;
      }
      readDocid(&m->in);
    }
    
    if( m->in.pDoclist==NULL || m->in.pDoclist->iType < DL_POSITIONS ){
      
      docListAddDocid(m->pOut, iDocid);
      if( m->pOut->iType >= DL_POSITIONS ){
        
        while( 1 ){
          int pos = readPosition(&blockReader);
          if( pos==-1 ) break;
          docListAddPos(m->pOut, pos);
        }
        docListAddEndPos(m->pOut);
      } else skipPositionList(&blockReader);
      continue;
    }
    mergePosList(m, iDocid, &blockReader);
  }
}
Ejemplo n.º 20
0
/* Skip past the end of a position list. */
static void skipPositionList(DocListReader *pReader){
  while( readPosition(pReader)!=-1 )
    ;
}
Ejemplo n.º 21
0
Mesh loadMeshFromObj(const char *filename, float scale)
{
	printf("Attempting to load mesh->from %s\n", filename);

	std::ifstream filehandle;
	filehandle.open(filename, std::ios::in);

	if(filehandle.fail())
	{
		printf("Could not open file.\n");
		return Mesh();
	}

	std::vector<std::list<sVertexIndex> > existingVertexTable;

	std::vector<sVertexIndex>	vertexTable;
	std::vector<Mesh::sFace>	faceTable;

	std::vector<sVec3> positionTable;
	std::vector<sVec3> normalTable;
	std::vector<sVec2> texcoordTable;

	std::string line;
	std::string name(filename);
	int sg = 0;

	clock_t start, end;
	start = clock();

	printf("Reading data... ");

	while( filehandle.good() && !filehandle.eof() )
	{
		std::getline(filehandle, line);
		if(line[0] == 'v')
		{
			if(line[1] == 't')
				readTexcoord(line, texcoordTable);
			else if(line[1] == 'n')
				readNormal(line, normalTable);
			else
				readPosition(line, positionTable, scale);
		}
		else if(line[0] == 'f')
			readFace(line, vertexTable, existingVertexTable, faceTable, sg);
		else if(line[0] == 's')
			readSG(line, sg);
	}

	Mesh m;
	fillMesh(	m, name, vertexTable, faceTable,
				positionTable, normalTable, texcoordTable);

	printf("done!\n");

	printf("total vertex count %i\n", vertexTable.size());
	printf("total face count %i\n", faceTable.size());

    end = clock();
    double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
    printf("Time taken %3.3fs \n", cpu_time_used);

	return m;
}
Ejemplo n.º 22
0
std::vector<Mesh> loadMeshesFromObj(const char *filename, float scale)
{
	printf("Attempting to load mesh->from %s\n", filename);

	std::ifstream filehandle;
	filehandle.open(filename, std::ios::in);

	std::vector<Mesh> meshes;

	if(filehandle.fail())
	{
		printf("Could not open file.\n");
		return meshes;
	}

	std::vector<std::list<sVertexIndex> > existingVertexTable;

	std::vector<sVertexIndex>	vertexTable;
	std::vector<Mesh::sFace>	faceTable;

	std::vector<sVec3> positionTable;
	std::vector<sVec3> normalTable;
	std::vector<sVec2> texcoordTable;

	std::string line;
	std::string name;
	std::string material;
	int sg = 0;
	int count = 0;

	clock_t start, end;
	start = clock();

	printf("Reading data... ");

	while( filehandle.good() && !filehandle.eof() )
	{
		std::getline(filehandle, line);
		if(line[0] == 'v')
		{
			if(line[1] == 't')
				readTexcoord(line, texcoordTable);
			else if(line[1] == 'n')
				readNormal(line, normalTable);
			else
				readPosition(line, positionTable, scale);
		}
		else if(line[0] == 'f')
			readFace(line, vertexTable, existingVertexTable, faceTable, sg);
		else if(line[0] == 's')
			readSG(line, sg);
		else if(line[0] == 'g')
		{
			readG(line, name);
		}
		else if(line[0] == 'u')
		{
			char str[32];
			char mtl[128];
			int success = sscanf(line.c_str(), "%s %s", str, mtl);
			if(success && strcmp(str, "usemtl") == 0)
			{
				if(count > 0)
				{
					meshes.push_back(Mesh());
					fillMesh(	meshes[count-1], name, vertexTable, faceTable,
								positionTable, normalTable, texcoordTable);
					meshes[count-1].material = material;
					vertexTable.clear();
					faceTable.clear();
					existingVertexTable.clear();
				}
				++count;

				if(success > 1)
					material = std::string(mtl);
			}
		}
	}

	if(count > 0)
	{
		meshes.push_back(Mesh());
		fillMesh(	meshes[count-1], name, vertexTable, faceTable,
					positionTable, normalTable, texcoordTable);
		meshes[count-1].material = material;
	}

	printf("done!\n");

	//printf("total vertex count %i\n", vertexTable.size());
	//printf("total face count %i\n", faceTable.size());

    end = clock();
    double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
    printf("Time taken %3.3fs \n", cpu_time_used);

    //printf("meshes.size() = %i\n", meshes.size());

	return meshes;
}
 void PortableReaderBase::setPosition(char const *fieldName, FieldType const& fieldType) {
     dataInput.position(readPosition(fieldName, fieldType));
 }
Ejemplo n.º 24
0
void NStep::TimerHit()
{
    if (isConnected() == false)
        return;

    double currentPosition = FocusAbsPosN[0].value;

    readPosition();

    // Check if we have a pending motion
    // and if we STOPPED, then let's take the next action
    if ( (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY) && isMoving() == false)
    {
        // Are we done moving?
        if (m_TargetDiff == 0)
        {
            FocusAbsPosNP.s = IPS_OK;
            FocusRelPosNP.s = IPS_OK;
            IDSetNumber(&FocusAbsPosNP, nullptr);
            IDSetNumber(&FocusRelPosNP, nullptr);
        }
        else
        {
            // 999 is the max we can go in one command
            // so we need to go 999 or LESS
            // therefore for larger movements, we break it down.
            int nextMotion = (std::abs(m_TargetDiff) > 999) ? 999 : std::abs(m_TargetDiff);
            int direction = m_TargetDiff > 0 ? FOCUS_OUTWARD : FOCUS_INWARD;
            int mode = IUFindOnSwitchIndex(&SteppingModeSP);
            char cmd[NSTEP_LEN] = {0};
            snprintf(cmd, NSTEP_LEN, ":F%d%d%03d#", direction, mode, nextMotion);
            if (sendCommand(cmd) == false)
            {
                LOG_ERROR("Failed to issue motion command.");
                if (FocusRelPosNP.s == IPS_BUSY)
                {
                    FocusRelPosNP.s = IPS_ALERT;
                    IDSetNumber(&FocusRelPosNP, nullptr);
                }
                if (FocusAbsPosNP.s == IPS_BUSY)
                {
                    FocusAbsPosNP.s = IPS_ALERT;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
                }
            }
            else
                // Reduce target diff depending on the motion direction
                // Negative targetDiff increases eventually to zero
                // Positive targetDiff decreases eventually to zero
                m_TargetDiff = m_TargetDiff + (nextMotion * ((direction == FOCUS_INWARD) ? 1 : -1));
        }
        // Check if can update the absolute position in case it changed.
    }
    else if (currentPosition != FocusAbsPosN[0].value)
    {
        IDSetNumber(&FocusAbsPosNP, nullptr);
    }

    // Read temperature
    if (TemperatureNP.s == IPS_OK && m_TemperatureCounter++ == NSTEP_TEMPERATURE_FREQ)
    {
        m_TemperatureCounter = 0;
        if (readTemperature())
            IDSetNumber(&TemperatureNP, nullptr);
    }

    SetTimer(POLLMS);
}
Ejemplo n.º 25
0
QWidget* MyFracWindow::createParamsDock(QWidget* parent)
{
	QVBox* wrapper = new QVBox(parent);
	wrapper->setSpacing(0);

	QGrid* propParams = new QGrid(2, wrapper);
	propParams->setMargin(7);
	propParams->setSpacing(5);

	new QLabel(i18n("X coordinate:"), propParams);
	_editPosX = new QLineEdit(propParams);
	_editPosX->setValidator(new QDoubleValidator(-4.0, 4.0, 15, _editPosX));
	connect(_editPosX, SIGNAL(returnPressed()), SLOT(readPosition()));
	connect(_editPosX, SIGNAL(lostFocus()), SLOT(readPosition()));
	QToolTip::add(_editPosX, i18n("X coordinate of the center of the view"));

	new QLabel(i18n("Y coordinate:"), propParams);
	_editPosY = new QLineEdit(propParams);
	_editPosY->setValidator(new QDoubleValidator(-4.0, 4.0, 15, _editPosY));
	connect(_editPosY, SIGNAL(returnPressed()), SLOT(readPosition()));
	connect(_editPosY, SIGNAL(lostFocus()), SLOT(readPosition()));
	QToolTip::add(_editPosY, i18n("Y coordinate of the center of the view"));

	new QLabel(i18n("Zoom magnitude:"), propParams);
	_editZoom = new QLineEdit(propParams);
	_editZoom->setValidator(new QDoubleValidator(-1.0, 14.0, 15, _editZoom));
	connect(_editZoom, SIGNAL(returnPressed()), SLOT(readPosition()));
	connect(_editZoom, SIGNAL(lostFocus()), SLOT(readPosition()));
	QToolTip::add(_editZoom, i18n("Zoom order of maginitude"));

	new QLabel(i18n("Rotation angle:"), propParams);
	_editAngle = new QLineEdit(propParams);
	_editAngle->setValidator(new QDoubleValidator(-360.0, 360.0, 15, _editAngle));
	connect(_editAngle, SIGNAL(returnPressed()), SLOT(readPosition()));
	connect(_editAngle, SIGNAL(lostFocus()), SLOT(readPosition()));
	QToolTip::add(_editAngle, i18n("View rotation angle in degrees"));

	new QLabel(i18n("Julia X param.:"), propParams);
	_editJuliaX = new QLineEdit(propParams);
	connect(_editJuliaX, SIGNAL(returnPressed()), SLOT(readJulia()));
	connect(_editJuliaX, SIGNAL(lostFocus()), SLOT(readJulia()));
	QToolTip::add(_editJuliaX, i18n("X coordinate of the Julia parameter"));

	new QLabel(i18n("Julia Y param.:"), propParams);
	_editJuliaY = new QLineEdit(propParams);
	connect(_editJuliaY, SIGNAL(returnPressed()), SLOT(readJulia()));
	connect(_editJuliaY, SIGNAL(lostFocus()), SLOT(readJulia()));
	QToolTip::add(_editJuliaY, i18n("Y coordinate of the Julia parameter"));

	new QLabel(i18n("Iterations limit:"), propParams);
	_sliderIterations = new QSlider(QSlider::Horizontal, propParams);
	_sliderIterations->setRange(0, 20);
	connect(_sliderIterations, SIGNAL(valueChanged(int)), SLOT(setMaxIterations(int)));
	QToolTip::add(_sliderIterations, i18n("Maximum number of iterations to calculate"));

	new QLabel(i18n("Detail level:"), propParams);
	_sliderQuality = new QSlider(QSlider::Horizontal, propParams);
	_sliderQuality->setRange(0, 10);
	connect(_sliderQuality, SIGNAL(valueChanged(int)), SLOT(setQuality(int)));
	QToolTip::add(_sliderQuality, i18n("Amount of details to calculate"));

	wrapper->setStretchFactor(new QWidget(wrapper), 1);

	return wrapper;
}
Ejemplo n.º 26
0
bool clsTranslator::loadSceneScript(LPSCENE3D Scene, TCHAR *fileName) {
    FILE* file;
    errno_t bErrorFlag = _tfopen_s(&file, fileName, _T("r"));
    if (bErrorFlag)
        return false;

    TCHAR buffer[256];
    buffer[19] = '\0';
    bErrorFlag = _ftscanf_s(file, _T("%19c"), buffer);
    if ( wcscmp(buffer, _T("3DEditor scene file")) )
        return false;

    // loading cameras
    bErrorFlag = _ftscanf_s(file, _T("%94c\0"), buffer);
    UINT objCount;
    bErrorFlag = _ftscanf_s(file, _T("%d"), &objCount);
    for (UINT i = 0; i < objCount; i++) {
        LPCAMERA3D camera = new CAMERA3D;

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        camera->setName(buffer, 256);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        readPosition(camera, file);

        bErrorFlag = _ftscanf_s(file, _T("%24c"), buffer);
        VECTOR3D fwd, rwd, uwd;
        readRotation(fwd, uwd, rwd, file);
        camera->setForwardLookDirection(fwd);
        camera->setUpLookDirection(uwd);
        camera->setRightLookDirection(rwd);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        float tmp;
        bErrorFlag = _ftscanf_s(file, _T("%f"), &tmp);
        camera->setHFov(tmp);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag =_ftscanf_s(file, _T("%f"), &tmp);
        camera->setVFov(tmp);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%f"), &tmp);
        camera->setNearCP(tmp);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%f"), &tmp);
        camera->setFarCP(tmp);

        bErrorFlag = _ftscanf_s(file, _T("%77c"), buffer, 256);
        Scene->AddObject(camera);
        camera->Transform();
    }

    // loading lighters
    bErrorFlag = _ftscanf_s(file, _T("%94c\0"), buffer);
    bErrorFlag = _ftscanf_s(file, _T("%d"), &objCount);
    for (UINT i = 0; i < objCount; i++) {
        LPDIFLIGHT3D light = new DIFLIGHT3D;

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        light->setName(buffer, 256);

        bErrorFlag = _ftscanf_s(file, _T("%24c"), buffer);
        VECTOR3D fwd, rwd, uwd;
        readRotation(fwd, uwd, rwd, file);
        light->setForwardLookDirection(fwd);
        light->setUpLookDirection(uwd);
        light->setRightLookDirection(rwd);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        float tmp;
        bErrorFlag = _ftscanf_s(file, _T("%f"), &tmp);
        light->setPower(tmp);

        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        int r, g, k;
        bErrorFlag = _ftscanf_s(file, _T("%d %d %d"), &r, &g, &k);
        light->setColor(r, g, k);

        bErrorFlag = _ftscanf_s(file, _T("%77c"), buffer, 256);
        Scene->AddObject(light);
    }

    // loading meshes
    bErrorFlag = _ftscanf_s(file, _T("%94c"), buffer);
    bErrorFlag = _ftscanf_s(file, _T("%d"), &objCount);
    for (UINT i = 0; i < objCount; i++) {
        bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
        //	LPMESH3D mesh = new MESH3D(readMeshID(file));
        switch ( readMeshID(file) ) {
        /*case MSH_PYRAMID:
        	readPyramid((LPPYRAMID3D)mesh, file, Scene);
        	break;
        case MSH_CONE:
        	readCone((LPCONE3D)mesh, file, Scene);
        	break;
        case MSH_EXCONE:
        	readExCone((LPEXCONE3D)mesh, file, Scene);
        	break;
        case MSH_HOLE:
        	readHole((LPHOLE3D)mesh, file, Scene);
        	break;*/
        case MSH_MIC:
            bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
            readMic(file, Scene);
            break;
        case MSH_TANK:
            bErrorFlag = _ftscanf_s(file, _T("%s"), buffer, 256);
            readTank(file, Scene);
            break;
        }
    }

    //return ( bErrorFlag != 0 );
    return true;
}
Ejemplo n.º 27
0
void TcxReader::readTrackpoint(CTrack *track, int lap)
{
    Q_ASSERT(isStartElement() && name() == "Trackpoint");

    CTrack::pt_t *pt = new CTrack::pt_t();
    pt->lat = pold.lat;
    pt->lon = pold.lon;
    pt->ele = pold.ele;
    pt->distance = pold.distance;
    pt->heartReateBpm = pold.heartReateBpm;

    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (name() == "Time")
            {
                QDateTime time(QDateTime::fromString(readElementText(),
                    Qt::ISODate));
                time.setTimeSpec(Qt::UTC);
                pt->timestamp = time.toTime_t();
            }
            else if (name() == "AltitudeMeters")
            {
                pt->ele = readElementText().toDouble();
                pold.ele = pt->ele;
            }
            else if (name() == "DistanceMeters")
            {
                pt->distance = readElementText().toDouble();
                pold.distance = pt->distance;
            }
            else if (name() == "Position")
            {
                readPosition(pt);
                pold.lat = pt->lat;
                pold.lon = pt->lon;
                firstPositionFound = true;
            }
            else if (name() == "HeartRateBpm")
            {
                readHeartRateBpm(pt);
                pold.heartReateBpm  = pt->heartReateBpm;
            }
            else if (name() == "Cadence")
            {
                //readCadenceRpm(pt);
                pt->cadenceRpm = readElementText().toInt();
                pold.cadenceRpm  = pt->cadenceRpm;
            }
            else
                readUnknownElement();
        }
    }
    pt->_lat=pt->lat;
    pt->_lon=pt->lon;
    pt->_ele=pt->ele;
    if (firstPositionFound)
    {
        *track << *pt;
    }
}