Пример #1
0
//---------------------------------------------------------------------------
NiCamera* NIF_Files::FindCamera(NiAVObject* pkObject)
{
    // This function recursively walks the scenegraph until a camera
    // is found.

	if (NiIsKindOf(NiCamera, pkObject))
    {
        return (NiCamera*) pkObject;
    }
    else if (NiIsKindOf(NiNode, pkObject))
    {
        // NiNodes are the primary structural objects in Gamebryo. They 
        // group other Gamebryo scene objects together under a common parent
        // and coordinate system. NiNodes can have as many children as 
        // necessary, but those children are not guaranteed to be contiguous.

        NiNode* pkNode = (NiNode*) pkObject;
        for (unsigned int ui = 0; ui < pkNode->GetArrayCount(); ui++)
        {
            NiCamera* pkFoundCamera = FindCamera(pkNode->GetAt(ui));
            if (pkFoundCamera)
                return pkFoundCamera;
        }
    }

    return NULL;
}
Пример #2
0
//-------------------------------------------------------------------------------------------------
uint sdPhysXSceneMgr::CookObject(sdPhysXMemoryWriteStream& kStream, NiAVObject* spAVObject, float fScale, bool bFlipNormal)
{
	uint uiSizeByBytes = 0;
	if (NiIsKindOf(NiMesh, spAVObject))
	{
		NiMesh* spMesh = (NiMesh*)spAVObject;
		uiSizeByBytes += CookMesh(kStream, spMesh, fScale, bFlipNormal);
	}
	else if (spAVObject->IsNode())
	{
		NiNode* spNode = (NiNode*)spAVObject;
		for (uint ui = 0; ui < spNode->GetArrayCount(); ++ui)
		{
			NiAVObject* spChildAVObject = spNode->GetAt(ui);
			if (spChildAVObject)
				uiSizeByBytes += CookObject(kStream, spChildAVObject, fScale, bFlipNormal);
		}
	}
	return uiSizeByBytes;
}
Пример #3
0
	//---------------------------------------------------------------------------
	void Player::Update(float fTime)
	{
		float fDeltaTime = NiAbs(fTime - m_fLastUpdateTime);

		if (fDeltaTime > 1.0f)
		{
			m_fLastUpdateTime = fTime;
			return;
		}

		if (m_pkTarget)    // if there is an object, move it
		{
			NiAVObject* pkObject = (NiAVObject*)m_pkTarget;
			NIASSERT(NiIsKindOf(NiAVObject, pkObject));

			// Check the Keyboard exists
			NiInputKeyboard* pkKeyboard = NULL;
			if (m_pkGameApp->GetInputSystem())
			{
	           
				pkKeyboard = m_pkGameApp->GetInputSystem()->GetKeyboard();
			}

			int iHorz = 0;
			int iVert = 0;

	       

			if (pkKeyboard != NULL)
			{
				if (pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_LEFT) || pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_A))
					iHorz = -127;

				if (pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_RIGHT)|| pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_D))
					iHorz = 127;

				if (pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_DOWN)|| pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_S))
					iVert = 127;

				if (pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_UP)|| pkKeyboard->KeyIsDown(NiInputKeyboard::KEY_W))
					iVert = -127;
			}

			if (iHorz)
			{
				float fZ = iHorz * (1.0f / 127.0f);
				NiPoint3 kTrans(.1*fZ,0,0);
				kTrans = kTrans + pkObject->GetTranslate();
				if(kTrans.x > m_xBoundNeg && kTrans.x <m_xBoundPos)
					pkObject->SetTranslate(kTrans);
			}

			 if (iVert)
			{
				float fZ = iVert * (1.0f / 127.0f);
				NiPoint3 kTrans(0,0,.1*fZ);
				kTrans = kTrans + pkObject->GetTranslate();
				if(kTrans.z > m_zBoundNeg && kTrans.z <m_zBoundPos)
					pkObject->SetTranslate(kTrans);
			}
			 
	        
		}

		m_fLastUpdateTime = fTime;
	}
Пример #4
0
//---------------------------------------------------------------------------
bool NIF_Files::CreateScene()
{
    // Because our scene will have some billboards with alpha, we use 
    // a NiAlphaAccumulator in order that our alpha gets sorted and drawn
    // correctly.
    NiAlphaAccumulator* pkAccum = NiNew NiAlphaAccumulator;
    m_spRenderer->SetSorter(pkAccum);
	
    // NiStreams are used to load a NIF file from disk. Once a stream is 
    // loaded, it will contain one or more "top-level" objects. These objects
    // could be NiNodes, NiTextures, or any other Gamebryo class. The Max and 
    // Maya exporters both place the scene graph as the first element in the
    // NIF file.

    NiStream kStream;

    // Load in the scenegraph for our world...
    bool bSuccess = kStream.Load(
        NiApplication::ConvertMediaFilename("GameScene.nif"));

    if (!bSuccess)
    {
        NiMessageBox("WORLD.NIF file could not be loaded!", "NIF Error");
        return false;
    }

    m_spScene = (NiNode*) kStream.GetObjectAt(0);
    NIASSERT(NiIsKindOf(NiNode, m_spScene));

    // We expect the world to have been exported with a camera, so we 
    // look for it here.
    // In order to render the scene graph, we need a camera. We're now going
    // to recurse the scene graph looking for a camera.
    if (!FindSceneCamera())
    {
        NiMessageBox("The NIF file has no camera!", "Camera Error");
        return false;
    }


	NiTObjectArray<NiCameraPtr> kCameras;
	NiTObjectArray<NiLightPtr> kLights;
	NiTObjectArray<NiNodePtr> kScenes;
	//NiStream kStream;
	//bool bSuccess = kStream.Load(
 //       NiApplication::ConvertMediaFilename("GameScene.nif"));

 //   if (!bSuccess)
 //   {
 //       NiMessageBox("WORLD.NIF file could not be loaded!", "NIF Error");
 //       return false;
 //   }

	for (unsigned int i = 0; i < kStream.GetObjectCount(); i++)
	{
		NiObject* pkObject = kStream.GetObjectAt(i);
		if (NiIsKindOf(NiCamera, pkObject))
			kCameras.Add((NiCamera*) pkObject);
		else if (NiIsKindOf(NiLight, pkObject))
			kLights.Add((NiLight*) pkObject);
		else if (NiIsKindOf(NiNode, pkObject))
			kScenes.Add((NiNode*) pkObject);
		else
		{
			// unknown object, handle it somehow
		}
	}

	//m_spScene = (NiNode*) kStream.GetObjectAt(0);
 //   NIASSERT(NiIsKindOf(NiNode, m_spScene));

    return bSuccess;
}