home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / renderbox.wxc < prev    next >
Encoding:
Text File  |  1996-04-26  |  19.7 KB  |  740 lines

  1. Save Format v1.3
  2. @begin ClassFile "RenderBox"
  3.  Exported 0;
  4.  
  5. @begin-code BaseClassList
  6.  
  7. public WObject
  8.  
  9. @end-code;
  10.  
  11.  @begin UserFunction "RenderBox( WWindow * box )"
  12.   GencodeSrcLine 131;
  13.   FunctionName "RenderBox::RenderBox( WWindow * box )";
  14.  @end;
  15.  
  16.  @begin UserFunction "Prototype for RenderBox( WWindow * box )"
  17.   Private 1;
  18.   GencodeSrcLine 21;
  19.   FunctionName "RenderBox::Prototype for RenderBox( WWindow * box )";
  20.  @end;
  21.  
  22.  @begin UserFunction "~RenderBox()"
  23.   GencodeSrcLine 141;
  24.   FunctionName "RenderBox::~RenderBox()";
  25.  @end;
  26.  
  27.  @begin UserFunction "Prototype for ~RenderBox()"
  28.   Private 1;
  29.   GencodeSrcLine 23;
  30.   FunctionName "RenderBox::Prototype for ~RenderBox()";
  31.  @end;
  32.  
  33.  @begin UserFunction "HdlBoxPaint( WObject *, WPaintEventData * event )"
  34.   Private 1;
  35.   GencodeSrcLine 146;
  36.   FunctionName "RenderBox::HdlBoxPaint( WObject *, WPaintEventData * event )";
  37.  @end;
  38.  
  39.  @begin UserFunction "Prototype for HdlBoxPaint( WObject *, WPaintEventData * event )"
  40.   Private 1;
  41.   GencodeSrcLine 25;
  42.   FunctionName "RenderBox::Prototype for HdlBoxPaint( WObject *, WPaintEventData * event )";
  43.  @end;
  44.  
  45.  @begin UserFunction "Render( WCanvas & canvas )"
  46.   GencodeSrcLine 171;
  47.   FunctionName "RenderBox::Render( WCanvas & canvas )";
  48.  @end;
  49.  
  50.  @begin UserFunction "Prototype for Render( WCanvas & canvas )"
  51.   Private 1;
  52.   GencodeSrcLine 27;
  53.   FunctionName "RenderBox::Prototype for Render( WCanvas & canvas )";
  54.  @end;
  55.  
  56.  @begin UserFunction "DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )"
  57.   Private 1;
  58.   GencodeSrcLine 231;
  59.   FunctionName "RenderBox::DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )";
  60.  @end;
  61.  
  62.  @begin UserFunction "Prototype for DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )"
  63.   Private 1;
  64.   GencodeSrcLine 29;
  65.   FunctionName "RenderBox::Prototype for DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )";
  66.  @end;
  67.  
  68.  @begin UserFunction "ClipLine( grPoint3 & A, grPoint3 & B )"
  69.   Private 1;
  70.   GencodeSrcLine 251;
  71.   FunctionName "RenderBox::ClipLine( grPoint3 & A, grPoint3 & B )";
  72.  @end;
  73.  
  74.  @begin UserFunction "Prototype for ClipLine( grPoint3 & A, grPoint3 & B )"
  75.   Private 1;
  76.   GencodeSrcLine 31;
  77.   FunctionName "RenderBox::Prototype for ClipLine( grPoint3 & A, grPoint3 & B )";
  78.  @end;
  79.  
  80.  @begin UserFunction "DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )"
  81.   GencodeSrcLine 291;
  82.   FunctionName "RenderBox::DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )";
  83.  @end;
  84.  
  85.  @begin UserFunction "Prototype for DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )"
  86.   Private 1;
  87.   GencodeSrcLine 33;
  88.   FunctionName "RenderBox::Prototype for DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )";
  89.  @end;
  90.  
  91.  @begin UserFunction "MapNDCToDC( const grPoint3 & p )"
  92.   Private 1;
  93.   GencodeSrcLine 313;
  94.   FunctionName "RenderBox::MapNDCToDC( const grPoint3 & p )";
  95.  @end;
  96.  
  97.  @begin UserFunction "Prototype for MapNDCToDC( const grPoint3 & p )"
  98.   Private 1;
  99.   GencodeSrcLine 35;
  100.   FunctionName "RenderBox::Prototype for MapNDCToDC( const grPoint3 & p )";
  101.  @end;
  102.  
  103.  @begin UserFunction "RotateModel( int axis, double radians )"
  104.   GencodeSrcLine 335;
  105.   FunctionName "RenderBox::RotateModel( int axis, double radians )";
  106.  @end;
  107.  
  108.  @begin UserFunction "Prototype for RotateModel( int axis, double radians )"
  109.   Private 1;
  110.   GencodeSrcLine 37;
  111.   FunctionName "RenderBox::Prototype for RotateModel( int axis, double radians )";
  112.  @end;
  113.  
  114.  @begin UserFunction "GetClipPlanes( double & nearf, double & farf )"
  115.   GencodeSrcLine 342;
  116.   FunctionName "RenderBox::GetClipPlanes( double & nearf, double & farf )";
  117.  @end;
  118.  
  119.  @begin UserFunction "Prototype for GetClipPlanes( double & nearf, double & farf )"
  120.   Private 1;
  121.   GencodeSrcLine 39;
  122.   FunctionName "RenderBox::Prototype for GetClipPlanes( double & nearf, double & farf )";
  123.  @end;
  124.  
  125.  @begin UserFunction "SetClipPlanes( double nearf, double farf )"
  126.   GencodeSrcLine 348;
  127.   FunctionName "RenderBox::SetClipPlanes( double nearf, double farf )";
  128.  @end;
  129.  
  130.  @begin UserFunction "Prototype for SetClipPlanes( double nearf, double farf )"
  131.   Private 1;
  132.   GencodeSrcLine 41;
  133.   FunctionName "RenderBox::Prototype for SetClipPlanes( double nearf, double farf )";
  134.  @end;
  135.  
  136.  @begin UserFunction "GetFOVY()"
  137.   GencodeSrcLine 357;
  138.   FunctionName "RenderBox::GetFOVY()";
  139.  @end;
  140.  
  141.  @begin UserFunction "Prototype for GetFOVY()"
  142.   Private 1;
  143.   GencodeSrcLine 43;
  144.   FunctionName "RenderBox::Prototype for GetFOVY()";
  145.  @end;
  146.  
  147.  @begin UserFunction "SetFOVY( double fovy )"
  148.   GencodeSrcLine 364;
  149.   FunctionName "RenderBox::SetFOVY( double fovy )";
  150.  @end;
  151.  
  152.  @begin UserFunction "Prototype for SetFOVY( double fovy )"
  153.   Private 1;
  154.   GencodeSrcLine 45;
  155.   FunctionName "RenderBox::Prototype for SetFOVY( double fovy )";
  156.  @end;
  157.  
  158.  @begin UserFunction "TranslateView( double, double, double )"
  159.   GencodeSrcLine 372;
  160.   FunctionName "RenderBox::TranslateView( double, double, double )";
  161.  @end;
  162.  
  163.  @begin UserFunction "Prototype for TranslateView( double, double, double )"
  164.   Private 1;
  165.   GencodeSrcLine 47;
  166.   FunctionName "RenderBox::Prototype for TranslateView( double, double, double )";
  167.  @end;
  168.  
  169.  @begin HPPPrefixBlock
  170. @begin-code HPPPrefix
  171.  
  172. class RenderBoxImplementation;
  173. class grVector;
  174. class grPoint3;
  175. class grBaseTransform;
  176.  
  177. @end-code;
  178.   GencodeSrcLine 10;
  179.  @end;
  180.  
  181.  @begin CPPPrefixBlock
  182. @begin-code CPPPrefix
  183.  
  184. #include <math.h>
  185. #include "grVector.hpp"
  186. #include "grTransform.hpp"
  187.  
  188. #define PI 3.14159265359
  189.  
  190. #define NEARF  0.1
  191. #define FARF   100.0
  192. #define FOVY   (45.0 * PI/180.0)
  193. #define ASPECT 1.0
  194.  
  195. //----------------- ClipPlane class --------------------//
  196.  
  197. class WCMCLASS ClipPlane {                    // REPRESENT CLIPPING PLANES
  198.     public:
  199.         ClipPlane(){}
  200.     
  201.         ClipPlane( const ClipPlane & o )
  202.           : point( o.point ), normal( o.normal ){}
  203.     
  204.         ClipPlane( const grPoint3 & p, const grVector & n )
  205.           : point( p ), normal( n ) {}
  206.     
  207.         grPoint3 point;                            // point on plane
  208.         grVector normal;                        // unit inward normal
  209. };
  210. #define NUMCLIPPLANES 6
  211.  
  212. //------------ RenderBoxImplementation class ---------------//
  213.  
  214. class WCMCLASS RenderBoxImplementation : public WObject 
  215. {
  216.     public:
  217.         RenderBoxImplementation();
  218.         Reset();
  219.         InitClipPlanes();
  220.     public:
  221.         grTransform     _modelTransform;
  222.         grVector        _modelScale;
  223.         grTransform     _viewTransform;
  224.         grTransform     _projTransform;                 // projection transform
  225.         double          _nearF;
  226.         double          _farF;
  227.         double          _fovy;
  228.  
  229.         ClipPlane       _clipPlanes[ NUMCLIPPLANES ];
  230. };
  231.  
  232. RenderBoxImplementation::RenderBoxImplementation()
  233.     : _nearF( NEARF )
  234.     , _farF( FARF )
  235.     , _fovy( FOVY )
  236. //------------------------------------------------
  237. {
  238.     InitClipPlanes();
  239.     Reset();
  240. }
  241.  
  242. RenderBoxImplementation::InitClipPlanes()
  243. //---------------------------------------
  244. {
  245.     grPoint3 point;
  246.     grVector normal;
  247.     double    ctan;
  248.  
  249.     ctan = 1.0 / tan( _fovy / 2.0 );
  250.  
  251.     // front
  252.     point = grPoint3( 0, 0, -_nearF );
  253.     normal = grVector( 0, 0, -1 );
  254.     _clipPlanes[ 0 ] = ClipPlane( point, normal );
  255.  
  256.     // back
  257.     point = grPoint3( 0, 0, -_farF );
  258.     normal = grVector( 0, 0, 1 );
  259.     _clipPlanes[ 1 ] = ClipPlane( point, normal );
  260.  
  261.     // top
  262.     point = grPoint3( 0, _nearF * ctan, -_nearF );
  263.     normal = grVector( 0, -1.0, -ctan );
  264.     normal.normalize();
  265.     _clipPlanes[ 2 ] = ClipPlane( point, normal );
  266.  
  267.     // bottom
  268.     point = grPoint3( 0, -_nearF * ctan, -_nearF );
  269.     normal = grVector( 0, 1.0, -ctan );
  270.     normal.normalize();
  271.     _clipPlanes[ 3 ] = ClipPlane( point, normal );
  272.  
  273.     // right
  274.     point = grPoint3( _nearF * ctan / ASPECT, 0, -_nearF );
  275.     normal = grVector( -1.0, 0, -ctan / ASPECT );
  276.     normal.normalize();
  277.     _clipPlanes[ 4 ] = ClipPlane( point, normal );
  278.  
  279.     // left
  280.     point = grPoint3( -_nearF * ctan / ASPECT, 0, -_nearF );
  281.     normal = grVector(  1.0, 0, -ctan / ASPECT );
  282.     normal.normalize();
  283.     _clipPlanes[ 5 ] = ClipPlane( point, normal );
  284.     
  285.     grPerspective pers( _fovy, ASPECT, _nearF, _farF );
  286.     _projTransform = pers;
  287. }
  288.  
  289. RenderBoxImplementation::Reset()
  290. //------------------------------
  291. {
  292.     _modelTransform = grBaseTransform();
  293.     _modelScale     = grVector( 1.0, 1.0, 1.0 );
  294.     _viewTransform  = grTranslate( grVector( 0.0, 0.0, -4.0 ) );
  295.  
  296.     InitClipPlanes();
  297. }
  298.  
  299. void grError( const char * msg )
  300. //------------------------------
  301. {
  302.     WMessageBox::Message( NULL, WMBLevelError, WMBButtonOk, "RenderBox Demo", msg, WMBDefault1, WMBAttributeTaskModal );
  303. }
  304.  
  305. @end-code;
  306.   GencodeSrcLine 11;
  307.  @end;
  308.  
  309.  @begin ClassContentsBlock
  310. @begin-code ClassContents
  311.  
  312.     private:
  313.         WWindow *                   _box;
  314.         RenderBoxImplementation *   _imp;
  315.  
  316. @end-code;
  317.   GencodeSrcLine 18;
  318.  @end;
  319.  
  320. @begin-code GeneratedClassContents
  321.  
  322.  
  323. @end-code;
  324.  
  325. @begin-code Code "RenderBox::RenderBox( WWindow * box )"
  326.  
  327. RenderBox::RenderBox( WWindow * box )
  328.     : _box( box )
  329.     , _imp( NULL )
  330. //----------------
  331. {
  332.     _imp = new RenderBoxImplementation;
  333.     
  334.     _box->SetEventHandler( WPaintEvent, this,
  335.         (WEventHandler)&RenderBox::HdlBoxPaint );
  336. }
  337.  
  338. @end-code;
  339.  
  340. @begin-code Code "RenderBox::Prototype for RenderBox( WWindow * box )"
  341.  
  342.     public:
  343.         RenderBox( WWindow * box );
  344.  
  345. @end-code;
  346.  
  347. @begin-code Code "RenderBox::~RenderBox()"
  348.  
  349. RenderBox::~RenderBox()
  350. //---------------------
  351. {
  352.     delete _imp;
  353. }
  354.  
  355. @end-code;
  356.  
  357. @begin-code Code "RenderBox::Prototype for ~RenderBox()"
  358.  
  359.     public:
  360.         ~RenderBox();
  361.  
  362. @end-code;
  363.  
  364. @begin-code Code "RenderBox::HdlBoxPaint( WObject *, WPaintEventData * event )"
  365.  
  366. WBool RenderBox::HdlBoxPaint( WObject *, WPaintEventData * event )
  367. //----------------------------------------------------------------
  368. //  Draw the scene onto the target window in response to a paint
  369. //  event.  Use double buffering to reduce screen flicker.
  370. {
  371.     WRect   br;
  372.     WCanvas dup( *event->canvas, TRUE );
  373.     WBitmap bmp;
  374.     WBitmap old_bmp;
  375.     
  376.     br = _box->GetRectangle();
  377.     br.x = 0;
  378.     br.y = 0;
  379.     
  380.     bmp.Create( event->canvas->GetHandle(), br.w, br.h );
  381.     old_bmp = dup.GetBitmap();
  382.     dup.SetBackColor( _box->GetBackColor() );
  383.     dup.SetBitmap( bmp );
  384.     dup.FillRectangle( br );
  385.     Render( dup );
  386.     event->canvas->DrawFromCanvas( br, dup );
  387.     dup.SetBitmap( old_bmp );
  388.     
  389.     return( TRUE );
  390. }
  391.  
  392. @end-code;
  393.  
  394. @begin-code Code "RenderBox::Prototype for HdlBoxPaint( WObject *, WPaintEventData * event )"
  395.  
  396.     private:
  397.         WBool HdlBoxPaint( WObject *, WPaintEventData * event );
  398.  
  399. @end-code;
  400.  
  401. @begin-code Code "RenderBox::Render( WCanvas & canvas )"
  402.  
  403. static grPoint3 WorldGnomon[] = {
  404.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3( +0.5,  0.0,  0.0 ),
  405.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3(  0.0, +0.5,  0.0 ),
  406.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3(  0.0,  0.0, +0.5 ),
  407. };
  408. #define NUMWORLDGLINES (sizeof(WorldGnomon) / (2*sizeof(WorldGnomon[0])) )
  409.  
  410. static grPoint3 BoxGnomon[] = {
  411.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3( +0.5,  0.0,  0.0 ),
  412.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3(  0.0, +0.5,  0.0 ),
  413.     grPoint3( 0.0, 0.0, 0.0 ), grPoint3(  0.0,  0.0, +0.5 ),
  414. };
  415. #define NUMBOXGLINES (sizeof(BoxGnomon) / (2*sizeof(BoxGnomon[0])) )
  416.  
  417. static grPoint3 Box[] = {
  418.     grPoint3( -1.0, -1.0, -1.0 ), grPoint3( +1.0, -1.0, -1.0 ),
  419.     grPoint3( +1.0, -1.0, -1.0 ), grPoint3( +1.0, -1.0, +1.0 ),
  420.     grPoint3( +1.0, -1.0, +1.0 ), grPoint3( -1.0, -1.0, +1.0 ),
  421.     grPoint3( -1.0, -1.0, +1.0 ), grPoint3( -1.0, -1.0, -1.0 ),
  422.  
  423.     grPoint3( -1.0, -1.0, -1.0 ), grPoint3( -1.0, +1.0, -1.0 ),
  424.     grPoint3( -1.0, +1.0, -1.0 ), grPoint3( -1.0, +1.0, +1.0 ),
  425.     grPoint3( -1.0, +1.0, +1.0 ), grPoint3( -1.0, -1.0, +1.0 ),
  426.  
  427.     grPoint3( -1.0, +1.0, +1.0 ), grPoint3( +1.0, +1.0, +1.0 ),
  428.     grPoint3( +1.0, +1.0, +1.0 ), grPoint3( +1.0, +1.0, -1.0 ),
  429.     grPoint3( +1.0, +1.0, -1.0 ), grPoint3( -1.0, +1.0, -1.0 ),
  430.  
  431.     grPoint3( +1.0, +1.0, +1.0 ), grPoint3( +1.0, -1.0, +1.0 ),
  432.     grPoint3( +1.0, +1.0, -1.0 ), grPoint3( +1.0, -1.0, -1.0 ),
  433. };
  434. #define NUMBOXLINES (sizeof(Box) / (2*sizeof(Box[0])) )
  435.  
  436.  
  437. void RenderBox::Render( WCanvas & canvas )
  438. //----------------------------------------
  439. {
  440.     grTransform boxg( _imp->_modelTransform );
  441.     grTransform box;
  442.     grTransform view( _imp->_viewTransform );
  443.     grVector    mScale( _imp->_modelScale );
  444.     WPen        old_pen;
  445.     WPen        red( WColorBrightRed );
  446.  
  447.     box.scale( grPoint3(0,0,0), mScale.x(), mScale.y(), mScale.z() );
  448.     box  *= boxg;
  449.     box *= view;
  450.     boxg *= view;
  451.  
  452.     old_pen = canvas.GetPen();
  453.     DrawObject( canvas, view, WorldGnomon, NUMWORLDGLINES );
  454.  
  455.     canvas.SetPen( red );
  456.     DrawObject( canvas, boxg, BoxGnomon, NUMBOXGLINES );
  457.  
  458.     canvas.SetPen( red );
  459.     DrawObject( canvas, box, Box, NUMBOXLINES );
  460.     
  461.     canvas.SetPen( old_pen );
  462. }
  463.  
  464. @end-code;
  465.  
  466. @begin-code Code "RenderBox::Prototype for Render( WCanvas & canvas )"
  467.  
  468.     public:
  469.         virtual void Render( WCanvas & canvas );
  470.  
  471. @end-code;
  472.  
  473. @begin-code Code "RenderBox::DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )"
  474.  
  475. void RenderBox::DrawObject( 
  476.     WCanvas & canvas, 
  477.     const grBaseTransform & xfrm, 
  478.     grPoint3 * lines, 
  479.     WUInt numLines )
  480. //-------------------------------
  481. {
  482.     WUInt    i;
  483.     grPoint3 p1, p2;
  484.  
  485.     for( i = 0; i < numLines; i++ ) {
  486.         p1 = lines[ 2 * i ];
  487.         p2 = lines[ 2 * i + 1 ];
  488.     
  489.         xfrm.apply( p1 );
  490.         xfrm.apply( p2 );
  491.  
  492.         DrawLine( canvas, p1, p2 );
  493.     }   
  494. }
  495.  
  496. @end-code;
  497.  
  498. @begin-code Code "RenderBox::Prototype for DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n )"
  499.  
  500.     private:
  501.         void DrawObject( WCanvas & canvas, const grBaseTransform & xfrm, grPoint3 * lines, WUInt n );
  502.  
  503. @end-code;
  504.  
  505. @begin-code Code "RenderBox::ClipLine( grPoint3 & A, grPoint3 & B )"
  506.  
  507. /*
  508.  * Liang Barsky 3-D clipping _Computer_Graphics_ (Hearn, Baker) p. 231,
  509.  * _Computer_Graphics,_Principle_and_Practice (Foley, van Dam, Feiner, Hughes)
  510.  * p. 122, 275.
  511.  *
  512.  * The formulation of ClipTest is from [Hearn,Baker]; the [Foley,et al]
  513.  * uses 'denom' instead of 'p', 'num' instead of 'q', 'tE' instead of 'u1',
  514.  * and 'tL' instead of 'u2'.
  515.  */
  516.  
  517. WBool RenderBox::ClipLine( grPoint3 & A, grPoint3 & B )
  518. //-----------------------------------------------------
  519. {
  520.     double        wecA, wecB;            // -- window edge coordinates
  521.     double        t;
  522.     ClipPlane *  plane;
  523.     uint         i;
  524.  
  525.     for( i = 0; i < NUMCLIPPLANES; i++ ) {
  526.         plane = &_imp->_clipPlanes[ i ];
  527.         wecA = dot( A - plane->point, plane->normal );
  528.         wecB = dot( B - plane->point, plane->normal );
  529.     
  530.         if( wecA < 0 && wecB < 0 ) {
  531.             return grFALSE;            // reject
  532.         }
  533.         if( wecA >= 0 && wecB >= 0 ) {
  534.             // accept trivially
  535.         } else {
  536.             t = wecA / (wecA - wecB);
  537.             if( wecA < 0 ) {
  538.                 A = A + t * (B - A);
  539.             } else {
  540.                 B = A + t * (B - A);
  541.             }
  542.         }
  543.     }
  544.  
  545.     return grTRUE;
  546. }
  547.  
  548. @end-code;
  549.  
  550. @begin-code Code "RenderBox::Prototype for ClipLine( grPoint3 & A, grPoint3 & B )"
  551.  
  552.     private:
  553.         WBool ClipLine( grPoint3 & A, grPoint3 & B );
  554.  
  555. @end-code;
  556.  
  557. @begin-code Code "RenderBox::DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )"
  558.  
  559. void RenderBox::DrawLine(           // DRAW A LINE BETWEEN 2 3-SPACE POINTS
  560.     WCanvas & canvas,
  561.     const grPoint3 & p1,            // -- first point
  562.     const grPoint3 & p2 )           // -- second point
  563. //-----------------------
  564. {
  565.     WPoint        wp1, wp2;
  566.     grPoint3    point1( p1 );
  567.     grPoint3    point2( p2 );
  568.  
  569.     if( !ClipLine( point1, point2 ) ) {
  570.         return;
  571.     }
  572.  
  573.     _imp->_projTransform.apply( point1 );
  574.     _imp->_projTransform.apply( point2 );
  575.  
  576.     wp1 = MapNDCToDC( point1 );
  577.     wp2 = MapNDCToDC( point2 );
  578.     
  579.     canvas.DrawLine( wp1, wp2 );
  580. }
  581.  
  582. @end-code;
  583.  
  584. @begin-code Code "RenderBox::Prototype for DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 )"
  585.  
  586.     public:
  587.         void DrawLine( WCanvas & canvas, const grPoint3 & p1, const grPoint3 & p2 );
  588.  
  589. @end-code;
  590.  
  591. @begin-code Code "RenderBox::MapNDCToDC( const grPoint3 & p )"
  592.  
  593. WPoint RenderBox::MapNDCToDC( 
  594.     const grPoint3 & p )
  595. //----------------------
  596. // convert a point from normalized device
  597. // coordinates (-1.0..1.0) to device coordinates (0..max)
  598. {
  599.     WRect       boxRect;
  600.     WPoint      ret;
  601.     WUInt       base;
  602.     grPoint3    point( p );
  603.     
  604.     point.fixup();
  605.     point.x( point.x() * 0.5 + 0.5 );
  606.     point.y( point.y() * 0.5 + 0.5 );
  607.     
  608.     boxRect = _box->GetRectangle();
  609.     base = __min( boxRect.w, boxRect.h );
  610.     ret.x = point.x() * base;
  611.     ret.y = base - point.y() * base;
  612.     
  613.     return( ret );
  614. }
  615.  
  616. @end-code;
  617.  
  618. @begin-code Code "RenderBox::Prototype for MapNDCToDC( const grPoint3 & p )"
  619.  
  620.     private:
  621.         WPoint MapNDCToDC( const grPoint3 & p );
  622.  
  623. @end-code;
  624.  
  625. @begin-code Code "RenderBox::RotateModel( int axis, double radians )"
  626.  
  627. void RenderBox::RotateModel( int axis, double radians )
  628. //-----------------------------------------------------
  629. {
  630.     _imp->_modelTransform.rotate( axis, radians );
  631.     _box->Invalidate( TRUE );
  632.     _box->Update();
  633. }
  634.  
  635. @end-code;
  636.  
  637. @begin-code Code "RenderBox::Prototype for RotateModel( int axis, double radians )"
  638.  
  639.     public:
  640.         void RotateModel( int axis, double radians );
  641.  
  642. @end-code;
  643.  
  644. @begin-code Code "RenderBox::GetClipPlanes( double & nearf, double & farf )"
  645.  
  646. void RenderBox::GetClipPlanes( double & nearf, double & farf )
  647. //----------------------------------------------------------
  648. {
  649.     nearf = _imp->_nearF;
  650.     farf = _imp->_farF;
  651. }
  652.  
  653. @end-code;
  654.  
  655. @begin-code Code "RenderBox::Prototype for GetClipPlanes( double & nearf, double & farf )"
  656.  
  657.     public:
  658.         void GetClipPlanes( double & nearf, double & farf );
  659.  
  660. @end-code;
  661.  
  662. @begin-code Code "RenderBox::SetClipPlanes( double nearf, double farf )"
  663.  
  664. void RenderBox::SetClipPlanes( double nearf, double farf )
  665. //------------------------------------------------------
  666. {
  667.     _imp->_nearF = nearf;
  668.     _imp->_farF  = farf;
  669.     _imp->InitClipPlanes();
  670.     _box->Invalidate();
  671.     _box->Update();
  672. }
  673.  
  674. @end-code;
  675.  
  676. @begin-code Code "RenderBox::Prototype for SetClipPlanes( double nearf, double farf )"
  677.  
  678.     public:
  679.         void SetClipPlanes( double nearf, double farf );
  680.  
  681. @end-code;
  682.  
  683. @begin-code Code "RenderBox::GetFOVY()"
  684.  
  685. double RenderBox::GetFOVY()
  686. //-------------------------
  687. {
  688.     double  fovy( _imp->_fovy );
  689.     fovy *= 180.0 / PI;
  690.     return( fovy );
  691. }
  692.  
  693. @end-code;
  694.  
  695. @begin-code Code "RenderBox::Prototype for GetFOVY()"
  696.  
  697.     public:
  698.         double GetFOVY();
  699.  
  700. @end-code;
  701.  
  702. @begin-code Code "RenderBox::SetFOVY( double fovy )"
  703.  
  704. void RenderBox::SetFOVY( double fovy )
  705. //------------------------------------
  706. {
  707.     _imp->_fovy = fovy * PI / 180.0;
  708.     _imp->InitClipPlanes();
  709.     _box->Invalidate();
  710.     _box->Update();
  711. }
  712.  
  713. @end-code;
  714.  
  715. @begin-code Code "RenderBox::Prototype for SetFOVY( double fovy )"
  716.  
  717.     public:
  718.         void SetFOVY( double fovy );
  719.  
  720. @end-code;
  721.  
  722. @begin-code Code "RenderBox::TranslateView( double, double, double )"
  723.  
  724. void RenderBox::TranslateView( double x, double y, double z )
  725. {
  726.     grVector    v( x, y, z );
  727.     grTranslate t( v );
  728.     _imp->_viewTransform = t;
  729. }
  730.  
  731. @end-code;
  732.  
  733. @begin-code Code "RenderBox::Prototype for TranslateView( double, double, double )"
  734.  
  735.     public:
  736.         void TranslateView( double, double, double );
  737.  
  738. @end-code;
  739. @end;
  740.