예제 #1
0
static int	ft_get_length(char const *s, unsigned int *first_ok_index, unsigned
		int *last_ok_index)
{
	unsigned int	i;
	unsigned int	length;

	i = 0;
	length = 0;
	while (wh(s[i]))
		i++;
	*first_ok_index = i;
	while (s[i])
	{
		i++;
		length++;
	}
	if (i)
		i--;
	while (wh(s[i]) && length)
	{
		i--;
		length--;
	}
	*last_ok_index = i;
	return (length);
}
예제 #2
0
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b)
{
    int right = x + width;
    int bottom = y + height;
    if (x < 0)
        x = 0;
    if (y < 0)
        y = 0;
    if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
        right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH);
    if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT))
        bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT);

    // Draw the text
    IwGxSetScreenSpaceSlot(0);

    CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
    fadeMat->SetAlphaMode(CIwMaterial::NONE);
    fadeMat->SetShadeMode(CIwMaterial::SHADE_FLAT);
    IwGxSetMaterial(fadeMat);

    CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
    for (int i = 0; i < 4; i++)
        cols[i].Set(r, g, b);

    CIwSVec2 xy(x, y);
    CIwSVec2 wh(width, height);
    IwGxDrawRectScreenSpace(&xy, &wh, cols);
}
예제 #3
0
WTL::CSize FMPlayerDShow::GetVideoSize()
{
	bool fKeepAspectRatio = true;//AfxGetAppSettings().fKeepAspectRatio;
	bool fCompMonDeskARDiff = false; //AfxGetAppSettings().fCompMonDeskARDiff;

	WTL::CSize ret(0,0);

	WTL::CSize wh(0, 0), arxy(0, 0);

	{
		m_pBV->GetVideoSize(&wh.cx, &wh.cy);

		long arx = 0, ary = 0;
		CComQIPtr<IBasicVideo2> pBV2 = m_VideoWnd;
		if(pBV2 && SUCCEEDED(pBV2->GetPreferredAspectRatio(&arx, &ary)) && arx > 0 && ary > 0)
			arxy.SetSize(arx, ary);
	}

	WTL::CSize& ar = m_AspectRatio;
	if(ar.cx && ar.cy) arxy = ar;

	if(wh.cx <= 0 || wh.cy <= 0)
		return ret;

	// with the overlay mixer IBasicVideo2 won't tell the new AR when changed dynamically

	ret = (arxy.cx <= 0 || arxy.cy <= 0)
		? wh
		: WTL::CSize(MulDiv(wh.cy, arxy.cx, arxy.cy), wh.cy);

	return ret;
}
glm::vec3 BlinnMicrofacetBxDF::EvaluateHemisphereScatteredEnergy(const glm::vec3 &wo, int num_samples, const glm::vec2 *samples) const
{
    //TODO
    glm::vec3 color( 0.f );

    for( int i = 0; i < num_samples; ++i ){

        float cos_theta( powf( samples[ i ].x, 1.f / ( exponent + 1.f ) ) );
        float sin_theta( sqrtf( fmaxf( 0.f, 1.f - cos_theta * cos_theta ) ) );

        float phi( samples[ i ].y * TWO_PI );
        float cos_phi( cosf( phi ) );
        float sin_phi( sinf( phi ) );

        glm::vec3 wh( sin_theta * cos_phi, sin_theta * sin_phi, cos_theta );

        float woDwh( glm::dot( wo, wh ) );

        if( woDwh < 0.f ) wh = -wh;

        glm::vec3 wi( -wo + 2.f * woDwh * wh );

        color += EvaluateScatteredEnergy( wo, wi );
    }

    return color / ( float )num_samples;
}
예제 #5
0
AGSurface makeWaterTileOld()
{
    int w=TILE_WIDTH;
    VoxelView v(w,w*2,Pos3D(0,0,0),true);

    float a=12;

    SplineMapD wh((int)a,(int)a,5,1,6);

    for(int x=0; x<w; x++)
        for(int z=0; z<w; z++)
        {
            float mx=x-z+w/2;
            float mz=x+z-w/2;

            float h=wh.get(a*float(mx)/w,a*float(mz)/w)+6;

            for(int y=std::max(0,(int)(h)-3); y<h; y++)
            {
                float f=std::min(1.0f,h-y);
                v.set(Pos3D(x,y,z),Color(0,0,0xAA,f));
            }
        }
    return v.getSurface();
}
void CEmpEdit::OnBnClickedButton6()
{
	// TODO: Update
	CString SqlString,s1;
	CString var_name,var_id,var_sh,var_sa,var_dep,var_Eid;
	int flg=0,col_index=1;
	
	CEmpTable recset(&database);
	
	EID->GetWindowText(var_id);
	ENA->GetWindowText(var_name);
	EWO->GetWindowText(var_sh);
	ESA->GetWindowText(var_sa);
	EDE->GetWindowText(var_dep);
	

	CString coma(", ");
	//CString CB(");");
	CString sc(" ;");
	CString Quo("'");
	CString Ei("  [Employee ID] = ");
	CString De(" , [Deprtment] = ");
	CString Sh(" , [Shift] = ");
	CString Sa(" , [Salary] = ");
	CString Id(" [ID] = ");
	CString sp(" AND ");
	CString wh(" WHERE "); 
	CString Bo(" ( ");
	CString Bc(" ) ");	
		recset.Open(CRecordset::dynaset,_T("SELECT * FROM EmpTable"),CRecordset::readOnly);

		recset.SetAbsolutePosition(rec_index);
		//recset.GetFieldValue(col_index,var_id);
		recset.GetFieldValue(col_index-1,var_Eid);

		
		s1.Format("UPDATE EmpTable SET [Employee Name] = ");

		
		SqlString=s1+Quo+var_name+Quo+De+Quo+var_dep+Quo+Sh+Quo+var_sh+Quo+Sa+var_sa+wh+Id+var_Eid+sc;
		AfxMessageBox(SqlString);
			try
{
   database.ExecuteSQL(SqlString);
}
catch(CDBException* pe)
{
	flg=1;
   // The error code is in pe->m_nRetCode
   pe->ReportError();
   pe->Delete();
}
if (flg == 0)
{
MessageBox(_T("Record Successfully Updated To The Database"),_T("Successfull")); 
}


	}
