» آموزش پروسیجرها و توابع رسم اشکال هندسی سه بعدی در دلفی

مهرگان
 
 
 

آموزش پروسیجرها و توابع رسم اشکال هندسی سه بعدی در دلفی

3 مرداد 1391

آموزش پروسیجرها و توابع رسم اشکال هندسی سه بعدی در دلفی

به نام خدا

//----------------------------------------------------------------------------------------------

// پروسیجری برای رسم مکعب //

type

QuadpointsArray = array [0..3,0..2] of Double;

var

A: QuadpointsArray=((1.0,1.0,-1.0),(-1.0, 1.0,-1.0),(-1.0, 1.0, 1.0),(1.0, 1.0,1.0));

B: QuadpointsArray=(( 1.0,-1.0, 1.0),(-1.0,-1.0, 1.0),(-1.0, -1.0,-1.0),( 1.0,-1.0,-1.0));

C: QuadpointsArray=(( 1.0, 1.0, 1.0),(-1.0, 1.0, 1.0),(-1.0,-1.0, 1.0),( 1.0,-1.0, 1.0));

D: QuadpointsArray=(( 1.0,-1.0,-1.0),(-1.0,-1.0,-1.0),(-1.0, 1.0,-1.0),( 1.0, 1.0,-1.0));

E: QuadpointsArray=((-1.0, 1.0, 1.0),(-1.0, 1.0,-1.0),(-1.0,-1.0,-1.0),(-1.0,-1.0, 1.0));

F: QuadpointsArray=(( 1.0, 1.0,-1.0),( 1.0, 1.0, 1.0),(1.0,-1.0, 1.0),( 1.0,-1.0,-1.0));

//------------------------------------------------------------------------------------------------------------------

procedure DrawCube(A,B,C,D,E,F:QuadpointsArray);

begin

glBegin(GL_QUADS);

glColor3f(0.0,1.0,0.0); // Set The Color To Blue

glVertex3f(A[0][0],A[0][1],A[0][2]); //( 1.0, 1.0,-1.0);

glVertex3f(A[1][0],A[1][1],A[1][2]); //(-1.0, 1.0,-1.0);

glVertex3f(A[2][0],A[2][1],A[2][2]); //(-1.0, 1.0, 1.0);

glVertex3f(A[3][0],A[3][1],A[3][2]); //( 1.0, 1.0, 1.0);


glColor3f(1.0,0.5,0.0);

glVertex3f(B[0][0],B[0][1],B[0][2]); //( 1.0,-1.0, 1.0);

glVertex3f(B[1][0],B[1][1],B[1][2]); //(-1.0,-1.0, 1.0);

glVertex3f(B[2][0],B[2][1],B[2][2]); //(-1.0,-1.0,-1.0);

glVertex3f(B[3][0],B[3][1],B[3][2]); //( 1.0,-1.0,-1.0);


glColor3f(1.0,0.0,0.0);

glVertex3f(C[0][0],C[0][1],C[0][2]); //( 1.0, 1.0, 1.0);

glVertex3f(C[1][0],C[1][1],C[1][2]); //(-1.0, 1.0, 1.0);

glVertex3f(C[2][0],C[2][1],C[2][2]); //(-1.0,-1.0, 1.0);

glVertex3f(C[3][0],C[3][1],C[3][2]); //( 1.0,-1.0, 1.0);


glColor3f(1.0,1.0,0.0);

glVertex3f(D[0][0],D[0][1],D[0][2]); //( 1.0,-1.0,-1.0);

glVertex3f(D[1][0],D[1][1],D[1][2]); //(-1.0,-1.0,-1.0);

glVertex3f(D[2][0],D[2][1],D[2][2]); //(-1.0, 1.0,-1.0);

glVertex3f(D[3][0],D[3][1],D[3][2]); //( 1.0, 1.0,-1.0);


glColor3f(0.0,0.0,1.0);

glVertex3f(E[0][0],E[0][1],E[0][2]); //(-1.0, 1.0, 1.0);

glVertex3f(E[1][0],E[1][1],E[1][2]); //(-1.0, 1.0,-1.0);

glVertex3f(E[2][0],E[2][1],E[2][2]); //(-1.0,-1.0,-1.0);

glVertex3f(E[3][0],E[3][1],E[3][2]); //(-1.0,-1.0, 1.0);


glColor3f(1.0,0.0,1.0);

glVertex3f(F[0][0],F[0][1],F[0][2]); //( 1.0, 1.0,-1.0);

glVertex3f(F[1][0],F[1][1],F[1][2]); //( 1.0, 1.0, 1.0);

glVertex3f(F[2][0],F[2][1],F[2][2]); //( 1.0,-1.0, 1.0);

glVertex3f(F[3][0],F[3][1],F[3][2]); //( 1.0,-1.0,-1.0);

glEnd();

end;
//----------------------------------------------------------------------------------------------
// پروسیجری برای رسم هرم //

