📄 gp2_point.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)gp2_point.c 1.1 92/07/30 Copyright Sun Micro";#endif/* * Copyright (c) 1988 by Sun Microsystems, Inc. */#include <stdio.h>#include <errno.h>#include <ctype.h>#include <math.h>#include <sys/types.h>#include <sys/ioctl.h>#include <pixrect/pixrect.h>#include <pixrect/pixrect_hs.h>#include <pixrect/memreg.h>#include <pixrect/cg2reg.h>#include <pixrect/gp1cmds.h>#include <sun/gpio.h>#include <suntool/sunview.h>#include <suntool/fullscreen.h>#include <suntool/gfx_hs.h>#include "gp2test.h"#include "gp2test_msgs.h"#include "sdrtns.h"extern char *sprintf();extern int debug, verbose;extern short *gp1_shmem;extern int ioctlfd;extern short statblk;extern float xscale, xoffset, yscale, yoffset, zscale, zoffset;/* ************************************************************************** * Get the 3D matrix stored that we will be using. ************************************************************************** */get_matrix(mat, shmptr, offset, dest) float mat[4][4]; short *shmptr; int offset; int dest;{ int i; float *fp1, *fp2; *shmptr++ = GP1_USE_CONTEXT | statblk; *shmptr++ = GP1_SET_MAT_NUM | dest; *shmptr++ = GP1_GET_MAT_3D | dest; *shmptr++ = -1; fp1 = (float *) shmptr; for (i = 0; i < 32; i++) *shmptr++ = -1; *shmptr++ = GP1_EOCL; if ((gp1_post(gp1_shmem, offset, ioctlfd)) !=0) gp_send_message(-POST_ERROR, FATAL, get_matrix_msg1); if ((gp1_sync(gp1_shmem, ioctlfd)) !=0) gp_send_message(-SYNC_ERROR, FATAL, get_matrix_msg2); fp2 = (float *) mat; bcopy((char *)fp1, (char *)fp2, 16*sizeof(float));}/* ************************************************************************* * get_pts * * Get the points that will be used in the transformation. ************************************************************************* */get_pts(k, points) int k; float points[4 * MAXPTS];{ float *fp1; switch(k) { case 0 : fp1 = points; fp1[0] = 1.0; fp1[1] = 1.0; fp1[2] = 1.0; fp1[3] = 1.0; break; case 1 : fp1 = points; fp1[0] = 0.000002; fp1[1] = 0.000004; fp1[2] = 0.000006; fp1[3] = 0.000008; break; case 2 : fp1 = points; fp1[0] = 999990.0; fp1[1] = 999991.0; fp1[2] = 999992.0; fp1[3] = 999993.0; break; case 3 : fp1 = points; fp1[0] = 791.0345; fp1[1] = 800.74050; fp1[2] = 8.00034; fp1[3] = 11.0; break; }}/* ************************************************************************* * set_pts_in_ram * * Send the points fetch in the above function to the GP2 in a * context block. * Tell the GP2 to multiply the points with the matrix and put * the result in the GP2 context block. ************************************************************************* */ float *set_pts_in_ram(points, shmptr, offset) float points[4 * MAXPTS]; short *shmptr; int offset;{ float *fp1, *fp2; shmptr = &((short *) gp1_shmem)[offset]; *shmptr++ = GP1_USE_CONTEXT | statblk; *shmptr++ = GP1_MUL_POINT_FLT_3D; *shmptr++ = 1; /* count */ fp1 = points; fp2 = (float *) shmptr; GP1_PUT_F(shmptr, *fp1); GP1_PUT_F(shmptr, *(fp1 + 1)); GP1_PUT_F(shmptr, *(fp1 + 2)); GP1_PUT_F(shmptr, *(fp1 + 3)); *shmptr++ = -1; /* Flag */ *shmptr++ = GP1_EOCL; if ((gp1_post(gp1_shmem, offset, ioctlfd)) != 0) gp_send_message(-POST_ERROR, FATAL, set_pts_msg1); if ((gp1_sync(gp1_shmem, ioctlfd)) !=0) gp_send_message(-SYNC_ERROR, FATAL, set_pts_msg2); return(fp2);}/* ************************************************************************* * multiply_pts * * This routine will take the points returned from get_pts routine * and multiply them with the matrix returned from get_matrix routine * and compare them with the transformed points in GP2 context block. ************************************************************************* */multiply_pts(mat, points, fp2) float mat[4][4]; float points[4 * MAXPTS]; float *fp2;{ float *fp1, error; float tfp2[4]; float fpoint[4]; int i, err_cnt = 0; fp1 = points; fpoint[0] = fp1[0] * mat[0][0] + fp1[1] * mat[1][0] + fp1[2] * mat[2][0] + fp1[3] * mat[3][0]; fpoint[1] = fp1[0] * mat[0][1] + fp1[1] * mat[1][1] + fp1[2] * mat[2][1] + fp1[3] * mat[3][1]; fpoint[2] = fp1[0] * mat[0][2] + fp1[1] * mat[1][2] + fp1[2] * mat[2][2] + fp1[3] * mat[3][2]; fpoint[3] = fp1[0] * mat[0][3] + fp1[1] * mat[1][3] + fp1[2] * mat[2][3] + fp1[3] * mat[3][3]; bcopy((char *)fp2, (char *)tfp2, 4*sizeof(float)); if (debug) { (void) sprintf(msg, "Original: %f %f %f %f\n", fp1[0], fp1[1], fp1[2], fp1[3]); gp_send_message(0, DEBUG, msg); (void) sprintf(msg, "Result: %f %f %f %f\n", tfp2[0], tfp2[1], tfp2[2], tfp2[3]); gp_send_message(0, DEBUG, msg); (void) sprintf(msg, "Should be: %f %f %f %f\n", fpoint[0], fpoint[1], fpoint[2], fpoint[3]); gp_send_message(0, DEBUG, msg); } for (i = 0; i < 4; i++) { if (tfp2[i] != fpoint[i]) { error = ((fpoint[i] - tfp2[i]) / fpoint[i]); if ((error > TOLERANCE) || (error < -TOLERANCE)) { err_cnt++; (void) sprintf(msg, multiply_pts_msg, fpoint[i],tfp2[i],i, *((int *)&fpoint[i]),*((int *)&tfp2[i])); gp_send_message(-DATA_ERROR, FATAL, msg); } } } return(err_cnt);}/* ************************************************************************* * set view port points * write view port points to gp2 ************************************************************************** */short *set_view_port(fpoint0, fpoint1, shmptr, dest) float fpoint0[4]; float fpoint1[4]; short *shmptr; int dest;{ *shmptr++ = GP1_USE_CONTEXT | statblk; *shmptr++ = GP1_SET_MAT_NUM | dest; fpoint0[0] = 100; fpoint0[1] = 200; fpoint0[2] = 300; fpoint1[0] = 400; fpoint1[1] = 500; fpoint1[2] = 600; *shmptr++ = GP1_SET_VWP_3D; xscale = (fpoint1[0] - fpoint0[0]) / 2.0; xoffset = fpoint0[0] + xscale; yscale = (fpoint1[1] - fpoint0[1]) / 2.0; yoffset = fpoint0[1] + yscale; zscale = (fpoint1[2] - fpoint0[2]); zoffset = fpoint0[2]; GP1_PUT_F(shmptr, xscale); GP1_PUT_F(shmptr, xoffset); GP1_PUT_F(shmptr, yscale); GP1_PUT_F(shmptr, yoffset); GP1_PUT_F(shmptr, zscale); GP1_PUT_F(shmptr, zoffset); return(shmptr);}/* ************************************************************************** * set_matrix * * This routine will the matrix sent to it and post the matix * to the GP2 using the same context block. ************************************************************************** */short *set_matrix(mat, shmptr, offset, dest) float mat[4][4]; short *shmptr; int offset; int dest;{ int i; *shmptr++ = GP1_GET_MAT_3D | dest; *shmptr++ = -1; for (i = 0; i < 32; i++) *shmptr++ = -1; *shmptr++ = GP1_SET_MAT_3D | dest; GP1_PUT_F(shmptr, mat[0][0]); GP1_PUT_F(shmptr, mat[0][1]); GP1_PUT_F(shmptr, mat[0][2]); GP1_PUT_F(shmptr, mat[0][3]); GP1_PUT_F(shmptr, mat[1][0]); GP1_PUT_F(shmptr, mat[1][1]); GP1_PUT_F(shmptr, mat[1][2]); GP1_PUT_F(shmptr, mat[1][3]); GP1_PUT_F(shmptr, mat[2][0]); GP1_PUT_F(shmptr, mat[2][1]); GP1_PUT_F(shmptr, mat[2][2]); GP1_PUT_F(shmptr, mat[2][3]); GP1_PUT_F(shmptr, mat[3][0]); GP1_PUT_F(shmptr, mat[3][1]); GP1_PUT_F(shmptr, mat[3][2]); GP1_PUT_F(shmptr, mat[3][3]); *shmptr++ = GP1_GET_MAT_3D | dest; *shmptr++ = -1; for (i = 0; i < 32; i++) *shmptr++ = -1; *shmptr++ = GP1_EOCL; if ((gp1_post(gp1_shmem, offset, ioctlfd)) !=0) gp_send_message(-POST_ERROR, FATAL, set_matrix_msg1); if ((gp1_sync(gp1_shmem, ioctlfd)) != 0) gp_send_message(-SYNC_ERROR, FATAL, set_matrix_msg2); return(shmptr);}/* ************************************************************************* * get_line * * This routine will get the start and end points for the line * to be clip checked. ************************************************************************* */get_line(k, points) int k; float points[8 * MAXLINES];{ float *fp_o_start, *fp_o_end; switch (k) { case 0 : /* all in left side */ fp_o_start = &points[0]; fp_o_start[0] = 1; fp_o_start[1] = -1; fp_o_start[2] = 1; fp_o_end = &points[4]; fp_o_end[0] = 1; fp_o_end[1] = 1; fp_o_end[2] = 1; break; case 1 : /* all in top */ fp_o_start = &points[0]; fp_o_start[0] = -1; fp_o_start[1] = 1; fp_o_start[2] = 1; fp_o_end = &points[4]; fp_o_end[0] = 1; fp_o_end[1] = 1; fp_o_end[2] = 1; break; case 2 : /* all in right side */ fp_o_start = &points[0]; fp_o_start[0] = -1; fp_o_start[1] = 1; fp_o_start[2] = 1; fp_o_end = &points[4]; fp_o_end[0] = -1; fp_o_end[1] = -1; fp_o_end[2] = 1; break; case 3 : /* all in bottom */ fp_o_start = &points[0]; fp_o_start[0] = -1; fp_o_start[1] = -1; fp_o_start[2] = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -