Beispiel #1
0
Component CaseFactory::constructBase(double innerHeight, int extensionDirection)
{
    // The walls and the floor are made by subtracting two cuboids.
    Component base = Cube(board.size[0] + 2*outset(), board.size[1] + 2*outset(), innerHeight + floors, false)
            .translatedCopy(-outset(), -outset(), 0);
    Component baseInner = Cube(board.size[0] + 2*space,  board.size[1] + 2*space,  innerHeight + eps, false)
            .translatedCopy(-space, -space, floors);
    base = base - baseInner;

    // Extension (half width wall goes a bit higher, either the inner or the outer half depending on extensionDirection)
    double off_ext_outer = walls * (extensionDirection ? 1.00 : 0.45) + space;
    double off_ext_inner = walls * (extensionDirection ? 0.55 : 0.00) + space;
    Component extension = Cube(board.size[0] + 2*off_ext_outer, board.size[1] + 2*off_ext_outer, extensionHeight() + eps, false)
            .translatedCopy(-off_ext_outer, -off_ext_outer, innerHeight + floors - eps);
    Component extensionInner = Cube(board.size[0] + 2*off_ext_inner, board.size[1] + 2*off_ext_inner, extensionHeight() + 3 * eps, false)
            .translatedCopy(-off_ext_inner, -off_ext_inner, innerHeight + floors - 2 * eps);
    extension = extension - extensionInner;

    // Combine both
    return base + extension;
}
Beispiel #2
0
//--------------------------------------------------------------
void testApp::setup(){
	ofSetFrameRate(70);

	fenster->setFPS(1);
	fenster->setBounds(100, 100, ofGetWidth()/10, ofGetHeight()/10);
	bTexInit = false;

	ofBackground(255, 255, 255);
	for (int i=0; i<400; i++) {
		cubes.push_back(Cube());
	}
}
Beispiel #3
0
TempOctree::TempOctree(char* fileNameTemplate,unsigned int sMaxNumPointsPerNode,LidarPoint* points,size_t numPoints)
	:tempFileName(new char[strlen(fileNameTemplate)+1]),
	 file(createTempFile(fileNameTemplate),File::ReadWrite),
	 maxNumPointsPerNode(sMaxNumPointsPerNode),
	 pointBbox(Box::empty),
	 writerThreadRun(true),writerThread(this,&TempOctree::writerThreadMethod)
	{
	/* Save the temporary file name: */
	strcpy(tempFileName,fileNameTemplate);
	
	/* Immediately unlink the temporary file; it will stay alive until the file handle is closed: */
	unlink(tempFileName);
	
	/* Calculate the point set's bounding box: */
	for(unsigned int i=0;i<numPoints;++i)
		pointBbox.addPoint(points[i]);
	
	/* Extend the bounding box by a small delta to include all points in a half-open box: */
	Point newMax=pointBbox.max;
	for(int i=0;i<3;++i)
		{
		Scalar delta=Scalar(1);
		if(newMax[i]+delta!=newMax[i])
			{
			while(newMax[i]+(delta*Scalar(0.5))!=newMax[i])
				delta*=Scalar(0.5);
			}
		else
			{
			while(newMax[i]+delta==newMax[i])
				delta*=Scalar(2);
			}
		newMax[i]+=delta;
		}
	pointBbox=Box(pointBbox.min,newMax);
	
	/* Set the root's domain to contain all points: */
	root.domain=Cube(pointBbox);
	
	/* Create the root node's subtree: */
	root.numPoints=numPoints;
	root.points=points;
	createSubTree(root);
	
	/* Wait until the octree file is finished: */
	writerThreadRun=false;
	writeQueueCond.signal();
	writerThread.join();
	file.flush();
	}
Beispiel #4
0
/*
============
idTraceModel::PolygonIntegrals
============
*/
void idTraceModel::PolygonIntegrals( int polyNum, int a, int b, int c, polygonIntegrals_t &integrals ) const {
	projectionIntegrals_t pi;
	idVec3 n;
	float w;
	float k1, k2, k3, k4;

	ProjectionIntegrals( polyNum, a, b, pi );

	n = polys[polyNum].normal;
	w = -polys[polyNum].dist;
	k1 = 1 / n[c];
	k2 = k1 * k1;
	k3 = k2 * k1;
	k4 = k3 * k1;

	integrals.Fa = k1 * pi.Pa;
	integrals.Fb = k1 * pi.Pb;
	integrals.Fc = -k2 * (n[a] * pi.Pa + n[b] * pi.Pb + w * pi.P1);

	integrals.Faa = k1 * pi.Paa;
	integrals.Fbb = k1 * pi.Pbb;
	integrals.Fcc = k3 * (Square(n[a]) * pi.Paa + 2 * n[a] * n[b] * pi.Pab + Square(n[b]) * pi.Pbb
			+ w * (2 * (n[a] * pi.Pa + n[b] * pi.Pb) + w * pi.P1));

	integrals.Faaa = k1 * pi.Paaa;
	integrals.Fbbb = k1 * pi.Pbbb;
	integrals.Fccc = -k4 * (Cube(n[a]) * pi.Paaa + 3 * Square(n[a]) * n[b] * pi.Paab 
			+ 3 * n[a] * Square(n[b]) * pi.Pabb + Cube(n[b]) * pi.Pbbb
			+ 3 * w * (Square(n[a]) * pi.Paa + 2 * n[a] * n[b] * pi.Pab + Square(n[b]) * pi.Pbb)
			+ w * w * (3 * (n[a] * pi.Pa + n[b] * pi.Pb) + w * pi.P1));

	integrals.Faab = k1 * pi.Paab;
	integrals.Fbbc = -k2 * (n[a] * pi.Pabb + n[b] * pi.Pbbb + w * pi.Pbb);
	integrals.Fcca = k3 * (Square(n[a]) * pi.Paaa + 2 * n[a] * n[b] * pi.Paab + Square(n[b]) * pi.Pabb
			+ w * (2 * (n[a] * pi.Paa + n[b] * pi.Pab) + w * pi.Pa));
}
Beispiel #5
0
std::list<Cube> Cube::Range( int rad ) const {
  Cube center( *this );
  std::list<Cube> range;
  
  int dx, dy, dz, lim;
  for( dx = -rad; dx <= rad; dx++ ){
    lim = std::min( rad, -dx+rad );
    for( dy = std::max( -rad, -dx-rad ); dy <= lim; dy++ ){
      dz = -dx - dy;
      if( dx != 0 || dy != 0 ) // No se incluye el centro
	range.push_back( center + Cube(dx,dy,dz) );
    }
  }
  return range;
}
void TempOctree::createSubTree(TempOctree::Node& node,PointePoint* points,size_t numPoints)
	{
	/* Check if the number of points is smaller than the maximum: */
	if(numPoints<=size_t(maxNumPointsPerNode))
		{
		/* Make this node a leaf and write the points to the temporary file: */
		node.numPoints=numPoints;
		node.pointsOffset=file.tell();
		file.write(points,numPoints);
		}
	else
		{
		/* Make this node an interior node: */
		node.numPoints=numPoints;
		node.pointsOffset=0;
		
		/* Split the point array between the node's children: */
		PointePoint* childPoints[8];
		size_t childNumPoints[8];
		childPoints[0]=points;
		childNumPoints[0]=numPoints;
		
		/* Split the point set along the three dimensions, according to the node's center: */
		int numSplits=1;
		int splitSize=4;
		for(int i=2;i>=0;--i,numSplits<<=1,splitSize>>=1)
			{
			int leftIndex=0;
			for(int j=0;j<numSplits;++j,leftIndex+=splitSize*2)
				{
				size_t leftNumPoints=splitPoints(childPoints[leftIndex],childNumPoints[leftIndex],i,node.domain.getCenter(i));
				childPoints[leftIndex+splitSize]=childPoints[leftIndex]+leftNumPoints;
				childNumPoints[leftIndex+splitSize]=childNumPoints[leftIndex]-leftNumPoints;
				childNumPoints[leftIndex]=leftNumPoints;
				}
			}
		
		/* Initialize the child nodes and create their subtrees: */
		node.children=new Node[8];
		for(int childIndex=0;childIndex<8;++childIndex)
			{
			Node& child=node.children[childIndex];
			child.domain=Cube(node.domain,childIndex);
			createSubTree(node.children[childIndex],childPoints[childIndex],childNumPoints[childIndex]);
			}
		}
	}
