2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: welldrawing.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
18 #include "welldrawing.h"
20 //===========================================================================
21 /// global init(int n_fields, int dx, int dy, unsigned l, unsigned h)
22 /// init indexes and allocate FieldPoints
23 /// tags WellDrawingEngine
24 void WellDrawingEngine::init(int inum_fields
, int idx
, int idy
,
25 unsigned int il
, unsigned int ih
)
31 num_fields
=inum_fields
;
32 points
=new FieldPoints
[num_fields
];
38 //===========================================================================
39 /// global flush_dirty()
40 /// pseudo function that need flush dirty rec to the screen,
41 /// here it only delete dirty rect from queue
42 /// tags WellDrawingEngine
43 void WellDrawingEngine::flush_dirty()
48 plist
=dirty_list
.get_next();
51 //Here we need to draw dirty rec on the screen -> will be in overloaded childs
61 void WellDrawingEngine::draw_square(int color
, int x
, int y
)
66 void WellDrawingEngine::draw_trapazoid(int color
, int x
, int y
)
71 void WellDrawingEngine::sync()
76 void WellDrawingEngine::flush_all()
81 void WellDrawingEngine::bell(int)
87 //===========================================================================
88 /// global outer_rotation()
89 /// make shift current field id -> switch to next field -> rotate it
90 /// tags WellDrawingEngine
91 void WellDrawingEngine::outer_rotation()
94 if(current_id
>=num_fields
)
97 current_id
+=(f_step
+f_step
);
102 current_id
+=(f_step
+f_step
);
107 //===========================================================================
108 /// global set_field_sizes(int dx, int dy, int wall_delta, int base_delta)
109 /// set and calculate base vars
110 /// tags WellDrawingEngine
111 void WellDrawingEngine::set_field_sizes(int idx
, int idy
,
117 pix_wall_delta
=ipix_wall_delta
;
118 pix_base_delta
=ipix_base_delta
;
119 pix_base_width
=pix_base_delta
*MAX_WIDTH
;
120 pix_max_delta
=pix_wall_delta
*MAX_DEPTH
;
121 pix_max_width
=pix_base_width
+ 2*pix_max_delta
;
124 //===========================================================================
125 /// global calc_grid_points()
126 /// calculate all points for each field, rotate it with inner and
127 /// outer alpha angle
128 /// tags WellDrawingEngine
129 void WellDrawingEngine::calc_grid_points()
133 center_x
=pix_dx
+pix_max_width
/2;
134 center_y
=pix_dy
+pix_max_width
/2;
135 for(n
=0;n
<num_fields
;n
++) //For each field
137 //Calculate points for the walls
138 for(gi
=0;gi
<MAX_PERIMETER
;gi
++)
139 for(j
=0;j
<MAX_DEPTH
+1;j
++)
141 w
=gi
/MAX_WIDTH
; //calc wall number
142 i
=gi
-w
*MAX_WIDTH
; //and delta inside it
146 x
=j
*pix_wall_delta
+ (i
*(pix_max_width
- 2*pix_wall_delta
*j
))/MAX_WIDTH
;
150 x
=pix_max_width
- j
*pix_wall_delta
;
151 y
=j
*pix_wall_delta
+ (i
*(pix_max_width
- 2*pix_wall_delta
*j
))/MAX_WIDTH
;
154 x
=pix_max_width
- (j
*pix_wall_delta
+
155 (i
*(pix_max_width
- 2*pix_wall_delta
*j
))/MAX_WIDTH
);
156 y
=pix_max_width
- j
*pix_wall_delta
;
160 y
=pix_max_width
- (j
*pix_wall_delta
+
161 (i
*(pix_max_width
- 2*pix_wall_delta
*j
))/MAX_WIDTH
);
164 // dbgprintf(("i=%2d, j=%2d -> x=%4d, y=%4d\n",i,j,x,y));
168 inner_max_alpha
*float(j
)/float(MAX_DEPTH
)*float(n
)/float(num_fields
-1)+
169 float(n
)*outer_max_alpha
/float(num_fields
-1);
171 if(alpha
!=0.0) //lets make rotation
173 points
[n
].wall_points
[gi
][j
].x
=int(
174 float((x
-center_x
))*cos(alpha
) -
175 float((y
-center_y
))*sin(alpha
) +
178 points
[n
].wall_points
[gi
][j
].y
=int(
179 float((x
-center_x
))*sin(alpha
) +
180 float((y
-center_y
))*cos(alpha
) +
185 points
[n
].wall_points
[gi
][j
].x
=x
;
186 points
[n
].wall_points
[gi
][j
].y
=y
;
189 for(j
=0;j
<MAX_DEPTH
+1;j
++)
190 points
[n
].wall_points
[MAX_PERIMETER
][j
]=points
[n
].wall_points
[0][j
];
192 //Calculate points for the base (floor) of the glass
193 for(i
=0;i
<MAX_WIDTH
+1;i
++)
194 for(j
=0;j
<MAX_WIDTH
+1;j
++)
196 x
=pix_dx
+ pix_max_delta
+ i
*pix_base_delta
;
197 y
=pix_dy
+ pix_max_delta
+ j
*pix_base_delta
;
199 float(n
)*inner_max_alpha
/float(num_fields
-1) +
200 float(n
)*outer_max_alpha
/float(num_fields
-1);
201 if(alpha
!=0.0) //lets make rotation
203 points
[n
].base_points
[i
][j
].x
=int(
204 float((x
-center_x
))*cos(alpha
) -
205 float((y
-center_y
))*sin(alpha
) +
208 points
[n
].base_points
[i
][j
].y
=int(
209 float((x
-center_x
))*sin(alpha
) +
210 float((y
-center_y
))*cos(alpha
) +
215 points
[n
].base_points
[i
][j
].x
=x
;
216 points
[n
].base_points
[i
][j
].y
=y
;