예제 #7
0
파일: memory.c 프로젝트: TASVideos/BizHawk
void REGPARM(3) p32x_sh2_write16(u32 a, u32 d, SH2 *sh2)
{
  const void **sh2_wmap = sh2->write16_tab;
  sh2_write_handler *wh;

  wh = sh2_wmap[SH2MAP_ADDR2OFFS_W(a)];
  wh(a, d, sh2);
}
예제 #8
0
static float wh(Coordsys *cs, bool w) 
{
	switch (cs->type) {
	case CS_ROOT:
		return 1;
	case CS_BOX: {
		BoxCS *p = (BoxCS*)cs;
		return w? p->w: p->h;
	}
	case CS_TRANS:
		return wh(((TransCS*)cs)->parent, w);
	case CS_ORTHO:
		return wh(((OrthoCS*)cs)->parent, w);
	default:
		errx(1, "No width or height implemented for cs: %d\n", 
		     cs->type);
	}
}
int main()
{
    int t,i;
    scanf("%d",&t);
    char a[limits],b[limits];
    while(t--)
    {
              fflush(stdin);
              scanf("%s",a);
              fflush(stdin);
              scanf("%s",b);
              int as4=0,ae4=0,ae7=0,as7=0;
              int bs4=0,be4=0,be7=0,bs7=0;
              for(i=0;a[i]!='\0';i++)
              {
                                     if(a[i]<'4') as4++;
                                     else if(a[i]=='4') ae4++;
                                     else if(a[i]<'7') as7++;
                                     else if(a[i]=='7') ae7++;           
                                     
                                     if(b[i]<'4') bs4++;
                                     else if(b[i]=='4') be4++;
                                     else if(b[i]<'7') bs7++;
                                     else if(b[i]=='7') be7++;
              }

              wh(ae7,bs7,'7')
              wh(be7,as7,'7')
              wh(ae7,bs4,'7')
              wh(be7,as4,'7')
              
              wh(be7,ae4,'7')
              wh(ae7,be4,'7')
              
              wh(ae7,be7,'7')
                                       
              wh(ae4,bs4,'4')         
              wh(be4,as4,'4')
              wh(ae4,be4,'4')
              
              putchar_unlocked('\n');
    }
    return 0;
}
예제 #10
0
void AsyncGenerator::failCpp() {
  assert(isRunning());
  setState(State::Done);

  if (m_waitHandle) {
    // Resumed execution. Take wh out of `this` as failCpp() may free `this`.
    req::ptr<c_AsyncGeneratorWaitHandle> wh(std::move(m_waitHandle));
    wh->failCpp();
  }
}
예제 #11
0
c_StaticWaitHandle*
AsyncGenerator::fail(ObjectData* exception) {
  assert(isRunning());
  setState(State::Done);

  if (m_waitHandle) {
    // Resumed execution. Take wh out of `this` as fail() may free `this`.
    req::ptr<c_AsyncGeneratorWaitHandle> wh(std::move(m_waitHandle));
    wh->fail(exception);
    return nullptr;
  }
  return c_StaticWaitHandle::CreateFailed(exception);
}
float BlinnMicrofacetBxDF::PDF(const glm::vec3 &wo, const glm::vec3 &wi) const{

    glm::vec3 wh( glm::normalize( wo + wi ) );
    float cos_theta( fabsf( wh.z ) );
    float woDwh( glm::dot( wo, wh ) );

    if( woDwh <= 0.f ) return 0.f;

    float PDF( ( ( exponent + 1.f ) * powf( cos_theta, exponent ) )
               / ( TWO_PI * 4.f * woDwh ) );

    return PDF;
}
예제 #13
0
int main()
{
    hpx::parcel_write_handler_type wh(&write_handler);

    // test that handler is called for every parcel
    hpx::parcel_write_handler_type f1 = hpx::set_parcel_write_handler(wh);
    HPX_TEST(!hpx::util::is_empty_function(f1));

    std::vector<hpx::id_type> localities = hpx::find_remote_localities();

    {
        std::vector<hpx::future<void> > wait_for;
        for (hpx::id_type const& id: localities)
        {
            hpx::lcos::promise<void> p;
            auto f = p.get_future();

            hpx::apply<test_action>(id, p.get_id());

            wait_for.push_back(std::move(f));
        }

        hpx::wait_all(wait_for);
        HPX_TEST_EQ(write_handler_called, localities.size());
    }

    // test that handler is not called anymore
    write_handler_called.store(0);
    hpx::parcel_write_handler_type f2 = hpx::set_parcel_write_handler(f1);

    {
        std::vector<hpx::future<void> > wait_for;
        for (hpx::id_type const& id: localities)
        {
            hpx::lcos::promise<void> p;
            auto f = p.get_future();

            hpx::apply<test_action>(id, p.get_id());

            wait_for.push_back(std::move(f));
        }

        hpx::wait_all(wait_for);
        HPX_TEST_EQ(write_handler_called, std::size_t(0));
    }

    HPX_TEST(f2.target<hpx::parcel_write_handler_type>() ==
        wh.target<hpx::parcel_write_handler_type>());

    return hpx::util::report_errors();
}
예제 #14
0
float blinnPhong(Vec3f camPos, Vec3f source, Vec3f vertex, Vec3f * triangle, float s)
{
    Vec3f wi(source - vertex);
    Vec3f wo(camPos - vertex);
    Vec3f n = getNormalwithRayComes(triangle, -wo);
    wi.normalize();
    wo.normalize();
    n.normalize();

    Vec3f wh(wi + wo);
    wh.normalize();

    return pow(dot(n, wh),s);
}
예제 #15
0
c_StaticWaitHandle*
AsyncGenerator::ret() {
  assert(isRunning());
  setState(State::Done);

  auto nullTV = make_tv<KindOfNull>();

  if (m_waitHandle) {
    // Resumed execution. Take wh out of `this` as ret() may free `this`.
    req::ptr<c_AsyncGeneratorWaitHandle> wh(std::move(m_waitHandle));
    wh->ret(nullTV);
    return nullptr;
  }
  return c_StaticWaitHandle::CreateSucceeded(nullTV);
}
예제 #16
0
VoxelImage *makeWaterTile()
{
    int w=TILE_WIDTH;
    FastVoxelView v(w,w*2,Pos3D(0,0,0),true);


    /** add water **/

    srand(0);
    {
        float a=18;

        SplineMapD wh((int)a,(int)a,3,1,3,true);

        for(int x=0; x<w; x++)
            for(int z=0; z<w; z++)
            {
                float mx=x-z+w/2;
                float mz=x+z-w/2;

                mx/=w;
                mz/=w;
                while(mx>1)
                    mx-=1;
                while(mx<0)
                    mx+=1;
                while(mz>1)
                    mz-=1;
                while(mz<0)
                    mz+=1;

                float h=wh.get(a*float(mx),a*float(mz))+6;

                for(int y=0; y<h; y++)
                {
                    float f=std::min(1.0f,h-y);
                    v.set(Pos3D(x,y,z),Color(0,0,0xAA,f));
                }
            }
    }


    /** till here */

    AGSurface s= v.getSurface();

    return new VoxelImage(s,Pos3D(0,0,0));
}
glm::vec3 BlinnMicrofacetBxDF::EvaluateScatteredEnergy(const glm::vec3 &wo, const glm::vec3 &wi) const
{
    //TODO
    float theta_wi( fabsf( wi.z ) );
    float theta_wo( fabsf( wo.z ) );

    if( theta_wi == 0.f || theta_wo == 0.f ) return glm::vec3( 0.f );

    glm::vec3 wh( glm::normalize( wo + wi ) );

    return reflection_color
            * F( wi, wh )
            * D( wh )
            * G( wo, wi, wh )
            * .25f / theta_wi / theta_wo;
}
예제 #18
0
파일: memory.c 프로젝트: TASVideos/BizHawk
void REGPARM(3) p32x_sh2_write32(u32 a, u32 d, SH2 *sh2)
{
  const void **sh2_wmap = sh2->write16_tab;
  sh2_write_handler *wh;
  u32 offs;

  offs = SH2MAP_ADDR2OFFS_W(a);

  if (offs == SH2MAP_ADDR2OFFS_W(0xffffc000)) {
    sh2_peripheral_write32(a, d, sh2);
    return;
  }

  wh = sh2_wmap[offs];
  wh(a, d >> 16, sh2);
  wh(a + 2, d, sh2);
}
예제 #19
0
파일: player.c 프로젝트: FOSSRIT/baresip
static void play_handler(void *userData, AudioQueueRef outQ,
			 AudioQueueBufferRef outQB)
{
	struct auplay_st *st = userData;
	auplay_write_h *wh;
	void *arg;

	pthread_mutex_lock(&st->mutex);
	wh  = st->wh;
	arg = st->arg;
	pthread_mutex_unlock(&st->mutex);

	if (!wh)
		return;

	wh(outQB->mAudioData, outQB->mAudioDataByteSize/2, arg);

	AudioQueueEnqueueBuffer(outQ, outQB, 0, NULL);
}
예제 #20
0
  explicit NextQueue(ObserverManager& manager)
      : manager_(manager), queue_(kNextQueueSize) {
    thread_ = std::thread([&]() {
      Core::WeakPtr queueCoreWeak;

      while (true) {
        queue_.blockingRead(queueCoreWeak);
        if (stop_) {
          return;
        }

        std::vector<Core::Ptr> cores;
        {
          auto queueCore = queueCoreWeak.lock();
          if (!queueCore) {
            continue;
          }
          cores.emplace_back(std::move(queueCore));
        }

        {
          SharedMutexReadPriority::WriteHolder wh(manager_.versionMutex_);

          // We can't pick more tasks from the queue after we bumped the
          // version, so we have to do this while holding the lock.
          while (cores.size() < kNextQueueSize && queue_.read(queueCoreWeak)) {
            if (stop_) {
              return;
            }
            if (auto queueCore = queueCoreWeak.lock()) {
              cores.emplace_back(std::move(queueCore));
            }
          }

          ++manager_.version_;
        }

        for (auto& core : cores) {
          manager_.scheduleRefresh(std::move(core), manager_.version_, true);
        }
      }
    });
  }
