コード例 #1
0
ファイル: GameObject.cpp プロジェクト: SnowblindFatal/tim
std::string Teleport::highlightClicked(sf::Vector2i point) {
	std::string result=drawable->highlightClicked(point);
	if (result=="rotate") {
		flipped++;
		if (flipped==4) flipped=0;
		if (flipped==0) {
			bodies[0].body_ptr->SetTransform(bodies[0].body_ptr->GetPosition(),0);
		}
		if (flipped==3) {
			bodies[0].body_ptr->SetTransform(bodies[0].body_ptr->GetPosition(),3.14159f/2.0f);
		}
		if (flipped==2) {
			bodies[0].body_ptr->SetTransform(bodies[0].body_ptr->GetPosition(),3.14159f);
		}
		if (flipped==1) {
			bodies[0].body_ptr->SetTransform(bodies[0].body_ptr->GetPosition(),3.0f*3.14159f/2.0f);
		}
		if (!noOverlaps()) {
			reset();
		}
		
		else {
			bodies[0].original_rot=bodies[0].body_ptr->GetAngle();
		}
			
	return "nothing";
	}
	else return result;
}
コード例 #2
0
ファイル: GameObject.cpp プロジェクト: SnowblindFatal/tim
void Platform::highlightDelta(sf::Vector2i point) {
	b2PolygonShape* shape_ptr = dynamic_cast<b2PolygonShape*>(bodies[0].body_ptr->GetFixtureList()->GetShape());

	b2Vec2 vertices[4];
	for (int index=0;index<4;index++) {
		vertices[index]=shape_ptr->GetVertex(index);
	}

    b2Vec2 movementDelta(point.x / 10.0f - manipulationReferenceLocation.x, point.y / 10.0f - manipulationReferenceLocation.y);

    movementDelta.x -= std::fmod(movementDelta.x, DISCRETE_MOVE_UNIT);
    movementDelta.y -= std::fmod(movementDelta.y, DISCRETE_MOVE_UNIT);

    manipulationReferenceLocation.x += movementDelta.x;
    manipulationReferenceLocation.y += movementDelta.y;
    
	vertices[0] += movementDelta;
	vertices[1] += movementDelta;
    
	if (std::abs(vertices[1].y-vertices[2].y)/std::abs(vertices[1].x-vertices[2].x) < 1
		&& std::abs(vertices[1].x-vertices[2].x) > 3.0f && std::abs(vertices[1].x-vertices[2].x) < 40.0f) {
		shape_ptr->Set(vertices, 4);
        dimensions += movementDelta;
	}
	if (!noOverlaps()) {
		vertices[0] -= movementDelta;
		vertices[1] -= movementDelta;
        dimensions -= movementDelta;
		shape_ptr->Set(vertices,4);
	}
}
コード例 #3
0
bool TopologyConstraints::solve() {
    FILE_LOG(logDEBUG)<<"TopologyConstraints::solve... dim="<<dim;
    COLA_ASSERT(assertConvexBends(edges));
    COLA_ASSERT(assertNoSegmentRectIntersection(nodes,edges));
    COLA_ASSERT(assertFeasible());
    vector<TopologyConstraint*> ts;
    constraints(ts);
    vpsc::IncSolver s(vs,cs);
    s.solve();
    double minTAlpha=1;
    TopologyConstraint* minT=nullptr;
    //printEdges(edges);
    // find minimum feasible alpha over all topology constraints
    for(vector<TopologyConstraint*>::iterator i=ts.begin();
            i!=ts.end();++i) {
        TopologyConstraint* t=*i;
        FILE_LOG(logDEBUG1)<<"Checking topology constraint:"<<t->toString();
        double tAlpha=t->c->maxSafeAlpha();
        FILE_LOG(logDEBUG1)<<"                              alpha="<<tAlpha;
        if(tAlpha<minTAlpha) {
            minTAlpha=tAlpha;
            minT=t;
        }
    }
#ifndef NDEBUG
    if(minT) {
        FILE_LOG(logDEBUG)<<"                 minT="<<minT->toString();
        FILE_LOG(logDEBUG)<<"                 minTAlpha="<<minTAlpha;
    } else {
        FILE_LOG(logDEBUG)<<" No violated constraints!";
    }
#endif
    if(minTAlpha>0) {
        for(Nodes::iterator i=nodes.begin();i!=nodes.end();++i) {
            Node* v=*i;
            v->rect->moveCentreD(dim,v->posOnLine(dim, minTAlpha));
        }
    }
    COLA_ASSERT(noOverlaps());
    COLA_ASSERT(assertConvexBends(edges));
    // rectangle and edge point positions updated to variables.
    FILE_LOG(logDEBUG)<<" moves done.";
    if(minTAlpha<1 && minT) {
        // now we satisfy the violated topology constraint, i.e. a bend point
        // that has become straight is removed or a segment that needs to bend
        // is split
        minT->satisfy();
    }
    //printEdges(edges);
    COLA_ASSERT(assertFeasible());
    COLA_ASSERT(assertConvexBends(edges));
    COLA_ASSERT(assertNoSegmentRectIntersection(nodes,edges));
    FILE_LOG(logDEBUG)<<"TopologyConstraints::solve... done";
    return minT!=nullptr;
}
コード例 #4
0
ファイル: GameObject.cpp プロジェクト: SnowblindFatal/tim
void GameObject::move(float x, float y) {
    b2Vec2 mousePos(x, y);
	for (auto& body : bodies) {
		body.body_ptr->SetTransform(body.body_ptr->GetTransform().p+ (mousePos - local_mouse), body.body_ptr->GetAngle());
		body.original_pos=body.body_ptr->GetTransform().p;
	}
    position += mousePos - local_mouse;
	local_mouse = mousePos;
	if (noOverlaps()) {
		can_place=true;
	}
	else {
		can_place=false;
	}
}
コード例 #5
0
ファイル: GameObject.cpp プロジェクト: SnowblindFatal/tim
void Wall::highlightDelta(sf::Vector2i point) {
	b2PolygonShape* shape_ptr = dynamic_cast<b2PolygonShape*>(bodies[0].body_ptr->GetFixtureList()->GetShape());

	b2Vec2 vertices[4];
	for (int index=0;index<4;index++) {
		vertices[index]=shape_ptr->GetVertex(index);
	}
    
    //Because of the way B2D handles vertices, we have to check here which ones we want.
    size_t wanted_index;
    if (vertices[0].y < vertices[1].y) wanted_index=1;
    else wanted_index=0;
    
    b2Vec2 movementDelta(point.x / 10.0f - manipulationReferenceLocation.x, point.y / 10.0f - manipulationReferenceLocation.y);

    movementDelta.x -= std::fmod(movementDelta.x, DISCRETE_MOVE_UNIT);
    movementDelta.y -= std::fmod(movementDelta.y, DISCRETE_MOVE_UNIT);

    manipulationReferenceLocation.x += movementDelta.x;
    manipulationReferenceLocation.y += movementDelta.y;
    
	vertices[wanted_index] += movementDelta;
	vertices[wanted_index+1] += movementDelta;
    
	if (std::abs(vertices[wanted_index+1].x-vertices[wanted_index+2].x)/std::abs(vertices[wanted_index+1].y-vertices[wanted_index+2].y) < 1
		&& std::abs(vertices[wanted_index +1].y-vertices[wanted_index +2].y) > 3.0f && std::abs(vertices[wanted_index +1].y-vertices[wanted_index +2].y) < 40.0f) {
		shape_ptr->Set(vertices, 4);
        dimensions += movementDelta;
	}
    
	if (!noOverlaps()) {
		vertices[wanted_index] -= movementDelta;
		vertices[wanted_index+1] -= movementDelta;
		shape_ptr->Set(vertices,4);
        dimensions -= movementDelta;
	}
}