Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sfCircleShape_setOrigin();  (Read 4149 times)

0 Members and 1 Guest are viewing this topic.

bostonbrooks

  • Newbie
  • *
  • Posts: 6
    • View Profile
sfCircleShape_setOrigin();
« on: March 21, 2016, 07:59:49 am »
Ive been experimenting, trying to get sfRenderWindow_drawCircleShape() to work,
it does work, but the function sfCircleShape_setOrigin() accepts coordinates that are scaled and negated.

eg.
#include <time.h>
#include <SFML/System.h>
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int main(void) {
    #define SCREEN_HEIGHT 300
    #define SCREEN_WIDTH 400

   
    sfVideoMode mode = {SCREEN_WIDTH, SCREEN_HEIGHT, 32};
    sfRenderWindow *window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);



        sfCircleShape *SelectedCircle = sfCircleShape_create();
        sfVector2f scale;
        scale.x = 1;
        scale.y = 0.5;
        sfCircleShape_setScale(SelectedCircle, scale);
        sfVector2f origin;
        origin.x = -150;
        origin.y = -150;
        sfCircleShape_setOrigin(SelectedCircle, origin);
        sfCircleShape_setRadius(SelectedCircle, 100);


        sfCircleShape_setFillColor(SelectedCircle, sfTransparent);
        sfCircleShape_setOutlineColor(SelectedCircle, sfCyan);
        sfCircleShape_setOutlineThickness(SelectedCircle, 5.0);
   
    sfRenderWindow_clear (window, sfColor_fromRGB (255,255,255));
        sfRenderWindow_drawCircleShape(window, SelectedCircle, NULL);
        //sfCircleShape_destroy(SelectedCircle);

    sfRenderWindow_display(window);
    while (1) {}
}

produces something like the attached image.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sfCircleShape_setOrigin();
« Reply #1 on: March 21, 2016, 12:41:24 pm »
the function sfCircleShape_setOrigin() accepts coordinates that are scaled and negated.
Why wouldn't it? You can set the origin to be outside of the range of the actual object. Setting a positive origin effectively moves the final image up and/or left whereas a negative origin effectively moves the final image down and/or right - as seen in your screenshot. The value of the origin is stored and processed at draw time, not at the actual time of setting it so it doesn't matter when it is set (before or after other settings).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfCircleShape_setOrigin();
« Reply #2 on: March 21, 2016, 06:17:48 pm »
The origin is set in local coordinates, which means before any transformation. And yes, setting negative origin offsets the shape to the bottom/right. Think about it twice (or re-read the doc) if you still don't understand why ;)

If you just want to move the shape, use setPosition instead.
Laurent Gomila - SFML developer