Beispiel #7
0
void TempOctree::createSubTree(TempOctree::Node& node)
	{
	/* Check if the number of points is smaller than the maximum: */
	if(node.numPoints<=size_t(maxNumPointsPerNode))
		{
		/* Queue up this node to be written to the octree file: */
		Threads::MutexCond::Lock writeQueueLock(writeQueueCond);
		writeQueue.push_back(&node);
		writeQueueCond.signal();
		}
	else
		{
		/* Make this node an interior node: */
		node.children=new Node[8];
		
		/* Split the point array between the node's children: */
		node.children[0].numPoints=node.numPoints;
		node.children[0].points=node.points;
		
		/* Split the point set along the three dimensions, according to the node's center: */
		int numSplits=1;
		int splitSize=4;
		for(int i=2;i>=0;--i,numSplits<<=1,splitSize>>=1)
			{
			int leftIndex=0;
			for(int j=0;j<numSplits;++j,leftIndex+=splitSize*2)
				{
				size_t leftNumPoints=splitPoints(node.children[leftIndex].points,node.children[leftIndex].numPoints,i,node.domain.getCenter(i));
				node.children[leftIndex+splitSize].points=node.children[leftIndex].points+leftNumPoints;
				node.children[leftIndex+splitSize].numPoints=node.children[leftIndex].numPoints-leftNumPoints;
				node.children[leftIndex].numPoints=leftNumPoints;
				}
			}
		
		/* Create the node's children's subtrees: */
		for(int childIndex=0;childIndex<8;++childIndex)
			{
			Node& child=node.children[childIndex];
			child.domain=Cube(node.domain,childIndex);
			createSubTree(node.children[childIndex]);
			}
		
		node.points=0;
		}
	}
Beispiel #8
0
// Added by: Anthony W. Rainer <*****@*****.**>
// Modified by: Bogdan Vacaliuc <*****@*****.**> to center the cavities in the posts
Component CaseFactory::addCavityForNut(const Component & component, double partOuterHeight, const Point & pos, HoleNutDescription holeNut )
{
    // The "radius" of the outer cuboid shaped enclosure for the screw.
    double ro = holesSize / 2.0 + holesWalls;
    double ri = holeNut.nutWidth / 2;
    double sx_adj = 0.0;
    double sy_adj = 0.0;
    double posx_adj = 0.0;
    double posy_adj = 0.0;
    switch(holeNut.side) {
	    case East:
		    //posx_adj = ro - ri;
		    posy_adj = ro - ri;         // was: ri / 2
		    sx_adj = 2*(ro - ri) + 0.1; // was: ro + 0.1
		    posx_adj = +1*(sx_adj / 2); // was: ro - ri
		    break;
	    case West:
		    //posx_adj = -ro + ri;
		    posy_adj = ro - ri;         // was: ri / 2
		    sx_adj = 2*(ro - ri) + 0.1; // was: ro + 0.1
		    posx_adj = -1*(sx_adj / 2); // was: -ro + ri
		    break;
	    case North:
		    //posy_adj = ro - ri;
		    posx_adj = ro - ri;         // was: ri / 2
		    sy_adj = 2*(ro - ri) + 0.1; // was: ro + 0.1
		    posy_adj = +1*(sy_adj / 2); // was: ro - ri
		    break;
	    case South:
		    //posy_adj = -ro + ri;
		    posx_adj = ro - ri;         // was: ri / 2
		    sy_adj = 2*(ro - ri) + 0.1; // was: ro + 0.1
		    posy_adj = -1*(sy_adj / 2); // was: -ro + ri
		    break;
	    default:
		    break;
    }

    // Subtract from component: nut cavity cuboid
    Component subtract = Cube(holeNut.nutWidth+sx_adj, holeNut.nutWidth+sy_adj, holeNut.nutThickness, false)
            .translatedCopy((pos.x - ro)+posx_adj, (pos.y - ro)+posy_adj, holeNut.nutCavityHeightFromBottom);

    return component - subtract;
}
Beispiel #9
0
Cube Cube::setCube(Vec4 min, Vec4 max)
{
    Cube cube = Cube();
    cube.transform.setIdentity();
    Matrix4x4 t;
    t.setIdentity();
    Vec4 center = (max+min)/2.0;

    //float s = (min-max).module()*sqrt(3.0)/3.0; //escala
    //this->transform.setIdentity();
    float diag = (max - center).module();
    float h    = (max - Vec4(max.x(),center.y(),max.z())).module(); //eixo y
    float c    = (Vec4(max.x(),center.y(),center.z())-Vec4(max.x(),center.y(),max.z())).module(); //eixo z
    float l    = (center - Vec4(max.x(),center.y(),center.z())).module();

    t.scale(2*l,2*h,2*c);
    t.translate(center);
    cube.setTransform(t);
    return cube;

}
Beispiel #10
0
HBB::HBB(std::vector<Object*> objects, int axis)
{
    std::vector<Object*> copy;
    for(unsigned int i=0; i<objects.size();i++) copy.push_back(objects.at(i));
    int n = copy.size();
    if (n==1){
        left = copy.at(0);
        right = NULL;
        box = Cube(left->getMin(),left->getMax());
        left_node = NULL;
        right_node = NULL;
    }
    else if(n==2){
        left = copy.at(0);
        right = copy.at(1);
        box = box.combineCube(left->boundingBox(),right->boundingBox());
        left_node = NULL;
        right_node = NULL;
    }else{
        //ordenar segundo o eixo
        std::vector<Object*> sort = sortObjects(copy,axis);
        for(unsigned int i=0; i<sort.size();i++) copy.at(i) = sort.at(i);

        std::vector<Object*> l;
        std::vector<Object*> r;
        for (int i=0;i<n/2;i++){
            l.push_back(copy.at(i));
        }
        for (int i=n/2;i<n;i++){
            r.push_back(copy.at(i));
        }

        left_node  = new HBB(l,(axis+1)%3);
        right_node = new HBB(r,(axis+1)%3);
        left = NULL;
        right = NULL;
        box = box.combineCube(left_node->box,right_node->box);
    }

}
Beispiel #11
0
void ComputeForcesDipoleR ()
{
  VecR dr, w;
  real a1, a2, a3, alpha2, d, irPi, rr, rrCut, rri, sr1, sr2, ss, t;
  int j1, j2, n;

  rrCut = Sqr (0.5 * region.x);
  irPi = 1. / sqrt (M_PI);
  alpha2 = Sqr (alpha);
  DO_MOL VZero (mol[n].sa);
  for (j1 = 0; j1 < nMol - 1; j1 ++) {
    for (j2 = j1 + 1; j2 < nMol; j2 ++) {
      VSub (dr, mol[j1].r, mol[j2].r);
      VWrapAll (dr);
      rr = VLenSq (dr);
      if (rr < rrCut) {
        d = sqrt (rr);
        rri = 1. / rr;
        t = 2. * dipoleInt * alpha * exp (- alpha2 * rr) * rri * irPi;
        a1 = dipoleInt * erfc (alpha * d) * rri / d + t;
        a2 = 3. * a1 * rri + 2. * alpha2 * t;
        a3 = 5. * a2 * rri + 4. * Sqr (alpha2) * t;
        ss = VDot (mol[j1].s, mol[j2].s);
        sr1 = VDot (mol[j1].s, dr);
        sr2 = VDot (mol[j2].s, dr);
        VSSAdd (w, sr2, mol[j1].s, sr1, mol[j2].s);
        t = (a2 * ss - a3 * sr1 * sr2);
        VSSAdd (w, t, dr, a2, w);
        VVAdd (mol[j1].ra, w);
        VVSub (mol[j2].ra, w);
        VVSAdd (mol[j1].sa, - a1, mol[j2].s);
        VVSAdd (mol[j1].sa, a2 * sr2, dr);
        VVSAdd (mol[j2].sa, - a1, mol[j1].s);
        VVSAdd (mol[j2].sa, a2 * sr1, dr);
        uSum += a1 * ss - a2 * sr1 * sr2;
      }
    }
  }
  uSum -= 2. * dipoleInt * Cube (alpha) * nMol * irPi / 3.;
}
Beispiel #12
0
/*
 *  Draw scene
 *    light>0  lit colors
 *    light<0  shaded colors
 *    light=0  shadow volumes
 */
