Ejemplo n.º 1
0
void Map2D::DrawTranslucent( const glImage *Tiles )
{
	
	TxOff = (TxOff + 1) & 31;
	glPushMatrix();
	glPolyFmt( POLY_ALPHA(15) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) );
				
	for( int y = 0; y < Height; y++ )
	{
		for( int x = 0; x < Width ; x++ )
		{
			
			int Tile = GetElement(x,y);
			switch( Tile )
			{
				
				case WATER:
					DrawFrontCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] );
					break;
				case TOP_WATER:
					DrawFrontTopCube( (x * TILE_SIZE_3D) + floattof32(0.5), (y * TILE_SIZE_3D) + floattof32(0.5), 0, 0, -TxOff, &Tiles[0] );
					break;
					
			}
			
		}	
	}
	
	glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) );
	
	glPopMatrix(1);
	
}
Ejemplo n.º 2
0
void RubiksCube::Resize(float size)
{
	Position.X=floattof32(-size/2);
	Position.Y=floattof32(-size/2);
	Position.Z=floattof32(-size/2);
	Size=floattof32(size);
}
Ejemplo n.º 3
0
RubiksCube::RubiksCube(float size)
{
	Position.X=floattof32(-size/2);
	Position.Y=floattof32(-size/2);
	Position.Z=floattof32(-size/2);
	Size=floattof32(size);
	rotateSensitivity=2;
	twistSensitivity=2;
	controlStyle=0;
	setDefaultColours();
	Reset();
}
Ejemplo n.º 4
0
Entity::Entity()
{
	
	Active = false;	
	
	x = 0;
	y = 0; 
	xv = 0; 
	yv = 0;
	Speed = floattof32(0.03); 
	
	Width = (32 * TILE_SIZE_3D) / TILE_SIZE;
	Height = (32 * TILE_SIZE_3D) / TILE_SIZE;   
	
	Counter = 0;
	Flipmode = GL_FLIP_NONE;
	Frame= 0;
	BaseFrame = 0;
	MaxFrame = 1;
	
	HP = 1;
	MaxHP = 1;
	Score = 0;
	Stunned = false;
	StunCoolDown = 30;
	
}
Ejemplo n.º 5
0
void TunnelPartExec(int time)
{
	int i;
	int32 dir[3];
	
	CurrentTime = time;
	
	
	
	TunnelFxDraw((time>>6), sinLerp(time>>1), cosLerp(time>>1));
	
	
	
	glEnable(GL_BLEND);
		
	DiscoElephant->transform->translation[2] = floattof32(-1) + ABS(sinLerp(time)/2);
	DiscoElephant->transform->rotation[0] = (DEGREES_IN_CIRCLE/16);
	DiscoElephant->transform->rotation[1] = sinLerp(time*2) / 2;

	for(i=0; i<4; i++) {
		dir[0] = (DiscoElephant->transform->translation[0] - flares[i]->position[0]);
		dir[1] = (DiscoElephant->transform->translation[1] - flares[i]->position[1]);
		dir[2] = (DiscoElephant->transform->translation[2] - flares[i]->position[2]);
		
		normalizef32(dir);
		
		dir[0] *= 0.9;
		dir[1] *= 0.9;
		dir[2] *= 0.9;
		
		Scene->lights[i]->direction[0] = f32tov10(dir[0]);
		Scene->lights[i]->direction[1] = f32tov10(dir[1]);
		Scene->lights[i]->direction[2] = f32tov10(dir[2]);
	}

	RenderScene(Scene);	
		
	for(i=0; i<4; i++) {
		flares[i]->position[0] = DiscoElephant->transform->translation[0] + (int32)sinLerp((time<<1) + (i+1) * DEGREES_IN_CIRCLE/4)/2;
		flares[i]->position[1] = DiscoElephant->transform->translation[1] + (int32)cosLerp((time<<2) + (i+1) * DEGREES_IN_CIRCLE/4)/2;
		flares[i]->position[2] = DiscoElephant->transform->translation[2] + (int32)sinLerp((time<<3) + DEGREES_IN_CIRCLE/(i+1))/2;
		DrawBillboard(flares[i], false, 0, 0, 0, 0);
	}
	
	if(time < 1000) {
		FadeIn(time);
	} else if(time >= 28000) {
		FadeOut(time);
	} else {
		DrawFlash(time);
	}
	
	glFlush(0);
	swiWaitForVBlank();
}
Ejemplo n.º 6
0
void Camera::Follow( s32 x, s32 y )
{
	
	Position.x = x;
	Position.y = y - floattof32(0.2);    // offset a little above so we look a little down
	Position.z = EyeDistanceFromScreen;       // move zpos 15 units from screen to eye
	
	Target.x = x;
	Target.y = y;
	Target.z = 0 << 12;
	
	Up.x = 0 << 12;
	Up.y = 1 << 12;
	Up.z = 0 << 12;
	
}
Ejemplo n.º 7
0
int main()
{	
    struct touchPosition pos;
	float rotateX = 0.0;
	float rotateY = 0.0;

	powerON(POWER_ALL);
    consoleDemoInit();

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	//irqs are nice
	irqInit();
	irqEnable(IRQ_VBLANK);
    
	// initialize gl
	glInit();
    
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewPort(0,0,255,191);
    
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(35, 256.0 / 192.0, 0.1, 100);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up

	while(1)		
	{
        float px, py;
        
    	pos = touchReadXY();
        px = pos.px;
        py = pos.py;

        px = (px * 5) / 256;
        py = (py * 3) / 192;

        px -= 2.5;
        py -= 1.5;

		glPushMatrix();

		//move it away from the camera
		glTranslate3f32(0, 0, floattof32(-1));

		glRotateX(rotateX);
		glRotateY(rotateY);

		glMatrixMode(GL_MODELVIEW);

		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
        
		scanKeys();
		
		u16 keys = keysHeld();
		
		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;
        
		//draw the obj
		glBegin(GL_TRIANGLE);
			
			glColor3b(255,0,0);
			glVertex3v16(inttov16(-1),inttov16(-1),0);

			glColor3b(0,255,0);
			glVertex3v16(inttov16(1), inttov16(-1), 0);

			glColor3b(0,0,255);
			glVertex3v16(inttov16(0), inttov16(1), 0);
			
		glEnd();

        glLoadIdentity();
        glTranslatef(px,-py,-3.0);
        glBegin(GL_TRIANGLE);
            glVertex3f( 0.0, 1.0, 0.0);
            glVertex3f(-1.0,-1.0, 0.0);
            glVertex3f( 1.0,-1.0, 0.0);
        glEnd();

		glPopMatrix(1);

		glFlush(0);
		swiWaitForVBlank();
	}

	return 0;
}//end main 
Ejemplo n.º 8
0
//---------------------------------------------------------------------------------
// Updates the Rubik's Cube, called once per frame. The general workhorse function
// of the class. Handles Grabbing/Twisting, and calls the Draw() function.
//---------------------------------------------------------------------------------
void RubiksCube::Update(bool moving, touchPosition touchXY, VECTOR touchVector, bool painting, int colour)
{
	Painting=painting;
	paintColour=colour;
	if(!painting)
	{
		undoQueue.numEntries=0;
		undoQueue.currentEntry=-1;
	}
	// somehow stumbled onto a good way to handle Twisting using states
	// F**K TOP-DOWN PLANNING; PROTOTYPING FTW!
	if (moving && !Grabbing && !Twisting)
	{
		Picking=true;
	}
	if(!moving)
	{
		if(Twisting)
		{
			if(Twist.rotation%90>=45) Twist.direction=true;
			else Twist.direction=false;
			TwistAgain();
		}
		Picking=false;
		Grabbing=false;
		Twisting=false;
	}

	if(AutoTwisting)
		TwistAgain();

	if((!AutoTwisting) && Scrambling)
	{
		//printf("(!AutoTwisting) && Scrambling\n");
		AutoTwist(rand()%3, rand()%3, !(!(rand()%2)));
	}
	
	if((!AutoTwisting) && Solving)
	{
		int tmp = solver.mov[0]-solvecount;
		AutoTwist(solution[tmp][0], solution[tmp][1], (!(!solution[tmp][2])));
	}

	
	if(Twisting)
	{
		int32 touchVf32[3];
		int32 twistVf32[3];
		
		touchVf32[0]=floattof32(touchVector.X*twistSensitivity);
		touchVf32[1]=floattof32(touchVector.Y*twistSensitivity);
		touchVf32[2]=0;
		
		twistVf32[0]=Twist.vector[0];
		twistVf32[1]=Twist.vector[1];
		twistVf32[2]=0;
		
		int32 twistyness = dotf32(twistVf32, touchVf32);
		Twist.rotation+=f32toint(twistyness);
		if (Twist.rotation<0)
			Twist.rotation+=360;
	}
	
	//move the cube
	glRotateX(ry);
	glRotateY(rx);
	
	
	if(Grabbing) Grab(touchVector);
	
	Draw(touchXY);
}
Ejemplo n.º 9
0
int main() {

	int rotateX = 0;
	int rotateY = 0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	// intialize gl
	glInit();
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewport(0,0,255,191);

	vramSetBankA(VRAM_A_TEXTURE);
	glEnable(GL_TEXTURE_2D);
	
	int cafe_texid;
	glGenTextures( 1, &cafe_texid );
	glBindTexture( 0, cafe_texid );
	glTexImage2D( 0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, GL_TEXTURE_WRAP_S|GL_TEXTURE_WRAP_T|TEXGEN_NORMAL, (u8*)cafe_bin );

	
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 40);
	
	while(1) {
		//TEXGEN_NORMAL helpfully pops our normals into this matrix and uses the result as texcoords
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		GLvector tex_scale = { 64<<16, -64<<16, 1<<16 };
		glScalev( &tex_scale );		//scale normals up from (-1,1) range into texcoords
		glRotateXi(rotateX);		//rotate texture-matrix to match the camera
		glRotateYi(rotateY);


		glMatrixMode(GL_POSITION);
		glLoadIdentity();
		glTranslatef32(0, 0, floattof32(-3));
		glRotateXi(rotateX);
		glRotateYi(rotateY);

		glMaterialf(GL_EMISSION, RGB15(31,31,31));

		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK );

		scanKeys();
		u32 keys = keysHeld();

		if( keys & KEY_UP ) rotateX += 3<<3;
		if( keys & KEY_DOWN ) rotateX -= 3<<3;
		if( keys & KEY_LEFT ) rotateY += 3<<3;
		if( keys & KEY_RIGHT ) rotateY -= 3<<3;

		int pen_delta[2];
		get_pen_delta( &pen_delta[0], &pen_delta[1] );
		rotateY -= pen_delta[0];
		rotateX -= pen_delta[1];


		glBindTexture( 0, cafe_texid );
		glCallList((u32*)teapot_bin);

		glFlush(0);
	}

	return 0;
}//end main
Ejemplo n.º 10
0
int App_Test::start()
{
    int code_out = 0;

    this->model_animated[ 0] = (u8 *)heavy_walk_01_bin;
    this->model_animated[ 1] = (u8 *)heavy_walk_02_bin;
    this->model_animated[ 2] = (u8 *)heavy_walk_03_bin;
    this->model_animated[ 3] = (u8 *)heavy_walk_04_bin;
    this->model_animated[ 4] = (u8 *)heavy_walk_05_bin;
    this->model_animated[ 5] = (u8 *)heavy_walk_06_bin;
    this->model_animated[ 6] = (u8 *)heavy_walk_07_bin;
    this->model_animated[ 7] = (u8 *)heavy_walk_08_bin;
    this->model_animated[ 8] = (u8 *)heavy_walk_09_bin;
    this->model_animated[ 9] = (u8 *)heavy_walk_10_bin;
    this->model_animated[10] = (u8 *)heavy_walk_11_bin;
    this->model_animated[11] = (u8 *)heavy_walk_12_bin;
    this->model_animated[12] = (u8 *)heavy_walk_13_bin;
    this->model_animated[13] = (u8 *)heavy_walk_14_bin;
    this->model_animated[14] = (u8 *)heavy_walk_15_bin;
    this->model_animated[15] = (u8 *)heavy_walk_16_bin;
    this->model_animated[16] = (u8 *)heavy_walk_17_bin;
    this->model_animated[17] = (u8 *)heavy_walk_18_bin;
    this->model_animated[18] = (u8 *)heavy_walk_19_bin;
    this->model_animated[19] = (u8 *)heavy_walk_20_bin;
    this->model_animated[20] = (u8 *)heavy_walk_21_bin;
    this->model_animated[21] = (u8 *)heavy_walk_22_bin;
    this->model_animated[22] = (u8 *)heavy_walk_23_bin;
    this->model_animated[23] = (u8 *)heavy_walk_24_bin;
    this->model_animated[24] = (u8 *)heavy_walk_25_bin;
    this->model_animated[25] = (u8 *)heavy_walk_26_bin;
    this->model_animated[26] = (u8 *)heavy_walk_27_bin;
    this->model_animated[27] = (u8 *)heavy_walk_28_bin;
    this->model_animated[28] = (u8 *)heavy_walk_29_bin;
    this->model_animated[29] = (u8 *)heavy_walk_30_bin;
    this->model_animated[30] = (u8 *)heavy_walk_31_bin;
    this->model_animated[31] = (u8 *)heavy_walk_32_bin;
    this->model_animated[32] = (u8 *)heavy_walk_33_bin;
    this->model_animated[33] = (u8 *)heavy_walk_34_bin;
    this->model_animated[34] = (u8 *)heavy_walk_35_bin;
    this->model_animated[35] = (u8 *)heavy_walk_36_bin;
    this->model_animated[36] = (u8 *)heavy_walk_37_bin;
    this->model_animated[37] = (u8 *)heavy_walk_38_bin;
    this->model_animated[38] = (u8 *)heavy_walk_39_bin;
    this->model_animated[39] = (u8 *)heavy_walk_40_bin;



    //Animations variables
	this->frame = 0;
    this->max_frame = 40;

	//Debug variables for animations
	int32 test_time = 0; 
 
	this->xrot = 0.0f;
    this->yrot = 0.0f;
    this->zrot = 0.0f;

    this->p_mgr_display->setup_screen();

    this->target.set_vec_ox(0);
    this->target.set_vec_oy(0);
    this->target.set_vec_oz(0);

    this->camera.setLookAt(CAMERA_MODE_TARGET,&(this->target));
    this->camera.computeLookAt();
	this->camera.dist_from_target = floattof32(23);
    this->p_mgr_display->set_camera(&(this->camera));

    this->p_mgr_display->init();
    this->load_Texture();

    this->app_running = 1;
    this->p_mgr_system->reset_timer();

	this->animation_pause = 1;	

    glSetToonTableRange( 0, 8, RGB15(8,8,8) );
    glSetToonTableRange( 8, 10, RGB15(12,12,12) );
    glSetToonTableRange( 10, 13, RGB15(16,16,16) );
    glSetToonTableRange( 13, 31, RGB15(31,31,31) );

	//glEnable(GL_TOON_HIGHLIGHT);
    while(this->app_running)
    {
        this->process_inputs();
        //printf("%d\n",this->p_mgr_system->last_millisec);
        //this->camera.setStep(this->p_mgr_system->last_millisec); // TODO : init and use millisec pointer within Model_Camera
        this->camera.setStep(17); // TODO : init and use millisec pointer within Model_Camera

        //Animations step calculation
        //this->frame += mulf32(this->frame_speed,this->p_mgr_system->last_millisec);
		if (!this->animation_pause) this->frame+= test_time;
		else this->frame=0;
        if (this->frame >= this->max_frame) this->frame = this->frame - this->max_frame;
		
		this->model_selected = this->model_animated[this->frame];
        //Start Display

        this->p_mgr_display->begin_3D();

        this->display_Model();

        this->p_mgr_display->end_3D();

        this->p_mgr_display->flush_display();
        //End Display

        iprintf("\x1b[2J");
        iprintf("\x1b[1;0Hframe  = %d\n",this->frame);
	    iprintf("\x1b[2;0Htest_timer  = %d\n",timerElapsed(0));
	    iprintf("\x1b[3;0Htest_ms  = %d\n",test_time);

		swiIntrWait(IRQ_TIMER0,1);
	    iprintf("\x1b[5;0H Timer ok\n");
		test_time = this->p_mgr_system->last_millisec;
        this->p_mgr_system->reset_timer();

//        printf("dst_from_target = %f\n",f32tofloat(this->camera.dist_from_target));
		swiWaitForVBlank(); 

    }

    return code_out;

}
Ejemplo n.º 11
0
int main(void)
{
    float x_angle = 0, y_angle = 0;
    float x_speed = 0, y_speed = 0;
    float distance = 1;

    powerON(POWER_ALL);
    irqInit();
    irqEnable(IRQ_VBLANK);
    videoSetMode(MODE_0_3D);
    consoleDemoInit();

    /* Set up a timer to count FPS */
    TIMER3_DATA = TIMER_FREQ_1024(1);
    TIMER3_CR = TIMER_DIV_1024 | TIMER_IRQ_REQ;
    irqSet(IRQ_TIMER3, fps_timer_irq);
    irqEnable(IRQ_TIMER3);

    glViewPort(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1);
    glClearColor(0, 0, 0);
    glClearDepth(GL_MAX_DEPTH);

    iprintf("Hello World!\n\n");

    glReset();
    gluPerspective(35, SCREEN_WIDTH / (float) SCREEN_HEIGHT, 0.1, 40.0);
    gluLookAt(0.0, 0.0, 1.0,   /* Eye */
	      0.0, 0.0, 0.0,   /* Look at */
	      0.0, 1.0, 0.0);  /* Up */

    glMaterialf(GL_AMBIENT, RGB15(8,8,8));
    glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
    glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
    glMaterialf(GL_EMISSION, RGB15(5,5,5));
    glMaterialShinyness();
    glColor(RGB15(31, 31, 31));

    glLight(0, RGB15(20, 15, 15),
	    floattov10(-0.9),
	    floattov10( 0.9),
	    floattov10( 0.2));

    glLight(1, RGB15(15, 15, 20),
	    floattov10( 0.4),
	    floattov10( 0.9),
	    floattov10( 0.2));

    glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK |
	      POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1);

    while (1) {
	scanKeys();
	if (keysHeld() & KEY_START)  Loader_Exit9();
	if (keysHeld() & KEY_UP)     x_speed += 0.05;
	if (keysHeld() & KEY_DOWN)   x_speed -= 0.05;
	if (keysHeld() & KEY_LEFT)   y_speed += 0.05;
	if (keysHeld() & KEY_RIGHT)  y_speed -= 0.05;
	if (keysHeld() & KEY_R)      distance += 0.05;
	if (keysHeld() & KEY_L)      distance -= 0.05;

	glPushMatrix();

	glTranslate3f32(floattof32( 0.0),
			floattof32( 0.0),
			floattof32(-distance));

	glRotateX(x_angle += x_speed);
	glRotateY(y_angle += y_speed);

	glCallList(display_list_bin);

	glPopMatrix(1);

	glFlush();
	frames++;
	swiWaitForVBlank();
    }

    return 0;
}
Ejemplo n.º 12
0
void Map2D::Draw( const glImage *Tiles )
{
	
	
	glPushMatrix();
	
	glPolyFmt( POLY_ALPHA(31) | POLY_CULL_FRONT | POLY_ID( GlobalManager::Instance()->GetFreePolyID() ) );
	
	for( int y = 0; y < Height; y++ )
	{
		for( int x = 0; x < Width ; x++ )
		{
			
			int Tile = GetElement(x,y);
			switch( Tile )
			{
				case BRICK:
					// offset by 0.5 so that (0,0) is top left of tile like standard 2D
					DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[8] );
					break;
				case TOP_BRICK:
					DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] );
					break;
				case TOP_BRICK_MOSS_TOP:
					DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[0] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D,  10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[11] );
					break;
				case BRICK_MOSS_BOTTOM:
					DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[8] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D,  10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[3] );
					break;
				case SOFT_BRICK:
					// offset by 0.5 so that (0,0) is top left of tile like standard 2D
					DrawCube( x * TILE_SIZE_3D + floattof32(0.5), y * TILE_SIZE_3D + floattof32(0.5), 0, &Tiles[13] );
					break;
				case SPIKE:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D,               0, GL_FLIP_NONE, &Tiles[2] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D,  TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] );
					break;
				case INVISIBLE:
					//glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, -TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[2] );
					break;
				case LADDER:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[1] );
					break;
				case TOP_LADDER:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[1] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[1] );
					break;
				case TOP_LADDER_HANDLE:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, -64, GL_FLIP_NONE, &Tiles[9] );
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[9] );
					break;
				case SIGN:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[10] );
					break;
				case MOSS_BOTTOM:
					glSprite3D( x * TILE_SIZE_3D, y  * TILE_SIZE_3D, 10 + TILE_SIZE_3D/2, GL_FLIP_NONE, &Tiles[3] );
					break;
					
			}
			
		}	
	}
	
	glPopMatrix(1);
	
}
Ejemplo n.º 13
0
void TunnelPartInit(void)
{
	T_Mesh* mesh;
	int i;
	
	/* 
	 * Initialisation vidéo
	 */ 
	/* Modes video */
	videoSetMode(MODE_5_3D);
	videoSetModeSub(MODE_5_2D);
	lcdMainOnBottom();
	
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
	vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
	vramSetBankC(VRAM_C_SUB_BG_0x06200000);
	vramSetBankD(VRAM_D_TEXTURE_SLOT3);
	
	videoBgEnable(DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE);
	videoBgEnableSub(DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
	
	/* Le BG qui servira pour le tunnel */
	TunnelBgId = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
	TunnelBgPixels = (u16*)bgGetGfxPtr(TunnelBgId);
	bgSetPriority(TunnelBgId, 2); /* Le tunnel en fond */

	/* L'avant plan de l'éléphant */	
	FrontLayerId = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 8, 0);
	FrontLayerPixels = (u8*)bgGetGfxPtr(FrontLayerId);
	bgSetPriority(FrontLayerId, 0); /* En avant plan */
	decompress(bouleBitmap, FrontLayerPixels, LZ77Vram);
	decompress(boulePal, BG_PALETTE, LZ77Vram); 
	
	bgSetPriority(0, 1); /* La 3D entre les deux */
	
	
	/* Initialisation de la 3D */
    Init3DEngine();
    
	TunnelFxInit(TunnelBgPixels);
	        
    mesh = CreateMesh();
    mesh->display_list = DiscoElephant_mesh;
    mesh->alpha = 31;
    mesh->texturing = TRUE;
    mesh->lighting = TRUE;
    DiscoElephant = CreateObj3D(mesh);
    Scene = CreateScene();
    AddObject(Scene, DiscoElephant);
    
    Scene->lights[0] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 0, 01), TRUE);
    Scene->lights[1] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 16, 0), TRUE);
    Scene->lights[2] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(0, 0, 16), TRUE);
    Scene->lights[3] = CreateLight(floattov10(0), floattov10(0), floattov10(-1), RGB15(16, 16, 0), TRUE);
    
    glClearColor(0, 0, 0, 0);
    
    flare_tex = CreateTextureFromMemory((u8*)flareBitmap, GL_RGBA, 0, 16, 64, TRUE, LZ77Vram);
    
    for(i=0; i<4; i++) {
    	flares[i] = malloc(sizeof(*flares[i]));
    }
    
    flares[0]->position[0] = 0;
    flares[0]->position[1] = 0;
    flares[0]->position[2] = floattof32(-1);
    flares[0]->poly_alpha = 16;
    flares[0]->color = RGB15(31, 0, 0);
    flares[0]->size = floattov16(0.15f);
    flares[0]->texture_id = flare_tex->id;
    flares[0]->poly_id = 5;
    
    flares[1]->position[0] = 0;
    flares[1]->position[1] = 0;
    flares[1]->position[2] = floattof32(-1);
    flares[1]->poly_alpha = 16;
    flares[1]->color = RGB15(0, 31, 0);
    flares[1]->size = floattov16(0.15f);
    flares[1]->texture_id = flare_tex->id;
    flares[1]->poly_id = 6;
    
    flares[2]->position[0] = 0;
    flares[2]->position[1] = 0;
    flares[2]->position[2] = floattof32(-1);
    flares[2]->poly_alpha = 16;
    flares[2]->color = RGB15(0, 0, 31);
    flares[2]->size = floattov16(0.15f);
    flares[2]->texture_id = flare_tex->id;
    flares[2]->poly_id = 6;
    
    flares[3]->position[0] = 0;
    flares[3]->position[1] = 0;
    flares[3]->position[2] = floattof32(-1);
    flares[3]->poly_alpha = 16;
    flares[3]->color = RGB15(31, 31, 0);
    flares[3]->size = floattov16(0.15f);
    flares[3]->texture_id = flare_tex->id;
    flares[3]->poly_id = 7;
    
    tex = CreateTextureFromMemory((u8*)DiscoElephantBitmap, GL_RGB, 0, 16, 64, TRUE, LZ77Vram);
    DiscoElephant->mesh->texture_id = tex->id;
    DiscoElephant->mesh->texturing = TRUE;
    
	/* Initialisation du fade in depuis le blanc */
	REG_MASTER_BRIGHT = (1<<14);
	REG_MASTER_BRIGHT_SUB = REG_MASTER_BRIGHT;
	
	StartFlash(-1000); // pour éviter un flash à la première seconde
	
	glMaterialf(GL_AMBIENT, RGB15(16,16,16));
    glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31));
	glMaterialShinyness();
}
Ejemplo n.º 14
0
void Camera::Follow( s32 x, s32 y, int signx, int signy, s32 &offx, s32 &offy, Map2D &Map )
{
	
	const int MAX_X = floattof32(2.0);  // Max rotation
	const int MAX_Y = floattof32(4.0);  // Max rotation
	static s32 xoff = 0;
	static s32 yoff = 0;
	
	int MAP_WID = Map.GetWidth();
	int MAP_HEI = Map.GetHeight();


	if( signx > 0 )
	{
		if( xoff < MAX_X ) xoff += floattof32(0.04);  
	}
	else if( signx < 0 )
	{
		if( xoff > -MAX_X ) xoff -= floattof32(0.04);
	}
	else  // 0
	{
		if( xoff > 0 ) xoff -= floattof32(0.02);
		if( xoff < 0 ) xoff += floattof32(0.02);
	}
	
	if( signy > 0 )
	{
		if( yoff < MAX_Y ) yoff += floattof32(0.04);  
	}
	else if( signy < 0 )
	{
		if( yoff > -MAX_Y ) yoff -= floattof32(0.04);
	}
	else  // 0
	{
		if( yoff > 0 ) yoff -= floattof32(0.08);
		if( yoff < 0 ) yoff += floattof32(0.08);
	}
	

	// Calculate limits
	s32 MinX = ( TILE_SIZE_3D /2 ) + (( SCREEN_WIDTH * TILE_SIZE_3D) / TILE_SIZE) / 2;
	s32 MinY = ( TILE_SIZE_3D /2 ) + (( SCREEN_HEIGHT * TILE_SIZE_3D) / TILE_SIZE) / 2;
	s32 MaxX = (MAP_WID * TILE_SIZE_3D) - MinX;
	s32 MaxY = (MAP_HEI * TILE_SIZE_3D) - MinY;;
	
	x += xoff;
	y += yoff;
	// limit
	if( x < MinX ) x = MinX;
	if( y < MinY ) y = MinY;
	if( x > MaxX ) x = MaxX;
	if( y > MaxY ) y = MaxY;
	
	
	Position.x = x;
	Position.y = y;
	Position.z = EyeDistanceFromScreen;       // move zpos 15 units from screen to eye
	
	Target.x = x;
	Target.y = y;
	Target.z = 0 << 12;
	
	Up.x = 0 << 12;
	Up.y = 1 << 12;
	Up.z = 0 << 12;
	
	offx = xoff;
	offy = yoff;
	
}
Ejemplo n.º 15
0
void RubiksCube::Grab(VECTOR touchVector)
{
	tvf32[0]+=floattof32(touchVector.X);
	tvf32[1]+=floattof32(touchVector.Y);
	tvf32[2]=0;
	if(f32toint(sqrtf32(mulf32(tvf32[0],tvf32[0])+mulf32(tvf32[1],tvf32[1])+mulf32(tvf32[2],tvf32[2])))>5)
	{
		VECTOR upv, rightv, rotduv, rotdrv;
		int32 uvf32[3];//up vector as f32
		int32 rvf32[3];//right vector
		int32 magup, magright;
		m4x4 grabMatrix;//container for the Position Matrix

		vectorFromSide(upv, rightv, clicked[0]);
		//printf ("Initial Vector:\n %f, ", tmpv.X);
		//printf("%f, ", tmpv.Y);
		//printf("%f\n", tmpv.Z);
		glGetFixed(GL_GET_MATRIX_POSITION, (int32*)&grabMatrix);
		glMatrixMode(GL_MODELVIEW);
		//rotate the up vector thru the projection matrix
		//and cast it to f32
		RotateVector(grabMatrix, upv, rotduv);
		uvf32[0]=floattof32(rotduv.X);
		uvf32[1]=floattof32(rotduv.Y);
		uvf32[2]=floattof32(rotduv.Z);
		//rinse and repeat with the right vector
		RotateVector(grabMatrix, rightv, rotdrv);
		rvf32[0]=floattof32(rotdrv.X);
		rvf32[1]=floattof32(rotdrv.Y);
		rvf32[2]=floattof32(rotdrv.Z);

		if(controlStyle)
		{
			int32 suvf32[3];
			int32 srvf32[3];
			suvf32[0]=0;
			suvf32[1]=inttof32(1);
			suvf32[2]=0;
			srvf32[0]=inttof32(1);
			srvf32[1]=0;
			srvf32[2]=0;

			magup=dotf32(uvf32, suvf32);
			magright=dotf32(uvf32, srvf32);
			if(abs(magup)>abs(magright))
			{
				for(int i=0; i<3; i++)
				{
					if(magup>0)
					{
						rvf32[i]=srvf32[i];
						uvf32[i]=suvf32[i];
					}
					else
					{
						rvf32[i]=-srvf32[i];
						uvf32[i]=-suvf32[i];
					}
				}
			} else {
				for(int i=0; i<3; i++)
				{
					if(magright>0)
					{
						uvf32[i]=srvf32[i];
						rvf32[i]=-suvf32[i];
					}
					else
					{
						uvf32[i]=-srvf32[i];
						rvf32[i]=suvf32[i];
					}
				}
			}

		}
		
		magup=dotf32(uvf32, tvf32);
		magright=dotf32(rvf32, tvf32);
		
		if(magup || magright)
		{
			int32 tmp[2];
			if(abs(magup)>abs(magright))
			{
				tmp[0]=uvf32[0];
				tmp[1]=uvf32[1];
				unitVector((int32*)tmp);
				InitTwist(true, tmp);
			}else{
				tmp[0]=rvf32[0];
				tmp[1]=rvf32[1];
				unitVector((int32*)tmp);
				InitTwist(false, tmp);
			}
			Twisting=true;
			Grabbing=false;
			tvf32[0]=0;
			tvf32[1]=0;
		}
	}
}
Ejemplo n.º 16
0
int main()
{	

	// initialize gl
	glInit();

	u32 rotateX = 0;
	u32 rotateY = 0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);
	
	// used to hold touched position
	touchPosition touchXY;
	
	lcdMainOnBottom(); // we are going to be touching the 3D display

	
	// enable edge outlining, this will be used to show which object is selected
	glEnable(GL_OUTLINE);
	
	//set the first outline color to white
	glSetOutlineColor(0,RGB15(31,31,31));
	
	int viewport[]={0,0,255,191}; // used later for gluPickMatrix()
	
	// setup the rear plane
	glClearColor(0,0,0,0); // set BG to black and clear
	glClearPolyID(0); // the BG and polygons will have the same ID unless a polygon is highlighted
	glClearDepth(0x7FFF);
	
	// setup the camera
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up
	
	glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0); // setup the light
	
	while(1) {
		// handle key input
		scanKeys();
		u16 keys = keysHeld();
		if(!(keys & KEY_UP)) rotateX += 3;
		if(!(keys & KEY_DOWN)) rotateX -= 3;
		if(!(keys & KEY_LEFT)) rotateY += 3;
		if(!(keys & KEY_RIGHT)) rotateY -= 3;
		
		// get touchscreen position
		touchRead(&touchXY);
		
		glViewport(0,0,255,191); // set the viewport to fullscreen
		
		// setup the projection matrix for regular drawing
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(60, 256.0 / 192.0, 0.1, 20); 
		
		glMatrixMode(GL_MODELVIEW); // use the modelview matrix while drawing
		
		glPushMatrix(); // save the state of the current matrix(the modelview matrix)
		{
			glTranslatef32(0,0,floattof32(-6));
			glRotateXi(rotateX); // add X rotation to the modelview matrix
			glRotateYi(rotateY); // add Y rotation to the modelview matrix
			
			glPushMatrix(); // save the state of the modelview matrix while making the first pass
			{ 
				// draw the scene for displaying
				
				glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location
				if(clicked==CONE) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)cone_bin); // draw a green cone from a predefined packed command list
				
				
				glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location
				if(clicked==CYLINDER) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)cylinder_bin); // draw a blue cylinder from a predefined packed command list
				
				
				glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location
				if(clicked==SPHERE) {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(1)); // set a poly ID for outlining
				} else {
					glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_ID(0)); // set a poly ID for no outlining (same as BG)
				}
				glCallList((u32*)sphere_bin); // draw a red sphere from a predefined packed command list

			}
			glPopMatrix(1); // restores the modelview matrix to where it was just rotated
			
			// draw the scene again for picking
			{
				
				clicked = NOTHING; //reset what was clicked on
				closeW = 0x7FFFFFFF; //reset the distance
				
				//set the viewport to just off-screen, this hides all rendering that will be done during picking
				glViewport(0,192,0,192);
				
				// setup the projection matrix for picking
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only what is below the cursor
				gluPerspective(60, 256.0 / 192.0, 0.1, 20); // this must be the same as the original perspective matrix
				
				glMatrixMode(GL_MODELVIEW); // switch back to modifying the modelview matrix for drawing
				
				glTranslatef32(floattof32(2.9),floattof32(0),floattof32(0)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)cone_bin); // draw a cone from a predefined packed command list
				endCheck(CONE);
				
				glTranslatef32(floattof32(-3),floattof32(1.8),floattof32(2)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)cylinder_bin); // draw a cylinder from a predefined packed command list
				endCheck(CYLINDER);
				
				glTranslatef32(floattof32(.5),floattof32(-2.6),floattof32(-4)); // translate the modelview matrix to the drawing location
				startCheck();
				glCallList((u32*)sphere_bin); // draw a sphere from a predefined packed command list
				endCheck(SPHERE);
			}
			
		}
		glPopMatrix(1); // restores the modelview matrix to its original state
		
		glFlush(0); // wait for everything to be drawn before starting on the next frame
	}

	return 0;
}//end main 
Ejemplo n.º 17
0
/******************************************************************************
*******************************************************************************

	Fuzed DS
	relminator
	http://rel.phatcode.net


*******************************************************************************
******************************************************************************/

