示例#1
0
static inline unsigned char sin_adv()
{
	static unsigned char sinoff=SO(sin)-1;
	++sinoff;
	sinoff %= SO(sin);
	return sin[sinoff];
}
	void CCharacterController::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive() || mInternal == nullptr)
			return;

		mInternal->setPosition(SO()->getWorldPosition());
	}
示例#3
0
	void CFixedJoint::getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation)
	{
		position = mPositions[(int)body];
		rotation = mRotations[(int)body];

		HRigidbody rigidbody = mBodies[(int)body];
		if (rigidbody == nullptr) // Get world space transform if no relative to any body
		{
			Quaternion worldRot = SO()->getWorldRotation();

			rotation = worldRot*rotation;
			position = worldRot.rotate(position) + SO()->getWorldPosition();
		}
		else
		{
			// Find world space transform
			Quaternion worldRot = rigidbody->SO()->getWorldRotation();

			rotation = worldRot * rotation;
			position = worldRot.rotate(position) + rigidbody->SO()->getWorldPosition();

			// Get transform of the joint local to the object
			Quaternion invRotation = rotation.inverse();

			position = invRotation.rotate(SO()->getWorldPosition() - position);
			rotation = invRotation * SO()->getWorldRotation();
		}
	}
示例#4
0
	void CAnimation::update()
	{
		const bool isRunning = SceneManager::instance().isRunning();
		if(!isRunning && !mPreviewMode)
		{
			// Make sure attached CBone components match the position of the skeleton bones even when the component is not
			// otherwise running.

			HRenderable animatedRenderable = SO()->getComponent<CRenderable>();
			if(animatedRenderable)
			{
				HMesh mesh = animatedRenderable->getMesh();
				if(mesh.isLoaded())
				{
					const SPtr<Skeleton>& skeleton = mesh->getSkeleton();
					if(skeleton)
					{
						for (auto& entry : mMappingInfos)
						{
							if(!entry.isMappedToBone)
								continue;

							const UINT32 numBones = skeleton->getNumBones();
							for (UINT32 j = 0; j < numBones; j++)
							{
								if (skeleton->getBoneInfo(j).name == entry.bone->getBoneName())
								{
									Matrix4 bindPose = skeleton->getInvBindPose(j).inverseAffine();
									bindPose = SO()->getTransform().getMatrix() * bindPose;

									Vector3 position, scale;
									Quaternion rotation;
									bindPose.decomposition(position, rotation, scale);

									entry.sceneObject->setWorldPosition(position);
									entry.sceneObject->setWorldRotation(rotation);
									entry.sceneObject->setWorldScale(scale);

									break;
								}
							}
						}
					}
				}
			}
		}

		if (mInternal == nullptr || !isRunning)
			return;

		HAnimationClip newPrimaryClip = mInternal->getClip(0);
		if (newPrimaryClip != mPrimaryPlayingClip)
			_refreshClipMappings();

		if (_scriptUpdateFloatProperties)
			_scriptUpdateFloatProperties();
	}
示例#5
0
	void CCollider::updateParentRigidbody()
	{
		if (mIsTrigger)
		{
			setRigidbody(HRigidbody());
			return;
		}

		HSceneObject currentSO = SO();
		while (currentSO != nullptr)
		{
			HRigidbody parent = currentSO->getComponent<CRigidbody>();
			if (parent != nullptr)
			{
				if(currentSO->getActive() && isValidParent(parent))
					setRigidbody(parent);
				else
					setRigidbody(HRigidbody());

				return;
			}

			currentSO = currentSO->getParent();
		}

		// Not found
		setRigidbody(HRigidbody());
	}
