Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** Dibuja un circulo (Implementacion del algoritmo de Bresenham)***/
- void NGN_ProDraw::Circle(int32_t cx, int32_t cy, int32_t r, uint32_t color, int32_t ry, double in_angle, double out_angle) {
- // Asignacion de los radios y proteccion de 0
- int32_t _rx = (r < 1) ? 1:r;
- int32_t _ry = (ry == NGN_DEFAULT_VALUE) ? _rx:ry;
- _ry = (_ry < 1) ? 1:_ry;
- // Calculos
- int32_t right = (surface_width - 1); // Limites del buffer
- int32_t bottom = (surface_height - 1);
- int32_t x = _rx; // Coordenadas
- int32_t y = 0;
- int32_t ix = ((_ry * _ry) * (1 - (_rx << 1))); // Cambios de coordenada
- int32_t iy = (_rx * _rx);
- int32_t square_x = ((_rx * _rx) << 1); // Cuadrados
- int32_t square_y = ((_ry * _ry) << 1);
- int32_t stop_x = (square_y * _rx); // Puntos de detencion
- int32_t stop_y = 0;
- int32_t ellip_error = 0; // Error en el dibujado de la elipse
- // Variables adicionales
- int32_t _x = 0, _y = 0;
- // Bloquea el surface
- SDL_LockSurface(surface);
- // Acceso al array de pixeles
- uint32_t* p = (uint32_t*)surface->pixels;
- // Primera area de dibujado (izquierda y derecha)
- while (stop_x >= stop_y) {
- // Dibuja el pixel del cuadrante 1
- _x = cx + x;
- _y = cy + y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 2
- _x = cx - x;
- _y = cy + y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 3
- _x = cx - x;
- _y = cy - y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 4
- _x = cx + x;
- _y = cy - y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Incrementa la Y
- y ++;
- // Incrementa stop_y
- stop_y += square_x;
- // Incrementa el error de elipse
- ellip_error += iy;
- // Incrementa el incremento de Y
- iy += square_x;
- // Correccion de valores
- if (((ellip_error << 1) + ix) > 0) {
- // Reduce X
- x --;
- // Reduce stop_x
- stop_x -= square_y;
- // Incrementa el error de elipse
- ellip_error += ix;
- // Incremente el incremento de X
- ix += square_y;
- }
- }
- // Prepara la segunda area (arriba y abajo)
- x = 0;
- y = _ry;
- ix = (_ry * _ry);
- iy = ((_rx * _rx) * (1 - (_ry << 1)));
- ellip_error = 0;
- stop_x = 0;
- stop_y = (square_x * _ry);
- // Segunda area de dibujado (arriba y abajo)
- while (stop_x <= stop_y) {
- // Dibuja el pixel del cuadrante 1
- _x = cx + x;
- _y = cy + y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 2
- _x = cx - x;
- _y = cy + y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 3
- _x = cx - x;
- _y = cy - y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Dibuja el pixel del cuadrante 4
- _x = cx + x;
- _y = cy - y;
- if (!((_x < 0) || (_y < 0) || (_x > right) || (_y > bottom))) {
- p[((_y * surface_width) + _x)] = color;
- }
- // Incrementa la X
- x ++;
- // Incrementa stop_x
- stop_x += square_y;
- // Incrementa el error de elipse
- ellip_error += ix;
- // Incrementa el incremento de X
- ix += square_y;
- // Correccion de valores
- if (((ellip_error << 1) + iy) > 0) {
- // Reduce Y
- y --;
- // Reduce stop_y
- stop_y -= square_x;
- // Incrementa el error de elipse
- ellip_error += iy;
- // Incremente el incremento de Y
- iy += square_x;
- }
- }
- // Desbloquea el surface
- SDL_UnlockSurface(surface);
- // Indica el blit
- blit = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement