bool Clipping::SutherlandHodgmanPolygonClip(Object* p){
    auto &input = p->getNCoords();
    Coordinates tmp;

    clipLeft(input, tmp);
    clipRight(tmp, input);
    clipBottom(input, tmp);
    clipTop(tmp, input);

    return (input.size() != 0);
}
bool Clipping::SutherlandHodgmanPolygonClip(Object* p){
    auto input = p->getNCoords();
    Coordinates tmp;
    Coordinates output;

    clipLeft(input, tmp);
    clipRight(tmp, output);
    clipTop(output, tmp);
    clipBottom(tmp, output);

    if(output.size() == 0)
        return false;

    p->setNCoord(output);
    return true;
}
Esempio n. 3
0
void Player::move( float x, float y, Direction directionOfInput, World& world ) {
    // The program will crash if attempting to load a chunk outside the world.
    // Constrain movement until infinite worlds are implemented.
    if( position.x + x > 150 || position.x + x < -150 ) {
        Physics::getPhysics().collideX( *this );
        return;
    }
    if( position.y + y > 150 || position.y + y < -150 ) {
        Physics::getPhysics().collideY( *this );
        return;
    }

    // If player is currently digging, disregard input and process dig step.
    if( digging ) {
        processDiggingStep();
        return;
    }

    // Check for collisions.
    float oldX = position.x;
    float oldY = position.y;
    float newX = oldX + x;
    float newY = oldY + y;

    if( clipLeft( oldX, oldY, newX, newY, directionOfInput, world ) ) {
            newX = floor( oldX ) - leftClip + 0.001f;
            Physics::getPhysics().collideX( *this );
    } else if( clipRight( oldX, oldY, newX, newY, directionOfInput, world ) ) {
        newX = floor( oldX + 1 ) - 0.001f - rightClip;
        Physics::getPhysics().collideX( *this );
    }
    if( clipAbove( oldX, oldY, newX, newY, directionOfInput, world ) ) {
        newY = floor( oldY + 1 ) - 0.001f - topClip;
        Physics::getPhysics().collideY( *this );
    } else if( clipBelow( oldX, oldY, newX, newY, directionOfInput, world ) ) {
        newY = floor( oldY ) - bottomClip + 0.001f;
        Physics::getPhysics().collideY( *this );
        if( onGround < DIG_DELAY ) onGround++;
    }

    if( digging ) {
        processDiggingStep();
    }
    else {
        position = sf::Vector2f( newX, newY );
    }
}
void Triangle2HeightField::clipTriangleAgainstHeightField(const osg::Vec2d& v1, const osg::Vec2d& v2, const osg::Vec2d& v3,
                                                          std::vector<osg::Vec2d>& result)
{
  std::vector<osg::Vec2d>& in = result;
  in.clear();
  in.push_back(v1);
  in.push_back(v2);
  in.push_back(v3);
  std::vector<osg::Vec2d> out;
  clipRight(in, out, _heightField->getNumColumns()-1);
  in.clear();
  clipLeft(out, in, 0);
  out.clear();
  clipTop(in, out, _heightField->getNumRows()-1);
  in.clear();
  clipBottom(out, in, 0);
}
Esempio n. 5
0
	bool Clipper::clip(Polygon &polygon, int clipFlagsOr, const DrawCall &draw)
	{
		if(clipFlagsOr & CLIP_FRUSTUM)
		{
			if(clipFlagsOr & CLIP_NEAR)   clipNear(polygon);
			if(polygon.n >= 3) {
			if(clipFlagsOr & CLIP_FAR)    clipFar(polygon);
			if(polygon.n >= 3) {
			if(clipFlagsOr & CLIP_LEFT)   clipLeft(polygon);
			if(polygon.n >= 3) {
			if(clipFlagsOr & CLIP_RIGHT)  clipRight(polygon);
			if(polygon.n >= 3) {
			if(clipFlagsOr & CLIP_TOP)    clipTop(polygon);
			if(polygon.n >= 3) {
			if(clipFlagsOr & CLIP_BOTTOM) clipBottom(polygon);
			}}}}}
		}

		return polygon.n >= 3;
	}