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.

Topics - Fugan

Pages: [1]
System / Rect with negative width
« on: May 04, 2012, 02:33:33 am »
I did some searching on the forum, but "Rect" "Intersect" "Negative" and the like are not the best search terms, so I apologise if this has been noted.

I held off posting on the tracker because I wanted to check if this is by design or a bug. If this is a bug I will happily toodle off to the Github and submit a patch.

Rectangles with a negative width/height do not seem to intersect properly with rectangles with positive width/height. For example, a rectangle at 0,0 with width and height of 10 should intersect with a rectangle at 15, 15 with a width and height of -10. In SFML they do not.

Here is the obligatory code snippet:
Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main(int argc, char *argv[]) {

// intersect test
sf::IntRect rect1(0,0,10,10); //Rectangle at 0,0 with width of 10 and height of 10
sf::IntRect rect2(15,15,-10,-10); //Rectangle at 15,15 with width of -10 and height of -10
bool test1 = rect1.intersects(rect2);
std::cout << "Test 1 " << test1 << std::endl;
return 0;
The output is:
Code: [Select]
Test 1 0

So clearly, the rectangles are considered to not intersect. Is this the intent?

For anyone interested in a more involved test, I've attached a .cpp that checks a couple different combinations.

[attachment deleted by admin]

Graphics / Inverted Texture Rect explanation
« on: February 22, 2012, 12:04:22 am »
From what I've read, inverted texture rects should be working, but I can't seem to get the behaviour I want.

For example, assuming a texture is 64x64, w and h are the width and height values, sprite is an initialised sf::sprite, the origin is in the top left default position, and the texture has been properly set (all tested)

Based on what I know about how this all works this code
Code: [Select]
sprite.SetTextureRect(sf::InteRect(w, 0, -w, h) );
should generate a flipped sprite, since I am setting the origin of the sub-rect for the texture to 0, 64 and creating a rectangle that goes backward 64 pixels and down 64 pixels, which should generate a texture that is mirrored on the Y axis.  

What I actually get when I draw the sprite, it that it is translated -w pixels on the x axis from the position.  i.e., if the aforementioned sprite is located at (128,128) the sprite will render as if it was located at (64,128).  The rendered sprite is also not mirrored.

(I have a solution that works, using:
Code: [Select]
sprite.SetTextureRect(sf::InteRect(w, 0, -w, h) );

I like this solution better than setting the origin to (w/2, h/2) since I am a top-left kinda guy.  In this case I understand how the SetScale() function works.  I am looking for an explanation as to why the inverted texture rect behaves the way it does).

Pages: [1]