glm::vec3 BlinnMicrofacetBxDF::SampleAndEvaluateScatteredEnergy(const glm::vec3 &wo, glm::vec3 &wi_ret, float rand1, float rand2, float &pdf_ret) const{

    float cos_theta( powf( rand1, 1.f / ( exponent + 1.f ) ) );
    float sin_theta( sqrtf( fmaxf( 0.f, 1.f - cos_theta * cos_theta ) ) );

    float phi( rand2 * TWO_PI );
    float cos_phi( cosf( phi ) );
    float sin_phi( sinf( phi ) );

    glm::vec3 wh( sin_theta * cos_phi, sin_theta * sin_phi, cos_theta );

    float woDwh( glm::dot( wo, wh ) );

    if( woDwh < 0.f ) wh = -wh;

    wi_ret = -wo + 2.f * woDwh * wh;
    pdf_ret = PDF( wo, wi_ret );

    return EvaluateScatteredEnergy( wo, wi_ret );
}
예제 #22
0
c_StaticWaitHandle*
AsyncGenerator::yield(Offset resumeOffset,
                      const Cell* key, const Cell value) {
  assert(isRunning());
  resumable()->setResumeAddr(nullptr, resumeOffset);
  setState(State::Started);

  auto keyValueTuple = make_packed_array(
    key ? Variant(tvAsCVarRef(key), Variant::CellCopy()) : init_null_variant,
    Variant(tvAsCVarRef(&value), Variant::CellCopy()));
  auto keyValueTupleTV = make_tv<KindOfArray>(keyValueTuple.detach());

  if (m_waitHandle) {
    // Resumed execution.
    req::ptr<c_AsyncGeneratorWaitHandle> wh(std::move(m_waitHandle));
    wh->ret(*tvAssertCell(&keyValueTupleTV));
    return nullptr;
  }
  // Eager execution.
  return c_StaticWaitHandle::CreateSucceeded(keyValueTupleTV);
}
예제 #23
0
void CursorRender()
{
    if (!s3ePointerGetInt(S3E_POINTER_AVAILABLE))
        return;

    if (!g_CursorMaterial)
    {
        g_CursorMaterial = new CIwMaterial();
        g_CursorMaterial->SetColAmbient(0, 0, 255, 255);
    }

    IwGxSetMaterial(g_CursorMaterial);
    int pointerx = s3ePointerGetX();
    int pointery = s3ePointerGetY();

    int cursor_size = 10;
    CIwSVec2 wh(cursor_size*2, 1);
    CIwSVec2 wh2(1, cursor_size*2);
    CIwSVec2 pos = CIwSVec2((int16)pointerx-cursor_size, (int16)pointery);
    CIwSVec2 pos2 = CIwSVec2((int16)pointerx, (int16)pointery-cursor_size);
    IwGxDrawRectScreenSpace(&pos, &wh);
    IwGxDrawRectScreenSpace(&pos2, &wh2);
}
예제 #24
0
void ReadAnimalsData(lhVec& landHerbs, whVec& waterHerbs, lcVec& landCarns, wcVec& waterCarns, waterVec& wv){
     ifstream myfile("EcosystemFile.txt");
     int waterLines = ReadWaterAreas();
     int grassLines = ReadGrassAreas();
     int algaeLines = ReadAlgaeAreas();
     int animalsLines = ReadAnimalsNumber();
     string line;
     vector <int> values(7);
     char gender;
     if (myfile.is_open()){
        for (int i = 0; i < waterLines + grassLines + algaeLines + animalsLines + 6; i++){
            getline(myfile, line);
            if (i > waterLines + grassLines + algaeLines + 5){
                int found = line.find('|');
                string typeFeeding(line.begin()+ found +1, line.begin()+ found + 1 + 9);
                line.erase(found, 10);
                gender = line[found + 1];
                line.erase(found, 2);
                for (int k = 0; k < line.size(); k++){
                    if (line[k] == ',' || line[k]== '|') line[k] = ' ';
                }
                istringstream iss(line);
                for (int j = 0; j < 7; j++){
                    int val;
                    iss >> val;
                    values[j] = val;
                }
                if (typeFeeding == "herbivore"){
                    bool inWater = false;
                    shared_ptr<Herbivore> h (new Herbivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                    for(int m = 0; m < wv.size(); m++){
                        if (wv[m]->HasThisCoordinate(*h)){
                            inWater = true;
                            break;
                        }
                    }
                    if (inWater){
                        shared_ptr<WaterHerbivore> wh (new WaterHerbivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                        waterHerbs.push_back(wh);
                    } else {
                        shared_ptr<LandHerbivore> lh (new LandHerbivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                        landHerbs.push_back(lh);
                    }
                }
                else if(typeFeeding == "carnivore"){
                    bool inWater = false;
                    shared_ptr<Carnivore> c (new Carnivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                    for(int m = 0; m < wv.size(); m++){
                        if (wv[m]->HasThisCoordinate(*c)){
                            inWater = true;
                            break;
                        }
                    }
                    if (inWater){
                         shared_ptr<WaterCarnivore> wc (new WaterCarnivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                         waterCarns.push_back(wc);
                    }else{
                        shared_ptr<LandCarnivore> lc (new LandCarnivore(values[0], values[1], gender, values[2], values[3], values[4], values[5], values[6]));
                        landCarns.push_back(lc);
                    }
                }
            }
        }
    }
예제 #25
0
int main(int argc, char** argv)
{

	std::mt19937 generator(SEED);

	std::vector<float> fl_p, sm_p, st_p, fe_p, br_p, co_p, wh_p;
	fl_p.push_back(0.3);

	sm_p.push_back(0.24);

	st_p.push_back(0.5);
	st_p.push_back(0.68);

	fe_p.push_back(0.32);
	fe_p.push_back(0.85);

	br_p.push_back(0.25);
	br_p.push_back(0.75);
	br_p.push_back(0.6);
	br_p.push_back(0.9);

	co_p.push_back(0.5);
	co_p.push_back(0.95);

	wh_p.push_back(0.3);
	wh_p.push_back(0.86);

	Bayes::Node fl(fl_p, generator);
	Bayes::Node sm(sm_p, generator);
	Bayes::Node st(st_p, generator);
	Bayes::Node fe(fe_p, generator);
	Bayes::Node br(br_p, generator);
	Bayes::Node co(co_p, generator);
	Bayes::Node wh(wh_p, generator);

	std::vector<std::pair<unsigned int, unsigned int>> dataset;


	for (unsigned int t = 1; t <= TESTS; ++t)
	{
			unsigned int frequency = 0;
			unsigned int misses = 0;
			for (unsigned int s = 0; s < t * SAMPLE_FACTOR; ++s)
			{
				uint8_t result = 0;
				result |= fl.sample(0) ? FL : 0;
				result |= sm.sample(0) ? SM : 0;
				result |= st.sample((result & FL) ? 1 : 0) ? ST : 0;
				result |= fe.sample((result & FL) ? 1 : 0) ? FE : 0;
				result |= br.sample((result & FL ? 2 : 0)|(result & SM ? 1 : 0)) ? BR : 0;
				result |= co.sample((result & BR ? 1 : 0)) ? CO : 0;
				result |= wh.sample((result & BR ? 1 : 0)) ? WH : 0;
				if ((result & (CO | WH)) != CO)
				{
					misses++;
					// Try again
					continue;
				}
				if (result & FL) frequency ++;
				//if (result == (FL | ST | FE | CO) ) frequency ++;
			}
			std::cerr << "Misses: " << misses << '\n';
			dataset.push_back(std::make_pair(t * SAMPLE_FACTOR, frequency));
	}

	std::cout << "Samples, Frequency, Probability\n";
	for (auto p: dataset)
	{
		std::cout << p.first << ", " << p.second << ", "
			<< static_cast<float>(p.second) / p.first << '\n';
	}

	return 0;
}
예제 #26
0
VoxelImage *makeTerrainTile(const SplineMapD &m,const SplineMapD &gm,int px,int py)
//ComplexVoxelImage *makeTerrainTile(const SplineMap<float> &m,const SplineMap<float> &gm,int px,int py)
{
    gDrawingTerrain=true;
    Uint32 t1=SDL_GetTicks();

    int w=TILE_WIDTH;
    FastVoxelView v(w,w*4,Pos3D(0,0,0),true);

    if(true)
    {
        for(int x=0; x<w; x++)
            for(int z=0; z<w; z++)
                //    for(int z=w/2-4;z<w/2;z++)
            {
                float mx=float(x*POINTS_PER_TILE)/w+px;
                float mz=float(z*POINTS_PER_TILE)/w+py;

                //  cdebug(mx<<" "<<mz);
                float h=m.get(mx,mz);
                for(int y=std::max(0,(int)(h-3)); y<h; y++)
                {
                    if(y>WATER_HEIGHT)
                    {
                        float a=std::min(1.0f,h-y);
                        int n=rand()%50;

                        v.set(Pos3D(x,y,z),Color(0xAA-n,0xAA-n,0,a));
                    }
                }

                // grass above


                int mgh=(int)gm.get(mx,mz);
                if(mgh>0)
                {
                    float gh=rand()%int(mgh);
                    if(gh>0)
                        for(int y=0; y<gh; y++)
                        {
                            float a=1.0f-(y/gh);
                            int mh=(int)(y+h);
                            //    cdebug(a);
                            if(mh>WATER_HEIGHT)
                                v.set(Pos3D(x,mh,z),Color(0,0xAA,0,a));
                        }
                }

                /*
                if(rand()%60<2)
                  {
                    int w=10;
                    int w2=w/2;
                    float x1=(rand()%w)-w2;
                    float z1=(rand()%w)-w2;
                    float x2=(rand()%w)-w2;
                    float z2=(rand()%w)-w2;

                    float steps=15;

                    // paint a longer leaf
                    for(int i=0;i<steps;i++)
                      {
                  int ax=(int)bezier2(i/steps,float(x),x1+x,x2+x);
                  int az=(int)bezier2(i/steps,float(z),z1+z,z2+z);
                  int ay=(int)bezier2(i/steps,0.0f,steps/4,steps/2);

                  v.set(Pos3D(ax,int(ay+h),az),Color(0,0xAA,0,i/steps));
                      }
                  }
                */
            }
        /*
            for(int x=0;x<8;x++)
        for(int y=0;y<8;y++)
         for(int z=0;z<8;z++)
           {
             int mx=x-4;
             int my=y-4;
             int mz=z-4;
             if(sqrt(mx*mx+my*my+mz*mz)<4)
        v.set(Pos3D(x+10,y+40,z+20),Color(0xAA,0,0));
           }

        */
    }


    /** add water **/

    srand(0);
    if(false) // skip water
    {
        float a=18;

        SplineMapD wh((int)a,(int)a,3,1,3,true);

        for(int x=0; x<w; x++)
            for(int z=0; z<w; z++)
            {
                float mx=x-z+w/2;
                float mz=x+z-w/2;

                mx/=w;
                mz/=w;
                while(mx>1)
                    mx-=1;
                while(mx<0)
                    mx+=1;
                while(mz>1)
                    mz-=1;
                while(mz<0)
                    mz+=1;

                float h=wh.get(a*float(mx),a*float(mz))+6;

                for(int y=0; y<h; y++)
                {
                    float f=std::min(1.0f,h-y);
                    v.set(Pos3D(x,y,z),Color(0,0,0xAA,f));
                }
            }
    }


    /** till here */

    Uint32 t2=SDL_GetTicks();

    cdebug("TIME:"<<t2-t1);

    AGSurface s= v.getSurface();

    t1=SDL_GetTicks();

    cdebug("TIME:"<<t1-t2);

    //  SDL_SaveBMP(s.surface(),"hupe.bmp");


    //return new ComplexVoxelImage(Pos3D(0,0,0),s,v.getDepthMap(),v.getShadowMap());

    gDrawingTerrain=false;
    return new VoxelImage(s,Pos3D(0,0,0));
}
예제 #27
0
float vob_coords_w(Coordsys *cs) {
	float ret = wh(cs, TRUE);
	//printf("ret %f\n",ret);
	return ret;
}
예제 #28
0
float vob_coords_h(Coordsys *cs) {
	float ret = wh(cs, FALSE);
	//printf("ret %f\n", ret);
	return ret;
}
예제 #29
0
SSMProcess* GIOutputModeler::compute()
{
    const int g = - Lb(m_ptrData->getDistribution(1,1));
    const int h = Ub(m_ptrData->getDistribution(1,1));
    const ivector u = m_ptrData->getDistribution(1,1);

    // perform Wiener-Hopf factorization
    ComputationParameters whParams;
    whParams.setInt(SMPWienerHopf::PARAM_NUMITERATIONS, 200);
    whParams.setReal(SMPWienerHopf::PARAM_EPSILON, real(1e-14));
    SMPWienerHopf wh(m_ptrData, whParams);
    const ISMPWHFactors* whFactors = wh.compute();

    ivector l = whFactors->getIdleDistributions().getVectorAt(1,1);
    ivector v = whFactors->getPhaseDistributions().getVectorAt(1,1);

    // create SMP model as described by Haßlinger
    // transition probabilities
    imatrix trans = IMatrixUtils::zeros(1,2,1,2);

    // a_00
    for(int i = 1; i<=g; ++i)
        trans[1][1] += u[-i];

    // E(N) = (I-V(1))^-1
    interval v1(0.0);
    for(int i = Lb(v); i<=Ub(v); ++i)
        v1 += v[i];
    interval e_n = 1.0 / (1.0 - v1);

    // a_11
    trans[2][2] = 1.0 - ((1.0 - trans[1][1])/(e_n - 1.0));

    // a_01, a_10
    trans[1][2] = 1.0 - trans[1][1];
    trans[2][1] = 1.0 - trans[2][2];

    // END of transition probabilities.

    // I^(N=1) (z)
    ivector i_n_eq_1(1,g);
    for(int i = 1; i<=g; ++i)
    {
        i_n_eq_1[i] = u[-i] / trans[1][1];
    }

    // I^(N>1) (z)
    ivector i_n_gr_1(1,g);
    for(int i = 1; i<=g; ++i)
    {
        i_n_gr_1[i] = (l[i] - trans[1][1]*i_n_eq_1[i])/(1.0 - trans[1][1]);
    }

    // state-specific distributions
    ivector s = m_ptrData->getServiceProcess()->getDistribution(1,1);
    ivector a00 = IMatrixUtils::conv(i_n_eq_1, s);
    ivector a01 = s;
    ivector a10 = s;
    ivector a11 = IMatrixUtils::conv(i_n_gr_1, s);

    // determine bounds
    int lowerBound = Lb(s);
    int upperBound = Ub(s) + std::max<int>(Ub(i_n_eq_1), Ub(i_n_gr_1));

    IMatrixPolynomial distributions(lowerBound, upperBound,1,2,1,2);
    imatrix emptyMatrix(1,2,1,2);
    emptyMatrix[1][1] = interval(0.0);
    emptyMatrix[1][2] = interval(0.0);
    emptyMatrix[2][1] = interval(0.0);
    emptyMatrix[2][2] = interval(0.0);
    for(int i = lowerBound; i<=upperBound; ++i)
        distributions[i] = emptyMatrix;
    distributions.setVectorAt(1,1,a00);
    distributions.setVectorAt(1,2,a01);
    distributions.setVectorAt(2,1,a10);
    distributions.setVectorAt(2,2,a11);


    // create SMP model
    SMProcess outputModel(trans, distributions);

    // convert to SSMP model
    SSMProcess* ssmpOutputModel = new SSMProcess(outputModel);

    // return
    return ssmpOutputModel;
}
예제 #30
0
void ShapePlug::parseGroupProperties(QDomNode &DOC, double &minXCoor, double &minYCoor, double &maxXCoor, double &maxYCoor, bool &firstCheck)
{
    QString FillCol = "White";
    QString StrokeCol = "Black";
    while(!DOC.isNull())
    {
        double x1, y1, x2, y2;
        FPointArray PoLine;
        PoLine.resize(0);
        QDomElement pg = DOC.toElement();
        QString STag = pg.tagName();
        if (STag == "svg:line")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion;
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x2, y2);
            PoLine.addPoint(x2, y2);
        }
        else if (STag == "svg:rect")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion;
            static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
                                    1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
                                    0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0
                                   };
            for (int a = 0; a < 29; a += 4)
            {
                double xa = x2 * rect[a];
                double ya = y2 * rect[a+1];
                double xb = x2 * rect[a+2];
                double yb = y2 * rect[a+3];
                PoLine.addPoint(x1+xa, y1+ya);
                PoLine.addPoint(x1+xb, y1+yb);
            }
        }
        else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
        {
            bool bFirst = true;
            double x = 0.0;
            double y = 0.0;
            QString points = pg.attribute( "points" ).simplified().replace(',', " ");
            QStringList pointList = points.split(' ', QString::SkipEmptyParts);
            FirstM = true;
            for( QStringList::Iterator it1 = pointList.begin(); it1 != pointList.end(); it1++ )
            {
                x = ScCLocale::toDoubleC(*(it1++));
                y = ScCLocale::toDoubleC(*it1);
                if( bFirst )
                {
                    svgMoveTo(x * Conversion, y * Conversion);
                    bFirst = false;
                    WasM = true;
                }
                else
                {
                    svgLineTo(&PoLine, x * Conversion, y * Conversion);
                }
            }
            if (STag == "svg:polygon")
                svgClosePath(&PoLine);
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
        }
        else if (STag == "svg:circle")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
            y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
            x1 *= 2.0;
            y1 *= 2.0;
            static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
                                    0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
                                    0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
                                    0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765
                                   };
            for (int a = 0; a < 29; a += 4)
            {
                double xa = x1 * rect[a];
                double ya = y1 * rect[a+1];
                double xb = x1 * rect[a+2];
                double yb = y1 * rect[a+3];
                PoLine.addPoint(x2+xa, y2+ya);
                PoLine.addPoint(x2+xb, y2+yb);
            }
        }
        else if (STag == "svg:ellipse")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("rx")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("ry")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
            y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
            x1 *= 2.0;
            y1 *= 2.0;
            static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0,
                                    0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235,
                                    0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0,
                                    0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765
                                   };
            for (int a = 0; a < 29; a += 4)
            {
                double xa = x1 * rect[a];
                double ya = y1 * rect[a+1];
                double xb = x1 * rect[a+2];
                double yb = y1 * rect[a+3];
                PoLine.addPoint(x2+xa, y2+ya);
                PoLine.addPoint(x2+xb, y2+yb);
            }
        }
        else if (STag == "svg:path")
        {
            parseSVG( pg.attribute( "d" ), &PoLine );
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
        }
        else if (STag == "svg:g")
        {
            QDomNode child = DOC.firstChild();
            parseGroupProperties(child, minXCoor, minYCoor, maxXCoor, maxYCoor, firstCheck);
        }
        if (PoLine.size() < 4)
        {
            DOC = DOC.nextSibling();
            continue;
        }
        FPoint tp2(getMinClipF(&PoLine));
        PoLine.translate(-tp2.x(), -tp2.y());
        FPoint wh(getMaxClipF(&PoLine));
        if (firstCheck)
        {
            minXCoor = tp2.x();
            minYCoor = tp2.y();
            maxXCoor = tp2.x() + wh.x();
            maxYCoor = tp2.y() + wh.y();
            firstCheck = false;
        }
        else
        {
            minXCoor = qMin(minXCoor, tp2.x());
            minYCoor = qMin(minYCoor, tp2.y());
            maxXCoor = qMax(maxXCoor, tp2.x() + wh.x());
            maxYCoor = qMax(maxYCoor, tp2.y() + wh.y());
        }
        DOC = DOC.nextSibling();
    }
}