Ejemplo n.º 1
0
float VolumeSampler::sampleTrilinear(float x, float y, float z) const
{
	if(!inBox(x,y,z))
		return 0;

	// otherwise do trilinear interpolation.
	float xnf = x*m_data.nx() - 0.5f;
	float ynf = y*m_data.ny() - 0.5f;
	float znf = z*m_data.nz() - 0.5f;

	int xn = int(xnf);
	int yn = int(ynf);
	int zn = int(znf);

	int xnp1 = min(xn+1, m_data.nx()-1);
	int ynp1 = min(yn+1, m_data.ny()-1);
	int znp1 = min(zn+1, m_data.nz()-1);

	float xl = xnf - xn;
	float yl = ynf - yn;
	float zl = znf - zn;

	return lerp(zl,
		lerp(yl, lerp(xl, m_data(xn,yn,zn), m_data(xnp1,yn,zn)),
				lerp(xl, m_data(xn,ynp1,zn), m_data(xnp1,ynp1,zn))),
		lerp(yl, lerp(xl, m_data(xn,yn,znp1), m_data(xnp1,yn,znp1)),
				lerp(xl, m_data(xn,ynp1,znp1), m_data(xnp1,ynp1,znp1)))
		);
}
Ejemplo n.º 2
0
int procesarAcontecimientos(std::list<tEscenario> *escenario, std::list<tResultado> *resultados) {

	FILE *file = fopen(".\\Acontecimientos.txt","r");

	if (!file)
		return -1;

	char dato[100];
	int x;
	int y;
	while (!feof(file)) {
		fgets(dato,100,file);
		x = atoi(strtok(dato,";"));
		y = atoi(strtok(NULL,";"));

		for (std::list<tEscenario>::iterator it = escenario->begin(); it != escenario->end(); it++) {
			if (inBox((*it),x,y) == true)
				actualizarResultados(resultados, (*it));
		}

	}

	fclose(file);

	return 0;
	

}
Ejemplo n.º 3
0
void CategoryDlg::InitializeLists()
{
	CListBox inBox(GetDlgItem(IDC_INCLUDE_LIST));
	CListBox exBox(GetDlgItem(IDC_EXCLUDE_LIST));
	ClearListBox(inBox);
	ClearListBox(exBox);
	int inWidth = 0;
	int exWidth = 0;
	ScopedGdiObjectSelection hIn(inBox.GetDC(), inBox.GetFont());
	ScopedGdiObjectSelection hEx(exBox.GetDC(), exBox.GetFont());

	for (auto it = m_categories.begin(); it != m_categories.end(); ++it)
	{
		if (it->second)
		{
			inBox.AddString(WStr(it->first));
			inWidth = std::max(inWidth, GetTextWidth(inBox.GetDC(), it->first));
		}
		else
		{
			exBox.AddString(WStr(it->first));
			exWidth = std::max(exWidth, GetTextWidth(exBox.GetDC(), it->first));
		}
	}

	inBox.SetHorizontalExtent(inWidth + 3*GetSystemMetrics(SM_CXBORDER));
	exBox.SetHorizontalExtent(exWidth + 3*GetSystemMetrics(SM_CXBORDER));

	UpdateUiState();
}
Ejemplo n.º 4
0
void firstIntersectionGridVisitor::examineOccluder(Polygon3r *occ){

    // check whether the edge and the polygon plane are coincident:
    //-------------------------------------------------------------
    //first let us compute the plane equation.
    Vec3r v1(((occ)->getVertices())[0]);           
    Vec3d normal((occ)->getNormal());
    real d = -(v1 * normal);

    real tmp_u, tmp_v, tmp_t;
    if((occ)->rayIntersect(ray_org_, ray_dir_, tmp_t, tmp_u, tmp_v)){
        if (fabs(ray_dir_ * normal) > 0.0001){
            // Check whether the intersection is in the cell:
            if(inBox(ray_org_+tmp_t*ray_dir_/ray_dir_.norm(), current_cell_->getOrigin(), current_cell_->getOrigin()+cell_size_)){

                //Vec3d bboxdiag(_scene3d->bbox().getMax()-_scene3d->bbox().getMin());
                //if ((t>1.0E-06*(min(min(bboxdiag.x(),bboxdiag.y()),bboxdiag.z()))) && (t<raylength)){
                if(tmp_t < t_){
                    occluder_ = occ;
                    u_ = tmp_u;
                    v_ = tmp_v;
                    t_ = tmp_t;
                }
            }else{
                occ->userdata2 = 0;
            }
        }
    }
}
Ejemplo n.º 5
0
void CategoryDlg::UpdateUiState()
{
	CListBox inBox(GetDlgItem(IDC_INCLUDE_LIST));
	CListBox exBox(GetDlgItem(IDC_EXCLUDE_LIST));

	GetDlgItem(IDC_ALL).EnableWindow(exBox.GetCount() > 0);
	GetDlgItem(IDC_INCLUDE).EnableWindow(exBox.GetSelCount() > 0);
	GetDlgItem(IDC_EXCLUDE).EnableWindow(inBox.GetSelCount() > 0);
	GetDlgItem(IDC_NONE).EnableWindow(inBox.GetCount() > 0);
}
Ejemplo n.º 6
0
int polyOverlap(Point p, Poly * pp, Point q, Poly * qp)
{
    Point op, cp;
    Point oq, cq;

    /* translate bounding boxes */
    addpt(&op, p, pp->origin);
    addpt(&cp, p, pp->corner);
    addpt(&oq, q, qp->origin);
    addpt(&cq, q, qp->corner);

    /* If bounding boxes don't overlap, done */
    if (!pintersect(op, cp, oq, cq))
	return 0;

    if (ISBOX(pp) && ISBOX(qp))
	return 1;
    if (ISCIRCLE(pp) && ISCIRCLE(qp)) {
	double d =
	    (pp->corner.x - pp->origin.x + qp->corner.x - qp->origin.x);
	double dx = p.x - q.x;
	double dy = p.y - q.y;
	if ((dx * dx + dy * dy) > (d * d) / 4.0)
	    return 0;
	else
	    return 1;
    }

    if (tp1 == NULL) {
	tp1 = N_GNEW(maxcnt, Point);
	tp2 = N_GNEW(maxcnt, Point);
    }

    transCopy(pp->verts, pp->nverts, p, tp1);
    transCopy(qp->verts, qp->nverts, q, tp2);
    return (edgesIntersect(tp1, tp2, pp->nverts, qp->nverts) ||
	    (inBox(*tp1, oq, cq) && inPoly(tp2, qp->nverts, *tp1)) ||
	    (inBox(*tp2, op, cp) && inPoly(tp1, pp->nverts, *tp2)));
}
Ejemplo n.º 7
0
// Simple bounding-box collision tester for sprites
bool onSprite(int x, int y, int sx, int sy, const gdl::Sprite *sprite) {

    int bx1,by1;
    int bx2,by2;

    bx1 = sx - sprite->cx;
    by1 = sy - sprite->cy;
    bx2 = sx + ((sprite->w-1) - sprite->cx);
    by2 = sy + ((sprite->h-1) - sprite->cy);

    if (inBox(x, y, bx1, by1, bx2, by2)) return(true);
    return(false);

}
Ejemplo n.º 8
0
tile* zone::getTile(float world_x, float world_y)
{
	if (!inBox(world_x, world_y, x, y, x + width, y + height))
		return 0;
	
	tile* pTile;
	pTile = 0;
	int i;
	for (i = 0; i < quads.size(); i++){
		pTile = quads[i]->getTile(world_x, world_y);
		if (pTile != 0) {
			return pTile;
		}
	}
	return pTile;
}
Ejemplo n.º 9
0
bool BoundingBox::isIn(float x1, float y1, float z1, float x2, float y2, float z2) const {
	if (_empty)
		return false;

	float minX, minY, minZ;
	getMin(minX, minY, minZ);

	float maxX, maxY, maxZ;
	getMax(maxX, maxY, maxZ);

	if ((x2 < minX) && (x1 < minX)) return false;
	if ((x2 > maxX) && (x1 > maxX)) return false;
	if ((y2 < minY) && (y1 < minY)) return false;
	if ((y2 > maxY) && (y1 > maxY)) return false;
	if ((z2 < minZ) && (z1 < minZ)) return false;
	if ((z2 > maxZ) && (z1 > maxZ)) return false;

	if ((x1 > minX) && (x1 < maxX) &&
	    (y1 > minY) && (y1 < maxY) &&
	    (z1 > minZ) && (z1 < maxZ))
		return true;

	float x, y, z;

	if (getIntersection(x1 - minX, x2 - minX, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 1))
		return true;
	if (getIntersection(y1 - minY, y2 - minY, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 2))
		return true;
	if (getIntersection(z1 - minZ, z2 - minZ, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 3))
		return true;
	if (getIntersection(x1 - maxX, x2 - maxX, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 1))
		return true;
	if (getIntersection(y1 - maxY, y2 - maxY, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 2))
		return true;
	if (getIntersection(z1 - maxZ, z2 - maxZ, x1, y1, z1, x2, y2, z2, x, y, z) &&
	    inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 3))
		return true;

	return false;
}
Ejemplo n.º 10
0
void DesignInterface::mousePressEvent(QMouseEvent *event){
    qDebug()<<"design interface: mouse press "<<event->pos();
    if (event->button()!=Qt::LeftButton) return;
    int a,b;
    if (game.getLoc(a,b,event->pos())){
        if (game.blocks[a][b].status == source){
            game.blocks[a][b].status = unmark;
            game.blocks[a][b].color = 0;
        }
        this->update();
        return;
    }
    int nowColor=0;
    for (int i=1;i<=2;i++)
        for (int j=1;j<=4;j++){
            nowColor++;
            if (inBox(event->pos(),QPoint(selectionStartX+i*selectionLen,selectionStartY+j*selectionLen))){
                chooseSource=1;
                sourceColor=nowColor;
            }
        }
    this->update();
}
Ejemplo n.º 11
0
	bool inBox( const float *pos ) {
	    return inBox( pos[0], pos[1], pos[2] );
	}