type
PyramidPointsArray = array [0..2,0..2] of Double;
var
W: PyramidPointsArray=(( 0.0, 1.0, 0.0),(-1.0,-1.0, 1.0),( 1.0,-1.0, 1.0));
X: PyramidPointsArray=(( 0.0, 1.0, 0.0),( 1.0,-1.0, 1.0),( 1.0,-1.0, -1.0));
Y: PyramidPointsArray=(( 0.0, 1.0, 0.0),( 1.0,-1.0, -1.0),(-1.0,-1.0, -1.0));
Z: PyramidPointsArray=(( 0.0, 1.0, 0.0),(-1.0,-1.0,-1.0),(-1.0,-1.0, 1.0));
//------------------------------------------------------------------------------------------------------------------
procedure DrawPyramid(W,X,Y,Z:PyramidPointsArray);
begin
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex3f(W[0][0],W[0][1],W[0][2]); //( 0.0, 1.0, 0.0);
glVertex3f(W[1][0],W[1][1],W[1][2]); //(-1.0,-1.0, 1.0);
glVertex3f(W[2][0],W[2][1],W[2][2]); //( 1.0,-1.0, 1.0);

glColor3f(0.0,1.0,0.0);
glVertex3f(X[0][0],X[0][1],X[0][2]); //( 0.0, 1.0, 0.0);
glVertex3f(X[1][0],X[1][1],X[1][2]); //( 1.0,-1.0, 1.0);
glVertex3f(X[2][0],X[2][1],X[2][2]); //( 1.0,-1.0, -1.0);

glColor3f(1.0,0.0,0.0);
glVertex3f(Y[0][0],Y[0][1],Y[0][2]); //( 0.0, 1.0, 0.0);
glVertex3f(Y[1][0],Y[1][1],Y[1][2]); //( 1.0,-1.0, -1.0);
glVertex3f(Y[2][0],Y[2][1],Y[2][2]); //(-1.0,-1.0, -1.0);

glColor3f(0.0,1.0,0.0);
glVertex3f(Z[0][0],Z[0][1],Z[0][2]); //( 0.0, 1.0, 0.0);
glVertex3f(Z[1][0],Z[1][1],Z[1][2]); //(-1.0,-1.0,-1.0);
glVertex3f(Z[2][0],Z[2][1],Z[2][2]); //(-1.0,-1.0, 1.0);
GlEnd();

end;

//----------------------------------------------------------------------------------------------
// پروسیجری برای رسم نان حلقه ای //
// for example: doughnut(0.285, 0.85, 30, 40, GL_QUADS);
procedure doughnut( R1 , R2 : GLdouble;nsides , rings : GLint;thetype : GLenum);
var
i , j : Integer;
theta , phi , theta1 , phi1 : GLdouble ;
p0 , p1 , p2 , p3 : array[0..2] of GLdouble;
n0, n1, n2,n3 : array[0..2] of GLdouble;

begin
for i := 0 To rings - 1 do
begin
theta := i * 2 * 3.1415927 / rings ;
theta1 := (i + 1) * 2 * 3.1415927 / rings ;
for j := 0 To nsides - 1 do
begin
phi := j * 2 * 3.1415927 / nsides;
phi1 := (j + 1) * 2 * 3.1415927 / nsides;
p0[0] := Cos(theta) * (R2 + R1 * Cos(phi));
p0[1] := -Sin(theta) * (R2 + R1 * Cos(phi));
p0[2] := R1 * Sin(phi);
p1[0] := Cos(theta1) * (R2 + R1 * Cos(phi));
p1[1] := -Sin(theta1) * (R2 + R1 * Cos(phi));
p1[2] := R1 * Sin(phi);
p2[0] := Cos(theta1) * (R2 + R1 * Cos(phi1));
p2[1] := -Sin(theta1) * (R2 + R1 * Cos(phi1));
p2[2] := R1 * Sin(phi1);
p3[0] := Cos(theta) * (R2 + R1 * Cos(phi1));
p3[1] := -Sin(theta) * (R2 + R1 * Cos(phi1));
p3[2] := R1 * Sin(phi1);
n0[0] := Cos(theta) * Cos(phi);
n0[1] := -Sin(theta) * Cos(phi);
n0[2] := Sin(phi);
n1[0] := Cos(theta1) * Cos(phi);
n1[1] := -Sin(theta1) * Cos(phi);
n1[2] := Sin(phi);
n2[0] := Cos(theta1) * Cos(phi1);
n2[1] := -Sin(theta1) * Cos(phi1);
n2[2] := Sin(phi1);
n3[0] := Cos(theta) * Cos(phi1);
n3[1] := -Sin(theta) * Cos(phi1);
n3[2] := Sin(phi1);
glBegin (thetype);
glNormal3dv (@n3);
glVertex3dv (@p3);
glNormal3dv (@n2);
glVertex3dv (@p2);
glNormal3dv (@n1);
glVertex3dv (@p1);
glNormal3dv (@n0);
glVertex3dv (@p0);
glEnd;
end;
end;

End;

//----------------------------------------------------------------------------------------------


موفق باشید

---


ارسال نظر

نام:
ایمیل:
متن نظر:
 
برای مشاهده بهتر سایت از مرورگر فایرفاکس ، اُپرا و یا گوگل کروم استفاده نمایید