sound source

mobensli72

10-05-2008 16:40:18

Hello

first I want you to excuse me for my bad English (i'm french)

this is my problem

I have in my 3D scene a Boeing 747 (mesh), I want to attach a sound to this plane, the problem is the source sound start from the camera and not from the Boeing

this is my code source

#ifndef _OGRE_APP_H_
#define _OGRE_APP_H_

#include <OgreCamera.h>
#include <OgreConfigFile.h>
#include <OgreEntity.h>
#include <OgreException.h>
#include <OgreLight.h>
#include <OgreLogManager.h>
#include <OgreMeshManager.h>
#include <OgreOverlayContainer.h>
#include <OgreRoot.h>
#include <OgreTextAreaOverlayElement.h>
#include <OgreFontManager.h>


#include "OgreAL.h"
#include "ExampleApplication.h"

using namespace Ogre;

#include <deque>
using namespace std;

class MoveAvionListener : public ExampleFrameListener
{
public:

MoveAvionListener(RenderWindow* win, Camera* cam, SceneNode *sn,
Entity *ent, deque<Vector3> &walk)
: ExampleFrameListener(win, cam, false, false), mNode(sn), mEntity(ent), mWalkList( walk )
{
pos=0;
mWalkSpeed = 90.0f;
mDirection = Vector3::ZERO;
} // MoveDemoListener

/* This function is called to start the object moving to the next position
in mWalkList.
*/
bool nextLocation( )
{
if ( mWalkList.empty() ){
return false;
}

mDestination = mWalkList.front( ); // this gets the front of the deque
mWalkList.pop_front( ); // this removes the front of the deque
pos++;
mDirection = mDestination - mNode->getPosition( );
mDistance = mDirection.normalise( );

return true;
} // nextLocation( )

bool frameStarted(const FrameEvent &evt)
{
if ( mDirection == Vector3::ZERO ) {
if ( nextLocation() ) {
// Set walking animation
// mAnimationState = mEntity->getAnimationState( "swim" );
// mAnimationState->setLoop( true );
// mAnimationState->setEnabled( true );
}
}

else
{
Real move = mWalkSpeed * evt.timeSinceLastFrame;
mDistance -= move;
// mAnimationState->addTime( evt.timeSinceLastFrame );
if (mDistance <= 0.0f)
{
mNode->setPosition( mDestination );
/* Quaternion q(Degree(90), Vector3::UNIT_Z);

mNode->rotate(q);*/
mDirection = Vector3::ZERO;
//mNode->setVisible(false);
// Set animation based on if the robot has another point to walk to.
}
else
{


mNode->translate( mDirection * move );


}
}



return ExampleFrameListener::frameStarted(evt);
}
protected:
Real mDistance; // The distance the object has left to travel
Vector3 mDirection; // The direction the object is moving
Vector3 mDestination; // The destination the object is moving towards

AnimationState *mAnimationState; // The current animation state of the object

Entity *mEntity; // The Entity we are animating
SceneNode *mNode; // The SceneNode that the Entity is attached to
std::deque<Vector3> mWalkList; // The list of points we are walking to

Real mWalkSpeed; // The speed at which the object is moving

};


class OgreApp: public ExampleApplication
{
public:

OgreApp(){
//mWindow, mCamera, mNode, mEntity, mWalkList

// root->addFrameListener(listener);
}

~OgreApp(){}


protected:
Entity *mEntity; // The entity of the object we are animating
SceneNode *mNode; // The SceneNode of the object we are moving
std::deque<Vector3> mWalkList; // A deque containing the waypoints
// DeviceListener *listener; // Listener

void chooseSceneManager(void){
mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

virtual void createCamera(void)
{

mCamera = mSceneMgr->createCamera("PlayerCam");


//régler sa position, direction
mCamera->setPosition(Vector3(700, 200, 2000 ));
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(1.0);

}




void createScene(void)
{


mSceneMgr->setAmbientLight(ColourValue(1,1,1));
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE) ;
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 2);
mSceneMgr->setWorldGeometry( "terrain.cfg" );


mEntity = mSceneMgr->createEntity( "Boeing747", "747.mesh" );

// Create the scene node
mNode = mSceneMgr->getRootSceneNode( )->
createChildSceneNode( "747", Vector3( 1250, 1500, 4000 ) );
mNode->attachObject( mEntity );
// Create the walking list
mWalkList.push_back( Vector3( 1250, 2000, -4000 ) );


mWalkList.push_back( Vector3( 1250, 0, 1000 ) );
mWalkList.push_back( Vector3( 1250, 0, 0 ) );
mWalkList.push_back( Vector3( 1250, 2000, -2000 ) );
mWalkList.push_back( Vector3( 0, 2000, -4000 ) );



soundManager = new OgreAL::SoundManager();
OgreAL::Sound *sound = soundManager->createSound("747", "747.wav", true,true);
mNode->attachObject(sound);
sound->play();



}

void createFrameListener(void)
{
mFrameListener= new MoveAvionListener(mWindow, mCamera, mNode, mEntity, mWalkList);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
};
#endif


Gohla

11-05-2008 08:53:41

You have to attach an OgreAL::Listener to the same node your camera is attached to, something like this:
mCameraNode->attachObject(mCamera);
mCameraNode->attachObject(mSoundManager->getListener());

mobensli72

13-05-2008 08:20:21

I try many things without success

like this
SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
camNode->attachObject(mCamera);
camNode->attachObject(soundManager->getListener());



i try also this


SceneNode *node;
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode");
node->setPosition(0, 100, 100);
node = node->createChildSceneNode("PitchNode");
node->attachObject(mCamera);
node->attachObject(mSoundManager->getListener());
node->pitch(Ogre::Degree(-30));


help me please

stickymango

13-05-2008 12:24:08

I hope your sound is mono....... :?:

mobensli72

13-05-2008 12:36:18

Yes for the test i use roar.wav so i think is a mono sound

stickymango

13-05-2008 14:10:08

Well then there is very little else to cause the problem, either your sound/listener ARE close together or your sounds properties are incorrectly set.