Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 27th Dec 2010 12:50
If attractors are going to be used for explosions I'd better add some new functionality. I'll make it so that the attractor will optionally only affect visible bodies. Visibility will be determined by whether a straight line can be drawn from the attractor to the centre of the body without crossing as static or kinematic body.

Quote: "Would it be possible to have a command to disable collisions between two objects?"


There are three different ways to do this in Box2D.

1) The simplest but least powerful
Each fixture has a group. Only fixtures in the same group will collide with each other, unless the group is negative, in which case it will collide with all groups except for that one.
b2SetFixtureFilterData

2) Not as simple but more powerful
Each fixture has a category and a mask. Two fixtures will only collide if the category of one ANDed with the mask of the other is non-zero and vice versa.
b2SetFixtureFilterData

3) Complicated but as powerful as you want
You can set a callback function to be called whenever two fixtures might collide. Depending on what you return from the function the fixtures will either collide or not collide.
b2SetContactFilter

Quote: "It would be nice though to be able to define a starting and ending value in degrees to be able to setup an emission "cone" sort of like how particle emitters work."


I'll see about adding this.

[b]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 27th Dec 2010 18:29 Edited at: 27th Dec 2010 18:47
Added attractor limits and ray test!

New commands:
b2SetAttractorLimitsEnabled
b2GetAttractorLimitsEnabled
b2SetAttractorLimits
b2GetAttractorLimitInnerRadius
b2GetAttractorLimitOuterRadius
b2GetAttractorLimitDirection
b2GetAttractorLimitAngle
b2SetAttractorRayTestEnabled
b2GetAttractorRayTestEnabled

For a total of 310 commands.

edit:
Just sent off the latest version to TGC so that it can be protected.

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Jan 2011 12:00
Great work Diggsey, any idea when this will become available?

I'm putting things back down to first gear on my WIP while I wait for this update...

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Jan 2011 12:59
Soon, hopefully I sent the new installer to TGC on the 30th, but I think Mike's away, so it might have to wait until he gets back.

[b]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Jan 2011 12:50
The new version is now available for download from your My Products page

Enjoy!

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jan 2011 22:12
Fantastic, thanks Diggsey!

Tapewormz
21
Years of Service
User Offline
Joined: 15th Sep 2002
Location: Winnipeg, Mantoba, Canada
Posted: 14th Jan 2011 07:45 Edited at: 14th Jan 2011 07:49
I just installed DBP and updated to the latest version. Also installed all my plugins including box2D. I installed IamM's plugins. I loaded tutorial 7 and tried to compile it and got an error: Undefined Parser Error.

Weird, I compiled it again and it ran just fine this time. Bizarre. I'll chalk that up to a synergy/compiler issue.
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 16th Jan 2011 00:04 Edited at: 16th Jan 2011 00:07
Diggsey,

I tried to use the new Attractor commands the way they made sense to me but nothing is happening. Could you knock up a small demo?

Thanks.

Intel Core Duo2 Quad Q9550 2.8 GHz - Asus P5N-D - 2x Geforce 8800 GTS SLI - 6GB RAM - Creative X-FI - Windows 7 64-bit.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Jan 2011 23:51
Open your copy of the pyramid demo which comes with Box2D, and add these two lines.

Just before the main loop:


Inside the main loop:


That's all you need to get started. I expect you just didn't make the force large enough to get an effect? (Remember, it will be divided by the distance squared, so it needs to be fairly large)

[b]
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 17th Jan 2011 11:26
Yep, that was the problem. Wow, this is really great! Well done.

Intel Core Duo2 Quad Q9550 2.8 GHz - Asus P5N-D - 2x Geforce 8800 GTS SLI - 6GB RAM - Creative X-FI - Windows 7 64-bit.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Jan 2011 11:35
I'm looking forward to using this, just need to find some time!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Jan 2011 17:34
Great, loving these new commands... I'll be using them in Ker-Bang for sure!

Thanks yet again Diggsey!!

Quick question: Is it possible to make a polygon shape with more than 8 x,y points? The help file seems to say 8 is the limit...

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Jan 2011 19:18
8 points per polygon is the maximum, due to it being a fixed size array internally for performance reasons.

It's easy to turn a polygon with more than 8 points into a valid one:
- Take the first 8 points and make a polygon shape
- Take the first, the previous and the next 6 points for the next shape
- Repeat until you've done all the points

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Jan 2011 21:19
Quote: "8 points per polygon is the maximum, due to it being a fixed size array internally for performance reasons.

