lcathey++at++ford.com
Tue, 23 Jan 1996 08:39:02 -0500
Below is the sample code I received from StereoGraphics when I purchased some
glasses
smm002% more plane.c
/*
plane.c
by Robert Akka
StereoGraphics Corporation
April 2, 1991
Demonstrates how to wtite a simple stereo application in SGI GL.
This application puts a crude stereo image of a paper airplane on the
screen, rotating about its center. To quit the user presses the
escape key, or selects quit from the application window menu.
To compile: cc plane.c -o plane -lgl
*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <gl.h>
#include <device.h>
#include <get.h> /* subfield height in pixels */
#include <gl/addrs.h> /* YSTEREO + YBLANK */
#include <gl/cg2vme.h>
#define YSTEREO 491
#define YOFFSET_LEFT 532
/* #define PRE_IRIX33 uncomment this #define if not running on IRIX 3.3 or
later */
#define SPEED 10 /* this should be an int that divides evenly into 3600 */
#ifndef PRE_IRIX33
#define XMAXSCREEN 1279 /* getgdesc(GP_XPMAX) */
#define YMAXSCREEN 1023 /* getgdesc(GP_YPMAX) */
#endif
main ( )
{
int position = 0, dev_id;
short value, mode;
long monitor, mouse_loc ;
/* open Full screen window monitor */
prefposition ( 0 , XMAXSCREEN, 0, YMAXSCREEN );
winopen ("");
monitor = getmonitor(); /* save monitor mode */
if (is_stereo()) /* if hardware is stereo-ready */
setmonitor(STR_RECT); /*change hardware to stereo mode */
else {
printf("Error: Hardware is not stereo-ready / n " ) ;
exit (0) ;
} /* save mouse y location */
/* save matrix mode */
mouse_loc = getvaluator(CURSORY); /* set projection matxix mode*/
mode = getmmode() ;
mmode(MPROJECTION);
doublebuffer();
RGBmode();
gconfig();
qdevice(ESCKEY);
qdevice(WINQUIT);
viewport(0, XMAXSCREEN, 0, YMAXSCREEN);
frontbuffer(1);
cpack(0x00111111); /* grey background*/
clear () ;
frontbuffer(0);
/* limit mouse to one subfield */
setvaluator(CURSORY, YSTEREO / 2, 0, YSTEREO);
/* redraw rotating image until quit */
while (1) {
if (qtest()) {
dev_id = qread(&value);
if (dev_id == ESCKEY || dev_id == WINQUIT)
break;
} /*leave while loop if quit or ESC*/
redraw(position--);
if (position < 0)
position = 3600 / SPEED;
}
/* restore to origin state and quit*/
setvaluator(CURSORY, mouse_loc, 0, YMAXSCREEN);
setmonitor (monitor) ; /* get out oF STEREO MODE*/
mmode (mode ) ; /* return to ORIGINAL MODE*/
exit ( 0 ) ;
} /* end of main */
int is_stereo() {
/* This routine returns 1 if Hardware is STEREO READY, 0 IF NOT*/
long rw1, rw2;
/* for: pre-IRIX 3.3 systems, */
/* is read/write or read-onl:*/
#ifdef PRE_IRIX33
rw1 = getvideo(DE_R1);
rw2 = rw1 ^= DER1_STEREO;
setvideo(DE_R1, rw2);
rw2 = getvideo(DE_R1);
if (! (rw1 == rw2))
return(1);
rw1 = rw2 ^= DER1_STEREO;
setvideo(DE_R1, rw2);
rw2 = getvideo(DE_R1);
return ( ! (rw1 == rw2 ) ) ;
#else
return(getgdesc(GD_STEREO));
#endif
/* end of is_stereo */
}
redraw(position)
int position;
/* This routine puts a stereo image of a stereo
image of a paper airplane onto the screen */
{
/* draw left: subfield */
viewport(0, XMAXSCREEN, YOFFSET_LEFT, YOFFSET_LEFT + YSTEREO);
cpack(0x00111111); /* grey background */
clear () ;
/* z-coordinate of plane of zero parallax is O.O.
In that plane, the coord range drawn to the screen will be
(-6.0 to 6.0, -4.8 to 4.8).
z-coordinate clipping planes are -6.0 and 6.0.
The eyes are set at world coord distance 14.5 from the plane of
zero parallax, and the eye separation is 0.62 in world coords.
These two values were calculated using equations ll to 15, and
17 to 19 in chapter 5. */
stereoproj(-6.0, 6.0, -4.8, 4.8, 6.0, -6.0, 0.0, 14.5, -0.31);
rotate(position * SPEED, 'y');
rotate(-100, 'x');
draw_airplane() ;
/* draw right subfield */
viewport(0, XMAXSCREEN, 0, YSTEREO);
cpack(0x00111111); /* gray background */
clear() ;
/*( Same as above stereoproj () call, except that eye arg is positive */
stereoproj(-6.0, 6.0, -4.8, 4.8, 6.0,-6.0, 0.0, 14.5, 0.31);
rotate(position * SPEED, 'y');
rotate(-100, 'x');
draw_airplane();
swapbuffers() ; /* update screen */
} /* end of redraw */
draw_airplane()
/* This routine draws a crude "paper airplane." */
{
static float airplane[9][3] = {
{ 0.0, 0.5, -4.5},
{ 3.0, 0.5, -4.5},
{ 3.0, 0.5, -3.5},
{ 0.0, 0.5, 0.0},
{ 0.0, 0.5, 3.25},
{ 0.0, -0.5, 5.5},
{-3.0, 0.5, -3.5},
{-3.0, 0.5, -4.5},
{ 0.0, -0.5, -4.5}
};
cpack(0x00b030ff); /* Set color to violet */
bgnclosedline();
v3f(airplane[6]);
v3f(airplane[7]);
v3f(airplane[1]);
v3f(airplane[2]);
v3f(airplane[4]);
endclosedline( ) ;
bgnclosedline();
v3f(airplane[0]);
v3f(airplane[4]);
v3f(airplane[5]);
v3f(airplane[8]);
endclosedline( ) ;
bgnline () ;
v3f(airplane[6]);
v3f(airplane[3]);
v3f(airplane[2]);
endline() ;
}
/* end of draw airplane */
stereoproj (xmin, xmax, ymin, ymax, znear, zfar, zzps, dist, eye)
float xmin, xmax, ymin, ymax, znear, zfar, zzps, dist, eye;
/* This routine performs the perspective projection for one eye's subfield.
The projection is in the direction of the negative z axis.
xmin, xmax, ymin, ymax = the coordinate range, in the plane of zero
parallax setting, that will be displayed on the screen. The rat++at++o
between (xmax-xmin) and (ymax-ymin) should equal the aspect ratio of
the display.
znear, zfar = the z-coordinate values of the clipping planes.
zzps = the z-coordinate of the plane of zero parallax setting.
dist = the distance from the center of projection to the plane of zero
parallax.
eye = half the eye separation; positive for the right: eye subfield,
negative for the leet eye subfield. */
{
float xmid, ymid, clip_near, clip_far, top, bottom, left, right, dx, dy,
n_over_d;
dx = xmax - xmin;
dy = ymax - ymin;
xmid = (xmax + xmin) / 2.0;
ymid = (ymax + ymin) / 2.0;
clip_near = dist + zzps - znear;
clip_far = dist + zzps - zfar;
n_over_d = clip_near / dist;
top = n_over_d * dy / 2.0;
bottom = -top;
right = n_over_d * (dx / 2.0 - eye);
left = n_over_d * (-dx / 2.0 - eye);
window (left, right, bottom, top, clip_near, clip_far);
translate(-xmid - eye, -ymid, -zzps - dist);
} /* end of stereoproj */
-- larry cathey ford research lab 20000 rotunda md 2122-srl dearborn, michigan 48121 ph 313 337-5327 fax 313 248-4602 email: lcathey++at++smm002.srl.ford.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:17 PDT