示例#6
0
	Vector<HBone> CAnimation::findChildBones()
	{
		Stack<HSceneObject> todo;
		todo.push(SO());

		Vector<HBone> bones;
		while (todo.size() > 0)
		{
			HSceneObject currentSO = todo.top();
			todo.pop();

			HBone bone = currentSO->getComponent<CBone>();
			if (bone != nullptr)
			{
				bone->_setParent(static_object_cast<CAnimation>(getHandle()), true);
				bones.push_back(bone);
			}

			int childCount = currentSO->getNumChildren();
			for (int i = 0; i < childCount; i++)
			{
				HSceneObject child = currentSO->getChild(i);
				if (child->getComponent<CAnimation>() != nullptr)
					continue;

				todo.push(child);
			}
		}

		return bones;
	}
示例#7
0
	void CSliderJoint::getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation)
	{
		position = mPositions[(UINT32)body];
		rotation = mRotations[(UINT32)body];

		HRigidbody rigidbody = mBodies[(UINT32)body];
		const Transform& tfrm = SO()->getTransform();
		if (rigidbody == nullptr) // Get world space transform if no relative to any body
		{
			Quaternion worldRot = tfrm.getRotation();

			rotation = worldRot*rotation;
			position = worldRot.rotate(position) + tfrm.getPosition();
		}
		else
		{
			const Transform& rigidbodyTfrm = rigidbody->SO()->getTransform();

			// Use only the offset for positioning, but for rotation use both the offset and target SO rotation.
			// (Needed because we need to rotate the joint SO in order to orient the slider direction, so we need an
			// additional transform that allows us to orient the object)
			position = rotation.rotate(position);
			rotation = (rigidbodyTfrm.getRotation()*rotation).inverse()*tfrm.getRotation();
		}
	}
示例#8
0
	bool Deflate::startup(string& startup_errors) {
		string errors;
		if ( ! loadattempted ) {
			loadattempted = true;
			loaded = false;
			string libdir,libstr;
			if (!Environment::getbenv("OBYX_LIBZIPSO",libstr)) { 	//legacy method
				if (Environment::getbenv("OBYX_LIBZIPDIR",libdir)) {
					if (!libdir.empty() && *libdir.rbegin() != '/') libdir.push_back('/');
				}
				libstr = SO(libdir,libz);
			}
			lib_handle = dlopen(libstr.c_str(),RTLD_GLOBAL | RTLD_NOW);
			dlerr(errors); //debug only.
			if (errors.empty() && lib_handle != nullptr ) {
				//load dl functions .
				obyx_zlibVersion  =(const char* (*)(void)) dlsym(lib_handle,"zlibVersion"); dlerr(errors);
				obyx_deflateInit =(int (*)(z_streamp,int,const char*,int)) dlsym(lib_handle,"deflateInit_"); dlerr(errors);
				obyx_deflate =(int (*)(z_streamp,int)) dlsym(lib_handle,"deflate"); dlerr(errors);
				obyx_deflateEnd =(int (*)(z_streamp)) dlsym(lib_handle,"deflateEnd"); dlerr(errors);
				obyx_inflateInit =(int (*)(z_streamp,const char*,int)) dlsym(lib_handle,"inflateInit_"); dlerr(errors);
				obyx_inflate =(int (*)(z_streamp,int)) dlsym(lib_handle,"inflate"); dlerr(errors);
				obyx_inflateEnd =(int (*)(z_streamp)) dlsym(lib_handle,"inflateEnd"); dlerr(errors);
				obyx_deflateBound = (uLong (*)(z_streamp,uLong)) dlsym(lib_handle,"deflateBound"); dlerr(errors);

				if ( errors.empty() ) {
					loaded = true;
					const char* zlv = obyx_zlibVersion();
					if (zlv != nullptr) { libversion = zlv; }
				}
			}
			startup_errors.append(errors);
		}
		return loaded;
	}
示例#9
0
	void CAudioSource::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive())
			return;

		if ((flags & (TCF_Parent | TCF_Transform)) != 0)
			updateTransform();
	}