It's easy to turn a polygon with more than 8 points into a valid one:
- Take the first 8 points and make a polygon shape
- Take the first, the previous and the next 6 points for the next shape
- Repeat until you've done all the points"

That's what I figured. Not the end of the world as I already figured a system like you just described for adding multiple fixtures.

Just thought I should check before getting complicated. I'm using edges for my complex static shapes as I figured that might be quicker (certainly easier to code!). I'll post my level editor once it's done and you can see what I've been up to, I'm quite pleased with how it's shaping up!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th Jan 2011 12:56
Hey diggsey, just wondering if you've any ideas for simulating water like you get in some sandbox games?

Heres one example:
http://www.patrickmatte.com/stuff/physicsLiquid/

...and another good one:
http://kakutogi.deviantart.com/art/BOX2D-water-169810645

I get the idea of using distance joints but getting a 'closed' shape seems tricky...

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Jan 2011 13:35
You could make a number of circle shapes like in those examples easily enough. To draw them you can do something like this:

- Make an image the size of the screen which you can draw to.
- Draw each water particle to the image each frame using additive blending.
- Each particle should be drawn as white in the middle and fading to black at the outside (It should reach black at some point outside the size of the actual circle used to simulate it)
- Draw a full-screen quad using this image as its texture, and use a shader to only draw value brighter than a certain threshold. You can also apply any colouring you want in this shader.

You should then get a smooth surface

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th Jan 2011 13:58
You make it sound so simple. I think this might be beyond my current knowledge of shaders though, I could probably manage the rest.

I was just thinking it must be possible and might make a great effect.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Jan 2011 17:38 Edited at: 20th Jan 2011 17:38
The idea behind that method is that although a pixel distance X from a particular water particle is not bright enough to pass the brightness threshold, if you have two particles near each other, the two brightnesses will add together and may then be enough to pass. That way you get the "blobbiness" of water.

It uses a similar technique here:
http://forum.thegamecreators.com/?m=forum_view&t=152033&b=1

However, that does all the calculations for all the particles in the shader, and so it only supports 8 different ones.

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th Jan 2011 17:51
That's exactly what I imagined. Any chance you could make an amended version of the shader for box2D? It would be an amazing update...

Please please pleeeeaaaassse?

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Feb 2011 10:22
Congrats on the new status Diggsey! You deserve it.

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 2nd Feb 2011 16:23
Quote: "Congrats on the new status Diggsey! You deserve it."

Beat me to it... Congratulations!

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Feb 2011 19:29
Thanks!

I'm just working on that shader demo

[b]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Feb 2011 23:18
It was touch and go...you had no avatar for the newsletter article, I nearly had to put a stop to the whole thing

It's a well deserved badge, wear it with pride.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Feb 2011 01:33
Quote: "you had no avatar for the newsletter article, I nearly had to put a stop to the whole thing"


Fixed that

[b]
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Feb 2011 09:49
Quote: "I'm just working on that shader demo"

I think I love you.

Actually I think it's something that a lot of people would use in combination with your plugin.

PS. Nice avatar.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Feb 2011 17:53
Quote: "PS. Nice avatar."


Thanks. I just knocked it up in inkscape, and surprised myself! It's amazing what a couple of white circles and a gradient can do to make something look shiny!

[b]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Feb 2011 01:55 Edited at: 4th Feb 2011 01:57
Here you go The physics aren't great as it's just using circles to simulate the water. You could get better results by simulating forces between them and things, but I'll leave that to you. It does look good however



Project files and shaders are attached.

[b]

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Feb 2011 10:15
Oh, you are a God. Is there a temple where I can worship you?

Thanks yet again Diggsey!!

Funnily enough this might revive a game idea I started a while ago...

BillR
21
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 4th Feb 2011 13:44 Edited at: 4th Feb 2011 13:46
@Diggsey - thanks for the water physics demo, but I get an error.
b2SetObjectUserData body, id - line 87 gives me a parsing error(could not understand command)
in fact, 'b2SetObjectUserData' is not highlighted in the editor like all the other Box2D commands are.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Feb 2011 16:03
You need the latest version of Box2D for those commands. You can download it from your My Products page.

[b]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Feb 2011 01:08 Edited at: 5th Feb 2011 01:09
OK, I couldn't resist

I've attached the code and shaders for a new fluid demo which actually behaves like fluid I had to use quite large particles to cover a large area of a screen. In an actual game it would be better to use smaller particles and in a much smaller region. Despite this is still runs at a steady 60FPS for me (which it is capped at) for over 200 particles.

