Ejemplo n.º 1
0
//! Clip poly by plane
void Polygon3::ClipByPlane(const Plane & plane)
{
    // TODO: test / check performance / optimize / эта пиздец! count чему в начале равен?
    Vector<Vector3> resultVector;
    int32 i2;
    int32 count = 0;
    for(int32 i = 0; i < pointCount; ++i)
    {
        i2 = i + 1;
        if (i2 >= pointCount) i2 = 0;

        float32 d1 = plane.DistanceToPoint(points[i]);
        float32 d2 = plane.DistanceToPoint(points[i2]);
        if ((d1 >= POLYGON_EPSILON) && (d2 >= POLYGON_EPSILON))
        {
            resultVector.push_back(points[i]);
            resultVector.push_back(points[i2]);
            count += 2;
        } else if ((d1 >= POLYGON_EPSILON) && (d2 <= -POLYGON_EPSILON))
        {
            Vector3 res;
            res.Lerp(points[i], points[i2], d1 / (d1 - d2));

            resultVector.push_back(points[i]);
            resultVector.push_back(res);
            count += 2;
        } else if ((d1 <= -POLYGON_EPSILON) && (d2 >= POLYGON_EPSILON))
        {
            Vector3 res;
            res.Lerp(points[i], points[i2], -d1 / (-d1 + d2));
            resultVector.push_back(res);
            //resultVector.push_back(points[i]);
            count += 1;
        }
    }
    points.clear();
    for (int32 i = 0; i < count; ++i)
        points.push_back(resultVector[i]);
}
Ejemplo n.º 2
0
bool Ray::castTo(Plane target_, Vec3 &output_) {
	//Ray is parrallel to plane
	if (Vec3::dot(target_.normal, dir) == 0) {
		return false;
	}

	if (target_.DistanceToPoint(point) < 0) {
		if (Vec3::dot(target_.normal, dir) > 0) {
			output_ = point + dir * (-(Vec3::dot(point, target_.normal) + target_.D) / Vec3::dot(target_.normal, dir));
			return true;
		} else {
			return false;
		}
	} else {
		if (Vec3::dot(target_.normal, dir) < 0) {
			output_ = point + dir * (-(Vec3::dot(point, target_.normal) + target_.D) / Vec3::dot(target_.normal, dir));
			return true;
		} else {
			return false;
		}
	}
	
}