Exemplo n.º 1
0
void Editor::Down()
{
	if (mode == MOVE_VIEW)
		addPos(0, -0.4f, 0);
	if (mode == MOVE_OBJECT) {
		if (Object3DS::selected != NULL)
			Object3DS::selected->transform.position.y -= moveStep;
	}
	if (mode == ROTATE_OBJECT) {
		if (Object3DS::selected != NULL)
			Object3DS::selected->transform.rotation.y += rotStep;
	}
}
Exemplo n.º 2
0
void PhysicsModule::update(sf::Time deltaT)
{
	float t = 1;
	//C
	float c = t*t*.5;
	setAccel(getAccel() * c);
	//B
	setVel(getVel() * t);
	//B&C
	addVel(getAccel());
	//A&B&C
	addPos(getVel());
	setAccel(sf::Vector2f(0,0));
}
Exemplo n.º 3
0
void Editor::Backward()
{
	if (mode == ROTATE_VIEW)
		addRot(-1.5F, 0, 0);
	if (mode == MOVE_VIEW)
		addPos(0, 0, 0.8f);
	if (mode == MOVE_OBJECT) {
		if (Object3DS::selected != NULL)
			Object3DS::selected->transform.position.z += moveStep;
	}

	if (mode == ROTATE_OBJECT) {
		if (Object3DS::selected != NULL)
			Object3DS::selected->transform.rotation.x += rotStep;
	}
}
Exemplo n.º 4
0
rapidjson::Value SuperastCPP::createMessageValue(clang::Decl* decl, const std::string& type,
    const std::string& value, const std::string& description) {
  
  rapidjson::Value object(rapidjson::kObjectType);
  addId(object);
  addPos(object, decl);
  object.AddMember("type",
      rapidjson::Value().SetString(type.c_str(), type.size(), allocator),
      allocator);
  object.AddMember("value",
      rapidjson::Value().SetString(value.c_str(), value.size(), allocator),
      allocator);
  object.AddMember("description",
      rapidjson::Value().SetString(description.c_str(), description.size(), allocator),
      allocator);

  return object;
}
Exemplo n.º 5
0
  // IF STATEMENT 