Enjoy

[b]

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Feb 2011 09:51 Edited at: 7th Feb 2011 12:55
Nice, I'll try it out tonight!

EDIT: Great work there! Much more watery! This has great potential for use in some interesting games.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Mar 2011 13:10
Maybe I should keep my Box2D questions to this thread...

I have a strange problem:

1. Multiple Dynamic Bodies, made up of multiple fixtures.
2. A kinematic Body, made from 1 Polygon Edge, set as a sensor - Called the "Scanner"

The Scanner tries to find the highest point on a pile of bodies. It does this by

1. Use b2FindBodyContacts to check for contact with bodies in pile
2. Work through contacts - b2GetContact()
3. If relevant contact found, see if touching - b2GetContactIsTouching()
4. If touching, move the scanner up the pile
5. Repeat until it no longer touches



As you can see from the video, it thinks it's touching when it clearly isn't. This is not always the case, it sometimes works. The connection line you see can appear even when it successfully realises it is no longer touching.

Any help appreciated!



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Mar 2011 16:58
I have not found an alternative way around this yet. I was wondering if there was a way to disconnect the 2 bodies but alas no.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 14th Mar 2011 19:47 Edited at: 14th Mar 2011 19:48
I *THINK* it's because you are repositioning the body every loop. You know how physics engines always tell that directly positioning a body can make the simulation unstable, this is one of those times.

There is some code in box2d which handles updating contacts, and box2d skips that code when you reposition a body, because it depends on results from the previous iteration, which wouldn't make sense if you have repositioned it. It should probably clear the contacts as well when this happens, but either way it won't generate new ones until it's had at least a frame to simulate it normally.

It's easy to work around though. Since the body is kinematic you can just set its velocity to upward at the start, and you won't need to reposition it all the time like this, it will move up each frame automatically.

Alternatively you can do a raycast instead. Just use b2RayCastWorld to cast a horizontal line instead of the body. You will need to set the ray-cast callback to a valid function. If that function is called you know that the ray hit something. The help files explain what the parameters and return value should be.

Finally you could only reposition the body every second loop. It's kinematic so won't be affected by gravity or anything. By having the extra frames where you don't reposition it, it should have time to recalculate the contacts.

[b]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Mar 2011 23:58
That worked, many thanks

I'm now setting the velocity successfully

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Mar 2011 14:17 Edited at: 20th Mar 2011 14:49
Contact Listener and DBP Crash

I have another issue(!). I have set up the Contact Listener function, and it's working ok. I'm outputting a contact count to prove it's catching everything and it's ticking along nicely.



I immediately started getting Windows application crashes in my DBP game. After a lot of jiggery pokery I have found the problem. When you have a listener, setting bodies to inactive, or deleting them crashes the program.

Does anyone know what I am doing wrong?

<EDIT> I think the problem is that once inactive or deleted,there is already a queue or additional calls to the listener function, with additional contacts for the same body. As the body is now deleted or inactive, the subsequent calls crash the program.

I think I would need a function to tell me if a body was now deleted/inactive? I don't think there is a Box2D function to tell me when they are deleted? I think maintaining my own list would be very inefficient.

Ratty Rat
21
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 4th May 2011 13:09
Hi Diggsey, I hope this is the place to post bugs/problems, if not apologies in advance.

I have a problem with 'b2SetFixtureFilterData' and it`s associated Get functions, I am not sure if it is a mistake in the manual or the code.

The manual states that all 3 values to b2SetFixtureFilterData are 16 bit unsigned integers, but then goes on to describe how a negative value for GroupIndex can be used - so clearly something confused there.

Anyway - if I set the GroupIndex to, say, -1, then use b2GetFixtureFilterDataGroupIndex I get 4294967295 back (IE the unsigned value of -1, but in 32 bits!).

So, something seems out of whack here.

Not too urgent as it`s pretty easy to work around.

Thanks,
RR

"Don`t try to engage my enthusiasm, I don`t have one"
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th May 2011 20:52 Edited at: 4th May 2011 20:55
@BatVink
It seems you found a bug DBPro doesn't follow the usual conventions of preserving the EBX register when you call a function and I forgot to restore it myself for that callback. Most code doesn't mind this, but the particular code that deletes the contacts when a body is set to inactive or deleted does mind!

I've fixed the bug, and I'll send an update to TGC as soon as I can.

Also, you can detect whether a body exists using b2GetObjectType(). If the ID doesn't exist it will return b2ObjectType_None().

