示例#1
0
static gxCanvas *tformCanvas( gxCanvas *c,float m[2][2],int x_handle,int y_handle ){

	vec2 v,v0,v1,v2,v3;
	float i[2][2];
	float dt=1.0f/(m[0][0]*m[1][1]-m[1][0]*m[0][1]);
	i[0][0]=dt*m[1][1];i[1][0]=-dt*m[1][0];
	i[0][1]=-dt*m[0][1];i[1][1]=dt*m[0][0];

	float ox=x_handle,oy=y_handle;
	v0.x=-ox;v0.y=-oy;	//tl
	v1.x=c->getWidth()-ox;v1.y=-oy;	//tr
	v2.x=c->getWidth()-ox;v2.y=c->getHeight()-oy;	//br
	v3.x=-ox;v3.y=c->getHeight()-oy;	//bl
	v0=vrot(m,v0);v1=vrot(m,v1);v2=vrot(m,v2);v3=vrot(m,v3);
	float minx=floor( vmin( v0.x,v1.x,v2.x,v3.x ) );
	float miny=floor( vmin( v0.y,v1.y,v2.y,v3.y ) );
	float maxx=ceil( vmax( v0.x,v1.x,v2.x,v3.x ) );
	float maxy=ceil( vmax( v0.y,v1.y,v2.y,v3.y ) );
	int iw=maxx-minx,ih=maxy-miny;

	gxCanvas *t=gx_graphics->createCanvas( iw,ih,0 );
	t->setHandle( -minx,-miny );
	t->setMask( c->getMask() );

	c->lock();
	t->lock();

	v.y=miny+.5f;
	for( int y=0;y<ih;++v.y,++y ){
		v.x=minx+.5f;
		for( int x=0;x<iw;++v.x,++x ){
			vec2 q=vrot(i,v);
			unsigned rgb=filter ? getPixel( c,q.x+ox,q.y+oy ) : c->getPixel( floor(q.x+ox),floor(q.y+oy) );
			t->setPixel( x,y,rgb );
		}
	}

	t->unlock();
	c->unlock();

	return t;
}
示例#2
0
文件: Game.cpp 项目: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,
					  vec4(0,0,0,1),
					  vec4(0,0,0,1),
					  vec4(0,0,0,0),
					  50.0f,
					  500.0f,
					  90.0f,
					  WINDOW_WIDTH,
					  WINDOW_HEIGHT);

	// all your initialization code goes here...
	vec4 vscale(5.0,5.0,5.0,1),  // scale of object
		vpos(0,0,0,1),        // position of object
		vrot(0,0,0,1);        // initial orientation of object

	// load the cube
	_obj.LoadPLG("../../assets/t3d/cube2.plg", &vscale, &vpos, &vrot);

	// set the position of the cube in the world
	_obj.SetWorldPos(0, 0, 100);
}
示例#3
0
static void update(sprite_t *s)
{
	float v[2],x,pull[2];
	mech_sprite_t *ms = (mech_sprite_t *)s;

	sprite_get_vel(s,v);
	if (!(s->state & PLANE_CRASHING))
	{
		if (s->state & PLANE_ACCELERATING)
		{
			vset(pull,mech_heading(ms));
			vrot(pull,-16); /* maybe the angle should depend on up/down */
			vmadd(ms->lin_impulse,engine_strength,pull);
		}
		if (s->state & PLANE_UP)
			ms->air_rotate = -turn_amount;
		else if (s->state & PLANE_DOWN)
			ms->air_rotate = turn_amount;
		else
			ms->air_rotate = 0;

		if (ms->damage >= hitpoints)
		{
			s->state |= PLANE_CRASHING;
			if (!(s->owner->schrodinger)){
				sprite_set_animation(s,crashing[s->owner->id_in_team]);
			}else{
				sprite_set_animation(s,crashing[MAXPLAYERINTEAMS]);
			}

			s->owner->lastEnnemi->points+=crash_point;
			create_effect(&fire,s->x,s->y);
			sprite_alarm(7000,s,SIGNAL_KILL,0);
		}
	}
	mech_update(ms);
}
示例#4
0
文件: Game.cpp 项目: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP, false);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,		// the euler model
					  vec4(0,0,0,1),	// initial camera position
					  vec4(0,0,0,1),		// initial camera angles
					  vec4(0,0,0,1),		// no target
					  10.0,					// near and far clipping planes
					  12000.0,
					  120.0,					// field of view in degrees
					  WINDOW_WIDTH,			// size of final screen viewport
					  WINDOW_HEIGHT);


	// filenames of objects to load
	char *object_filenames[NUM_OBJECTS] = {
		"../../assets/chap12/fighter_01.cob",
	};

	// load in default object
	vec4 vscale(5.00,5.00,5.00,1),
		 vpos(0,0,150,1), 
		 vrot(0,0,0,1);

	// load all the objects in
	for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
	{
		obj_array[index_obj]->LoadCOB(object_filenames[index_obj],
									  &vscale, &vpos, &vrot, 
									  VERTEX_FLAGS_SWAP_YZ  | 
									  VERTEX_FLAGS_INVERT_WINDING_ORDER |
									  VERTEX_FLAGS_TRANSFORM_LOCAL 
									  /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/ );

	} // end for index_obj

	// set current object
	curr_object = 0;
	obj_work = obj_array[curr_object];

	vscale.Assign(20.00,20.00,20.00);

	// load in the scenery object that we will place all over the place
	obj_scene->LoadCOB("../../assets/chap12/borg_flat_01.cob",  
					   &vscale, &vpos, &vrot, 
					   VERTEX_FLAGS_SWAP_YZ  |
					   VERTEX_FLAGS_TRANSFORM_LOCAL 
					   /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/ );

	// position the scenery objects randomly
	for (int index = 0; index < NUM_SCENE_OBJECTS; index++)
	{
		// randomly position object
		scene_objects[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		scene_objects[index].y = RAND_RANGE(-(UNIVERSE_RADIUS/2), (UNIVERSE_RADIUS/2));
		scene_objects[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
	} // end for

	// select random velocities
	for (int index = 0; index < NUM_SCENE_OBJECTS; index++)
	{
		// randomly position object
		scene_objects_vel[index].x = RAND_RANGE(-MAX_VEL, MAX_VEL);
		scene_objects_vel[index].y = RAND_RANGE(-MAX_VEL, MAX_VEL);
		scene_objects_vel[index].z = RAND_RANGE(-MAX_VEL, MAX_VEL);
	} // end for

	// set up lights
	LightsMgr& lights = Modules::GetGraphics().GetLights();
	lights.Reset();

	// create some working colors
	Color white(255,255,255,0),
		  gray(100,100,100,0),
		  black(0,0,0,0),
		  red(255,0,0,0),
		  green(0,255,0,0),
		  blue(0,0,255,0);

	// ambient light
	lights.Init(AMBIENT_LIGHT_INDEX,   
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_AMBIENT,  // ambient light type
				gray, black, black,    // color for ambient term only
				NULL, NULL,            // no need for pos or dir
				0,0,0,                 // no need for attenuation
				0,0,0);                // spotlight info NA

	vec4 dlight_dir(-1,0,-1,1);

	// directional light
	lights.Init(INFINITE_LIGHT_INDEX,  
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_INFINITE, // infinite light type
				black, gray, black,    // color for diffuse term only
				NULL, &dlight_dir,     // need direction only
				0,0,0,                 // no need for attenuation
				0,0,0);                // spotlight info NA

	vec4 plight_pos(0,200,0,1);

	// point light
	lights.Init(POINT_LIGHT_INDEX,
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_POINT,    // pointlight type
				black, green, black,   // color for diffuse term only
				&plight_pos, NULL,     // need pos only
				0,.002,0,              // linear attenuation only
				0,0,1);                // spotlight info NA

	vec4 slight2_pos(0,1000,0,1);
	vec4 slight2_dir(-1,0,-1,1);

	// spot light2
	lights.Init(SPOT_LIGHT2_INDEX,
				LIGHT_STATE_ON,         // turn the light on
				LIGHT_ATTR_SPOTLIGHT2,  // spot light type 2
				black, red, black,      // color for diffuse term only
				&slight2_pos, &slight2_dir, // need pos only
				0,.001,0,                 // linear attenuation only
				0,0,1);    


// 	// create lookup for lighting engine
// 	RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
// 		palette,             // source palette
// 		rgblookup);          // lookup table

	// create the z buffer
	zbuffer->Create(WINDOW_WIDTH, WINDOW_HEIGHT, ZBUFFER_ATTR_32BIT);

	// load in the background
	background->Create(0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 32);
	BmpFile* bitmap = new BmpFile("../../assets/chap12/nebred01.bmp");
	background->LoadFrame(bitmap, 0,0,0,BITMAP_EXTRACT_MODE_ABS);
	delete bitmap;
}
示例#5
0
static void sigget(sprite_t *s, int signal, void *data)
{
	float v[2] = {0,0};
	sprite_t *p;
	float r[2];
	int sigabs;

	switch(signal)
	{
	case SIGNAL_CANCONTROL:
		*(int *)data = !(s->state & PLANE_CRASHING);
		break;
	case SIGNAL_DAMAGE:
		((mech_sprite_t *)s)->damage += *(int *)data;
		((player_t*)s->owner)->damage=(100*((mech_sprite_t *)s)->damage)/hitpoints;
		break;
	case SIGNAL_LAST_ENNEMI:
		((player_t*)s->owner)->lastEnnemi=(player_t*)data;
		break;
	case SIGNAL_ACCELERATE:
		s->state |= PLANE_ACCELERATING;
		break;
	case -SIGNAL_ACCELERATE:
		s->state &= ~PLANE_ACCELERATING;
		break;
	case SIGNAL_UP:
		s->state |= PLANE_UP;
		s->state &= ~PLANE_DOWN;
		break;
	case -SIGNAL_UP:
		s->state &= ~PLANE_UP;
		break;
	case SIGNAL_DOWN:
		s->state |= PLANE_DOWN;
		s->state &= ~PLANE_UP;
		break;
	case -SIGNAL_DOWN:
		s->state &= ~PLANE_DOWN;
		break;
	case SIGNAL_FIRE: /* create bullet */
		if (sprite_timer_finished(((struct biplane*)s)->gun_timer) &&
				!(s->state & PLANE_CRASHING))
		{
			sound_effect(&sound_gunfire,s->x,s->y);
			p = sprite_create(((struct biplane*)s)->bullet_type,s->owner);
			//p->owner=s->owner;
			sprite_group_insert(bullet_group,p);
			r[0] = mech_heading((mech_sprite_t *)s)[0];
			r[1] = mech_heading((mech_sprite_t *)s)[1];
			vmul(r,21); /* Find start of bullet in clumsy way */
			vrot(r,-9);
			sprite_set_pos(p,s->x + r[0],s->y + r[1]);
			sprite_get_vel(s,v);
			vmadd(v,200,mech_heading((mech_sprite_t *)s));
			sprite_set_vel(p,v);
			/* cannot fire again in some time */
			sprite_timer_set(&(((struct biplane*)s)->gun_timer),bullet_delay);
		}
		break;
	case SIGNAL_NUM0: /* create bomb */
		if (sprite_timer_finished(((struct biplane*)s)->bomb_timer) &&
				(!(s->state & PLANE_CRASHING)) &&
				(((struct biplane*)s)->nr_bombs > 0))
		{
			((struct biplane*)s)->nr_bombs--;
			p = sprite_create(&bomb,s->owner);
			p->anim_p = s->anim_p;
			((mech_sprite_t *)p)->angle = ((mech_sprite_t *)s)->angle;
			r[0] = mech_heading((mech_sprite_t *)s)[0];
			r[1] = mech_heading((mech_sprite_t *)s)[1];
			vmul(r,14);
			vrot(r,-80);
			sprite_set_pos(p,s->x + r[0],s->y + r[1]);
			sprite_get_vel(s,v);
			vmadd(v,5,r);
			sprite_set_vel(p,v);
			sprite_group_insert(bomb_group,p);
			sprite_timer_set(&(((struct biplane*)s)->bomb_timer),
					bomb_delay);
		}
		break;
	case SIGNAL_NUM1: /* jump ship */
		if (sprite_timer_finished(((struct biplane*)s)->bomb_timer) &&
				(!(s->state & PLANE_CRASHING)))
		{
			p = sprite_create(&parachute,NULL);
			r[0] = mech_heading((mech_sprite_t *)s)[0];
			r[1] = mech_heading((mech_sprite_t *)s)[1];
			vmul(r,14);
			vrot(r,80);
			sprite_set_pos(p,s->x + r[0],s->y + r[1]);
			sprite_get_vel(s,v);
			vmadd(v,5,r);
			sprite_set_vel(p,v);
			sprite_group_insert(mech_group,p);
			sprite_timer_set(&(((struct biplane*)s)->bomb_timer),bomb_delay);
		}
		break;
	case SIGNAL_KILL:
		create_effect(&explosion,s->x,s->y);
		sprite_kill(s);
		break;
	case SIGNAL_ISHARMLESS:
		if (s->state & PLANE_CRASHING)
			((struct signal_reply *)data)->reply = 1;
		break;
	case SIGNAL_STATSTRING://TTODO : useless ?
		sprintf(data,"%i bombs",((struct biplane*)s)->nr_bombs);
		break;
	default:
		break;
	}
}
示例#6
0
文件: Game.cpp 项目: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,
					  vec4(0,40,0,1),
					  vec4(0,0,0,1),
					  vec4(0,0,0,1),
					  200.0f,
					  12000.0f,
					  120.0f,
					  WINDOW_WIDTH,
					  WINDOW_HEIGHT);

	// all your initialization code goes here...
	vec4 vscale(0.75f,0.75f,0.75f,1),		// scale of object
		vpos(0,0,0,1),        // position of object
		vrot(0,0,0,1);        // initial orientation of object

	// load the master tank object
	vscale.Assign(0.75,0.75,0.75);
	_obj_tank.LoadPLG("../../assets/chap09/tank3.plg",&vscale, &vpos, &vrot);

	// load player object for 3rd person view
	vscale.Assign(15.75,15.75,15.75);
	_obj_player.LoadCOB("../../assets/chap09/tie04.cob",  
		&vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_TEXTURE_V |
		VERTEX_FLAGS_SWAP_YZ | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD);

	// load the master tower object
	vscale.Assign(1.0, 2.0, 1.0);
	_obj_tower.LoadPLG("../../assets/chap09/towerg1.plg",&vscale, &vpos, &vrot);

	// load the master ground marker
	vscale.Assign(3.0,3.0,3.0);
	_obj_marker.LoadPLG("../../assets/chap09/marker2.plg",&vscale, &vpos, &vrot);

	// position the tanks
	for (int index = 0; index < NUM_TANKS; index++)
	{
		// randomly position the tanks
		_tanks[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_tanks[index].y = 0; // obj_tank.max_radius;
		_tanks[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_tanks[index].w = RAND_RANGE(0,360);
	}
	// position the towers
	for (int index = 0; index < NUM_TOWERS; index++)
	{
		// randomly position the tower
		_towers[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_towers[index].y = 0; // obj_tower.max_radius;
		_towers[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
	}

	// set up lights
	LightsMgr& lights = Modules::GetGraphics().GetLights();
	lights.Reset();

	// create some working colors
	Color white(255,255,255,0),
		  gray(100,100,100,0),
		  black(0,0,0,0),
		  red(255,0,0,0),
		  green(0,255,0,0),
		  blue(0,0,255,0);

	// ambient light
	lights.Init(AMBIENT_LIGHT_INDEX,   
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_AMBIENT,  // ambient light type
		gray, black, black,    // color for ambient term only
		NULL, NULL,            // no need for pos or dir
		0,0,0,                 // no need for attenuation
		0,0,0);                // spotlight info NA

	vec4 dlight_dir(-1,0,-1,0);

	// directional light
	lights.Init(INFINITE_LIGHT_INDEX,  
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_INFINITE, // infinite light type
		black, gray, black,    // color for diffuse term only
		NULL, &dlight_dir,     // need direction only
		0,0,0,                 // no need for attenuation
		0,0,0);                // spotlight info NA


	vec4 plight_pos(0,200,0,0);

	// point light
	lights.Init(POINT_LIGHT_INDEX,
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_POINT,    // pointlight type
		black, green, black,   // color for diffuse term only
		&plight_pos, NULL,     // need pos only
		0,.001,0,              // linear attenuation only
		0,0,1);                // spotlight info NA

	vec4 slight_pos(0,200,0,0);
	vec4 slight_dir(-1,0,-1,0);

	// spot light
	lights.Init(SPOT_LIGHT_INDEX,
		LIGHT_STATE_ON,         // turn the light on
		LIGHT_ATTR_SPOTLIGHT2,  // spot light type 2
		black, red, black,      // color for diffuse term only
		&slight_pos, &slight_dir, // need pos only
		0,.001,0,                 // linear attenuation only
		0,0,1);                   // spotlight powerfactor only


// 	// create lookup for lighting engine
// 	RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
// 		palette,             // source palette
// 		rgblookup);          // lookup table
}