Example #1
0
void update_wall_scale(World *w, int wall_num, fixed xscale, fixed yscale)
{
    Wall *wall;
    Texture *texture;
    fixed wall_length;

    if (wall_num < 0 || wall_num > TABLE_SIZE(w->walls))
        fatal_error("invalid wall number");

    wall = (Wall *) w->walls->table + wall_num;
    texture = wall->surface_texture;

    wall_length =
        FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(wall->vertex2->x -
                                           wall->vertex1->x) *
                            FIXED_TO_FLOAT(wall->vertex2->x -
                                           wall->vertex1->x) +
                            FIXED_TO_FLOAT(wall->vertex2->y -
                                           wall->vertex1->y) *
                            FIXED_TO_FLOAT(wall->vertex2->y -
                                           wall->vertex1->y)));
    wall->yscale = fixmul(yscale, INT_TO_FIXED(texture->height));
    wall->xscale = fixmul(fixmul(xscale, INT_TO_FIXED(texture->width)),
                          wall_length);
}
Example #2
0
void CFmBall::CheckUpperFence()																//위쪽 펜스 비교
{
/*	if (m_pPos->GetY() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS) && m_pPos->GetY() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17))			//펜스 넘어감
	{
		if (m_pPos->GetZ() < INT_TO_FIXED(17))				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	} else if (m_pPos->GetY() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17) && m_pPos->GetY() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30)) {
		if (m_pPos->GetZ() < 0)				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	} else if (m_pPos->GetY() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30) && m_pPos->GetY() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30+37)) {
		if (m_pPos->GetZ() < INT_TO_FIXED(37))				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	}
    
	if (abs(m_pPos->GetX()) > INT_TO_FIXED(SIDE_FENCE_DIS_X*BACK_X/1000) && abs(m_pPos->GetX()) < INT_TO_FIXED(SIDE_FENCE_DIS_X*BACK_X/1000 + 17))		//펜스 넘어감
	{
		if (m_pPos->GetZ() < INT_TO_FIXED(17))				//펜스 높이에 걸림
		{
			if(m_pPos->GetX() > 0) {
				m_pPos->SetX(INT_TO_FIXED(SIDE_FENCE_DIS_X*BACK_X/1000));
			} else {
				m_pPos->SetX(-INT_TO_FIXED(SIDE_FENCE_DIS_X*BACK_X/1000));
			}
			m_nAngle = Mod(360-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	} else {
        
		if (abs(m_pPos->GetX()) > INT_TO_FIXED(BACK_X+500))		//펜스 넘어감
		{
			m_nAngle = Mod(360-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 6;
			m_nSpeedZ = m_nSpeedZ / 6;
		}
	}*/
    
    if (abs(m_pPos->GetY()) > INT_TO_FIXED(BACK_Y))//+500))		//펜스 넘어감
	{
        m_pPos->SetY(FmSign(m_pPos->GetY())*INT_TO_FIXED(BACK_Y));
		m_nAngle = Mod(180-m_nAngle, 360);
//		m_nSpeed = m_nSpeed / 6;
//		m_nSpeedZ = m_nSpeedZ / 6;
	}
}
Example #3
0
bool CFmBall::Update(bool bTmp/* = false*/)
{
    bool ret = false;
    //좌표이동
    *m_pPos = *m_pPos + FmP3D(-sin(CC_DEGREES_TO_RADIANS(m_nAngle))*m_nSpeed, cos(CC_DEGREES_TO_RADIANS(m_nAngle))*m_nSpeed, m_nSpeedZ);
    
    if(!bTmp)
        ret = CheckGoalpost();
    
    if(m_pPos->GetZ() <= 0)                     //땅에 닿았을때 처리
    {
        if(m_nSpeedZ == 0)
        {
            if(m_nSpeed/20 > CON_SPEED_REG2)
                m_nSpeed -= m_nSpeed/20;        //공 빠르면 많이 차감
            else
                m_nSpeed -= CON_SPEED_REG2;     //공기 저항 속도
        }
        else
        {
            m_nSpeed = m_nSpeed * CON_SPEED_REG/1000 - CON_SPEED_REG2;
        }
        
        m_nSpeedZ = -m_nSpeedZ * CON_SPEEDZ_REG/1000 - CON_SPEEDZ_REG2;         //Z축 속도 감소
        if(m_nSpeedZ < INT_TO_FIXED(1))
            m_nSpeedZ = 0;
        
        m_pPos->SetZ(0);
        m_nAngle = m_nAngle + m_nSpin/16;
        m_nSpin = m_nSpin * CON_SPIN_REG/1000;
        
        if(!bTmp)
        {
            if(m_nSpeedZ != 0)
                SetBoundPos();
            else
                m_nBoundHH = -1;
        }
    }
    else
    {
        m_nSpeed = m_nSpeed * CON_SPEED_AIR_REG/1000;
        m_nSpeedZ -= CON_SPEEDZ_AIR_REG;
        int t = 10 + m_nSpeed / INT_TO_FIXED(30);
        m_nAngle = m_nAngle + m_nSpin*t/900;
        m_nSpin = m_nSpin * CON_SPIN_AIR_REG/1000;
    }
    
    m_nAngle = Mod(m_nAngle, 360);
    if(m_nSpeed < INT_TO_FIXED(1))
        m_nSpeed = 0;
    if(m_nNotForceFlag > 0)
        m_nNotForceFlag--;
    if(m_nMissFlag > 0)
        m_nMissFlag--;
    
    return ret;
}
Example #4
0
bool CFmBall::CheckGoalpost()																//골대 비교
{
	if(m_nSpeed == 0)	return false;
	int tmpx = abs(m_pPos->GetX()) - abs(INT_TO_FIXED(BACK_X));
	int tmpy = abs(m_pPos->GetY()) - abs(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000));
	int rate = 20;
	if(tmpx*tmpx+tmpy*tmpy < INT_TO_FIXED(5)*INT_TO_FIXED(5))									//골포스트 맞음
	{
		int movex, movey;
		for(int i = 0; i <= 20; ++i)
		{
			movex = m_pPos->GetX() + (sin(CC_DEGREES_TO_RADIANS(m_nAngle))*i*m_nSpeed)/20;
			movey = m_pPos->GetY() - (cos(CC_DEGREES_TO_RADIANS(m_nAngle))*i*m_nSpeed)/20;
			tmpx = abs(movex) - abs(INT_TO_FIXED(BACK_X));
			tmpy = abs(movey) - abs(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000));
			if(tmpx*tmpx+tmpy*tmpy < INT_TO_FIXED(5)*INT_TO_FIXED(5)) continue;
			rate = i-1;
			break;
		}
		m_pPos->SetX(m_pPos->GetX() + (sin(CC_DEGREES_TO_RADIANS(m_nAngle))*rate*m_nSpeed)/20);
		m_pPos->SetY(m_pPos->GetY() - (cos(CC_DEGREES_TO_RADIANS(m_nAngle))*rate*m_nSpeed)/20);
        
		FmP3D cBack = FmP3D((FmSign(m_pPos->GetX()))*abs(INT_TO_FIXED(BACK_X)), FmSign(m_pPos->GetY())*abs(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000)));
		m_nAngle = cBack.GetAngle(*m_pPos);
		m_nMissFlag = 8;
		m_nSpeed = m_nSpeed*(rand()%20+60)/100;
		m_nSpeedZ = m_nSpeedZ*(rand()%20+60)/100;
		return true;
	}
	return false;
}
Example #5
0
void anim_staraptor_oam_callback(oam_object *self){
    FIXED period = INT_TO_FIXED(32);
    FIXED amplitude = INT_TO_FIXED(3);
    FIXED x = INT_TO_FIXED((self->private[0])++);
    x = FIXED_DIV(x, period);
    FIXED y = FIXED_COS(x);
    y = FIXED_MUL(y, amplitude);
    int y2 = FIXED_TO_INT(y);
    self->y2 = (s16)y2;
    
}
Example #6
0
void dungeon2_wild_pokemon_sample_level_boundaries(u8 *level_min, u8 *level_max, u8 mean,
    u8 std_deviation, dungeon_generator2 *dg2) {
  FIXED fx1 = FIXED_ADD(INT_TO_FIXED(mean), FIXED_MUL(INT_TO_FIXED(std_deviation),
      dungeon2_rnd_normal(dg2)));
  FIXED fx2 = FIXED_ADD(INT_TO_FIXED(mean), FIXED_MUL(INT_TO_FIXED(std_deviation),
      dungeon2_rnd_normal(dg2)));
  int x1 = min(100, max(2, FIXED_TO_INT(fx1)));
  int x2 = min(100, max(2, FIXED_TO_INT(fx2)));
  *level_min = (u8)min(x1, x2);
  *level_max = (u8)max(x1, x2);
}
Example #7
0
void centerTimeEditPrepare(void)
{
	//Î÷èñòèòü ýêðàíû
	MyGDC_FillArea(L5ADR0, GDC_16BPP_FORMAT, 0, 0, L5_WIDTH, L5_HEIGHT, GDC_TRANS16);	
	MyGDC_FillArea(L2ADR0, GDC_DRAW_FORMAT, 50+CENTER_X_POS, 15+CENTER_Y_POS, CENTER_WIDTH-100, 30, MENU_COLOR);	
	MyGDC_FillArea(L4ADR0, GDC_16BPP_FORMAT, 0, 0, WIN_WIDTH, WIN_HEIGHT, GDC_TRANS16);	
	Text_DrawText("ÈÇÌÅÍÅÍÈÅ ÂÐÅÌÅÍÈ", FALSE, 200+CENTER_X_POS, 15+CENTER_Y_POS, FONT_ALIGN_CENTER, FONT_ARIAL18, L2ADR0, GDC_WHITE16);
	
	XGdcDrawDimension(&g_stcMyGDC_DrvCTX, GDC_16BPP_FORMAT, L4ADR0, WIN_WIDTH, WIN_HEIGHT);
	XGdcPrimType (&g_stcMyGDC_DrvCTX, GDC_TRIANGLE_FAN);
		XGdcColor (&g_stcMyGDC_DrvCTX, GDC_YELLOW16);
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, INT_TO_FIXED(0), INT_TO_FIXED(0));
		XGdcColor (&g_stcMyGDC_DrvCTX, GDC_YELLOW16);
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, INT_TO_FIXED(300), INT_TO_FIXED(0));
		XGdcColor (&g_stcMyGDC_DrvCTX, GDC_YELLOW16);
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, INT_TO_FIXED(300), INT_TO_FIXED(50));
		XGdcColor (&g_stcMyGDC_DrvCTX, GDC_YELLOW16);
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, INT_TO_FIXED(0), INT_TO_FIXED(50));
	XGdcPrimEnd(&g_stcMyGDC_DrvCTX);
	
	GdcDispSetLayerWindow(GDC_DISP_LAYER_L4 , CENTER_X_POS + 108, CENTER_Y_POS + 85, 55, 40);
	GdcDispPos(GDC_DISP_LAYER_L4, 0, 0, 0);
	GdcDispPos(GDC_DISP_LAYER_L5, 0, 0, 0);
	time_edit = m_unTime;
	posMenu = Hours;
}
Example #8
0
int wt_init(char *pszWorldFile, int width, int height)
{
     FILE *fp;

     if ((fp = fopen(pszWorldFile, "r")) == NULL) {
   	  perror(pszWorldFile);
   	  exit(EXIT_FAILURE);
     }
     w = read_world_file(fp);
     fclose(fp);

     init_graphics();
     init_renderer(width, height);
     init_input_devices();

     /* setup view */
     view = new_view(fixdiv(FIXED_2PI, INT_TO_FIXED(4)));

     view->x = FIXED_ZERO;
     view->y = FIXED_ZERO;
     view->height = FIXED_ONE;
     view->angle = FIXED_ZERO;

     frames = 0;
     return EXIT_SUCCESS;
}
Example #9
0
void InitializeFixedPoint()
{
   int i, j;

   for (i=0; i<3; i++)
      for (j=0; j<4; j++)
         WorldViewXform[i][j] = INT_TO_FIXED(IntWorldViewXform[i][j]);
}
Example #10
0
Satellite_t* Satellite_Init(QueueHandle_t eventMaster, FlightModeHandler_t* stateHandler, SpHandler_t* setpointHandler, CtrlModeHandler_t * CtrlModeHandler)
{
  /* Create the queue used to pass things to the display task*/
  Satellite_t* taskParam = pvPortMalloc(sizeof(Satellite_t));
  taskParam->decoded_data = pvPortMalloc(sizeof(spektrum_data_t));
  taskParam->configuration = pvPortMalloc(sizeof(spectrum_config_t));
  taskParam->setpoint = pvPortMalloc(sizeof(state_data_t));
  taskParam->satellite_receive_buffer = pvPortMalloc(SATELLITE_MESSAGE_LENGTH * 2);
  taskParam->setpointHandler = setpointHandler;
  taskParam->CtrlModeHandler = CtrlModeHandler;
  taskParam->stateHandler = stateHandler;
  taskParam->multiplier = INT_TO_FIXED(1, FP_16_16_SHIFT);
  taskParam->throMult = INT_TO_FIXED(1, FP_16_16_SHIFT);
  taskParam->xMutexParam = xSemaphoreCreateMutex();
  taskParam->current_state = fmode_not_available;
  taskParam->current_control_mode = Control_mode_not_available;
  taskParam->evHandler = Event_CreateHandler(eventMaster,0);

  param_obj_t * ReceiverRoot = Param_CreateObj(3, variable_type_NoType, readOnly, NULL, "Rcver", Param_GetRoot(), NULL);

  // Enable receiver sensitivity adjustment.
  Param_CreateObj(0, variable_type_fp_16_16, readWrite, &taskParam->multiplier, "mult", ReceiverRoot, taskParam->xMutexParam);

  Param_CreateObj(0, variable_type_fp_16_16, readWrite, &taskParam->throMult, "TMult", ReceiverRoot, taskParam->xMutexParam);

  if( !taskParam || !taskParam->decoded_data || !taskParam->configuration || !taskParam->setpoint
      || !taskParam->satellite_receive_buffer || !taskParam->xMutexParam || !taskParam->evHandler)
  {
    return NULL;
  }
  //Scope so that the tmp structs live a short life.
  {
    spektrum_data_t tmpData = {{{0}}};
    *taskParam->decoded_data = tmpData;

    spectrum_config_t tmpConfig = {{{0}}};
    *taskParam->configuration = tmpConfig;

    state_data_t tmpSetpoint = {{0}};
    *taskParam->setpoint = tmpSetpoint;
  }

  return taskParam;
}
Example #11
0
void dungeon2_set_encounter_cave() {
  dungeon_generator2 *dg2 = &(cmem.dg2);
  dungeon2_cave_init_state(dg2);
  pokemon_clear_opponent_party();

  u16 species = *var_access(DUNGEON_OVERWORLD_SPECIES);
  u8 mean = 0, std_deviation = 0;
  dungeon2_cave_wild_pokemon_level_distribution(&mean, &std_deviation);
  mean = (u8)(mean + std_deviation + std_deviation / 2); // High level for this pokemon

  int level = FIXED_TO_INT(FIXED_ADD(INT_TO_FIXED(mean), FIXED_MUL(INT_TO_FIXED(std_deviation),
        dungeon2_rnd_normal(dg2))));
  level = max(min(level, 100), 2);

  pid_t p = {dungeon2_rnd(dg2)};

  pokemon_spawn_by_seed_algorithm(&opponent_pokemon[0], species, (u8)level, 32, true, p, false, 0,
      dungeon2_encounter_rnd_generator, dungeon2_encounter_rnd_generator);
}
Example #12
0
/* Set up the empty object list, with sentinels at both ends to
   terminate searches */
void InitializeObjectList()
{
   ObjectListStart.NextObject = &ObjectListEnd;
   ObjectListStart.PreviousObject = NULL;
   ObjectListStart.CenterInView.Z = INT_TO_FIXED(-32768);
   ObjectListEnd.NextObject = NULL;
   ObjectListEnd.PreviousObject = &ObjectListStart;
   ObjectListEnd.CenterInView.Z = 0x7FFFFFFFL;
   NumObjects = 0;
}
Example #13
0
void CFmBall::CheckGoalArea()
{
	if(abs(m_pPos->GetX()) > abs(INT_TO_FIXED(GOALPOST_X*BACK_X/1000)))
	{
		m_pPos->SetX(INT_TO_FIXED(GOALPOST_X*BACK_X/1000)*FmSign(m_pPos->GetX()));
		m_nAngle = Mod(360-m_nAngle, 360);
        
		m_nSpeedZ = m_nSpeedZ/6;
		m_nSpeed = m_nSpeed/6;
		//if(m_pPos->GetZ() < INT_TO_FIXED(20))
		//	m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][2]->GetAniObject()->InitMotion(6, false);
		//else
		//	m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][2]->GetAniObject()->InitMotion(5, false);
		//GET_APP()->PlaySound(SOUND_KIND_GOALWEB, false);
	}
    
	if (abs(m_pPos->GetY()) > abs(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000)))
	{
		m_pPos->SetY(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000)*FmSign(m_pPos->GetY()));
		m_nAngle = Mod(180-m_nAngle, 360);
		m_nSpeedZ = m_nSpeedZ / 6;
		m_nSpeed = m_nSpeed / 3;
		//if(m_pPos->GetY() > 0)
		//	m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][0]->GetAniObject()->InitMotion(4, false);
	}
	if (m_pPos->GetZ() > INT_TO_FIXED(GOALPOST_Z))
	{
		m_pPos->SetZ(INT_TO_FIXED(GOALPOST_Z));
		m_nSpeedZ = m_nSpeedZ / 6;
		m_nSpeed = m_nSpeed / 6;
		if (m_nSpeedZ > 0)
            m_nSpeedZ *= -1;
		//m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][0]->GetAniObject()->InitMotion(3, false);
	}
}
Example #14
0
void CFmBall::CheckGoalArea2()														//노골일 경우 골대와 비교
{
	if (abs(m_pPos->GetX()) > abs(INT_TO_FIXED(BACK_X)) && abs(m_pPos->GetX()) < abs(INT_TO_FIXED(GOALPOST_X*BACK_X/1000)) && (m_pPos->GetZ() < INT_TO_FIXED(GOALPOST_Z)) && abs(m_pPos->GetY()) < abs(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000)))
	{
		if (m_pPos->GetZ() - m_nSpeedZ - CON_SPEEDZ_AIR_REG < INT_TO_FIXED(GOALPOST_Z))	//골망의 옆쪽에 걸린경우
		{
			m_pPos->SetY(INT_TO_FIXED(GOALPOST_Y*BACK_Y/1000)*FmSign(m_pPos->GetY()));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeedZ = m_nSpeedZ / 6;
			m_nSpeed = m_nSpeed / 6;
			//if(m_pPos->GetY() > 0)
			//	m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][0]->GetAniObject()->InitMotion(4, false);
		}
		else																		//골망의 위쪽에 걸린 경우
		{
			m_pPos->SetZ(INT_TO_FIXED(GOALPOST_Z)+1);
			m_nSpeedZ = abs(m_nSpeedZ / 6);										//공은 위로 튀게
			m_nSpeed = m_nSpeed / 2;
			//m_pRefPlayMgr->m_pGoalPost[m_pPos->GetX()>0?1:0][0]->GetAniObject()->InitMotion(3, false);
		}
	}
}
Example #15
0
void CFmBall::CheckSideFence()																//위쪽 펜스 비교
{
/*	if (m_pPos->GetX() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS) && m_pPos->GetX() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17))			//펜스 넘어감
	{
		if (m_pPos->GetZ() < INT_TO_FIXED(17))				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	} else if (m_pPos->GetY() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17) && m_pPos->GetY() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30)) {
		if (m_pPos->GetZ() < INT_TO_FIXED(0))				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	} else if (m_pPos->GetY() < -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30) && m_pPos->GetY() > -INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30+37)) {
		if (m_pPos->GetZ() < INT_TO_FIXED(37))				//펜스 높이에 걸림
		{
			m_pPos->SetY(-INT_TO_FIXED(BACK_Y+UPPER_FENCE_DIS+17+30));
			m_nAngle = Mod(180-m_nAngle, 360);
			m_nSpeed = m_nSpeed / 4;
			m_nSpeedZ = m_nSpeedZ / 4;
		}
	}*/
    
    
	if (abs(m_pPos->GetX()) > INT_TO_FIXED(BACK_X))//+500))		//펜스 넘어감
	{
        m_pPos->SetX(FmSign(m_pPos->GetX())*INT_TO_FIXED(BACK_X));
		m_nAngle = Mod(360-m_nAngle, 360);
		//m_nSpeed = m_nSpeed / 6;
		//m_nSpeedZ = m_nSpeedZ / 6;
	}
}
Example #16
0
void CFmBall::Bound(int nTeam, int nIdx, int nAng)
{
    int t = (180 - abs(AngDis(m_nAngle, nAng))) / 45;               //0~3(순방향3, 역방향0)
    m_nTouchTeam = nTeam;
    m_nTouchPI = nIdx;
    m_nAngle = nAng;
    m_nSpeed = (m_nSpeed*(rand()%2+2+t))>>3;                    //(25%~62.5% , 37.5%~75%) 로 감속된다.
    m_nSpeedZ = (m_nSpeedZ*(rand()%2+2+t))>>4;                  //(25%~62.5% , 37.5%~75%) 로 감속된다.
    SetBoundPos();
    m_nMissFlag = 0;
    m_nNotForceFlag = 0;
    if(m_nSpeed > INT_TO_FIXED(8))
        m_nMissFlag = 6;
}
Example #17
0
void CFmBall::Force(int nTeam, int nIdx, int nAng, int nPow, int nPowZ, int nSpin, bool dribble/* = false*/)
{
    if(nPow != 0 && m_nNotForceFlag > 0 && m_nTouchTeam == nTeam && m_nTouchPI == nIdx)
        return;
    m_nTouchTeam = nTeam;
    m_nTouchPI = nIdx;
    m_nAngle = nAng;
    m_nSpeed = nPow;
    m_nSpeedZ = nPowZ;
    m_nSpin = nSpin;
    m_nMissFlag = 0;
    
    if(m_nSpeed > INT_TO_FIXED(8))
		m_nMissFlag = 12;
}
Example #18
0
GLbitfield GLAPIENTRY _mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16])
{
    GLfloat matrix[16];
    GLint tmp;
    GLenum currentMode = GL_FALSE;
    GLenum desiredMatrix = GL_FALSE;
    /* The bitfield returns 1 for each component that is invalid (i.e.
     * NaN or Inf).  In case of error, everything is invalid.
     */
    GLbitfield rv;
    register unsigned int i;
    unsigned int bit;

    /* This data structure defines the mapping between the current matrix
     * mode and the desired matrix identifier.
     */
    static struct {
        GLenum currentMode;
        GLenum desiredMatrix;
    } modes[] = {
        {GL_MODELVIEW, GL_MODELVIEW_MATRIX},
        {GL_PROJECTION, GL_PROJECTION_MATRIX},
        {GL_TEXTURE, GL_TEXTURE_MATRIX},
    };

    /* Call Mesa to get the current matrix in floating-point form.  First,
     * we have to figure out what the current matrix mode is.
     */
    _mesa_GetIntegerv(GL_MATRIX_MODE, &tmp);
    currentMode = (GLenum) tmp;

    /* The mode is either GL_FALSE, if for some reason we failed to query
     * the mode, or a given mode from the above table.  Search for the
     * returned mode to get the desired matrix; if we don't find it,
     * we can return immediately, as _mesa_GetInteger() will have
     * logged the necessary error already.
     */
    for (i = 0; i < sizeof(modes)/sizeof(modes[0]); i++) {
        if (modes[i].currentMode == currentMode) {
            desiredMatrix = modes[i].desiredMatrix;
            break;
        }
    }
    if (desiredMatrix == GL_FALSE) {
        /* Early error means all values are invalid. */
        return 0xffff;
    }

    /* Now pull the matrix itself. */
    _mesa_GetFloatv(desiredMatrix, matrix);

    rv = 0;
    for (i = 0, bit = 1; i < 16; i++, bit<<=1) {
        float normalizedFraction;
        int exp;

        switch (fpclassify(matrix[i])) {
            /* A "subnormal" or denormalized number is too small to be
             * represented in normal format; but despite that it's a
             * valid floating point number.  FP_ZERO and FP_NORMAL
             * are both valid as well.  We should be fine treating
             * these three cases as legitimate floating-point numbers.
             */
            case FP_SUBNORMAL:
            case FP_NORMAL:
            case FP_ZERO:
                normalizedFraction = (GLfloat)frexp(matrix[i], &exp);
                mantissa[i] = FLOAT_TO_FIXED(normalizedFraction);
                exponent[i] = (GLint) exp;
                break;

            /* If the entry is not-a-number or an infinity, then the
             * matrix component is invalid.  The invalid flag for
             * the component is already set; might as well set the
             * other return values to known values.  We'll set
             * distinct values so that a savvy end user could determine
             * whether the matrix component was a NaN or an infinity,
             * but this is more useful for debugging than anything else
             * since the standard doesn't specify any such magic
             * values to return.
             */
            case FP_NAN:
                mantissa[i] = INT_TO_FIXED(0);
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;

            case FP_INFINITE:
                /* Return +/- 1 based on whether it's a positive or
                 * negative infinity.
                 */
                if (matrix[i] > 0) {
                    mantissa[i] = INT_TO_FIXED(1);
                }
                else {
                    mantissa[i] = -INT_TO_FIXED(1);
                }
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;

            /* We should never get here; but here's a catching case
             * in case fpclassify() is returnings something unexpected.
             */
            default:
                mantissa[i] = INT_TO_FIXED(2);
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;
        }

    } /* for each component */

    /* All done */
    return rv;
}
Example #19
0
int main(int argc, char *argv[])
{
     World *w;
     FILE *fp;
     Boolean quit = False;
     Intent *intent;
     fixed v = FIXED_ZERO;
     double vx = 0.0, vy = 0.0, va = 0.0;
     #ifdef MSDOS
     long       frames;
     time_t     starttime, endtime;
     #endif


     if (argc != 2) {
	  fprintf(stderr, "Usage:  wt <world file>\n");
	  exit(EXIT_FAILURE);
     }

     if ((fp = fopen(argv[1], "r")) == NULL) {
	  perror(argv[1]);
	  exit(EXIT_FAILURE);
     }
     w = read_world_file(fp);
     fclose(fp);

     init_graphics();
     init_renderer(SCREEN_WIDTH, SCREEN_HEIGHT);
     init_input_devices();

     /* setup view */
     view = new_view(fixdiv(FIXED_2PI, INT_TO_FIXED(4)));

     view->x = FIXED_ZERO;
     view->y = FIXED_ZERO;
     view->height = FIXED_ONE;
     view->angle = FIXED_ZERO;

     #ifdef MSDOS
     starttime = time(NULL);
     frames = 0;
     #endif

     while (!quit) {
	  double sin_facing, cos_facing;

	  render(w, view);
      #ifdef MSDOS
      frames++;
      #endif
	  intent = read_input_devices();

	  /* This block code is a hack to do acceleration and deceleration. */
	  if (fabs(vx) > fabs(intent->force_x)) {
	       if (vx < 0.0)
		    vx = MIN(vx + 0.1, intent->force_x);
	       else
		    vx = MAX(vx - 0.1, intent->force_x);
	  } else if (fabs(vx) < fabs(intent->force_x)) {
	       vx += intent->force_x / 5.0;
	       if (fabs(vx) > fabs(intent->force_x))
		    vx = intent->force_x;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  /* Angular deceleration here is weird and unrealistic, but it feels
	  **   right to me.
	  */
	  if (fabs(va) > fabs(intent->force_rotate))
	       va *= 0.6;
	  else if (fabs(va) < fabs(intent->force_rotate)) {
	       va += intent->force_rotate / 8.0;
	       if (fabs(va) > fabs(intent->force_rotate))
		    va = intent->force_rotate;
	  }
	  view->angle += FLOAT_TO_FIXED(0.3 * va);
	  sin_facing = sin(FIXED_TO_FLOAT(view->angle));
	  cos_facing = cos(FIXED_TO_FLOAT(view->angle));

	  view->x += FLOAT_TO_FIXED(0.8 * vx * cos_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vx * sin_facing);
	  view->x += FLOAT_TO_FIXED(0.8 * vy * -sin_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vy * cos_facing);
	  if (view->height > FIXED_ONE)
	       v -= FIXED_ONE / 16;
	  view->height += v;
	  if (view->height < FIXED_ONE) {
	       v = FIXED_ZERO;
	       view->height = FIXED_ONE;
	  }
	  while (intent->n_special--) {
	       if (intent->special[intent->n_special] == INTENT_END_GAME)
		    quit = True;
	       else
		    v = FIXED_ONE / 2;
	  }
     }

     #ifdef MSDOS
     endtime = time(NULL);
     #endif

     end_input_devices();
     end_graphics();

     #ifdef MSDOS
     printf("%li frames in %lu seconds - %.2f frames per second",
        (long) frames, (long) endtime - starttime,
        (float) frames / (float) (endtime-starttime));
     #endif

     return EXIT_SUCCESS;
}
Example #20
0
void CFmBall::SetBoundPos()
{
    CFmBall* pBall = new CFmBall();
    pBall->Init();
    *pBall = *this;
    pBall->m_nBoundHH = -1;
    pBall->m_tBoundPos.nX = 0;
    pBall->m_tBoundPos.nY = 0;
    pBall->m_tBoundPosSnd.nX = 0;
    pBall->m_tBoundPosSnd.nY = 0;
    
    bool bBound = false;
    int nBeforeSpdZ = 0;
    
    for(int i = 0; i < 150; i++)
    {
//        m_tBallTracePos[i].nX = -1;
//        m_tBallTracePos[i].nY = -1;
//        
//        m_tBallTracePos2[i].nX = -1;
//        m_tBallTracePos2[i].nY = -1;
    }
    
    for(int i = 0; i < 150; i++)
    {
        if(bBound == false)
            nBeforeSpdZ = m_nSpeedZ;
        Update(true);
        if(bBound == false && nBeforeSpdZ < 0 && m_nSpeedZ > 0)
            bBound = true;
        
//        m_tBallTracePos[i] = m_pPos->GetDD();
//        m_tBallTracePos[i] = m_pPos->GetDD(false);
        
        //공 머리 위치지점 체크
        if(pBall->m_tBoundPos.nX == 0 && pBall->m_tBoundPos.nY == 0 && bBound == false && m_nSpeedZ <= 0 && m_pPos->GetTrZ() < 80)
        {
            pBall->m_tBoundPos.nX = m_pPos->GetX();
            pBall->m_tBoundPos.nY = m_pPos->GetY();
        }
        
        //공 착지 위치 체크
        if(pBall->m_tBoundPosSnd.nX == 0 && pBall->m_tBoundPosSnd.nY == 0 && bBound)
        {
            pBall->m_tBoundPosSnd.nX = m_pPos->GetX();
            pBall->m_tBoundPosSnd.nY = m_pPos->GetY();
            break;
        }
        
        //경기장 밖으로 나가는 공에 대한 체크
        if(abs(m_pPos->GetX()) > INT_TO_FIXED(BACK_X)*11/10 || abs(m_pPos->GetY()) > INT_TO_FIXED(BACK_Y)*12/10)
        {
            pBall->m_tBoundPos.nX = m_pPos->GetX();
            pBall->m_tBoundPos.nY = m_pPos->GetY();
            pBall->m_tBoundPosSnd.nX = m_pPos->GetX();
            pBall->m_tBoundPosSnd.nY = m_pPos->GetY();
            break;
        }
        
        //공이 가장 높게 떴을때 Z좌표 체크
        if(m_pPos->GetTrZ() > pBall->m_nBoundHH)
        {
            pBall->m_nBoundHH = m_pPos->GetTrZ();
        }
    }
    
    *this = *pBall;
    CC_SAFE_DELETE(pBall);
}
Example #21
0
  cid_load_glyph( T1_Decoder  decoder,
                  FT_UInt     glyph_index )
  {
    CID_Face       face = (CID_Face)decoder->builder.face;
    CID_FaceInfo   cid  = &face->cid;
    FT_Byte*       p;
    FT_UInt        fd_select;
    FT_Stream      stream       = face->cid_stream;
    FT_Error       error        = CID_Err_Ok;
    FT_Byte*       charstring   = 0;
    FT_Memory      memory       = face->root.memory;
    FT_ULong       glyph_length = 0;
    PSAux_Service  psaux        = (PSAux_Service)face->psaux;

#ifdef FT_CONFIG_OPTION_INCREMENTAL
    FT_Incremental_InterfaceRec *inc =
                                  face->root.internal->incremental_interface;
#endif


    FT_TRACE4(( "cid_load_glyph: glyph index %d\n", glyph_index ));

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* For incremental fonts get the character data using */
    /* the callback function.                             */
    if ( inc )
    {
      FT_Data  glyph_data;


      error = inc->funcs->get_glyph_data( inc->object,
                                          glyph_index, &glyph_data );
      if ( error )
        goto Exit;

      p         = (FT_Byte*)glyph_data.pointer;
      fd_select = (FT_UInt)cid_get_offset( &p, (FT_Byte)cid->fd_bytes );

      if ( glyph_data.length != 0 )
      {
        glyph_length = glyph_data.length - cid->fd_bytes;
        (void)FT_ALLOC( charstring, glyph_length );
        if ( !error )
          ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes,
                     glyph_length );
      }

      inc->funcs->free_glyph_data( inc->object, &glyph_data );

      if ( error )
        goto Exit;
    }

    else

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

    /* For ordinary fonts read the CID font dictionary index */
    /* and charstring offset from the CIDMap.                */
    {
      FT_UInt   entry_len = cid->fd_bytes + cid->gd_bytes;
      FT_ULong  off1;


      if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset +
                           glyph_index * entry_len )               ||
           FT_FRAME_ENTER( 2 * entry_len )                         )
        goto Exit;

      p            = (FT_Byte*)stream->cursor;
      fd_select    = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
      off1         = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
      p           += cid->fd_bytes;
      glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1;
      FT_FRAME_EXIT();

      if ( fd_select >= (FT_UInt)cid->num_dicts )
      {
        error = CID_Err_Invalid_Offset;
        goto Exit;
      }
      if ( glyph_length == 0 )
        goto Exit;
      if ( FT_ALLOC( charstring, glyph_length ) )
        goto Exit;
      if ( FT_STREAM_READ_AT( cid->data_offset + off1,
                              charstring, glyph_length ) )
        goto Exit;
    }

    /* Now set up the subrs array and parse the charstrings. */
    {
      CID_FaceDict  dict;
      CID_Subrs     cid_subrs = face->subrs + fd_select;
      FT_Int        cs_offset;


      /* Set up subrs */
      decoder->num_subrs = cid_subrs->num_subrs;
      decoder->subrs     = cid_subrs->code;
      decoder->subrs_len = 0;

      /* Set up font matrix */
      dict                 = cid->font_dicts + fd_select;

      decoder->font_matrix = dict->font_matrix;
      decoder->font_offset = dict->font_offset;
      decoder->lenIV       = dict->private_dict.lenIV;

      /* Decode the charstring. */

      /* Adjustment for seed bytes. */
      cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );

      /* Decrypt only if lenIV >= 0. */
      if ( decoder->lenIV >= 0 )
        psaux->t1_decrypt( charstring, glyph_length, 4330 );

      error = decoder->funcs.parse_charstrings(
                decoder, charstring + cs_offset,
                (FT_Int)glyph_length - cs_offset );
    }

    FT_FREE( charstring );

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* Incremental fonts can optionally override the metrics. */
    if ( !error && inc && inc->funcs->get_glyph_metrics )
    {
      FT_Incremental_MetricsRec  metrics;


      metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
      metrics.bearing_y = 0;
      metrics.advance   = FIXED_TO_INT( decoder->builder.advance.x );
      metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );

      error = inc->funcs->get_glyph_metrics( inc->object,
                                             glyph_index, FALSE, &metrics );

      decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
      decoder->builder.advance.x      = INT_TO_FIXED( metrics.advance );
      decoder->builder.advance.y      = INT_TO_FIXED( metrics.advance_v );
    }

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

  Exit:
    return error;
  }
