void
dir_vect(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;
    int rc = 0;    /* the return code value from str_dbl() */
    vect_t Dir;	   /* Direction vector x, y and z */

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current direct coors */
	fprintf(stdout, "(x, y, z) = (%4.2f, %4.2f, %4.2f)\n",
	       direct(X), direct(Y), direct(Z));
	return;
    }
    if ((rc = str_dbl(buffer+i, &Dir[X])) == 0) {
	/* get direct x coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Dir[Y])) == 0) {
	/* get direct y coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Dir[Z])) == 0) {
	/* get direct z coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    VUNITIZE(Dir);
    direct(X) = Dir[X];
    direct(Y) = Dir[Y];
    direct(Z) = Dir[Z];
    dir2ae();
}
Example #2
0
/**
 * R E A D _ M A T
 */
void read_mat (struct rt_i *rtip)
{
    double scan[16] = MAT_INIT_ZERO;
    char	*buf;
    int		status = 0x0;
    mat_t	m;
    mat_t       q;

    while ((buf = rt_read_cmd(stdin)) != (char *) 0) {
	if (bu_strncmp(buf, "eye_pt", 6) == 0) {
	    if (sscanf(buf + 6, "%lf%lf%lf", &scan[X], &scan[Y], &scan[Z]) != 3) {
		bu_exit(1, "nirt: read_mat(): Failed to read eye_pt\n");
	    }
	    target(X) = scan[X];
	    target(Y) = scan[Y];
	    target(Z) = scan[Z];
	    status |= RMAT_SAW_EYE;
	} else if (bu_strncmp(buf, "orientation", 11) == 0) {
	    if (sscanf(buf + 11,
		       "%lf%lf%lf%lf",
		       &scan[X], &scan[Y], &scan[Z], &scan[W]) != 4) {
		bu_exit(1, "nirt: read_mat(): Failed to read orientation\n");
	    }
	    MAT_COPY(q, scan);
	    quat_quat2mat(m, q);
	    if (nirt_debug & DEBUG_MAT)
		bn_mat_print("view matrix", m);
	    azimuth() = atan2(-m[0], m[1]) / DEG2RAD;
	    elevation() = atan2(m[10], m[6]) / DEG2RAD;
	    status |= RMAT_SAW_ORI;
	} else if (bu_strncmp(buf, "viewrot", 7) == 0) {
	    if (sscanf(buf + 7,
		       "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
		       &scan[0], &scan[1], &scan[2], &scan[3],
		       &scan[4], &scan[5], &scan[6], &scan[7],
		       &scan[8], &scan[9], &scan[10], &scan[11],
		       &scan[12], &scan[13], &scan[14], &scan[15]) != 16) {
		bu_exit(1, "nirt: read_mat(): Failed to read viewrot\n");
	    }
	    MAT_COPY(m, scan);
	    if (nirt_debug & DEBUG_MAT)
		bn_mat_print("view matrix", m);
	    azimuth() = atan2(-m[0], m[1]) / DEG2RAD;
	    elevation() = atan2(m[10], m[6]) / DEG2RAD;
	    status |= RMAT_SAW_VR;
	}
    }

    if ((status & RMAT_SAW_EYE) == 0) {
	bu_exit(1, "nirt: read_mat(): Was given no eye_pt\n");
    }
    if ((status & (RMAT_SAW_ORI | RMAT_SAW_VR)) == 0) {
	bu_exit(1, "nirt: read_mat(): Was given no orientation or viewrot\n");
    }

    direct(X) = -m[8];
    direct(Y) = -m[9];
    direct(Z) = -m[10];

    dir2ae();

    targ2grid();
    shoot("", 0, rtip);
}