9 Object::Object(Layout &l):
14 Snap Object::get_snap_node(unsigned) const
16 throw out_of_range("Object::get_snap_node");
19 bool Object::snap(Snap &sn, float limit, SnapType what) const
23 unsigned nsn = get_n_snap_nodes();
24 for(unsigned i=0; i<nsn; ++i)
26 Snap node = get_snap_node(i);
27 Vector span = sn.position-node.position;
28 if(dot(span, span)<limit*limit)
39 bool Object::snap_to(const Object &other, float limit, SnapType what)
41 if(what==SNAP_DEFAULT)
42 what = get_default_snap_type_to(other);
47 unsigned nsn = get_n_snap_nodes();
48 for(unsigned i=0; i<nsn; ++i)
50 Snap sn = get_snap_node(i);
52 if(other.snap(ssn, limit, what))
55 set_rotation(rotation+ssn.rotation-sn.rotation-Angle::half_turn());
58 Angle adiff = wrap_balanced((ssn.rotation-sn.rotation)*2.0f)/2.0f;
59 set_rotation(rotation+adiff);
61 sn = get_snap_node(i);
62 set_position(position+ssn.position-sn.position);
70 Object *Object::get_link(unsigned) const
72 throw out_of_range("Object::get_link");
75 bool Object::break_link(Object &other)
77 unsigned nls = get_n_link_slots();
78 for(unsigned i=0; i<nls; ++i)
79 if(get_link(i)==&other)
85 void Object::break_links()
87 unsigned nls = get_n_link_slots();
88 for(unsigned i=0; i<nls; ++i)
92 const Shape *Object::get_shape() const
96 return get_type().get_shape();
99 bool Object::collide_ray(const Ray &ray, float *d) const
101 const Shape *s = get_shape();
105 Transform reverse_trans = Transform::rotation(rotation, Vector(0, 0, -1))*
106 Transform::translation(-position);
109 vector<Geometry::SurfacePoint<float, 3> > points = s->get_intersections(reverse_trans.transform(ray));
112 *d = points.front().distance;
116 return s->check_intersection(reverse_trans.transform(ray));
119 BoundingBox Object::get_bounding_box() const
121 const Shape *s = get_shape();
123 return BoundingBox();
125 Transform trans = Transform::translation(position)*
126 Transform::rotation(rotation, Vector(0, 0, 1));
127 return trans.transform(s->get_axis_aligned_bounding_box());