Exemple #1
0
void sToolBorder::OnCalcSize()
{
    ReqSizeX = 0;
    ReqSizeY = 0;
    for(auto w : Childs)
        ReqSizeY = sMax(ReqSizeY,w->DecoratedSizeY);
    ReqSizeY += Style()->ToolBorderSize;
}
Exemple #2
0
/*
** setPosition
** Sets the position of the multiScope window.
*/ 
void ofxMultiScope::setPosition(ofPoint min, ofPoint max) {
	_min = min;
	_max = max;
	for (int i=0; i<_numScopes; i++) {
		ofPoint sMin(min.x, min.y + i*(max.y - min.y)/_numScopes);
		ofPoint sMax(max.x, min.y + (i+1)*(max.y - min.y)/_numScopes);
		scopes.at(i).setPosition(sMin, sMax);
	}
}
Exemple #3
0
sF32 Wz4PDFMerge::GetDistance(const sVector31 &p)
{
  sF32 d1=Obj1->GetDistance(p);
  sF32 d2=Obj2->GetDistance(p);
  sF32 d;
  switch(Type)
  {
    case 5 :
      if (d1<0)
        d1=0;
      if (d2<0)
        d2=0;
      d=d1*(1.0f-Factor)+d2*Factor;
    break;
    case 4 :              
      if (d1<d2)
      {
        d=d1*(1.0f-Factor)+d2*Factor;
      }
      else
      {
        d=d2*(1.0f-Factor)+d1*Factor;
      }
    break;

    case 3 :
        d=d1*(1.0f-Factor)+d2*Factor;
    break;

    case 2 :
      d1=-d1;
      d = sMax(d1,d2);
    break;

    case 1 :
      d = sMax(d1,d2);
    break;
    default :
      d = sMin(d1,d2);
    break;
  }
  return d;
}
Exemple #4
0
sF32 RNFR067_IsoSplash::func(const sVector31 &pp,sInt px,sInt py,sInt pz)
{
  sVector31 p;
  if(RotEnable)
    p = pp*RubberMat[py];
  else
    p = pp;

  sF32 f = 0;

  if(SphereEnable)
    f += Para.SphereAmp/sFSqrt(p.x*p.x*SphereAmp.x + p.y*p.y*SphereAmp.y + p.z*p.z*SphereAmp.z);

  if(CubeEnable)
    f += Para.CubeAmp/sMax(sMax(sFAbs(p.x*CubeAmp.x),sFAbs(p.y*CubeAmp.y)),sFAbs(p.z*CubeAmp.z));

  if(NoiseEnable)
  {
    f += NoiseXY[py*Size+px];
    f += NoiseYZ[pz*Size+py];
    f += NoiseZX[px*Size+pz];
  }

  if(PolarEnable)
  {
    sF32 a = 0;
    if(Para.PolarY!=0)
    {
      sF32 rr = sSqrt(p.x*p.x+p.z*p.z);
      sF32 aa = sATan2(p.y,rr);
      a = sFCos(aa*Para.PolarY);
    }
    sF32 b = PolarPhi[px*Size+pz];//sFSin(sATan2(p.x,p.z)*Para.PolarXZ*0.5f);
    sF32 d = sFSqrt(p.x*p.x + p.y*p.y + p.z*p.z)-Para.PolarCenter;

    f += Para.PolarAmp/sMax(0.0f,sFSqrt(a*a + b*b + d*d*Para.PolarCenterAmount));
  }

  return f-Para.IsoValue;
}
Exemple #5
0
/*
** ofxMultiScope 
*/
ofxMultiScope::ofxMultiScope(int numScopes, ofPoint min, ofPoint max, ofTrueTypeFont legendFont, 
	int legendWidth, ofColor outlineColor, ofColor zeroLineColor, ofColor backgroundColor) {
		_min = min;
		_max = max;
		_numScopes = numScopes;
		scopes.resize(_numScopes);
		for (int i=0; i<_numScopes; i++) {
			ofPoint sMin(_min.x, _min.y + i*(_max.y - _min.y)/_numScopes);
			ofPoint sMax(_max.x, _min.y + (i+1)*(_max.y - _min.y)/_numScopes);
			scopes.at(i) = ofxOscilloscope(sMin, sMax, legendFont, legendWidth, 
				outlineColor, zeroLineColor);
		}
}
Exemple #6
0
/*
** ofxMultiScope 
*/
ofxMultiScope::ofxMultiScope(int numScopes, ofRectangle scopeArea, ofTrueTypeFont legendFont, 
	int legendWidth, ofColor outlineColor, ofColor zeroLineColor, ofColor backgroundColor) {
		_min = scopeArea.getTopLeft();
		_max = scopeArea.getBottomRight();
		_numScopes = numScopes;
		scopes.resize(_numScopes);
		for (int i=0; i<_numScopes; i++) {
			ofPoint sMin(_min.x, _min.y + i*(_max.y - _min.y)/_numScopes);
			ofPoint sMax(_max.x, _min.y + (i+1)*(_max.y - _min.y)/_numScopes);
			scopes.at(i) = ofxOscilloscope(sMin, sMax, legendFont, legendWidth, 
				outlineColor, zeroLineColor);
		}
}
Exemple #7
0
void sTextControl::Realloc(sInt size)
{
  sChar *s;
  if(size>TextAlloc)
  {
    size = sMax(size*3/2,TextAlloc*2);
    s = new sChar[size];
    sCopyString(s,Text,size);
    delete[] Text;
    Text = s;
    TextAlloc = size;
    Post(ReallocCmd);
  }
}
Exemple #8
0
sF32 Wz4PDFCube::GetDistance(const sVector31 &p)
{

  sF32 t=sAbs(p.x);  
  t = sMax(t,sAbs(p.y));
  t = sMax(t,sAbs(p.z));
  t -= 0.5f;

  if ((p.x>0.5f || p.x<-0.5f) &&
      (p.y>0.5f || p.y<-0.5f) &&
      (p.z>0.5f || p.z<-0.5f))
  {
    sF32 x=p.x>0.0f ? 0.5f:-0.5f;
    sF32 y=p.y>0.0f ? 0.5f:-0.5f;
    sF32 z=p.z>0.0f ? 0.5f:-0.5f;
    x-=p.x;
    y-=p.y;
    z-=p.z;
    t=sSqrt(x*x+y*y+z*z);
  }
 
  return t;
}
Exemple #9
0
void sChoiceControl::OnCalcSize()
{
  ChoiceInfo *ci;
  ReqSizeY = sGui->PropFont->GetHeight();
  ReqSizeX = 0;
  sFORALL(Choices,ci)
    ReqSizeX = sMax(ReqSizeX,sGui->PropFont->GetWidth(ci->Label,ci->Length));
  ReqSizeX += sGui->PropFont->GetWidth(L"  ");

  ReqSizeX += 4;
  ReqSizeY += 4;

  if(Width!=0)
    ReqSizeX = Width;
}
Exemple #10
0
void SoloPong::OnTick()
{
  sF32 dist;
  BallX += SpeedX * speed;
  BallY += SpeedY * speed;

  dist = (PaddleA-BallY)/PaddleSize;
  if(BallX<=-0.86f && SpeedX<0 && dist>=-1 && dist<1)
  {
    SpeedX =  sFAbs(SpeedX)+Speedup;
    SpeedY -= dist*1.0f;
    Score++;
  }

  dist = (PaddleB-BallY)/PaddleSize;
  if(BallX>=0.86f && SpeedX>0 && dist>=-1 && dist<1)
  {
    SpeedX = -sFAbs(SpeedX)-Speedup;
    SpeedY -= dist*1.0f;
    Score++;
  }

  sBool die = 0;

  if(BallY<-1) { SpeedY =  sFAbs(SpeedY); }
  if(BallY> 1) { SpeedY = -sFAbs(SpeedY); }
  if(BallX<-1) { SpeedX =  sFAbs(SpeedX); die = 1; }
  if(BallX> 1) { SpeedX = -sFAbs(SpeedX); die = 1; }

  if(die)
  {
    DeathTimer = 200;
    Lives--;
    if(Lives==0)
    {
      SpeedX = 0;
      SpeedY = 0;
      BallX = 0;
      BallY = 2;
      SpeedX -= sSign(SpeedX)*0.3f;
      DeathTimer = 2000;
    }
  }
  if(Lives==0 && DeathTimer == 0)
    Reset();

  DeathTimer = sMax(DeathTimer-10,0);
}
Exemple #11
0
void sTextControl::DelSel()
{
  sInt s0,s1,len;
  if(SelMode)
  {
    s0 = sMin(SelPos,Cursor);
    s1 = sMax(SelPos,Cursor);
    len = s1-s0;
    if(len>0)
    {
      Engine(s0,len,0);
      Cursor = s0;
      SelMode = 0;
    }
  }
}
Exemple #12
0
  void Grow(sInt max)
  {
    if(max>Alloc)
    {
      sInt newalloc = sMax(max,Alloc*2);
      Type *newdata = new Type[newalloc];

      for(sInt i=0;i<Used;i++)
        newdata[i] = Data[i];
      delete[] Data;
      Data = newdata;
      Alloc = newalloc;
    }
    if(max>Used)
    {
      for(sInt i=Used;i<max;i++)
        Data[i] = Default;
      Used = max;
    }
  }
