/* $XConsortium: viewxf2.pi,v 5.2 94/04/17 20:47:26 rws 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.

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


## viewxf2.pi -  
## Test that the view mapping 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

/* confirm view representation test (2D case)
 * setup view rep structure, verify the output primitives
 *      win - window
 *      view - viewport
 *      text - textual info for failure message
 */

macro im_confirm_viewrep(@win,@view,@text)
	viewmap = I_Pview_map(@win,@view);
	err = i_bogus_error();
	peval_view_map_matrix(&viewmap,&err,mapmtx);
	im_ifneq(err,0,"ERROR: %d in pevalviewmappingtrix\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

/* confirm view representation test (3D case)
 * setup view rep structure, verify the output primitives
 *      win - window
 *      view - viewport
 *      proj - projection type
 *      prp - projection reference point
 *      vpd - view plane distance
 *      bpd - back plane distance
 *      fpd - front plane distance
 *      text - textual info for failure message
 */
macro im_confirm_viewrep3(@win,@view,@proj,@prp,@vpd,@bpd,@fpd,@text)
	viewmap3 = I_Pview_map3(@win,@view,@proj,@prp,@vpd,@bpd,@fpd);
	err = i_bogus_error();
	peval_view_map_matrix3(&viewmap3,&err,mapmtx3);
	im_ifneq(err,0,"ERROR: %d in pevalviewmappingtrix3\n",err);
	viewrep3 = I_Pview_rep3(orientmtx3,mapmtx3,cliplimit3,PIND_CLIP,PIND_CLIP,PIND_CLIP);
	pset_view_rep3(1,1,&viewrep3);
	im_confirm_line3(xdisplay,xwindow,1,1,xaxis3,7,1,
 		"failed: 3D, %s, a line is missing\n",@text);
	im_confirm_line3(xdisplay,xwindow,1,1,yaxis3,7,1,
 		"failed: 3D, %s, a line is missing\n",@text);
	im_confirm_line3(xdisplay,xwindow,1,1,zaxis3,7,1,
 		"failed: 3D, %s, a line is missing\n",@text);
endmacro

tbegintest("viewxf2","view mapping transformation");


# initialize data for output primitives 
xaxis = IA_Ppoint(2, 0.0,0.0, 0.6,0.0);
yaxis = IA_Ppoint(2, 0.0,0.0, 0.0,0.6);
xaxis3 = IA_Ppoint3(2, 0.0,0.0,0.0, 0.6,0.0,0.0 );
yaxis3 = IA_Ppoint3(2, 0.0,0.0,0.0, 0.0,0.6,0.0 );
zaxis3 = IA_Ppoint3(2, 0.0,0.0,0.0, 0.0,0.0,0.6 );
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);

# intialize view orientation matrices to identity matrices
i_identity(orientmtx);
i_identity3(orientmtx3);

# initialize window 
window = I_Plimit(-1.0,1.0, -1.0,1.0);

# SETUP: open phigs and two workstations
i_open_phigs(NULL,PDEF_MEM_SIZE);
i_open_x_ws(1,&xdisplay,&xwindow,0,0,200,200);




# 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);

# same aspect ratio
viewport = I_Plimit(0.0,0.75, 0.0,0.75);
cliplimit = I_Plimit(0.0,0.75, 0.0,0.75);
im_confirm_viewrep(window,viewport,"same window-viewport aspect ratio");
i_pause();

# different aspect ratio
viewport = I_Plimit(0.0,1.0, 0.0,0.75);
cliplimit = I_Plimit(0.0,1.0, 0.0,0.75);
im_confirm_viewrep(window,viewport,"different window-viewport aspect ratio");
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);

# initialize viewport and cliplimit for 3D case
viewport3 = I_Plimit3(0.2,0.8, 0.2,0.8, 0.2,0.8);
cliplimit3 = I_Plimit3(0.2,0.8, 0.2,0.8, 0.2,0.8);

# projection is PERSPECTIVE
prp3 = I_Ppoint3(5.0,5.0,10.0);
im_confirm_viewrep3(window,viewport3,PTYPE_PERSPECT,prp3,0.0,-1.0,1.0,
	"perspective projection");
i_pause();


# change projection to PARALLEL
im_confirm_viewrep3(window,viewport3,PTYPE_PARAL,prp3,0.0,-1.0,1.0,
	"parallel projection");
i_pause();

# change view, front and back plane distances
im_confirm_viewrep3(window,viewport3,PTYPE_PERSPECT,prp3,1.0,-1.0,1.0,
	"testing a different view plane distance");
i_pause();

# change prp
prp3 = I_Ppoint3(1.0,5.0,10.0);
im_confirm_viewrep3(window,viewport3,PTYPE_PERSPECT,prp3,1.0,-1.0,1.0,
	"testing a different projection reference point");
i_pause();

# change viewport
viewport3 = I_Plimit3(0.0,0.5,0.0,0.5,0.0,1.0);
im_confirm_viewrep3(window,viewport3,PTYPE_PERSPECT,prp3,1.0,-1.0,1.0,
	"testing a different viewport");


tendtest();
