forums

TNT Basic Forums > Feedback
Rotation
< Last Thread     Next Thread >
Author
Thread        Post A Reply

03-29-2003 01:24

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Could the collision mask rotate with the sprite? I get a rotated sprite but the collision mask keeps unrotated.

03-30-2003 20:52

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

TNT Basic doesn't currently support this I'm afraid. We'd like to do it, but we have yet to figure out a fast way of doing it. The problem is that the graphics card does the scaling and rotations and the CPU does the collisions. As the CPU doesn't have access to the scaled and rotated graphics it can't detect collisions. So we have rotate and scale the collision masks or somehow get the graphics card to do the collisions for us.

We'll try and get it working but don't hold you breath!

Cheers,

Mark

03-30-2003 21:29

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

I found out that a manual check such as
if (x1-x0)^2+(y1-y0)^2<r^2
is often MUCH better than the sprite col function in rotation cases.

03-31-2003 20:59

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

The default routine that TNT Basic uses for scaled rotated images is a rotated rectangle collision. You may find that using a circular radius as you are doing may give slightly better results if your sprite is better approximated by a circle than a box. I'll suggest people try it if they aren't happen with the rotated box case.

Cheers,

Mark

03-31-2003 22:52

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

> found out that a manual check such as
> if (x1-x0)^2+(y1-y0)^2<r^2
> is often MUCH better than the sprite col function in rotation cases

I'm afraid I'm not advanced enoughed in Maths. What does this code do?

03-31-2003 23:08

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

Mark, I think really it' s not a rotated rectangle! I' m quite sure (absolutely sure on my iMac) that the mask becomes not a rotated rectangle, but the "non rotated" rectangle that contains the sprite :

example: sprite is a long thin rectangle: if the sprite is horizontal or perpendicular the mask is the sprite: if the sprite is 45 degrees, the mask is the square (with sides parellel to the standard x,y axis) that contains the long, thin rectangle. This causes very strange collisions with long thiin sprites.

03-31-2003 23:13

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

> found out that a manual check such as
> if (x1-x0)^2+(y1-y0)^2<r^2
> is often MUCH better than the sprite col function in rotation cases

I'm afraid I'm not advanced enoughed in Maths. What does this code do?

It looks if the distance between points (x0,y0) and (x1,y1) is smaller than "r" (a generic number)

04-01-2003 22:01

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

>> found out that a manual check such as
>> if (x1-x0)^2+(y1-y0)^2<r^2
>> is often MUCH better than the sprite col function in rotation cases
>
>I'm afraid I'm not advanced enoughed in Maths. What does this code do?
>
>It looks if the distance between points (x0,y0) and (x1,y1) is smaller than "r" (a >generic number)


Sorry, I'm only 14. How am I supposed to use it?

04-04-2003 21:07

Posted by:
Wil Hostman

Find more posts by Wil Hostman

In Radius Check

Here is some code for you to use the "Hypotenuse Fomula"; copy and paste.

procedure radiuscheck (int xa, int ya, int xb, int yb, int r)
int dx, dy, dr, out
dx = (xa - xb)*(xa - xb)
dy =(ya - yb) * (ya - yb)
dr = r * r
if (dx + dy) > dr
out = 1
else
out = 0
end if
return out
end proc

when invoked
put the x and y for item 1 in xa and yb
the x and y for item 2 in xb and yb
and the maimum distance to be "In range" in r.

04-05-2003 17:40

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

Its the Pythagorean theorem. Its can be used to calculate the distance between two points.

(x2-x1)^2+(y2-y1)^2=r^2

Where r is the distance squared. To get the actual distance, find the square root of (x2-x1)^2+(y2-y1)^2.

He's using this to check for a collision between the sprite and a point. So, we enclose the sprite in an imaginary circle of radius r (Which would be equal to the distance between the center of the sprite and its furthest corner.) Now if the distance between the point and the center of the sprite is less than or equal to r, we know the point is on or in the circle containing the sprite, and we have a collision.

04-08-2003 06:42

Posted by:
Holmes

Location:
Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

Stencil buffer solution?

Hey tully, for sprite rotation collision detection why not use the OpenGL's stencil buffer?

Draw one sprite's mask to the stencil buffer, then draw the other, anding the values together. If any of the values in the buffer remain 1, then wallah, you've got a collision. I've never tried this myself, but I would imagine that it'd work.

04-09-2003 22:28

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Well I thought of that, and I must admit I'm not the worlds expert on OpenGL so I could be wrong here, but if you did the stencil buffer surely you'd still have to afterwards check each pixel in the buffer individually to see if it's been written to 2 or more times? Or does OpenGL have some sort of cunning callback based mechanism? I'm sure we could solve it it we hacked at it for long enough, but if anyone does want to discuss solutions then we can do so in the Beyond Basic forum.

Cheers

Mark

04-11-2003 23:52

Posted by:
Holmes

Location:
Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

Indeed, nor do I consider myself an OpenGL expert, even though I develop with it. I think it takes a lot to be qualified as one of those :P I'll see if I can come up with anything for you.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.