void Scene(int Light)
{
   int k;  // Counters used to draw floor
 
   //  Set global light switch (used in DrawPolyShadow)
   light = Light;

   //  Texture (pi.bmp)
   glBindTexture(GL_TEXTURE_2D,tex2d[2]);
   //  Enable textures if not drawing shadow volumes
   if (light) glEnable(GL_TEXTURE_2D);

   //  Draw objects         x    y   z          th,ph    dims   
   if (obj&0x01)     Cube(-0.8,+0.8,0.0 , -0.25*zh, 0  , 0.3    );
   if (obj&0x02) Cylinder(+0.8,+0.5,0.0 ,   0.5*zh,zh  , 0.2,0.5);
   if (obj&0x04)    Torus(+0.5,-0.8,0.0 ,        0,zh  , 0.5,0.2);
   if (obj&0x08)   Teapot(-0.5,-0.5,0.0 ,     2*zh, 0  , 0.25   );

   //  Disable textures
   if (light) glDisable(GL_TEXTURE_2D);

   //  The floor, ceiling and walls don't cast a shadow, so bail here
   if (!light) return;

   //  Always enable textures
   glEnable(GL_TEXTURE_2D);
   Color(1,1,1);

   //  Water texture for floor and ceiling
   glBindTexture(GL_TEXTURE_2D,tex2d[0]);
   for (k=-1;k<=box;k+=2)
      Wall(0,0,0, 0,90*k , 8,8,box?6:2 , 4);
   //  Crate texture for walls
   glBindTexture(GL_TEXTURE_2D,tex2d[1]);
   for (k=0;k<4*box;k++)
      Wall(0,0,0, 90*k,0 , 8,box?6:2,8 , 1);

   //  Disable textures
   glDisable(GL_TEXTURE_2D);
}
Beispiel #13
0
void EvalRdf ()
{
  VecR dr;
  real deltaR, normFac, rr, sr1, sr2, ss;
  int j1, j2, k, n;

  if (countRdf == 0) {
    for (k = 0; k < 3; k ++) {
      for (n = 0; n < sizeHistRdf; n ++) histRdf[k][n] = 0.;
    }
  }
  deltaR = rangeRdf / sizeHistRdf;
  for (j1 = 0; j1 < nMol - 1; j1 ++) {
    for (j2 = j1 + 1; j2 < nMol; j2 ++) {
      VSub (dr, mol[j1].r, mol[j2].r);
      VWrapAll (dr);
      rr = VLenSq (dr);
      if (rr < Sqr (rangeRdf)) {
        ss = VDot (mol[j1].s, mol[j2].s);
        sr1 = VDot (mol[j1].s, dr);
        sr2 = VDot (mol[j2].s, dr);
        n = sqrt (rr) / deltaR;
        ++ histRdf[0][n];
        histRdf[1][n] += ss;
        histRdf[2][n] += 3. * sr1 * sr2 / rr - ss;
      }
    }
  }
  ++ countRdf;
  if (countRdf == limitRdf) {
    normFac = VProd (region) / (2. * M_PI * Cube (deltaR) *
       Sqr (nMol) * countRdf);
    for (k = 0; k < 3; k ++) {
      for (n = 0; n < sizeHistRdf; n ++)
         histRdf[k][n] *= normFac / Sqr (n - 0.5);
    }
    PrintRdf (stdout);
    countRdf = 0;
  }
}
TempOctree::TempOctree(char* fileNameTemplate,unsigned int sMaxNumPointsPerNode,PointePoint* points,size_t numPoints)
	:tempFileName(new char[strlen(fileNameTemplate)+1]),
	 file(mkstemp(fileNameTemplate),"w+b",File::DontCare),
	 maxNumPointsPerNode(sMaxNumPointsPerNode),
	 pointBbox(Box::empty)
	{
	/* Save the temporary file name: */
	strcpy(tempFileName,fileNameTemplate);
	
	/* Calculate the point set's bounding box: */
	for(unsigned int i=0;i<numPoints;++i)
		pointBbox.addPoint(points[i]);
	
	/* Extend the bounding box by a small delta to include all points in a half-open box: */
	Point newMax=pointBbox.max;
	for(int i=0;i<3;++i)
		{
		Scalar delta=Scalar(1);
		if(newMax[i]+delta!=newMax[i])
			{
			while(newMax[i]+(delta*Scalar(0.5))!=newMax[i])
				delta*=Scalar(0.5);
			}
		else
			{
			while(newMax[i]+delta==newMax[i])
				delta*=Scalar(2);
			}
		newMax[i]+=delta;
		}
	pointBbox=Box(pointBbox.min,newMax);
	
	/* Set the root's domain to contain all points: */
	root.domain=Cube(pointBbox);
	
	/* Create the root node's subtree: */
	createSubTree(root,points,numPoints);
	}
