Beispiel #1
0
V3d hillfor(int x,int y) {
        V3d v=V3d((2.0*(float)(x-scrwid/2)/scrhei)*3,1-2*(float)intmap.pos[x][y]/255/1.5,(-1+2.0*(float)y/scrhei)*3);
        V3d vr=v.rotate(V3d(0,1,0),-pi/16);
        V3d vrr=vr.rotate(V3d(1,0,0),-pi/4);
        vrr=vrr+V3d(0,0,4);
  return vrr;
}
Beispiel #2
0
void main() {
  allegrosetup(scrwid,scrhei);
  makesplitpalette(&redtowhitepalette,&greentowhitepalette);
  randomise();
  PPsetup(scrwid,scrhei,4);
  JBmp j=JBmp(scrwid,scrhei);
  j.clear();
  List<Part> ps=List<Part>();
  for (int i=1;i<=numparts/line;i++) {
    newparts(&ps);
  }
  int frame=0;
  do {
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      int sx,sy;
      PPgetscrpos(p->pos,&sx,&sy);
      int sxb,syb;
      PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb);
      float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb));
      j.filledcirclenodarker(sx,sy,rad,p->outc);
      j.filledcirclenodarker(sx,sy,rad/3,p->inc);
//      j.shadedcirclenodarker(sx,sy,rad,p->inc,p->outc);
    }
    for (int x=0;x<scrwid;x++)
      for (int y=0;y<scrhei;y++) {
        int k=j.bmp[y][x];
        if (k>=128+fade)
          j.bmp[y][x]-=fade;
        else
          if (k<128)
            if (k>=fade)
              j.bmp[y][x]-=fade;
//            j.bmp[y][x]=intchop(k-fade,0,128);
//          j.bmp[y][x]=128+intchop(k-fade-128,0,128);
        if (k>=128 && k<=128+3)
          j.bmp[y][x]=0;
      }
    j.writetoscreen();
    Matrix m,n;
    V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/2000));
    m.makerotation(rotaxis,pi/1000.0);
    n.makerotation(rotaxis,-pi/1000.0);
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      if (p->sgn>0)
        p->pos=m*p->pos;
      else
        p->pos=n*p->pos;
      p->pos=p->pos+V3d(0,0,-0.03);
      if ((p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2)) {
        ps.removenum(i);
        if (ps.len<numparts-line)
          newparts(&ps);
      }
    }
    frame++;
  } while (!key[KEY_ESC]);
}
Beispiel #3
0
//-*****************************************************************************
void init( void )
{
    {
        GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat mat_shininess[] = { 100.0 };
        GLfloat mat_front_emission[] = {0.0, 0.0, 0.0, 0.0 };
        GLfloat mat_back_emission[] = {1.0f, 0.0, 0.0, 1.0f };

        glClearColor( 0.0, 0.0, 0.0, 0.0 );
        glMaterialfv( GL_FRONT, GL_EMISSION, mat_front_emission );
        glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
        glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );

        glMaterialfv( GL_BACK, GL_EMISSION, mat_back_emission );
        glMaterialfv( GL_BACK, GL_SPECULAR, mat_specular );
        glMaterialfv( GL_BACK, GL_SHININESS, mat_shininess );

        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
    }

    glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
    glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glDisable(GL_CULL_FACE);

    glShadeModel( GL_SMOOTH );

    g_state.scene.cam.setSize( 800, 600 );
    g_state.scene.cam.lookAt( V3d( 24, 18, 24 ), V3d( 0.0 ) );
    g_state.bMask = 0;
    g_state.showHelp = false;
    g_state.playback = kStopped;
    g_state.scene.pointSize = 3.0f;
    glPointSize( 3.0f );

    init_surface();

    setMaterials( 1.0, false );

    g_state.scene.cam.frame( g_transport->getBounds() );

    std::ostringstream titleStream;
    titleStream << "Archive = " 
                << g_transport->getFileName()
                << " | Frame = "
                << g_transport->getCurrentFrame();
    glutSetWindowTitle( titleStream.str().c_str() );
}
Beispiel #4
0
void main() {
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  makepalette(&myRGB::hue);
  randomise();
  for (int i=0;i<20;i++) {
    float amp=0;
    S s=S(V3d::randomvolume(1),radfromamp(amp),0);
    S v=S(V3d(0,0,0),0,0);
    xs+s;
    xvs+v;
  }
  for (int rndloop=0;rndloop<100;rndloop++) {
    for (int i=0;i<20;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
  }
  JBmp j=JBmp(scrwid,scrhei);
  Map2d<int> intmap=Map2d<int>(scrwid,scrhei);
  do {
    for (int x=0;x<scrwid;x+=jump)
    for (int y=0;y<scrhei;y+=jump) {
      V3d here=V3d((x-scrwid/2)*2.0/scrhei,-1.0+2.0*y/scrhei,0);
      float sum=getpotentialfor(here);
      int newcol=128+128*sum;
      intmap.pos[x][y]=newcol;
      if (x>0 && y>0) {
        int nwcol=intmap.pos[x-jump][y-jump];
        int wcol=intmap.pos[x-jump][y];
        int ncol=intmap.pos[x][y-jump];
        for (int i=0;i<=jump;i++)
        for (int k=0;k<=jump;k++) {
          float e=(float)i/(float)jump;
          float w=1.0-e;
          float s=(float)k/(float)jump;
          float n=1.0-s;
          j.bmp[y-jump+k][x-jump+i]=ucharmod(s*e*newcol+n*w*nwcol+s*w*wcol+n*e*ncol);
          // j.bmp[y-jump+k][x-jump+i]=(1.0-i/(float)jump)*(1.0-k/(float)jump)*nwcol+(1.0-i/(float)jump)*(k/(float)jump)*wcol+(i/(float)jump)*(1.0-k/(float)jump)*ncol+(i/(float)jump)*(k/(float)jump)*newcol;
        }
      }
    }
    for (int i=1;i<=xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
      /* if (debug) {
           // int c=j.point(x->cx,x->cy)+x->amp;
           int c=0;
           j.vliner(x->cx,x->cy,plusminus(i)*x->amp,c);
           j.hliner(x->cx,x->cy,x->rad,c);
           j.setpixel(x->cx+radfromamp(x->amp),x->cy,c);
         }*/
    }
    j.writetoscreen();
  } while (!key[KEY_ESC]);
}
Beispiel #5
0
void main() {
  allegrosetup(scrwid,scrhei);
  makesplitpalette(&redtowhitepalette,&greentowhitepalette);
  PPsetup(scrwid,scrhei,4);
  JBmp j=JBmp(scrwid,scrhei);
  j.clear();
  List<Part> ps=List<Part>();
  for (int i=1;i<=10;i++) {
    Part p;
    newpart(&p);
    ps+p;
  }
  int frame=0;
  do {
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      int sx,sy;
      PPgetscrpos(p->pos,&sx,&sy);
      int sxb,syb;
      PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb);
      float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb));
      j.filledcircle(sx,sy,rad,p->inc);