Ejemplo n.º 12
0
bool Ray::checkLineBox( hpvec3 boxPointMin, hpvec3 boxPointMax, hpvec3 linePoint1, hpvec3 linePoint2, hpvec3 &hitPoint) {
    if (linePoint2.x < boxPointMin.x && linePoint1.x < boxPointMin.x) return false;
    if (linePoint2.x > boxPointMax.x && linePoint1.x > boxPointMax.x) return false;
    if (linePoint2.y < boxPointMin.y && linePoint1.y < boxPointMin.y) return false;
    if (linePoint2.y > boxPointMax.y && linePoint1.y > boxPointMax.y) return false;
    if (linePoint2.z < boxPointMin.z && linePoint1.z < boxPointMin.z) return false;
    if (linePoint2.z > boxPointMax.z && linePoint1.z > boxPointMax.z) return false;
    if (linePoint1.x > boxPointMin.x && linePoint1.x < boxPointMax.x &&
        linePoint1.y > boxPointMin.y && linePoint1.y < boxPointMax.y &&
        linePoint1.z > boxPointMin.z && linePoint1.z < boxPointMax.z)
        {hitPoint = linePoint1;
        return true;}
    if ( (getIntersection( linePoint1.x-boxPointMin.x, linePoint2.x-boxPointMin.x, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 1 ))
      || (getIntersection( linePoint1.y-boxPointMin.y, linePoint2.y-boxPointMin.y, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 2 ))
      || (getIntersection( linePoint1.z-boxPointMin.z, linePoint2.z-boxPointMin.z, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 3 ))
      || (getIntersection( linePoint1.x-boxPointMax.x, linePoint2.x-boxPointMax.x, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 1 ))
      || (getIntersection( linePoint1.y-boxPointMax.y, linePoint2.y-boxPointMax.y, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 2 ))
      || (getIntersection( linePoint1.z-boxPointMax.z, linePoint2.z-boxPointMax.z, linePoint1, linePoint2, hitPoint) && inBox( hitPoint, boxPointMin, boxPointMax, 3 )))
        return true;

    return false;
}