コード例 #1
0
ファイル: game.c プロジェクト: ukarroum/pong-allegro
void loopMenu()
{
    int fin = 1;
    while(fin)
    {
        ALLEGRO_EVENT event = {0};

        al_wait_for_event(queue, &event);

        switch(event.type) {
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                fin = 0;
                break;
            case ALLEGRO_EVENT_KEY_DOWN:
                if (event.keyboard.keycode == ALLEGRO_KEY_1) {
                    mode = SOLO;
                    fin = 0;
                    drawWorld();
                    lunchBall();
                }
                else if (event.keyboard.keycode == ALLEGRO_KEY_2) {
                    mode = MULTI;
                    fin = 0;
                    drawWorld();
                    lunchBall();
                }
                break;
        }
    }
}
コード例 #2
0
ファイル: Viewport.cpp プロジェクト: ldematte/beppe
long Viewport::onPaint(FXObject*,FXSelector,void*)
{
	//---------------- inizializzo la finestra per il paint ------------
	makeCurrent();
		
	w = getWidth();
	h = getHeight();
	glViewport(0, 0, w, h);

	// pulisco lo schermo
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (reproject)
	{
		prepareProjection();
		Pick.Reshape();
		reproject = false;
	}
	prepareModelView();

	//------------------------- disegna il mondo -----------------------
	drawWorld();

	//---------------------------- finalizza... ------------------------	

	glFlush();
	swapBuffers();
	makeNonCurrent();	

	return 1;
}
コード例 #3
0
ファイル: main.c プロジェクト: achellies/WaveSimulation
void draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    drawWorld(scene->world);
    drawWater(scene->water);
}
コード例 #4
0
ファイル: KinectV2.cpp プロジェクト: SuiOni/ofxRulr
			//----------
			void KinectV2::drawObject() {
				if (this->device) {
					switch (this->viewType.get()) { // don't break on the cases, flow through
					case 2:
						//this should be something like 'draw pretty mesh'
						//something seems to have been missed out of a merge in ofxKinectForWindows2
						this->device->drawWorld();
					case 1:
					{
						auto bodySource = this->device->getBodySource();
						if (bodySource) {
							bodySource->drawWorld();
						}
					}
					case 0:
					{
						ofPushStyle();
						ofSetColor(this->getColor());
						ofNoFill();
						ofSetLineWidth(1.0f);
						auto depthSource = this->device->getDepthSource();
						if (depthSource) {
							depthSource->drawFrustum();
						}
						auto colorSource = this->device->getColorSource();
						if (colorSource) {
							colorSource->drawFrustum();
						}
						ofPopStyle();
					}
					default:
						break;
					}
				}
			}
コード例 #5
0
ファイル: view.c プロジェクト: LokiW/Gnomish
void display (void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    player cur = getPlayer();

    //Camera is always centered on the player
    gluLookAt(cur.x, cur.y, 0.0, cur.x, cur.y, -5.0, 0.0, 1.0, 0.0);

    //Draw in world
    drawWorld();

    //Move brush to player location
    glTranslatef(cur.x, cur.y, Y_VAL);
    glRotatef((cur.angle*360)/(2*M_PI),0.0,0.0,1.0);

    //Draw player
    glBegin(GL_TRIANGLES);
    glColor3f(1.0,0.0,0.0);
    glVertex3f(-0.4,0.2,Y_VAL);
    glVertex3f(0.2,0.0,Y_VAL);
    glVertex3f(-0.4,-0.2,Y_VAL);
    glEnd();
    glFlush();          //Finish rendering
}
コード例 #6
0
		//----------
		void NodeThroughView::drawOnVideoOutput(const ofRectangle & viewBounds) {
			auto node = this->getInput<Node>();
			auto view = this->getInput<Item::View>();

			if (node && view) {
				view->getViewInWorldSpace().beginAsCamera(true);
				node->drawWorld();
				view->getViewInWorldSpace().endAsCamera();
			}
		}
