-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.pas
More file actions
115 lines (108 loc) · 3.7 KB
/
Copy pathrotate.pas
File metadata and controls
115 lines (108 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
unit rotate;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, Spin;
type
Tf_rotate = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
RadioGroup1: TRadioGroup;
SpinEdit1: TSpinEdit;
Label1: TLabel;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
procedure rotate(); // rotate vx & vy around selected r_axis
end;
var
f_rotate: Tf_rotate;
implementation
uses tools,OpenGL;
{$R *.dfm}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure Tf_rotate.rotate();
var
a,xi,yi,zi,r : real;
x,y,z,r1 : real;
m : integer;
begin
xi:=0; yi:=0; zi:=0; a:=0; r:=0;
x:=0; y:=0; z:=0; r1:=0;
glColor3d(1,1,1);
//=================== start recalculate vx & vy for rotate
if (surface_type=2) then glEnable(GL_LIGHTING);
case (surface_type) of // select what type of drawing needed
0 : glPolygonMode(GL_FRONT_AND_BACK,GL_POINTS); // drawing points
1 : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); // drawing wire surface
2 : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // drawing surface
end;
// start drawing surface
if (surface_type=0) then glBegin(GL_POINTS) else glBegin(GL_TRIANGLE_STRIP);
for m:=0 to v_size-2 do
begin
while (a<(2*PI)) do
begin
case r_axis of
0 : // rotate around x
begin
xi:=vx[m];
zi:=vy[m]*sin(a);
yi:=vy[m]*cos(a);
// next point for drawing surfaces
x:=vx[m+1];
z:=vy[m+1]*sin(a);
y:=vy[m+1]*cos(a);
end;
1 : // rotate around y
begin
yi:= vy[m];
zi:= vx[m]*cos(a);
xi:=-vx[m]*sin(a);
// next point for drawing surfaces
y:= vy[m+1];
z:= vx[m+1]*cos(a);
x:=-vx[m+1]*sin(a);
end;
2 : // rotate around z
begin
xi:= vx[m]*cos(a)+vy[m]*sin(a);
yi:=-vx[m]*sin(a)+vy[m]*cos(a);
// next point for drawing surfaces
x:= vx[m+1]*cos(a)+vy[m+1]*sin(a);
y:=-vx[m+1]*sin(a)+vy[m+1]*cos(a);
end;
end;
r:=sqrt(sqr(xi)+sqr(yi)+sqr(zi)); // calculate if point coordinates...
r1:=sqrt(sqr(x)+sqr(y)+sqr(z)); // ...out of draw area
if (r>5.5) or (r<-5.5) or (r1>5.5) or (r1<-5.5) then // don't draw, out of screen
begin
a:=a+PI/r_angle;
continue;
end;
glVertex3d(xi,yi,zi);
glVertex3d(x,y,z);
a:=a+PI/r_angle;
end;
a:=0;
end;
glEnd();
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // this is default value
glDisable(GL_LIGHTING);
//===================
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure Tf_rotate.BitBtn1Click(Sender: TObject);
begin
if (v_size=0) then
begin ShowMessage('Error 05: Íå÷åãî âðàùàòü! Âûáåðèòå ôóíêöèþ!'); Exit; end;
if (RadioGroup1.ItemIndex=3) then begin need_rotate:=0; Exit; end else need_rotate:=1;
r_angle:=f_rotate.SpinEdit1.Value; // every step function rotate on PI/r_angle
r_axis:=f_rotate.RadioGroup1.ItemIndex; // rotate around axis: 0 - x; 1 - y; 2 - z
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
end.