About Store Forum Documentation Contact



Post Reply 
3D Sound in World Editor
Author Message
Barthap Offline
Member

Post: #1
3D Sound in World Editor
Many people asked Esenthel for adding 3D Sound to World Editor. Because it's easy, I managed to do it. Here is source code of Sound3D class:

Code:
//sound3d.h
struct Sound3D : Game::Obj
{

   Vec     position; // the class will contain only position
   Sound sound;

   Str path;
   Flt range;
   Flt volume;

   // provide necessary methods required by Game::Obj :
      virtual void create(Game::ObjParams &obj); // extend default creation

      virtual Vec        pos(          )            {return position    ;} // get position
      virtual void        pos(C Vec &pos)            {     T.position=pos;} // set position
      virtual Matrix    matrix(                ){return position           ;} // get matrix
      virtual void        matrix(C Matrix &matrix){     T.position=matrix.pos;} // set matrix

      virtual Bool update     ();// object update
      virtual UInt drawPrepare();               // object draw prepare

   // constructor
   Sound3D();
};

And .cpp file
Code:
#include "stdafx.h"
#include "Main.h"
/******************************************************************************/

Sound3D::Sound3D() // initialize values in constructor
{
    position.zero();
    path = NULL;
    range = 1;
    volume = 0.5;
}
void Sound3D::create(Game::ObjParams &obj)
{
    // now setup custom parameters from 'obj'
    position=obj.matrixFinal().pos; // obtain our 'position' member from 'obj'
    
    if(Param *p = obj.findParam("path"))path = p->asText();
    if(Param *p = obj.findParam("range"))range = p->asFlt();
    if(Param *p = obj.findParam("volume"))volume = p->asFlt();

    sound.play(path,position,range,true,volume);
}

UInt Sound3D::drawPrepare()
{
    return 0; // return 0 because no additional rendering modes are required
}

Bool Sound3D::update()
{
    sound.pos(position);
    return true;
}

In main.h
Code:
#include "Sound3d.h"
In ObjType enum add OBJ_3D_SOUND

Example of use:
in Game.cpp
Code:
Game::ObjMemx<Sound3D> Sounds3D;

//in Init() in world creation code
Game::World
//...
.setObjType(Sounds3D, OBJ_3D_SOUND)

In world editor add object with parametrs:
  • Type: OBJ_3D_SOUND
  • Access: Constant! (screenshots are bad, there should be Constant Access, not Default)
  • Custom Params (type, name, default value):
    • Real, range, 1
    • Real, volume, 1
    • String, path, (your path to sound file)
I created 3d sound base object and I add to world its derived objects. Here is screenshot:
[Image: sndobj.png]

And 3d sound is ready!
(This post was last modified: 02-01-2012 11:26 AM by Barthap.)
01-04-2011 05:33 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: 3D Sound in World Editor
That's great tutorial/snippet! Thanks

Edit: But either add missing save/load methods, or change the Access Mode to CONST (in the base Object)
01-04-2011 05:52 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #3
RE: 3D Sound in World Editor
Oh, I forgot changing it to Constant mode. Thanks!
01-04-2011 05:56 PM
Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #4
RE: 3D Sound in World Editor
I've added Polish version of this snippet to my blog http://hapex.com.pl/.
And added it to Esenthel Wiki: http://www.esenthel.com/wiki/index.php?t...rld_Editor
(This post was last modified: 01-22-2011 10:43 AM by Barthap.)
01-22-2011 10:18 AM
Find all posts by this user Quote this message in a reply
Dante190884 Offline
Member

Post: #5
RE: 3D Sound in World Editor
@Barthap: very helpful tutorial, thx and make more.

but how i can make the new base.obj file in Editor?
(This post was last modified: 07-03-2011 02:41 AM by Dante190884.)
07-03-2011 12:18 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Jben Offline
Member

Post: #6
RE: 3D Sound in World Editor
Very Thx ! smile
07-03-2011 04:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #7
RE: 3D Sound in World Editor
in Object mode in Editor you should click File->New and there specify parametrs (wrote them in first post) then click F2 and save it as for example baseSound.obj. Then again click File->New and as Base select baseSound.obj and just tick the String path parametr and specify your path to sound file smile I can make video.
07-03-2011 07:49 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #8
RE: 3D Sound in World Editor
Your tutorial on Esenthel Wiki was probably removed.
07-03-2011 11:06 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #9
RE: 3D Sound in World Editor
I dont remember removing it. Maybe it got lost when I was switching hosting
07-03-2011 11:40 AM
Find all posts by this user Quote this message in a reply
Dante190884 Offline
Member

Post: #10
RE: 3D Sound in World Editor
(07-03-2011 07:49 AM)Barthap Wrote:  in Object mode in Editor you should click File->New and there specify parametrs (wrote them in first post) then click F2 and save it as for example baseSound.obj. Then again click File->New and as Base select baseSound.obj and just tick the String path parametr and specify your path to sound file smile I can make video.

Sorry, but in new version create new object is unavailable. Check this:

[Image: 95727092.th.jpg]

Uploaded with ImageShack.us

Can you make a quick video in this operation in newst engine edition? Can you do this?

----------------------------------
EDIT: im find little bug in your code:

Code:
Bool Sound3D::update()
{
    sound.pos(position);
    return true;
}

Must add in code this:
Code:
Listener.orn(Cam.matrix.z,Cam.matrix.y)  // set listener orientation (from camera)
              .pos(Cam.matrix.pos           ); // set listener position    (from camera)
(This post was last modified: 07-03-2011 02:36 PM by Dante190884.)
07-03-2011 01:47 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #11
RE: 3D Sound in World Editor
In Tymczasowy Obiekt (Temp Object) windows you should have Plik/Nowy (File/New).
(This post was last modified: 07-03-2011 03:34 PM by Harry.)
07-03-2011 03:33 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Barthap Offline
Member

Post: #12
RE: 3D Sound in World Editor
Dante sorry but you dont know how to use world editor?
You should just set object parametrs same as I specified. You dont have to have base obj but you have to set that params smile
07-03-2011 08:29 PM
Find all posts by this user Quote this message in a reply
Truelegend Offline
Member

Post: #13
RE: 3D Sound in World Editor
I will add it for my game soon smile thanks smile
07-04-2011 07:23 PM
Find all posts by this user Quote this message in a reply
pcarl Offline
Member

Post: #14
RE: 3D Sound in World Editor
So I'm trying to follow this example, but when I get to addObjType part of it, the function call does not exist. We are using the company license, is this limited in this release or has the interface change for this?

Thanks,

Carl
12-18-2011 01:19 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #15
RE: 3D Sound in World Editor
It is setObjType
12-18-2011 10:21 AM
Find all posts by this user Quote this message in a reply
Post Reply