Transformasi objek 3D merupakan perluasan dan teknik. Sebagaimana dalam transformasi 2D, sembarang transformasi dapat disajikan ke dalam suatu matrik transformasi dan transformasi yang lebih rumit dapat dinyatakan oleh sebuah matrik transformasi yang merupakan gabungan dari matrik-matrik transformasi dasar yang ada.
ROTASI
SHEARING
Shearing pada sembarang sepasang sumbu dapat dilaksanakan pada sumbu ke tiga.
- Matrik transformasi untuk shearing :
1) Kamera Sintetik
3) Menentukan arah kamera
INTERFACE :
SOURCE CODE :
//---------------------------------------------------------------------------
#include
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
struct Elemen { float x,y ;} ;
Elemen Objek[17];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++){ Objek[i].y-=5;};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++){ Objek[i].x-=5;};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++){ Objek[i].x+=5;};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++){ Objek[i].x+=5;};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++)
{ Objek[i].y*=2;
Objek[i].x*=2;
};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
int i;
for (i=1;i<=16;i++)
{
Objek[i].y/=2;
Objek[i].x/=2;
};
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
Elemen TempObjek[17];
int i; float Sdt;
for (i=1;i<=16;i++)
{
Objek[i].x=Objek[i].x-Image1->Width / 2;
Objek[i].y=Objek[i].y-Image1->Height / 2;
Sdt=10*M_PI/180;
TempObjek[i].x=(Objek[i].x*cos(Sdt)-Objek[i].y*sin(Sdt));
TempObjek[i].y=(Objek[i].x*sin(Sdt)+Objek[i].y*cos(Sdt));
Objek[i]=TempObjek[i];
Objek[i].x=Objek[i].x+Image1->Width / 2;
Objek[i].y=Objek[i].y+Image1->Height / 2;
}
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
Elemen TempObjek[17];
int i,n,m; float Sdt;
for (i=1;i<=16;i++)
{
n = Objek[3].x;
m = Objek[3].y;
Objek[i].x=Objek[i].x-n;
Objek[i].y=Objek[i].y-m;
Sdt=10*M_PI/180;
TempObjek[i].x=(Objek[i].x*cos(Sdt)-Objek[i].y*sin(Sdt));
TempObjek[i].y=(Objek[i].x*sin(Sdt)+Objek[i].y*cos(Sdt));
Objek[i]=TempObjek[i];
Objek[i].x=Objek[i].x+n;
Objek[i].y=Objek[i].y+m;
}
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
FormActivate(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
Objek[1].x = 100; Objek[1].y = 50;
Objek[2].x = 50; Objek[2].y = 50;
Objek[3].x = 50; Objek[3].y = 100;
Objek[4].x = 100; Objek[4].y = 100;
Objek[5].x = 125; Objek[5].y = 125;
Objek[6].x = 75; Objek[6].y = 125;
Objek[7].x = 75; Objek[7].y = 175;
Objek[8].x = 125; Objek[8].y = 175;
Objek[9].x = 100; Objek[9].y = 100;
Objek[10].x = 125; Objek[10].y = 175;
Objek[11].x = 50; Objek[11].y = 100;
Objek[12].x = 75; Objek[12].y = 175;
Objek[13].x = 50; Objek[13].y = 50;
Objek[14].x = 75; Objek[14].y = 125;
Objek[15].x = 100; Objek[15].y = 50;
Objek[16].x = 125; Objek[16].y = 125;
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
int i;
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);
Image1->Canvas->MoveTo(Objek[4].x,Objek[4].y);
for (i=1;i<=4;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[8].x,Objek[8].y);
for (i=5;i<=8;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[10].x,Objek[10].y);
for (i=9;i<=10;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[12].x,Objek[12].y);
for (i=11;i<=12;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[14].x,Objek[14].y);
for (i=13;i<=14;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[16].x,Objek[16].y);
for (i=15;i<=16;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
}
//---------------------------------------------------------------------------
UNIT1.H
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TGroupBox *GroupBox1;
TGroupBox *GroupBox2;
TGroupBox *GroupBox3;
TButton *Button1;
TButton *Button2;
TButton *Button3;
TButton *Button4;
TButton *Button5;
TButton *Button6;
TButton *Button7;
TButton *Button8;
TButton *Button9;
TButton *Button10;
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Button5Click(TObject *Sender);
void __fastcall Button6Click(TObject *Sender);
void __fastcall Button7Click(TObject *Sender);
void __fastcall Button8Click(TObject *Sender);
void __fastcall Button9Click(TObject *Sender);
void __fastcall Button10Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
OUTPUT :
Tidak ada komentar:
Posting Komentar