Slick Forums

Discuss the Slick 2D Library
It is currently Tue Jun 18, 2013 8:49 pm

All times are UTC




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Thu Feb 04, 2010 12:55 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 620
Location: Iceland
In any case, I believe it should work the same in Slick as it does in Java2D.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 04, 2010 11:05 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
I don't know whether this is related to the original post, but it seems as though it may be.

Image

What you see here is the rectangle which is meant to be around the player. The player/world is scaled in 4x so you can see that the rectangle doesn't include the last pixel on the bottom and on the right. It's a bit of a pain when it comes to collision detection because it means I'll have to make the shapes one pixel bigger than the images.

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 05, 2010 8:27 am 
Offline

Joined: Mon Jan 11, 2010 10:37 pm
Posts: 68
Yes, this seems to be related to this issue. Can You confirm that the guy's bounding box in your game is working correctly on the guy's left? I mean: from the simple example with rectangle-contains I've got that rectangle does not contain its top-most or left-most points (besides the right and bottom as You show on picture). From Your picture it seams that it does.

_________________
Jattra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 05, 2010 11:54 am 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
It seems to contain all points except the bottom and right sides.

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 05, 2010 1:23 pm 
Offline

Joined: Mon Jan 11, 2010 10:37 pm
Posts: 68
OK, I have been playing with Rectangle.contains again. this time giving it the float precision.
Result: rectangle with position 0 and size 10 contains points from 0.001 to 8.999 (there can be more zeros before 1 and more nines after 8 of course).

The left side problem is not visible because there is insignificant differrence between 0 and 0.001.
The right side problem is visible because whole pixel 8.999 to 9.999 is missing.

The comparison with Java2D: Rectangle2d.Float with position 0 and size 10 contains 0 to 9.999

Thanks to Gwinnell, we have one real example of this strange behaviour influence.

What do You think about it?

_________________
Jattra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 05, 2010 4:38 pm 
Offline
Regular

Joined: Mon Feb 23, 2009 11:32 am
Posts: 113
you could just increase your size like he said, to accomadate for the lack of a pixel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 05, 2010 6:39 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
h3ckboy wrote:
you could just increase your size like he said, to accomadate for the lack of a pixel


These are exactly the types of gimmicks I try to avoid when developing an engine/game. :)

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 20, 2010 9:11 pm 
Offline

Joined: Mon Jan 11, 2010 10:37 pm
Posts: 68
Hi Kev,
have You taken any stand in this issue?
Could You somehow comment it?

Thank You very much for Your time.

_________________
Jattra


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 20, 2010 11:06 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
I'm not sure what you want me to say. I'll fix it on the next bug run just as soon as I get a proper bit of time after this cold.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 6:07 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Fixed the contains method.

In SVN.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 7:42 pm 
Offline

Joined: Mon Jan 11, 2010 10:37 pm
Posts: 68
Thank You Kev, it works much better now, though it is not according to Java2D yet.
Try this simple test:

Code:
public static void main(String[] args) {
   // Slick2D
   Rectangle rect = new Rectangle(0, 0, 10, 10);
   System.out.println(rect);
   System.out.println("Slick2D: Does the rectangle contain [0, 0]? " +rect.contains(0, 0));
   System.out.println("Slick2D: Does the rectangle contain [9.9, 9.9]? " +rect.contains(9.9f, 9.9f));
   
   System.out.println();
   
   // Java2D
   Rectangle2D.Float rect2 = new Rectangle2D.Float(0, 0, 10, 10);
   System.out.println(rect2);
   System.out.println("Java2D: Does the rectangle contain [0, 0]? " +rect2.contains(0, 0));
   System.out.println("Java2D: Does the rectangle contain [9.9, 9.9]? " +rect2.contains(9.9f, 9.9f));
}


The result is:

[Rectangle 10.0x10.0]
Slick2D: Does the rectangle contain [0, 0]?
false
Slick2D: Does the rectangle contain [9.9, 9.9]?
true

java.awt.geom.Rectangle2D$Float[x=0.0,y=0.0,w=10.0,h=10.0]
Java2D: Does the rectangle contain [0, 0]?
true
Java2D: Does the rectangle contain [9.9, 9.9]?
true

I see that now the contains method returns true for points from 0.001 to 9.999. Maybe this is enough but still there is an area between two rectangles that does not belong to any. What is Your opinion?

_________________
Jattra


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 7:47 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
If it doesn't include 10,10 then I don't see why it should include 0,0. "because Java2D is that way" isn't enough.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 8:05 pm 
Offline

Joined: Mon Jan 11, 2010 10:37 pm
Posts: 68
kevglass wrote:
If it doesn't include 10,10 then I don't see why it should include 0,0. "because Java2D is that way" isn't enough.

Kev


Simply because the size is 10, which is 0, 1, 2, 3, ... 8, 9 in int precision and 0.0 to 9.9 in float precision. And because two neighboring rectangles should fill continuous area.

Let's have R1(0, 0, 10, 10) and R2(10, 0, 10, 10). Point [10, 5] does not belong to any of them. I think it should belong to R2.

Please, I really don't want to bother You with this issue. Just trying to make Slick better. I understand that better in my eyes isn't necessarily better for all. Just think it over. Thank You.

_________________
Jattra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2010 12:10 pm 
Offline

Joined: Fri Jul 13, 2007 6:38 pm
Posts: 11
Location: Stockholm, Sweden
kevglass wrote:
If it doesn't include 10,10 then I don't see why it should include 0,0. "because Java2D is that way" isn't enough.

Kev

A reason would be to make it possible to contain an entire area with multiple rectangles without having any overlap or gaps. This is not possible at the moment.

Lets consider this problem in one dimension, a line. Current implementation will contain the points in the interval (x, x+width). That is, neither of the edges is contained. With this we can't contain an area with multiple rectangles without either having gaps or overlaps.

To fix this one have to either include the left OR the right boundary. [x, x+width) or (x, x+width]. Java2D chose the former, to include the top/left boundary in the shape.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2010 5:08 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Ok, looks like this thread caught me on one of my many down moments in the last year. I think you're absolutely right but this is going to have to be another change that comes after the next major release. It's going to break way to many games otherwise.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group