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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tanders12

Pages: [1]
1
Graphics / SetCenter()
« on: May 18, 2011, 07:52:09 am »
Ah ok. Well this is all still a bit confusing but it's working the way I expect now and I think I have a workable understanding of it. I'm sure as I work with things more it will eventually just click.

Thanks so much for your help Laurent and for making such an awesome library!

2
Graphics / SetCenter()
« on: May 18, 2011, 05:46:24 am »
Quote from: "Laurent"

If you call SetPosition(x, y), the top-left corner of your shape will move to (x, y).


With the following code:
Code: [Select]

line_start.x = x1;
line_start.y = y1;

line_end.x = 0 - ( Line_Length * cos( M_PI / 4 ) );
line_end.y = 0 - ( Line_Length * sin( M_PI / 4 ) );

Line = sf::Shape::Line ( 0,
                                     0,
                                     line_end.x,
                                     line_end.y
                                     Line_Thickness,
                                     Bounds_Color,
                                     Border_Width,
                                     Border_Color );

Line.SetPosition( line_start );


The top left corner of the line isn't moved to x1,y1 like you said. Instead the bottom right corner of the line is. I think it's because I'm using negatives to define the line from 0,0, correct? The reason I'm doing that is because the goal is to have a line of a given length displayed at a 160 degree angle.

3
Graphics / SetCenter()
« on: May 17, 2011, 08:54:16 pm »
Ah... that makes sense I will try that tonight. Is it normal practice to initialize entity's at 0,0 and then move them where you want them?

4
Graphics / SetCenter()
« on: May 17, 2011, 07:14:01 pm »
Ok that definitely helps, but there must be something wrong with my code because it doesn't seem to be working that way. If I use only SetPosition, the top left corner of my line doesn't move to the new position, instead it is moving completely off the window where I can't even see it.

Maybe this will help me understand. You said that the default position of the center is (0,0). Is that (0,0) on the line or the global (0,0) on the window? If it's on the window then the behavior I'm seeing sort of makes sense.

5
Graphics / SetCenter()
« on: May 17, 2011, 06:58:22 pm »
Ok I think I might be getting it. SetPosition doesn't set the position of the entity, it sets the position of the entity's center, which by default is at 0,0 - correct? So when I only use one of the functions it shifts the entity of the window. They both behave very similar but SetCenter allows finer control? Does SetCenter set the center to a point (with an ID) on the entity or just the top left position?

6
Graphics / SetCenter()
« on: May 17, 2011, 06:48:42 pm »
Ok thank you it seems to be working better with the following:

Code: [Select]

x1 = x_pos + (bounds_size * .5);
y1 = y_pos + (bounds_size * .5);
x2 = x1 - (Line_Length * cos(M_PI / 4));
y2 = y1 - (Line_Length * sin(M_PI / 4));

Line = sf::Shape::Line ( x1, y1, x2, y2, LINE_THICKNESS, LINE_COLOR, BORDER_WIDTH, BORDER_COLOR );
   
Line.SetPosition(x1, y1);
Line.SetCenter(x1, y1);


After your last post I tried it using just SetPosition, and it change the point it rotates around to x1,y1, but the radius was still to large. Instead of the line pivoting around one of it's points, the entire line circled around x1,y1 with a large radius of maybe 300 or 400, at times going off the window entirely. After I used SetPosition and SetCenter together, it now pivots around the point.

I've played with different values for SetCenter and SetPosition and I have been unable to discern any pattern in order to figure out the difference, all I know is that if I use them together it sort of works. Could you please give a more detailed explanation?

7
Graphics / SetCenter()
« on: May 17, 2011, 06:25:59 pm »
If GetPosition refers to the position of the center, what does GetCenter refer to?

8
Graphics / SetCenter()
« on: May 17, 2011, 09:36:18 am »
This is driving me nuts. I can't understand how SetCenter works, or how it is different from Move and SetPosition. I have a line that starts out in the middle of a box at 160 degrees and I'm trying to make it pivot around point 0 (x1, y1), but when I run the following code the line ends up clear off the screen somewhere. I have it set up so when I press a button on my joystick it rotates by 30 degrees. The line seems to rotate around (0,0) even after changing the center with SetCenter as below.


Code: [Select]

 x1 = x_pos + (bounds_size * .5);
 y1 = y_pos + (bounds_size * .5);
 x2 = x1 - (Line_Length * cos(M_PI / 4));
 y2 = y1 - (Line_Length * sin(M_PI / 4));

 Line = sf::Shape::Line ( x1, y1, x2, y2, LINE_THICKNESS, LINE_COLOR, BORDER_WIDTH, BORDER_COLOR );
   
 Line.SetCenter(x1, y1);

9
Window / Pixels off by one.
« on: May 17, 2011, 03:11:34 am »
Ok I'm sure the answer to my question is somewhere in the forums but doing a search for the title didn't get me to far.

When you define a window or a rectangle to be a certain size, does that define the actual size or the number of pixels? For example, if I make a window of size 100x100, the upper-left pixel is (0,0), correct? So is the bottom-right pixel (99,99) or (100,100)? If it's (100,100) then the actual size would be 101x101.

The problem I'm having is that I'm referring to positions within the window using constants that are ratios of the full window size, and I suspect that they are off by just a little bit because I'm assuming the size is 100x100. I hope this makes sense...

Pages: [1]
anything