Beispiel #1
0
bool playGame(Affichage A, Damier *map, Snake *snake, Sound sound)
{
	int end = 0;
	bool win = FALSE;
	Position newPos = initPosition();
	Input input = initInput();
	Chrono chrono = initChrono();
	Timer timer = initTimer();
	
	
	setProiesToMap(map);
	
	drawTile(A, TILE_TITLE);
	drawTextChrono(chrono, A);
	drawMap(A, *map, newPosition(MAXCASES/2 + 3,MAXCASES/2), *snake);

	startChrono(&chrono);
	while (1)
	{
		
		setTimer(&timer);
		newPos = updatePositions(map, snake, &input);
		
		if (input.end)
			break;

		if (testPosMap(newPos))
		{
			end = addPositionSnake(map, snake, newPos, sound);
			if (end)
			{
				win = FALSE;
				break;
			}
		}
		
		setPositionsToMap(map, snake);
		drawChrono(chrono, A);
		drawMap(A, *map, newPos, *snake);
		
		if(endChrono(chrono))
		{
			win = FALSE;
			break;
		}
		
		if (endGame(map))
		{
			win = TRUE;
			break;
		}
		
		reguleFPS(&timer);
	}
	
	deleteChrono(&chrono);
	return win;
}
const uint8_t* TilesAttackGameModeManager::restoreInternalState(const uint8_t* in, int size) {
    in = GameModeManager::restoreInternalState(in, size);
    memcpy(&leavesDone, in, sizeof(leavesDone)); in += sizeof(leavesDone);

    initPosition();
    TRANSFORM(herisson)->position.x = GameModeManager::position(leavesDone);

    return in;
}
visualOdometry::visualOdometry()
{
    start_index_ = boost::lexical_cast<int>(pd_.getData("start_index"));
    end_index_ = boost::lexical_cast<int>(pd_.getData("end_index"));
    publish_trajectory_ = node_handle_.advertise<visualization_msgs::Marker>("trajectory",10);
    publish_ground_truth = node_handle_.advertise<visualization_msgs::Marker>("ground_truth",10);
    initPosition();
    mainloop();
}
int KITECH_SDM8::StartHoming(void)
{
	vector<double> initPosition(joints.size());
	vector<unsigned long> time;

	for(size_t i = 0; i < initPosition.size(); i++) {
		initPosition[i] = 0.0;
	}
	
	return SetPosition(initPosition, time);
}
Beispiel #5
0
int main(int argc, char** argv) {
    Chemin *spirale = initPosition(5,4);
    Chemin *tmp = spirale;
    while(tmp) {
        printf("(%d,%d)\n",tmp->x,tmp->y);
        tmp = tmp->Suivant;
    }
    //initPosition(5,4);
//    initPosition(7,3);
//    initPosition(3,3);
}
void BirdEye::initiation()
{
  initPosition();
  initParameters();
  flightOrigin();
  initPointcloud();

  //defining pre points for later velocity calculation
  prePoint = originPoint;
  ROS_INFO("origin at %.3f %.3f %.3f",originPoint.x,originPoint.y,originPoint.z);

}
Beispiel #7
0
void HW3b::setsize(int value)
{
    timer->stop();
    m_sliderGrid->setValue(value);
    m_spinboxGrid->setValue(value);
    grid = value+1;
//    sdepth = 5.0/4.0 * (grid+3);
//    sdepth = sdepth+0.6;
    initPoints();
    initPosition();
    initVertexBuffer();
    updateGL();
}
UBStylusPalette::UBStylusPalette(QWidget *parent, Qt::Orientation orient)
    : UBActionPalette(Qt::TopLeftCorner, parent, orient)
    , mLastSelectedId(-1)
{
    QList<QAction*> actions;

    actions << UBApplication::mainWindow->actionPen;
    actions << UBApplication::mainWindow->actionEraser;
    actions << UBApplication::mainWindow->actionMarker;
    actions << UBApplication::mainWindow->actionSelector;
    actions << UBApplication::mainWindow->actionPlay;

    actions << UBApplication::mainWindow->actionHand;
    actions << UBApplication::mainWindow->actionZoomIn;
    actions << UBApplication::mainWindow->actionZoomOut;

    actions << UBApplication::mainWindow->actionPointer;
    actions << UBApplication::mainWindow->actionLine;
    actions << UBApplication::mainWindow->actionText;
    actions << UBApplication::mainWindow->actionCapture;

    if(UBPlatformUtils::hasVirtualKeyboard())
        actions << UBApplication::mainWindow->actionVirtualKeyboard;

    setActions(actions);
    setButtonIconSize(QSize(42, 42));

    if(!UBPlatformUtils::hasVirtualKeyboard())
    {
            groupActions();
    }
    else
    {
            // VirtualKeyboard action is not in group
            // So, groupping all buttons, except last
            mButtonGroup = new QButtonGroup(this);
            for(int i=0; i < mButtons.size()-1; i++)
            {
                    mButtonGroup->addButton(mButtons[i], i);
            }
        connect(mButtonGroup, SIGNAL(buttonClicked(int)), this, SIGNAL(buttonGroupClicked(int)));
    }

    adjustSizeAndPosition();

    initPosition();

    foreach(const UBActionPaletteButton* button, mButtons)
    {
        connect(button, SIGNAL(doubleClicked()), this, SLOT(stylusToolDoubleClicked()));
    }
void TilesAttackGameModeManager::Enter() {
	time = 0;
	leavesDone = 0;
	points = 0;
	bonus =  Random::Int(0, theHeriswapGridSystem.Types-1);
	succNoGridReset=false;
	initPosition();

	generateLeaves(0, 8);

	TEXT(uiHelper.scoreProgress)->flags &= ~TextComponent::IsANumberBit;

	GameModeManager::Enter();
}
Beispiel #10
0
// Constructor
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
                       reactphysics3d::CollisionWorld* world,
                       const std::string& meshPath)
           : openglframework::Mesh(), mVBOVertices(GL_ARRAY_BUFFER),
             mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
             mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) {

    // Load the mesh from a file
    openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this);

    // Calculate the normals of the mesh
    calculateNormals();

    // Initialize the position where the sphere will be rendered
    translateWorld(position);

    // Compute the scaling matrix
    mScalingMatrix = openglframework::Matrix4::identity();


    // Vertex and Indices array for the triangle mesh (data in shared and not copied)
    mPhysicsTriangleVertexArray =
            new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3),
                                          getNbFaces(0), &(mIndices[0][0]), sizeof(int),
                                          rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
                                          rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);

    // Create the collision shape for the rigid body (convex mesh shape) and
    // do not forget to delete it at the end
    mConvexShape = new rp3d::ConvexMeshShape(mPhysicsTriangleVertexArray);

    // Initial position and orientation of the rigid body
    rp3d::Vector3 initPosition(position.x, position.y, position.z);
    rp3d::Quaternion initOrientation = rp3d::Quaternion::identity();
    rp3d::Transform transform(initPosition, initOrientation);

    mPreviousTransform = transform;

    // Create a rigid body corresponding to the sphere in the dynamics world
    mBody = world->createCollisionBody(transform);

    // Add a collision shape to the body and specify the mass of the collision shape
    mProxyShape = mBody->addCollisionShape(mConvexShape, rp3d::Transform::identity());

    // Create the VBOs and VAO
    createVBOAndVAO();

    mTransformMatrix = mTransformMatrix * mScalingMatrix;
}
Beispiel #11
0
void HW3b::mouseMoveEvent(QMouseEvent *event)
{
    if (leftButton==true) {
        
        sphi += (float)(event->x() - downX) / 4.0;
        stheta += (float)(downY - event->y()) / 4.0;
        
        downX = event->x();
        downY = event->y();
        initPosition();
        updateGL();
        
        
    }
}
Beispiel #12
0
// Constructor
Sphere::Sphere(float radius, const openglframework::Vector3 &position,
               float mass, reactphysics3d::DynamicsWorld* world,
               const std::string& meshFolderPath)
       : openglframework::Mesh(), mRadius(radius) {

    // Load the mesh from a file
    openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", *this);

    // Calculate the normals of the mesh
    calculateNormals();

    // Compute the scaling matrix
    mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0,
                                              0, mRadius, 0, 0,
                                              0, 0, mRadius, 0,
                                              0, 0, 0, 1);

    // Initialize the position where the sphere will be rendered
    translateWorld(position);

    // Create the collision shape for the rigid body (sphere shape)
    // ReactPhysics3D will clone this object to create an internal one. Therefore,
    // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape()
    mCollisionShape = new rp3d::SphereShape(mRadius);

    // Initial position and orientation of the rigid body
    rp3d::Vector3 initPosition(position.x, position.y, position.z);
    rp3d::Quaternion initOrientation = rp3d::Quaternion::identity();
    rp3d::Transform transform(initPosition, initOrientation);

    // Create a rigid body corresponding to the sphere in the dynamics world
    rp3d::RigidBody* body = world->createRigidBody(transform);

    // Add a collision shape to the body and specify the mass of the shape
    mProxyShape = body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass);

    mBody = body;

    mTransformMatrix = mTransformMatrix * mScalingMatrix;

    // Create the VBOs and VAO
    if (totalNbSpheres == 0) {
        createVBOAndVAO();
    }

    totalNbSpheres++;
}
Beispiel #13
0
// Constructor
Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& position,
           float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
                   const std::string& meshFolderPath)
     : openglframework::Mesh(), mRadius(radius), mHeight(height) {

    // Load the mesh from a file
    openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cylinder.obj", *this);

    // Calculate the normals of the mesh
    calculateNormals();

    // Compute the scaling matrix
    mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0,
                                              0, mHeight, 0, 0,
                                              0, 0, mRadius, 0,
                                              0, 0, 0, 1);

    // Initialize the position where the cylinder will be rendered
    translateWorld(position);

    // Create the collision shape for the rigid body (cylinder shape) and do
    // not forget to delete it at the end
    mCylinderShape = new rp3d::CylinderShape(mRadius, mHeight);

    // Initial position and orientation of the rigid body
    rp3d::Vector3 initPosition(position.x, position.y, position.z);
    rp3d::Quaternion initOrientation = rp3d::Quaternion::identity();
    rp3d::Transform transform(initPosition, initOrientation);

    // Create a rigid body corresponding to the cylinder in the dynamics world
    rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);

    // Add a collision shape to the body and specify the mass of the shape
    mProxyShape = body->addCollisionShape(mCylinderShape, rp3d::Transform::identity(), mass);

    mTransformMatrix = mTransformMatrix * mScalingMatrix;

    mBody = body;

    // Create the VBOs and VAO
    if (totalNbCylinders == 0) {
        createVBOAndVAO();
    }

    totalNbCylinders++;
}
Beispiel #14
0
bool GameLayer::init() {
	if (CCLayer::init()) {
		LOCAL_CONTEXT->clearScore();

		this->setTouchMode(kCCTouchesOneByOne);
		this->setTouchEnabled(true);
		this->scheduleUpdate();
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		this->ignoreAnchorPointForPosition(true);
		setAnchorPoint(ccp(0.5f, 0.5f));
		this->setContentSize(s);
		setPosition(ccp(s.width / 2, s.height / 2));
		LOCAL_CONTEXT->playBgMusic();
		/*-- 计分 --*/
		CCLabelBMFont *score=CCLabelBMFont::create(CCString::createWithFormat("%d", LOCAL_CONTEXT->getScore())->getCString(),"score_font.fnt");
		//CCLabelTTF *score = CCLabelTTF::create(CCString::createWithFormat("%d", LOCAL_CONTEXT->getScore())->getCString(),LOCAL_RESOURCES->valueByKey("font")->getCString(),LOCAL_RESOURCES->valueByKey("font_size")->floatValue());
		//score->setColor(LOCAL_CONTEXT->getFontColor());
		score->setAnchorPoint(ccp(1, 0.5));
		score->setPosition(ccpp(0.45,0.42));
		this->addChild(score,0,TAG_SCORE);

		/*-- 倒计时 --*/
		CCSprite *timeBack = CCSprite::create("time_back.png");
		timeBack->setAnchorPoint(ccp(0.5,0.5));
		timeBack->setPosition(ccpp(0,0.32));
		this->addChild(timeBack);
		timer->setAnchorPoint(ccp(0.5,0.5));
		timer->setPosition(ccp(timeBack->getContentSize().width/2,timeBack->getContentSize().height/2));
		timer->setTarget(this,callfunc_selector(GameLayer::gameover));
		timeBack->addChild(timer);

		/*-- 放瓶子 --*/
		initPosition();

		if (LOCAL_CONTEXT->isFirstRun()) {
			this->createHelpLayer();
		} else {
			timer->start();
		}
		return true;

	} else {
		return false;
	}
}
void MissionMenu::makeMenu()
{
    option.clear();
    option.reserve(missions.size());
    for(unsigned int i=0;i<missions.size();i++){
        std::string s = "Mission "+missions.getMissionName(i)+(missions.getMissionState(i)?"":" (locked) ");
        Button button;
        button.txt = sf::Text(s,*FontManager::getFont("ressources/Symtext.ttf"),32);
        button.f = static_cast<void (Menu::*)()>(&MissionMenu::startMission);
        option.push_back(button);
    }

    option.resize(option.size()+1);
    option.back().txt = sf::Text("Return to main menu",*FontManager::getFont("ressources/Symtext.ttf"),32);
    option.back().f = &Menu::exit;

    initPosition();
}
Beispiel #16
0
void HW3b::reset (){
    
    timer->stop();
    waving = false;
    grid = 17;
    dt=0.006;
//    displayMode = TEX_WIRE;
//    resetMode = HILLFOUR;
    sphi=45.0;stheta=45.0;
    sdepth = 1.5;
    m_comboBox->setCurrentIndex(displayMode);
    m_comboBox_mode->setCurrentIndex(resetMode);
    m_spinboxSpeed->setValue(6);
    m_sliderSpeed->setValue(6);
    m_spinboxGrid->setValue(16);
    m_sliderGrid->setValue(16);
    initPosition();
    initPoints();
    initVertexBuffer();
    
 
    updateGL();
}
Beispiel #17
0
Client::Client( WindowSystem* windowsystem, Window w, bool viewable,
		int wx, int wy, int wwidth, int wheight,
		long wcolormap )
    : ws(windowsystem)
{
    assert(ws);
    ws->transientForHint( w, &trans );
    nm = ws->windowName( w );
    window = w;
    ignore_unmap = 0;
    x = wx;
    y = wy;
    width = wwidth;
    height = wheight;
    cmap = wcolormap;
    size = ws->allocSizeHints();
    active = false;
    awaiting_close = false;
    awaiting_iconize = false;

    long dummy;
    ws->windowNormalHints( window, size, &dummy );

    if ( viewable ) {
	ignore_unmap++;
    } else {
	initPosition();
	ws->setState(window, NormalState);
	// consolidate
	XWMHints *hints;
	if ((hints = ws->windowHints(w))) {
	    if (hints->flags & StateHint) 
		ws->setState(window, hints->initial_state);
	    ws->xFree(hints);
	}
    }

    gravitate( APPLY_GRAVITY );

    frame = ws->createFrame( x-1, y - titleHeight(), 
			     width + 2,  // 1 pixel border, each side
			     height + titleHeight() + 1 ); // 1 pixel border, top
    button_size = titleHeight() - 2;
    titlebar_width = width - 2*button_size;

    close_button = ws->createWindow( 0,0, button_size, button_size );
    iconize_button = ws->createWindow( 0,0, button_size, button_size );
    titlebar = ws->createWindow( 0,0, titlebar_width, button_size );

    ws->addToSaveSet( window );
    ws->selectInput( window, ColormapChangeMask|PropertyChangeMask);
    ws->grabButtons( window );
    ws->setBorderWidth( window, 0);
    ws->resize( window, width, height); //db more needed?

    ws->reparent( close_button, frame, width + 1 - button_size, 1 );
    ws->reparent( iconize_button, frame, 1, 1 );
    ws->reparent( titlebar, frame, button_size + 1, 1 );
    ws->reparent( window, frame, 1, titleHeight()); // for 1 pixel border
    configure();

    // db more fix: initial iconized windows
    if ( viewable ) {
	if ( ws->getState(window) == IconicState ) {
	    ignore_unmap++;
	    ws->unmap( window );
	} else {
	    mapRaised();
	}
    } else {
	if ( ws->getState(window) == NormalState ) {
	    ws->map( window );
	    ws->map( close_button );
	    ws->map( iconize_button );
	    ws->map( titlebar );
	    ws->mapRaised( frame );
	}
    }
    redraw( false, true );
    
}
Beispiel #18
0
void xboardLoop(Position *pos) {
	int version = 1;
	int player = 2; //don't make moves
	setbuf(stdout, NULL);
	while (1) {
		char *line;
		char *word;
		line = readLine();
		word = strtok(line, " ");
		if (strcmp(word, "xboard") == 0) {
			; //no action required
		} else if (strcmp(word, "protover") == 0) {
			int i;
			word = strtok(NULL, " ");
			version = atol(word);
			for (i = 0; i < n_features; ++i) {
				if (features[i].s_value) {
					printf("feature %s=\"%s\"\n", features[i].name, features[i].s_value);
				} else {
					printf("feature %s=%d\n", features[i].name, features[i].i_value);
				}
			}
			printf("feature done=1\n");
		} else if (strcmp(word, "accepted") == 0) {
			int i;
			word = strtok(NULL, " ");
			for (i = 0; i < n_features; ++i) {
				if (strcmp(word, features[i].name) == 0) {
					features[i].accepted = 1;
				}
			}
		} else if (strcmp(word, "rejected") == 0) {
			int i;
			word = strtok(NULL, " ");
			for (i = 0; i < n_features; ++i) {
				if (strcmp(word, features[i].name) == 0) {
					features[i].accepted = 0;
				}
			}
		} else if (strcmp(word, "new") == 0) {
			initPosition(pos);
			player = 1;
		} else if (strcmp(word, "variant") == 0) {
			//uh oh, variants not supported yet
			exit(1);
		} else if (strcmp(word, "quit") == 0) {
			exit(0);
		} else if (strcmp(word, "random") == 0) {
			;//not supported, nop for the time being
		} else if (strcmp(word, "force") == 0) {
			player = 2; //no player
		} else if (strcmp(word, "go") == 0) {
			player = pos->ply % 2;
		} else if (strcmp(word, "playother") == 0) {
			player = 1 - (pos->ply % 2);
		} else if (strcmp(word, "level") == 0) {
			//TODO: add time controls
			;
		} else if (strcmp(word, "st") == 0) {
			;
		} else if (strcmp(word, "sd") == 0) {
			//TODO: set depth
			;
		} else {
			int move;
			move = fromAlg(pos, word);
			if (move < -1) {
				printf("Illegal move: %s\n", word);
			} else if (move > 0) {
				makeMove(pos, move);
			}
		}
		if (player == pos->ply % 2) {
			char moveStr[21];
			int move, score;
			move = moveSearch(pos, SEARCH_DEPTH, &score);
			toAlg(pos, move, moveStr);
			makeMove(pos, move);
			printf("move %s\n", moveStr);
		}
	}
}
Beispiel #19
0
int main(){

	
	srand(time(NULL));
	
	int encore=0;
	int choixmodif=2;
	int choixaffich=0;
	int affichH=0;
	int action=0;
	
	int nbCell=0;
	int iteration=0, iMax=0;
	int ageMature=0, ageMax=0;
	float beta=0, delta=0;
	CELLULE* P[taille][taille];
	initMat(P);
	bordure(P);
	H* matH=Allouematrice();
	
	printf("Ce programme permet de modéliser l'évolution d'une culture cellulaire.\nIl prend en compte l'âge de maturité des cellules, c'est à dire l'âge à partir duquel les cellules peuvent se diviser.\nLe programme gère également l'espérance de vie des cellules et le nombre initial de cellules en culture.\nLe nombre d'itérations est à relier au temps nécessaire à une cellule pour se diviser.\nLors d'une itération, la cellule peut également se transformer en cellule cancéreuse, mourir.\n\n");
	
	do{
		printf("Souhaitez vous utiliser les paramètres par défaut:\nAge de maturité=3\nAge maximum=1001\nNombre de cellules initiales=100\nNombre maximal d'itérations=1000\nbeta=0.5\ndelta=0.8\n\n[1]Oui [2]Non\n");
		do{
			scanf("%d", &choixmodif);
			if(choixmodif==1){
				ageMature=3;
				ageMax= 1001;
				nbCell= 100;
				iMax= 1000;
				beta= 0.5;
				delta= 0.8;
			}else if(choixmodif==2){
				printf("Age de maturité (par défaut 3): "); scanf("%d", &ageMature);
				printf("Age maximum (par défaut 1001): "); scanf("%d", &ageMax);
				printf("Nombre de cellules initiales (par défaut 100): "); scanf("%d", &nbCell);
				printf("Nombre maximal d'itérations (par défaut 1000): "); scanf("%d", &iMax);
				printf("beta (par défaut 0.5): "); scanf("%f", &beta);
				printf("delta (par défaut 0.8): "); scanf("%f", &delta);
	 		 }else printf("Erreur de saisie...\nLes choix sont:\n[1]paramètres par défault\n[2]Modifier les paramètres\n");
	 	}while(choixmodif!=1 && choixmodif!=2);
		do{
			initPosition(nbCell, P, matH, iteration);
			chgmtType(beta, ageMax, P, matH, iteration);
			comptVoisines(P);
			printf("\nVoici la disposition des cellules à l'état initial (avant la première itération)\n");
			afficheMat(P, iteration);
			printf("\n");
			
			do{
				printf("Souhaitez-vous afficher l'état de la matrice à chaque itération? [1]Oui [2]Non\n");
				scanf("%d", &choixaffich);
				if(choixaffich!=1 && choixaffich!=2) printf("Erreur de saisie...\n");
			}while(choixaffich!=1 && choixaffich!=2);
		
			while(iteration<iMax)
			{
				iteration++;
				incrementeAge(ageMax, P, matH, iteration);
				
				tuer_f_nbVoisines(P, matH, iteration);
				tuer_f_Cancer(delta, P, matH, iteration);
				chgmtType(beta, ageMax, P, matH, iteration);
			
				divisions(ageMature, P, matH, iteration);

				comptVoisines(P);
				if(choixaffich==1){
					afficheMat(P, iteration);
					printf("\n");
				}
			 
			}			
			sauvegarde(matH);
			printf("Un fichier contenant l'historique de la matrice vient d'être créé.\nIl se trouve dans le répertertoire du programme principal.\n");
		
			printf("\nVoici l'état de la culture cellulaire à la fin de toutes les itérations.\n");
			afficheMat(P, iteration);
			printf("\n");
	
			do{
				printf("Souhaitez-vous afficher l'histoire d'une cellule? [1]Oui [2]Non\n");
				scanf("%d", &affichH);
				if(affichH!=1 && affichH!=2) printf("Erreur de saisie...\n");
			}while(affichH!=1 && affichH!=2);
			if(affichH==1) affichelistHCase(matH);
			
			do{
				printf("Souhaitez-vous relancer la modélisation en concervant ces paramètres? [1]Oui [2]Non\n");
				scanf("%d", &encore);
				if(encore!=1 && encore!=2) printf("Erreur de saisie...\n");
			}while(encore!=1 && encore!=2);
		}while(encore==1);
		
		do{
			printf("Souhaitez-vous [1]relancer une modélisation [2]quitter le programme ?\n");
			scanf("%d", &action);
			if(action!=1 && action!=2) printf("Erreur de saisie...\n");
		}while(action!=1 && action!=2);
	 }while(action==1);

printf("Au revoir.\n");
return 0;
}