Exemplo n.º 1
0
	void SetTransform(const btTransform& aT, VectorMap<void*, int>& set){
		if (set.Find(mSelf) != set.end())
			return;
		mSelf->setWorldTransform(aT);
		mSelf->clearForces();
		set[mSelf] = 1;
		if (mGameFlag != 0)
			Logger::Log(FB_DEFAULT_LOG_ARG, FormatString("(info) Setting rigid body transform for %d", mGameFlag).c_str());
		auto numConstraints = mSelf->getNumConstraintRefs();
		for (int i = 0; i < numConstraints; ++i){
			auto con = mSelf->getConstraintRef(i);
			auto conType = con->getConstraintType();
			if (conType == FIXED_CONSTRAINT_TYPE || conType == D6_SPRING_2_CONSTRAINT_TYPE){
				btFixedConstraint* fixedCon = (btFixedConstraint*)con;
				auto a = &con->getRigidBodyA();
				auto b = &con->getRigidBodyB();
				auto trA = fixedCon->getFrameOffsetA();
				auto trB = fixedCon->getFrameOffsetB();
				if (b->getUserPointer() == mSelf){
					std::swap(a, b);
					std::swap(trA, trB);
				}
				auto bT = aT * trA * trB.inverse();
				auto rigidBodyImpl = (RigidBodyImpl*)b->getUserPointer();
				rigidBodyImpl->mImpl->SetTransform(bT, set);				
			}
		}
		mSelf->activate();
	}
	ShaderPtr GetShader(int ResourceTypes_Shaders){
		auto it = mShaders.Find(ResourceTypes_Shaders);
		if (it == mShaders.end()){
			auto shader = CreateShader(ResourceTypes_Shaders);
			if (!shader){
				Logger::Log(FB_ERROR_LOG_ARG, FormatString("Resource Provider - Failed to create the shader (%d)", ResourceTypes_Shaders).c_str());
				return 0;
			}
			mShaders[ResourceTypes_Shaders] = shader;
			return shader;
		}
		return it->second;
	}
Exemplo n.º 3
0
float EventInterpreter::getMean(const VectorMap& items){
    
        float sum = 0;
  
        for(VectorMap::const_iterator i=items.begin();i != items.end(); ++i){
    
            sum += *i;
    
        }
        
        return (sum/items.size());
    
    }
	SamplerStatePtr GetSamplerState(int ResourceTypes_SamplerStates){
		auto it = mSamplerStates.Find(ResourceTypes_SamplerStates);
		if (it == mSamplerStates.end()){
			auto state = CreateSamplerState(ResourceTypes_SamplerStates);
			if (!state){
				Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a depth stencil state(%d)", ResourceTypes_SamplerStates);
				return 0;
			}
			mSamplerStates[ResourceTypes_SamplerStates] = state;
			return state;
		}

		return it->second;
	}
	BlendStatePtr GetBlendState(int ResourceTypes_BlendStates){
		auto it = mBlendStates.Find(ResourceTypes_BlendStates);
		if (it == mBlendStates.end()){
			auto state = CreateBlendState(ResourceTypes_BlendStates);
			if (!state){
				Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a rasterizer state(%d)", ResourceTypes_BlendStates);
				return 0;
			}
			mBlendStates[ResourceTypes_BlendStates] = state;
			return state;
		}

		return it->second;
	}
	MaterialPtr GetMaterial(int ResourceTypes_Materials){
		auto it = mMaterials.Find(ResourceTypes_Materials);
		if (it == mMaterials.end()){
			auto material = CreateMaterial(ResourceTypes_Materials);
			if (!material){
				Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a material(%d)", ResourceTypes_Materials);
				return 0;
			}
			mMaterials[ResourceTypes_Materials] = material;
			return material;
		}

		return it->second;
	}
Exemplo n.º 7
0
float EventInterpreter::getSTDDev(const VectorMap& items, float mean){
        
        float stddev = 0;
        
          for(VectorMap::const_iterator i=items.begin(); i != items.end(); ++i){
            
            stddev += pow((*i-mean),2);
    
          }
        
        
        return sqrt(stddev/items.size());
    
    }
	TexturePtr GetTexture(int ResourceTypes_Textures, int index){
		auto it = mTextures.Find(ResourceTypes_Textures);
		if (it == mTextures.end() || index >= (int)it->second.size()){
			auto textures = CreateTexture(ResourceTypes_Textures);
			mTextures[ResourceTypes_Textures] = textures;
			if (index < (int)textures.size()){
				return textures[index];
			}
		}
		else{
			if (index < (int)it->second.size())
				return it->second[index];
		}
		return 0;
	}
