Commit 17bff2e5 authored by Ken Martin's avatar Ken Martin
Browse files

Initial revision

parent be443bf4
/*=========================================================================
Program: Visualization Library
Module: XglrCam.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlXglrCamera - Camera for Suns XGL
// .SECTION Description
// vlXglrCamera is a concrete implementation of the abstract class vlCamera.
// vlXglrCamera interfaces to the Hewlett-Packard starbase rendering library.
#ifndef __vlXglrCamera_hh
#define __vlXglrCamera_hh
#include "Camera.hh"
class vlXglrRenderer;
class vlXglrCamera : public vlCamera
{
public:
char *GetClassName() {return "vlXglrCamera";};
void Render(vlRenderer *ren);
void Render(vlXglrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrLgt.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlXglrLight - Light for Suns XGL
// .SECTION Description
// vlXglrLight is a concrete implementation of the abstract class vlLight.
// vlXglrLight interfaces to the Hewlett-Packard starbase rendering library.
#ifndef __vlXglrLight_hh
#define __vlXglrLight_hh
#include "Light.hh"
class vlXglrRenderer;
class vlXglrLight : public vlLight
{
protected:
public:
char *GetClassName() {return "vlXglrLight";};
void Render(vlRenderer *ren,int light_index);
void Render(vlXglrRenderer *ren,int light_index);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrProp.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlXglrProperty - Suns XGL property
// .SECTION Description
// vlXglrProperty is a concrete implementation of the abstract class
// vlProperty. vlXglrProperty interfaces to Suns XGL rendering library.
#ifndef __vlXglrProperty_hh
#define __vlXglrProperty_hh
#include "Property.hh"
class vlXglrRenderer;
class vlXglrProperty : public vlProperty
{
public:
char *GetClassName() {return "vlXglrProperty";};
void Render(vlRenderer *ren);
void Render(vlXglrRenderer *ren);
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrRen.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlXglrRenderer - Suns XGL renderer
// .SECTION Description
// vlXglrRenderer is a concrete implementation of the abstract class
// vlRenderer. vlXglrRenderer interfaces to Suns XGL graphics library.
#ifndef __vlXglrRenderer_hh
#define __vlXglrRenderer_hh
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "Renderer.hh"
#include <xgl/xgl.h>
#define MAX_LIGHTS 12
class vlXglrRenderer : public vlRenderer
{
protected:
Xgl_light XglrLights[MAX_LIGHTS];
int NumberOfLightsBound;
Xgl_3d_ctx Context;
public:
vlXglrRenderer();
char *GetClassName() {return "vlXglrRenderer";};
void PrintSelf(ostream& os, vlIndent indent);
void Render(void);
vlGeometryPrimitive *GetPrimitive(char *);
int UpdateActors(void);
int UpdateCameras(void);
int UpdateLights(void);
Xgl_3d_ctx *GetContext() {return &(this->Context);};
Xgl_win_ras *GetRaster()
{return ((vlXglrRenderWindow *)(this->GetRenderWindow()))->GetRaster();};
Xgl_light *GetLightArray() {return this->XglrLights;};
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrRenW.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlXglrRenderWindow - Suns XGL rendering window
// .SECTION Description
// vlXglrRenderWindow is a concrete implementation of the abstract class
// vlRenderWindow. vlXglrRenderer interfaces to Suns XGL graphics library.
#ifndef __vlXglrRenderWindow_hh
#define __vlXglrRenderWindow_hh
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "XRenWin.hh"
#include <xgl/xgl.h>
class vlXglrRenderWindow : public vlXRenderWindow
{
public:
vlXglrRenderWindow();
char *GetClassName() {return "vlXglrRenderWindow";};
void PrintSelf(ostream& os, vlIndent indent);
vlRenderer *MakeRenderer();
vlActor *MakeActor();
vlLight *MakeLight();
vlCamera *MakeCamera();
vlProperty *MakeProperty();
vlTexture *MakeTexture();
void Start(void);
void Frame(void);
void WindowInitialize(void);
void Initialize(void);
virtual void SetFullScreen(int);
void WindowRemap(void);
void PrefFullScreen(void);
void SetSize(int,int);
// stereo rendering stuff
virtual void StereoUpdate();
// Description:
// Set/Get the pixel data of an image, transmitted as RGBRGB...
virtual unsigned char *GetPixelData(int x,int y,int x2,int y2);
virtual void SetPixelData(int x,int y,int x2,int y2,unsigned char *);
// Xwindow stuff
int GetDesiredDepth();
Colormap GetDesiredColormap();
Visual *GetDesiredVisual();
int CreateXWindow(Display *,int x,int y,int w,int h,int depth,
char name[80]);
Xgl_3d_ctx *GetContext() {return &(this->Context);};
Xgl_win_ras *GetRaster() {return &(this->WindowRaster);};
protected:
Xgl_3d_ctx Context;
Xgl_win_ras WindowRaster;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrText.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlKXglrTexture - starbase texture map object
// .SECTION Description
// vlXglrTexture is a concrete implementation of the abstract class vlTexture.
// currently we don't support texture mapping on starbase.
#ifndef __vlXglrTexture_hh
#define __vlXglrTexture_hh
#include "Texture.hh"
class vlXglrRenderer;
class vlXglrTexture : public vlTexture
{
public:
vlXglrTexture();
char *GetClassName() {return "vlXglrTexture";};
void Load(vlRenderer *ren);
void Load(vlXglrRenderer *ren);
protected:
vlTimeStamp LoadTime;
long Index;
static long GlobalIndex;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: XglrCam.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "XglrCam.hh"
#include "XglrRenW.hh"
#include "XglrRen.hh"
#include <xgl/xgl.h>
extern Xgl_sys_state xglr_sys_state;
/****
*
* view_calc
*
* Calculate the View Transform consisting of the orientation given by
* the eye position and the perspective given by the field of view.
* Then redisplay the wireframe object.
*
***/
static void
view_calc (Xgl_pt_f3d *eye, Xgl_pt_f3d *focus,
float near, float far, float fov, float twist,
Xgl_trans *trans, float conv, float eye_ang, float aspect)
{
#ifndef PI
#define PI 3.1415926
#endif
Xgl_pt pt;
Xgl_pt_f3d pt_f3d;
Xgl_trans view_trans;
Xgl_trans perspective_trans;
Xgl_matrix_f3d matrix;
float temp;
float distance;
float x_view_ratio;
float distance_old;
int i;
float gltan;
float top,bottom,left,right;
/* do some stereo calculations */
eye_ang = tan(eye_ang*PI/180.0)*conv;
gltan = tan(fov*PI/360.0);
top = gltan*near;
bottom = -top;
gltan = tan(fov*aspect*M_PI/360.0);
left = bottom*aspect - eye_ang/conv*near;
right = top*aspect - eye_ang/conv*near;
/* Translate the origin of VDC to the eye position in WC */
pt.pt_type = XGL_PT_F3D;
pt.pt.f3d = &pt_f3d;
pt_f3d.x = -eye->x;
pt_f3d.y = -eye->y;
pt_f3d.z = -eye->z;
xgl_transform_translate (*trans, &pt, XGL_TRANS_REPLACE);
/* first rotate y */
distance = sqrt((eye->x-focus->x)*(eye->x-focus->x) +
(eye->z-focus->z)*(eye->z-focus->z));
if (distance > 0.0)
{
matrix[0][0] = (eye->z-focus->z)/distance;
matrix[0][2] = -1.0*(focus->x - eye->x)/distance;
}
else
{
if (eye->y < focus->y)
{
matrix[0][0] = -1.0;
}
else
{
matrix[0][0] = 1.0;
}
matrix[0][2] = 0.0;
}
matrix[0][1] = matrix[0][3] = 0.0;
matrix[1][1] = 1.0;
matrix[1][0] = matrix[1][2] = matrix[1][3] = 0.0;
matrix[2][0] = -1.0*matrix[0][2];
matrix[2][2] = matrix[0][0];
matrix[2][3] = 0.0;
matrix[2][1] = 0.0;
matrix[3][3] = 1.0;
matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0;
perspective_trans = xgl_object_create(xglr_sys_state,XGL_TRANS, NULL, NULL);
xgl_transform_write (perspective_trans, matrix);
xgl_transform_multiply (*trans, *trans, perspective_trans);
/* now rotate x */
distance_old = distance;
distance = sqrt((eye->x-focus->x)*(eye->x-focus->x) +
(eye->y-focus->y)*(eye->y-focus->y) +
(eye->z-focus->z)*(eye->z-focus->z));
matrix[0][0] = 1.0;
matrix[0][1] = matrix[0][2] = matrix[0][3] = 0.0;
matrix[1][1] = distance_old/distance;
matrix[1][2] = (eye->y - focus->y)/distance;
matrix[1][0] = matrix[1][3] = 0.0;
matrix[2][1] = -1.0*matrix[1][2];
matrix[2][2] = matrix[1][1];
matrix[2][3] = 0.0;
matrix[2][0] = 0.0;
matrix[3][3] = 1.0;
matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0;
xgl_transform_write (perspective_trans, matrix);
xgl_transform_multiply (*trans, *trans, perspective_trans);
/* now rotate z (twist) */
matrix[0][0] = cos(-twist);
matrix[0][1] = sin(-twist);
matrix[0][2] = matrix[0][3] = 0.0;
matrix[1][0] = -1.0*matrix[0][1];
matrix[1][1] = matrix[0][0];
matrix[1][2] = matrix[1][3] = 0.0;
matrix[2][1] = 0.0;
matrix[2][2] = 1.0;
matrix[2][3] = 0.0;
matrix[2][0] = 0.0;
matrix[3][3] = 1.0;
matrix[3][0] = matrix[3][1] = matrix[3][2] = 0.0;
xgl_transform_write (perspective_trans, matrix);
xgl_transform_multiply (*trans, *trans, perspective_trans);
xgl_transform_read(*trans,matrix);
/* do the stereo translate */
pt_f3d.x = -eye_ang;
pt_f3d.y = 0;
pt_f3d.z = 0;
xgl_transform_translate (*trans, &pt, XGL_TRANS_POSTCONCAT);
/* Set view perspective and concatenate with view orientation */
matrix[0][0] = 2.0*near/(right-left);
matrix[0][1] = matrix[0][2] = matrix[0][3] = 0.0;
matrix[1][1] = 2.0*near/(top-bottom);
matrix[1][0] = matrix[1][2] = matrix[1][3] = 0.0;
matrix[2][2] = 0.5*(far+near)/(far-near) + 0.5;
matrix[2][3] = -1.0;
matrix[2][0] = (right+left)/(right-left);
matrix[2][1] = (top+bottom)/(top-bottom);
matrix[3][2] = 1.0*far*near/ (far-near);
matrix[3][0] = matrix[3][1] = 0.0;
matrix[3][3] = 0;
xgl_transform_write (perspective_trans, matrix);
xgl_transform_multiply (*trans, *trans, perspective_trans);
xgl_object_destroy (perspective_trans);
}
// Description:
// Implement base class method.
void vlXglrCamera::Render(vlRenderer *ren)
{
this->Render((vlXglrRenderer *)ren);
}
// Description:
// Actual camera render method.
void vlXglrCamera::Render(vlXglrRenderer *ren)
{
Xgl_ctx *context;
Xgl_win_ras *win_ras = NULL; // XGLR Window Raster object
int stereo;
int *size;
Xgl_color_rgb bg_color;
float *background;
float aspect[3];
Xgl_bounds_d3d vdc_bounds;
Xgl_trans view_trans;
Xgl_trans trans;
Xgl_pt_f3d eye,focus;
float twist;
float matrix[4][4];
vlXglrRenderWindow *rw;
context = ren->GetContext();
win_ras = ren->GetRaster();
// get size info
rw = (vlXglrRenderWindow*)(ren->GetRenderWindow());
size = rw->GetSize();
// find out if we should stereo render
stereo = rw->GetStereoRender();
if (stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VL_STEREO_CRYSTAL_EYES:
if (this->LeftEye)
{
xgl_object_set(*win_ras,
XGL_WIN_RAS_STEREO_MODE,XGL_STEREO_LEFT,NULL);
}
else
{
xgl_object_set(*win_ras,
XGL_WIN_RAS_STEREO_MODE,XGL_STEREO_RIGHT,NULL);
}
break;
default:
xgl_object_set(*win_ras,
XGL_WIN_RAS_STEREO_MODE, XGL_STEREO_NONE,NULL);
}
}
else
{
xgl_object_set(*win_ras,
XGL_WIN_RAS_STEREO_MODE, XGL_STEREO_NONE,NULL);
}
// get the background color
background = ren->GetBackground();
bg_color.r = background[0];
bg_color.g = background[1];
bg_color.b = background[2];
if (this->LeftEye || (!stereo))
{
xgl_object_set(*context,XGL_CTX_BACKGROUND_COLOR,
&bg_color,0);
xgl_context_new_frame(*context);
}
aspect[0] = size[0]/size[1];
aspect[1] = 1.0;
vdc_bounds.xmin = -1;
vdc_bounds.xmax = 1;
vdc_bounds.ymin = -1.0*aspect[1];
vdc_bounds.ymax = 1.0*aspect[1];
vdc_bounds.zmin = -1.0;
vdc_bounds.zmax = 0;
ren->SetAspect(aspect);
trans = xgl_object_create(xglr_sys_state,XGL_TRANS,NULL,NULL);
eye.x = this->Position[0];
eye.y = this->Position[1];
eye.z = this->Position[2];
focus.x = this->FocalPoint[0];
focus.y = this->FocalPoint[1];
focus.z = this->FocalPoint[2];
/* xgl_object_set(*context,XGL_CTX_VDC_WINDOW, &vdc_bounds, NULL); */
xgl_object_set(*context,XGL_CTX_VDC_WINDOW, &vdc_bounds, NULL);
xgl_object_set(*context,XGL_CTX_VIEW_CLIP_BOUNDS, &vdc_bounds, NULL);
twist = this->GetTwist();
if (stereo)
{
if (this->LeftEye)
{
view_calc(&eye,&focus,this->ClippingRange[0],
this->ClippingRange[1],
this->ViewAngle,twist,&trans,this->Distance,
-1.0*this->EyeAngle,aspect[0]/aspect[1]);
}
else
{
view_calc(&eye,&focus,this->ClippingRange[0],
this->ClippingRange[1],
this->ViewAngle,twist,&trans,this->Distance,
this->EyeAngle,aspect[0]/aspect[1]);
}
}
else
{
view_calc(&eye,&focus,this->ClippingRange[0],
this->ClippingRange[1],
this->ViewAngle,twist,&trans,this->Distance,
0.0,aspect[0]/aspect[1]);
}
xgl_object_get(*context,XGL_CTX_VIEW_TRANS, &view_trans);
xgl_transform_copy(view_trans,trans);
xgl_transform_read(trans,matrix);
xgl_object_destroy(trans);
// if we have a stereo renderer, draw other eye next time
if (stereo)
{
if (this->LeftEye) this->LeftEye = 0;
else this->LeftEye = 1;
}
}
/*=========================================================================
Program: Visualization Library
Module: XglrLgt.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include <math.h>
#include "XglrRenW.hh"
#include "XglrRen.hh"
#include "XglrLgt.hh"
// Description:
// Implement base class method.
void vlXglrLight::Render(vlRenderer *ren,int light_index)
{