3D Physics with ZgeBullet

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Re: 3D Physics with ZgeBullet

Postby Rado1 » Mon Apr 17, 2017 11:50 am

Hi Smags.

I like your effect; cool idea. Even if I did not study it in details at first look there's a bug, you should set the current world before creating any shape, so the init script should look like this:

Code: Select all

World = zbtCreateWorld();
zbtSetCurrentWorld(World);
zbtSetWorldGravity(0,-9.8*4, 0);
sphere = zbtCreateSphereShape(1.5);
...

You can also remove (or comment)

Code: Select all

// zbtSetCurrentWorld(World);
in OnUpdate expression. It is useless since you are using just one world.

Another quite big problem leading to bad performance is that you remove all Keys models and spawn them again on each render pass. You should just spawn them on initialization time (in OnLoaded section) and do not touch them during lifetime. Just removing the RemoveAllModels component from OnBeginRenderPass and moving the

Code: Select all

for (int i=0; i<spc1.SizeDim1; i++){
  keys.Position.x=spc1[i].x;
  ...

expression to the OnLoaded section makes the job. But please check correctness of these changes, because I do not understand your code in details...

Rado1.

Smags
Posts: 2
Joined: Fri Apr 14, 2017 7:22 pm

Re: 3D Physics with ZgeBullet

Postby Smags » Mon Apr 17, 2017 9:38 pm

Thanks Rado -

It was the init code. I was convinced that the init code was fine because it did work occasionally. I never would have guessed that was the problem.

My Code:

Code: Select all

World = zbtCreateWorld();
sphere = zbtCreateSphereShape(1.5);[/quote]
zbtSetCurrentWorld(World);
zbtSetWorldGravity(0,-9.8*4, 0);


Fix:

Code: Select all

World = zbtCreateWorld();
zbtSetCurrentWorld(World);
zbtSetWorldGravity(0,-9.8*4, 0);
sphere = zbtCreateSphereShape(1.5)


I also removed World zbtCreateWorld() from update and moved the keys to onLoaded.

User avatar
Rado1
Posts: 770
Joined: Wed May 05, 2010 12:16 pm

Re: 3D Physics with ZgeBullet

Postby Rado1 » Tue Apr 18, 2017 6:37 am

Smags wrote:I also removed World zbtCreateWorld() from update and moved the keys to onLoaded.

You probably meant zbtSetCurrentWorld(World). I hope your code works fine now.


Return to “Extensions”

Who is online

Users browsing this forum: No registered users and 1 guest