示例#10
0
文件: thinning.cpp 项目: helderc/hIP
bool Thinning::vizinhanca(QImage *img, int x,int y) {



// verificaCorerifica se o número de vizinhos pretos está na faixa entre 2 e 6
int vizinhos=0;

vizinhos = ( verificaPixel(img, NO(x,y)) + verificaPixel(img, N(x,y)) + verificaPixel(img,NE(x,y)) +
           verificaPixel(img, O(x,y)) + verificaPixel(img, L(x,y)) + verificaPixel(img, SO(x,y)) +
           verificaPixel(img, S(x,y)) + verificaPixel(img, SE(x,y)) );

if (vizinhos < 2 || vizinhos > 6) return false;

// verificaCorerifica conectividade é igual 1...
int conectividade = 0;

if(verificaPixel (img, N(x,y))  == false && verificaPixel (img, NE(x,y)) == true)
        conectividade++;

if(verificaPixel(img, NE(x,y)) == false && verificaPixel(img, L(x,y)) == true)
    conectividade++;

if(verificaPixel(img, L(x,y)) == false && verificaPixel(img, SE(x,y)) == true)
    conectividade++;

if(verificaPixel(img, SE(x,y)) == false && verificaPixel(img, S(x,y)) == true)
    conectividade++;

if(verificaPixel(img, S(x,y)) == false && verificaPixel(img, SO(x,y)) == true)
    conectividade++;

if(verificaPixel(img, SO(x,y)) == false && verificaPixel(img, O(x,y)) == true)
    conectividade++;

if(verificaPixel(img, O(x,y)) == false && verificaPixel(img, NO(x,y)) == true)
    conectividade++;

if(verificaPixel(img, NO(x,y)) == false && verificaPixel(img, N(x,y)) == true)
    conectividade++;

if(conectividade == 1)
    return true;
else
    return false;

}
示例#11
0
	void CBone::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive())
			return;

		if ((flags & TCF_Parent) != 0)
			updateParentAnimation();
	}
示例#12
0
	SPtr<Collider> CBoxCollider::createInternal()
	{
		const Transform& tfrm = SO()->getTransform();
		SPtr<Collider> collider = BoxCollider::create(mExtents, tfrm.getPosition(), tfrm.getRotation());
		collider->_setOwner(PhysicsOwnerType::Component, this);

		return collider;
	}
示例#13
0
	void CAnimation::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive())
			return;

		if ((flags & (TCF_Transform)) != 0)
			_updateBounds(false);
	}
示例#14
0
	void CRigidbody::move(const Vector3& position)
	{
		if (mInternal != nullptr)
			mInternal->move(position);

		mNotifyFlags = (TransformChangedFlags)0;
		SO()->setWorldPosition(position);
		mNotifyFlags = (TransformChangedFlags)(TCF_Parent | TCF_Transform);
	}
	void CCharacterController::updateDimensions()
	{
		Vector3 scale = SO()->getWorldScale();
		float height = mDesc.height * Math::abs(scale.y);
		float radius = mDesc.radius * Math::abs(std::max(scale.x, scale.z));

		mInternal->setHeight(height);
		mInternal->setRadius(radius);
	}
示例#16
0
 Lattice SO () {
   Lattice SO(4);
   SO.bond(0,1).bond(1,2).bond(2,3).bond(3,0).bond(2,0,coo(0,1)).bond(1,3,coo(1,0));
   SO.z[0]=cpx(.5,.25);
   SO.z[1]=cpx(.75,.5);
   SO.z[2]=cpx(.5,.75);
   SO.z[3]=cpx(.25,.5);
   return SO;
 }
示例#17
0
	void CRigidbody::rotate(const Quaternion& rotation)
	{
		if (mInternal != nullptr)
			mInternal->rotate(rotation);

		mNotifyFlags = (TransformChangedFlags)0;
		SO()->setWorldRotation(rotation);
		mNotifyFlags = (TransformChangedFlags)(TCF_Parent | TCF_Transform);
	}