コード例 #7
0
ファイル: Visual.cpp プロジェクト: desmondw/alife
void Visual::drawGraphics(sf::RenderWindow& mainWindow, World& world)
{
	//mainWindow.Clear(sf::Color(50, 50, 50, 255)); //clear screen
	mainWindow.Clear(sf::Color::Black);

	drawWorld(mainWindow, world);
	textDisplay(mainWindow);

    mainWindow.Display(); //draw screen
}
コード例 #8
0
ファイル: Main.c プロジェクト: kursion/glThunderhawk
// Fonction d'affichage avec gestion mode
void display(void)
{


    // Suppression du buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Dessin des lumières
    if(iLight == 0){
        glDisable(GL_LIGHTING);	// Désactive l'éclairage
        glDisable(GL_LIGHT0); // Désactive la lumière 1
    }else{
        glEnable(GL_LIGHTING);	// Active l'éclairage
        glEnable(GL_LIGHT0);	// Active la lumière 1
        setLights();

    }

    // Mode solide ou file de fer
    if(iMode == 1)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    }
    else if(iMode == 0)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }

    // Gl Texture 2D
    if(iTexture){ glEnable(GL_TEXTURE_2D); }
    else{ glDisable(GL_TEXTURE_2D); }

    // Dessin du monde avec ses éléments
    drawWorld();


    // Affichage des erreurs
    if(glGetError()){
        int iGL_Error = glGetError();
        if(iGL_Error == 1282)
        {
            printf("Window close by user !");
            close();
            exit(0);
        }
        else if(iGL_Error != 0)
        {
            printf("Erreur OpenGL:%s\n",gluErrorString(glGetError()));
        }
    }


    glutSwapBuffers();
}
コード例 #9
0
ファイル: cube.c プロジェクト: pombredanne/anacrolix
static void display ()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    setProjection();
    setViewPoint();
    drawWorld();

    /* Check everything OK and update screen */
    CheckGL();
    glutSwapBuffers();
}
コード例 #10
0
ファイル: viewing.cpp プロジェクト: kbailo/487
/* Draw the cube with the latest transformations */
void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  drawWorld(mode, screen_w, screen_h);

  /* Force display */
  glutSwapBuffers();

  return;
}
コード例 #11
0
ファイル: MapperGui.cpp プロジェクト: hoodwolf/Infraelly
void MapperGui::prepareWorldImage(){
    /**************************************
            Make sure the Cache exists
            and is still relevent
    ***************************************/
    //  check if the map has been edited since last drawn
    //  if so, regen layer images
    if( mapTouched ){
        //  check if there a no world
        if( world != NULL ){
            //  check if layers are initialised
            if( !world->empty() ){
                Layer& workingLayer = world->getLayer(layerToggleBox->getWorkingLayer());
                //  check if the worldImage exists and is coherrent
                if( worldImage == NULL ){
                    //  there is no world image, create one
                    worldImage = createSurface(
                                 workingLayer.getWidth()*
                                 workingLayer.getTileWidth(),
                                 workingLayer.getHeight()*
                                 workingLayer.getTileHeight(),
                                 graphics->getTarget()->format->BitsPerPixel,
                                 SDL_SWSURFACE );
                } else
                //  a world image exists, but it is the wrong dimensions
                if ( ( worldImage->w != workingLayer.getWidth()*
                                        workingLayer.getTileWidth() ) ||
                     ( worldImage->h != workingLayer.getHeight()*
                                        workingLayer.getTileHeight() )   )
                {
                    //free old image
                    SDL_FreeSurface(worldImage);
                    //creaet new one of correct dimensions
                    worldImage = createSurface(
                                workingLayer.getWidth()*
                                workingLayer.getTileWidth(),
                                workingLayer.getHeight()*
                                workingLayer.getTileHeight(),
                                graphics->getTarget()->format->BitsPerPixel,
                                SDL_SWSURFACE );
                }
                //match the dimensions of the world image and the PlaceHolder
                worldImagePlaceHolder->setWidth( worldImage->w );
                worldImagePlaceHolder->setHeight( worldImage->h );

                //now that worldImage is properly initialised, draw the world onto it
                drawWorld();
            }   // end layers exists
        }// end if world exists
        mapTouched = 0;
    }// end if touched
}
コード例 #12
0
ファイル: relative.cpp プロジェクト: svddries/image_creator
void drawWorldModelAbsolute(Canvas& canvas, const WorldModel2D& wm, const geo::Vec2& p0)
{
    drawWorld(canvas, wm);

    for(unsigned int i = 1; i < wm.entities.size(); ++i)
    {
        const Entity2D& e = wm.entities[i];
        drawArrow(canvas, p0, e.pose.t, Color(150, 150, 150, 2));
        drawAxis(canvas, e.pose);
    }

    drawAxis(canvas, fromXYA(p0.x, p0.y, 0));
}
コード例 #13
0
ファイル: lighting.cpp プロジェクト: kbailo/487
/* Draw the world with the latest transformations */
void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glGetDoublev(GL_TEXTURE_MATRIX, cmodview);
  setup_view();
  drawAxes(screen_w, screen_h, 1.0);  // draw world axes in eye space
  glMultMatrixd(cmodview);
  drawWorld(screen_w, screen_h);

  /* Force display */
  glutSwapBuffers();

  return;
}
コード例 #14
0
ファイル: View.cpp プロジェクト: ggobbe/pacman-3d
// Définit le modèle pour affichage à l'écran
void View::display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Initialisation du buffer de couleur à la couleur de fond


	// Viewport contenant les informations sur la partie en cours
	viewportInfos();
	if(model->getLifes() < 0) {
		model->stopGame();
		gameOver();
	}
	else {
		drawScore();
		drawLifes();
	}

	// Viewport contenant les contrôles souris (boutons)
	viewportControls();
	drawMouseControls();
	drawButton("Reset",100);
	drawButton("Close",150);
	drawButton("View", 200);



	// Viewport contenant le plateau de jeu
	glEnable(GL_DEPTH_TEST);

	initLights();

	viewportWorld(); // Définit une viewport et ses caractéristiques de projection
	drawWorld();
	drawPills();
	drawPacMan();
	drawGhosts();

	glDisable(GL_LIGHT0);
	glDisable(GL_LIGHT1);
	glDisable(GL_LIGHT2);
	glDisable(GL_LIGHT3);
	glDisable(GL_LIGHTING);	// nuit !
	glDisable(GL_DEPTH_TEST);


	glutSwapBuffers(); // Car on travaille en mode "double buffer", cf. main.cpp
}
コード例 #15
0
void display(void)
{
	//mydisplay();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	camera();
	glRotatef(-angleZ, 0.0f, 0.0f, 1.0f);
	glRotatef(-angleY, 1.0f, 0.0f, 0.0f);
	glRotatef(-_angleX, 0.0f, 1.0f, 0.0f);
	glTranslatef(McamX, 0, McamY);
	initilizeTexture(image1);
	drawTerrain();
	//Write your code here
	initilizeTexture(image2);
	drawLand();
	initilizeTexture(image3);
	drawWorld();
	glutSwapBuffers();
}
コード例 #16
0
ファイル: relative.cpp プロジェクト: svddries/image_creator
void drawWorldModelSceneGraph(Canvas& canvas, const WorldModel2D& wm, const std::vector<Link>& links)
{
    drawWorld(canvas, wm);

    for(unsigned int i = 0; i < links.size(); ++i)
    {
        const Link& link = links[i];

        const Entity2D& e1 = wm.entities[link.i1];
        const Entity2D& e2 = wm.entities[link.i2];

        drawArrow(canvas, e1.pose.t, e2.pose.t, Color(150, 150, 150, 2));

        drawAxis(canvas, e1.pose);
        drawAxis(canvas, e2.pose);
    }

//    drawAxis(canvas, fromXYA(p0.x, p0.y, 0));
}
コード例 #17
0
ファイル: main.cpp プロジェクト: drumsetmonkey/voxel
static void render(SDL_Window* window) {
	cameraRot.x = sinf(angle.x) * cosf(angle.y);
	cameraRot.y = sinf(angle.y);
	cameraRot.z = cosf(angle.x) * cosf(angle.y);

	glm::mat4 view = glm::lookAt(cameraPos, cameraPos+cameraRot, glm::vec3(0.0f, 1.0f, 0.0f));
	glm::mat4 projection = glm::perspective(45.0f, 1.0f*(screen.x / screen.y), 0.01f, 2048.0f);
	//glm::mat4 projection = glm::ortho(0,screen.x,0,screen.y,0.01f, 2048.0f);

	glm::mat4 mvp = projection * view;
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));
	
	// draw the blocks in the world
	drawWorld(mvp, view, projection);

	// draw text in the world
	drawText(mvp, view, projection);

	SDL_GL_SwapWindow(window);
}
コード例 #18
0
ファイル: game.c プロジェクト: ukarroum/pong-allegro
void loopGame()
{
    bool fin = true;
    bool key[KEY_MAX]={0};

    while(fin) {
        ALLEGRO_EVENT event = {0};

        al_wait_for_event(queue, &event);

        switch (event.type) {
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                fin = false;
                break;
            case ALLEGRO_EVENT_KEY_DOWN:
                switch (event.keyboard.keycode) {
                    case ALLEGRO_KEY_UP:
                        key[KEY_UP] = true;
                        break;
                    case ALLEGRO_KEY_DOWN:
                        key[KEY_DOWN] = true;
                        break;
                    case ALLEGRO_KEY_A:
                        key[KEY_A] = true;
                        break;
                    case ALLEGRO_KEY_Q:
                        key[KEY_Q] = true;
                        break;
                }
                break;
            case ALLEGRO_EVENT_KEY_UP:
                switch (event.keyboard.keycode) {
                    case ALLEGRO_KEY_UP:
                        key[KEY_UP] = false;
                        break;
                    case ALLEGRO_KEY_DOWN:
                        key[KEY_DOWN] = false;
                        break;
                    case ALLEGRO_KEY_A:
                        key[KEY_A] = false;
                        break;
                    case ALLEGRO_KEY_Q:
                        key[KEY_Q] = false;
                        break;
                }
                break;
            case ALLEGRO_EVENT_TIMER:
                player1.y -= key[KEY_UP] * 10;
                player1.y += key[KEY_DOWN] * 10;
                if(mode == MULTI)
                {
                    player2.y -= key[KEY_A] * 10;
                    player2.y += key[KEY_Q] * 10;
                }
                ball.x += ball.dx;
                ball.y += ball.dy;
                if(mode == SOLO)
                    playComputer();
                if(al_is_event_queue_empty(queue))
                    drawWorld();
                break;
        }
    }
}
コード例 #19
0
ファイル: itd.c プロジェクト: ACCITD/ITD
int main(int argc,  char* argv[]) {
	int width = 1024, height = 768;
	if(argc == 5 && strcmp(argv[2], "-r") == 0 ){
		width = atoi(argv[3]);
		height = atoi(argv[4]);
	}
	else if(argc == 4 && strcmp(argv[1], "-r") == 0 ){
		width = atoi(argv[2]);
		height = atoi(argv[3]);	
	}
	
	/*Initialisation SDL, OpenGL etc */
	if( initWindow(width, height) == EXIT_FAILURE){
		perror("Impossible d'initialiser la fenêtre SDL, le programme va fermer.\n");
		exit(-1);
	}

	/* initialisation de SDL_TTF*/
	if(TTF_Init()== -1){
		printf("Error loading TTF: %s\n",TTF_GetError());
		exit(1);
	}
	bool askedForQuit = false;
	World world;
	world.towersList = NULL;
	world.map.name = NULL;
	world.map.tabXYConstruct = NULL;
	world.map.image = NULL;
	world.map.pathNodeList = NULL;
	Interface interface;
	interface.lstButtons = NULL;
	char* mapName= NULL;
	BUTTON_OF_MENU.lstMapName = NULL;
	BUTTON_OF_MENU.lstMapButton = NULL;
	BUTTON_OF_MENU.lstMapTextureIndex = NULL;
	bool play = false;
	
	List* lstMaps = createEmptyList();
	readDirectory(lstMaps);
	/* selection d'une carte en ligne de commande*/
	if (argc >= 2 && strcmp(argv[1], "-r") != 0){
		char* curMap = NULL;
		while( (curMap = (char*) nextData(lstMaps)) != NULL){
			if (strcmp(argv[1],curMap)==0){
				mapName = (char*) malloc(strlen(argv[1])*sizeof(char));
				if(mapName == NULL){
					fprintf(stderr, "Erreur fatale : impossible d'allouer la mémoire nécessaire.\n");
					exit(EXIT_FAILURE);
				}
				strcpy(mapName,argv[1]);
				play = true;
				break;	
			}	

		}
		if(! play) fprintf(stderr, "Erreur le nom donné en paramètre ne correspond à aucun fichier map\n");
		
	}
	freeListComplete(lstMaps);
	
/*-------------- GESTION DU MENU --------------------*/
do{

	interface.lstButtons = NULL;

	/* chargement des polices */
	int playIsPush = 0;
	int menuOpen = 0;
	int aideOpen = 0;
	initMenuGraphics();


	/* ouverture du répertoire data */

	while(!play && askedForQuit == false) {
		/* Récupération du temps au début de la boucle */
		Uint32 startTime = SDL_GetTicks();

		/* Placer ici le code de dessin du menu */		
		drawMenu(&menuOpen,&aideOpen,&playIsPush,mapName);

		/* Echange du front et du back buffer : mise à jour de la fenêtre */
		SDL_GL_SwapBuffers();

		/* Renvoie une chaine de caractère contenant le nom
		du fichier ITD choisi par l'utilisateur ou NULL si rien n'a encore été choisi */
		askedForQuit = handleMenuActions(&mapName,&playIsPush, &menuOpen,&aideOpen);

		if(playIsPush == 2) play = true;
		
		/* Calcul du temps écoulé */
		Uint32 elapsedTime = SDL_GetTicks() - startTime;
		/* Si trop peu de temps s'est écoulé, on met en pause le programme */
		if(elapsedTime < FRAMERATE_MILLISECONDS) {
			SDL_Delay(FRAMERATE_MILLISECONDS - elapsedTime);
		}

	}
	

/*-------------- GESTION DU JEU --------------------*/
	bool gameFinished = false;
	//Surtout à appeler APRES avoir initialisé la SDL
	char mapPath[50] = "data/";
	
	
	float width = .15;//10% de largeur
	float height = 1.; //Toute la hauteur
	float positionX = 0.85; //A 90% de la largeur
	float positionY = .0; //A 100% de la hauter
	
	if(!askedForQuit){
		strcat(mapPath, mapName);
		world = initWorld(mapPath);
		initGameGraphics();
		GAME_TEXTURES_ID.MAP_ID = makeTextureFromSurface(world.map.image);

		//Initialisation interface
		interface = initGameInterface(width, height, positionX, positionY);
	
		startWorld(&world);
	}
	while(!gameFinished && !askedForQuit) {
		/* Récupération du temps au début de la boucle */
		Uint32 startTime = SDL_GetTicks();
		
		/* On tente un nouveau cycle de tours de jeu si besoin. Le temps est 
		 géré par la fonction. La plupart du temps plusieurs tours de jeu sont
		 joués d'affilé. */
		worldNewStep(&world);
		

		drawWorld(&world);
		drawInterface(&interface, &world);
		/* Calcul du temps écoulé, si temps < 10 ms, on ne passe pas 
		au tour suivant.
		 */
		Uint32 elapsedTime = SDL_GetTicks() - startTime;
		/* Si trop peu de temps s'est écoulé, on ne dessine rien. */
		if(elapsedTime < FRAMERATE_MILLISECONDS) {

			 /* Echange du front et du back buffer : mise à jour de la fenêtre */
			SDL_GL_SwapBuffers();
      			SDL_Delay(FRAMERATE_MILLISECONDS - elapsedTime);
    			
		}
		
		/* Boucle traitant les evenements */
		askedForQuit = handleGameActions(&world, &interface, &gameFinished);
	}
	play = false;
	mapName = NULL;
	
	cleanWorld(&world);
	cleanInterface(&interface);
	
}while(! askedForQuit);
	/* Liberation des ressources */ 
	cleanExit(&world, &interface);

	return EXIT_SUCCESS;
}
コード例 #20
0
ファイル: SceneManager.cpp プロジェクト: HariSeldon/Domino
// -----------------------------------------------------------------------------
inline void SceneManager::screenRenderingPass() {
  glm::mat4 modelView = m_camera->applyView();
  drawWorld(modelView, glm::vec3(m_camera->getPosition()));
  drawText();
}
コード例 #21
0
void lrfExample(ImageWriter& iw)
{
    iw.setLabel("lrf-example");

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    WorldModel2D wm;

//    wm.addEntity(createBox(geo::Vec2(), geo::Vec2()));

    wm.addEntity(createBox(7.63, 4.09, true), fromXYADegrees(0.085, 0.065, 0));
    wm.addEntity(createBox(0.691667, 1.45833), fromXYADegrees(-0.529166, 0.404165, 0));
    wm.addEntity(createBox(0.45833, 0.6), fromXYADegrees(-1.69583, 0.375, 0));
    wm.addEntity(createBox(0.95833, 0.516667), fromXYADegrees(-1.72917, -0.616667, 0));
    wm.addEntity(createBox(0.96666, 0.50833), fromXYADegrees(-1.75, 1.37084, 0));
    wm.addEntity(createBox(1.6, 0.30834), fromXYADegrees(-0.45, -1.8375, 0));
    wm.addEntity(createBox(0.65, 0.95), fromXYADegrees(1.6, 0.4, 0));
    wm.addEntity(createBox(0.55, 1.28333), fromXYADegrees(3.54167, 0.558333, 0));

    wm.addEntity(createCircle(0.1), fromXYA(0.358333, 1.81667, 0));
    wm.addEntity(createCircle(0.1), fromXYA(-1.73333, -1.78333, 0));
    wm.addEntity(createCircle(0.1), fromXYA(3.18333, 1.68333, 0));

    Model2D model;
    Contour2D& c = model.addContour();
    c.addPoint(-3.73333 + 3.3, -1 + 1.6);
    c.addPoint(-3.15 + 3.3, -1 + 1.6);
    c.addPoint(-3.15 + 3.3, -1.46 + 1.6);
    c.addPoint(-2.36 + 3.3, -1.46 + 1.6);
    c.addPoint(-2.36 + 3.3, -1.97 + 1.6);
    c.addPoint(-3.73333 + 3.3, -1.97 + 1.6);

    wm.addEntity(model, fromXYADegrees(-3.3, -1.6, 0));


//    wm.addEntity(createBox(geo::Vec2(0, -4), geo::Vec2(8, 0), true), fromXYA(-4, 2, 0)); // 0
//    wm.addEntity(createBox(1.6, 0.8), fromXYA(2, -1, 0));      // 1  table
//    wm.addEntity(createCircle(0.1), fromXYA(2.6, -0.8, 0));    // 2  small object
//    wm.addEntity(createCircle(0.5), fromXYA(-3.2, -1.2, 0));   // 3
//    wm.addEntity(createCircle(0.3), fromXYA(-2.2, -1.4, 0));   // 4
//    wm.addEntity(createCircle(0.3), fromXYA(3.3, 1.0, 0));     // 5

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    geo::LaserRangeFinder lrf;
    lrf.setNumBeams(50);
    lrf.setAngleLimits(-1.0, 1.0);
    lrf.setRangeLimits(0, 10);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Draw world model without extra object

    Canvas canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom.jpg", 0.9);

    iw.setLabel("livingroom");
    iw.process(canvas);

    iw.setLabel("lrf-example");
    iw.process(canvas);

//    canvas = iw.nextCanvas();
//    drawWorld(canvas, wm);
//    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Render world model (LRF) without extra object (virtual data)

    geo::Transform2 lrf_pose = fromXYADegrees(0.533333, -1.24167, 145);
    drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2));
    iw.process(canvas);

    std::vector<double> ranges_virtual = renderLRF(lrf, lrf_pose, wm);
    drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50));
    drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2));
    iw.process(canvas);

    drawWorld(canvas, wm);
    drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50));
    drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2));
    iw.process(canvas);

    canvas = iw.nextCanvas();
    drawWorld(canvas, wm);
    drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50));
    drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2));
    iw.process(canvas);

}
コード例 #22
0
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			bool usePointSize = true;