@Ratty Rat
Ah, I see what you mean. It should really be a 16 bit signed integer, but DBPro doesn't support those. I'll change it to just use a normal integer for the update.

[b]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th May 2011 20:41
I've released an update for Box2D which fixes the issues mentioned above. You can download the new version from your "My Products" page.

[b]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th May 2011 01:38
I found the only bug in EzRotate in 3 years Ironically my day job is to find out why software is misbehaving, and I often find its behaving worse than actually reported.

Glad to see you got it sorted, many thanks!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th May 2011 23:36
I just love this plugin!

Attached is a small game I'm working on using this plugin. It's the start of a 'need for speed' / 'GTA' style driving game. I had over 100 police cars chasing me at around 200->300 fps... only when I had 800 police chasing me did the fps drop below 30->40!

With some simple avoiding obstacles code the AI could remain really simple and work even better!

This game is going to be using Josh Mooney's images and models from the May newsletter for the most part.

Attachments

Login to view attachments
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th May 2011 01:13
Great start! It's already fun to play and it will look excellent with actual gameplay and nice graphics.

[b]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th May 2011 01:38
It annoyed me very quickly. The second those cops hit you, you can never get away and just get pushed around off the map! Car needs better acceleration.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th May 2011 10:48 Edited at: 12th May 2011 19:40
Quote: "Great start! It's already fun to play and it will look excellent with actual gameplay and nice graphics."

Thanks Diggsey! It's mostly your code for the car you are driving but I had a real job getting the cops to work nicely!

Quote: "It annoyed me very quickly. The second those cops hit you, you can never get away and just get pushed around off the map! Car needs better acceleration."

I'll be adding difficulty levels etc later to make it a bit easier but it is possible to keep them off your back, just not easy! I agree that it all needs some tweaking still though.

I just need to finalise how the gameplay will work and get the media together for the levels. I'm hoping this game will be a quick one to write since I got this much together in a couple of days.

I thought 800 cops was impressive (if impossible to play) but I was really testing how many vehicles I could control without slowing the game down. I'll be adding in NPC cars which will drive around too...

EDIT: Been adding some media etc. Have created a system for the city generator which makes maps 100x100 tiles which is also seemless so you could drive around the city all day and never reach the edge. FPS here is terrible but only because of the way I'm drawing the map. I'll be switching it to image kit to improve performance:


Attachments

Login to view attachments
SolusHunter
12
Years of Service
User Offline
Joined: 18th May 2011
Location: Kent, United Kingdom
Posted: 18th May 2011 11:39
I'm just have a play around with Box2D and loving what I see so far, but I have a newbie question if I may:

How would I get the screen to scroll keeping one of the physics objects in view at all times, for simplicity sakes centred on screen?

This would be for a 2D game, if that affects anything.

Thanks for any help.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th May 2011 11:48 Edited at: 18th May 2011 11:49
Quote: "I'm just have a play around with Box2D and loving what I see so far, but I have a newbie question if I may:

How would I get the screen to scroll keeping one of the physics objects in view at all times, for simplicity sakes centred on screen?

This would be for a 2D game, if that affects anything.

Thanks for any help."

I see I'm answering before your post has passed a moderator but here's the answer:
If you mean the background you can simply paste your background in as a sprite before you draw the box2d world in. That way your background will be shown behind the box2d stuff.

You can centre the screen on one object using this command:

(car is my box2d bodyID)

SolusHunter
12
Years of Service
User Offline
Joined: 18th May 2011
Location: Kent, United Kingdom
Posted: 18th May 2011 11:51
That was fast, thanks.

I was referring to the entire screen, rather than just the background. So that some physics objects would be off screen until the game scrolled them into view.

I presume the code snippet you posted would do this.

Thanks.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th May 2011 12:02
Quote: "I was referring to the entire screen, rather than just the background. So that some physics objects would be off screen until the game scrolled them into view.

I presume the code snippet you posted would do this."

You can use "b2SetScreenTransform" to position the "camera" far off to from the 'action' but a better method would be to set a variable that decides whether to draw the scene or not IE:


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th May 2011 06:30
Quote: "How would I get the screen to scroll keeping one of the physics objects in view at all times, for simplicity sakes centred on screen?"


I just had to do the same thing the other day. Since I was already using ImageKit my entire scene is drawn to an image first then that image is pasted to the screen. I just offset the image to do the map scrolling.

Login to post a reply

Server time is: 2024-04-25 15:14:40
Your offset time is: 2024-04-25 15:14:40