//      j.filledcirclenodarker(sx,sy,rad/3,p->inc);
    }
    for (int x=0;x<scrwid;x++)
      for (int y=0;y<scrhei;y++) {
        int k=j.bmp[y][x];
        if (k==128)
          j.bmp[y][x]=0;
        if (k<128)
          j.bmp[y][x]=chop(k-4,0,128);
        else
          j.bmp[y][x]=128+chop(k-4-128,0,128);
      }
    j.writetoscreen();
    Matrix m,n;
    V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/4000));
    m.makerotation(rotaxis,pi/1000.0);
    n.makerotation(rotaxis,-pi/1000.0);
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      if (p->sgn>0)
        p->pos=m*p->pos;
      else
        p->pos=n*p->pos;
      p->pos=p->pos+V3d(0,0,-0.03);
      if (p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2)
        newpart(p);
    }
    frame++;
  } while (!key[KEY_ESC]);
}
Beispiel #6
0
bool TriMesh::pickVertex(const V3d& cameraPos,
                         const EllipticalDist& distFunc,
                         V3d& pickedVertex,
                         double* distance,
                         std::string* info) const
{
    if (m_verts.empty())
        return false;

    size_t idx = distFunc.findNearest(offset(), (V3f*)&m_verts[0],
                                      m_verts.size()/3, distance);

    pickedVertex = V3d(m_verts[3*idx], m_verts[3*idx+1], m_verts[3*idx+2]) + offset();

    if (info)
    {
        *info = "";
        *info += tfm::format("  position = %.3f %.3f %.3f\n", pickedVertex.x, pickedVertex.y, pickedVertex.z);
        if (!m_colors.empty())
        {
            *info += tfm::format("  color = %.3f %.3f %.3f\n",
                                 m_colors[3*idx], m_colors[3*idx+1], m_colors[3*idx+2]);
        }
    }

    return true;
}
Beispiel #7
0
bool TriMesh::pickVertex(const V3d& cameraPos,
                         const V3d& rayOrigin,
                         const V3d& rayDirection,
                         const double longitudinalScale,
                         V3d& pickedVertex,
                         double* distance,
                         std::string* info) const
{
    if (m_verts.empty())
        return false;

    size_t idx = closestPointToRay((V3f*)&m_verts[0], m_verts.size()/3,
                                   rayOrigin - offset(), rayDirection,
                                   longitudinalScale, distance);

    pickedVertex = V3d(m_verts[3*idx], m_verts[3*idx+1], m_verts[3*idx+2]) + offset();

    if (info)
    {
        *info = "";
        *info += tfm::format("  position = %.3f %.3f %.3f\n", pickedVertex.x, pickedVertex.y, pickedVertex.z);
        if (!m_colors.empty())
        {
            *info += tfm::format("  color = %.3f %.3f %.3f\n",
                                 m_colors[3*idx], m_colors[3*idx+1], m_colors[3*idx+2]);
        }
    }

    return true;
}
Beispiel #8
0
void View3D::drawMeshes(const TransformState& transState,
                        const std::vector<const Geometry*>& geoms) const
{
    // Draw faces
    if (m_meshFaceShader->isValid())
    {
        QGLShaderProgram& meshFaceShader = m_meshFaceShader->shaderProgram();
        meshFaceShader.bind();
        M44d worldToEyeVecTransform = m_camera.viewMatrix();
        worldToEyeVecTransform[3][0] = 0;
        worldToEyeVecTransform[3][1] = 0;
        worldToEyeVecTransform[3][2] = 0;
        V3d lightDir = V3d(1,1,-1).normalized() * worldToEyeVecTransform;
        meshFaceShader.setUniformValue("lightDir_eye", lightDir.x, lightDir.y, lightDir.z);
        for (size_t i = 0; i < geoms.size(); ++i)
            geoms[i]->drawFaces(meshFaceShader, transState);
    }

    // Draw edges
    if (m_meshEdgeShader->isValid())
    {
        QGLShaderProgram& meshEdgeShader = m_meshEdgeShader->shaderProgram();
        glLineWidth(1.0f);
        meshEdgeShader.bind();
        for(size_t i = 0; i < geoms.size(); ++i)
            geoms[i]->drawEdges(meshEdgeShader, transState);
    }
}
Beispiel #9
0
//------------------------------------------------------------------------------
// TriMesh implementation
bool TriMesh::loadFile(QString fileName, size_t /*maxVertexCount*/)
{
    // maxVertexCount is ignored - not sure there's anything useful we can do
    // to respect it when loading a mesh...
    PlyLoadInfo info;
    if (!loadPlyFile(fileName, info))
        return false;
    setFileName(fileName);
    V3d offset = V3d(info.offset[0], info.offset[1], info.offset[2]);
    setOffset(offset);
    setCentroid(getCentroid(offset, info.verts));
    setBoundingBox(getBoundingBox(offset, info.verts));
    m_verts.swap(info.verts);
    m_colors.swap(info.colors);
    m_texcoords.swap(info.texcoords);
    m_triangles.swap(info.triangles);
    m_edges.swap(info.edges);
    if (!info.textureFileName.isEmpty())
    {
        QImage image;
        if (image.load(info.textureFileName))
            m_texture.reset(new Texture(image));
        else
            g_logger.warning("Could not load texture %s for model %s", info.textureFileName, fileName);
    }
    //makeSmoothNormals(m_normals, m_verts, m_triangles);
    //makeEdges(m_edges, m_triangles);
    return true;
}
Beispiel #10
0
C3f Renderer::radiance(const Ray & ray, Random *rnd, const int depth) const
{
	Intersection intersection;
	if (!_scene.intersect(ray, &intersection))
	{
		return C3f(0.0f, 0.0f, 0.0f);
	}

	double prob = intersection.pMaterial->getMaxColor();

	if (depth > 5)
	{
		return C3f(0.0f, 0.0f, 0.0f);
	} else {
		prob = 1.0;
	}
	C3f incomingRadiance(0.0f, 0.0f, 0.0f);
	C3f weight(1.0f, 1.0f, 1.0f);

	V3d w, u, v;
	w = intersection.normal.dot(ray.dir) < 0.0 ? intersection.normal : (-1.0 * intersection.normal);

	if (fabs(w.x) > SR_EPSILON)
	{
		u = (V3d(0.0, 1.0, 0.0).cross(w)).normalized();
	} else {
		u = (V3d(1.0, 0.0, 0.0).cross(w)).normalized();
	}
	v = w.cross(u);
	const double r1 = SR_PITIMES2 * rnd->next01();
	const double r2 = rnd->next01(), r2s = sqrt(r2);

	Ray next;
	next.pos = intersection.position;
	next.dir = (
		u * cos(r1) * r2s +
		v * sin(r1) * r2s +
		w * sqrt(1.0 - r2)).normalized();

	incomingRadiance = radiance(next, rnd, depth + 1);

	weight = intersection.pMaterial->shade() /prob;

	return intersection.pMaterial->getEmission() + weight*incomingRadiance;

}
Beispiel #11
0
void main() {
  int scrwid=320;
  int scrhei=200;
  float cenx=-0.5;
  float ceny=0;
  float wid=2.0;
  float hei=1.5;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  float front=-1.0;
  float back=0.5;
  float scale=2.0/(2.0*front);
  float crazy=0.1234567;
  int steps=20;
  int jump=1;
  int frames=30;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
//  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
  Map2d<float> *map=new Map2d<float>(scrhei,scrhei);
  for (int frame=0;frame<frames;frame++) {
    float angle=pi*(float)frame/(float)frames;
    for (int i=0;i<scrwid;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        // b->setpixelud(indent+i,j,255);
        // b->writetoscreen();
        int col=0;
        V3d tmp=V3d(left+2.0*wid*i/(float)scrwid,top+2.0*hei*j/(float)scrhei,0);
        tmp=V3d::rotate(tmp,V3d(0,1,0),angle);
        current=Quaternion(tmp.x,tmp.y,tmp.z,0);
        b->bmp[j][i]=julquat(Quaternion(0,0,0,0));
        if (key[KEY_SPACE])
          exit(0);
      }
    b->writetoscreen();
    }
//    PALETTE pal;
//    get_palette(pal);
//    save_bitmap(getnextfilename("bmp"),screen,pal);
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Beispiel #12
0
V3d hillfor(int x,int y) {
  if (intmap.pos[x][y]==0) {
      float sum=0;
      for (int i=1;i<=xs.len;i++) {
        S s=xs.num(i);
        sum+=plusminus(i)*s.amp*sin(sqrt(mysquare(x-s.cx)+mysquare(y-s.cy))/s.rad*2);
      }
      sum=scale*sum/(float)(xs.len);
      int newcol=128+128*sum;
      intmap.pos[x][y]=newcol;
  }
        V3d v=V3d((2.0*(float)(x-scrwid/2)/scrhei)*3,1-2*(float)intmap.pos[x][y]/255/1.5,(-1+2.0*(float)y/scrhei)*3);
        V3d vr=v.rotate(V3d(0,1,0),-pi/16);
        V3d vrr=vr.rotate(V3d(1,0,0),-pi/4);
        vrr=vrr+V3d(0,0,4);
  return vrr;
}
Beispiel #13
0
  void Corner::findnormal() {
    normal=V3d::o;
    for (int i=1;i<=gs.len;i++)
      normal=normal+gs.num(i)->normal();
    if (gs.len>0)
      normal.normalise();
    col=ucharchop(255*myabs(V3d::normdot(normal,V3d(-1,2,-1))));
//    col=col*(float)gs.len/6.0;
  }
Beispiel #14
0
//------------------------------------------------------------------------------
// utils
static V3d getCentroid(const V3d& offset, const std::vector<float>& vertices)
{
    V3d posSum(0);
    for (size_t i = 0; i < vertices.size(); i+=3)
        posSum += V3d(vertices[i], vertices[i+1], vertices[i+2]);
    if (vertices.size() > 0)
        posSum = 1.0/(vertices.size()/3.0) * posSum;
    return posSum + offset;
}
Beispiel #15
0
  void Triangle3d::render(JBmp *j,Viewpoint *v) {
    int xa,xb,xc,ya,yb,yc;
    if (PPgetscrposnoadd(v->bring(a),&xa,&ya) &&
        PPgetscrposnoadd(v->bring(b),&xb,&yb) &&
        PPgetscrposnoadd(v->bring(c),&xc,&yc)) {
      V3d n=normal().disorientate(v->ori);
      int c=ucharchop(255*myabs(V3d::normdot(n,V3d(-1,2,-1))));
      j->filltri(xa,ya,xb,yb,xc,yc,c);
//      j->filltri(xa,ya,xb,yb,xc,yc,ucharchop(255-255*v->bring(cen).z/8.0));
    }
  }
Beispiel #16
0
V3d Matrix::operator*(V3d u) {
  V3d n=V3d(0,0,0);
  float c;
  for (int i=0;i<=2;i++) {
    c=u.var(i);
    n.x=n.x+c*v[i][0];
    n.y=n.y+c*v[i][1];
    n.z=n.z+c*v[i][2];
  }
  return n;
}
Beispiel #17
0
void newpart(Part *p) {
    p->pos=V3d(magrnd(1),magrnd(1),1);
    p->rad=0.02+myrnd(0.04);
    p->sgn=plusminus();
    if (p->sgn>0) {
      p->inc=127;
      p->outc=63;
    } else {
      p->inc=255;
      p->outc=128+63;
    }
}
Beispiel #18
0
static Imath::Box3d getBoundingBox(const V3d& offset, const std::vector<float>& vertices)
{
    Imath::Box3d bbox;
    for (size_t i = 0; i < vertices.size(); i+=3)
        bbox.extendBy(V3d(vertices[i], vertices[i+1], vertices[i+2]));
    if (!bbox.isEmpty())
    {
        bbox.min += offset;
        bbox.max += offset;
    }
    return bbox;
}
Beispiel #19
0
void newparts(List<Part> *l) {
  V3d a=V3d(magrnd(1),magrnd(1),1+magrnd(2));
  V3d b=a+V3d(magrnd(1),magrnd(1),magrnd(0.4));;
  float sgn=plusminus();
  float rad=0.005+myrnd(0.01);
  for (int i=1;i<=line;i++) {
    Part p;
    float thru=(float)(i-1)/(line-1);
    p.pos=a+thru*(b-a);
    p.rad=rad;
    p.sgn=sgn;
    if (p.sgn>0) {
      p.inc=127;
      p.outc=63;
    } else {
      p.inc=255;
      p.outc=128+63;
    }
    l->add(p);
  }
}
Beispiel #20
0
int main() {
    List<V3d> l;
    List<float> m;
    allegrosetup(scrwid,scrhei);
    makepalette(&greypalette);
//  List<V3d> l(5);
    for (int i=1; i<=numps; i++) {
        V3d r=sqrt(myrnd())*(V3d::random());
        l.add(r);
        m.add(r.mod());
    }

    JBmp j=JBmp(scrwid,scrhei);
    int time=0;
    while (!key[KEY_ESC]) {
        time++;
        V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(1,0,0),time*pi/500);
        V3d rotaxis2=V3d::rotate(V3d(0,1,0),V3d(1,0,0),time*pi/500);
        j.clear();
        for (int i=1; i<=l.length(); i++) {
//      V3d t=(V3d)(l.num(i));
//      t.changeto(V3d::rotate(t,rotaxis,pi/40));
//      l.replace(i,t);
            V3d v=(V3d)(l.num(i));
            V3d t=(V3d::rotate((V3d::rotate(v,V3d(1,0,0),pi/700*time)),V3d(0,1,0),pi/40*time));
            j.setpixel(scrwid/2+scrhei/2*t.x,scrhei/2*(1+t.y),127*(1-t.z));
        }
        j.writetoscreen();
    }
}
Beispiel #21
0
//-*****************************************************************************
void MeshDrwHelper::computeBounds()
{
    m_bounds.makeEmpty();
    if ( m_meshP )
    {
        size_t numPoints = m_meshP->size();
        for ( size_t p = 0; p < numPoints; ++p )
        {
            const V3f &P = (*m_meshP)[p];
            m_bounds.extendBy( V3d( P.x, P.y, P.z ) );
        }
    }
}
Beispiel #22
0
 void RGBHistogram::display() {
   #ifdef ALLEGRO
   int winwid=640,winhei=480;
   set_color_depth(24);
   allegrosetup(winwid,winhei);
   PALETTE pal;
   generate_332_palette(pal);
   set_palette(pal);
   float rot=pi/4,elev=pi/8,rotspeed=pi/64;
   int smallize=largest();
   PPsetup(winwid,winhei,3);
   BITMAP *b=create_bitmap(winwid,winhei);
   do {
     clear(b);
     Matrix m1=Matrix();
     m1.makerotation(V3d(0,1,0),rot);
     Matrix m2=Matrix();
     m2.makerotation(V3d(1,0,0),elev);
     for (int i=0;i<quant;i++) {
       for (int j=0;j<quant;j++) {
         for (int k=0;k<quant;k++) {
           V3d c=V3d(i,j,k);
           c=c/c.getlongestside();
           c=c*(float)rgb[i][j][k]/smallize*255;
           // c=c*255;
           c.chop(0,255);
           if (c.getlongestside()>64) {
             V3d v=2*(V3d(i,j,k)/quant-V3d(.5,.5,.5));
             // v=V3d::rotate(v,V3d(0,1,0),rot);
             // v=V3d::rotate(v,V3d(1,0,0),elev);
             v=m1*v;
             v=m2*v;
             V3d u=v+V3d(.02,0,0);
             int x,y,rx,dx;
             PPgetscrpos(v,&x,&y);
             PPgetscrpos(u,&rx,&dx);
             dx=rx-x;
             circle(b,x,y,dx,makecol(c.x,c.y,c.z));
           }
         }
       }
     }
     blit(b,screen,0,0,0,0,winwid,winhei);
     if (key[KEY_LEFT])
       rot-=rotspeed;
     if (key[KEY_RIGHT])
       rot+=rotspeed;
     if (key[KEY_UP])
       elev-=rotspeed;
     if (key[KEY_DOWN])
       elev+=rotspeed;
     if (key[KEY_Z])
       smallize=smallize*1.2;
     if (key[KEY_X])
       smallize=smallize/1.2;
   } while (!key[KEY_ESC]);
   #endif
 }