#include "VectorSpring.h"

static const s32 FORCE = floattof32(1);    // Arbitrary force constant
static const s32 FRICTION = floattof32(0.949996);	// Damping for spring
static const int MAGNITUDE = 5;		// Arbirtarry distance kinda work like dt(deltatime) increase = faster springs

// Force should have been F = -K * X or F = -K * ( Length - Restlength)
// But meh, this is faster and works just as well

VectorSpring::VectorSpring()
{

	x = 0;
	y = 0;
	xv = 0;
	yv = 0;
	ox = 0;
	oy = 0;
	Force = FORCE;
	Friction = FRICTION;
Ejemplo n.º 18
0
int main()
{	
	
	int textureID;
	int i;
	float rotateX = 0.0;
	float rotateY = 0.0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	// initialize gl
	glInit();
	
	//enable textures
	glEnable(GL_TEXTURE_2D);
	
	//this should work the same as the normal gl call
	glViewport(0,0,255,191);
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	vramSetBankB(VRAM_B_LCD);
	REG_DISPCAPCNT = 
			DCAP_MODE(DCAP_MODE_BLEND) //blend source A and source B
		//|	DCAP_SRC_ADDR //this is not used since we are setting the display to render from VRAM
		|	DCAP_SRC_B(DCAP_SRC_B_VRAM)
		|	DCAP_SRC_A(DCAP_SRC_A_3DONLY)
		|	DCAP_SIZE(DCAP_SIZE_256x192)
		|	DCAP_OFFSET(0) //where to write the captured data within our chosen VRAM bank
		|	DCAP_BANK(DCAP_BANK_VRAM_B)
		|	DCAP_B(12) //blend mostly from B to make a very dramatic effect
		|	DCAP_A(4) //and blend only a little bit from the new scene
		;
	//but, dramatic effects tend to leave some garbage on the screen since the precision of the math is low,
	//and we're not putting a lot of dampening on the effect.
	//a more realistic value might be 8 and 8, but perhaps in a more complex 3d scene the garbage isn't such a bad thing
	//since the scene is changing constantly

	DisplayEnableMotionBlur();
	bool displayBlurred = true;


	vramSetBankA(VRAM_A_TEXTURE);

	glGenTextures(1, &textureID);
	glBindTexture(0, textureID);
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);
	
	
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 40);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up
	
	while(1) {
		
		glLight(0, RGB15(31,31,31) , 0,				  floattov10(-1.0),		 0);
		glLight(1, RGB15(31,0,31),   0,				  floattov10(1) - 1,			 0);
		glLight(2, RGB15(0,31,0) ,   floattov10(-1.0), 0,					 0);
		glLight(3, RGB15(0,0,31) ,   floattov10(1.0) - 1,  0,					 0);

		glPushMatrix();

		//move it away from the camera
		glTranslatef32(0, 0, floattof32(-1));
				
		glRotateX(rotateX);
		glRotateY(rotateY);
		
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		
		glMatrixMode(GL_MODELVIEW);

		glMaterialf(GL_AMBIENT, RGB15(8,8,8));
		glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
		glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
		glMaterialf(GL_EMISSION, RGB15(5,5,5));

		//ds uses a table for shinyness..this generates a half-ass one
		glMaterialShinyness();

		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | 
													POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ;
		
		scanKeys();
		
		u16 keys = keysHeld();
		
		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;

		if(keysDown() & KEY_A)
		{
			displayBlurred = !displayBlurred;
			if(displayBlurred)
				DisplayEnableMotionBlur();
			else 
				DisplayEnableNormal();
		}
		
		glBindTexture(0, textureID);

		//draw the obj
		glBegin(GL_QUAD);
			for(i = 0; i < 6; i++)
				drawQuad(i);
		
		glEnd();
		
		glPopMatrix(1);
			
		glFlush(0);

		swiWaitForVBlank();

		if(keys & KEY_START) break;

		//the display capture enable bit must be set again each frame if you want to continue capturing.
		REG_DISPCAPCNT |= DCAP_ENABLE;
	}

	return 0;
}//end main 
Ejemplo n.º 19
0
int main()
{

	float rotateX = 0.0;
	float rotateY = 0.0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	// initialize gl
	glInit();
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewport(0,0,255,191);

	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 40);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up

	while(1)
	{
		glPushMatrix();

		//move it away from the camera
		glTranslatef32(0, 0, floattof32(-1));

		glRotateX(rotateX);
		glRotateY(rotateY);


		glMatrixMode(GL_MODELVIEW);



		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);

		scanKeys();

		u16 keys = keysHeld();

		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;

		//draw the obj
		glBegin(GL_QUAD);

			glColor3b(255,0,0);
			glVertex3v16(inttov16(-1),inttov16(-1),0);

			glColor3b(0,255,0);
			glVertex3v16(inttov16(1), inttov16(-1), 0);

			glColor3b(0,0,255);
			glVertex3v16(inttov16(1), inttov16(1), 0);

			glColor3b(255,0,255);
			glVertex3v16(inttov16(-1), inttov16(1), 0);

		glEnd();

		glPopMatrix(1);

		glFlush(0);

		swiWaitForVBlank();

		if(keys & KEY_START) break;
	}

	return 0;
}//end main
Ejemplo n.º 20
0
int main() {	
	
	int textureID;

	float rotateX = 0.0;
	float rotateY = 0.0;

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	// initialize gl
	glInit();
	
	//enable textures
	glEnable(GL_TEXTURE_2D);
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewport(0,0,255,191);
	
	vramSetBankA(VRAM_A_TEXTURE);

	glGenTextures(1, &textureID);
	glBindTexture(0, textureID);
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);
	
	
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 40);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up	
	
	while(1) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();

		//move it away from the camera
		glTranslate3f32(0, 0, floattof32(-1));
				
		glRotateX(rotateX);
		glRotateY(rotateY);
		
		

		glMaterialf(GL_AMBIENT, RGB15(16,16,16));
		glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
		glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
		glMaterialf(GL_EMISSION, RGB15(16,16,16));

		//ds uses a table for shinyness..this generates a half-ass one
		glMaterialShinyness();

		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK);

		scanKeys();
		
		u16 keys = keysHeld();
		
		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;
		
		glBindTexture(0, textureID);

		//draw the obj
		glBegin(GL_QUAD);
			glNormal(NORMAL_PACK(0,inttov10(-1),0));

			GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(128)));
			glVertex3v16(floattov16(-0.5),	floattov16(-0.5), 0 );
	
			GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128),inttot16(128)));
			glVertex3v16(floattov16(0.5),	floattov16(-0.5), 0 );
	
			GFX_TEX_COORD = (TEXTURE_PACK(inttot16(128), 0));
			glVertex3v16(floattov16(0.5),	floattov16(0.5), 0 );

			GFX_TEX_COORD = (TEXTURE_PACK(0,0));
			glVertex3v16(floattov16(-0.5),	floattov16(0.5), 0 );
		
		glEnd();
		
		glPopMatrix(1);
			
		glFlush(0);

		swiWaitForVBlank();
	}

	return 0;
}//end main