Beispiel #15
0
Component FutabaS3003::build()
{
        Component joint = Cylinder(4.25,4,30,true);
        Component hole_servo = Cylinder(1.8,1.8,15.0,20);
        Component hole_servo_fill = Cylinder(1.8,1.8,36.6,20,false);

        Component servo = RoundedTablet(20.5,41.5,36.6,1,true,true,true,true,100,false)
                          + getCrown(_type,3,true).translate(10.5,10.5,42.1)
                          + joint.translate(10.5,10.5,38.6)
                          + RoundedTablet(20,9,3,1,true,true,true,true,50,false).translate(0.25,-8,26.6)
                          + RoundedTablet(20,9,3,1,true,true,true,true,50,false).translate(0.25,40.5,26.6);




        //fill the holes of the screws?
        if(!_fill_hole)
                        servo = servo
                                - hole_servo.translatedCopy(5.25,-4.25,24)
                                - hole_servo.translatedCopy(15.25,-4.25,24)
                                - hole_servo.translatedCopy(5.25,45.75,24)
                                - hole_servo.translatedCopy(15.25,45.75,24);
        else
                        servo = servo //+ Cube(5,2,36.5,false).translate(7.75,41.5,0)
                                + hole_servo_fill.translatedCopy(5.25,-4.25,0)
                                + hole_servo_fill.translatedCopy(15.25,-4.25,0)
                                + hole_servo_fill.translatedCopy(5.25,45.75,0)
                                + hole_servo_fill.translatedCopy(15.25,45.75,0);

		  //leave space for inserting the cable
		  if (_cable_hole){
				servo = servo + Cube(5,2,3,false).translate(7.75,41.5,0);
		  }

        servo.color(0.3,0.3,0.3);

	return servo;
}
Object* Primitives::Sphere(int iSegments, float fRadius)
{
	Object* object = Cube(iSegments, fRadius);

	for (int i = 0; i < object->nrVertices; i++)
	{
		float x = object->vertex[i].x;
		float y = object->vertex[i].y;
		float z = object->vertex[i].z;

		float l = sqrt((x * x) + (y * y) + (z * z));

		x = (x / l) * fRadius;
		y = (y / l) * fRadius;
		z = (z / l) * fRadius;

		object->vertex[i].x = x;
		object->vertex[i].y = y;
		object->vertex[i].z = z;
	}

	return object;
}
Beispiel #17
0
void TreeGeneratorCanvas::Setup()
{
	SceneManager* sceneMgr = gEngine->GetSceneManager();

	D3DVIEWPORT9 viewPort = gEngine->GetDriver()->GetViewPort(swapChainIndex);
	sceneMgr->CreateExtraCamera(Vector3(0, 0, -10.0f), Vector3::Zero,
		PI/3, (float)viewPort.Width / (float)viewPort.Height, 0.1f, 1000.0f);

	Camera* extraCamera = sceneMgr->GetExtraCamera();

	HoverCameraController* hoverCameraController = New HoverCameraController(5.0f, 20.0f, -4*PI/9, 4*PI/9, 2.0f, 100.0f);
	extraCamera->SetCameraController(hoverCameraController);

	Cube* cubeGeo = New Cube(L"cubeGeo1");
	gEngine->GetGeometryManager()->AddGeometry(cubeGeo);

	cubeGeo->CalculateTBN();
	cubeGeo->BuildGeometry(XYZ_UV_TBN);

	mCube = New ModelNode(L"cube", NULL, cubeGeo, gEngine->GetMaterialManager()->GetDefaultFlatMtl());

	mTree = New Tree();
}
Beispiel #18
0
#include "beta-cube-library/beta-cube-library.h"

Cube cube = Cube();

void setup()
{
  cube.begin();
  cube.background(black);
}

void loop()
{
  cube.setVoxel(3,3,3,red);
  cube.show();
  delay(500);
  cube.background(black);
  cube.show();
  delay(500);
}
Beispiel #19
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Select shader (0 => no shader)
   glUseProgram(shader[mode]);
   if (mode>0)
   {
      int id = glGetUniformLocation(shader[mode],"dim");
      if (id>=0) glUniform3f(id,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT),1.0);
   }

   //  Draw the model, teapot or cube
   glPushMatrix();
   glTranslated(x,y,z);
   glColor3f(1,1,0);
   glScaled(size,size,size);
   if (obj==2)
      glCallList(model);
   else if (obj==1)
      glutSolidTeapot(1.0);
   else
      Cube();
   glPopMatrix();

   //  No shader for what follows
   glUseProgram(0);

   //  Draw axes - no lighting from here on
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }

   //  Display parameters
   glWindowPos2i(5,25);
   Print("Angle=%d,%d  Off=%.1f,%.1f,%.1f Dim=%.1f Projection=%s Shader=%s",
     th,ph,x,y,z,dim,proj?"Perpective":"Orthogonal",text[mode]);

   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Beispiel #20
