Physic Body Impact Callback

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Henry00
User
User
Posts: 88
Joined: Thu Jul 12, 2012 7:00 pm
Location: Germany
Contact:

Physic Body Impact Callback

Post by Henry00 »

Hi everyone, wouldn't it be nice to have a callback whenever a physical entity collides with an other entity, not only could you handle that event it would be possible to play a sound effect, even have additional information such as the force of the impact to change the volume of the sound, you name it. I could make use of this, otherwise I will have to add a custom physics engine (I already had to add libsndfile + OpenAL because the Sound3D library was incomplete), what is PureBasic using for the physics anyway?
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Physic Body Impact Callback

Post by Fred »

There is already ExamineWorldCollisions() with contact/impulse/normal info, isn't this enough ? We use bullet for the physics engine. BTW, what was missing in the openal implementation ?
Henry00
User
User
Posts: 88
Joined: Thu Jul 12, 2012 7:00 pm
Location: Germany
Contact:

Re: Physic Body Impact Callback

Post by Henry00 »

Sorry I didn't realize that procedure existed because I am using 5.11, I have been using PureBasic for years now and am saving money as we speak to buy it as I wish to go commercial with my project, I'm sorry Fred! But the fact full versions are out there was my (I believe) main motivation to even use this language (and Fasm). But now I love it and hope to support the community as an apology for not buying it sooner, anyway:

Please take a look here, this is the current documentation (or close enough?)
http://www.purebasic.com/documentation/ ... index.html

Now all basic elements are there, but as mentioned in this article http://www.purebasic.fr/english/viewtop ... =3&t=51369 a crucial procedure is missing: SoundListenerDirection or Orientation, as currently it would only work if the user never rotates the camera, PureBasic doesn't inform OpenAL what the listener orientation is, even the example doesn't work correctly.

I currently (pseudo) use this as orientation:

Code: Select all

; location
Sound_SetListenerLocation(CameraX(), CameraY(), CameraZ())
; rotation
Sound_SetListenerDirection(-Sin(Radian(180 - CameraYaw())),
                           0.0,
                           Cos(Radian(180 - CameraYaw())),
                           0.0,
                           1.0,
                           0.0)
; fixme: although this works, there should be a way to add pitch for more realism.
Those Sound_ procedures are literally:

Code: Select all

Procedure Sound_SetListenerLocation(X.f, Y.f, Z.f)
  alListener3f(#AL_POSITION, X, Y, Z)
EndProcedure

Procedure Sound_SetListenerDirection(X1.f, Y1.f, Z1.f, X2.f, Y2.f, Z2.f)
  Protected Dim Values.f(5)
  Values(0) = X1
  Values(1) = Y1
  Values(2) = Z1
  Values(3) = X2
  Values(4) = Y2
  Values(5) = Z2
  alListenerfv(#AL_ORIENTATION, @Values())
  FreeArray(Values())
EndProcedure
It's a procedure "UpdateListener" for my camera object, so I can use any camera I want as orientation for the sound.
Sound3D is also missing the whole reason why one would want to use OpenAL such as EFX, pitch, velocity, doppler effects...

I also recommend libsndfile, a great library to load many sound formats that is compatible with cdecl and cares about license issues (not supporting mp3 because of it). SFML uses this as well.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Physic Body Impact Callback

Post by PMV »

Fred wrote:BTW, what was missing in the openal implementation ?
I have just played a little bit around with it and just got problems.
http://www.ogre3d.org/tikiwiki/tiki-index.php?page=OgreAL wrote:There is a limited number of sources allowed in audio hardware. This limit varies from card to card and currently OgreAL is restricted to that number of Sounds. In order to find this limit on the current hardware you can call SoundManager::maxSources(). There is a plan to work around this in the near future to allow for infinite Sounds.
This limitation results in randomly not playing sounds.
My current implementation also starts playing the false
sounds ... and even so it could be a bug from me, i
have more the feeling that this is a problem of the lib itself.

Additional it seems, that OgreAL isn't updated since years.
Better changing the soundlib to OgreOggSound, as this
is using OpenAL, too ... but with a long feature list. :)
http://www.ogre3d.org/tikiwiki/tiki-ind ... reOggSound
Some nice features for next PB versions :mrgreen:

MFG PMV
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Physic Body Impact Callback

Post by Fred »

If it uses OpenAL, how will this solve the problem ?
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Physic Body Impact Callback

Post by PMV »

OpenAL is not the problem, as the number of sounds
that can be played at the same time is a hardware-limitation
as i read. I haven't complained about the sound3d-lib yet
because i doesn't know enough about OgreAL and alternatives.
I just know i need to investigate it later. :?
But a function GetSound3DSourceLimit() would be nice to have.
And the SoundlistenerDirection-Function of course :D

I mentioned OgreOggSound as the featurelist seems to have
everything that OgreAL has, but more and it is still updated
Btw. features that Henry00 has already mentioned. :)

MFG PMV
Henry00
User
User
Posts: 88
Joined: Thu Jul 12, 2012 7:00 pm
Location: Germany
Contact:

Re: Physic Body Impact Callback

Post by Henry00 »

PMV wrote:OpenAL is not the problem, as the number of sounds
that can be played at the same time is a hardware-limitation
as i read.
Confirmed with the real OpenAL Soft it does have a limitation where sound sources just cannot be created with alGenSources anymore until some are disposed of again, there is no error message and because of that limitation one should limit the amount of sources and recycle them (around 32), I guess that's a good idea. You could mark a source as available if it cannot be heard anymore due to the distance or other factors, perhaps if it's a sound that isn't looping, after all those are probably less important effects than looping ones (e.g. music).
It doesn't seem like the Sound3D library can actually allow the programmer to take care of this as you would have to keep FreeSound3D and load it again which is terribly slow. The main reason why OpenAL has buffers and sources (e.g. data and action).
Not to mention it's a matter of simply attaching a node to have OpenAL work seamlessly with every single Ogre related in-game transformation, I would really recommend spending one or two days implementing a custom PureBasic sound system, it took me only 2 days to support nearly every popular audio format out there, it shouldn't be impossible for your Team @Fred.

Don't wish to spoil the Sound3D library with my implementation so I will keep it to myself for the moment...
Henry00
User
User
Posts: 88
Joined: Thu Jul 12, 2012 7:00 pm
Location: Germany
Contact:

Re: Physic Body Impact Callback

Post by Henry00 »

William888 wrote:There is currently ExamineWorldCollisions() along with contact/impulse/normal information, is just not this specific sufficient? We all work with bullet for your physics engine. BY THE WAY, what was absent inside openal rendering?
What is the point of reviving this thread from 2013, sounds like a troll to me especially if you copy paste Fred's message. Although it's true that even PureBasic 5.31 still doesn't have a proper 3D sound implementation of OpenAL. At least I finally bought PureBasic =]
Edit: I was working on a neat OpenAL module, perhaps I can make my headers public soon in case anyone runs into these limits.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Physic Body Impact Callback

Post by Danilo »

@Henry00: It's a Bot. They copy messages all time, so they look more human.
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

Re: Physic Body Impact Callback

Post by Rings »

plz do not reply to spam, thx ;)
SPAMINATOR NR.1
Post Reply