int lua_AudioSource_release(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { AudioSource* instance = getInstance(state); instance->release(); return 0; } else { lua_pushstring(state, "lua_AudioSource_release - Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1)."); lua_error(state); break; } } return 0; }
void Audio3DTest::addSound(const std::string& file) { std::string path("res/common/"); path.append(file); Node* node = NULL; std::map<std::string, Node*>::iterator it = _audioNodes.find(path); if (it != _audioNodes.end()) { node = it->second->clone(); } else { AudioSource* audioSource = AudioSource::create(path.c_str()); assert(audioSource); audioSource->setLooped(true); node = _cubeNode->clone(); node->setId(file.c_str()); node->setAudioSource(audioSource); audioSource->release(); _audioNodes[path] = node; node->addRef(); } assert(node); Node* cameraNode = _scene->getActiveCamera()->getNode(); // Position the sound infront of the user node->setTranslation(cameraNode->getTranslationWorld()); Vector3 dir = cameraNode->getForwardVectorWorld().normalize(); dir.scale(2); node->translate(dir); _scene->addNode(node); node->getAudioSource()->play(); node->release(); }