Beispiel #1
0
//==============================================================================
void Gjk::support(const ConvexShape& shape0,
	const ConvexShape& shape1,
	const Vec4& dir,
	Support& support)
{
	support.m_v0 = shape0.computeSupport(dir);
	support.m_v1 = shape1.computeSupport(-dir);
	support.m_v = support.m_v0 - support.m_v1;
}
Beispiel #2
0
void Sierpinski::draw(RenderTarget& target, RenderStates states) const{
	ConvexShape triangle;
  	triangle.setPointCount(3);
  	triangle.setPoint(0, C);
	triangle.setPoint(1, A);
	triangle.setPoint(2, B);
	target.draw(triangle, states);
	
	if (depth == 1){
		return;
	}
	
	/* Define the three new triangles by point and length */
	Vector2f a, b, c, temp1, temp2;
	a.x = (C.x + B.x)/2;
	a.y = (C.y + B.y)/2;
	
	b.x = (C.x + A.x)/2;
	b.y = (C.y + A.y)/2;
	
	c.x = (A.x + B.x)/2;
	c.y = A.y;
	
	double length = sqrt(pow(C.x - A.x, 2) + pow(C.y - A.y, 2))/2;
	
	/* a is the small triangle to the right */
	temp1.x = a.x + length;
	temp1.y = a.y;
	temp2.x = a.x + length/2;
	temp2.y = a.y + (length/2 * sqrt(3));
	Sierpinski child1(temp2, a, temp1, depth - 1);
	target.draw(child1, states);	
	
	/* b is the small triangle to the left */
	temp1.x = b.x - length;
	temp1.y = b.y;
	temp2.x = b.x - length/2;
	temp2.y = b.y + (length/2 * sqrt(3));
	Sierpinski child2(temp2, temp1, b ,depth - 1);	
	target.draw(child2, states);	
	
	/* c is the small triangle on the top */
	temp1.x = c.x + length/2;
	temp1.y = c.y - (length/2 * sqrt(3));
	temp2.x = c.x - length/2;
	temp2.y = c.y - (length/2 * sqrt(3));
	Sierpinski child3(c, temp2, temp1, depth - 1);
	target.draw(child3, states);		
	
	return;
}
Beispiel #3
0
void SFMLRenderer::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color){

	ConvexShape poligono;
	
	poligono.setPointCount(vertexCount);

	for(int i=0;i<vertexCount;++i){		
		poligono.setPoint(i,Vector2f(vertices[i].x, vertices[i].y));		
	}

	poligono.setFillColor(box2d2SFMLColor(color));
	
	wnd->draw(poligono);

}
Beispiel #4
0
void Other::draw(RenderTarget& target, RenderStates states) const {
	ConvexShape rectangle;
  	rectangle.setPointCount(4);
  	rectangle.setPoint(0, A);
	rectangle.setPoint(1, B);
	rectangle.setPoint(2, C);
	rectangle.setPoint(3, D);
	rectangle.setFillColor(Color(55 + (depth*depth), 55 + (depth*depth), 55 + (depth*depth)));
	target.draw(rectangle, states);
	
	if (depth == 1){
		return;
	}
	
	/* Skeliton for two new squares */
	double length = sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2))/2;
	Vector2f upper, right, temp1, temp2, temp3;
	upper.x = (A.x + B.x)/2;
	upper.y = A.y;
	right.x = C.x;
	right.y = (B.x + C.x)/2 + length;
	
	/* Defining upper square */
	temp1.x = upper.x - length;
	temp1.y = upper.y - length;
	temp2.x = upper.x;
	temp2.y = upper.y - length;
	temp3.x = upper.x - length;
	temp3.y = upper.y;
	Other child1(temp1, temp2, upper, temp3, depth - 1);
	target.draw(child1, states);
	
	/* Defining right square */
	temp1.x = right.x + length;
	temp1.y = right.y;
	temp2.x = right.x + length;
	temp2.y = right.y + length;
	temp3.x = right.x;
	temp3.y = right.y + length;
	Other child2(right, temp1, temp2, temp3, depth - 1);
	target.draw(child2, states);
	
	return;
}
Beispiel #5
0
void Body::setShape(Shape* s) {
    if (shape) {
        delete shape;
        shape = NULL;
        shape->setOrigin(0);
    }

    if (s) {
        if (s->getType() == circle) {
            shape = new Circle();
            *shape = *s;
            inertiaMoment = 0.5*mass*pow(((Circle*)s)->getRadius(),2);
        } else if (s->getType() == convexshape) {
            ConvexShape *cs = new ConvexShape();
            shape = cs;
            *cs = *((ConvexShape*)s);

            //let's determine the center off mass
            double area = 0;
            Vec2 sum;
            for (int i = 1; i < cs->getSize()-1; i ++) {
                double a = abs(det(cs->getVertex(0), 
                            cs->getVertex(i), cs->getVertex(i+1)))/2.0;
                area += a;
                sum += (cs->getVertex(0)+cs->getVertex(i)+cs->getVertex(i+1))*a/3.0; 
            }
            cs->setOrigin(sum/area);

            for (int i = 0; i < cs->getSize(); i ++) {
                inertiaMoment += 
                    abs(det(cs->getOrigin(), cs->getVertex(i), 
                                cs->getVertex(i+1)))*0.5*mass/area*
                    pow(distance(cs->getOrigin(),
                        (cs->getVertex(i)+cs->getVertex(i+1)+cs->getOrigin())/3.0),2);
            }
        }
    }
}