//------------------------------------------------------------------------------ Intersection2d intersect( const Rectangle& r1, const Rectangle& r2 ) { Intersection2d r; if( intersects( r1, r2 ) ) { r.add( intersect( LineSegment2d( r1.bottomLeft(), r1.topLeft() ), r2 ) ); r.add( intersect( LineSegment2d( r1.topLeft(), r1.topRight() ), r2 ) ); r.add( intersect( LineSegment2d( r1.topRight(), r1.bottomRight() ), r2 ) ); r.add( intersect( LineSegment2d( r1.bottomRight(), r1.bottomLeft() ), r2 ) ); } return r; }
//------------------------------------------------------------------------------ Intersection2d intersect( const Circle& c, const Rectangle& r) { Intersection2d result; //printf("bottomLeft %f, %f\n", r.bottomLeft().x(), r.bottomLeft().y() ); //printf("topLeft %f, %f\n", r.topLeft().x(), r.topLeft().y() ); //printf("topRight %f, %f\n", r.topRight().x(), r.topRight().y() ); //printf("bottomRight %f, %f\n", r.bottomRight().x(), r.bottomRight().y() ); result.add( intersect( c, LineSegment2d( r.bottomLeft(), r.topLeft() ) ) ); result.add( intersect( c, LineSegment2d( r.topLeft(), r.topRight() ) ) ); result.add( intersect( c, LineSegment2d( r.topRight(), r.bottomRight() ) ) ); result.add( intersect( c, LineSegment2d( r.bottomRight(), r.bottomLeft() ) ) ); return result; }
inline LineSegment2d Circle2d::projectedOnto(const Axis2d& axis) const { Point2d projectedCenter = centerPoint().projectedOnto(axis); Vector2d offset = radius() * axis.directionVector(); return LineSegment2d(projectedCenter - offset, projectedCenter + offset); }
inline LineSegment2d Triangle2d::edge(int oppositeIndex) const { assert(oppositeIndex >= 0 && oppositeIndex < 3); return LineSegment2d( vertex((oppositeIndex + 2) % 3), vertex((oppositeIndex + 1) % 3), handedness() ); }
Javelin::Javelin(Vector3d initialPosition, Vector3d initialDirection, double power) { PhysicsModule* physics = new PhysicsModule(this, initialPosition); Vector3d velocity = initialDirection.normalized() * power; physics->velocity = velocity; addModule(physics); GraphicsModule* graphics = new GraphicsModule(this); double size = 0.02; graphics->objectLines.push_back(LineSegment2d(-size, 0, size, 0)); addModule(graphics); }