示例#18
0
/** Reports received end of stream */
static void vlc_h2_stream_end(void *ctx)
{
    struct vlc_h2_stream *s = ctx;

    msg_Dbg(SO(s), "stream %"PRIu32" closed by peer", s->id);

    s->recv_end = true;
    vlc_cond_broadcast(&s->recv_wait);
}
示例#19
0
	void CAnimation::updateSceneObjectMapping()
	{
		Vector<SceneObjectMappingInfo> newMappingInfos;
		for(auto& entry : mMappingInfos)
		{
			if (entry.isMappedToBone)
				newMappingInfos.push_back(entry);
			else
				unmapSceneObject(entry.sceneObject);
		}

		if (mPrimaryPlayingClip.isLoaded())
		{
			HSceneObject root = SO();

			const auto& findMappings = [&](const String& name, AnimationCurveFlags flags)
			{
				if (flags.isSet(AnimationCurveFlag::ImportedCurve))
					return;

				HSceneObject currentSO = root->findPath(name);

				bool found = false;
				for (UINT32 i = 0; i < (UINT32)newMappingInfos.size(); i++)
				{
					if (newMappingInfos[i].sceneObject == currentSO)
					{
						found = true;
						break;
					}
				}

				if (!found)
				{
					SceneObjectMappingInfo newMappingInfo;
					newMappingInfo.isMappedToBone = false;
					newMappingInfo.sceneObject = currentSO;

					newMappingInfos.push_back(newMappingInfo);
					mapCurveToSceneObject(name, currentSO);
				}
			};

			SPtr<AnimationCurves> curves = mPrimaryPlayingClip->getCurves();
			for(auto& curve : curves->position)
				findMappings(curve.name, curve.flags);

			for(auto& curve : curves->rotation)
				findMappings(curve.name, curve.flags);

			for(auto& curve : curves->scale)
				findMappings(curve.name, curve.flags);
		}

		mMappingInfos = newMappingInfos;
	}
示例#20
0
	void CRigidbody::onEnabled()
	{
		mInternal = Rigidbody::create(SO());
		mInternal->_setOwner(PhysicsOwnerType::Component, this);

		updateColliders();

#if BS_DEBUG_MODE
		checkForNestedRigibody();
#endif

		mInternal->onCollisionBegin.connect(std::bind(&CRigidbody::triggerOnCollisionBegin, this, _1));
		mInternal->onCollisionStay.connect(std::bind(&CRigidbody::triggerOnCollisionStay, this, _1));
		mInternal->onCollisionEnd.connect(std::bind(&CRigidbody::triggerOnCollisionEnd, this, _1));

		mInternal->setTransform(SO()->getWorldPosition(), SO()->getWorldRotation());

		// Note: Merge into one call to avoid many virtual function calls
		mInternal->setPositionSolverCount(mPositionSolverCount);
		mInternal->setVelocitySolverCount(mVelocitySolverCount);
		mInternal->setMaxAngularVelocity(mMaxAngularVelocity);
		mInternal->setDrag(mLinearDrag);
		mInternal->setAngularDrag(mAngularDrag);
		mInternal->setSleepThreshold(mSleepThreshold);
		mInternal->setUseGravity(mUseGravity);
		mInternal->setIsKinematic(mIsKinematic);
		mInternal->setFlags(mFlags);

		if(((UINT32)mFlags & (UINT32)Rigidbody::Flag::AutoTensors) == 0)
		{
			mInternal->setCenterOfMass(mCMassPosition, mCMassRotation);
			mInternal->setInertiaTensor(mInertiaTensor);
			mInternal->setMass(mMass);
		}
		else
		{
			if (((UINT32)mFlags & (UINT32)Rigidbody::Flag::AutoMass) == 0)
				mInternal->setMass(mMass);

			mInternal->updateMassDistribution();
		}
	}