Example #22
0
void update_clock_area_layer(Layer *l, GContext* ctx) {
  // check layer bounds
  GRect bounds = layer_get_unobstructed_bounds(l);

  #ifdef PBL_ROUND
    bounds = GRect(0, ROUND_VERTICAL_PADDING, screen_rect.size.w, screen_rect.size.h - ROUND_VERTICAL_PADDING * 2);
  #endif

  // initialize FCTX, the fancy 3rd party drawing library that all the cool kids use
  FContext fctx;

  fctx_init_context(&fctx, ctx);
  fctx_set_color_bias(&fctx, 0);
  fctx_set_fill_color(&fctx, globalSettings.timeColor);


  // calculate font size
  int font_size = 4 * bounds.size.h / 7;

  // avenir + avenir bold metrics
  int v_padding = bounds.size.h / 16;
  int h_adjust = 0;
  int v_adjust = 0;

  // alternate metrics for LECO
  if(globalSettings.clockFontId == FONT_SETTING_LECO) {
    font_size = 4 * bounds.size.h / 7 + 6;
    v_padding = bounds.size.h / 20;
    h_adjust = -4;
    v_adjust = 0;

    // leco looks awful with antialiasing
    #ifdef PBL_COLOR
      fctx_enable_aa(false);
    #endif
  } else {
    #ifdef PBL_COLOR
      fctx_enable_aa(true);
    #endif
  }

  // if it's a round watch, EVERYTHING CHANGES
  #ifdef PBL_ROUND
    v_adjust = ROUND_VERTICAL_PADDING;

    if(globalSettings.clockFontId != FONT_SETTING_LECO) {
      h_adjust = -1;
    }
  #else
    // for rectangular watches, adjust X position based on sidebar position
    if(globalSettings.sidebarOnLeft) {
      h_adjust += ACTION_BAR_WIDTH / 2;
    } else {
      h_adjust -= ACTION_BAR_WIDTH / 2 + 1;
    }
  #endif

  FPoint time_pos;
  fctx_begin_fill(&fctx);
  fctx_set_text_em_height(&fctx, hours_font, font_size);
  fctx_set_text_em_height(&fctx, minutes_font, font_size);

  // draw hours
  time_pos.x = INT_TO_FIXED(bounds.size.w / 2 + h_adjust);
  time_pos.y = INT_TO_FIXED(v_padding + v_adjust);
  fctx_set_offset(&fctx, time_pos);
  fctx_draw_string(&fctx, time_hours, hours_font, GTextAlignmentCenter, FTextAnchorTop);

  //draw minutes
  time_pos.y = INT_TO_FIXED(bounds.size.h - v_padding + v_adjust);
  fctx_set_offset(&fctx, time_pos);
  fctx_draw_string(&fctx, time_minutes, minutes_font, GTextAlignmentCenter, FTextAnchorBaseline);
  fctx_end_fill(&fctx);

  fctx_deinit_context(&fctx);
}
Example #23
0
  static FT_Error
  T1_Parse_Glyph_And_Get_Char_String( T1_Decoder  decoder,
                                      FT_UInt     glyph_index,
                                      FT_Data*    char_string )
  {
    T1_Face   face  = (T1_Face)decoder->builder.face;
    T1_Font   type1 = &face->type1;
    FT_Error  error = FT_Err_Ok;

#ifdef FT_CONFIG_OPTION_INCREMENTAL
    FT_Incremental_InterfaceRec *inc =
                      face->root.internal->incremental_interface;
#endif


    decoder->font_matrix = type1->font_matrix;
    decoder->font_offset = type1->font_offset;

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* For incremental fonts get the character data using the */
    /* callback function.                                     */
    if ( inc )
      error = inc->funcs->get_glyph_data( inc->object,
                                          glyph_index, char_string );
    else

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

    /* For ordinary fonts get the character data stored in the face record. */
    {
      char_string->pointer = type1->charstrings[glyph_index];
      char_string->length  = (FT_Int)type1->charstrings_len[glyph_index];
    }

    if ( !error )
      error = decoder->funcs.parse_charstrings(
                decoder, (FT_Byte*)char_string->pointer,
                (FT_UInt)char_string->length );

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* Incremental fonts can optionally override the metrics. */
    if ( !error && inc && inc->funcs->get_glyph_metrics )
    {
      FT_Incremental_MetricsRec  metrics;


      metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
      metrics.bearing_y = 0;
      metrics.advance   = FIXED_TO_INT( decoder->builder.advance.x );
      metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );

      error = inc->funcs->get_glyph_metrics( inc->object,
                                             glyph_index, FALSE, &metrics );

      decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
      decoder->builder.advance.x      = INT_TO_FIXED( metrics.advance );
      decoder->builder.advance.y      = INT_TO_FIXED( metrics.advance_v );
    }

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

    return error;
  }
