Barthap
Member
|
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:
And 3d sound is ready!
(This post was last modified: 02-01-2012 11:26 AM by Barthap.)
|
|
01-04-2011 05:33 PM |
|
Esenthel
Administrator
|
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 |
|
Barthap
Member
|
RE: 3D Sound in World Editor
Oh, I forgot changing it to Constant mode. Thanks!
|
|
01-04-2011 05:56 PM |
|
Barthap
Member
|
RE: 3D Sound in World Editor
(This post was last modified: 01-22-2011 10:43 AM by Barthap.)
|
|
01-22-2011 10:18 AM |
|
Dante190884
Member
|
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 |
|
Barthap
Member
|
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 I can make video.
|
|
07-03-2011 07:49 AM |
|
Harry
Member
|
RE: 3D Sound in World Editor
Your tutorial on Esenthel Wiki was probably removed.
|
|
07-03-2011 11:06 AM |
|
Esenthel
Administrator
|
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 |
|
Dante190884
Member
|
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 I can make video.
Sorry, but in new version create new object is unavailable. Check this:
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 |
|
Harry
Member
|
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 |
|
Barthap
Member
|
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
|
|
07-03-2011 08:29 PM |
|
pcarl
Member
|
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 |
|
Esenthel
Administrator
|
RE: 3D Sound in World Editor
It is setObjType
|
|
12-18-2011 10:21 AM |
|