8 Object::Object(Layout &l):
13 Snap Object::get_snap_node(unsigned) const
15 throw out_of_range("Object::get_snap_node");
18 bool Object::snap(Snap &sn, float limit, SnapType what) const
22 unsigned nsn = get_n_snap_nodes();
23 for(unsigned i=0; i<nsn; ++i)
25 Snap node = get_snap_node(i);
26 Vector span = sn.position-node.position;
27 if(dot(span, span)<limit*limit)
38 bool Object::snap_to(const Object &other, float limit, SnapType what)
40 if(what==SNAP_DEFAULT)
41 what = get_default_snap_type_to(other);
46 unsigned nsn = get_n_snap_nodes();
47 for(unsigned i=0; i<nsn; ++i)
49 Snap sn = get_snap_node(i);
51 if(other.snap(ssn, limit, what))
54 set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
57 Angle adiff = wrap_balanced((ssn.rotation-sn.rotation)*2.0f)/2.0f;
58 set_rotation(rotation+adiff);
60 sn = get_snap_node(i);
61 set_position(position+ssn.position-sn.position);
69 Object *Object::get_link(unsigned) const
71 throw out_of_range("Object::get_link");
74 bool Object::break_link(Object &other)
76 unsigned nls = get_n_link_slots();
77 for(unsigned i=0; i<nls; ++i)
78 if(get_link(i)==&other)
84 void Object::break_links()
86 unsigned nls = get_n_link_slots();
87 for(unsigned i=0; i<nls; ++i)
91 const Shape *Object::get_shape() const
95 return get_type().get_shape();
98 bool Object::collide_ray(const Ray &ray) const
100 const Shape *s = get_shape();
104 Transform reverse_trans = Transform::rotation(rotation, Vector(0, 0, -1))*
105 Transform::translation(-position);
106 return s->check_intersection(reverse_trans.transform(ray));
109 BoundingBox Object::get_bounding_box() const
111 const Shape *s = get_shape();
113 return BoundingBox();
115 Transform trans = Transform::translation(position)*
116 Transform::rotation(rotation, Vector(0, 0, 1));
117 return trans.transform(s->get_axis_aligned_bounding_box());