예제 #1
0
KodeEngine::Cube::Cube(GLfloat x, GLfloat y, GLfloat z)
{
	xpos = x;
	ypos = y;
	zpos = z;

	initCube();
}
예제 #2
0
파일: Cubo.cpp 프로젝트: pmdp/P3_1_IG
Cubo::Cubo(int numText, GLuint* tex, int numCaraTex)
{
	numTexturas = numText;
	textura = tex;
	numCaraTextura = numCaraTex;

	initCube();
}
예제 #3
0
void moveCube(void* ptr){
    Cube *c = ptr;
    if(c->vx == 0 && c->vy == 0 && c->vz == 0 
       || c->x < -250 || c->x > 250
       || c->y < -250 || c->y > 250
       || c->z < -250 || c->z > 250
       ){
        initCube(c);
    }

    c->cnt++;
    c->x += c->vx;
    c->y += c->vy;
    c->z += c->vz;
    //c->z = sin(3.14f / 60.0f * c->cnt) * 100;

    // 当たり判定
    GLfloat mx0 = c->x - c->size / 2.0f;
    GLfloat mx1 = c->x + c->size / 2.0f;
    GLfloat my0 = c->y - c->size / 2.0f;
    GLfloat my1 = c->y + c->size / 2.0f;

    GLfloat x0 = player.x - player.size / 2.0f;
    GLfloat x1 = player.x + player.size / 2.0f;
    GLfloat y0 = player.y - player.size / 2.0f;
    GLfloat y1 = player.y + player.size / 2.0f;

    if(! player.isDeleted &&
       mx0 < x1 && x0 < mx1 && my0 < y1 && y0 < my1){
        //printf("HIT!!!!!\n");
        if(player.size > c->size){
            player.size -= c->size;  //小さくなっちゃった
            initCube(c);             //弾は消す
        }else{
            // プレイヤー消滅
            player.isDeleted = 1;

            // プレイヤーのタスクを爆発タスクに書き換え
            initBomb(&bomb, player.x, player.y, player.z);
            tasks[0].data = &bomb;
            tasks[0].move = &moveBomb;
            tasks[0].draw = &drawBomb;
        }
    }
}
예제 #4
0
CuboColor::CuboColor(
		const glm::vec3& colorzp,
		const glm::vec3& colorzm,
		const glm::vec3& colorxp,
		const glm::vec3& colorxm,
		const glm::vec3& coloryp,
		const glm::vec3& colorym
		) { 
	initCube(colorzp, colorzm, colorxp, colorxm, coloryp, colorym);		
}
예제 #5
0
void cRenderObjs::init()
{
   if(!m_bIsInit) {
      m_bIsInit = true;
      initPlane();
      initCube();
      initSphere();
      initElevator();
      initHuman();
   }
}
예제 #6
0
파일: prakt6.cpp 프로젝트: abimelex/htwcg1
static void myinit(void)
{   
	printf( "OpenGL renderer:                  |%s|\n", (char*)glGetString( GL_RENDERER));
	printf( "OpenGL driver version:            |%s|\n", (char*)glGetString( GL_VERSION));		

    /* Initializations */
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();		
    glClearColor (1, 1, 1, 0);	//Hintergrundfarbe
    initCube();
    time(&tstart);	//save start time
}
예제 #7
0
Skybox::Skybox(string name, string textures_dir_path, string file_extension)
{
	Shader* shader = new Shader("./skybox.vs", "./skybox.frag");

	vector<string> faces;
	string files[6] = { "right", "left", "top", "bottom", "back", "front" };
	for (int i = 0; i < 6; i++)
		faces.push_back(textures_dir_path + "/" + files[i] + file_extension);

	textureID = loadCubemap(faces);

	initCube();

	this->name = name;
	this->shader = shader;
}
예제 #8
0
파일: jeu.c 프로젝트: pouet/rubik
int jeu(Cube * cube, struct SItem * it, int nbItem) {
  Bouton ** b;
  SDL_Rect rimg[6] = {
    { POS_X_CUBISO + 3, POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO +
      cube->nbCubLig * 53 + 12, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * OFFSET_X_H_CUBISO + 22 - 6,
      POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO +
      (cube->nbCubLig - 1) * OFFSET_Y_H_CUBISO + cube->nbCubLig * 53 + 12, 0, 0 },
    { POS_X_CUBISO, POS_Y_CUBISO + (cube->nbCubLig - 1) * OFFSET_Y_H_CUBISO - 15 + 10, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * OFFSET_X_H_CUBISO + 18, POS_Y_CUBISO - 15 + 10, 0, 0 },
    { POS_X_CUBISO + cube->nbCubLig * (OFFSET_X_H_CUBISO * 2 ) + 10,
      POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO + 15, 0, 0 },
    { POS_X_CUBISO - 27, POS_Y_CUBISO + cube->nbCubLig * OFFSET_Y_H_CUBISO + 15, 0, 0 }
  };
  SDL_Rect roff[6] = {
    { OFFSET_X_H_CUBISO, OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, -OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, -OFFSET_Y_H_CUBISO, 0, 0 },
    { OFFSET_X_H_CUBISO, OFFSET_Y_H_CUBISO, 0, 0 },
    { 0, 53, 0, 0 },
    { 0, 53, 0, 0 }
  };
  Input * in;
  int ret = M_MENU;
  int nbBtn;
  int done;
  int clic;
  int timer;
  int i, j, k;
  
  if (cube == NULL)
    return ret;
  
  in = newEvent();
  
  nbBtn = nbItem + cube->nbCubLig * 6;
  b = emalloc((nbBtn + 1) * sizeof **b, "Erreur d'allocation de boutons.\n");
  b[nbBtn] = NULL;
  
  for (i = 0, j = 0; i < nbItem; i++, j++)
    b[i] = creerBoutonTexte(it[i].pItemName, SCR_W - g_boutons[0]->w - 12,
                            SCR_H - 6 - (nbItem - i) * (g_boutons[0]->h + 6), 1);
  
  for (k = 0; k < 6; k++)
    for (i = 0; i < cube->nbCubLig; i++, j++)
      b[j] = creerBoutonImage(k * 3, rimg[k].x + roff[k].x * i,
                              rimg[k].y + roff[k].y * i, 1);
  
  refreshScreen();
  
  timer = 0;
  clic = 0;
  done = 0;
  while (!done) {
    updateEvents(in);
    
    if (in->quit) {
      done = 1;
      ret = M_QUIT;
    }
    
    for (i = 0; i < nbBtn; i++) {
      if (b[i]->actif) {
        if (collisionPoint(&b[i]->r, &in->mouse)) {
          /* Si on clique */
          if (!clic && (in->mousebuttons[1] || in->mousebuttons[2])) {
            clic = 1;
            b[i]->etat = BTN_ETAT_CLIC;
            b[i]->majAff = 1;
          }
          /* Si on relâche le clic */
          else if (clic && b[i]->etat == BTN_ETAT_CLIC &&
                   !in->mousebuttons[1] && !in->mousebuttons[2]) {
            clic = 0;
            b[i]->etat = BTN_ETAT_NORMAL;
            b[i]->majAff = 1;
            
            if (i < nbItem) {
              if (it[i].nItemVal == M_MENU || it[i].nItemVal == M_QUIT) {
                ret = it[i].nItemVal;
                if (it[i].pVal)
                  *it[i].pVal = it[i].nVal;
                done = 1;
              }
              else if (it[i].nItemVal == M_MELANGE) {
                melangerCube(cube);
                timer = 0;
                cube->tpsTotal = 0;
                cube->nbCoups = 0;
              }
              else if (it[i].nItemVal == M_REINIT) {
                refreshScreen();
                initCube(cube, cube->nbCubLig);
                timer = 0;
              }
              else if (it[i].nItemVal == M_SAUVE) {
                sauverCube(cube);
              }
            }
            else if (i >= nbItem) {
              int tmp = i - nbItem;
              
              cube->nbCoups++;
              if (timer == 0)
                timer = 1;
              
              /* Ca va crescendo on teste la borne la plus basse et ainsi de suite
               * sans retester plus bas, c'est déjà test avant */
              /* Flèche haut gauche */
              if (tmp < cube->nbCubLig) {
                rotationCubeEntier(cube, R_GAUCHE);
                mouvement(cube, tmp, R_BAS);
                rotationCubeEntier(cube, R_DROITE);
              }
              /* Flèches haut droite */
              else if (tmp < cube->nbCubLig * 2) {
                tmp -= cube->nbCubLig;
                mouvement(cube, tmp, R_BAS);
              }
              /* Flèches bas gauche */
              else if (tmp < cube->nbCubLig * 3) {
                tmp -= (cube->nbCubLig * 2);
                mouvement(cube, tmp, R_HAUT);
              }
              /* Flèches bas droite */
              else if (tmp < cube->nbCubLig * 4) {
                tmp -= (cube->nbCubLig * 3);
                rotationCubeEntier(cube, R_GAUCHE);
                mouvement(cube, tmp, R_HAUT);
                rotationCubeEntier(cube, R_DROITE);
              }
              /* Flèches droite */
              else if (tmp < cube->nbCubLig * 5) {
                tmp -= (cube->nbCubLig * 4);
                mouvement(cube, tmp, R_DROITE);
              }
              /* Flèches gauche */
              else if (tmp < cube->nbCubLig * 6) {
                tmp -= (cube->nbCubLig * 5);
                mouvement(cube, tmp, R_GAUCHE);
              }
              else {
                cube->nbCoups--;
                aprintf("Bouton inconnu.\n");
              }
            }
            else {
              aprintf("Bouton inconnu.\n");
            }
          }
          else if (b[i]->etat != BTN_ETAT_CLIC) {
            if (b[i]->etat != BTN_ETAT_SURVOLE)
              b[i]->majAff = 1;
            b[i]->etat = BTN_ETAT_SURVOLE;
          }
        }
        else if (b[i]->etat != BTN_ETAT_CLIC) {
          if (b[i]->etat != BTN_ETAT_NORMAL)
            b[i]->majAff = 1;
          b[i]->etat = BTN_ETAT_NORMAL;
        }
      }
    }
    
    if (clic && !in->mousebuttons[1] && !in->mousebuttons[2]) {
      clic = 0;
      for (i = 0; i < nbBtn; i++)
        if (b[i]->etat == BTN_ETAT_CLIC) {
          b[i]->etat = BTN_ETAT_NORMAL;
          b[i]->majAff = 1;
        }
    }
    
    if (timer)
      cube->tpsTotal += TICK;
    
    affiche(BCK_JEU, cube, b);
  }
  
  for (i = 0; i < nbBtn; i++)
    detruireBouton(&b[i]);
  free(b);
  deleteEvent(&in);
  
  return ret;
}
예제 #9
0
파일: main.c 프로젝트: fukusyo/NDKBook_2nd
// EGL初期化
static int engine_init_display(struct engine* engine) {

  EGLint w, h, dummy, format;
  EGLint numConfigs;
  EGLConfig config;
  EGLSurface surface;
  EGLContext context;

  // 有効にするEGLパラメータ
  const EGLint attribs[] = 
    {
      // サーフェイスのタイプを指定(ダブルバッファを利用するのでEGL_WINDOW_BIT)
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      // 青が利用する最小フレームサイズ(単位はbit)
      EGL_BLUE_SIZE,  8,
      // 緑が利用する最小フレームサイズ(単位はbit)
      EGL_GREEN_SIZE, 8,
      // 赤が利用する最小フレームサイズ(単位はbit)
      EGL_RED_SIZE,   8,
      // デプスバッファとして確保するサイズ(単位はbit)
      EGL_DEPTH_SIZE, 16,
      // 終端
      EGL_NONE }; 

  // EGLディスプレイコネクションを取得
  EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  // EGLディスプレイコネクション初期化
  eglInitialize(display, 0, 0);
  // 条件に合ったEGLフレームバッファ設定のリストを返す
  eglChooseConfig(display, attribs, &config, 1, &numConfigs);
  // EGLフレームバッファ設定の情報を取得
  eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
  // NativeActivityへバッファを設定
  ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
  // EGLウィンドウサーフェイスの取得
  surface = eglCreateWindowSurface(display, config, engine->app->window,
                                   NULL);
  // EGLレンダリングコンテキストの取得
  context = eglCreateContext(display, config, NULL, NULL);
  // EGLレンダリングコンテキストをEGLサーフェイスにアタッチする
  if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
    LOGW("Unable to eglMakeCurrent");
    return -1;
  }

  // 画面解像度取得
  eglQuerySurface(display, surface, EGL_WIDTH, &w);
  eglQuerySurface(display, surface, EGL_HEIGHT, &h);

  // EGL関連データの保存
  engine->display = display;
  engine->context = context;
  engine->surface = surface;

  // 画面解像度の保存
  engine->width = w;
  engine->height = h;

  // 初期値設定
  int j; 
  for (j = 0; j < 3; j++){
    engine->angle[j] = 0;
  }

  // 立方体表示の初期化
  initCube(engine); 

  return 0;
}
예제 #10
0
파일: particle.c 프로젝트: gloob/Metaballs
int setParticle( particle *particles, float isovalue )
{
	int p, i, j, k;
	GLfloat initX, initY, initZ;
	GLfloat incX, incY, incZ;
	GLfloat total;
	double media = 0.0f;

	int offset2 = DIV_Y*DIV_X;

	p = 0;
//	for(p = 0; p < NUM_PARTICLES; p++) {

		particles[p].x = p * 5.0f;
		particles[p].y = p * 5.0f;
		particles[p].z = p * 5.0f;
		particles[p].r = 1.0f;
		particles[p].g = 0.0f;
		particles[p].b = 0.5f;

		incX = initX = particles[p].x - (( stepX * DIV_X ) / 2) + (stepX / 2);
		incY = initY = particles[p].y - (( stepY * DIV_Y ) / 2) + (stepY / 2);
		incZ = initZ = particles[p].z - (( stepZ * DIV_Z ) / 2) + (stepZ / 2);	

		printf("* InitX = %f\n", initX);
		printf("* InitY = %f\n", initY);
		printf("* InitZ = %f\n", initZ);

		for(k = 0; k < DIV_Z; k++) {
			incY = initY;
			for(j = 0; j < DIV_Y; j++) {
				incZ = initZ;
				for(i = 0; i < DIV_X; i++) {
					particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].x = incX;
					particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].y = incY;
					particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].z = incZ;
					printf("[%d][%d][%d] (%d) X = %f Y = %f Z = %f\n", i, j, k, (j*DIV_X)+(k*DIV_Y*DIV_X)+i, incX, incY, incZ);

					total = (particles[p].x - incX) * (particles[p].x - incX) +
							(particles[p].y - incY) * (particles[p].y - incY) +
							(particles[p].z - incZ) * (particles[p].z - incZ);
					printf("[%d][%d][%d] = %f\n", i, j, k, total);
					media += total;
					if( total <= isovalue )
						particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].sel = GL_TRUE;
					else 
						particles[p].vertexs[(j*DIV_X)+(k*offset2)+i].sel = GL_FALSE;

					incZ += stepZ;
				}
				incY += stepY;	
			}
			incX += stepX;
		}	
	//}

	media = media / (DIV_X*DIV_Y*DIV_Z);
	//printf("media = %f", media);
	isovalue = (float) media / 1.75;
	
	//start cubes
	int idx = 0;
	incX = initX = particles[p].x - (( stepX * DIV_X ) / 2) + (stepX / 2);
	incY = initY = particles[p].y - (( stepY * DIV_Y ) / 2) + (stepY / 2);
	incZ = initZ = particles[p].z - (( stepZ * DIV_Z ) / 2) + (stepZ / 2);

	printf("* InitX = %f\n", initX);
	printf("* InitY = %f\n", initY);
	printf("* InitZ = %f\n", initZ);
	printf("* stepX  = %f\n", stepX);


	for (k = 0; k < DIV_Z-1; k++) {
		incY = initY;
		for (j = 0; j < DIV_Y-1; j++) {
			incZ = initZ;
			for (i = 0; i < DIV_X-1; i++) {
				initCube(&particles[p].cubes[idx++], incX, incY, incZ, 1.0f);
				printf("x: %f, y: %f, z:%f\n", incX, incY, incZ);
				incZ += stepZ;
			}
			incY += stepY;
		}
		incX += stepX;
	}
	return 1;
}
예제 #11
0
CuboColor::CuboColor(const glm::vec3& color) {
	initCube(color,color,color,color,color,color);
}
예제 #12
0
파일: Cubo.cpp 프로젝트: pmdp/P3_1_IG
Cubo::Cubo()
{
	numTexturas = -1;
	initCube();
}
예제 #13
0
Cube::Cube(GLfloat x, GLfloat y, GLfloat z, GLfloat halfX, GLfloat halfY, GLfloat halfZ, bool wall)
{
	isWall = wall;
	initCube(x, y, z, halfX, halfY, halfZ);
}
예제 #14
0
Cube::Cube(void)
{
	isWall = false;
	initCube(0, 0, 0, 0.5, 0.5, 0.5);
}