Ejemplo n.º 1
0
void updateCamera()
{
	if (StereoHMD)
	{
		NLMISC::CQuat hmdOrient = StereoHMD->getOrientation();
		NLMISC::CMatrix camMatrix = Camera.getMatrix();
		NLMISC::CMatrix hmdMatrix;
		hmdMatrix.setRot(hmdOrient);
		NLMISC::CMatrix posMatrix; // minimal head modeling, will be changed in the future
		posMatrix.translate(StereoHMD->getEyePosition());
		Camera.setMatrix((camMatrix * hmdMatrix) * posMatrix);
	}
	// Set the new position of the snow emitter
	CMatrix	mat = CMatrix::Identity;
	mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
	Snow.setMatrix(mat);
}
Ejemplo n.º 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);
}
Ejemplo n.º 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());
			}
		}
}