Exemple #13
0
static sBool sRectsIntersect(const sRect &a,const sRect &b)
{
  return sMax(a.x0,b.x0) < sMin(a.x1,b.x1) && sMax(a.y0,b.y0) < sMin(a.y1,b.y1);
}
Exemple #14
0
void sChoiceControl::InitChoices(const sChar *&s,sInt *val)
{
  sInt id = 0;
  ChoiceInfo *ci;
  sInt min=0;
  sInt max=0;
  sInt len;
  sBool fullmask = 0;
  
  Choices.Clear();
  ValueMask = 0;
  ValueShift = 0;
  if(*s=='#')
  {
    s++;
    fullmask = 1;
  }
  if(*s=='*')
  {
    s++;
    sScanInt(s,ValueShift);
  }
  for(;;)
  {
    while(*s=='|')
    {
      s++;
      id++;
    }
    if(*s==':' || *s==0)
      break;

    if(sIsDigit(*s) || (*s=='-' && sIsDigit(s[1])) || (*s=='+' && sIsDigit(s[1])))
      sScanInt(s,id);
    if(*s==' ')
      s++;

    len = 0;
    while(s[len]!='|' && s[len]!=':' && s[len]!=0) len++;
    ci = Choices.AddMany(1);
    ci->Label = s;
    ci->Length = len;
    ci->Value = id;
    min = sMin(min,id);
    max = sMax(max,id);
    s+=len;
  }

  ValueMask = 1;
  while(ValueMask<max)
    ValueMask = ValueMask*2+1;
  if (min<0)
    ValueMask = ~0;
  ValueMask <<= ValueShift;
  if(fullmask)
    ValueMask = ~0;

  if(val)
  {
    Values.Clear();
    AddMultiChoice(val);
    ClearNotify();
    AddNotify(val,sizeof(sInt));
    Style = Choices.GetCount()==2 ? sCBS_CYCLE : sCBS_DROPDOWN;
  }
  else
  {
    Style |= sCBS_DROPDOWN;
  }
}
Exemple #15
0
void sScrollBorder::OnPaint(int layer)
{
    sRect r;

    uint lo = Style()->Colors[sGC_Low];
    uint hi = Style()->Colors[sGC_High];
    //  uint ba = Style()->Colors[sGC_Back];
    uint bu = Style()->Colors[sGC_Button];
    int f = Style()->ScrollBorderFrameSize;
    sWindow *root = BorderParent;
    BarX.Set();
    BarY.Set();

    if(EnableX)
    {
        Painter()->SetLayer(layer);
        r = RectX;
        Painter()->Frame(hi,lo,r,f);
        r.Extend(-f);
        Style()->Rect(layer,this->FocusParent,sSK_Back,r);
        //    Painter()->Rect(ba,r);

        if(root->Inner.SizeX()<root->ReqSizeX && root->Inner.SizeX()>0)
        {
            int s = r.SizeX();
            int h = sMax(root->Inner.SizeX()*s/root->ReqSizeX, sMin(Style()->ScrollBorderSize,s/2));
            r.x0 = r.x0 + root->ScrollX * (s-h) / (root->ReqSizeX-root->Inner.SizeX());
            r.x1 = r.x0 + h;
            BarX = r;

            Painter()->SetLayer(layer+1);
            Painter()->Frame(hi,lo,r,f);
            r.Extend(-f);
            Painter()->Rect(bu,r);
        }
    }
    if(EnableY)
    {
        Painter()->SetLayer(layer);
        r = RectY;
        Painter()->Frame(hi,lo,r,f);
        r.Extend(-f);
        Style()->Rect(layer,this->FocusParent,sSK_Back,r);
        //    Painter()->Rect(ba,r);

        if(root->Inner.SizeY()<root->ReqSizeY && root->Inner.SizeY()>0)
        {
            int s = r.SizeY();
            int h = sMax(root->Inner.SizeY()*s/root->ReqSizeY, sMin(Style()->ScrollBorderSize,s/2));
            r.y0 = r.y0 + root->ScrollY * (s-h) / (root->ReqSizeY-root->Inner.SizeY());
            r.y1 = r.y0 + h;
            BarY = r;

            Painter()->SetLayer(layer+1);
            Painter()->Frame(hi,lo,r,f);
            r.Extend(-f);
            Painter()->Rect(bu,r);
        }
    }
    if(EnableX && EnableY)
    {
        Painter()->SetLayer(layer);
        Style()->Rect(layer,this->FocusParent,sSK_Back,RectC);
        //    Painter()->Rect(ba,RectC);
    }
}
Exemple #16
0
void RNMarchingCubesBase<T>::Render()
{
  sStsCode code = 0;

  if(Para.Subdivide)
  {
    switch(Para.BaseGrid)
    {
      case 0: code = StaticRenderT<T,0,1>; break;
      case 1: code = StaticRenderT<T,1,1>; break;
      case 2: code = StaticRenderT<T,2,1>; break;
      case 3: code = StaticRenderT<T,3,1>; break;
      case 4: code = StaticRenderT<T,4,1>; break;
      case 5: code = StaticRenderT<T,5,1>; break;
    }
  }
  else
  {
    switch(Para.BaseGrid)
    {
      case 0: code = StaticRenderT<T,0,0>; break;
      case 1: code = StaticRenderT<T,1,0>; break;
      case 2: code = StaticRenderT<T,2,0>; break;
      case 3: code = StaticRenderT<T,3,0>; break;
      case 4: code = StaticRenderT<T,4,0>; break;
      case 5: code = StaticRenderT<T,5,0>; break;
    }
  }
  sVERIFY(code);

  // finish work

  if(Workload)
  {
    Workload->Sync();
    Workload->End();
    Workload = 0;
  }

  if(Para.Multithreading==2)
    MC.End();

  // reorganize memory

  const sInt s = 1<<Para.BaseGrid;
  sInt size = (s+2)*(s+1)*(s+1);
  if(size>PotSize)
  {
    PotSize = size;
    for(sInt i=0;i<MaxThread;i++)
    {
      delete[] PotData[i];
      PotData[i] = (typename T::FieldType *) sAllocMem(PotSize*sizeof(typename T::FieldType),16,0);
    }
  }
  sInt maxparts = 0;
  HashContainer *hc;
  sFORALL(NodeHashConts,hc)
  {
    sInt hcp = 0;
    PartContainer *nc = hc->FirstPart;
    while(nc)
    {
      hcp += nc->Count;
      nc = nc->Next;
    }
    maxparts = sMax(maxparts,hcp);
  }
Exemple #17
0
void RNRenderADF::Render(Wz4RenderContext *ctx)
{
  RenderChilds(ctx);
  
  if((ctx->RenderMode & sRF_TARGET_MASK)==sRF_TARGET_MAIN)
  {    
    sInt sx = ctx->ScreenX;
    sInt sy = ctx->ScreenY;

    sRay rtl;
    sRay rtr;
    sRay rtb;
    sRay rcp;
       
    ctx->View.MakeRay(-1, 1,rtl);
    ctx->View.MakeRay( 1, 1,rtr);
    ctx->View.MakeRay(-1,-1,rtb);
    ctx->View.MakeRay(0,0,rcp);
  
    sRay ray2;

    sVector30 dnx= (rtr.Start - rtl.Start);
    sVector30 dny= (rtb.Start - rtl.Start);
    sVector31 px=rtl.Start;  
    sVector31 cp=ctx->View.Camera.l;// rcp.Start;

    sTexture2D *dest = sRTMan->WriteScreen();
//    sTexture2D *src = sRTMan->ReadScreen();
    sTexture2D *mask = sRTMan->Acquire(sx,sy,sTEX_2D|sTEX_NOMIPMAPS|sTEX_ARGB16F);
    
    sRTMan->SetTarget(mask);

    //Render Gradient Texture
    sCBuffer<tADFMatVSPara> cbv;
    sCBuffer<tADFMatPSPara> cbp;

    ctx->IppHelper->GetTargetInfo(cbv.Data->mvp);
    cbv.Modify(); 

    sF32 imd=1.0f/sMax(sMax(SDF->DimX, SDF->DimY), SDF->DimZ);

    sAABBox box;
    SDF->GetBox(box);

    cbp.Data->dnx=dnx;
    cbp.Data->dny=dny;
    cbp.Data->px=rtl.Start;
    cbp.Data->cp=cp;
    cbp.Data->sp.Init(SDF->STBX,SDF->STBY,SDF->STBZ,0);
    cbp.Data->op.Init(box.Min.x,box.Min.y,box.Min.z,0);
    cbp.Data->mp.Init(box.Max.x,box.Max.y,box.Max.z,0);
    cbp.Data->id.Init(1.0f/(SDF->DimX-1),1.0f/(SDF->DimY-1),1.0f/(SDF->DimZ-1),imd);
    cbp.Data->d.Init(SDF->DimX,SDF->DimY,SDF->DimZ,0);
    cbp.Data->pstep.Init(SDF->PStepX,SDF->PStepY,SDF->PStepZ,0);

    cbp.Modify();
    Mtrl->Texture[0]=texture;
    Mtrl->Set(&cbv,&cbp);
    ctx->IppHelper->DrawQuad(dest);
    Mtrl->Texture[0]=0;



    sRTMan->SetTarget(dest);
    sCBuffer<tADFShadowMatVSPara> cbv_shadow;
    sCBuffer<tADFShadowMatPSPara> cbp_shadow;

    ctx->IppHelper->GetTargetInfo(cbv_shadow.Data->mvp);
    cbv_shadow.Modify(); 

    cbp_shadow.Data->dnx=dnx;
    cbp_shadow.Data->dny=dny;
    cbp_shadow.Data->px=rtl.Start;
    cbp_shadow.Data->cp=cp;    

    cbp_shadow.Data->sp.Init(SDF->STBX,SDF->STBY,SDF->STBZ,0);
    cbp_shadow.Data->op.Init(box.Min.x,box.Min.y,box.Min.z,0);
    cbp_shadow.Data->mp.Init(box.Max.x,box.Max.y,box.Max.z,0);
    cbp_shadow.Data->id.Init(1.0f/(SDF->DimX-1),1.0f/(SDF->DimY-1),1.0f/(SDF->DimZ-1),imd);
    cbp_shadow.Data->d.Init(SDF->DimX,SDF->DimY,SDF->DimZ,0);
    cbp_shadow.Data->pstep.Init(SDF->PStepX,SDF->PStepY,SDF->PStepZ,0);


    cbp_shadow.Data->light=Para.LightPos;
    cbp_shadow.Data->phongpara.Init(Para.PhongMax,Para.PhongPower,0,0);
    cbp_shadow.Data->diffusecolor.InitColor(Para.DiffuseColor);
    cbp_shadow.Data->ambientcolor.InitColor(Para.AmbientColor);
    cbp_shadow.Data->speccolor.InitColor(Para.SpecColor);



    //cbp_shadow.Data->
    cbp_shadow.Modify();

    MtrlShadow->Texture[0]=texture;
    MtrlShadow->Texture[1]=mask;
    MtrlShadow->Set(&cbv_shadow,&cbp_shadow);
    ctx->IppHelper->DrawQuad(dest,mask);
    MtrlShadow->Texture[0]=0;
    MtrlShadow->Texture[1]=0;

    sRTMan->Release(mask);
  //  sRenderTargetManager->Release(src);    
    sRTMan->Release(dest);
  } 
}
Exemple #18
0
void ViewBitmapWin_::OnPaint3d(sViewport &view)
{
//  sU32 states[256],*p;
  sVertexTSpace3 *vp;
  sMatrix mat;
  sMaterial11 *mtrl;
  sU16 *ip;
  sInt x,y,xs,ys;
  sInt handle;
  GenBitmap *bm_flat;
  static sInt var[] = 
  {
    GenBitmapTile::Pixel16C::Variant,
    GenBitmapTile::Pixel16I::Variant,
    GenBitmapTile::Pixel8C::Variant,
    GenBitmapTile::Pixel8I::Variant,
  };

  bm_flat = 0;
  if(ShowOp)
  {
    Doc->Connect();
    if(!ShowOp->Error)
    {
      bm_flat = CalcBitmap(ShowOp,16<<ShowSizeX,16<<ShowSizeY,var[ShowVariant]);
    }
  }

  if(bm_flat)
  {
    if(bm_flat->Texture==sINVALID)
    {
      bm_flat->MakeTexture(bm_flat->Format);
    }

    if(App->CurrentViewWin == this)
      sSPrintF(App->StatusObject,"Bitmap: %d x %d @ %d bits, %dkb",bm_flat->XSize,bm_flat->YSize,bm_flat->BytesPerPixel*8,(bm_flat->BytesTotal+1023)/1024);

//    view.ClearColor = sGui->Palette[sGC_BACK] & 0xffffff;
    mat.Init();

//    p = states;

    sSystem->SetViewport(view);
    sSystem->Clear(sVCF_ALL,sGui->Palette[sGC_BACK] & 0xffffff);
    MtrlTexAlpha->SetTex(0,bm_flat->Texture);
    MtrlTex->SetTex(0,bm_flat->Texture);
    MtrlNormal->SetTex(0,bm_flat->Texture);
    MtrlNormalLight->SetTex(1,bm_flat->Texture);

    if(bm_flat->XSize >= bm_flat->YSize)
    {
      xs = 256 * (1<<BitmapZoom)/16;
      ys = sMulDiv(xs,bm_flat->YSize,bm_flat->XSize);
    }
    else
    {
      ys = 256 * (1<<BitmapZoom)/16;
      xs = sMulDiv(ys,bm_flat->XSize,bm_flat->YSize);
    }

    x = BitmapX;
    y = BitmapY;

    if(bm_flat->Format == sTF_Q8W8V8U8) // normal map
    {
      mtrl = MtrlNormalLight;

      MtrlEnv.LightAmplify = 1.0f;
      MtrlEnv.LightColor.Init(1,1,1,1);

      sInt r = sMax(xs/2,ys/2);
      sVector dir;

      dir.Init(1.0f * LightPosX / r,1.0f * LightPosY / r,0.0f,0.0f);
      dir.z = 1.0 - dir.x * dir.x - dir.y*dir.y;
      dir.z = (dir.z < 0.3f * 0.3f) ? 0.3f : sFSqrt(dir.z);
      dir.Unit3();

      MtrlEnv.LightPos.Init(r*dir.x,r*dir.y,-r*dir.z);
      MtrlEnv.LightRange = r * 32.0f;
      MtrlEnv.CenterX = -1.0f * (x + xs / 2);
      MtrlEnv.CenterY = -1.0f * (y + ys / 2);
      x = -xs / 2;
      y = -ys / 2;
    }
    else
      mtrl = BitmapAlpha ? MtrlTexAlpha : MtrlTex;

    sSystem->SetViewProject(&MtrlEnv);
    mtrl->Set(MtrlEnv);

    handle = sSystem->GeoAdd(sFVF_TSPACE3,sGEO_TRISTRIP|sGEO_DYNAMIC);
    sSystem->GeoBegin(handle,4,4,(sF32 **)&vp,(void **)&ip);    
    *ip++ = 3;
    *ip++ = 2;
    *ip++ = 1;
    *ip++ = 0;
    if(BitmapTile)
    {
      vp->Init(x-xs  ,y-ys  ,0.5f,~0,-1,-1); vp++;
      vp->Init(x+xs*2,y-ys  ,0.5f,~0, 2,-1); vp++;
      vp->Init(x-xs  ,y+ys*2,0.5f,~0,-1, 2); vp++;
      vp->Init(x+xs*2,y+ys*2,0.5f,~0, 2, 2); vp++;
    }
    else
    {
      vp->Init( 0+x, 0+y,0.5f,~0,0,0); vp++;
      vp->Init(xs+x, 0+y,0.5f,~0,1,0); vp++;
      vp->Init( 0+x,ys+y,0.5f,~0,0,1); vp++;
      vp->Init(xs+x,ys+y,0.5f,~0,1,1); vp++;
    }
    sSystem->GeoEnd(handle);
    sSystem->GeoDraw(handle);
    sSystem->GeoRem(handle);

    if(bm_flat->Format == sTF_Q8W8V8U8)
    {
//      GenOverlayManager->FXQuad(GENOVER_ADDDESTALPHA);
      MtrlEnv.CenterX = MtrlEnv.CenterY = 0.0f;
    }
  }
}
Exemple #19
0
void s3DWindow::OnPaint3D()
{
  if(Enable)
  {
    // initial setup

    QuakeCam();                   // quake cam
    PrepareView();                // viewport
  }

  sScreenMode sm;
  sGetScreenMode(sm);

  if(Enable && !Client.IsEmpty())
  {
    // repare rendertarget spec

    sTargetSpec spec;
#if sRENDERER==sRENDER_DX11       // blit back
    sInt xs = Client.SizeX();
    sInt ys = Client.SizeY();
    if(ColorRT==0 || xs!=ColorRT->SizeX || ys!=ColorRT->SizeY || sm.MultiLevel!=RTMultiLevel)
    {
      sDelete(ColorRT);
      sDelete(DepthRT);
      ColorRT = new sTexture2D(xs,ys,sTEX_2D|sTEX_ARGB8888|sTEX_RENDERTARGET|sTEX_MSAA,1);
      DepthRT = new sTexture2D(xs,ys,sTEX_2D|sTEX_DEPTH24|sTEX_RENDERTARGET|sTEX_MSAA,1);
      RTMultiLevel = sm.MultiLevel;
    }
    spec.Depth = DepthRT;
    spec.Color = ColorRT;
    spec.Window.Init(0,0,xs,ys);
#else
    spec.Init(Client);
#endif

    // painting

    Paint(View);                  // paint 3d
    Paint(View,spec);

    View.Model.Init();            // prepare for wireframe
    View.SetTargetCurrent(&Client);
    View.Prepare();

    GridUnit = 0;                 // pain t grid
    if(Grid)
    {
      sEnableGraphicsStats(0);
      sSetTarget(sTargetPara(0,0,spec));
      PaintGrid();
      sEnableGraphicsStats(1);
    }

    PaintWire(View);                // custom wireframe
    PaintWire(View,spec);

    // screenshots

    if(ScreenshotFlag)
    {
      const sU8 *data;
      sS32 pitch;
      sTextureFlags flags;
      sImage img;

      sRect r=spec.Window;
      img.Init(r.SizeX(),r.SizeY());
      img.Fill(0xffff0000);

      sBeginReadTexture(data,pitch,flags,spec.Color2D);
      if(flags==sTEX_ARGB8888)
      {
        data += r.x0*4 + r.y0*pitch;
        sU32 *dest = img.Data;
        for(sInt y=r.y0;y<r.y1;y++)
        {
          sCopyMem(dest,data,r.SizeX()*4);
          dest += img.SizeX;
          data += pitch;
        }
      }
      sEndReadTexture();

      if(flags==sTEX_ARGB8888)
      {
        sInt nr = 0;
        sArray<sDirEntry> dir;
        sDirEntry *ent;
        sInt len = sGetStringLen(SCREENSHOTNAME);
        if(sLoadDir(dir,SCREENSHOTDIR))
        {
          sFORALL(dir,ent)
          {
            if(sCmpStringILen(ent->Name,SCREENSHOTNAME,len)==0)
            {
              sInt newnr;
              const sChar *scan = ent->Name+len;
              if(sScanInt(scan,newnr))
                nr = sMax(nr,newnr);
            }
          }
        }
        else
        {
          sMakeDirAll(SCREENSHOTDIR);
        }
        sString<64> name;
        sSPrintF(name,SCREENSHOTDIR L"/" SCREENSHOTNAME L"%04d.bmp",nr+1);
        img.SaveBMP(name);
      }
Exemple #20
0
void sTextControl::OnPaint()
{
  sChar *p;
  sInt i,x,y,h,xs;
  sInt pos;
  sRect r;
  sInt font;
  sInt s0,s1;

  if(RecalcSize) // usefull for Logwindow
  {
    RecalcSize = 0;
    OnCalcSize();
  }

  x = Client.x0+2;
  y = Client.y0+2;
  font = sGui->FixedFont;
  h = sPainter->GetHeight(font);
  p = Text;
  pos = 0;

  s0 = s1 = 0;
  if(SelMode)
  {
    s0 = sMin(Cursor,SelPos);
    s1 = sMax(Cursor,SelPos);
  }

  r.y0 = y-2;
  r.y1 = y;
  r.x0 = Client.x0;
  r.x1 = Client.x1;
  sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);

  for(;;)
  {
    i = 0;
    while(p[i]!=0 && p[i]!='\n')
      i++;

    r.y0 = y;
    r.y1 = y+h;
    r.x0 = Client.x0;
    r.x1 = Client.x1;
    if(sGui->CurrentClip.Hit(r))
    {
      sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);
      if(Cursor>=pos && Cursor<=pos+i)
      {
        r.x0 = x+sPainter->GetWidth(font,p,Cursor-pos);
        if(Overwrite)
        {
          if(Cursor==pos+i)
            r.x1 = x+sPainter->GetWidth(font," ");
          else
            r.x1 = x+sPainter->GetWidth(font,p,Cursor-pos+1);
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_SELBACK]);
        }
        else
        {
          r.x1 = r.x0+1;
          r.x0--;
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_TEXT]);
        }
      }
      if(SelMode && s0<=pos+i && s1>=pos)
      {
        if(s0<=pos)
          r.x0 = x;
        else
          r.x0 = x+sPainter->GetWidth(font,p,s0-pos);
        if(s1>pos+i)
          r.x1 = x+sPainter->GetWidth(font,p,i)+sPainter->GetWidth(font," ");
        else
          r.x1 = x+sPainter->GetWidth(font,p,s1-pos);
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_SELBACK]);
      }
      sPainter->Print(font,x,y,p,sGui->Palette[sGC_TEXT],i);
    }
    xs = sPainter->GetWidth(font,p,i)+4+sPainter->GetWidth(font," ");
    y+=h;
    p+=i;
    pos+=i;
    if(*p==0)
      break;
    if(*p=='\n')
    {
      p++;
      pos++;
    }
  }
  r.y0 = y;
  r.y1 = Client.y1;
  r.x0 = Client.x0;
  r.x1 = Client.x1;
  if(r.y0<r.y1)
    sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);
}
Exemple #21
0
void sBSpline::FitToCurve(const sCurveSamplePoint *points,sInt nPoints,sF32 skipThresh,sF32 maxError)
{
    if(nPoints < 2)
        return;

    // What this function does is generate a list of simple sample points
    // plus an initial knot vector for the actual approximation functions
    // to work with.
    sArray<Sample> samples;
    samples.Init(nPoints);

    Knots.Count = 0;

    // Find time range of samples
    sF32 minTime = points[0].Time, maxTime = points[0].Time;
    for(sInt i=1; i<nPoints; i++)
    {
        minTime = sMin(minTime,points[i].Time);
        maxTime = sMax(maxTime,points[i].Time);
    }

    // Generate sample points, plus knots at discontinuities
    for(sInt i=0; i<nPoints; i++)
    {
        sF32 time = (points[i].Time - minTime) / (maxTime - minTime);

        // Add value sample everywhere
        Sample *smp = samples.Add();
        smp->Time = time;
        smp->Value = points[i].Value;
        smp->Type = 0;

        // Add derivative sample if the derivative exists
        sBool derivExists = (points[i].Flags & 3) == 3 && sFAbs(points[i].DerivLeft - points[i].DerivRight) < 1e-6f;

        if(derivExists && (points[i].Flags & 4))
        {
            Sample *smp = samples.Add();
            smp->Time = time;
            smp->Value = points[i].DerivLeft;
            smp->Type = 1;
        }

        // Discontinuity checking
        sInt discontinuityOrder = Degree + 1;
        if(!derivExists && (points[i].Flags & 3)) // C^1 discontinuity
            discontinuityOrder = 1;

        // C^0 discontinuity?
        if(i == 0 || i == nPoints - 1 || sFAbs(points[i].Value - points[i-1].Value) > skipThresh)
            discontinuityOrder = 0;

        // Add knots as necessary
        for(sInt j=discontinuityOrder; j<=Degree; j++)
            *Knots.Add() = time;
    }

    Values.Resize(Knots.Count);

    // Perform actual curve fitting
    FitCurveImpl(&samples[0],samples.Count,maxError,8);

    samples.Exit();
}
Exemple #22
0
void sBSpline::LeastSquaresFit(const Sample *samples,sInt nSamples)
{
    // The input dataset is assumed to be on [0,1)
    // Now do a least-squares fit via normal equations, that is solve
    //   (A^T A) x = A^T b
    // for x.
    //
    // To do this, first compute the weights of the B-Spline at
    // sample points to determine A
    sInt deg = Degree,order = Degree + 1;
    sInt nKnots = Knots.Count;

    sF32 *A = new sF32[nSamples * order];
    sInt *start = new sInt[nSamples];

    for(sInt i=0; i<nSamples; i++)
        if(samples[i].Type == 0) // normal function value
            CalcBasis(samples[i].Time,start[i],A + i*order);
        else // derivative
            CalcBasisDeriv(samples[i].Time,start[i],A + i*order);

    // Next, calculate the matrix A^T A. This is always symmetrical and
    // positive semidefinite, and in this case also a banded matrix, so we
    // only need order * nKnots floats to store it
    sF32 *ATA = new sF32[nKnots * order];

    for(sInt i=0; i<nKnots; i++)
    {
        // samples for knot i
        sInt start1 = lowerBound(start,i-deg,nSamples);
        sInt end1 = lowerBound(start,i+1,nSamples);

        for(sInt j=0; j<order; j++)
        {
            // samples for knot i+j-deg
            sInt start2 = lowerBound(start,i+j-2*deg,nSamples);
            sInt end2 = lowerBound(start,i+j-deg+1,nSamples);

            // calculate overlap
            sInt commonStart = sMax(start1,start2);
            sInt commonEnd = sMin(end1,end2);

            // perform summation
            sF64 sum = 0.0f;
            for(sInt k=commonStart; k<commonEnd; k++)
            {
                sF32 *pos = &A[k*order + i-start[k]];
                sum += pos[0] * pos[j-deg];
            }

            ATA[i*order+j] = sum;
        }
    }

    // Compute a LDL^T decomposition of A^T A (in-place)
    sF32 *scale = new sF32[nKnots];
    for(sInt i=0; i<nKnots; i++)
    {
        // Solve for diagonal element
        sF64 d = ATA[i*order+deg];
        for(sInt j=sMax(i-deg,0); j<i; j++)
            d -= sSquare(ATA[i*order+(j-i)+deg])*ATA[j*order+deg];

        // Calculate inverse d, store back
        d = (sFAbs(d) > 1e-10f) ? d : 0.0f;
        sF64 id = d ? 1.0f / d : 0.0f;
        ATA[i*order+deg] = d;
        scale[i] = id;

        // Solve for rest
        for(sInt j=1; j<order; j++)
        {
            sInt row = i+j;

            if(row < nKnots)
            {
                sF64 sum = ATA[row*order+deg-j];
                for(sInt k=sMax(row-deg,0); k<i; k++)
                    sum -= ATA[row*order+(k-row)+deg] * ATA[i*order+(k-i)+deg] * ATA[k*order+deg];

                ATA[row*order+deg-j] = id * sum;
            }
        }
    }

    // Now, actually solve the system. Anything before this only needs to be
    // done once per knot vector.
    // Compute A^T b
    for(sInt i=0; i<nKnots; i++)
    {
        sInt startw = lowerBound(start,i-deg,nSamples);
        sInt endw = lowerBound(start,i+1,nSamples);

        sF64 c = 0.0f;
        for(sInt j=startw; j<endw; j++)
            c += A[j*order + i-start[j]] * samples[j].Value;

        Values[i] = c;
    }

    // Solve Lx
    for(sInt i=0; i<nKnots; i++)
    {
        sF64 sum = Values[i];
        for(sInt j=sMax(i-deg,0); j<i; j++)
            sum -= ATA[i*order+(j-i)+deg] * Values[j];

        Values[i] = sum;
    }

    // Solve Dx
    for(sInt i=0; i<nKnots; i++)
        Values[i] *= scale[i];

    // Solve L^Tx (backwards substitution)
    for(sInt i=nKnots-2; i>=0; i--)
    {
        sF64 sum = Values[i];
        for(sInt j=i+1; j<sMin(i+order,nKnots); j++)
            sum -= ATA[j*order+(i-j)+deg] * Values[j];

        Values[i] = sum;
    }

    // Cleanup
    delete[] A;
    delete[] start;
    delete[] ATA;
    delete[] scale;
}
Exemple #23
0
sBool sTextControl::OnCommand(sU32 cmd)
{
  sInt s0,s1,len;
  sDiskItem *di;
  sChar buffer[sDI_PATHSIZE];
  sChar *t;

  s0 = sMin(SelPos,Cursor);
  s1 = sMax(SelPos,Cursor);
  len = s1-s0;

  switch(cmd)
  {
  case sTCC_CUT:
    if(SelMode && s0!=s1)
    {
      sGui->ClipboardClear();
      sGui->ClipboardAddText(Text+s0,len);
      Engine(s0,len,0);
      Post(DoneCmd);
      SelMode = 0;
      Cursor = s0;
    }
    return sTRUE;
  case sTCC_COPY:
    if(SelMode && s0!=s1)
    {
      sGui->ClipboardClear();
      sGui->ClipboardAddText(Text+s0,len);
      SelMode = 0;
    }
    return sTRUE;
  case sTCC_PASTE:
    t = sGui->ClipboardFindText();
    if(t && t[0])
    {
      Engine(Cursor,sGetStringLen(t),t);
      Cursor+=sGetStringLen(t);
      Post(DoneCmd);
    }
    return sTRUE;
  case sTCC_BLOCK:
    if(SelMode==0)
    {
      SelMode = 2;
      SelPos = Cursor;
    }
    else
    {
      SelMode = 0;
    }  
    return sTRUE;

  case 3:     // Cancel File Requester
    if(File)
    {
      File->Parent->RemChild(File);
      File = 0;
    }
    return sTRUE;
  case sTCC_OPEN:
    if(!File)
    {
      File = new sFileWindow;
      File->AddTitle("Open File");
      sGui->AddApp(File);
    }
    sGui->SetFocus(File);
    File->OkCmd = 4;
    File->CancelCmd = 3;
    File->SendTo = this;
    Modal = File;
    File->SetPath(PathName);
    return sTRUE;
  case 4:
    if(File)
    {
      File->GetPath(buffer,sizeof(buffer));
      OnCommand(3);
      if(!LoadFile(buffer))
      {
        SetText("");
        (new sDialogWindow)->InitOk(this,"Open File","Load failed",0);
      }
    }
    return sTRUE;

  case sTCC_CLEAR:
    SetText("");
    return sTRUE;      


  case sTCC_SAVEAS:
    if(!File)
    {
      File = new sFileWindow;
      File->AddTitle("Open File");
      sGui->AddApp(File);
    }
    sGui->SetFocus(File);
    File->OkCmd = 5;
    File->CancelCmd = 3;
    File->SendTo = this;
    Modal = File;
    File->SetPath(PathName);
    return sTRUE;
  case 5:
    if(File)
    {
      File->GetPath(PathName,sizeof(PathName));
      OnCommand(3);
      OnCommand(sTCC_SAVE);
    }
    return sTRUE;
  case sTCC_SAVE:
    di = sDiskRoot->Find(PathName,sDIF_CREATE);
    if(di)
    {
      len = sGetStringLen(Text);
      if(di->SetBinary(sDIA_DATA,(sU8 *)Text,len))
      {
        Post(CursorCmd);
        Changed = 0;
      }
      else
      {
        (new sDialogWindow)->InitOk(this,"Save File","Save failed",0);
      }
    }
    return sTRUE;

  default:
    return sFALSE;
  }
}
Exemple #24
0
void RNFR067_IsoSplash::MarchTask(sStsThread *thread,sInt start,sInt count)
{
  sInt id = thread ? thread->GetIndex() : 0;
  sSchedMon->Begin(id,0xff8080);
  const sInt s1 = CellSize+1;
  const sInt s2 = CellSize+2;
  const sInt s3 = CellSize+3;
  for(sInt ii=start;ii<start+count;ii++)
  {
    IsoNode *node = &Nodes[ii];

    sF32 pots[s3][s3][s3];
    sVector31 p0 = node->Min;
    sVector31 pp;

    //  calculate some coefficients

    sF32 pd = (node->Max.x-node->Min.x)/CellSize;
    p0.x -= pd;
    p0.y -= pd;
    p0.z -= pd;

    sMatrix34 mat[s3];

    if(RubberEnable)
    {
      for(sInt y=0;y<s3;y++)
      {
         sF32 py = p0.y+pd*y;
         mat[y].EulerXYZ((Para.Rot.x+Para.Rubber.x*py)*sPI2F,
                         (Para.Rot.y+Para.Rubber.y*py)*sPI2F,
                         (Para.Rot.z+Para.Rubber.z*py)*sPI2F);
      }
    }
    else
    {
      mat[0].EulerXYZ(Para.Rot.x*sPI2F,Para.Rot.y*sPI2F,Para.Rot.z*sPI2F);
      for(sInt y=1;y<s3;y++)
        mat[y] = mat[0];
    }

    // check some points

    sInt testpoints[9][3] =
    {
      { 5,5,5 },
      { 1,1,1 },
      { 1,1,9 },
      { 1,9,1 },
      { 1,9,9 },
      { 9,1,1 },
      { 9,1,9 },
      { 9,9,1 },
      { 9,9,9 },
    };

    sF32 pmin = 1000;
    sF32 pmax = -1000;
    for(sInt i=0;i<9;i++)
    {
      pp.x = p0.x+pd*testpoints[i][0];
      pp.y = p0.y+pd*testpoints[i][1];
      pp.z = p0.z+pd*testpoints[i][2];
      sF32 f = func(pp
        ,testpoints[i][0]+node->px
        ,testpoints[i][1]+node->py
        ,testpoints[i][2]+node->pz);
      pmin = sMin(pmin,f);
      pmax = sMax(pmax,f);       
    }
    if(!(pmax>-Para.QuickOutSaveGuard && pmin<Para.QuickOutSaveGuard))
      continue;


    // generate volume

    pmin = 1000;
    pmax = -1000;
    for(sInt z=0;z<s3;z++)
    {
      for(sInt y=0;y<s3;y++)
      {
        for(sInt x=0;x<s3;x++)
        {
          pp.x = p0.x+pd*x;
          pp.y = p0.y+pd*y;
          pp.z = p0.z+pd*z;
          sF32 f = func(pp,x+node->px
                          ,y+node->py
                          ,z+node->pz);
          pots[z][y][x] = f;
          
          pmin = sMin(pmin,f);
          pmax = sMax(pmax,f);       
        }
      }
    }

    if(!(pmax>0 && pmin<0))
      continue;

    // generate normals

    MCPotField pot[s1+1][s1][s1];
    sVector30 n;

    for(sInt z=1;z<s2;z++)
    {
      for(sInt y=1;y<s2;y++)
      {
        for(sInt x=1;x<s2;x++)
        {
          sF32 w = pots[z][y][x];
          n.x = pots[z][y][x+1] - pots[z][y][x-1];
          n.y = pots[z][y+1][x] - pots[z][y-1][x];
          n.z = pots[z+1][y][x] - pots[z-1][y][x];

          sF32 e = n.x*n.x + n.y*n.y + n.z*n.z;

          if(e>1e-24f)
          {
            e=sFRSqrt(e);
            n.x = e*n.x;
            n.y = e*n.y;
            n.z = e*n.z;
          }
          else
          {
            n.Init(0,0,0);
          }

          pot[z-1][y-1][x-1].x = -n.x;
          pot[z-1][y-1][x-1].y = -n.y;
          pot[z-1][y-1][x-1].z = -n.z;
          pot[z-1][y-1][x-1].w = w;
        }
      }
    }

    // marching cubes

    MC.March(3,&pot[0][0][0],pd*Para.GridSize*0.5f,sVector31(sVector30(node->Min)*(Para.GridSize*0.5f)),id);
  }
  sSchedMon->End(id);
}
Exemple #25
0
 void Grow(sInt add)             { if(this->Used+add>this->Alloc) ReAlloc(sMax(this->Used+add,this->Alloc*2)); }
Exemple #26
0
 void GrowTo(sInt size)             { if(size>this->Alloc) ReAlloc(sMax(size,this->Alloc*2)); }