bool SuperastCPP::TraverseIfStmt(clang::IfStmt* ifs) {
  rapidjson::Value ifValue(rapidjson::kObjectType);
  addId(ifValue);
  addPos(ifValue, ifs);
  ifValue.AddMember("type", "conditional", allocator);

  // Check if the condition contains a var declaration
  if (ifs->getConditionVariable()) {
    ifValue.AddMember("condition", createMessageValue(ifs->getConditionVariable(), "error",
        "condition-variable",
        "Variable declarations are not allowed in if conditions"),
        allocator);
  }
  else {
    // condition part
    TRY_TO(TraverseStmt(ifs->getCond()));

    rapidjson::Value conditionValue;
    conditionValue = sonValue;
    ifValue.AddMember("condition", conditionValue, allocator);
  }

  // then part
  TRY_TO(TraverseStmt(ifs->getThen()));
  // Now sonValue contains the arrayValue
  ensureSonIsArray();
  rapidjson::Value blockValue = createBlockValue(sonValue);
  ifValue.AddMember("then", blockValue, allocator);

  // if has else, print
  if (ifs->getElse()) {
    TRY_TO(TraverseStmt(ifs->getElse()));
    // sonValue contains the arrayValue
    ensureSonIsArray();
    blockValue = createBlockValue(sonValue);
    ifValue.AddMember("else", blockValue, allocator);
  }

  sonValue = ifValue;
  return true;
}
Exemplo n.º 6
0
void twinOrfStats(char *axtFile, char *raFile, char *outFile)
/* twinOrfStats - Collect stats on refSeq cDNAs aligned to another species via axtForEst. */
{
struct hash *rsiHash = readRefRa(raFile);
struct lineFile *lf = lineFileOpen(axtFile, TRUE);
FILE *f = mustOpen(outFile, "w");
struct axt *axt;
static struct c1Counts c1Kozak[10], c1all, c1utr5, c1utr3, c1cds;
static struct c2Counts c2Kozak[10], c2All, c2Utr5, c2Utr3, c2Cds;
static struct c3Counts c3All, c3Utr5, c3Utr3, c3Cds;
char label[64];
char *predictFile = optionVal("predict", NULL);
int i;
static struct c3Counts cod1, cod2, cod3, stop, earlyCod1, earlyCod2, earlyCod3;
int earlySize;

initC3Counts(&cod1, 0);
initC3Counts(&cod2, 0);
initC3Counts(&cod3, 0);
initC3Counts(&earlyCod1, 0);
initC3Counts(&earlyCod2, 0);
initC3Counts(&earlyCod3, 0);
initC3Counts(&c3Utr3, 0);
initC3Counts(&c3Utr5, 0);
initC3Counts(&stop, 0);

threshold = optionFloat("threshold", threshold);
earlyAaSize = optionInt("earlyAaSize", earlyAaSize);
earlySize = 3*earlyAaSize;
while ((axt = axtRead(lf)) != NULL)
    {
    struct refSeqInfo *rsi = hashFindVal(rsiHash, axt->tName);
    if (rsi != NULL && rsi->cdsStart >= 6)
        {
	if (checkAtg(axt, rsi->cdsStart))
	    {
	    for (i=0; i<10; ++i)
		addPos(&c1Kozak[i], &c2Kozak[i], axt, rsi->cdsStart - 5 + i);
	    addRange(&c1all, &c2All, &c3All, axt, 0, rsi->size);
	    addRange(&c1utr5, &c2Utr5, &c3Utr5, axt, 0, rsi->cdsStart);
	    addRange(&c1cds, &c2Cds, &c3Cds, axt, rsi->cdsStart, rsi->cdsEnd);
	    addRange(&c1utr3, &c2Utr3, &c3Utr3, axt, rsi->cdsEnd, rsi->size);

	    /* The +3+1 in the expression below breaks down as so:  the
	     * +3 is to move past the first 'ATG' codon, which is part of
	     * the Kozak consensus model, not the coding model.  The +1
	     * is so that we look at the 2nd and 3rd bases of the previous
	     * codon, and the first base of the current codon.   */
	    addCodons(&earlyCod1, axt, rsi->cdsStart+3+1, rsi->cdsStart+1+earlySize);
	    addCodons(&earlyCod2, axt, rsi->cdsStart+3+2, rsi->cdsStart+2+earlySize);
	    addCodons(&earlyCod3, axt, rsi->cdsStart+3+3, rsi->cdsStart+3+earlySize);
	    addCodons(&cod1, axt, rsi->cdsStart+3+1+earlySize, rsi->cdsEnd-5);
	    addCodons(&cod2, axt, rsi->cdsStart+3+2+earlySize, rsi->cdsEnd-4);
	    addCodons(&cod3, axt, rsi->cdsStart+3+3+earlySize, rsi->cdsEnd-3);
	    addCodons(&stop, axt, rsi->cdsEnd-3, rsi->cdsEnd);
	    }
	}
    axtFree(&axt);
    }
lineFileClose(&lf);

dumpC1(f, &c1all, "c1_all");
dumpC2(f, &c2All, "c2_all");
dumpC3(f, &c3All, "c3_all");

dumpC1(f, &c1utr5, "c1_utr5");
dumpC2(f, &c2Utr5, "c2_utr5");
dumpC3(f, &c3Utr5, "c3_utr5");

dumpC1(f, &c1cds, "c1_cds");
dumpC2(f, &c2Cds, "c2_cds");
dumpC3(f, &c3Cds, "c3_cds");

dumpC1(f, &c1utr3, "c1_utr3");
dumpC2(f, &c2Utr3, "c2_utr3");
dumpC3(f, &c3Utr3, "c3_utr3");

for (i=0; i<10; ++i)
    {
    sprintf(label, "c1_kozak[%d]", i-5);
    dumpC1(f, &c1Kozak[i], label);
    sprintf(label, "c2_kozak[%d]", i-5);
    dumpC2(f, &c2Kozak[i], label);
    }
dumpC3(f, &earlyCod1, "earlyCod1");
dumpC3(f, &earlyCod2, "earlyCod2");
dumpC3(f, &earlyCod3, "earlyCod3");
dumpC3(f, &cod1, "cod1");
dumpC3(f, &cod2, "cod2");
dumpC3(f, &cod3, "cod3");
dumpC3(f, &stop, "stop");

if (predictFile)
    {
    predict(c1Kozak, &c1all, axtFile, predictFile, rsiHash);
    }
}
Exemplo n.º 7
0
/*
*	FUNZIONE CHE DATO IL PUNTATORE ALLA POSIZIONE E ALLA DIREZIONE ATTUALI
*	SETTA LA NUOVA POSIZIONE E LA NUOVA DIREZIONE 
*/
GLvoid setPosDir(SpaceShip *spSh){
	me=g_camera.getPos();
	dist=distance(spSh->pos,me);
	GLfloat rad=spSh->rad;
	
	if(dist>35){
	//if(dist>10){
		spSh->move=true;	
		int i=checkDistPlanet(spSh->pos);
		int j=checkDistSatellite(spSh->pos);
		Point3 *tmp=(Point3 *) malloc(sizeof(Point3));
		
		/* ALGORITMO CHE PERMETTE ALLE NAVETTE SPAZIALI DI EVITARE PIANETI, SATELLITI E ALTRE NAVETTE */
			
			if( (i!=-1) && (j==-1) && RaySphereIntersection(spSh->pos,me,posPlanet[i],radius[i]+rad+rad*0.1,tmp) )
			{	// se stiamo andando addosso ad un pianeta ma non c'e' un satellite nelle vicinanze		
			
				// troviamo il nuovo punto verso cui dirigerci per evitare il pianeta
				*tmp=addPos(*tmp, radius[i]+rad);			
				spSh->dir=directionRel(spSh->pos,*tmp);
				spSh->dirCorr=false;		// perche' non ci stiamo muovendo verso la telecamera
			}
			// se stiamo andando addosso ad un satellite ma non siamo ancora nelle vicinanze di un pianeta
			else if( (i==-1) && (j!=-1) && RaySphereIntersection(spSh->pos,me,satellite[j].pos,satellite[j].rad+rad+rad*0.1,tmp) )
			{
				*tmp=addPos(*tmp, satellite[j].rad);
				spSh->dir=directionRel(spSh->pos,*tmp);
				spSh->dirCorr=false;		// perche' non ci stiamo muovendo verso la telecamera
			}
			// se siamo nelle vicinanze sia di un satellite che di un pianeta e vi e' intesersezione con almeno uno dei due
			else if( (i!=-1) && (j!=-1) && 
				( 	RaySphereIntersection(spSh->pos,me,satellite[j].pos,satellite[j].rad+rad+rad*0.1,tmp) ||  
					RaySphereIntersection(spSh->pos,me,posPlanet[i],radius[i]+rad+rad*0.1,tmp))	)
				{
				
				Point3 *tmpSat=(Point3 *) malloc(sizeof(Point3));
				Point3 *tmpPl=(Point3 *) malloc(sizeof(Point3));
				bool intersectionSat=RaySphereIntersection(spSh->pos,me,satellite[j].pos,satellite[j].rad+rad+rad*0.1,tmpSat);
				bool intersectionPl=RaySphereIntersection(spSh->pos,me,posPlanet[i],radius[i]+rad+rad*0.1,tmpPl);
				float distPl=distance(spSh->pos,*tmpPl);
				float distSat=distance(spSh->pos,*tmpSat);
				// se interseca solo il pianeta, o se gli interseca entrambi, ma prima il pianeta
				if( (intersectionPl && !intersectionSat) || ((intersectionPl && intersectionSat) && distPl<distSat) )
				{
					*tmpPl=addPos(*tmpPl, radius[i]+rad);
					spSh->dir=directionRel(spSh->pos,*tmpPl);
					spSh->dirCorr=false;		// perche' non ci stiamo muovendo verso la telecamera
				} 
				// se interseca solo il satellite, o se gli interseca entrambi, ma prima il satellite
				else if(!intersectionPl && intersectionSat || ((intersectionPl && intersectionSat) && distSat<=distPl) )
				{
					*tmpSat=addPos(*tmpSat, satellite[j].rad);
					//*tmpSat=addPos(*tmpSat, satellite[j].rad+rad);
					spSh->dir=directionRel(spSh->pos,*tmpSat);
					spSh->dirCorr=false;		// perche' non ci stiamo muovendo verso la telecamera
				}
				free(tmpPl);
				free(tmpSat);
			}
			else	// se non c'e' rischio collisione ne con un satellite ne con un pianeta
			{	
				// le variabili di tipo clock servono per non far "impazzire" il cambio di direzione delle navicelle 
				//quando abbengono rapidi cambiamenti di posizione della telecamera
				int num;
				char type;
				Point3 intShip;
				GLboolean collision=firstShip(spSh,&num,&type,&intShip);
				// restituisce se esiste il numero e il tipo della prima navicella che c'e' nella direzione verso la telecamera
				if(collision && abs(clock()-pastClock)>=CLOCKS_PER_SEC*0.3)
				{ 	// si controlla se c'e' un altra navetta sulla traiettoria
					pastClock=clock();					
					
					GLboolean mv;
					switch(type){	case 'p': mv=police[num].move; break;
							case 'e': mv=enemy[num].move; break;	}
					
					// si settano queste variabili in modo che si mantenga la stessa direzione 
					// finche' continua ad esserci insersezione con la stessa navetta		
					if(!mv && type!=oldType && num!=oldNum)
					{	// si trova la nuova direzione per evitarla						
						oldType=type;
						oldNum=num;	
						switch(type){
							case 'p': *tmp=addPos(intShip, (spSh->rad+police[num].rad)); break;
							case 'e': *tmp=addPos(intShip, (spSh->rad+enemy[num].rad)); break;
						}
						spSh->dir= directionRel(spSh->pos,*tmp);
						spSh->dirCorr=false;	
					}
					//else if(mv && abs(clock()-pastClock)>=CLOCKS_PER_SEC*0.3)
					else if(mv) 
					{
						oldType=' ';
						oldNum=-1;
						switch(type){
							case 'p': *tmp=addPos(intShip, (spSh->rad+police[num].rad)); break;
							case 'e': *tmp=addPos(intShip, (spSh->rad+enemy[num].rad)); break;
						}
						spSh->dir= directionRel(spSh->pos,*tmp);
						spSh->dirCorr=false;
					}
				}
				// se non ci sono ostacoli
				else if(!collision && abs(clock()-pastClock)>=CLOCKS_PER_SEC*0.3)
				//else
				{
					pastClock=clock();
					oldType=' ';
					oldNum=-1;
					spSh->dir=directionRel(spSh->pos,me); 	// si aggiorna nella direzione tra oggetto e me
					spSh->dirCorr=true;			// perche' ci stiamo muovendo verso la telecamera
				}
			}
		
			// ora che abbiamo trovato la direzione di movimento, muoviamo la navicella
			if (!freezeShip){			
				spSh->pos.x += spSh->dir.x*sp;
				spSh->pos.y += spSh->dir.y*sp;
				spSh->pos.z += spSh->dir.z*sp;
				glutPostRedisplay();
			}
		free(tmp);
	}
	// se non ci si deve muovere, la direzione deve essere sempre rivolta verso la telecamera
	else if (!freezeShip){
		spSh->move=false;
		spSh->dir=directionRel(spSh->pos,me); 		// si aggiorna nella direzione tra oggetto e me
		spSh->dirCorr=true; 				// perche' ci stiamo muovendo verso la telecamera
	}
}
Exemplo n.º 8
0
bool SuperastCPP::TraverseCXXOperatorCallExpr(clang::CXXOperatorCallExpr* operatorCallExpr) {
  // IF THERE IS A PRINT
  auto decl = llvm::dyn_cast<clang::FunctionDecl>(operatorCallExpr->getCalleeDecl());
  if (!decl) {
    std::cerr << "Unknown function in CXXOperatorCallExpr" << std::endl;
    return true;
  }
  const std::string functionName = decl->getNameInfo().getAsString();
  if (functionName == PRINT_NAME || functionName == READ_NAME) {
    bool isFirst = false;
    if (!iofunctionStarted) {
      isFirst = true;
      iofunctionStarted = true;
    }

    rapidjson::Value arrayValue(rapidjson::kArrayType);
    for (unsigned i = 0; i < operatorCallExpr->getNumArgs(); ++i) {
      TRY_TO(TraverseStmt(operatorCallExpr->getArg(i)));
      if (i == 0) {
        // If sonValue is not an array, is because it reached the begin of
        // call, which is the cout/cerr/stream class
        if (sonValue.IsArray()) {
          arrayValue = sonValue;
        }
      }
      else {
        arrayValue.PushBack(sonValue, allocator);
      }
    }
    
    if (!isFirst) {
      sonValue = arrayValue;
    }
    else {
      iofunctionStarted = false;

      rapidjson::Value functionValue(rapidjson::kObjectType);
      addId(functionValue);
      addPos(functionValue, operatorCallExpr);
      functionValue.AddMember("type", "function-call", allocator);
      if (functionName == PRINT_NAME) 
        functionValue.AddMember("name", "print", allocator);
      else functionValue.AddMember("name", "read", allocator);
      functionValue.AddMember("arguments", arrayValue, allocator);
      sonValue = functionValue;
    }
  }
  else if (functionName == VECTOR_POS_NAME) {
    // Operator []
    TRY_TO(TraverseStmt(operatorCallExpr->getArg(0)));
    rapidjson::Value leftValue(rapidjson::kObjectType);
    leftValue = sonValue;
    TRY_TO(TraverseStmt(operatorCallExpr->getArg(1)));
    rapidjson::Value rightValue(rapidjson::kObjectType);
    rightValue = sonValue;
    sonValue = createBinOpValue("[]", leftValue, rightValue);
  }
  else {
    std::cerr << "Operator call not defined: " << functionName << std::endl;
  }
    return true;
}
	/************************************************************************
	  CMinPack minimzation:
	*************************************************************************/
	void SkeletonFitting::updateCMP(Joint* joint)
	{
		// TODO: use same minimization method also with MT_CMINPACK_CCD, just exchange the function

		if (!joint) {
			WARN << "joint invalid" << ENDL;	// should never happen
			return;
		}
		
		// TODO: implement simple steepest descent method using the same functions
		const int i = 0;
		
		// if this is the root joint, also update the position
		if (!joint->getPrevJoint()) {
			const double tol = 0.000001;
			const double factor = 0.01;
			const double eps = 0.00001;
			const int iterFac = 50;

			cv::Point3d addPos(0, 0, 0);
			double addSize = 0;
			
			if (i == 0) {
				minimize(&Payload(joint, 0), funcPos, 1, 1, &addPos.x, tol, iterFac, factor, eps);
				minimize(&Payload(joint, 1), funcPos, 1, 1, &addPos.y, tol, iterFac, factor, eps);
				minimize(&Payload(joint, 2), funcPos, 1, 1, &addPos.z, tol, iterFac, factor, eps);

				if (m_minimizeSize)
					minimize(&Payload(joint, 2), funcSize, 1, 1, &addSize, tol, iterFac, factor, eps);
			}
			else {
				/*minimizeSteepestDesc(&Payload(joint, 0), funcPos, 1, 1, &addPos.x);
				minimizeSteepestDesc(&Payload(joint, 1), funcPos, 1, 1, &addPos.y);
				minimizeSteepestDesc(&Payload(joint, 2), funcPos, 1, 1, &addPos.z);
				
				if (m_minimizeSize)
					minimizeSteepestDesc(&Payload(joint, 2), funcSize, 1, 1, &addSize);*/
			}
		
			joint->addPos3d(addPos);
			joint->addBoneSize(addSize);
			joint->updateForward(false);	// changing position doesn't need constraint checking
		}
		
		// update joint angles
		const double tol = 0.001;
		const int iterFac = 50;
		double factor = 100;
		double eps = 0.001;

		switch (joint->getClass()) {
		case JC_BALLANDSOCKET:
			{
				// update ball and socket joints
				JointBallAndSocket* jointBAS = (JointBallAndSocket*)joint;

				// update angles
				cv::Point3d addRot(0, 0, 0);
			
				if (i == 0) {
					minimize(&Payload(joint, 0), funcBAS, 1, 1, &addRot.x, tol, iterFac, factor, eps);
					minimize(&Payload(joint, 1), funcBAS, 1, 1, &addRot.y, tol, iterFac, factor, eps);
					minimize(&Payload(joint, 2), funcBAS, 1, 1, &addRot.z, tol, iterFac, factor, eps);
				}
				else {
					//minimizeSteepestDesc(&Payload(joint, 0), funcBAS, 1, 1, &addRot.x);
					//minimizeSteepestDesc(&Payload(joint, 1), funcBAS, 1, 1, &addRot.y);
					//minimizeSteepestDesc(&Payload(joint, 2), funcBAS, 1, 1, &addRot.z);
				}


				jointBAS->addOrientation(addRot);
				jointBAS->updateForward(true);

				break;
			}
		case JC_HINGE:
			{
				// update hinge joints
				JointHinge* jointHinge = (JointHinge*)joint;
				
				// update angles
				double addAngle = 0;
				
				if (i == 0) {
					minimize(&Payload(joint, 0), funcHinge, 1, 1, &addAngle, tol, iterFac, factor, eps);
				}
				else {
					//minimizeSteepestDesc(&Payload(joint, 0), funcHinge, 1, 1, &addAngle);
				}

				jointHinge->addAngle(addAngle);
				jointHinge->updateForward(true);

				break;
			}
		case JC_ENDCONNECTOR:
			// no need to update end connector joints, their position is only
			// affected by their subordinate joints
			break;
		case JC_CONNECTOR:
			// does also not need to be updated
			break;
		default:
			WARN << "unknown joint type: " << (int)joint->getClass() << ENDL;
			break;
		}
		
		// if this is not the root joint, update the next previous joint
		if (joint->getPrevJoint())
			updateCMP(joint->getPrevJoint());
	}