0
void process(unsigned char Con_in){

	if(aktuellerBefehl == 0x00){ //neuen Befehl annehmen
		char nr = Con_in - 'a';

		if(nr == 0){ //sofort ausfuehren
			WholeCube(SET);
			aktuellerBefehl = 0x00;
		}else if( nr == 1){ //b
			WholeCube(CLEAR);
			aktuellerBefehl = 0x00;
		}else if(nr == 2){ //c
			WholeCube(INVERT);
			aktuellerBefehl = 0x00;
		}else if(nr == 22){ //w      -->senden, ob Cube bereit ist, 2 layer anzunehmen
			//nix
			aktuellerBefehl = Con_in;
		}else if(nr == 23){ //x
			//Handshake --> einfaches return
			aktuellerBefehl = 0x00;
		}else if(nr == 24){ //y
			//Reset (TODO)
			aktuellerBefehl = 0x00;
		}else if(nr == 25){ //z
			//Version
			aktuellerBefehl = 0x00;
			//uart_puts_P("LC_FS_V_1.3");
			
		}else if(nr >= 3 && nr <= 21){ //a-u --> Befehl annehmen	
			Con_delBuf();
			
			verbleibendeParameter = Con_arrayParameter[nr];
			aktuellerBefehl = Con_in;								
		}else{
		
			/*char buffer[7];
			uart_puts("falsche Nr.: ");
			itoa( Con_in, buffer, 10);
			uart_puts(buffer);
			uart_puts("\n");*
			
			uart_puts_P("FalBef");*/
		}
	}else{
		if(verbleibendeParameter>0){  //vP = 0 --> es gibt keine Parameter, nicht speichern
			verbleibendeParameter--;
		
			Con_saveData(Con_in);
			
			
		}

		if (verbleibendeParameter == 0){
			unsigned char param[14];
			unsigned char nrBef = aktuellerBefehl - 'a';
			unsigned char a = nrBef%3;
			switch(a){
				case 0: a = SET; break;
				case 1: a = CLEAR; break;
				case 2: a = INVERT; break;
			}
		
			switch(nrBef){
				case 3: case 4: case 5: //d,e,f --> Layer
					param[0] = Con_nextParam() - '0';
					//if(Layer(param[0],a) == ERROR) uart_puts_P("Fehler");
					Layer(param[0],a);
					break;
				case 6: case 7: case 8: //g,h,i --> Pixel
					for(char i = 0; i<3; i++){
						param[i] = Con_nextParam() - '0';
					}
					//if(Pixel(param[0],param[1],param[2],a) == ERROR) uart_puts_P("Fehler");
					Pixel(param[0],param[1],param[2],a);
					break;
				case 9: case 10: case 11: //j,k,l --> Cube
					for(char i = 0; i<6; i++){
						param[i] = Con_nextParam() - '0';
					}
					//if(Cube(param[0],param[1],param[2],param[3],param[4],param[5],a) == ERROR) uart_puts_P("Fehler");
					Cube(param[0],param[1],param[2],param[3],param[4],param[5],a);
					break;
				case 12: case 13: case 14: //m,n,o --> FilledCube
					for(char i = 0; i<6; i++){
						param[i] = Con_nextParam() - '0';
					}
					//if(FilledCube(param[0],param[1],param[2],param[3],param[4],param[5],a) == ERROR) uart_puts_P("Fehler");
					FilledCube(param[0],param[1],param[2],param[3],param[4],param[5],a);
					break;
				case 15: case 16: case 17: //p,q,r --> EdgeCube
					for(char i = 0; i<6; i++){
						param[i] = Con_nextParam() - '0';
					}
					//if(EdgeCube(param[0],param[1],param[2],param[3],param[4],param[5],a) == ERROR) uart_puts_P("Fehler");
					EdgeCube(param[0],param[1],param[2],param[3],param[4],param[5],a);
					break;
				case 18: case 19: case 20: //s,t,u --> Line
					for(char i = 0; i<6; i++){
						param[i] = Con_nextParam() - '0';
					}
					//if(Line(param[0],param[1],param[2],param[3],param[4],param[5],a) == ERROR) uart_puts_P("Fehler");
					Line(param[0],param[1],param[2],param[3],param[4],param[5],a);
					break;
				case 21: //kompletter Wuerfel
					param[0] = Con_nextParam(); 
					char layer_ = param[0]>>4; // 0xF0 --> 0xF sind hier die Daten
					CUBE[layer_][12] = (param[0] & 0x0F); //letzte Bytes setzen (0x0F --> 0xF sind die Daten)
				
					for(char i = 1; i<13; i++){ //ein versetzt
						param[i] = Con_nextParam(); //Hier wirklich daten, keine ascii-codes
						
						CUBE[layer_][i-1] = param[i]; // on beginn an auffuellen (param[0] ueberspringen, da dort layer und letzte bytes
					}

			}
			aktuellerBefehl = 0x00; //nach abschluss befehl auf NULL setzen
			//uart_puts_P("\n");
		}
	}//end if: aktueller befehl
Beispiel #21
0
Component CaseFactory::constructPart(Side whichSide)
{
    // Select parameters depending on which part to build
    auto innerHeight     = (whichSide == BottomSide) ? bottomInnerHeight()        : topInnerHeight();
    auto outerHeight     = (whichSide == BottomSide) ? bottomHeight()             : topHeight();
    auto forbiddenAreas  = (whichSide == BottomSide) ? board.bottomForbiddenAreas          : board.topForbiddenAreas;
    auto ports           = (whichSide == BottomSide) ? board.bottomPorts          : board.topPorts;
    auto wallSupports    = (whichSide == BottomSide) ? board.bottomWallSupports   : board.topWallSupports;
    auto extension       = (whichSide == outerExtensionOnSide) ? ExtensionOutside : ExtensionInside;
    auto screwHoleRadius =((whichSide == screwHeadsOnSide) ? holesAddRadiusLoose : holesAddRadiusTight) + board.holesRadius;
    auto screwHeads      = (whichSide == screwHeadsOnSide);

    // We start with the base
    Component c = constructBase(innerHeight, extension);

    // Add wall support
    for (auto wallSupport : wallSupports) {
        c = addWallSupport(c, outerHeight, wallSupport);
    }

    // Screw holes
    for (auto hole : board.holes) {
        c = addHoleForScrew(c, outerHeight, hole, screwHoleRadius, screwHeads);
    }

    // Added by: Anthony W. Rainer <*****@*****.**>
    // Modified by: Bogdan Vacaliuc <*****@*****.**> to allow selection of side
    if(whichSide == board.holeNutsSide) {
	// Screw holes Nuts
        for (auto holeNut : board.holeNuts) {
            c = addCavityForNut(c, outerHeight, board.holes[holeNut.holeIndex], holeNut);
        }
    }

    // Apply rounded corners (if enabled)
    if (cornerRadius > 0.0) {
        // Class "RoundedCube" of ooml is buggy as it doesn't respect the "faces" parameter.
        // So we construct our own rounded cuboid by taking the convex hull of eight spheres.
        Vec min = {-outset(), -outset(), 0};
        Vec max = outerDimensions() + min;
        Vec cornerOffset = {cornerRadius, cornerRadius, cornerRadius};
        min += cornerOffset;
        max -= cornerOffset;
        CompositeComponent roundedCorners = Hull::create();
        for (int corner = 0; corner < 8; corner++) {
            double x = (corner & (1 << 0)) ? min.x : max.x;
            double y = (corner & (1 << 1)) ? min.y : max.y;
            double z = (corner & (1 << 2)) ? min.z : max.z;
            roundedCorners.addComponent(Sphere(cornerRadius, cornerFaces).translatedCopy(x, y, z));
        }

        // Intersect the current part with the rounded cuboid
        c = c * roundedCorners;
    }

    // Port holes
    for (auto port : ports) {
        c = addHoleForPort(c, outerHeight, port);
    }

    // "Forbidden areas" of the board
    for (auto area : forbiddenAreas) {
        c = c - Cube(area.sx, area.sy, area.sz + extensionHeight() + eps, false)
                .translatedCopy(area.x, area.y, outerHeight - area.sz);
    }

    // If this is the top, we've just built it mirrored. So we mirror the y axis and move it so it matches the dimensions of the bottom part.
    if (whichSide == TopSide) {
        c.scale(1.0, -1.0, 1.0);
        c.translate(0.0, board.size[1], 0.0);
    }

    return c;
}
Beispiel #22
0
#include "meshmanager.hpp"
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/Importer.hpp>
#include "../util/filesystem.hpp"
#include "../util/logging.hpp"

static std::vector<Mesh> loaded_meshes{Cube(), Cube(true), Sphere()};

// Assuming the metallic-roughness material model of models loaded with GLTF.
std::pair<ID, std::vector<std::pair<Texture::Type, std::string>>>
MeshManager::load_mesh(const std::string& directory, const std::string& file) {
    MeshInformation mesh_info;
    mesh_info.loaded_from_filepath = directory + file;

    Assimp::Importer importer;
    auto scene = importer.ReadFile(mesh_info.loaded_from_filepath.c_str(), aiProcess_Triangulate | aiProcess_JoinIdenticalVertices);

    if (scene == nullptr || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) {
        Log::error(std::string(importer.GetErrorString()));
        return {0, {}};
    }

    std::vector<std::pair<Texture::Type, std::string>> texture_info;
    if (scene->HasMaterials()) {
        Log::info("Number of materials: " + std::to_string(scene->mNumMaterials));
        for (size_t i = 0; i < scene->mNumMaterials; i++) {
            auto material = scene->mMaterials[i];

            aiString material_name;
            material->Get(AI_MATKEY_NAME, material_name);
void LidarProcessOctree::subdivide(LidarProcessOctree::Node& node)
	{
	{
	#if ALLOW_THREADING
	Threads::Mutex::Lock lruLock(lruMutex);
	#endif
	++numSubdivideCalls;
	}
	
	#if ALLOW_THREADING
	Threads::Mutex::Lock nodeLock(node.mutex);
	#endif
	
	/* Bail out if the node's children have magically appeared since the last check: */
	if(node.children!=0)
		return;
	
	/* Check if the node cache is full: */
	{
	#if ALLOW_THREADING
	Threads::Mutex::Lock lruLock(lruMutex);
	#endif
	if(numCachedNodes+8>cacheSize)
		{
		/* Find an unused leaf node parent and remove its children: */
		Node* coarsenNode;
		#if ALLOW_THREADING
		for(coarsenNode=lruHead;coarsenNode!=0;coarsenNode=coarsenNode->lruSucc)
			{
			/* Check if the leaf parent is currently unused: */
			coarsenNode->mutex.lock();
			if(coarsenNode->processCounter==0)
				break;
			coarsenNode->mutex.unlock();
			}
		#else
		for(coarsenNode=lruHead;coarsenNode!=0&&coarsenNode->processCounter!=0;coarsenNode=coarsenNode->lruSucc)
			;
		#endif
		
		/* Remove the found node's children: */
		delete[] coarsenNode->children;
		coarsenNode->children=0;
		
		#if ALLOW_THREADING
		coarsenNode->mutex.unlock();
		#endif
		
		/* Remove the found node from the lru list: */
		if(coarsenNode->lruPred!=0)
			coarsenNode->lruPred->lruSucc=coarsenNode->lruSucc;
		else
			lruHead=coarsenNode->lruSucc;
		if(coarsenNode->lruSucc!=0)
			coarsenNode->lruSucc->lruPred=coarsenNode->lruPred;
		else
			lruTail=coarsenNode->lruPred;
		coarsenNode->lruPred=0;
		coarsenNode->lruSucc=0;
		
		/* Update the node cache: */
		numCachedNodes-=8;
		
		/* Check if the found node's parent is now a leaf parent node: */
		Node* parent=coarsenNode->parent;
		if(parent!=0)
			{
			/* Check if all children of the parent are leaves: */
			bool leafParent=true;
			for(int childIndex=0;childIndex<8&&leafParent;++childIndex)
				leafParent=parent->children[childIndex].children==0;
			
			if(leafParent)
				{
				/* Add the parent to the end of the leaf parent node list: */
				parent->lruPred=lruTail;
				parent->lruSucc=0;
				if(lruTail!=0)
					lruTail->lruSucc=parent;
				else
					lruHead=parent;
				lruTail=parent;
				}
			}
		}
	
	/* Check if the node's parent was a leaf parent: */
	Node* parent=node.parent;
	if(parent!=0&&(parent->lruPred!=0||parent->lruSucc!=0||lruHead==parent))
		{
		/* Remove the node's parent from the leaf parent node list: */
		if(parent->lruPred!=0)
			parent->lruPred->lruSucc=parent->lruSucc;
		else
			lruHead=parent->lruSucc;
		if(parent->lruSucc!=0)
			parent->lruSucc->lruPred=parent->lruPred;
		else
			lruTail=parent->lruPred;
		parent->lruPred=0;
		parent->lruSucc=0;
		}
	
	/* Add the node to the leaf parent node list: */
	node.lruPred=lruTail;
	node.lruSucc=0;
	if(lruTail!=0)
		lruTail->lruSucc=&node;
	else
		lruHead=&node;
	lruTail=&node;
	
	/* Update the node cache: */
	numCachedNodes+=8U;
	}
	
	/* Create and load the node's children: */
	{
	#if ALLOW_THREADING
	Threads::Mutex::Lock fileLock(fileMutex);
	#endif
	Node* children=new Node[8];
	indexFile.setReadPosAbs(node.childrenOffset);
	for(int childIndex=0;childIndex<8;++childIndex)
		{
		Node& child=children[childIndex];
		
		/* Read the child node's structure: */
		LidarOctreeFileNode ofn;
		ofn.read(indexFile);
		child.parent=&node;
		child.childrenOffset=ofn.childrenOffset;
		child.domain=Cube(node.domain,childIndex);
		child.numPoints=ofn.numPoints;
		child.dataOffset=ofn.dataOffset;
		child.detailSize=ofn.detailSize;
		
		if(child.numPoints>0)
			{
			/* Load the child node's points: */
			child.points=new LidarPoint[maxNumPointsPerNode]; // Always allocate maximum to prevent memory fragmentation
			pointsFile.setReadPosAbs(LidarDataFileHeader::getFileSize()+pointsRecordSize*child.dataOffset);
			pointsFile.read(child.points,child.numPoints);
			}
		
		++numLoadedNodes;
		}
	
	/* Install the node's children array: */
	node.children=children;
	}
	}
Beispiel #24
0
Component KeyboardMount::build()
{
    Component base = Cube(m_lenght, m_width, m_thickness);

    Component holding_edge_long = Cube(m_lenght-4, 2, 1).translate(0,m_neg_y_edge+2+1,m_thickness/2+0.5);
    Component holding_edge_short = Cube(2, m_width-2, 1).translate(0,1,m_thickness/2+0.5);

//    Component sub_slot_side = Cube(4, m_slot_width+3, 4);

    Component sub_slot_middle_small = Cube(18, 4, 4)
            .translate(0,m_slot_displacement+m_slot_pos_y_edge,1.5);

    Component sub_slot_middle = Cube(22, 20, 4).translate(0,m_slot_displacement,2);

//    Component sub_slot_left_right = Cube(5, 42, 4);

//    Component sub_slot_small = Cube(7, 3, 4);

    Component slot = Cube(m_slot_length, m_slot_width, 4).translate(0,m_slot_displacement,2.5);

    Component corner = Cylinder(3, m_thickness+2);
    Component keys_slot = corner.translatedCopy(-m_keys_slot_length/2+3,
                                                -m_keys_slot_width/2+3+m_keys_slot_displacement,0)
            & corner.translatedCopy(m_keys_slot_length/2-3,
                                    -m_keys_slot_width/2+3+m_keys_slot_displacement,0)
            & corner.translatedCopy(m_keys_slot_length/2-3,
                                    m_keys_slot_width/2-3+m_keys_slot_displacement,0)
            & corner.translatedCopy(-m_keys_slot_length/2+3,
                                    m_keys_slot_width/2-3+m_keys_slot_displacement,0);

    // Component led_slot

    Component mount = base
            + holding_edge_long
            + holding_edge_short.translatedCopy(m_neg_x_edge+2+1,0,0)
            + holding_edge_short.translatedCopy(m_pos_x_edge-2-1,0,0)
            - sub_slot_middle
            - sub_slot_middle_small
            - slot
            - keys_slot;

    int number_of_screws = 9;

    Component screwholes[number_of_screws];

    for(int i = 0; i < number_of_screws; i++)
    {
        screwholes[i] = ScrewHole(0.75, 1.2, 1.5, 1);
    }
    //first row 6mm away from camera edge, 3mm, 25mm, and 44mm away from inner edge
    screwholes[0].translate(0, m_neg_y_edge+4.5, 0);
    screwholes[1].translate(48, m_neg_y_edge+4.5, 0);
    screwholes[2].translate(-42, m_neg_y_edge+4.5, 0);
    //2nd row 9mm away from non-camera edge, 3mm, 25mm, and 44mm away from inner edge
    screwholes[3].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+3+m_slot_displacement, 0);
    screwholes[4].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+25+m_slot_displacement, 0);
    screwholes[5].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+44+m_slot_displacement, 0);

    for(int i = 0; i < 3; i++)
    {
        mount = mount - screwholes[i];
    }
    return mount;

}
Beispiel #25
0
Component KeyboardTOH::build()
{
    Component toh = Component::loadFromFilename("toh.scad");

    //Component square = Cube(128.5, 67.5, 0.1).translate(0,0,0.9);
    //Component roundingCyl1 = Cylinder(1.0, 128.0).translate(0,67/2-1,-1).rotate(0,90,0);
    //Component roundingCyl2 = Cylinder(1.0, 128.0).translate(0,-67/2+1,-1).rotate(0,90,0);

    //Component base = square & roundingCyl1 & roundingCyl2;
    Component base = Cube(m_lenght, m_width, m_thickness).translate(0,0,0);

    Component holding_edge_long = Cube(m_lenght, 2, 1).translate(0,0,0);
    Component holding_edge_short = Cube(2, m_width, 1).translate(0,0,0);

    Component sub_slot_side = Cube(4, m_slot_width+3, 4);

    Component sub_slot_middle = Cube(16, 21, 4);

    Component sub_slot_left_right = Cube(5, 42, 4);

    Component sub_slot_small = Cube(7, 3, 4);

    Component slot = Cube(m_slot_length, m_slot_width, 4).translate(0,m_slot_displacement,-2);

    Component camera_hole = Cylinder(4.05, 4).translate(49.775, 0.075, 0);

    Component flash_hole = Cylinder(2.075, 4).translate(49.95, 10.7, 0);

    Component mount = base
            //add holding edges which allow movement only to sliding direction
            + holding_edge_long.translatedCopy(0, m_neg_y_edge+1, -m_thickness/2)
            + holding_edge_short.translatedCopy(m_neg_x_edge+1, 0, -m_thickness/2)
            + holding_edge_short.translatedCopy(m_pos_x_edge-1, 0, -m_thickness/2)
            //holes for camera and flash
            - camera_hole - flash_hole
            //begin building the slot for keyboard slide mechanism
            - slot
            //long slots on the sides
            -sub_slot_side.translatedCopy(m_slot_neg_x_edge+2, m_slot_displacement-3, m_sub_slot_depth)
            -sub_slot_side.translatedCopy(m_slot_pos_x_edge-2, m_slot_displacement-3, m_sub_slot_depth)
            //long slots, on each side, but half way to middle
            -sub_slot_left_right.translatedCopy(m_slot_neg_x_edge+23+2.5,
                                                m_slot_displacement-1.75, m_sub_slot_depth)
            -sub_slot_left_right.translatedCopy(m_slot_pos_x_edge-23-2.5,
                                                m_slot_displacement-1.75, m_sub_slot_depth)
            //four smaller slots
            -sub_slot_small.translatedCopy(m_slot_pos_x_edge-24-3.5,
                                           m_slot_pos_y_edge-1.5+m_slot_displacement, m_sub_slot_depth)
            -sub_slot_small.translatedCopy(m_slot_neg_x_edge+24+3.5,
                                           m_slot_pos_y_edge-1.5+m_slot_displacement, m_sub_slot_depth)
            -sub_slot_small.translatedCopy(m_slot_pos_x_edge-15-3.5,
                                           m_slot_neg_y_edge+1.5+m_slot_displacement, m_sub_slot_depth)
            -sub_slot_small.translatedCopy(m_slot_neg_x_edge+15+3.5,
                                           m_slot_neg_y_edge+1.5+m_slot_displacement, m_sub_slot_depth)
            //square slot in the middle
            -sub_slot_middle.translate(0, m_slot_displacement, m_sub_slot_depth);

    Component screwholes[6];
    for(int i = 0; i < 6; i++)
    {
        screwholes[i] = ScrewHole(0.75, 0.5, 1.5, 1);
    }
    //first row 6mm away from camera edge, 3mm, 25mm, and 44mm away from inner edge
    screwholes[0].translate(m_slot_pos_x_edge-6, m_slot_neg_y_edge+3+m_slot_displacement, 0);
    screwholes[1].translate(m_slot_pos_x_edge-6, m_slot_neg_y_edge+25+m_slot_displacement, 0);
    screwholes[2].translate(m_slot_pos_x_edge-6, m_slot_neg_y_edge+44+m_slot_displacement, 0);
    //2nd row 9mm away from non-camera edge, 3mm, 25mm, and 44mm away from inner edge
    screwholes[3].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+3+m_slot_displacement, 0);
    screwholes[4].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+25+m_slot_displacement, 0);
    screwholes[5].translate(m_slot_neg_x_edge+9, m_slot_neg_y_edge+44+m_slot_displacement, 0);

    Component to_be_screwed = toh + mount.translate(0,0,-0.75);

    for(int i = 0; i < 6; i++)
    {
        to_be_screwed = to_be_screwed - screwholes[i];
    }
    return to_be_screwed;
}
Beispiel #26
0
void World::loadScene(string filename) {
    // for as4, you can optionally hard-code the scene.  For as5 and as6 it must be loaded from a file.

    if (_FINAL_PROJ) {
        vec4 eye(0.0, 0.0, 0, 1.0);
        vec4 LL(-1.0, -1.0, -3.0, 1.0);
        vec4 UL(-1.0, 1.0, -3.0, 1.0);
        vec4 LR(1.0, -1.0, -3.0, 1.0);
        vec4 UR(1.0, 1.0, -3.0, 1.0);

        _view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT, 1);

        _lights[LIGHT_DIRECTIONAL].push_back(
            Light(0, vec3(0.5,0.5,-0.5),
                  LightInfo(LIGHT_DIRECTIONAL, vec3(.4, .8, 1.2))));
        _lights[LIGHT_POINT].push_back(
            Light(vec3(0.0,0.0,-14.0), vec3(0.5,0.5,-0.5),
                  LightInfo(LIGHT_POINT, vec3(1.39, 0.2, 0.2))));

        _ambientLight = vec3(.5,.2,.2);
        /*
        _spheres.push_back(Sphere(vec4(-2.5,-1.5,-17.0,1.0), 2.0,
        					MaterialInfo(vec3(.4, .5, .9),
        					.1, .5, .5, 150, 1.0)));
        _spheres.push_back(Sphere(vec4(0.0,4.0,-25.0,1.0), 2.5,
        					MaterialInfo(vec3(.9, .4, .5),
        					.4, .2, .5, 20, 0.0)));
        _spheres.push_back(Sphere(vec4(1.5,-1.5,-10.0,1.0), 1.0,
        					MaterialInfo(vec3(.5, .9, .4),
        					.5, .5, .3, 4, .5)));
        */

        _cubes.push_back(Cube(vec4(-3.5,-3.5,-15.0,1.0), 1.5, MaterialInfo(vec3(.4, .5, .9),
                              .1, .5, .5, 150, 1.0)));

        _cubes.push_back(Cube(vec4(2.0, 1.5, -10,1.0), 1.5, MaterialInfo(vec3(.9, .4, .5),
                              .4, .2, .5, 20, 0.0)));

        _cubes.push_back(Cube(vec4(-3.5,4,-120.0,1.0), 3, MaterialInfo(vec3(.5, .9, .4),
                              .5, .5, .3, 4, .5)));

        _cubes.push_back(Cube(vec4(3.5,-4,-250.0,1.0), 3.5, MaterialInfo(vec3(.5, .9, .4),
                              .5, .5, .3, 4, .5)));

        ksmMod = kspMod = 1.0;
    }

    else if (_ASSIGNMENT >= 5) {
        scene = new Scene(filename);

        loadInstance(scene->getRoot());

        if (_ASSIGNMENT >= 6)
            _bb = new BoundingBox(_spheres, 0);
    }

    if (_ASSIGNMENT <= 4) {
        //vec4 eye(0.0, 0.0, 0, 1.0);
        //vec4 LL(-1.0, -1.0, -3.0, 1.0);
        //vec4 UL(-1.0, 1.0, -3.0, 1.0);
        //vec4 LR(1.0, -1.0, -3.0, 1.0);
        //vec4 UR(1.0, 1.0, -3.0, 1.0);

        //_view = Viewport(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT);

        //_lights[LIGHT_DIRECTIONAL].push_back(
        //						Light(0, vec3(0.5,0.5,-0.5),
        //						LightInfo(LIGHT_DIRECTIONAL, vec3(.4, .8, 1.2))));
        //_lights[LIGHT_POINT].push_back(
        //						Light(vec3(0.0,0.0,-14.0), vec3(0.5,0.5,-0.5),
        //						LightInfo(LIGHT_POINT, vec3(1.39, 0.2, 0.2))));

        //_ambientLight = vec3(.5,.2,.2);

        //_spheres.push_back(Sphere(vec4(-2.5,-1.5,-17.0,1.0), 2.0,
        //					MaterialInfo(vec3(.4, .5, .9),
        //					.1, .5, .5, 150, 1.0)));
        //_spheres.push_back(Sphere(vec4(0.0,4.0,-25.0,1.0), 2.5,
        //					MaterialInfo(vec3(.9, .4, .5),
        //					.4, .2, .5, 20, 0.0)));
        //_spheres.push_back(Sphere(vec4(1.5,-1.5,-10.0,1.0), 1.0,
        //					MaterialInfo(vec3(.5, .9, .4),
        //					.5, .5, .3, 4, .5)));

        //ksmMod = kspMod = 1.0;
    }
}
Beispiel #27
0
Cube Cube::boundingBox()
{

    return Cube(getMin(),getMax(),getCenter());
}
Beispiel #28
0
Scene::Type GameScene::update(float time)
{
	// Cube
	float cubeDistToGround = m_level.getSize().y - (m_cube.getBoundingRect().top + m_cube.getBoundingRect().height);
	for (std::list<Block>::iterator it = m_level.getBlocks().begin(); it != m_level.getBlocks().end(); ++it)
	{
		sf::FloatRect rect = it->getRect();
		sf::Vector2f cubePosition = m_cube.getHitSphere().getPosition();

		if(rect.left <= cubePosition.x+PADOFFSET && rect.left+rect.width >= cubePosition.x-PADOFFSET && rect.top >= cubePosition.y && it->isPracticable())
		{
			float newCubeDistToGround = rect.top - (cubePosition.y+CUBESIZE/2);
			if(newCubeDistToGround < cubeDistToGround)
				 cubeDistToGround = newCubeDistToGround;
		}
	}
	m_cube.update(time, cubeDistToGround);

	// Update view according to cube's position
	m_sceneView.setCenter(m_cube.getPosition()+sf::Vector2f(250.f,-150.f));

	// Events
	std::list<Level::Event>::iterator it = m_level.getEvents().begin();
	if(it != m_level.getEvents().end() && it->position <= m_cube.getPosition().x)
	{
		switch(it->type)
		{
		case Level::Event::ROTATE :
			m_sceneView.rotate(it->parameter.f);
			break;

		case Level::Event::COLOR :
			{
				unsigned int r = it->parameter.ui << 8 >> 24;
				unsigned int g = it->parameter.ui << 16 >> 24;
				unsigned int b = it->parameter.ui << 24 >> 24;
				m_scenery.setColor(sf::Color(r,g,b));
			}
			break;

		default :
			break;
		}
		it = m_level.getEvents().erase(it);
	}

	// Blocks
	for (std::list<Block>::iterator it = m_level.getBlocks().begin(); it != m_level.getBlocks().end(); ++it)
	{
		if (it->getHitSphere().intersects(m_cube.getHitSphere()) && !m_godMode && m_cube.getState() == Cube::ALIVE)
			m_cube.setState(Cube::DESTROYING);
	}

	// Start next level or restart
	if (m_cube.getPosition().x >= m_level.getSize().x)
	{
		loadLevel();
		m_level.start();
	}
	if(m_cube.getState() == Cube::DESTROYED)
	{
		m_cube = Cube(0.f, 0.f, CUBESIZE);
		loadLevel();
		m_level.start();
		++m_attemptCount;
		std::stringstream ss;
		ss << "Attempts : " << m_attemptCount;
		m_attemptsText.setString(ss.str());
	}

	return m_quit ? Scene::MENUSCENE : Scene::NONE;
}
Beispiel #29
0
void IntersectionUI::writeTest() const {
    // creates a deterministic sequence of ray positions and directions
    // and writes the resulting intersections to a file
    // you must add the proper intersect calls for this file to be generated
    
    double invBase[5] = {1.0 / 2.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 7.0, 1.0 / 11.0};
    double values[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
    std::ofstream file("../intersections.txt");
    file.precision(4);

    const int seed = static_cast<int>(intersectionUI->m_iSeed->value());
    // generate a halton sequence to pick position/ray combinations
    // skip the first 'seed' values
    for (int i = 0; i < seed; i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
    }
    for (int i = seed; i < (seed + 1638); i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
        // create the ray from the five random values
        // compute ray origin
        Point3 p;
        p[0] = values[4] * sin(values[0] * M_PI) * cos(values[1] * 2.0 * M_PI);
        p[1] = values[4] * sin(values[0] * M_PI) * sin(values[1] * 2.0 * M_PI);
        p[2] = values[4] * cos(values[0] * M_PI);
        // compute ray direction
        Vector3 dir;
        dir[0] = sin(values[2] * M_PI) * cos(values[3] * 2.0 * M_PI);
        dir[1] = sin(values[2] * M_PI) * sin(values[3] * 2.0 * M_PI);
        dir[2] = cos(values[2] * M_PI);
        
        HitRecord cubeHr, cylinderHr, coneHr, sphereHr;
        // ToDo: intersect with your shapes here and store the result
        // in the appropriate hit record
        //cube.intersect(p, dir);
		Cube cube = Cube(1);
		cubeHr = *(cube.intersect(p, dir));
        //cylinder.intersect(p, dir);
		Cylinder cylinder = Cylinder(1, 1);
		cylinderHr = *(cylinder.intersect(p, dir));
        //coneHr = cone.intersect(p, dir);
		Cone cone = Cone(1, 1);
		coneHr = *(cone.intersect(p, dir));
        //sphereHr = sphere.intersect(p, dir);
		Sphere sphere = Sphere(1);
		sphereHr = *(sphere.intersect(p, dir));

        // write out
        file << i << " Cube     " << cubeHr     << std::endl;
        file << i << " Cylinder " << cylinderHr << std::endl;
        file << i << " Cone     " << coneHr     << std::endl;
        file << i << " Sphere   " << sphereHr   << std::endl;
    }
    file.close();
}
Beispiel #30
0
#include "StdAfx.h"
#include "main.h"

GLfloat boxsize = 2;
bool rotating = false;
GLfloat degrees = 1;
bool mute = false;

// Size of the window
int width = 800;
int height = 600;
Cube c = Cube(mute);
Platform p = Platform(&c);

// Title screen global variables
GLfloat mgrow =0.5;
bool growing = true;

GLfloat msize = 0.5;
GLfloat titledegrees = 0;
GLfloat titleposition = 0.25;

void initRendering() {
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable( GL_BLEND ); glClearColor(0.0,0.0,0.0,0.0);