示例#21
0
/** Reports remote stream error */
static int vlc_h2_stream_reset(void *ctx, uint_fast32_t code)
{
    struct vlc_h2_stream *s = ctx;

    msg_Err(SO(s), "peer stream %"PRIu32" error: %s (0x%"PRIXFAST32")",
            s->id, vlc_h2_strerror(code), code);

    s->recv_end = true;
    vlc_cond_broadcast(&s->recv_wait);
    return 0;
}
	void CCharacterController::onEnabled()
	{
		mDesc.position = SO()->getWorldPosition();
		mInternal = CharacterController::create(mDesc);
		mInternal->_setOwner(PhysicsOwnerType::Component, this);

		mInternal->onColliderHit.connect(std::bind(&CCharacterController::triggerOnColliderHit, this, _1));
		mInternal->onControllerHit.connect(std::bind(&CCharacterController::triggerOnControllerHit, this, _1));

		mInternal->setLayer(mLayer);
		updateDimensions();
	}
示例#23
0
	void CCollider::updateTransform()
	{
		Vector3 myScale = SO()->getWorldScale();

		if (mParent != nullptr)
		{
			Vector3 parentPos = mParent->SO()->getWorldPosition();
			Quaternion parentRot = mParent->SO()->getWorldRotation();

			Vector3 myPos = SO()->getWorldPosition();
			Quaternion myRot = SO()->getWorldRotation();

			Vector3 scale = mParent->SO()->getWorldScale();
			Vector3 invScale = scale;
			if (invScale.x != 0) invScale.x = 1.0f / invScale.x;
			if (invScale.y != 0) invScale.y = 1.0f / invScale.y;
			if (invScale.z != 0) invScale.z = 1.0f / invScale.z;

			Quaternion invRotation = parentRot.inverse();

			Vector3 relativePos = invRotation.rotate(myPos - parentPos) *  invScale;
			Quaternion relativeRot = invRotation * myRot;

			relativePos = relativePos + myRot.rotate(mLocalPosition * scale);
			relativeRot = relativeRot * mLocalRotation;

			mInternal->setTransform(relativePos, relativeRot);
			mParent->_updateMassDistribution();
		}
		else
		{
			Quaternion myRot = SO()->getWorldRotation();
			Vector3 myPos = SO()->getWorldPosition() + myRot.rotate(mLocalPosition * myScale);
			myRot = myRot * mLocalRotation;

			mInternal->setTransform(myPos, myRot);
		}

		mInternal->setScale(myScale);
	}
示例#24
0
	void CRigidbody::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive())
			return;

		if((flags & TCF_Parent) != 0)
		{
			clearColliders();
			updateColliders();

			if (((UINT32)mFlags & (UINT32)Rigidbody::Flag::AutoTensors) != 0)
				mInternal->updateMassDistribution();

#if BS_DEBUG_MODE
			checkForNestedRigibody();
#endif
		}

		mInternal->setTransform(SO()->getWorldPosition(), SO()->getWorldRotation());

		if (mParentJoint != nullptr)
			mParentJoint->notifyRigidbodyMoved(mThisHandle);
	}
示例#25
0
/** Reports received stream headers */
static void vlc_h2_stream_headers(void *ctx, unsigned count, char *hdrs[][2])
{
    struct vlc_h2_stream *s = ctx;

    /* NOTE: HTTP message trailers are not supported so far. Follow-up headers
     * can therefore only be a final response after a 1xx continue response.
     * Then it is safe to discard the existing header. */
    if (s->recv_hdr != NULL)
    {
        msg_Dbg(SO(s), "stream %"PRIu32" discarding old headers", s->id);
        vlc_http_msg_destroy(s->recv_hdr);
        s->recv_hdr = NULL;
    }

    msg_Dbg(SO(s), "stream %"PRIu32" %u headers:", s->id, count);

    for (unsigned i = 0; i < count; i++)
        msg_Dbg(SO(s), " %s: \"%s\"", hdrs[i][0], hdrs[i][1]);

    s->recv_hdr = vlc_http_msg_h2_headers(count, hdrs);
    if (unlikely(s->recv_hdr == NULL))
        vlc_h2_stream_fatal(s, VLC_H2_PROTOCOL_ERROR);
    vlc_cond_signal(&s->recv_wait);
}
示例#26
0
	void CAnimation::setBoneMappings()
	{
		mMappingInfos.clear();

		SceneObjectMappingInfo rootMapping;
		rootMapping.sceneObject = SO();
		rootMapping.isMappedToBone = true;

		mMappingInfos.push_back(rootMapping);
		mInternal->mapCurveToSceneObject("", rootMapping.sceneObject);

		Vector<HBone> childBones = findChildBones();
		for (auto& entry : childBones)
			_addBone(entry);
	}
