// 
// File name: Scene.cpp
//
// Discription: Base classes
//
// Programmer: Vladimir P. Stasevich (SV)
//
// History: 
//    Created 26.01.2000 (SV)
//

#include <math.h>
#pragma hdrstop

#include "Scene.h"
#include "Robot.h"

TScene scene;

TScene::TScene()
{
   width           = 0;
   height          = 0;
   bushRadius      = 38;
   bushFacetRadius = 65;
   bushFacetAngle  = 3.1415*0.5;

   criticalRadius  = 5;
}

void TScene::GetLeft ( double& x, double& y )
{

   x = 10;
   y = height*BUSHHEIGTHKOEF;
}

void TScene::GetRight( double& x, double& y )
{
   x = width - 10;
   y = height*BUSHHEIGTHKOEF;
}

void TScene::GetLeftFacet ( double& x, double& y )
{
   x = width/2 - bushFacetRadius;
   y = height*BUSHHEIGTHKOEF;
}

void TScene::GetRightFacet( double& x, double& y )
{
   x = width/2 + bushFacetRadius;
   y = height*BUSHHEIGTHKOEF;
}

void TScene::GetLeftBush ( double& x, double& y )
{
   x = width/2 - bushRadius;
   y = height*BUSHHEIGTHKOEF + (bushFacetRadius - 
       bushRadius)*(1/tan(bushFacetAngle/2));
}

void TScene::GetRightBush( double& x, double& y )
{
   x = width/2 + bushRadius;
   y = height*BUSHHEIGTHKOEF + (bushFacetRadius - 
       bushRadius)*(1/tan(bushFacetAngle/2));
}

void TScene::GetLeftDown ( double& x, double& y )
{
   x = width/2 - bushRadius;
   y = height - 10;
}

void TScene::GetRightDown( double& x, double& y )
{
   x = width/2 + bushRadius;
   y = height - 10;
}
      
void TScene::PaintOnCanvas
( 
   TCanvas* canvas, 
   TColor color 
)
{
   double leftX,  leftFacetX,  leftBushX,  leftDownX;
   double leftY,  leftFacetY,  leftBushY,  leftDownY;
   double rightX, rightFacetX, rightBushX, rightDownX;
   double rightY, rightFacetY, rightBushY, rightDownY;

   GetLeft ( leftX,  leftY  );
   GetRight( rightX, rightY );
   GetLeftFacet ( leftFacetX,  leftFacetY  );
   GetRightFacet( rightFacetX, rightFacetY );
   GetLeftBush ( leftBushX,  leftBushY  );
   GetRightBush( rightBushX, rightBushY );
   GetLeftDown ( leftDownX,  leftDownY  );
   GetRightDown( rightDownX, rightDownY );
   
   canvas->Brush->Color = color;
   canvas->Pen->Color   = color;
   
   canvas->MoveTo( leftX, leftY );
   canvas->LineTo( leftFacetX, leftFacetY );

/*
   canvas->Pen->Color   = clRed;
   canvas->Brush->Color = clBtnFace;
   canvas->Ellipse( leftBushX - criticalRadius, leftBushY - criticalRadius,
                    leftBushX + criticalRadius, leftBushY + criticalRadius );
   canvas->Pen->Color   = color;
   canvas->Brush->Color = color;
*/
   canvas->LineTo( leftBushX, leftBushY );
   canvas->LineTo( leftDownX, leftDownY );

   canvas->MoveTo( rightX, rightY );
   canvas->LineTo( rightFacetX, rightFacetY );
/*
   canvas->Pen->Color   = clRed;
   canvas->Brush->Color = clBtnFace;
   canvas->Ellipse( rightBushX - criticalRadius, rightBushY - criticalRadius,
                    rightBushX + criticalRadius, rightBushY + criticalRadius );
   canvas->Pen->Color   = color;
   canvas->Brush->Color = color;
*/
   canvas->LineTo( rightBushX, rightBushY );
   canvas->LineTo( rightDownX, rightDownY );
}

