Ejemplo n.º 1
0
void PLAYERS::render_hand(TEE_RENDER_INFO *info, vec2 center_pos, vec2 dir, float angle_offset, vec2 post_rot_offset)
{
	// for drawing hand
	//const skin *s = skin_get(skin_id);
	
	float basesize = 10.0f;
	//dir = normalize(hook_pos-pos);

	vec2 hand_pos = center_pos + dir;
	float angle = get_angle(dir);
	if (dir.x < 0)
		angle -= angle_offset;
	else
		angle += angle_offset;

	vec2 dirx = dir;
	vec2 diry(-dir.y,dir.x);

	if (dir.x < 0)
		diry = -diry;

	hand_pos += dirx * post_rot_offset.x;
	hand_pos += diry * post_rot_offset.y;

	//gfx_texture_set(data->images[IMAGE_CHAR_DEFAULT].id);
	gfx_texture_set(info->texture);
	gfx_quads_begin();
	gfx_setcolor(info->color_body.r, info->color_body.g, info->color_body.b, info->color_body.a);

	// two passes
	for (int i = 0; i < 2; i++)
	{
		bool outline = i == 0;

		select_sprite(outline?SPRITE_TEE_HAND_OUTLINE:SPRITE_TEE_HAND, 0, 0, 0);
		gfx_quads_setrotation(angle);
		gfx_quads_draw(hand_pos.x, hand_pos.y, 2*basesize, 2*basesize);
	}

	gfx_quads_setrotation(0);
	gfx_quads_end();
}
Ejemplo n.º 2
0
void PLAYERS::render_player(
	const NETOBJ_CHARACTER *prev_char,
	const NETOBJ_CHARACTER *player_char,
	const NETOBJ_PLAYER_INFO *prev_info,
	const NETOBJ_PLAYER_INFO *player_info
	)
{
	NETOBJ_CHARACTER prev;
	NETOBJ_CHARACTER player;
	prev = *prev_char;
	player = *player_char;

	NETOBJ_PLAYER_INFO info = *player_info;
	TEE_RENDER_INFO render_info = gameclient.clients[info.cid].render_info;

	// check for teamplay modes
	bool new_tick = gameclient.new_tick;

	// check for ninja	
	if ( player.weapon == WEAPON_NINJA ) {
		// change the skin for the player to the ninja
		int skin = gameclient.skins->find("x_ninja");
		
		if (skin != -1) {
			render_info.texture = gameclient.skins->get( skin )->org_texture;
			render_info.color_body = vec4( 1,1,1,1 );
			render_info.color_feet = vec4( 1,1,1,1 );
		}	
	}
	
	// set size
	render_info.size = 64.0f;

	float intratick = client_intratick();
	
	if(player.health < 0) // dont render dead players
		return;

	float angle = mix((float)prev.angle, (float)player.angle, intratick)/256.0f;
	
	//float angle = 0;
	
	// just use the direct input if it's local player we are rendering
	if(info.local && client_state() != CLIENTSTATE_DEMOPLAYBACK)
		angle = get_angle(gameclient.controls->mouse_pos);
	
	// use preditect players if needed
	if(info.local && config.cl_predict && client_state() != CLIENTSTATE_DEMOPLAYBACK)
	{
		if ( gameclient.snap.local_character && ( gameclient.snap.local_character->health >= 0 ) ) {
			// apply predicted results
			gameclient.predicted_char.write(&player);
			gameclient.predicted_prev_char.write(&prev);
			intratick = client_predintratick();
			new_tick = gameclient.new_predicted_tick;
		}
	}
	
	vec2 direction = get_direction((int)(angle*256.0f));
	vec2 position = mix(vec2(prev.x, prev.y), vec2(player.x, player.y), intratick);
	vec2 vel = mix(vec2(prev.vx/256.0f, prev.vy/256.0f), vec2(player.vx/256.0f, player.vy/256.0f), intratick);
	
	gameclient.flow->add(position, vel*100.0f, 10.0f);
	
	render_info.got_airjump = player.jumped&2?0:1;
	
	
	// detect events
	if(new_tick)
	{
		// detect air jump
		if(!render_info.got_airjump && !(prev.jumped&2))
			gameclient.effects->air_jump(position);
	}

	if(prev.health < 0) // Don't flicker from previous position
		position = vec2(player.x, player.y);

	bool stationary = player.vx < 1 && player.vx > -1;
	bool inair = col_check_point(player.x, player.y+16) == 0;
	bool want_other_dir = (player.direction == -1 && vel.x > 0) || (player.direction == 1 && vel.x < 0);

	// evaluate animation
	float walk_time = fmod(position.x, 100.0f)/100.0f;
	ANIMSTATE state;
	state.set(&data->animations[ANIM_BASE], 0);

	if(inair)
		state.add(&data->animations[ANIM_INAIR], 0, 1.0f); // TODO: some sort of time here
	else if(stationary)
		state.add(&data->animations[ANIM_IDLE], 0, 1.0f); // TODO: some sort of time here
	else if(!want_other_dir)
		state.add(&data->animations[ANIM_WALK], walk_time, 1.0f);

	if (player.weapon == WEAPON_HAMMER)
	{
		float ct = (client_prevtick()-player.attacktick)/(float)SERVER_TICK_SPEED + client_ticktime();
		state.add(&data->animations[ANIM_HAMMER_SWING], clamp(ct*5.0f,0.0f,1.0f), 1.0f);
	}
	if (player.weapon == WEAPON_NINJA)
	{
		float ct = (client_prevtick()-player.attacktick)/(float)SERVER_TICK_SPEED + client_ticktime();
		state.add(&data->animations[ANIM_NINJA_SWING], clamp(ct*2.0f,0.0f,1.0f), 1.0f);
	}
	
	// do skidding
	if(!inair && want_other_dir && length(vel*50) > 500.0f)
	{
		static int64 skid_sound_time = 0;
		if(time_get()-skid_sound_time > time_freq()/10)
		{
			gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, position);
			skid_sound_time = time_get();
		}
		
		gameclient.effects->skidtrail(
			position+vec2(-player.direction*6,12),
			vec2(-player.direction*100*length(vel),-50)
		);
	}

	// draw hook
	if (prev.hook_state>0 && player.hook_state>0)
	{
		gfx_texture_set(data->images[IMAGE_GAME].id);
		gfx_quads_begin();
		//gfx_quads_begin();

		vec2 pos = position;
		vec2 hook_pos;
		
		if(player_char->hooked_player != -1)
		{
			if(gameclient.snap.local_info && player_char->hooked_player == gameclient.snap.local_info->cid)
			{
				hook_pos = mix(vec2(gameclient.predicted_prev_char.pos.x, gameclient.predicted_prev_char.pos.y),
					vec2(gameclient.predicted_char.pos.x, gameclient.predicted_char.pos.y), client_predintratick());
			}
			else
				hook_pos = mix(vec2(prev_char->hook_x, prev_char->hook_y), vec2(player_char->hook_x, player_char->hook_y), client_intratick());
		}
		else
			hook_pos = mix(vec2(prev.hook_x, prev.hook_y), vec2(player.hook_x, player.hook_y), intratick);

		float d = distance(pos, hook_pos);
		vec2 dir = normalize(pos-hook_pos);

		gfx_quads_setrotation(get_angle(dir)+pi);

		// render head
		select_sprite(SPRITE_HOOK_HEAD);
		gfx_quads_draw(hook_pos.x, hook_pos.y, 24,16);

		// render chain
		select_sprite(SPRITE_HOOK_CHAIN);
		int i = 0;
		for(float f = 24; f < d && i < 1024; f += 24, i++)
		{
			vec2 p = hook_pos + dir*f;
			gfx_quads_draw(p.x, p.y,24,16);
		}

		gfx_quads_setrotation(0);
		gfx_quads_end();

		render_hand(&render_info, position, normalize(hook_pos-pos), -pi/2, vec2(20, 0));
	}

	// draw gun
	{
		gfx_texture_set(data->images[IMAGE_GAME].id);
		gfx_quads_begin();
		gfx_quads_setrotation(state.attach.angle*pi*2+angle);

		// normal weapons
		int iw = clamp(player.weapon, 0, NUM_WEAPONS-1);
		select_sprite(data->weapons.id[iw].sprite_body, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0);

		vec2 dir = direction;
		float recoil = 0.0f;
		vec2 p;
		if (player.weapon == WEAPON_HAMMER)
		{
			// Static position for hammer
			p = position + vec2(state.attach.x, state.attach.y);
			p.y += data->weapons.id[iw].offsety;
			// if attack is under way, bash stuffs
			if(direction.x < 0)
			{
				gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2);
				p.x -= data->weapons.id[iw].offsetx;
			}
			else
			{
				gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2);
			}
			draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size);
		}
		else if (player.weapon == WEAPON_NINJA)
		{
			p = position;
			p.y += data->weapons.id[iw].offsety;

			if(direction.x < 0)
			{
				gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2);
				p.x -= data->weapons.id[iw].offsetx;
				gameclient.effects->powerupshine(p+vec2(32,0), vec2(32,12));
			}
			else
			{
				gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2);
				gameclient.effects->powerupshine(p-vec2(32,0), vec2(32,12));
			}
			draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size);

			// HADOKEN
			if ((client_tick()-player.attacktick) <= (SERVER_TICK_SPEED / 6) && data->weapons.id[iw].num_sprite_muzzles)
			{
				int itex = rand() % data->weapons.id[iw].num_sprite_muzzles;
				float alpha = 1.0f;
				if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex])
				{
					vec2 dir = vec2(player_char->x,player_char->y) - vec2(prev_char->x, prev_char->y);
					dir = normalize(dir);
					float hadokenangle = get_angle(dir);
					gfx_quads_setrotation(hadokenangle);
					//float offsety = -data->weapons[iw].muzzleoffsety;
					select_sprite(data->weapons.id[iw].sprite_muzzles[itex], 0);
					vec2 diry(-dir.y,dir.x);
					p = position;
					float offsetx = data->weapons.id[iw].muzzleoffsetx;
					p -= dir * offsetx;
					draw_sprite(p.x, p.y, 160.0f);
				}
			}
		}
		else
		{
			// TODO: should be an animation
			recoil = 0;
			float a = (client_tick()-player.attacktick+intratick)/5.0f;
			if(a < 1)
				recoil = sinf(a*pi);
			p = position + dir * data->weapons.id[iw].offsetx - dir*recoil*10.0f;
			p.y += data->weapons.id[iw].offsety;
			draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size);
		}

		if (player.weapon == WEAPON_GUN || player.weapon == WEAPON_SHOTGUN)
		{
			// check if we're firing stuff
			if(data->weapons.id[iw].num_sprite_muzzles)//prev.attackticks)
			{
				float alpha = 0.0f;
				int phase1tick = (client_tick() - player.attacktick);
				if (phase1tick < (data->weapons.id[iw].muzzleduration + 3))
				{
					float t = ((((float)phase1tick) + intratick)/(float)data->weapons.id[iw].muzzleduration);
					alpha = LERP(2.0, 0.0f, min(1.0f,max(0.0f,t)));
				}

				int itex = rand() % data->weapons.id[iw].num_sprite_muzzles;
				if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex])
				{
					float offsety = -data->weapons.id[iw].muzzleoffsety;
					select_sprite(data->weapons.id[iw].sprite_muzzles[itex], direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0);
					if(direction.x < 0)
						offsety = -offsety;

					vec2 diry(-dir.y,dir.x);
					vec2 muzzlepos = p + dir * data->weapons.id[iw].muzzleoffsetx + diry * offsety;

					draw_sprite(muzzlepos.x, muzzlepos.y, data->weapons.id[iw].visual_size);
				}
			}
		}
		gfx_quads_end();

		switch (player.weapon)
		{
			case WEAPON_GUN: render_hand(&render_info, p, direction, -3*pi/4, vec2(-15, 4)); break;
			case WEAPON_SHOTGUN: render_hand(&render_info, p, direction, -pi/2, vec2(-5, 4)); break;
			case WEAPON_GRENADE: render_hand(&render_info, p, direction, -pi/2, vec2(-4, 7)); break;
		}

	}

	// render the "shadow" tee
	if(info.local && config.debug)
	{
		vec2 ghost_position = mix(vec2(prev_char->x, prev_char->y), vec2(player_char->x, player_char->y), client_intratick());
		TEE_RENDER_INFO ghost = render_info;
		ghost.color_body.a = 0.5f;
		ghost.color_feet.a = 0.5f;
		render_tee(&state, &ghost, player.emote, direction, ghost_position); // render ghost
	}

	render_info.size = 64.0f; // force some settings
	render_info.color_body.a = 1.0f;
	render_info.color_feet.a = 1.0f;
	
	render_tee(&state, &render_info, player.emote, direction, position);

	if(player.player_state == PLAYERSTATE_CHATTING)
	{
		gfx_texture_set(data->images[IMAGE_EMOTICONS].id);
		gfx_quads_begin();
		select_sprite(SPRITE_DOTDOT);
		gfx_quads_draw(position.x + 24, position.y - 40, 64,64);
		gfx_quads_end();
	}

	if (gameclient.clients[info.cid].emoticon_start != -1 && gameclient.clients[info.cid].emoticon_start + 2 * client_tickspeed() > client_tick())
	{
		gfx_texture_set(data->images[IMAGE_EMOTICONS].id);
		gfx_quads_begin();

		int since_start = client_tick() - gameclient.clients[info.cid].emoticon_start;
		int from_end = gameclient.clients[info.cid].emoticon_start + 2 * client_tickspeed() - client_tick();

		float a = 1;

		if (from_end < client_tickspeed() / 5)
			a = from_end / (client_tickspeed() / 5.0);

		float h = 1;
		if (since_start < client_tickspeed() / 10)
			h = since_start / (client_tickspeed() / 10.0);

		float wiggle = 0;
		if (since_start < client_tickspeed() / 5)
			wiggle = since_start / (client_tickspeed() / 5.0);

		float wiggle_angle = sin(5*wiggle);

		gfx_quads_setrotation(pi/6*wiggle_angle);

		gfx_setcolor(1.0f,1.0f,1.0f,a);
		// client_datas::emoticon is an offset from the first emoticon
		select_sprite(SPRITE_OOP + gameclient.clients[info.cid].emoticon);
		gfx_quads_draw(position.x, position.y - 23 - 32*h, 64, 64*h);
		gfx_quads_end();
	}
}
Ejemplo n.º 3
0
int CTraQ::CalcNeck( CModel* srcmodel, TSELEM* tsptr, CTraQ* traqptr, RPSELEM* rpsptr, int frameno, int skipflag )
{
	CQuaternion parq;
	parq = ( traqptr + frameno * SKEL_MAX + SKEL_TORSO )->m_totalq;
	CQuaternion invparq;
	parq.inv( &invparq );

	if( skipflag == 3 ){
		( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_q.SetParams( 1.0f, 0.0f, 0.0f, 0.0f );
		( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_totalq = parq;
		return 0;
	}


	D3DXVECTOR3 befLpos, aftLpos, befRpos, aftRpos;
	befLpos = ( rpsptr + 0 * SKEL_MAX + SKEL_LEFT_SHOULDER )->pos;
	aftLpos = ( rpsptr + frameno * SKEL_MAX + SKEL_LEFT_SHOULDER )->pos;
	befRpos = ( rpsptr + 0 * SKEL_MAX + SKEL_RIGHT_SHOULDER )->pos;
	aftRpos = ( rpsptr + frameno * SKEL_MAX + SKEL_RIGHT_SHOULDER )->pos;

	D3DXVECTOR3 paftLpos, paftRpos;
	invparq.Rotate( &paftLpos, aftLpos );
	invparq.Rotate( &paftRpos, aftRpos );

	double radxz;
	D3DXVECTOR3 vDir0, vDir;
	D3DXVECTOR3 dirY( 0.0f, 1.0f, 0.0f );
	D3DXVECTOR3 diffpos;
	diffpos = paftLpos - paftRpos;
	DVec3Normalize( &diffpos, diffpos );

	DVec3Cross( &diffpos, &dirY, &vDir0 );
	DVec3Normalize( &vDir, vDir0 );
	if( vDir.x == 0.0f ){
		if( vDir.z >= 0.0f )
			radxz = 0.0;
		else
			radxz = PAI;
	}else if( vDir.x > 0.0f ){
		radxz = -atanf( vDir.z / vDir.x ) + PAI / 2;
	}else{
		radxz = -atanf( vDir.z / vDir.x ) - PAI / 2;
	}

///////////////
	D3DXVECTOR3 beftor, afttor, befneck, aftneck;
	beftor = ( rpsptr + 0 * SKEL_MAX + SKEL_TORSO )->pos;
	afttor = ( rpsptr + frameno * SKEL_MAX + SKEL_TORSO )->pos;
	befneck = ( rpsptr + 0 * SKEL_MAX + SKEL_NECK )->pos;
	aftneck = ( rpsptr + frameno * SKEL_MAX + SKEL_NECK )->pos;

	D3DXVECTOR3 pafttor, paftneck;
	invparq.Rotate( &pafttor, afttor );
	invparq.Rotate( &paftneck, aftneck );

	D3DXVECTOR3 vecA, vecB;
	vecA = befneck - beftor;
	vecB = paftneck - pafttor;
	D3DXVECTOR3 nvecA, nvecB;
	DVec3Normalize( &nvecA, vecA );
	DVec3Normalize( &nvecB, vecB );
	int ret;
	CQuaternion q2;
	ret = DCalcDiffQ( &nvecA, &nvecB, &q2 );
	_ASSERT( !ret );
	

	CQuaternion za3q;
	D3DXVECTOR3 cureul( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 befeul( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 neckbefeul( 0.0f, 0.0f, 0.0f );
	neckbefeul = ( traqptr + ( frameno - 1 ) * SKEL_MAX + SKEL_NECK )->m_neckbefeul;
	ret = QtoEul( srcmodel, q2, neckbefeul, CAX_INI, 0, &cureul, &za3q );
	_ASSERT( !ret );

	CQuaternion invza3q;
	za3q.inv( &invza3q );

	D3DXVECTOR3 dirx( 1.0f, 0.0f, 0.0f );
	D3DXVECTOR3 diry( 0.0f, 1.0f, 0.0f );
	D3DXVECTOR3 dirz( 0.0f, 0.0f, 1.0f );

	CQuaternion qx2, qy2, qz2, qzx2;
	qx2.SetAxisAndRot( dirx, cureul.x * DEG2PAI );
	qy2.SetAxisAndRot( diry, cureul.y * DEG2PAI );
	qz2.SetAxisAndRot( dirz, cureul.z * DEG2PAI );

	CQuaternion q;
	q = qx2 * qz2;


	D3DXVECTOR3 axis;
	q.Rotate( &axis, diry );
	DVec3Normalize( &axis, axis );
	CQuaternion qxz;
	qxz.SetAxisAndRot( axis, radxz );

	CQuaternion setq;
	if( skipflag & 1 ){
		setq = q;
	}else{
		setq = qxz * q;
	}

/////////////////////
	D3DXVECTOR3 setcureul;
	befeul = ( traqptr + ( frameno - 1 ) * SKEL_MAX + SKEL_NECK )->m_befeul;

	ret = QtoEul( srcmodel, setq, befeul, CAX_INI, 0, &setcureul, &za3q );
	_ASSERT( !ret );


	( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_q = setq;
	( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_totalq = parq * setq;

	( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_neckbefeul = cureul;
	( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_cureul = setcureul;
	( traqptr + frameno * SKEL_MAX + SKEL_NECK )->m_befeul = setcureul;


	return 0;
}
Ejemplo n.º 4
0
int CTraQ::CalcQ( CModel* srcmodel, TSELEM* tsptr, CTraQ* traqptr, RPSELEM* rpsptr, int frameno, int pivotskel, int skelno, int skipflag )
{
	CQuaternion parq;
	parq = ( traqptr + frameno * SKEL_MAX + pivotskel )->m_totalq;
	CQuaternion invparq;
	parq.inv( &invparq );

	if( skipflag != 0 ){
		( traqptr + frameno * SKEL_MAX + skelno )->m_q.SetParams( 1.0f, 0.0f, 0.0f, 0.0f );
		( traqptr + frameno * SKEL_MAX + skelno )->m_totalq = parq;
		return 0;
	}


	D3DXVECTOR3 befpivpos, aftpivpos, befpos, aftpos;
	befpivpos = ( rpsptr + 0 * SKEL_MAX + pivotskel )->pos;
	aftpivpos = ( rpsptr + frameno * SKEL_MAX + pivotskel )->pos;
	befpos = ( rpsptr + 0 * SKEL_MAX + skelno )->pos;
	aftpos = ( rpsptr + frameno * SKEL_MAX + skelno )->pos;

	D3DXVECTOR3 paftpivpos, paftpos;
	invparq.Rotate( &paftpivpos, aftpivpos );
	invparq.Rotate( &paftpos, aftpos );

	D3DXVECTOR3 vec1, vec2;
	vec1 = befpos - befpivpos;
	vec2 = paftpos - paftpivpos;
	D3DXVECTOR3 nvec1, nvec2;
	DVec3Normalize( &nvec1, vec1 );
	DVec3Normalize( &nvec2, vec2 );


	int ret;
	CQuaternion setq;
	ret = DCalcDiffQ( &nvec1, &nvec2, &setq );
	_ASSERT( !ret );
////////////////


	D3DXVECTOR3 cureul( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 befeul( 0.0f, 0.0f, 0.0f );
	befeul = ( traqptr + ( frameno - 1 ) * SKEL_MAX + skelno )->m_befeul;
	CQuaternion za3q;
	ret = QtoEul( srcmodel, setq, befeul, CAX_ZA3, (tsptr + skelno)->jointno, &cureul, &za3q );
	_ASSERT( !ret );

	CQuaternion invza3q;
	za3q.inv( &invza3q );

	float twistdeg;
	if( ( tsptr + skelno )->twistflag == 0 ){

		D3DXVECTOR3 dirx( 1.0f, 0.0f, 0.0f );
		D3DXVECTOR3 diry( 0.0f, 1.0f, 0.0f );
		D3DXVECTOR3 dirz( 0.0f, 0.0f, 1.0f );

		CQuaternion qx, qy, qz;
		qx.SetAxisAndRot( dirx, cureul.x * DEG2PAI );
		qy.SetAxisAndRot( diry, cureul.y * DEG2PAI );
		qz.SetAxisAndRot( dirz, cureul.z * DEG2PAI );
		CQuaternion qxy;
		qxy = qy * qx;


///////////
		
		D3DXVECTOR3 aftdiry;
		qxy.Rotate( &aftdiry, diry );
		DVec3Normalize( &aftdiry, aftdiry );

		double doty;
		DCalcDot( &diry, &aftdiry, &doty );
		double rady;
		rady = acos( doty );

		CQuaternion ya, yb;
		ya.SetAxisAndRot( dirz, rady );
		yb.SetAxisAndRot( dirz, -rady );
		D3DXVECTOR3 afta, aftb;
		ya.Rotate( &afta, diry );
		yb.Rotate( &aftb, diry );
		DVec3Normalize( &afta, afta );
		DVec3Normalize( &aftb, aftb );
		double dotya, dotyb;
		DCalcDot( &aftdiry, &afta, &dotya );
		DCalcDot( &aftdiry, &aftb, &dotyb );
		CQuaternion twistq;
		if( dotya >= dotyb ){
			twistq = ya;
			twistdeg = (float)( rady * PAI2DEG );
		}else{
			twistq = yb;
			twistdeg = (float)( -rady * PAI2DEG );
		}
		
		setq = za3q * qxy * twistq * invza3q;
	}else{
		twistdeg = cureul.z;
	}


	( traqptr + frameno * SKEL_MAX + skelno )->m_q = setq;
	( traqptr + frameno * SKEL_MAX + skelno )->m_totalq = parq * setq;

	( traqptr + frameno * SKEL_MAX + skelno )->m_befeul = cureul;
	( traqptr + frameno * SKEL_MAX + skelno )->m_cureul = D3DXVECTOR3( cureul.x, cureul.y, twistdeg );


	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[])
{
	// ACL tests
	char* exename = getenv("WINDIR");

	PSID psidOwner;
	PSID psidGroup;
	PACL pDacl;
	PSECURITY_DESCRIPTOR pSecurityDesc;

	DWORD result = GetNamedSecurityInfo(
		exename, // pObjectName
		SE_FILE_OBJECT, // ObjectType
		DACL_SECURITY_INFORMATION | // SecurityInfo
		GROUP_SECURITY_INFORMATION |
		OWNER_SECURITY_INFORMATION,
		&psidOwner, // ppsidOwner,
		&psidGroup, // ppsidGroup,
		&pDacl,     // ppDacl,
		NULL,       // ppSacl,
		&pSecurityDesc // ppSecurityDescriptor
	);
	if (result != ERROR_SUCCESS)
	{
		printf("Error getting security info for '%s': error %d",
			exename, result);
	}
	assert(result == ERROR_SUCCESS);

	char namebuf[1024];
	char domainbuf[1024];
	SID_NAME_USE nametype;
	DWORD namelen = sizeof(namebuf);
	DWORD domainlen = sizeof(domainbuf);

	assert(LookupAccountSid(NULL, psidOwner, namebuf, &namelen,
		domainbuf, &domainlen, &nametype));

	printf("Owner:\n");
	printf("User name:   %s\n", namebuf);
	printf("Domain name: %s\n", domainbuf);
	printf("Name type:   %d\n", nametype);
	printf("\n");

	namelen = sizeof(namebuf);
	domainlen = sizeof(domainbuf);

	assert(LookupAccountSid(NULL, psidGroup, namebuf, &namelen,
		domainbuf, &domainlen, &nametype));

	printf("Group:\n");
	printf("User name:   %s\n", namebuf);
	printf("Domain name: %s\n", domainbuf);
	printf("Name type:   %d\n", nametype);
	printf("\n");

	ULONG numEntries;
	PEXPLICIT_ACCESS pEntries;
	result = GetExplicitEntriesFromAcl
	(
		pDacl,       // pAcl
		&numEntries, // pcCountOfExplicitEntries,
		&pEntries    // pListOfExplicitEntries
	);
	assert(result == ERROR_SUCCESS);

	printf("Found %lu explicit DACL entries for '%s'\n\n",
		(unsigned long)numEntries, exename);

	for (ULONG i = 0; i < numEntries; i++)
	{
		EXPLICIT_ACCESS* pEntry = &(pEntries[i]);
		printf("DACL entry %lu:\n", (unsigned long)i);

		DWORD perms = pEntry->grfAccessPermissions;
		printf("  Access permissions: ", perms);

		#define PRINT_PERM(name) \
		if (perms & name) \
		{ \
			printf(#name " "); \
			perms &= ~name; \
		}

		PRINT_PERM(FILE_ADD_FILE);
		PRINT_PERM(FILE_ADD_SUBDIRECTORY);
		PRINT_PERM(FILE_ALL_ACCESS);
		PRINT_PERM(FILE_APPEND_DATA);
		PRINT_PERM(FILE_CREATE_PIPE_INSTANCE);
		PRINT_PERM(FILE_DELETE_CHILD);
		PRINT_PERM(FILE_EXECUTE);
		PRINT_PERM(FILE_LIST_DIRECTORY);
		PRINT_PERM(FILE_READ_ATTRIBUTES);
		PRINT_PERM(FILE_READ_DATA);
		PRINT_PERM(FILE_READ_EA);
		PRINT_PERM(FILE_TRAVERSE);
		PRINT_PERM(FILE_WRITE_ATTRIBUTES);
		PRINT_PERM(FILE_WRITE_DATA);
		PRINT_PERM(FILE_WRITE_EA);
		PRINT_PERM(STANDARD_RIGHTS_READ);
		PRINT_PERM(STANDARD_RIGHTS_WRITE);
		PRINT_PERM(SYNCHRONIZE);
		PRINT_PERM(DELETE);
		PRINT_PERM(READ_CONTROL);
		PRINT_PERM(WRITE_DAC);
		PRINT_PERM(WRITE_OWNER);
		PRINT_PERM(MAXIMUM_ALLOWED);
		PRINT_PERM(GENERIC_ALL);
		PRINT_PERM(GENERIC_EXECUTE);
		PRINT_PERM(GENERIC_WRITE);
		PRINT_PERM(GENERIC_READ);
		printf("\n");

		if (perms)
		{
			printf("  Bits left over: %08x\n", perms);
		}
		assert(!perms);

		printf("  Access mode: ");
		switch(pEntry->grfAccessMode)
		{
		case NOT_USED_ACCESS:
			printf("NOT_USED_ACCESS\n"); break;
		case GRANT_ACCESS:
			printf("GRANT_ACCESS\n"); break;
		case DENY_ACCESS:
			printf("DENY_ACCESS\n"); break;
		case REVOKE_ACCESS:
			printf("REVOKE_ACCESS\n"); break;
		case SET_AUDIT_SUCCESS:
			printf("SET_AUDIT_SUCCESS\n"); break;
		case SET_AUDIT_FAILURE:
			printf("SET_AUDIT_FAILURE\n"); break;
		default:
			printf("Unknown (%08x)\n", pEntry->grfAccessMode);
		}

		printf("  Trustee: ");
		assert(pEntry->Trustee.pMultipleTrustee == NULL);
		assert(pEntry->Trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE);
		switch(pEntry->Trustee.TrusteeForm)
		{
		case TRUSTEE_IS_SID:
			{
				PSID trusteeSid = (PSID)(pEntry->Trustee.ptstrName);

				namelen = sizeof(namebuf);
				domainlen = sizeof(domainbuf);

				assert(LookupAccountSid(NULL, trusteeSid, namebuf, &namelen,
					domainbuf, &domainlen, &nametype));

				printf("SID of %s\\%s (%d)\n", domainbuf, namebuf, nametype);
			}
			break;
		case TRUSTEE_IS_NAME:
			printf("Name\n"); break;
		case TRUSTEE_BAD_FORM:
			printf("Bad form\n"); assert(0);
		case TRUSTEE_IS_OBJECTS_AND_SID:
			printf("Objects and SID\n"); break;
		case TRUSTEE_IS_OBJECTS_AND_NAME:
			printf("Objects and name\n"); break;
		default:
			printf("Unknown form\n"); assert(0);
		}

		printf("  Trustee type: ");
		switch(pEntry->Trustee.TrusteeType)
		{
		case TRUSTEE_IS_UNKNOWN:
			printf("Unknown type.\n"); break;
		case TRUSTEE_IS_USER:
			printf("User\n"); break;
		case TRUSTEE_IS_GROUP:
			printf("Group\n"); break;
		case TRUSTEE_IS_DOMAIN:
			printf("Domain\n"); break;
		case TRUSTEE_IS_ALIAS:
			printf("Alias\n"); break;
		case TRUSTEE_IS_WELL_KNOWN_GROUP:
			printf("Well-known group\n"); break;
		case TRUSTEE_IS_DELETED:
			printf("Deleted account\n"); break;
		case TRUSTEE_IS_INVALID:
			printf("Invalid trustee type\n"); break;
		case TRUSTEE_IS_COMPUTER:
			printf("Computer\n"); break;
		default:
			printf("Unknown type %d\n", pEntry->Trustee.TrusteeType); 
			assert(0);
		}

		printf("\n");
	}

	assert(LocalFree((HLOCAL)pEntries) == 0);
	assert(LocalFree((HLOCAL)pSecurityDesc) == 0);

	chdir("c:\\tmp");
	openfile("test", O_CREAT, 0);
	struct stat ourfs;
	//test our opendir, readdir and closedir
	//functions
	DIR *ourDir = opendir("C:");

	if ( ourDir != NULL )
	{
		struct dirent *info;
		do
		{
			info = readdir(ourDir);
			if (info) printf("File/Dir name is : %s\r\n", info->d_name);
		}
		while (info != NULL);

		closedir(ourDir);
	}
	
	std::string diry("C:\\Projects\\boxbuild\\testfiles\\");
	ourDir = opendir(diry.c_str());
	if ( ourDir != NULL )
	{
		struct dirent *info;
		do
		{
			info = readdir(ourDir);
			if (info == NULL) break;
			std::string file(diry + info->d_name);
			stat(file.c_str(), &ourfs);
			if (info) printf("File/Dir name is : %s\r\n", info->d_name);
		}
		while ( info != NULL );

		closedir(ourDir);

	}

	stat("c:\\windows", &ourfs);
	stat("c:\\autoexec.bat", &ourfs);
	printf("Finished dir read\n");

	//test our getopt function
	char * test_argv[] = 
	{
		"foobar.exe",
		"-qwc",
		"-",
		"-c",
		"fgfgfg",
		"-f",
		"-l",
		"hello",
		"-",
		"force-sync",
		NULL
	};
	int test_argc;
	for (test_argc = 0; test_argv[test_argc]; test_argc++) { }
	const char* opts = "qwc:l:";

	assert(getopt(test_argc, test_argv, opts) == 'q');
	assert(getopt(test_argc, test_argv, opts) == 'w');
	assert(getopt(test_argc, test_argv, opts) == 'c');
	assert(strcmp(optarg, "-") == 0);
	assert(getopt(test_argc, test_argv, opts) == 'c');
	assert(strcmp(optarg, "fgfgfg") == 0);
	assert(getopt(test_argc, test_argv, opts) == '?');
	assert(optopt == 'f');
	assert(getopt(test_argc, test_argv, opts) == 'l');
	assert(strcmp(optarg, "hello") == 0);
	assert(getopt(test_argc, test_argv, opts) == -1);
	// assert(optopt == 0); // no more options
	assert(strcmp(test_argv[optind], "-") == 0);
	assert(strcmp(test_argv[optind+1], "force-sync") == 0);
	//end of getopt test
	
	//now test our statfs funct
	stat("c:\\cert.cer", &ourfs);

	char *timee;
	
	timee = ctime(&ourfs.st_mtime);

	if (S_ISREG(ourfs.st_mode))
	{
		printf("is a normal file\n");
	}
	else
	{
		printf("is a directory?\n");
		exit(1);
	}

	lstat(getenv("WINDIR"), &ourfs);

	if ( S_ISDIR(ourfs.st_mode))
	{
		printf("is a directory\n");
	}
	else
	{
		printf("is a file?\n");
		exit(1);
	}

	//test the syslog functions
	openlog("Box Backup", 0,0);
	//the old ones are the best...
	syslog(LOG_ERR, "Hello World");
	syslog(LOG_ERR, "Value of int is: %i", 6);

	closelog();

	/*
	//first off get the path name for the default 
	char buf[MAX_PATH];
	
	GetModuleFileName(NULL, buf, sizeof(buf));
	std::string buffer(buf);
	std::string conf("-c " + buffer.substr(0,(buffer.find("win32test.exe"))) + "bbackupd.conf");
	//std::string conf( "-c " + buffer.substr(0,(buffer.find("bbackupd.exe"))) + "bbackupd.conf");
	*/

	return 0;
}