//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
#include <math.h>
#define PI 3.141693
#define NS 6
#define D 5
#define VD 500 float Theta=0, Phi = 0,
SN1,SN2,CN1,CN2,NV=8,K1=10,K2=15,W,phi,theta,
V[8][3]={1,1,-1, 1,1,1, 1,-1,1, 1,-1,-1,
-1,1,-1, -1,-1,-1, -1,-1,1, -1,1,1},
VC[8][3],
SC[8][3],
N[6][3],
U[3],
P[3],
VSF[6],
SF[6][5]={0,1,2,3,0, 0,4,7,1,0, 4,5,6,7,4,
3,2,6,5,3, 1,7,6,2,1, 0,3,5,4,0};
int mouse_x,mouse_y; void DefineViewingParameters();
void VerticeArray();
void ViewingCoordinates(int);
void ScreenCoordinates(int);
void NormalArray();
void VisibilityTest();
void Plot(); TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender)
{
Timer1->Enabled=false;
Timer1->Interval=200;
Form1->Caption="正方體的旋轉";
Form1->Canvas->FillRect(Rect(0,0,ClientWidth,ClientHeight));
Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X=" IntToStr(X) " Y=" IntToStr(Y));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
AnsiString InputString;
mouse_x=X;
mouse_y=Y;
Form1->Canvas->FillRect(Rect(0,0,ClientWidth,ClientHeight));
Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X=" IntToStr(X) " Y=" IntToStr(Y));
if(Timer1->Enabled==false)
{
InputString = InputBox("Input Box", "請輸入Phi角", "45");
phi=StrToInt(InputString);
}
Timer1->Enabled^=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(theta>180)
{
theta=0; phi =5;
if(phi>180)phi=0;
}
Theta=theta; Phi=phi;
DefineViewingParameters();
VerticeArray();
NormalArray();
VisibilityTest();
Plot();
theta =1;
}
//---------------------------------------------------------------------------
void DefineViewingParameters()
{ Theta=Theta*PI/180;
Phi=Phi*PI/180;
SN1=sin(Theta); SN2=sin(Phi); CN1=cos(Theta); CN2=cos(Phi);
}
//---------------------------------------------------------------------------
void VerticeArray()
{ int j;
for(j=0;jCanvas->FillRect(Rect(0,0,Form1->ClientWidth,Form1->ClientHeight));
Form1->Canvas->TextOutA(5,5,"用滑鼠選擇繪圖位置 X=" IntToStr(mouse_x) " Y=" IntToStr(mouse_y));
for(j=0; jCanvas->MoveTo(a mouse_x,b mouse_y);
Form1->Canvas->Pixels[a mouse_x][b mouse_y]=clRed;
}
else Form1->Canvas->LineTo(a mouse_x,b mouse_y);
}
}
}
//--------------------------------------------------------------------------- ~ 勿在浮沙上面築高塔 ~
------
~ 勿在浮沙上面築高塔 ~