#if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
#endif

			usePointSize = false;

			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			bool useColor = colorSource.get();
			if (useColor) {
				useColor &= colorSource->getTexture().isAllocated();
			}

			if (useColor) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (useColor) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotateDeg(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}
コード例 #23
0
ファイル: main.cpp プロジェクト: pombredanne/anacrolix
void draw()
{
    //if (drawThread) pthread_join(drawThread, NULL);
    //pthread_create(&drawThread, NULL, drawWorld, (void *)world);
    drawWorld(world);
}
コード例 #24
0
void display(void)
{
    // Clear the screen with the background colour (set in myinit)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    model_view = mat4(1.0f);
    
	double curprev = TM.GetElapsedTime() - prev;
	frames++;

	if (curprev > 1)
	{
		prev = TM.GetElapsedTime();
		fps = frames / curprev;
		frames = 0;
		printf("FPS: %i\n", fps);
	}
    model_view *= Translate(0.0f, 0.0f, -15.0f);
    HMatrix r;
    Ball_Value(Arcball,r);

    mat4 mat_arcball_rot(
        r[0][0], r[0][1], r[0][2], r[0][3],
        r[1][0], r[1][1], r[1][2], r[1][3],
        r[2][0], r[2][1], r[2][2], r[2][3],
        r[3][0], r[3][1], r[3][2], r[3][3]);
    model_view *= mat_arcball_rot;
    
    mat4 view = model_view;
    
    
   // model_view = Angel::LookAt(eye, ref, up);//just the view matrix;

    glUniformMatrix4fv( uView, 1, GL_TRUE, model_view );

    // Previously glScalef(Zoom, Zoom, Zoom);
    model_view *= Scale(Zoom);

	
    // Draw Something
	mvstack.push(model_view);
	drawWorld();
	model_view = mvstack.pop();
	//guy 1
	mvstack.push(model_view);
	model_view *= Translate (0, 8, -40);
	model_view *= Scale(1.5, 1.5, 1.5);
	model_view *= RotateY(180);
	// turn
	if (TIME >= 5 && TIME < 6)
	{
		model_view *= RotateY(-900 + TIME*180);
	}
	// move up
	else if (TIME >= 6 && TIME < 6.5)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0 , -36 + TIME*6);
	}
	// jump on bench
	else if (TIME >= 6.5 && TIME < 7)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, 3);
		model_view *= Translate (0, -16.25 + TIME*2.5, -13 + TIME*2);
	}
	// jump off bench
	else if (TIME >= 7 && TIME < 7.5)
	{
		model_view *= RotateY(180);
		model_view *= Translate(0, 1.25, 4);
		model_view *= Translate(0, -112 + TIME*16, -112 + TIME*16);
		model_view *= RotateX(-5040 + TIME*720);
	}
	// land
	else if (TIME >= 7.5 && TIME < 8)
	{
		model_view *= RotateY(180);
		model_view *= Translate(0, 9.25, 15);
		model_view *= Translate (0, 138.75-TIME*18.5, 0);
	}
	// walk toward other guy
	else if (TIME >= 8 && TIME < 9)
	{
		model_view *= RotateY(180);
		model_view *= Translate(0, 0, 15);
		model_view *= Translate(0, 0, -64 + TIME*8);
	}
	// stand for a bit
	else if (TIME >= 9 && TIME < 15)
	{
		model_view *= RotateY(180);
		model_view *= Translate(0, 0, 23);
		model_view *= RotateY(3*sin(5*TIME));
	}
	// spin thing
	else if (TIME >= 15 && TIME < 16)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, 23);
		model_view *= RotateY(-5400 + TIME*360);
	}
	// backflip thing
	else if (TIME >= 16 && TIME < 16.5)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, 23);
		model_view *= RotateX(5040 - TIME*720);
	}
	//walk backwards
	else if (TIME >= 16.5 && TIME < 17)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, 23);
		model_view *= Translate (0, 0, 264 - TIME*16);
	}
	//fall
	else if (TIME >= 17 && TIME < 17.5)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, 15);
		model_view *= Translate (0, (17*9) - TIME*9, 0);
		model_view *= RotateX (3060 - TIME*180);
	}
	// lay on ground
	else if (TIME >= 17.5)
	{
		model_view *= RotateY(180);
		model_view *= Translate (0, -4.5, 15);
		model_view *= RotateX (-90);
	}
	drawGuy1();
	model_view = mvstack.pop();

	//GUY 2
	mvstack.push(model_view);
	model_view *= Translate (-20, 8, 35);
	model_view *= Scale(1.5, 1.5, 1.5);
	model_view *= RotateY(180);
	if (TIME >= 6 && TIME < 8)
	{
		model_view *= Translate(39 - TIME*6.5, 0, 0);
		model_view *= RotateY(270 - TIME*45);
	}
	else if( TIME >= 8 && TIME  < 10)
	{
		model_view *= Translate (-13, 0, 0);
		model_view *= Translate (0, 0, -(8*10.5) + TIME*10.5);
	}
	else if (TIME >= 10 && TIME < 15)
	{
		model_view *= Translate (-13,0, 21);
		model_view *= RotateY(3*sin(5*TIME));
	}
	else if (TIME >= 15 && TIME < 26.5)
	{
		model_view *= Translate(-13, 0, 21);
	}
	else if (TIME >= 26.5 && TIME < 28.5)
	{
		model_view *= Translate (-13, 0, 21);
		model_view *= Translate (0, 0, (26.5*5) - TIME*5);
	}
	else if (TIME >= 28.5 && TIME < 29.5)
	{
		model_view *= Translate (-13, 0, 11);
		model_view *= RotateY((180*28.5) - TIME*180);
	}
	else if (TIME >= 29.5 && TIME < 31.5)
	{
		model_view *= Translate(-13, 0, 11);
		model_view *= RotateY(180);
		model_view *= Translate (0, 0, -(29.5*15) + 15*TIME);
	}


	drawGuy2();
	model_view = mvstack.pop();

	cam();
	


	if (TIME > 31.5)
		exit(0);

    glutSwapBuffers();
    if(Recording == 1)
        FrSaver.DumpPPM(Width, Height) ;
}
コード例 #25
0
ファイル: SimWindow.cpp プロジェクト: Shushman/dart
void SimWindow::draw() {
  glDisable(GL_LIGHTING);
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  if (!mSimulating) {
      if (mPlayFrame < mWorld->getRecording()->getNumFrames()) {
      size_t nSkels = mWorld->getNumSkeletons();
      for (size_t i = 0; i < nSkels; i++) {
        // size_t start = mWorld->getIndex(i);
        // size_t size = mWorld->getSkeleton(i)->getNumDofs();
        mWorld->getSkeleton(i)->setPositions(mWorld->getRecording()->getConfig(mPlayFrame, i));
      }
      if (mShowMarkers) {
        // size_t sumDofs = mWorld->getIndex(nSkels);
        int nContact = mWorld->getRecording()->getNumContacts(mPlayFrame);
        for (int i = 0; i < nContact; i++) {
            Eigen::Vector3d v = mWorld->getRecording()->getContactPoint(mPlayFrame, i);
            Eigen::Vector3d f = mWorld->getRecording()->getContactForce(mPlayFrame, i);

          glBegin(GL_LINES);
          glVertex3f(v[0], v[1], v[2]);
          glVertex3f(v[0] + f[0], v[1] + f[1], v[2] + f[2]);
          glEnd();
          mRI->setPenColor(Eigen::Vector3d(0.2, 0.2, 0.8));
          mRI->pushMatrix();
          glTranslated(v[0], v[1], v[2]);
          mRI->drawEllipsoid(Eigen::Vector3d(0.02, 0.02, 0.02));
          mRI->popMatrix();
        }
      }
    }
  } else {
    if (mShowMarkers) {
      collision::CollisionDetector* cd =
          mWorld->getConstraintSolver()->getCollisionDetector();
      for (size_t k = 0; k < cd->getNumContacts(); k++) {
        Eigen::Vector3d v = cd->getContact(k).point;
        Eigen::Vector3d f = cd->getContact(k).force / 10.0;
        glBegin(GL_LINES);
        glVertex3f(v[0], v[1], v[2]);
        glVertex3f(v[0] + f[0], v[1] + f[1], v[2] + f[2]);
        glEnd();
        mRI->setPenColor(Eigen::Vector3d(0.2, 0.2, 0.8));
        mRI->pushMatrix();
        glTranslated(v[0], v[1], v[2]);
        mRI->drawEllipsoid(Eigen::Vector3d(0.02, 0.02, 0.02));
        mRI->popMatrix();
      }
    }
  }

  drawWorld();

  // display the frame count in 2D text
  char buff[64];
  if (!mSimulating)
#ifdef _WIN32
    _snprintf(buff, sizeof(buff), "%d", mPlayFrame);
#else
    std::snprintf(buff, sizeof(buff), "%d", mPlayFrame);
#endif
  else
コード例 #26
0
ファイル: client.c プロジェクト: krjohnn/tron
int main(int argc, char *argv[])
{
	int counter=0;
	FILE *fd = NULL;fopen("./client.out", "w+");
	if ( fd != NULL )
		setOutputType(fd);
	else
		setOutputType(stderr);

	
	setLogLevel(LOG_LEVEL_DEBUG);

	uint8_t keep_alive = 1;
	uint8_t msg_type = 0, timeout = 0;
	int sockfd = 0, n = 0,c=0,xadd=0,yadd=1,BCD=0,running=1, startx=30,starty=30;
	char recvBuff[1024];
	uint8_t gameStarted = 0,fakeResponded=0;
	struct EventPlayer event;
	sleep_time.tv_sec  = 0;
    	sleep_time.tv_nsec = 450000000;

	memset(recvBuff, '0',sizeof(recvBuff));


	if(argc != 3)
	{
		printf("\n Usage: %s <ip of server> <port of server>\n",argv[0]);
		return 1;
	}

	init_game();
	
	keep_alive = ConnectToServer(argv[1], argv[2], &sockfd);

	while (keep_alive)
	{
		
		void *buf = NULL;
		buf = RecieveMessage(sockfd, &msg_type, &timeout);
		
		if ( timeout == 5 ) {
			keep_alive = 0;
			ERROR("Connection to server timed out\n");
		} else {
			if(buf){
				switch(msg_type) {
					case 2:
						/* Player just connected to server;
							Message contains servers rules; */
						NOTICE("Connected to server, please stand by\n");
						CreateClientWorld(&game, buf);
						break;
					case 3:
						/* Update message received; calculate wait for button pressed */
						DEBUG("Update information recieved\n" /*TODO add data here for debuging */);
						updateClientWorld(&game,buf);
						gameStarted = 1;
						break;
					default:
						keep_alive = 0;
						DEBUG("Trashed unhandeled message type:%d\n", msg_type);
						break;
				}
				free(buf);
			}

			if (gameStarted)
			{
				
				//init_game();
				c = wgetch(key_detecter);
				
				if ( c != ERR ) {
					NOTICE(" WE PRESSED: %c\n",c);
					ClientMove(c, &game);//TODO pass c to world-done
				}		
				event.direction = (getSelf(&game))->direction;
				if ( c == ' ')
					event.shot = 1;
				else
					event.shot = 0;
				SendMessage(sockfd, &event, sizeof(event), PCKT_EVENT);
			 	DEBUG("Sending update event { %d, %d } to server \n", event.direction, event.shot );

	    	}
			drawWorld(&game);	
			getchar();		
			refresh();			
		}
	}
	NOTICE("Disconnected from server\n");
	if (fd != NULL)
		fclose(fd);
	//terminate_game();
	return 0;
}
コード例 #27
0
ファイル: relative.cpp プロジェクト: svddries/image_creator
void relativeSection(ImageWriter& iw)
{
    iw.setLabel("relative");

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    WorldModel2D wm;

//    wm.addEntity(createBox(geo::Vec2(), geo::Vec2()));

//    wm.addEntity(createBox(7.63, 4.09, true), fromXYADegrees(0.085, 0.065, 0));
    wm.addEntity(createBox(geo::Vec2(0, -4.09), geo::Vec2(7.63, 0), true), fromXYADegrees(-3.75, 2.1, 0));


    int idx_couch = wm.entities.size();
    wm.addEntity(createBox(0.691667, 1.45833), fromXYADegrees(-0.529166, 0.404165, 0));
    wm.addEntity(createBox(0.45833, 0.6), fromXYADegrees(-1.69583, 0.375, 0));
    wm.addEntity(createBox(0.95833, 0.516667), fromXYADegrees(-1.72917, -0.616667, 0));
    wm.addEntity(createBox(0.96666, 0.50833), fromXYADegrees(-1.75, 1.37084, 0));
    wm.addEntity(createBox(1.6, 0.30834), fromXYADegrees(-0.45, -1.8375, 0));

    int idx_table = wm.entities.size();
    wm.addEntity(createBox(0.65, 0.95), fromXYADegrees(1.6, 0.4, 0));

    int idx_cabinet = wm.entities.size();
    wm.addEntity(createBox(0.55, 1.28333), fromXYADegrees(3.54167, 0.558333, 0));

    wm.addEntity(createCircle(0.1), fromXYA(0.358333, 1.81667, 0));
    wm.addEntity(createCircle(0.1), fromXYA(-1.73333, -1.78333, 0));

    int idx_plant = wm.entities.size();
    wm.addEntity(createCircle(0.1), fromXYA(3.18333, 1.68333, 0));

    Model2D model;
    Contour2D& c = model.addContour();
    c.addPoint(-3.73333 + 3.3, -1 + 1.6);
    c.addPoint(-3.15 + 3.3, -1 + 1.6);
    c.addPoint(-3.15 + 3.3, -1.46 + 1.6);
    c.addPoint(-2.36 + 3.3, -1.46 + 1.6);
    c.addPoint(-2.36 + 3.3, -1.97 + 1.6);
    c.addPoint(-3.73333 + 3.3, -1.97 + 1.6);

    wm.addEntity(model, fromXYADegrees(-3.3, -1.6, 0));

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Canvas canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom.jpg", 0.9);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    drawWorld(canvas, wm);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    int idx_lrf = wm.entities.size();
    wm.addEntity(createLRFPose(), fromXYADegrees(0.533333, -1.24167, 145), Color(0, 150, 0, 2));
    drawWorld(canvas, wm);
    iw.process(canvas);

    int idx_target = wm.entities.size();
    wm.addEntity(createTarget(), fromXYADegrees(-0.533333, -0.725, 0), Color(255, 0, 0, 2));
    drawWorld(canvas, wm);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    // Moved couch

    canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9);
    drawWorld(canvas, wm);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//    canvas = iw.nextCanvas();
    drawWorldModelAbsolute(canvas, wm, wm.entities[0].pose.t);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9);
    drawWorld(canvas, wm);
    iw.process(canvas);

    std::vector<Link> links;
    links.push_back(Link(0, idx_target));
    links.push_back(Link(0, idx_lrf));

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9);
    drawWorld(canvas, wm);
    iw.process(canvas);

    links.clear();

    links.push_back(Link(idx_couch, idx_target));
    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    links.push_back(Link(idx_lrf, idx_couch));
    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    WorldModel2D wm2;
    wm2.entities.push_back(wm.entities[idx_lrf]);
    wm2.entities.push_back(wm.entities[idx_couch]);
    wm2.entities.push_back(wm.entities[idx_target]);

    links.clear();
    links.push_back(Link(0, 1));
    links.push_back(Link(1, 2));

    canvas = iw.nextCanvas();
    drawWorldModelSceneGraph(canvas, wm2, links);
    iw.process(canvas);

    canvas = iw.nextCanvas();
    drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9);

    wm.entities[idx_target].pose.t.y += 0.7;
    wm.entities[idx_couch].pose.t.y += 0.7;

    links.clear();
    links.push_back(Link(idx_couch, idx_target));
    links.push_back(Link(idx_lrf, idx_couch));

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    links.push_back(Link(idx_couch, 2));
    links.push_back(Link(2, 3));
    links.push_back(Link(2, 4));
    links.push_back(Link(idx_lrf, idx_table));
    links.push_back(Link(idx_table, idx_cabinet));
    links.push_back(Link(idx_cabinet, idx_plant));

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Soccer field

    iw.setLabel("relative-soccer");

