Beispiel #1
0
// this function calculates the normal using the local coordinates;
SbVec3f Cone::calculate_normal(SbVec3f *starting_position, SbVec3f *ray_direction, float t){
    SbVec3f poi, normal;

    poi = point_of_intersection( starting_position, ray_direction, t);
    normal[0] = -1 * poi[0];//(sp + (t *(rd))); //ntc
    normal[1] = 1 * poi[1];
    normal[2] = 1 * poi[2];
    return normal;
}
Beispiel #2
0
/**
 * @brief given a quad, this function applies linear regression to the points
 *        between each of the vertices to improve the estimate of where the
 *        vertices actually are
 *
 * @param quad  the \c koki_quad_t* that should be refined
 */
void koki_quad_refine_vertices(koki_quad_t *quad)
{

	koki_point2Df_t vects[4][2];
	float vals[4][2];
	koki_point2Df_t avgs[4];
	GSList *start, *end;

	if (quad == NULL)
		return;


	/* perform PCA on edges between vertices */
	koki_debug(KOKI_DEBUG_INFO, "PCA on quad\n");
	koki_debug(KOKI_DEBUG_INFO, "-----------\n");

	/* side 0 (v0 --> v1) */
	get_centre_section(quad->links[0], quad->links[1], &start, &end);
	koki_pca(start, end, vects[0], vals[0], &avgs[0]);
	pca_output_debug(vects[0], vals[0], avgs[0], 0);

	/* side 1 (v1 --> v2) */
	get_centre_section(quad->links[1], quad->links[2], &start, &end);
	koki_pca(start, end, vects[1], vals[1], &avgs[1]);
	pca_output_debug(vects[1], vals[1], avgs[1], 1);

	/* side 2  (v2 --> v3) */
	get_centre_section(quad->links[2], quad->links[3], &start, &end);
	koki_pca(start, end, vects[2], vals[2], &avgs[2]);
	pca_output_debug(vects[2], vals[2], avgs[2], 2);

	/* side 3 (v3 --> [end]) */
	get_centre_section(quad->links[3], NULL, &start, &end);
	koki_pca(start, end, vects[3], vals[3], &avgs[3]);
	pca_output_debug(vects[3], vals[3], avgs[3], 3);


	/* set vertex positions based on the intersection of PCA's
	   significant eigen vectors */

	/* vertex 0 (intersection of e3 and e0) */
	quad->vertices[0]
		= point_of_intersection(avgs[3],
					significant_eigen_vector(vects[3], vals[3]),
					avgs[0],
					significant_eigen_vector(vects[0], vals[0]));

	/* vertex 1 (intersection of e0 and e1) */
	quad->vertices[1]
		= point_of_intersection(avgs[0],
					significant_eigen_vector(vects[0], vals[0]),
					avgs[1],
					significant_eigen_vector(vects[1], vals[1]));

	/* vertex 2 (intersection of e1 and e2) */
	quad->vertices[2]
		= point_of_intersection(avgs[1],
					significant_eigen_vector(vects[1], vals[1]),
					avgs[2],
					significant_eigen_vector(vects[2], vals[2]));

	/* vertex 3 (intersection of e2 and e3) */
	quad->vertices[3]
		= point_of_intersection(avgs[2],
					significant_eigen_vector(vects[2], vals[2]),
					avgs[3],
					significant_eigen_vector(vects[3], vals[3]));



}