/* $XConsortium: viewxf1.pi,v 5.3 94/04/17 20:47:25 hersh Exp $ */

/*****************************************************************

Copyright (c) 1989, 1990, 1991,1990  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.

Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity 
pertaining to distribution of the software without specific, written 
prior permission.  

SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/


## viewxf1.pi -  
## Test that the view orientation transformation matrix is applied to output
## primitives. 
## Test with non-default view reference point, view plane normal(case 3D only) 
## and view up vector
## Draw polylines and verify the presence of pixels in transformed locations

source macro.pi
source xpmacro.pi

/*
 * im_confirm_viewrep (case 2D)
 * set up a view orientation matrix and a view representation
 * Verify that a polyline is rendered using that view rep.
 * 	viewrp - view reference point
 *	viewup - view up vector
 *	text - textual information for failure message
 */
macro im_confirm_viewrep(@viewrp,@viewup,@text)
	err = i_bogus_error();
	peval_view_ori_matrix(@viewrp,@viewup,&err,orientmtx);
	im_ifneq(err,0,"ERROR: %d in peval_view_ori_matrix\n",err);
	viewrep = I_Pview_rep(orientmtx,mapmtx,cliplimit,PIND_CLIP);
	pset_view_rep(1,1,&viewrep);
	im_confirm_line3(xdisplay,xwindow,1,1,xaxis3,5,1,
		"failed: 2D: %s, a line is missing\n",@text);
	im_confirm_line3(xdisplay,xwindow,1,1,yaxis3,5,1,
		"failed: 2D: %s, a line is missing\n",@text);
endmacro

/*
 * im_confirm_viewrep3 (case 3D)
 * set up a view orientation matrix and a view representation
 * Verify that a polyline is rendered using that view rep.
 * 	viewrp - view reference point
 *	viewup - view up vector
 *	viewpn - view plane normal 
 *	text - textual information for failure message
 */
macro im_confirm_viewrep3(@viewrp,@viewup,@viewpn,@text)
	err = i_bogus_error();
	peval_view_ori_matrix3(@viewrp,@viewpn,@viewup,&err, orientmtx3);
	im_ifneq(err,0,"ERROR: %d in peval_view_ori_matrix3\n",err);
	viewrep3 = I_Pview_rep3(orientmtx3,mapmtx3,cliplimit3,PIND_CLIP,PIND_CLIP,PIND_CLIP);
	pset_view_rep3(1,1,&viewrep3);
pupd_ws(1,PFLAG_PERFORM);
	im_confirm_line3(xdisplay,xwindow,1,1,xaxis3,5,1,
		"failed: 3D: %s, a line is missing\n",@text);
	im_confirm_line3(xdisplay,xwindow,1,1,yaxis3,5,1,
		"failed: 3D: %s, a line is missing\n",@text);
	im_confirm_line3(xdisplay,xwindow,1,1,zaxis3,5,1,
		"failed: 3D: %s, a line is missing\n",@text);
endmacro

tbegintest("viewxf1","view orientation transformation");

# INITIALIZE: data for output primitives
xaxis = IA_Ppoint(2, 0.5,0.5, 0.8,0.5);
yaxis = IA_Ppoint(2, 0.5,0.5, 0.5,0.8);
xaxis3 = IA_Ppoint3(2, 0.5,0.5,0.5, 0.8,0.5,0.5 );
yaxis3 = IA_Ppoint3(2, 0.5,0.5,0.5, 0.5,0.8,0.5 );
zaxis3 = IA_Ppoint3(2, 0.5,0.5,0.5, 0.5,0.5,0.8 );
plx = I_Ppoint_list(2,xaxis);
ply = I_Ppoint_list(2,yaxis);
plx3 = I_Ppoint_list3(2,xaxis3);
ply3 = I_Ppoint_list3(2,yaxis3);
plz3 = I_Ppoint_list3(2,zaxis3);
# initialize clipping limits,  (2D and 3D cases)
cliplimit = I_Plimit(0.0,1.0, 0.0,1.0);
cliplimit3 = I_Plimit3(0.0,1.0, 0.0,1.0, 0.0,1.0);
# initialize view mapping matrices to identity matrices
i_identity(mapmtx);
i_identity3(mapmtx3);

# SETUP: set up phigs and a workstation
i_open_phigs(NULL,PDEF_MEM_SIZE);
i_open_x_ws(1,&xdisplay,&xwindow,0,0,200,200);


# INITIALIZATION, OPERATION, VERIFICATION loop follows:
# testing 2D case:
# create and post a structure on ws1 and use view index 1 to draw the x and y 
# axes 
#
popen_struct(1);
ppost_struct(1,1,1.0);

pset_view_ind(1);
ppolyline(&plx);
ppolyline(&ply);

# testing non-default view reference point
vrp = I_Ppoint(0.1,0.2);
vup = I_Pvec(0.0,1.0);
im_confirm_viewrep(&vrp,&vup,"non-default view reference point");
i_pause();

# testing non-default view up vector
vrp = I_Ppoint(0.0,0.0);
vup = I_Pvec(0.25,1.0);
im_confirm_viewrep(&vrp,&vup,"non-default view up vector");
i_pause();


# testing 3D case:
# empty the structure, then use view index 1 to draw the x, y 
# and z axes with different colors  

pempty_struct(1);
pset_view_ind(1);
ppolyline3(&plx3);
ppolyline3(&ply3);
ppolyline3(&plz3);

# testing non-default view reference point
vrp3 = I_Ppoint3(0.1,0.25,0.1);
vup3 = I_Pvec3(0.0,1.0,0.0);
vpn3 = I_Pvec3(0.0,0.0,1.0);
im_confirm_viewrep3(&vrp3,&vup3,&vpn3,"non-default view reference point");
i_pause();

# testing non-default view up vector
vrp3 = I_Ppoint3(0.0,0.0,0.0);
vup3 = I_Pvec3(0.25,1.0,0.2);
vpn3 = I_Pvec3(0.0,0.0,1.0);
im_confirm_viewrep3(&vrp3,&vup3,&vpn3,"non-default view up vector");
i_pause();

# testing non-default view plane normal
vrp3 = I_Ppoint3(0.0,0.0,0.0);
vup3 = I_Pvec3(0.0,1.0,0.0);
vpn3 = I_Pvec3(0.2,0.2,1.0);
im_confirm_viewrep3(&vrp3,&vup3,&vpn3,"non-default view plane normal");
i_pause();

tendtest();