//Click: [ -2.0125 -0.0125 ]
//Click: [ 0.8375 -1.1 ]
//Click: [ 2.075 0.025 ]
//Click: [ 2 1.7125 ]  ball

    wm.entities.clear();
    wm.addEntity(createSoccerFieldModel(), geo::Transform2::identity(), Color(255, 255, 255, 2));
    wm.addEntity(createCircle(0.2), fromXYA(2, 1.7125, 0), Color(255, 220, 0, 2));

    wm.addEntity(createTurtleModel(), fromXYADegrees(0.8375, -1.1 , 60), Color(0, 0, 0, 2));
//    wm.addEntity(createTurtleModel(), fromXYADegrees(-1.1, -0.15, -90), Color(0, 0, 0, 2));
//    wm.addEntity(createTurtleModel(), fromXYADegrees(2.275, 0.025, 105), Color(0, 0, 0, 2));


    canvas = iw.nextCanvas();
    drawSoccerField(canvas);
    drawWorld(canvas, wm);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    drawWorldModelAbsolute(canvas, wm, geo::Vec2(-4, 2.67));
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    links.clear();
    links.push_back(Link(2, 1));

    canvas = iw.nextCanvas();
    drawSoccerField(canvas);
    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    wm.addEntity(createTurtleModel(), fromXYADegrees(-1.5, -0.15, -10), Color(0, 0, 0, 2));

    canvas = iw.nextCanvas();
    drawSoccerField(canvas);
    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    links.push_back(Link(3, 2));

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    drawArrow(canvas, wm.entities[3].pose.t, wm.entities[1].pose.t, Color(150, 150, 150, 2), true);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    canvas = iw.nextCanvas();
    drawSoccerField(canvas);

    geo::Vec2 ball_pos_rel = wm.entities[2].pose.inverse() * wm.entities[1].pose.t;

    geo::Transform2 offset = geo::Transform2::identity();
    offset.setRotation(-0.3);

    wm.entities[2].pose = wm.entities[2].pose * offset;
    wm.entities[1].pose.t = wm.entities[2].pose * ball_pos_rel;

    drawWorldModelSceneGraph(canvas, wm, links);
    drawArrow(canvas, wm.entities[3].pose.t, wm.entities[1].pose.t, Color(150, 150, 150, 2), true);
    iw.process(canvas);

    // Turn back
    wm.entities[2].pose = wm.entities[2].pose * offset.inverse();
    wm.entities[1].pose.t = wm.entities[2].pose * ball_pos_rel;

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    canvas = iw.nextCanvas();
    drawSoccerField(canvas);
    drawWorld(canvas, wm);
    iw.process(canvas);

//    wm.addEntity(createTurtleModel(), fromXYADegrees(2.275, 0.025, 105), Color(0, 0, 0, 2));
    wm.addEntity(createTurtleModel(), fromXYADegrees(0.375, 0.65, -105), Color(0, 0, 0, 2));

    drawWorld(canvas, wm);
    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    links.clear();
    links.push_back(Link(2, 1));
    links.push_back(Link(2, 4));

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

//    links.push_back(Link(4, 1));

//    drawWorldModelSceneGraph(canvas, wm, links);
//    iw.process(canvas);

    links.push_back(Link(3, 2));
    links.push_back(Link(3, 4));

    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    cv::Mat temp = canvas.image.clone();

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    canvas = iw.nextCanvas();
    canvas.image = temp.clone();

    drawTriangle(canvas, wm.entities[1].pose.t, wm.entities[2].pose.t, wm.entities[4].pose.t, Color(0, 255, 255, 2));

    iw.process(canvas);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    // Replace 3th turtle by field feature
    wm.entities[4] = Entity2D(Model2D(), fromXYA(0, 0.7, 0), Color());

    canvas = iw.nextCanvas();
    drawSoccerField(canvas);
    drawWorldModelSceneGraph(canvas, wm, links);
    iw.process(canvas);

    drawTriangle(canvas, wm.entities[1].pose.t, wm.entities[2].pose.t, wm.entities[4].pose.t, Color(0, 255, 255, 2));

    iw.process(canvas);


}
コード例 #28
0
ファイル: Flat.cpp プロジェクト: Lucretiel/Art2D
void Flat::render()
{
	drawWorld(back3, &shiftUpLeft2, sf::Color::Black, sf::Color::White, -1);
	drawWorld(back2, &shiftUpLeft, sf::Color::Black, sf::Color::White, -1);
	drawWorld(back1, &noShift, sf::Color::Black, sf::Color::White, -1);
}
コード例 #29
0
void drawCam(int player) {
	int i;
	float up[3] = { 0, 0, 1 };
	Visual *d = & gPlayerVisuals[player].display;
	
	float reflectivity = getReflectivity();
	// compute shadow color based on glocal constant & reflectivity
	for(i = 0; i < 4; i++) 
		gCurrentShadowColor[i] = gShadowColor[i] * (1 - reflectivity);

	glColor3f(0.0, 1.0, 0.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	doPerspective(gSettingsCache.fov, (float) d->vp_w / (float) d->vp_h,
		gSettingsCache.znear, box2_Diameter(& game2->level->boundingBox) * 6.5f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	{
		vec3 vLookAt;
		vec3 vTarget;
		matrix matRotate;

		vec3_Sub(&vLookAt, (vec3*)gPlayerVisuals[player].camera.target, (vec3*)gPlayerVisuals[player].camera.cam);
		vec3_Normalize(&vLookAt, &vLookAt);
		matrixRotationAxis(&matRotate, 90.0f * (float) gPlayerVisuals[player].camera.bIsGlancing, (vec3*)up);
		vec3_Transform(&vLookAt, &vLookAt, &matRotate);
		vec3_Add(&vTarget, (vec3*)gPlayerVisuals[player].camera.cam, &vLookAt);
		doLookAt(gPlayerVisuals[player].camera.cam, (float*)&vTarget, up);
	}

	glDisable(GL_LIGHTING); // initial config at frame start
	glDisable(GL_BLEND); // initial config at frame start

	// disable writes to alpha
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

	/* skybox */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* skybox done */

	/* floor */ 
	if(reflectivity == 0) {
		// draw floor to fb and stencil (set to 1),
		// using alpha-blending
		// TODO: draw floor alpha to fb
		video_Shader_Setup(& gWorld->floor_shader);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		glDisable(GL_BLEND);
		glDisable(GL_STENCIL_TEST);
		video_Shader_Cleanup(& gWorld->floor_shader);
	} else {
		/* reflections */
		/* first draw reflector to stencil */
		/* and reflector alpha to fb */

		video_Shader_Setup(& gWorld->floor_shader);

		// store only reflector alpha in framebuffer
		glDepthMask(GL_FALSE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
		// glEnable(GL_ALPHA_TEST);
		// glAlphaFunc(GL_GREATER, 0.1f);

		nebu_Mesh_DrawGeometry( gWorld->floor );
		
		// glDisable(GL_ALPHA_TEST);
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		glDepthMask(GL_TRUE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_EQUAL, 1, 255);

		video_Shader_Cleanup(& gWorld->floor_shader);
		
		/* then draw world & skybox reflected, where stencil is set */
		/* protect the alpha buffer */
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

		isRenderingReflection = 1; // hack: reverse lighting
		glPushMatrix();
		glScalef(1,1,-1);
		glCullFace(GL_FRONT); // reverse culling
		// clip skybox & world to floor plane
		glEnable(GL_CLIP_PLANE0);
		{
			double plane[] = { 0, 0, 1, 0 };
			glClipPlane(GL_CLIP_PLANE0, plane);
		}

		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		drawWorld(player);

		glDisable(GL_CLIP_PLANE0);
		glCullFace(GL_BACK);
		glPopMatrix();
		isRenderingReflection = 0; // hack: normal lighting

		/* then blend the skybox into the scene, where stencil is set */
		/* modulate with the destination alpha */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
		
		/* then blend reflector into the scene */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glColor4f(1, 1, 1, 1 - reflectivity);

		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_ALWAYS, 1, 255);

		video_Shader_Setup(& gWorld->floor_shader);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		video_Shader_Cleanup(& gWorld->floor_shader);

		glDisable(GL_STENCIL_TEST);
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
	}
	/* floor done */

	/* planar shadows */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	if(reflectivity != 1) // there are no shadows on perfect mirrors
		drawPlanarShadows(player);

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* planar shadows done */

	drawWorld(player);

	/* transparent stuff */
	/* draw the glow around the other players: */
	if (gSettingsCache.show_glow == 1) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for (i = 0; i < game->players; i++)
		{
			if (i != player && PLAYER_IS_ACTIVE(game->player + i))
			{
				drawGlow(&gPlayerVisuals[player].camera, game->player + i, gPlayerVisuals + i,
					d, TRAIL_HEIGHT * 4);
			}
		}
		glDisable(GL_BLEND);
	}
}
コード例 #30
0
ファイル: ofApp.cpp プロジェクト: benmirath/GameAesthetics
//--------------------------------------------------------------
void ofApp::draw(){
	drawWorld();
}