8 Snap Object::get_snap_node(unsigned) const
10 throw out_of_range("Object::get_snap_node");
13 bool Object::snap(Snap &sn, float limit, SnapType what) const
17 unsigned nsn = get_n_snap_nodes();
18 for(unsigned i=0; i<nsn; ++i)
20 Snap node = get_snap_node(i);
21 Vector span = sn.position-node.position;
22 if(dot(span, span)<limit*limit)
33 bool Object::snap_to(const Object &other, float limit, SnapType what)
35 if(what==SNAP_DEFAULT)
36 what = get_default_snap_type_to(other);
41 unsigned nsn = get_n_snap_nodes();
42 for(unsigned i=0; i<nsn; ++i)
44 Snap sn = get_snap_node(i);
46 if(other.snap(ssn, limit, what))
49 set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
52 Angle adiff = wrap_balanced((ssn.rotation-sn.rotation)*2.0f)/2.0f;
53 set_rotation(rotation+adiff);
55 sn = get_snap_node(i);
56 set_position(position+ssn.position-sn.position);
64 Object *Object::get_link(unsigned) const
66 throw out_of_range("Object::get_link");
69 bool Object::break_link(Object &other)
71 unsigned nls = get_n_link_slots();
72 for(unsigned i=0; i<nls; ++i)
73 if(get_link(i)==&other)
79 void Object::break_links()
81 unsigned nls = get_n_link_slots();
82 for(unsigned i=0; i<nls; ++i)
86 bool Object::collide_ray(const Ray &ray) const
88 const Shape *shape = get_type().get_shape();
92 Transform reverse_trans = Transform::rotation(rotation, Vector(0, 0, -1))*
93 Transform::translation(-position);
94 return shape->check_intersection(reverse_trans.transform(ray));
97 BoundingBox Object::get_bounding_box() const
99 const Shape *shape = get_type().get_shape();
101 return BoundingBox();
103 Transform trans = Transform::translation(position)*
104 Transform::rotation(rotation, Vector(0, 0, 1));
105 return trans.transform(shape->get_axis_aligned_bounding_box());