40 |
using namespace world; |
using namespace world; |
41 |
using namespace px; |
using namespace px; |
42 |
|
|
|
namespace test |
|
|
{ |
|
|
enum ShapeType |
|
|
{ |
|
|
SHAPE_Sphere, |
|
|
SHAPE_Square, |
|
|
SHAPE_Rectangle, |
|
|
SHAPE_Polygon, |
|
|
}; |
|
|
|
|
|
class Shape |
|
|
{ |
|
|
ShapeType type; |
|
|
public: |
|
|
Shape (ShapeType t) : type(t) {} |
|
|
virtual ~Shape() {} |
|
|
|
|
|
ShapeType get_type() const { return type; } |
|
|
}; |
|
|
|
|
|
struct Sphere : public Shape |
|
|
{ |
|
|
Sphere (const V2 &c, double r) |
|
|
: Shape(SHAPE_Sphere), center(c), radius(r) |
|
|
{} |
|
|
|
|
|
// Variables. |
|
|
V2 center; |
|
|
double radius; |
|
|
}; |
|
|
} |
|
|
|
|
|
//---------------------------------------- |
|
|
// Sphere |
|
|
//---------------------------------------- |
|
|
namespace |
|
|
{ |
|
|
class Sphere { |
|
|
V2 center; |
|
|
double radius; |
|
|
public: |
|
|
Sphere(const V2 &c, double r) |
|
|
: center(c), radius(r) |
|
|
{} |
|
|
bool contains(const V2 &p) const { |
|
|
return length(center-p) < radius; |
|
|
} |
|
|
bool intersection_point(const Sphere &s, V2 &ip) { |
|
|
double rr = radius + s.radius; |
|
|
ip = center + normalize(s.center-center)*rr/2; |
|
|
return (length(center - s.center) <= rr); |
|
|
} |
|
|
}; |
|
|
} |
|
|
|
|
43 |
//---------------------------------------- |
//---------------------------------------- |
44 |
// Rubber band |
// Rubber band |
45 |
//---------------------------------------- |
//---------------------------------------- |
70 |
} |
} |
71 |
|
|
72 |
RubberBand::RubberBand (Actor *a1, Actor *a2, double strength_, double length_) |
RubberBand::RubberBand (Actor *a1, Actor *a2, double strength_, double length_) |
73 |
: actor(a1), actor2(a2), stone(0), model(), |
: actor(a1), actor2(a2), stone(0), |
74 |
|
model(display::AddRubber(get_p1(),get_p2())), |
75 |
strength(strength_), length(length_) |
strength(strength_), length(length_) |
76 |
{ |
{ |
77 |
assert(actor); |
assert(actor); |
78 |
assert(length >= 0); |
assert(length >= 0); |
|
model = display::AddRubber(get_p1(),get_p2()); |
|
79 |
} |
} |
80 |
|
|
81 |
RubberBand::RubberBand (Actor *a1, Stone *st, double strength_, double length_) |
RubberBand::RubberBand (Actor *a1, Stone *st, double strength_, double length_) |
82 |
: actor(a1), actor2(0), stone(st), model(0) |
: actor(a1), actor2(0), stone(st), model(0), |
83 |
, strength(strength_), length(length_) |
strength(strength_), length(length_) |
84 |
{ |
{ |
85 |
assert(actor); |
assert(actor); |
86 |
assert(length >= 0); |
assert(length >= 0); |
716 |
clear_world(); |
clear_world(); |
717 |
return false; |
return false; |
718 |
} |
} |
719 |
|
|
720 |
|
InitWorld(); |
721 |
|
return true; |
722 |
|
} |
723 |
|
|
724 |
|
void |
725 |
|
world::InitWorld() |
726 |
|
{ |
727 |
laser::RecalcLight(); |
laser::RecalcLight(); |
728 |
laser::RecalcLightNow(); // recalculate laser beams if necessary |
laser::RecalcLightNow(); // recalculate laser beams if necessary |
729 |
|
|
736 |
player::AddActor(iplayer,a); |
player::AddActor(iplayer,a); |
737 |
} |
} |
738 |
} |
} |
|
|
|
|
return true; |
|
739 |
} |
} |
740 |
|
|
741 |
void |
void |