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
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