Ejemplo n.º 1
0
 * @param point Zu testender Punkt
 * @return true wenn Punkt im Wuerfel liegt
 */
bool Cube::enclosesPoint(const Vector3D& point) const
{
	VTYPE x = point.x(), y = point.y(), z = point.z();
		
	return
		!IS_SMALLER(x, m_vertices[0].x()) &&
		!IS_GREATER(x, m_vertices[1].x()) &&
		!IS_SMALLER(y, m_vertices[3].y()) &&
		!IS_GREATER(y, m_vertices[0].y()) &&
Ejemplo n.º 2
0
bool Triangle::isPointInTriangle(const Vector3D &p) const
{
	Vector3D v0(m_c - m_a);
	Vector3D v1(m_b - m_a);
	Vector3D v2(p - m_a);

	VTYPE dot00 = v0 * v0;
	VTYPE dot01 = v0 * v1;
	VTYPE dot02 = v0 * v2;
	VTYPE dot11 = v1 * v1;
	VTYPE dot12 = v1 * v2;

	VTYPE invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
	VTYPE u = (dot11 * dot02 - dot01 * dot12) * invDenom;
	VTYPE v = (dot00 * dot12 - dot01 * dot02) * invDenom;

	return (!IS_SMALLER(u,0)) && (!IS_SMALLER(v,0)) && (!IS_GREATER(u+v,1));
}
Ejemplo n.º 3
0
static void gray_out_pixmap( int* src, int* dest, int width, int height )
{
    // assuming the pixels along the edges are of the background color

    int x = 0;
    int y = 1;

    do
    {
        int cur       = GET_ELEM(src,x,y);


        if ( IS_IN_ARRAY(x-1,y-1) )
        {
            int upperElem = GET_ELEM(src,x-1,y-1);

            // if the upper element is lighter than current
            if ( IS_GREATER(upperElem,cur) )
            {
                GET_ELEM(dest,x,y) = MASK_DARK;
            }
            else
            // if the current element is ligher than the upper
            if ( IS_GREATER(cur,upperElem) )
            {
                GET_ELEM(dest,x,y) = MASK_LIGHT;
            }
            else
            {
                if ( GET_ELEM(dest,x-1,y-1) == MASK_LIGHT )

                    GET_ELEM(dest,x,y) = MASK_BG;

                if ( GET_ELEM(dest,x-1,y-1 ) == MASK_DARK )

                    GET_ELEM(dest,x,y) = MASK_DARK;
                else
                    GET_ELEM(dest,x,y) = MASK_BG;
            }
        }

        // go zig-zag

        if ( IS_IN_ARRAY(x+1,y-1) )
        {
            ++x;
            --y;
        }
        else
        {
            while ( IS_IN_ARRAY(x-1,y+1) )
            {
                --x;
                ++y;
            }

            if ( IS_IN_ARRAY(x,y+1) )
            {
                ++y;
                continue;
            }
            else
            {
                if ( IS_IN_ARRAY(x+1,y) )
                {
                    ++x;
                    continue;
                }
                else break;
            }
        }

    } while (1);
}
Ejemplo n.º 4
0
	*v2 = tmp;
}

bool Cube::intersectsRay(const Ray &ray, Vector3D *res) const
{
	Vector3D bL = m_vertices[7];//[7];
	Vector3D bH = m_vertices[1];//[1];
	Ray rai = ray;
	rai.dir = ray.dir * 20;
	
	VTYPE tNear = -MAX_VALUE;
	VTYPE tFar = MAX_VALUE;
	VTYPE t1, t2;
	//int i = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (IS_ZERO(rai.dir[i]))
		{
			if(IS_SMALLER(rai.point[i], bL[i]) || IS_GREATER(rai.point[i], bH[i]))
				return false;
		} else
		{
			t1 = (bL[i] - rai.point[i]) / rai.dir[i];
			t2 = (bH[i] - rai.point[i]) / rai.dir[i];

			if (IS_GREATER(t1, t2))
				swap(&t1, &t2);
				
			if (IS_GREATER(t1, tNear))
				tNear = t1;
				
			if (IS_SMALLER(t2, tFar))
				tFar = t2;
				
			if (IS_GREATER(tNear, tFar))
				return false;
				
			if (IS_SMALLER(tFar, 0))
				return false;
		}
	}
	
	*res = rai.point + rai.dir * tNear;
	
	return true;

	/*VTYPE t1n = (bL[0] - ray.point.x()) / (rai.dir.x() - ray.point.x());
	VTYPE t2n = (bL[1] - ray.point.y()) / (rai.dir.y() - ray.point.y());
	VTYPE t3n = (bL[2] - ray.point.z()) / (rai.dir.z() - ray.point.z());
	
	VTYPE t1f = (bH[0] - ray.point.x()) / (rai.dir.x() - ray.point.x());
	VTYPE t2f = (bH[1] - ray.point.y()) / (rai.dir.y() - ray.point.y());
	VTYPE t3f = (bH[2] - ray.point.z()) / (rai.dir.z() - ray.point.z());
	
	VTYPE tn = MAX(MAX(t1n, t2n), t3n);
	VTYPE tf = MIN(MIN(t1f, t2f), t3f);
	
	if ((tn < tf) && (tf > 0))
	{
		*res = ray.point + ray.dir * tn;
		return true;
	}
	else