Example #24
0
void on_layer_update(Layer* layer, GContext* ctx) {

    GRect bounds = layer_get_bounds(layer);
    FPoint center = FPointI(bounds.size.w / 2, bounds.size.h / 2);
    int16_t outer_radius = bounds.size.w / 2 - BEZEL_INSET;
    int16_t pip_size = 6;
    int32_t minute_angle = g_local_time.tm_min * TRIG_MAX_ANGLE / 60;
    int32_t hour_angle = (g_local_time.tm_hour % 12) * TRIG_MAX_ANGLE / 12
                       +  g_local_time.tm_min        * TRIG_MAX_ANGLE / (12 * 60);
    char date_string[3];
    strftime(date_string, sizeof date_string, "%d", &g_local_time);

    FContext fctx;
    fctx_init_context(&fctx, ctx);
    fctx_set_color_bias(&fctx, 0);
    fctx_set_fill_color(&fctx, GColorBlack);

    /* Draw the pips. */
    fixed_t bar_length = INT_TO_FIXED(pip_size);
    fixed_t dot_radius = INT_TO_FIXED(pip_size - 4) / 2;
    fixed_t pips_radius = INT_TO_FIXED(outer_radius) - INT_TO_FIXED(pip_size) / 2;
    fctx_begin_fill(&fctx);
    fctx_set_pivot(&fctx, FPoint(0, pips_radius));
    fctx_set_offset(&fctx, center);
    for (int m = 0; m < 60; ++m) {
        int32_t angle = m * TRIG_MAX_ANGLE / 60;
        if (0 == m % 5) {
            fixed_t pipw = (m % 15 == 0) ? INT_TO_FIXED(2) : INT_TO_FIXED(1);
            fctx_set_rotation(&fctx, angle);
            fctx_move_to(&fctx, FPoint(-pipw, -bar_length / 2));
            fctx_line_to(&fctx, FPoint( pipw, -bar_length / 2));
            fctx_line_to(&fctx, FPoint( pipw,  bar_length / 2));
            fctx_line_to(&fctx, FPoint(-pipw,  bar_length / 2));
            fctx_close_path(&fctx);
        } else {
            FPoint p = clockToCartesian(center, pips_radius, angle);
            fctx_plot_circle(&fctx, &p, dot_radius);
        }
    }
    fctx_end_fill(&fctx);

    /* Set up for drawing the hands. */
    int16_t from_size = 90;
    int16_t to_size = outer_radius - pip_size;
    fctx_set_scale(&fctx, FPoint(from_size, from_size), FPoint(to_size, to_size));
    fctx_set_pivot(&fctx, FPointI(90, 90));
    fctx_set_offset(&fctx, center);

    /* Draw the hour hand. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorDarkGray);
    fctx_set_rotation(&fctx, hour_angle);
    fctx_draw_commands(&fctx, FPointZero, g_hour->data, g_hour->size);
    fctx_end_fill(&fctx);

    /* Draw the minute hand. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorBlack);
    fctx_set_rotation(&fctx, minute_angle);
    fctx_draw_commands(&fctx, FPointZero, g_minute->data, g_minute->size);
    fctx_end_fill(&fctx);

    /* Draw the body. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorBlack);
    fctx_set_rotation(&fctx, 0);
    fctx_draw_commands(&fctx, FPointZero, g_body->data, g_body->size);
    fctx_end_fill(&fctx);

    /* Draw the date. */
    FPoint date_pos;
    date_pos.x = center.x + INT_TO_FIXED( 5) * to_size / from_size;
    date_pos.y = center.y + INT_TO_FIXED(48) * to_size / from_size;
    fctx_begin_fill(&fctx);
    fctx_set_text_em_height(&fctx, g_font, 30 * to_size / from_size);
    fctx_set_fill_color(&fctx, GColorWhite);
    fctx_set_pivot(&fctx, FPointZero);
    fctx_set_offset(&fctx, date_pos);
    fctx_set_rotation(&fctx, -5 * TRIG_MAX_ANGLE / (2*360));
    fctx_draw_string(&fctx, date_string, g_font, GTextAlignmentCenter, FTextAnchorBaseline);
    fctx_end_fill(&fctx);

    fctx_deinit_context(&fctx);
}
Example #25
0
  static FT_Error
  T1_Parse_Glyph_And_Get_Char_String( T1_Decoder  decoder,
                                      FT_UInt     glyph_index,
                                      FT_Data*    char_string,
                                      FT_Bool*    force_scaling )
  {
    T1_Face   face  = (T1_Face)decoder->builder.face;
    T1_Font   type1 = &face->type1;
    FT_Error  error = FT_Err_Ok;

    PSAux_Service           psaux         = (PSAux_Service)face->psaux;
    const T1_Decoder_Funcs  decoder_funcs = psaux->t1_decoder_funcs;
    PS_Decoder              psdecoder;

#ifdef FT_CONFIG_OPTION_INCREMENTAL
    FT_Incremental_InterfaceRec *inc =
                      face->root.internal->incremental_interface;
#endif

#ifdef T1_CONFIG_OPTION_OLD_ENGINE
    PS_Driver  driver = (PS_Driver)FT_FACE_DRIVER( face );
#endif

    decoder->font_matrix = type1->font_matrix;
    decoder->font_offset = type1->font_offset;

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* For incremental fonts get the character data using the */
    /* callback function.                                     */
    if ( inc )
      error = inc->funcs->get_glyph_data( inc->object,
                                          glyph_index, char_string );
    else

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

    /* For ordinary fonts get the character data stored in the face record. */
    {
      char_string->pointer = type1->charstrings[glyph_index];
      char_string->length  = (FT_Int)type1->charstrings_len[glyph_index];
    }

    if ( !error )
    {
      /* choose which renderer to use */
#ifdef T1_CONFIG_OPTION_OLD_ENGINE
      if ( driver->hinting_engine == FT_HINTING_FREETYPE ||
           decoder->builder.metrics_only                 )
        error = decoder_funcs->parse_charstrings_old(
                  decoder,
                  (FT_Byte*)char_string->pointer,
                  (FT_UInt)char_string->length );
#else
      if ( decoder->builder.metrics_only )
        error = decoder_funcs->parse_metrics(
                  decoder,
                  (FT_Byte*)char_string->pointer,
                  (FT_UInt)char_string->length );
#endif
      else
      {
        CFF_SubFontRec  subfont;


        psaux->ps_decoder_init( &psdecoder, decoder, TRUE );

        psaux->t1_make_subfont( FT_FACE( face ),
                                &face->type1.private_dict, &subfont );
        psdecoder.current_subfont = &subfont;

        error = decoder_funcs->parse_charstrings(
                  &psdecoder,
                  (FT_Byte*)char_string->pointer,
                  (FT_ULong)char_string->length );

        /* Adobe's engine uses 16.16 numbers everywhere;              */
        /* as a consequence, glyphs larger than 2000ppem get rejected */
        if ( FT_ERR_EQ( error, Glyph_Too_Big ) )
        {
          /* this time, we retry unhinted and scale up the glyph later on */
          /* (the engine uses and sets the hardcoded value 0x10000 / 64 = */
          /* 0x400 for both `x_scale' and `y_scale' in this case)         */
          ((T1_GlyphSlot)decoder->builder.glyph)->hint = FALSE;

          *force_scaling = TRUE;

          error = decoder_funcs->parse_charstrings(
                    &psdecoder,
                    (FT_Byte*)char_string->pointer,
                    (FT_ULong)char_string->length );
        }
      }
    }

#ifdef FT_CONFIG_OPTION_INCREMENTAL

    /* Incremental fonts can optionally override the metrics. */
    if ( !error && inc && inc->funcs->get_glyph_metrics )
    {
      FT_Incremental_MetricsRec  metrics;


      metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
      metrics.bearing_y = 0;
      metrics.advance   = FIXED_TO_INT( decoder->builder.advance.x );
      metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );

      error = inc->funcs->get_glyph_metrics( inc->object,
                                             glyph_index, FALSE, &metrics );

      decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
      decoder->builder.advance.x      = INT_TO_FIXED( metrics.advance );
      decoder->builder.advance.y      = INT_TO_FIXED( metrics.advance_v );
    }