Beispiel #23
0
void main() {
  allegrosetup(scrwid,scrhei);
  psychedelicpalette();
  mypalette(255,0,0,0);
  V3d pos=V3d(0,0,0);
  V3d vel=V3d(0,0,0);
  V3d acc=V3d(0,0,0);
  Ori ori;
  float roll=0;
  float yaw=0;
  JBmp b=JBmp(scrwid,scrhei);
  PPsetup(scrwid,scrhei,4);
  do {
    b.clear(255);
    V3d off=V3d(mymod(pos.x,gjump),mymod(pos.y,gjump),mymod(pos.z,gjump));
    int ioff=-mydiv(pos.x,gjump);
    int joff=-mydiv(pos.y,gjump);
    int koff=-mydiv(pos.z,gjump);
    for (int k=gridsize;k>=-gridsize;k-=gjump)
      for (int i=-gridsize;i<=gridsize;i+=gjump)
        for (int j=-gridsize;j<=gridsize;j+=gjump) {
          int x,y;
          V3d cen=V3d(i,j,k)-off;
          cen=V3d::orientate(cen,ori);
          int c=256.0*mymod(5*mysquare((i-ioff)/gjump)-11*(j-joff)/gjump-7*(k-koff)/gjump,6)/6.0;
          PPgetscrpos(cen,&x,&y);
          b.filledcircle(x,y,0.1*PPgetunit(cen),c);
        }
    b.writetoscreen();
    acc=hang(acc,V3d::origin,0.93,0.02);
    vel=hang(vel,V3d::origin,0.93,0)+acc;
    pos=pos+vel;
    roll=hang(roll,0,0.92,0.01);
    yaw=hang(yaw,0,0.92,0.01);
    ori.roll(roll);
    ori.yaw(yaw);
  } while (!key[KEY_ESC]);
}
Beispiel #24
0
float getdepth(int i,int j) {
//  printf("gd\n");
  if (!rend->inmap(i,j))
    return back;
  if (rend->pos[i][j]==crazy) {
        // Shoot ray into image
        V3d near=V3d((i-scrhei/2)*2.0/scrhei,(j-scrhei/2)*2.0/scrhei,-2);
        V3d far=V3d(near.x*2.0,near.y*2.0,2.0);
        rend->pos[i][j]=back;
        V3d next,last=near;
        bool lastin=(getpotentialfor(near)<lessthan);
        
        for (int k=1;k<steps;k++) {
          float dk=(float)k/(float)steps;
          next=near*(1.0-dk)+far*dk;
          if ((getpotentialfor(next)<lessthan)!=lastin) {
            rend->pos[i][j]=searchline(last,next,!lastin).z;
            break;
          }
          last=next;
        }
  }
  return rend->pos[i][j];
}
Beispiel #25
0
void main() {

  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  _farsetsel(screen->seg);
  PALETTE pal;
  get_palette(pal);

  randomise(0.456);
  for (int i=0;i<20;i++) {
    S s=S(V3d::randomvolume(1),0,0);
    S v=S(V3d(0,0,0),0,0);
    xs+s;
    xvs+v;
  }
  for (int rndloop=0;rndloop<100;rndloop++) {
    for (int i=0;i<xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
  }
  do {

    rend->clear(crazy);

    for (int i=0;i<scrhei;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        fillsquare(i,j,jump,jump);
      }
      b->writetoscreen();
    }

    for (int lkg=0;lkg<1;lkg++)
    for (int i=1;i<=xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
    b->writefile(getnextfilename("bmp"));
  } while (!key[KEY_ESC]);
}
Beispiel #26
0
//------------------------------------------------------------------------------
// TriMesh implementation
bool TriMesh::loadFile(QString fileName, size_t /*maxVertexCount*/)
{
    // maxVertexCount is ignored - not sure there's anything useful we can do
    // to respect it when loading a mesh...
    PlyLoadInfo info;
    if (!loadPlyFile(fileName, info))
        return false;
    setFileName(fileName);
    V3d offset = V3d(info.offset[0], info.offset[1], info.offset[2]);
    setOffset(offset);
    setCentroid(getCentroid(offset, info.verts));
    setBoundingBox(getBoundingBox(offset, info.verts));
    m_verts.swap(info.verts);
    m_colors.swap(info.colors);
    m_faces.swap(info.faces);
    m_edges.swap(info.edges);
    //makeSmoothNormals(m_normals, m_verts, m_faces);
    //makeEdges(m_edges, m_faces);
    return true;
}
Beispiel #27
0
 float RGBHistogram::variance() {
   long c=0;
   float ax=0,ay=0,az=0;
   for (int i=0;i<quant;i++)
   for (int j=0;j<quant;j++)
   for (int k=0;k<quant;k++) {
     int r=rgb[i][j][k];
     c=c+r;
     ax=ax+r*i;
     ay=ay+r*j;
     az=az+r*k;
   }
   ax=ax/(float)c;
   ay=ay/(float)c;
   az=az/(float)c;
   float var=0;
   for (int i=0;i<quant;i++)
   for (int j=0;j<quant;j++)
   for (int k=0;k<quant;k++) {
     var=var+rgb[i][j][k]*mysquare((V3d((float)i-ax,(float)j-ay,(float)k-az)).mod());
   }
   var=var/(float)quant/(float)quant/(float)quant/c;
   return var;
 }
Beispiel #28
0
int main(int argc,String *argv) {
  ArgParser a=ArgParser(argc,argv);
  String imagefile=a.getarg("Image file");
  String boolfile=a.getarg("Binary file");
  a.done();
  
  RGBmp *p=RGBmp::readfile(imagefile);
  Map2d<float> *b=Map2d<float>::readfile(boolfile);
//  rad=0;
//  Map2d<float> *gs=p->getgreyscale();
//  gs=gs->smoothed(rad);

  printf("Picture %i %i clipped mask %i %i\n",p->width,p->height,b->width,b->height);
  
  // Find regions, keep largest region, and split
  List< Region * > *l=b->getrealregions();
  printf("Got %i regions.\n",l->len);

/*  int larea=-1;
  int largest=-1;
  for (int i=1;i<=l->len;i++) {
    printf("*");
    if (l->num(i)->area()>larea) {
      larea=l->num(i)->area();
      largest=i;
    }
  }*/

  OrderedList< Region * > ol;
  for (int i=1;i<=l->len;i++)
    ol.add(l->p2num(i),l->num(i)->area());
  
  pos=V3d(1,1,0);
  ori=Ori::indir(V3d(0,0,1)-V3d(1,1,0));

  for (int i=ol.len;i>=1;i--) {

  Region *vs=ol.num(i);
  printf("Recovered largest.\n");

  printf("Generating points...\n");
  octree->clear();
    List<V2d> ps=*vs->getlist();
    for (int i=1;i<=ps.len;i++) {
      int x=ps.num(i).x;
      int y=ps.num(i).y;
      myRGB r=p->getpos(x,y);
      octree->add(V3d((float)r.r/128.0,(float)r.g/128.0,(float)r.b/128.0));
    }

  for (int i=0;i<=100;i++) {
    octree->add(V3d((float)i*255.0/100.0/128.0,0,0));
    octree->add(V3d(0,(float)i*255.0/100.0/128.0,0));
    octree->add(V3d(0,0,(float)i*255.0/100.0/128.0));
  }

  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  PPsetup(scrwid,scrhei,2.0);

  visengfly();

  if (key[KEY_ESC])
    break;

  }

  allegroexit();
  
}
Beispiel #29
0
void main() {
  int scrwid=320;
  int scrhei=200;
  int indent=(scrwid-scrhei)/2;
  float cenx=0;
  float ceny=0;
  float wid=1.0;
  float hei=1.0;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  float front=-1.0;
  float back=1.0;
  float scale=2.0/(2.0*front);
  float crazy=0.1234567;
  int steps=1000;
  int jump=1;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
  Map2d<float> *map=new Map2d<float>(scrhei,scrhei);
  current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5));
  do {
    current=current*Quaternion(0.99,0,0,0)+Quaternion(floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05));
    
    float dslice=floatrnd(-.3,.3);
    current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5));
  current=*new Quaternion(-0.488193901,0.572800587,0,0);
    
    for (int i=0;i<scrhei;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        // b->setpixelud(indent+i,j,255);
        // b->writetoscreen();
        int col=0;
        V3d tmpnear=V3d(left+2.0*wid*i/(float)scrhei,top+2.0*hei*j/(float)scrhei,front);
        V3d tmpfar=V3d(tmpnear.x*2.0,tmpnear.y*2.0,back);
        tmpnear=V3d::rotate(tmpnear,V3d(0,1,0),rotation);
        tmpfar=V3d::rotate(tmpfar,V3d(0,1,0),rotation);
        tmpnear=V3d::rotate(tmpnear,V3d(1,0,0),elevation);
        tmpfar=V3d::rotate(tmpfar,V3d(1,0,0),elevation);
        Quaternion near=Quaternion(tmpnear.x,tmpnear.y,tmpnear.z,dslice);
        Quaternion far=Quaternion(tmpfar.x,tmpfar.y,tmpfar.z,dslice);
        map->pos[i][j]=crazy;
        Quaternion last=near-(far-near);
        for (int k=0;k<steps;k++) {
          float dk=(float)k/(float)steps;
          Quaternion next=near*(1.0-dk)+far*dk;
          if (julquat(next)==0) {
            Quaternion res=searchline(last,next);
            // col=255.0*(1.0-(res.c-front)/(forget-front));
            map->pos[i][j]=res.c;
            break;
          }
          last=next;
        }
        if (i>=jump && j>=jump) {
          if (map->pos[i-jump][j-jump]==crazy || map->pos[i-jump][j]==crazy || map->pos[i][j-jump]==crazy)
            col=0;
          else {
            float diff=2.0*map->pos[i-jump][j-jump]-map->pos[i-jump][j]-map->pos[i][j-jump];
            col=chop(128.0+diff*1600.0,0,255);
          }
          for (int x=0;x<jump;x++) {
            for (int y=0;y<jump;y++) {
              b->setpixel(indent+i+x,j+y,col);
            }
          }
        }
        if (key[KEY_SPACE])
          exit(0);
      }
      b->writetoscreen();
    }
    PALETTE pal;
    get_palette(pal);
    save_bitmap(getnextfilename("bmp"),screen,pal);
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Beispiel #30
0
bool PointArray::pickVertex(const V3d& cameraPos,
                            const V3d& rayOrigin,
                            const V3d& rayDirection,
                            const double longitudinalScale,
                            V3d& pickedVertex,
                            double* distance,
                            std::string* info) const
{
    if (m_npoints == 0)
        return false;

    const V3d rayOriginOffset = rayOrigin - offset();

    double rClosest = DBL_MAX;
    size_t idx = 0;

    std::vector<const OctreeNode*> nodeStack;
    nodeStack.push_back(m_rootNode.get());
    while (!nodeStack.empty())
    {
        const OctreeNode* node = nodeStack.back();
        nodeStack.pop_back();

        if(!node->rayPassesNearOrThrough(rayOriginOffset, rayDirection))
            continue;

        if (!node->isLeaf())
        {
            for (int i = 0; i < 8; ++i)
            {
                OctreeNode* n = node->children[i];
                if (n)
                    nodeStack.push_back(n);
            }
            continue;
        }

        double thisRClosest;
        size_t thisIdx = node->closestPoint(m_P, rayOriginOffset, rayDirection, longitudinalScale, thisRClosest);
        if(thisRClosest < rClosest)
        {
            rClosest = thisRClosest;
            idx = thisIdx;
        }
    }

    if(rClosest == DBL_MAX)
        return false;

    *distance = rClosest;
    pickedVertex = V3d(m_P[idx]) + offset();

    if (info)
    {
        // Format all selected point attributes for user display
        // TODO: Make the type dispatch machinary generic & put in TypeSpec
        std::ostringstream out;
        for (size_t i = 0; i < m_fields.size(); ++i)
        {
            const GeomField& field = m_fields[i];
            tfm::format(out, "  %s = ", field.name);
            if (field.name == "position")
            {
                // Special case for position, since it has an associated offset
                const float* p = (float*)(field.data.get() + idx*field.spec.size());
                tfm::format(out, "%.3f %.3f %.3f\n",
                            p[0] + offset().x, p[1] + offset().y, p[2] + offset().z);
                continue;
            }
            for (int j = 0; j < field.spec.count; ++j)
            {
                const char* data = field.data.get() + idx*field.spec.size() + j*field.spec.elsize;
                switch (field.spec.type)
                {
                    case TypeSpec::Float:
                        switch (field.spec.elsize)
                        {
                            case 4:  tfm::format(out, "%g", *(float*)data);  break;
                            case 8:  tfm::format(out, "%g", *(double*)data); break;
                            default: tfm::format(out, "?"); break;
                        }
                        break;
                    case TypeSpec::Int:
                        switch (field.spec.elsize)
                        {
                            case 1:  tfm::format(out, "%d", *(int8_t*)data);  break;
                            case 2:  tfm::format(out, "%d", *(int16_t*)data); break;
                            case 4:  tfm::format(out, "%d", *(int32_t*)data); break;
                            case 8:  tfm::format(out, "%d", *(int64_t*)data); break;
                            default: tfm::format(out, "?"); break;
                        }
                        break;
                    case TypeSpec::Uint:
                        switch (field.spec.elsize)
                        {
                            case 1:  tfm::format(out, "%d", *(uint8_t*)data);  break;
                            case 2:  tfm::format(out, "%d", *(uint16_t*)data); break;
                            case 4:  tfm::format(out, "%d", *(uint32_t*)data); break;
                            case 8:  tfm::format(out, "%d", *(uint64_t*)data); break;
                            default: tfm::format(out, "?"); break;
                        }
                        break;
                    default:
                        tfm::format(out, "unknown");
                }
                if (j < field.spec.count - 1)
                    tfm::format(out, " ");
                else
                    tfm::format(out, "\n");
            }
        }
        *info = out.str();
    }

    return true;
}