Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** Dibuja un arco ***/
- void NGN_ProDraw::Arc(int32_t cx, int32_t cy, int32_t r, double start_angle, double end_angle, uint32_t color, int32_t ry, uint8_t close) {
- // Asignacion de los radios y proteccion de 0
- int32_t _rx = r;
- int32_t _ry = (ry == NGN_DEFAULT_VALUE) ? _rx:ry;
- // Ordena los angulos de inicio y fin
- double st_angle = 0.0f, ed_angle = 0.0f;
- if (start_angle == end_angle) {
- // Si son identicos, sal
- return;
- } else if (start_angle > end_angle) {
- // Si el angulo inicial es mayor que el final
- st_angle = start_angle;
- ed_angle = end_angle += (PI * 2.0f);
- } else {
- st_angle = start_angle;
- ed_angle = end_angle;
- }
- // Algun radio es 0...
- if ((_rx == 0) && (_ry == 0)) {
- return;
- }
- // Calculos
- int32_t x = 0, y = 0; // Coordenadas
- int32_t _x = 0, _y = 0;
- int32_t _fx = 0, _fy = 0;
- // Precision
- double p = 0.0f;
- if (_rx >= _ry) {
- p = (PI * 4.0f) / (double)_rx;
- } else {
- p = (PI * 4.0f) / (double)_ry;
- }
- // Primer punto del angulo
- _fx = _x = (std::round((std::cos(st_angle) * (float)_rx)) + cx);
- _fy = _y = (std::round((std::sin(st_angle) * (float)_ry)) + cy);
- // Dibuja los segmentos del arco
- for (double angle = st_angle; angle <= ed_angle; angle += p) {
- // Calculos de las coordenadas
- x = (std::round((std::cos(angle) * (float)_rx)) + cx);
- y = (std::round((std::sin(angle) * (float)_ry)) + cy);
- if ((_x != x) || (_y != y)) Line(x, y, _x, _y, color);
- _x = x;
- _y = y;
- }
- // Ultimo punto del arco
- x = (std::round((std::cos(ed_angle) * (float)_rx)) + cx);
- y = (std::round((std::sin(ed_angle) * (float)_ry)) + cy);
- if ((_x != x) || (_y != y)) Line(x, y, _x, _y, color);
- // Has de cerrar el arco (0 = no, 1 = entre los puntos, 2 = con el centro)
- switch (close) {
- // Entre ellos
- case 1:
- Line(x, y, _fx, _fy, color);
- break;
- // Con el centro
- case 2:
- Line(x, y, cx, cy, color);
- Line(_fx, _fy, cx, cy, color);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement