Пример #1
0
//-----------------------------------------------
// updateParticlesNoActor :
//
//-----------------------------------------------
void CSceneParser::updateParticlesNoActor(float difTime, CParticle &particle, UAnimation &animation)
{
	// Animate all instances.
	for(uint i = 0; i < particle.IGPtr->getNumInstance(); ++i )
	{
		std::string iName = particle.IGPtr->getInstanceName(i);
		UInstance instance = particle.IGPtr->getByName(iName);

		if(!instance)
			continue;

		instance->setTransformMode(UTransformable::RotQuat);

		// If the animation has no track of position.
		UTrack* trackPos = animation.getTrackByName("PathPos");
		if(!trackPos)
			trackPos = animation.getTrackByName(string(iName + "." + "PathPos").c_str());
		if(trackPos)
		{
			CVector pos;
			trackPos->interpolate(difTime, pos);
			instance->setPos(pos);
		}

		// If the animation has no track of rotation.
		UTrack* trackRot = animation.getTrackByName("PathRotQuat");
		if(!trackRot)
			trackRot = animation.getTrackByName(string(iName + "." + "PathRotQuat").c_str());
		if(trackRot)
		{
			CQuat rot;
			if(trackRot->interpolate(difTime, rot))
				instance->setRotQuat(rot);
			else
				nlwarning("CSceneParser::updateParticles : Not a Quat!");
		}
	}
}// updateParticlesNoActor //
Пример #2
0
void	initCamera()
{
	if (ConfigFile->getVar("HMDEnable").asBool())
	{
		std::vector<NL3D::CStereoDeviceInfo> devices;
		IStereoDisplay::listDevices(devices);
		for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
		{
			std::stringstream name;
			name << std::string("[") << it->Serial << "] [" << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName << "]";
			nlinfo("Stereo Display: %s", name.str().c_str());
		}
		CStereoDeviceInfo *deviceInfo = NULL;
		std::string hmdDeviceCfg = ConfigFile->getVar("HMDDevice").asString();
		if (hmdDeviceCfg == std::string("Auto")
			&& devices.begin() != devices.end())
		{
			for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
			{
				if (it->AllowAuto)
				{
					deviceInfo = &devices[0];
				}
			}
		}
		else
		{
			std::string hmdDeviceId = ConfigFile->getVar("HMDDeviceId").asString();
			for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
			{
				std::stringstream name;
				name << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName;
				if (name.str() == hmdDeviceCfg)
					deviceInfo = &(*it);
				if (hmdDeviceId == it->Serial)
					break;
			}
		}
		if (deviceInfo)
		{
			nlinfo("Create VR stereo display device");
			StereoDisplay = IStereoDisplay::createDevice(*deviceInfo);
			if (StereoDisplay)
			{
				if (deviceInfo->Class == CStereoDeviceInfo::StereoHMD)
				{
					nlinfo("Stereo display device is a HMD");
					StereoHMD = static_cast<IStereoHMD *>(StereoDisplay);
					StereoHMD->setScale(3.0f); // snowballs is about 4 units per meter
				}
				StereoDisplay->setDriver(Driver); // move after driver creation, move stereodisplay before driver creation
				StereoDisplay->attachToDisplay();
			}
		}
	}
	IStereoDisplay::releaseUnusedLibraries();

	// Set up directly the camera
	Camera = Scene->getCam();
	Camera.setTransformMode (UTransformable::DirectMatrix);
	Camera.setPerspective((float)Pi/2.f, 
		ConfigFile->getVar("ScreenWidth").asFloat() / ConfigFile->getVar("ScreenHeight").asFloat(), 
		0.1f, 1000.f);
	Camera.lookAt (CVector(ConfigFile->getVar("StartPoint").asFloat(0),
							ConfigFile->getVar("StartPoint").asFloat(1),
							ConfigFile->getVar("StartPoint").asFloat(2)),
							CVectorD (0,0,0));

	CamCollisionEntity = VisualCollisionManager->createEntity();
	CamCollisionEntity->setCeilMode(true);

	// Create the snowing particle system
	Snow = Scene->createInstance("snow.ps");
	// And setup it
	Snow.setTransformMode (UTransformable::DirectMatrix);

	//
	// Setup the sky scene
	//

	// -- -- not sure what the sky has to do with the camera

	SkyScene = Driver->createScene(false);

	SkyCamera = SkyScene->getCam ();
	SkyCamera.setTransformMode (UTransformable::DirectMatrix);
	// Set the very same frustum as the main camera
	SkyCamera.setFrustum (Camera.getFrustum ());

	Sky = SkyScene->createInstance("sky.shape");
	Sky.setTransformMode (UTransformable::DirectMatrix);
	Sky.setMatrix(CMatrix::Identity);
}
Пример #3
0
// ------------------------------------------------------------------------------------------------
void CCharacter3D::createInstance (TChar3DPart i, const SCharacter3DSetup::SCharacterPart &part)
{
	if (_Scene == NULL)
	{
		nlwarning ("CCharacter3D::createInstance : no scene setup.");
		return;
	}

	if (!_Instances[i].empty())
		_Scene->deleteInstance (_Instances[i]);

	if ((!part.Name.empty()) && (part.Name != "none.shape"))
		_Instances[i] = _Scene->createInstance (part.Name);

	// if cannot create output some errors
	if (_Instances[i].empty())
	{
		if ((i != Char3DPart_HandRightItem) && (i != Char3DPart_HandLeftItem))
			nlwarning ("CCharacter3D::createInstance : cannot create the instance : %s.", part.Name.c_str());
		return;
	}

	// FX Management

	// Advantage Fx
	if (!_InstancesFx[i].AdvantageFx.empty())
		_Scene->deleteInstance (_InstancesFx[i].AdvantageFx);

	if ((!part.AdvFx.empty()) && (part.AdvFx != "none.shape"))
	{
		_InstancesFx[i].AdvantageFx = _Scene->createInstance (part.AdvFx);
		if (_InstancesFx[i].AdvantageFx.empty())
		{
			nlwarning ("CCharacter3D::createInstance : cannot create the fx : %s.", part.AdvFx.c_str());
		}
		else
		{
			CMatrix mat = _Instances[i].getMatrix();
			mat.invert();
			mat *= _InstancesFx[i].AdvantageFx.getMatrix();
			_InstancesFx[i].AdvantageFx.setTransformMode(UTransformable::DirectMatrix);
			_InstancesFx[i].AdvantageFx.setMatrix(mat);
			_InstancesFx[i].AdvantageFx.parent(_Instances[i]);
		}
	}

	// Static Fx
	uint32 fx;
	for (fx = 0; fx < _InstancesFx[i].StaticFx.size(); ++fx)
		if (!_InstancesFx[i].StaticFx[fx].empty())
			_Scene->deleteInstance(_InstancesFx[i].StaticFx[fx]);
	_InstancesFx[i].StaticFx.clear();

	for (fx = 0; fx < part.StatFxNames.size(); ++fx)
		if ((!part.StatFxNames[fx].empty()) && (part.StatFxNames[fx] != "none.shape") &&
			(!part.StatFxBones[fx].empty()) && (part.StatFxBones[fx] != "none.shape"))
		{
			sint boneID = _Skeleton.getBoneIdByName(part.StatFxBones[fx]);
			if (boneID != -1)
			{
				UInstance instance = _Scene->createInstance(part.StatFxNames[fx]);
				if (!instance.empty())
				{
					instance.setTransformMode(UTransform::DirectMatrix);
					CMatrix mat;
					mat.setPos(part.StatFxOffss[fx]);
					instance.setMatrix(mat);
					_Skeleton.stickObject(instance, boneID);
					_InstancesFx[i].StaticFx.push_back(instance);
				}
				else
				{
					nlwarning("Can't create static fx %s sticked on bone %s", part.StatFxNames[fx].c_str(), part.StatFxBones[fx].c_str());
				}
			}
			else
			{
				nlwarning("Can't find bone %s for static fx %s", part.StatFxBones[fx].c_str(), part.StatFxNames[fx].c_str());
			}
		}
}
Пример #4
0
//-----------------------------------------------
// updateParticlesActor :
//
//-----------------------------------------------
void CSceneParser::updateParticlesActor(float difTime, CParticle &particle, UAnimation &animation)
{
	// Get the entity pointer.
	CEntityCL *entity = getEntity(Sid(Sid::npc, (uint64)particle.Actor));
	if(!entity)
	{
		nlwarning("CSceneParser::updateParticlesActor : cannot get the actor %d.", (uint64)particle.Actor);
		return;
	}

	// If the entity has no skeleton -> Next particle.
	if(!entity->skeleton())
	{
		nlwarning("The particle follow an entity %d without a skeleton.", (uint64)particle.Actor);
		return;
	}

	// Matrix 90°
	CMatrix m90;
	m90.identity();
	m90.rotateZ((float)(Pi/2.0));

	// Matrix of the entity.
	CMatrix mChar = entity->skeleton()->getMatrix();
	mChar.setPos(entity->pos());

	// Animate all instances.
	for(uint i = 0; i < particle.IGPtr->getNumInstance(); ++i )
	{
		std::string iName = particle.IGPtr->getInstanceName(i);
		UInstance instance = particle.IGPtr->getByName(iName);

		if(!instance)
			continue;

		instance->setTransformMode(UTransformable::RotQuat);

		CMatrix mAnim;
		mAnim.identity();
		// If the animation has no track of position.
		UTrack* trackPos = animation.getTrackByName("PathPos");
		if(!trackPos)
			trackPos = animation.getTrackByName(string(iName + "." + "PathPos").c_str());
		if(trackPos)
		{
			CVector pos;
			trackPos->interpolate(difTime, pos);
			mAnim.setPos(pos);
		}

		// If the animation has no track of rotation.
		UTrack* trackRot = animation.getTrackByName("PathRotQuat");
		if(!trackRot)
			trackRot = animation.getTrackByName(string(iName + "." + "PathRotQuat").c_str());
		if(trackRot)
		{
			CQuat rot;
			trackPos->interpolate(difTime, rot);
			mAnim.setRot(rot);
		}

		CMatrix mFinal = mChar * m90 * mAnim;
		instance->setPos(mFinal.getPos());
		instance->setRotQuat(mFinal.getRot());
	}
}// updateParticlesActor //