示例#27
0
	void CCollider::onTransformChanged(TransformChangedFlags flags)
	{
		if (!SO()->getActive())
			return;

		if ((flags & TCF_Parent) != 0)
			updateParentRigidbody();

		// Don't update the transform if it's due to Physics update since then we can guarantee it will remain at the same
		// relative transform to its parent
		if (gPhysics()._isUpdateInProgress())
			return;

		if ((flags & (TCF_Parent | TCF_Transform)) != 0)
			updateTransform();
	}
示例#28
0
	void CRigidbody::checkForNestedRigibody()
	{
		HSceneObject currentSO = SO()->getParent();

		while(currentSO != nullptr)
		{
			if(currentSO->hasComponent<CRigidbody>())
			{
				LOGWRN("Nested Rigidbodies detected. This will result in inconsistent transformations. To parent one " \
					"Rigidbody to another move its colliders to the new parent, but remove the Rigidbody component.");
				return;
			}

			currentSO = currentSO->getParent();
		}
	}
示例#29
0
	void CRigidbody::updateColliders()
	{
		Stack<HSceneObject> todo;
		todo.push(SO());

		while(!todo.empty())
		{
			HSceneObject currentSO = todo.top();
			todo.pop();

			if(currentSO->hasComponent<CCollider>())
			{
				Vector<HCollider> colliders = currentSO->getComponents<CCollider>();
				
				for (auto& entry : colliders)
				{
					if (!entry->isValidParent(mThisHandle))
						continue;

					Collider* collider = entry->_getInternal();
					if (collider == nullptr)
						continue;

					entry->setRigidbody(mThisHandle, true);
					mChildren.push_back(entry);

					collider->setRigidbody(mInternal.get());
					mInternal->addCollider(collider->_getInternal());
				}
			}

			UINT32 childCount = currentSO->getNumChildren();
			for (UINT32 i = 0; i < childCount; i++)
			{
				HSceneObject child = currentSO->getChild(i);

				if (child->hasComponent<CRigidbody>())
					continue;

				todo.push(child);
			}
		}
	}
int CMP3::PlayMP3( const char *pszSong )
{
	if( m_iIsPlaying )
	{
	// sound system is already initialized
		SCL( m_Stream );
	} 
	else
	{
		SOP( FSOUND_OUTPUT_DSOUND );
		SBS( 200 );
		SDRV( 0 );
		INIT( 44100, 1, 0 ); // we need just one channel, multiple mp3s at a time would be, erm, strange...	
	}//AJH not for really cool effects, say walking past cars in a street playing different tunes, might change this later.

	char song[256];

	sprintf( song, "%s/%s", gEngfuncs.pfnGetGameDirectory(), pszSong);

	//gEngfuncs.Con_Printf("Using fmod.dll version %f\n",VER());

	if (SO)
	{
		m_Stream = SO( song, FSOUND_NORMAL | FSOUND_LOOP_NORMAL, 0 ,0); //AJH new version fmod uses Open
	}
	else if( SOF )
	{													
		m_Stream = SOF( song, FSOUND_NORMAL | FSOUND_LOOP_NORMAL, 1 ); //AJH old version fmod OpenFile
	}
	if(m_Stream)
	{
		SPLAY( 0, m_Stream );
		m_iIsPlaying = 1;
		return 1;
	}
	else
	{
		m_iIsPlaying = 0;
		gEngfuncs.Con_Printf("Error: Could not load %s\n",song);
		return 0;
	}
}