Exemplo n.º 9
0
	/// returns true, when playable
	/// should be called after the position for this audioex has set.
	/// Audio Thread + Main Thread
	bool CheckSimultaneous(){
		if (mFilePathKey.empty())
			return true;

		if (mProperty.mNumSimultaneous == 0)
			return true;
		
		VectorMap< std::string, std::vector<AudioExWeakPtr>>::iterator audioListIt;
		{
			READ_LOCK l(sAudioExListLock);
			audioListIt = sAudioExList.Find(mFilePathKey);
			if (audioListIt == sAudioExList.end())
				return true;
		}

		std::vector<AudioExPtr> audioExesInRange;
		audioExesInRange.reserve(10);
		auto& audioList = audioListIt->second;
		float rangeSQ = mProperty.mSimultaneousCheckRange * mProperty.mSimultaneousCheckRange;
		// gather audioList in range
		for (auto it = audioList.begin(); it != audioList.end(); /**/){
			IteratingWeakContainer(audioList, it, audio);
			if (!audio->IsPlaying())
				continue;
			if (mProperty.mSimultaneousCheckRange == 0.f){
				audioExesInRange.push_back(audio);
			}
			else{
				// check distance
				const auto& position = audio->GetPosition();
				auto distSq = GetDistanceSQBetween(position, mProperty.mPosition);
				if (distSq <= rangeSQ){
					audioExesInRange.push_back(audio);
				}
			}
		}
		if (audioExesInRange.size() < mProperty.mNumSimultaneous)
			return true;

		return false;
	}
Exemplo n.º 10
0
	//----------------------------------------------------------------------------
	Ray3 ScreenPosToRay(long x, long y)
	{
		Update();
		auto it = mRayCache.Find(Vec2I(x, y));
		if (it != mRayCache.end()){
			return it->second;
		}

		Real fx = 2.0f * x / GetWidth() - 1.0f;
		Real fy = 1.0f - 2.0f * y / GetHeight();
		Vec3 screenPos((Real)fx, (Real)fy, -1.0f);
		Vec3 screenMidPos((Real)fx, (Real)fy, 0.0f);
		Vec3 origin = mMatrices[InverseViewProj]* screenPos;
		Vec3 target = mMatrices[InverseViewProj] * screenMidPos;
		Vec3 dir = target - origin;
		dir.Normalize();

		Ray3 ray(mTransformation.GetTranslation(), dir);
		mRayCache[Vec2I(x, y)] = ray;
		return ray;
	}
Exemplo n.º 11
0
	void PreRender(const RenderParam& renderParam, RenderParamOut* renderParamOut){
		mRenderPass = (RENDER_PASS)renderParam.mRenderPass;
		if (!mSkipSpatialObjects)
		{
			auto cam = renderParam.mCamera;
			assert(cam);

			auto it = mLastPreRenderFramePerCam.Find(cam);
			if (it != mLastPreRenderFramePerCam.end() && it->second == gpTimer->GetFrame())
				return;
			mLastPreRenderFramePerCam[cam] = gpTimer->GetFrame();

			MakeVisibleSet(renderParam, renderParamOut);

			auto objIt = mPreRenderList[cam].begin(), objItEnd = mPreRenderList[cam].end();
			for (; objIt != objItEnd; objIt++)
			{
				// Only objects that have a valid renderable is in the render lists.
				(*objIt)->PreRender(renderParam, renderParamOut);				
			}
		}

		if (mSkyRendering)
		{
			if (mSkySphere)
			{
				mSkySphere->PreRender(renderParam, renderParamOut);
			}
		}

		for (auto it = mObjects.begin(); it != mObjects.end(); /**/){
			auto obj = it->lock();
			if (!obj){
				it = mObjects.erase(it);
				continue;
			}
			++it;
			obj->PreRender(renderParam, renderParamOut);			
		}
	}
Exemplo n.º 12
0
	void DeleteShader(int ResourceTypes_Shaders){
		auto it = mShaders.Find(ResourceTypes_Shaders);
		if (it != mShaders.end())
			mShaders.erase(it);
	}
Exemplo n.º 13
0
	void DeleteTexture(int ResourceTypes_Textures){
		auto it = mTextures.Find(ResourceTypes_Textures);
		if (it != mTextures.end())
			mTextures.erase(it);
	}