View Single Post
Old 15th July 2004, 02:50 AM   #2
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,565
Default

You need to call a couple of other functions. Normals should be recalculated and the bounding box should be remade.

Here's the actual code used for Vertex->Align-to-axis.

Code:
Prototype void selected_vertices_align_to_axis(int axis)
{
	List *vl = ac_selection_get_vertices_all();
	add_undoable_vertex_positions("align vertices", vl);

	for (List *p = vl; p != NULL; p = p->next)
		{
		Vertex *v = (Vertex *)p->data;

		switch (axis)
			{
			case 0: // x
				v->x= 0.0;
				break;
			case 1: // y
				v->y = 0.0;
				break;
			case 2: // z
				v->z = 0.0;
				break;
			}
		}

	selected_calc_normals();
	find_bounding_box();
	display_message("%d vertices aligned to axis", list_count(vl));
	list_free(&vl); 
	redraw_all();
}
Whilst vertex_set_point will move the vertex, you really need to make it undoable like above. add_undoable_vertex_positions will record the origional positions of the given vertices and restore them after an undo (and put them back for a redo).

Note that selected_calc_normals will also recalculate any subdivisions too.

Andy
Andy is offline   Reply With Quote