#endif /* FT_CONFIG_OPTION_INCREMENTAL */

    return error;
  }
Example #26
0
void parse_wall(FILE *fp, World *w)
{
    Wall wall;
    char texture_name[STRING_TOKEN_MAX_LENGTH];
    int texture_index;
    int front_region, back_region;
    int vertex1, vertex2;
    fixed wall_length;


    /* vertices */
    if (get_integer_token(fp, &vertex1) != Token_integer)
        parse_error("integer expected");
    if (get_integer_token(fp, &vertex2) != Token_integer)
        parse_error("integer expected");
    if (vertex1 < 0 || vertex1 > TABLE_SIZE(w->vertices))
        parse_error("invalid vertex number");
    if (vertex2 < 0 || vertex2 > TABLE_SIZE(w->vertices))
        parse_error("invalid vertex number");
    wall.vertex1 = &WORLD_VERTEX(w, vertex1);
    wall.vertex2 = &WORLD_VERTEX(w, vertex2);

    /* texture */
    if (get_string_token(fp, texture_name) != Token_string)
        parse_error("texture name expected");
    texture_index = get_texture_index(texture_name);
    if (texture_index < 0 || texture_index > TABLE_SIZE(w->textures))
        parse_error("non-existent texture");
    else
        wall.surface_texture = WORLD_TEXTURE(w, texture_index);

    if (strcmp(texture_name, "sky") == 0)
        wall.sky = True;
    else
        wall.sky = False;

    /* front and back regions */
    if (get_integer_token(fp, &front_region) != Token_integer)
        fatal_error("non-existent region");
    if (get_integer_token(fp, &back_region) != Token_integer)
        fatal_error("non-existent region");
    if (front_region < 0 || front_region > TABLE_SIZE(w->regions))
        fatal_error("non-existent region");
    if (back_region < 0 || back_region > TABLE_SIZE(w->regions))
        fatal_error("non-existent region");
    wall.front = &WORLD_REGION(w, front_region);
    wall.back = &WORLD_REGION(w, back_region);

    /* Texture phase and scale.  This code is somewhat more complicated than
    **   you'd expect, since the texture scale must be normalized to the
    **   wall length.
    */
    if (get_real_token(fp, &wall.xscale) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.yscale) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.xphase) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.yphase) != Token_real)
        parse_error("number expected");
    wall_length =
        FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(wall.vertex2->x -
                                           wall.vertex1->x) *
                            FIXED_TO_FLOAT(wall.vertex2->x -
                                           wall.vertex1->x) +
                            FIXED_TO_FLOAT(wall.vertex2->y -
                                           wall.vertex1->y) *
                            FIXED_TO_FLOAT(wall.vertex2->y -
                                           wall.vertex1->y)));
    wall.yscale = fixmul(wall.yscale,
                         INT_TO_FIXED(wall.surface_texture->height));
    wall.xscale = fixmul(fixmul(wall.xscale,
                                INT_TO_FIXED(wall.surface_texture->width)),
                         wall_length);

    add_wall(w, &wall);
}