예제 #1
0
//------------------------------------------------------------------------
// Initialize the scene content for the application.
//------------------------------------------------------------------------
HRESULT LightShadowApp::OneTimeSceneInit(void)
{
    FlyKernel& engine = FlyKernel::Instance();

    // Create a new sceneManager.
    FlySceneManager* pManager = engine.CreateSceneManager( "TestShadow","default" );
    if( !pManager )
    {
        OnErrorExit( "Create the sceneManager failed, The application will exit!" );
        return FLY_OK;
    }

    // Set the backcolor.
    engine.GetRenderDevice()->SetClearColor( 0.1f,0.1f,0.1f );

    // Set the ambient color.
    FLYCOLOR color;
    color.fR = 0.1f;
    color.fG = 0.1f;
    color.fB = 0.1f;
    color.fA = 1.0f;
    pManager->SetAmbientColor( color );

    FlyMeshEntity* pObject = pManager->CreateMeshEntity( "Ground","../../Media/Models/Teapot/Ground.smd" );
    pObject->SetLightingMode( true );
    pManager->GetSceneRoot()->AttachObject( pObject );

    FlySceneNode* pChild = pManager->GetSceneRoot()->CreateChildNode();
    pObject = pManager->CreateMeshEntity( "Teapot","../../Media/Models/Teapot/Teapot.smd" );
    pObject->SetLightingMode( true );
    pObject->SetHaveShadow( true );
    pChild->AttachObject( pObject );

    // Create a light object.
    FlyVector vPosition( 150.0f,150.0f,0.0f );
    FlyLightObject* pLight = pManager->CreateLightObject( "Light1","default" );
    pLight->SetLightType( LGT_POINT );
    pLight->SetPosition( vPosition );
    pLight->SetDiffuseColor( FLYCOLOR::White );
    pLight->SetRange( 1000.0f );
    pLight->SetAttenuationA( 0.9f );
    pLight->SetAttenuationB( 0.0f );
    pLight->SetCastShadows( true );
    pManager->GetSceneRoot()->AttachLightObject( pLight );
    pManager->SetShadowMode( true );

    engine.SetActiveSceneManager( pManager );

    // Create a new camera.
    FlyCamManager* pCamMgr = engine.GetCamManager();
    FlyCameraBase* pCamera = pCamMgr->CreateCamera( "DefaultCamera" );
    pManager->SetCurrentCamera( pCamera );
    pCamera->SetPosition( 0.0f,10.0f,-120.0f );
    pCamera->LookAt( 0.0f,0.0f,0.0f );

    // Create a font object.
    //m_pFont = engine.GetResourceManager()->MakeSystemFont();

    return FLY_OK;
}
예제 #2
0
int KFixedTrackMissileProcessor::Update(double fTime, double fTimeLast, KRLMissile* pRLMissile)
{
    HRESULT hr = E_FAIL;
    int nRetCode = false;
    int nSFXModelCount = 0;
    double fTimeDelta = 0.0;
    double fTimeTotal = 0.0;

    ASSERT(m_pRLMissile);
    ASSERT(m_pMissilePhaseModel);

    nSFXModelCount = GetSFXModelCount();
    fTimeTotal = GetTimeTotal();
    fTimeDelta = fTime - GetTimeStart();

    if (fTimeDelta <= fTimeTotal)
    {
        nRetCode = abs(fTimeTotal) > FLT_EPSILON;
        KGLOG_PROCESS_ERROR(nRetCode);

        int nFrameIndex = static_cast<int>(fTimeDelta * GAME_FPS / 1000.0f) % MISSILE_FIXED_TRACK_FRAME_COUNT;

        for (int nSFXModel = 0; nSFXModel < nSFXModelCount; ++nSFXModel)
        {
            D3DXVECTOR3 vPosition(0.0f, 0.0f, 0.0f);
            D3DXVECTOR3 vPositionTarget(0.0f, 0.0f, 0.0f);
            D3DXVECTOR3 vLocalPosition(0.0f, 0.0f, 0.0f);
            D3DXQUATERNION qRotationTarget;
            D3DXQUATERNION qRotationLH;
            KFixedTrackMissile& Missile = m_aFixedTrackMissile[nSFXModel];
            float fModelScale = static_cast<float>(m_fTotalModelScale * (fTimeDelta / fTimeTotal) + m_pMissilePhaseModel->fModelScaleBegin);

            int nFrameX = static_cast<int>(m_aFixedTrackMissile[nSFXModel].vFramePosition[nFrameIndex].x);
            int nFrameY = static_cast<int>(m_aFixedTrackMissile[nSFXModel].vFramePosition[nFrameIndex].y);
            int nFrameZ = static_cast<int>(m_aFixedTrackMissile[nSFXModel].vFramePosition[nFrameIndex].z);

            hr = GetTargetOrientation(vPositionTarget, qRotationTarget);
            KGLOG_COM_PROCESS_ERROR(hr);

            GameWorldCellPointToScenePoint(vPosition, nFrameX, nFrameY, nFrameZ, FALSE);

            hr = MissileMoveAngle(vPosition - Missile.vLastMoveDistance, m_aFixedTrackMissile[nSFXModel].fAngle);
            KGLOG_COM_PROCESS_ERROR(hr);

            Missile.vLastMoveDistance = vPosition;
            YawToQuatLH(qRotationLH, m_aFixedTrackMissile[nSFXModel].fAngle);

            for (int nModelType = 0; nModelType != MISSILE_PHASE_SFX_TYPE_COUNT; ++nModelType)
            {
                hr = SetSFXModelOrientation(nModelType, nSFXModel, fModelScale, vLocalPosition, vPosition, qRotationLH);
                KGLOG_COM_PROCESS_ERROR(hr);
            }
            Missile.vPosition = vLocalPosition;
        }
    }

    return true;
Exit0:
    return false;
}
예제 #3
0
void _XMeshObjectManager::IntersectionEventObject(D3DXVECTOR3& vRayPos, D3DXVECTOR3& vRayDir)
{
	if(g_CurrentFocusedObject && g_CurrentFocusedObject != _XDEF_DUMMYID_GAMEBACKGROUND) return;

	D3DXVECTOR3 vLocalRayDir;
	D3DXVec3Normalize(&vLocalRayDir, &vRayDir);

	sldef_XOctreeObject::iterator it;
	for (it = m_slEventObjectList.begin(); it != m_slEventObjectList.end(); ++ it)
	{
		_XOctreeObject* pObject = (*it);

		D3DXVECTOR3 vPosition(pObject->m_matWorldPosition._41, pObject->m_matWorldPosition._42, pObject->m_matWorldPosition._43);

		if (RayAndSphereIntersect(vRayPos, vLocalRayDir, vPosition, pObject->m_Radius) == TRUE)
		{
			FLOAT dx = ( g_LodTerrain.m_3PCamera.m_CameraPosition.x - vPosition.x);
			FLOAT dz = ( g_LodTerrain.m_3PCamera.m_CameraPosition.z - vPosition.z);
			FLOAT _distance = _XFC_sqrt( dx*dx + dz*dz );

			if( _distance < g_LastPickedObjectDistance )
			{
				g_LastPickedObjectDistance = _distance;
				g_LastPickedObjectType = _XPICKINGTARGET_COLLECT;
				g_LastPickedObject = pObject;
			}
		}
	}
}
void __MsgFunc_TerrainMod( const char *pszName, int iSize, void *pbuf )
{
	CTerrainModParams params;

	BEGIN_READ( pbuf, iSize );

	unsigned char type = READ_BYTE();

	params.m_vCenter.x = READ_FLOAT();
	params.m_vCenter.y = READ_FLOAT();
	params.m_vCenter.z = READ_FLOAT();

	params.m_flRadius   = RemapVal( READ_SHORT(), 0, 65535, MIN_TMOD_RADIUS, MAX_TMOD_RADIUS );

	params.m_vecMin.x = READ_FLOAT();
	params.m_vecMin.y = READ_FLOAT();
	params.m_vecMin.z = READ_FLOAT();

	params.m_vecMax.x = READ_FLOAT();
	params.m_vecMax.y = READ_FLOAT();
	params.m_vecMax.z = READ_FLOAT();

	params.m_flStrength = READ_FLOAT();

	params.m_Flags = READ_BYTE();

	if( type == TMod_Suck && (params.m_Flags & CTerrainModParams::TMOD_SUCKTONORMAL) )
	{
		params.m_vNormal.x = READ_FLOAT();
		params.m_vNormal.y = READ_FLOAT();
		params.m_vNormal.z = READ_FLOAT();
	}	

	// Apply the decal first because the place where we're applying the decal 
	// may not be there if we blow it out first!
	Vector vPosition(0,0,0);
	QAngle vAngles(0,0,0);
	int iModel = 0;
	C_BaseEntity *ent = cl_entitylist->GetEnt( iModel );
	if( ent && type == TMod_Sphere )
	{
		effects->DecalShoot( 
			effects->Draw_DecalIndexFromName( "decals/tscorch" ), 
			iModel, 
			ent->GetModel(), 
			vPosition, 
			vAngles, 
			params.m_vCenter, 
			NULL, 
			0 );
	}

	engine->ApplyTerrainMod( (TerrainModType)type, params );
}
예제 #5
0
//--------------------------------------------------------------------------------------
// Render the Fluid
//--------------------------------------------------------------------------------------
void RenderFluid( ID3D11DeviceContext* pd3dImmediateContext )
{
	DirectX::XMMATRIX proj = DirectX::XMMatrixOrthographicOffCenterLH(0, FLUID->Width(), FLUID->Height(), 0, 0, 1);
	proj = DirectX::XMMatrixTranspose(proj);

	D3D11_MAPPED_SUBRESOURCE MappedResource = {};
	pd3dImmediateContext->Map( g_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
	ConstantBuffer* pCB = reinterpret_cast<ConstantBuffer*>(MappedResource.pData);
	DirectX::XMStoreFloat4x4A( &pCB->mViewProjection, proj );
	pCB->fParticleSize = PARTICLE_SIZE;
	pd3dImmediateContext->Unmap( g_pConstantBuffer, 0 );

	pd3dImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
	pd3dImmediateContext->GSSetShader( g_pGeometryShader, NULL, 0 );
	pd3dImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );

	pd3dImmediateContext->GSSetConstantBuffers(0, 1, &g_pConstantBuffer);
	
	pd3dImmediateContext->IASetInputLayout( g_pVertexLayout );
	pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
	
	for (unsigned int i = 0; i < FLUID->Size(); i += FluidVertexBufferSize)
	{
		pd3dImmediateContext->Map(g_pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource);
		ParticleVertex* pVertices = reinterpret_cast<ParticleVertex*>(MappedResource.pData);

		// Render each particle
		unsigned int j = 0;
		for (; j < FluidVertexBufferSize && i + j < FLUID->Size(); j++) {
			float color = (float)(0.5f * FLUID->density[i + j] / FluidRestDensity);
			color = (color > 1.0f) ? 1.0f : color;
			DirectX::XMFLOAT4 vColor(1.0f - color, 1.0f - color, 1.0f, 1.0f);
			DirectX::XMFLOAT2 vPosition(FLUID->pos[i + j].x, FLUID->pos[i + j].y);
			pVertices[j].position = vPosition;
			pVertices[j].color = vColor;
		}

		pd3dImmediateContext->Unmap(g_pVertexBuffer, 0);

		UINT stride = sizeof(ParticleVertex);
		UINT offset = 0;
		pd3dImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);

		pd3dImmediateContext->Draw(j, 0);
	}
}
예제 #6
0
int KRLLocalCharacter::UpdateListener()
{
    int nRetCode = false;
    int nResult = false;
    HRESULT hr = E_FAIL;
    IKG3DSoundShell* pSoundShell = NULL;
    float fFaceYaw = 0.0f;
    D3DXVECTOR3 vFront(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vFrontTop(0.0f, 1.0f, 0.0f);
    D3DXVECTOR3 vPosition(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vVelocity(0.0f, 0.0f, 0.0f);

    pSoundShell = g_pRL->m_pSound;
    KG_PROCESS_SUCCESS(pSoundShell == NULL);

    fFaceYaw = YawLHToRH(m_fFaceYaw);

    m_RLCharacter.GetPosition(vPosition);

    vPosition *= 0.01f;

    hr = pSoundShell->SetListenerPosition(&vPosition, &vVelocity);
    KGLOG_COM_PROCESS_ERROR(hr);

    vFront.x = cosf(fFaceYaw);
    vFront.y = 0.0f;
    vFront.z = sinf(fFaceYaw);

    hr = pSoundShell->SetOrientation(&vFront, &vFrontTop);
    KGLOG_COM_PROCESS_ERROR(hr);

Exit1:
    nResult = true;
Exit0:
    return nResult;
}
예제 #7
0
파일: Game.cpp 프로젝트: foundry/glTemplate
// Render method runs repeatedly in a loop
void Game::Render() 
{
	
	// Clear the buffers and enable depth testing (z-buffering)
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	// Set up a matrix stack
	glutil::MatrixStack modelViewMatrixStack;
	modelViewMatrixStack.SetIdentity();
	modelViewMatrixStack.LookAt(m_pCamera->GetPosition(), m_pCamera->GetView(), m_pCamera->GetUpVector());


	// Use the main shader program 
	CShaderProgram *pMainProgram = (*m_pShaderPrograms)[0];
	pMainProgram->UseProgram();

	// Set light and materials in main shader program
	glm::vec4 vPosition(-100, 100, 50, 1);
	glm::mat3 normalMatrix = m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top());
	glm::vec4 vLightEye = modelViewMatrixStack.Top()*vPosition;
	pMainProgram->SetUniform("light1.position", vLightEye);		// Position of light source in eye coordinates
	pMainProgram->SetUniform("light1.La", glm::vec3(0.15f, 0.15f, 0.15f));
	pMainProgram->SetUniform("light1.Ld", glm::vec3(1.0f, 1.0f, 1.0f));
	pMainProgram->SetUniform("light1.Ls", glm::vec3(1.0f, 1.0f, 1.0f));
	pMainProgram->SetUniform("material1.Ma", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.Md", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.Ms", glm::vec3(0.5f, 0.5f, 0.5f));
	pMainProgram->SetUniform("material1.shininess", 15.0f);
	pMainProgram->SetUniform("bUseTexture", false);
	pMainProgram->SetUniform("sampler0", 0);


	// Render the grid
	modelViewMatrixStack.Push();
		pMainProgram->SetUniform("matrices.projMatrix", m_pCamera->GetPerspectiveProjectionMatrix());
		pMainProgram->SetUniform("matrices.modelViewMatrix", modelViewMatrixStack.Top());
		pMainProgram->SetUniform("matrices.normalMatrix", m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top()));
		m_pGrid->Render();
	modelViewMatrixStack.Pop();

	
	// Switch to the sphere program
	CShaderProgram *pSphereProgram = (*m_pShaderPrograms)[2];
	pSphereProgram->UseProgram();

	// Set light and materials in sphere programme
	pSphereProgram->SetUniform("material1.Ma", glm::vec3(0.0f, 1.0f, 0.0f));
	pSphereProgram->SetUniform("material1.Md", glm::vec3(0.0f, 1.0f, 0.0f));
	pSphereProgram->SetUniform("material1.Ms", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("material1.shininess", 50.0f);
	pSphereProgram->SetUniform("light1.La", glm::vec3(0.15f, 0.15f, 0.15f));
	pSphereProgram->SetUniform("light1.Ld", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("light1.Ls", glm::vec3(1.0f, 1.0f, 1.0f));
	pSphereProgram->SetUniform("light1.position", vLightEye); 

	// Render the sphere
	modelViewMatrixStack.Push();
		modelViewMatrixStack.Translate(glm::vec3(0.0f, 5.0f, 50.0f));
		modelViewMatrixStack.Scale(5.0f);
		pSphereProgram->SetUniform("matrices.projMatrix", m_pCamera->GetPerspectiveProjectionMatrix());
		pSphereProgram->SetUniform("matrices.modelViewMatrix", modelViewMatrixStack.Top());
		pSphereProgram->SetUniform("matrices.normalMatrix", m_pCamera->ComputeNormalMatrix(modelViewMatrixStack.Top()));
		
		pSphereProgram->SetUniform("t",m_elapsedTime);
			
		pSphereProgram->SetUniform("levels",m_levels);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		m_pSphere->Render();
	modelViewMatrixStack.Pop();

#ifdef __WIN32
    void swapBuffers();
#endif
#ifdef __APPLE__
    glSwapAPPLE();
#endif

}
예제 #8
0
    void	MapOptionsMenu::draw()
    {
      Vector3f      vPosition(65.0, 15.0, 0);
      Vector3f      vPositionArrow(57.0, 15.0, 0);

      if (this->_menu)
      	this->_menu->affAllOnglet();

      int       f = this->_width / 100;
      int       s = (this->_width / 10) % 10;
      int	l = this->_width % 10;

      this->_nb[f]->getImage()->setPosition(vPosition);
      this->_nb[f]->affOnglet();
      vPosition.setX(70);
      this->_nb[s]->getImage()->setPosition(vPosition);
      this->_nb[s]->affOnglet();
      vPosition.setX(75);
      this->_nb[l]->getImage()->setPosition(vPosition);
      this->_nb[l]->affOnglet();

      if (this->_cursor == 0)
      	{
      	  if (this->_width > MIN_SIZE)
      	    {
      	      this->_arrow[0]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[0]->affOnglet();
      	    }
      	  if (this->_width < MAX_SIZE)
      	    {
      	      vPositionArrow.setX(84);
      	      this->_arrow[1]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[1]->affOnglet();
      	    }
      	}

      vPosition.setX(65.0);
      vPosition.setY(28.0);
      vPositionArrow.setX(57.0);
      vPositionArrow.setY(28.0);

      f = this->_height / 100;
      s = (this->_height / 10) % 10;
      l = this->_height % 10;

      this->_nb[f]->getImage()->setPosition(vPosition);
      this->_nb[f]->affOnglet();
      vPosition.setX(70);
      this->_nb[s]->getImage()->setPosition(vPosition);
      this->_nb[s]->affOnglet();
      vPosition.setX(75);
      this->_nb[l]->getImage()->setPosition(vPosition);
      this->_nb[l]->affOnglet();

      if (this->_cursor == 1)
      	{
      	  if (this->_height > MIN_SIZE)
      	    {
      	      this->_arrow[0]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[0]->affOnglet();
      	    }
      	  if (this->_height < MAX_SIZE)
      	    {
      	      vPositionArrow.setX(84);
      	      this->_arrow[1]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[1]->affOnglet();
      	    }
      	}



      vPosition.setX(68.0);
      vPosition.setY(40.0);
      vPositionArrow.setX(60.0);
      vPositionArrow.setY(40.0);

      f = this->_buffDensity / 10;
      s = this->_buffDensity % 10;

      this->_nb[f]->getImage()->setPosition(vPosition);
      this->_nb[f]->affOnglet();
      vPosition.setX(73);
      this->_nb[s]->getImage()->setPosition(vPosition);
      this->_nb[s]->affOnglet();

      if (this->_cursor == 2)
      	{
      	  if (this->_buffDensity > BUFFMIN)
      	    {
      	      this->_arrow[0]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[0]->affOnglet();
      	    }
      	  if (this->_buffDensity < BUFFMAX)
      	    {
      	      vPositionArrow.setX(82);
      	      this->_arrow[1]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[1]->affOnglet();
      	    }
      	}


      vPosition.setX(68.0);
      vPosition.setY(60.0);
      vPositionArrow.setX(60.0);
      vPositionArrow.setY(60.0);

      f = this->_wallDensity / 10;
      s = this->_wallDensity % 10;

      this->_nb[f]->getImage()->setPosition(vPosition);
      this->_nb[f]->affOnglet();
      vPosition.setX(73);
      this->_nb[s]->getImage()->setPosition(vPosition);
      this->_nb[s]->affOnglet();

      if (this->_cursor == 3)
      	{
      	  if (this->_wallDensity > BUFFMIN)
      	    {
      	      this->_arrow[0]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[0]->affOnglet();
      	    }
      	  if (this->_wallDensity < BUFFMAX)
      	    {
      	      vPositionArrow.setX(82);
      	      this->_arrow[1]->getImage()->setPosition(vPositionArrow);
      	      this->_arrow[1]->affOnglet();
      	    }
      	}
    }
예제 #9
0
// load a file if we recognize the type.
DWORD CXMLWorldLoader::OnLoadWorldFile(DWORD size, void *params)
{
	CHashString oldVersion = _T("");
	CREATEOBJECTPARAMS cop;
	INITOBJECTPARAMS iop;
	SERIALIZEOBJECTPARAMS sop;
	DWORD retVal;
	IXMLArchive *Archive = NULL;
	DWORD currNode = 0;
	LOADINGUPDATEPARAMS pbp;

	VERIFY_MESSAGE_SIZE(size, sizeof(TCHAR *));
	TCHAR *pFileName = (TCHAR *)params;

	// use both a hashstring and a pointer so that the first iteration of the loop
	// will pass SetParentName a NULL instead of an address of a hashstring
	// hashed to ""
	CHashString hszParentType(_T("CWorld"));
	CHashString hszParentName(_T("World"));
	CHashString hszName(_T(""));
	CHashString hszTypeName(_T(""));
	CHashString streamType(_T("File"));

	// delete previous world root
	DELETEOBJECTPARAMS dop;
	dop.name = &hszParentName;
	static DWORD msgHash_DeleteObject = CHashString(_T("DeleteObject")).GetUniqueID();
	EngineGetToolBox()->SendMessage(msgHash_DeleteObject, sizeof(dop), &dop );
	// delete is ok to fail if no world has been created yet

	// create new world root
	cop.name = &hszParentName;
	cop.parentName = NULL;
	cop.typeName = &hszParentType;
	static DWORD msgHash_CreateObject = CHashString(_T("CreateObject")).GetUniqueID();
	DWORD returnValue = EngineGetToolBox()->SendMessage(msgHash_CreateObject, sizeof(cop), &cop );
	if (returnValue != MSG_HANDLED)
	{
		EngineGetToolBox()->Log(LOGERROR, _T("Failed to create World Root Object\n"));
		return MSG_ERROR;
	}

	CREATEARCHIVE ca;
	ca.streamData = (void *)pFileName;
	ca.mode = STREAM_MODE_READ;
	ca.streamType = &streamType;
#ifdef USEXMLFILESTREAMS
	// call the Archive factory to create an XML archive
	static DWORD msgHash_CreateXMLArchiveStream = CHashString(_T("CreateXMLArchiveStream")).GetUniqueID();
	if (retVal = m_ToolBox->SendMessage(msgHash_CreateXMLArchiveStream, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED)
#else
	// call the Archive factory to create an XML archive
	static DWORD msgHash_CreateXMLArchive = CHashString(_T("CreateXMLArchive")).GetUniqueID();
	if (retVal = m_ToolBox->SendMessage(msgHash_CreateXMLArchive, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED)
#endif
	{
		return retVal;
	}

	Archive = dynamic_cast<IXMLArchive *>(ca.archive);
	DWORD numNodes = Archive->GetNumberOfNodes();

	// Deteriminte World Version
	int iWorldNumAttrib = Archive->GetNumAttributes();

	StdString szNodeName;
	Archive->GetNode(szNodeName);
	
	pbp.currentPosition = Archive->GetCurrentNodePosition();
	pbp.totalSize = numNodes;
	// update progress bar
	static DWORD msgHash_LoadingUpdate = CHashString(_T("LoadingUpdate")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_LoadingUpdate, sizeof(LOADINGUPDATEPARAMS), &pbp);


	// must start with <World>
	if (szNodeName != _T("CWorld"))
	{
		EngineGetToolBox()->SetErrorValue(WARN_INVALID_FILE);
		EngineGetToolBox()->Log(LOGWARNING, _T("Invalid world file %s\n"), pFileName);
		Archive->Close();
		return MSG_ERROR;
	}

	// Version 1.0
	if( iWorldNumAttrib == 1 )
	{
		// read the name of the world
		StdString szName;
		Archive->Read( szName, _T("Name") );
		m_WorldFileVersion = 1.0f;
		static DWORD msgHash_GetFileVersion = CHashString(_T("GetFileVersion")).GetUniqueID();
		DWORD retval = m_ToolBox->SendMessage(msgHash_GetFileVersion, sizeof(IHashString), &oldVersion);
		if (retval != MSG_HANDLED)
		{
			m_ToolBox->Log(LOGERROR, _T("Could not get world version!"));
			return MSG_ERROR;
		}
		CHashString hszNewVersion = _T("1.0");
		static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
		retval = m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &hszNewVersion);
		if (retval != MSG_HANDLED)
		{
			m_ToolBox->Log(LOGERROR, _T("Could not set world version!"));
			return MSG_ERROR;
		}
	}
	// Version 1.5
	else if( iWorldNumAttrib == 2 )
	{
		StdString szName;
		Archive->Read( szName, _T("Name") );
		float fileVersion = 0;
		Archive->Read( m_WorldFileVersion, _T("Version") );
		static DWORD msgHash_GetFileVersion = CHashString(_T("GetFileVersion")).GetUniqueID();
		DWORD retval = m_ToolBox->SendMessage(msgHash_GetFileVersion, sizeof(IHashString), &oldVersion);
		if (retval != MSG_HANDLED)
		{
			m_ToolBox->Log(LOGERROR, _T("Could not get world version!"));
			return MSG_ERROR;
		}
		TCHAR buf[50];
		_stprintf(buf, "%.1f", m_WorldFileVersion);
		CHashString hszNewVersion(buf);
		static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
		retval = m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &hszNewVersion);
		if (retval != MSG_HANDLED)
		{
			m_ToolBox->Log(LOGERROR, _T("Could not set world version!"));
			return MSG_ERROR;
		}
	}
	// Unknown Version
	else
	{
		EngineGetToolBox()->SetErrorValue(WARN_INVALID_FILE);
		EngineGetToolBox()->Log(LOGWARNING, _T("Invalid world file %s\n"), pFileName);
		Archive->Close();
		static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
		return MSG_ERROR;
	}

	// failure checks
	bool componentFailed = false;
	int failedDepth = 0;

	float secondsPerFrame = 1 / m_fLoadingUpdateFPS;
	ITimer *timer = EngineGetToolBox()->GetTimer();
	float lastLoadTime = timer->GetRealTime();
	float elapsedTime = 0.0f;

	while (Archive->GetNode(szNodeName))
	{
		int currDepth = Archive->GetDepth();
		if (componentFailed == true)
		{
			// current node is child of failed
			if (currDepth > failedDepth)
			{
				continue;
			}
			// if sibling or uncle, reset comp failed flag
			else
			{
				componentFailed = false;
			}
		}

		hszTypeName.Init( szNodeName.c_str() );

		StdString parentName;
		StdString parentType;
		StdString childType;
		Archive->GotoParentNode( parentType );
		Archive->Read( parentName, _T("Name") );
		if ( parentName != _T("") )
		{
			hszParentName = parentName;
		}
		Archive->ReturnToChildNode( childType );
		if( hszTypeName.GetString() != childType )
		{
			assert( hszTypeName.GetString() == childType );
			static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
			m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
			return MSG_ERROR;
		}
		//parentName = Archive->GetParentName();

		StdString szName;
		Archive->Read( szName, _T("Name") );
		hszName.Init( szName.c_str() );

		cop.parentName = &hszParentName;
		cop.typeName = &hszTypeName;
		cop.name = &hszName;
		static DWORD msgHash_CreateObject = CHashString(_T("CreateObject")).GetUniqueID();
		DWORD retval = m_ToolBox->SendMessage(msgHash_CreateObject, sizeof(CREATEOBJECTPARAMS), &cop, NULL, NULL);

		if (retval != MSG_HANDLED)
		{
			m_ToolBox->Log(LOGINFORMATION, _T("World loader: could not create component; skipping children!\n"));
			componentFailed = true;
			failedDepth = Archive->GetDepth();			
			continue;
		}

		// 1.0 -> 1.5 Readjusted scale and position on object by 1000/898
		if( m_WorldFileVersion == 1.0 )
		{
			float fConvert = 1000.0f/898.0f;
			if( hszTypeName.GetUniqueID() == CHashString(_T("CV3ORenderObject")).GetUniqueID() )
			{
				StdString szFileName;
				Vec3 vPosition(0,0,0);
				Vec3 vRotation(0,0,0);
				Vec3 vScaling(0,0,0);

				Archive->Read( szFileName, _T("FileName") );
				
				Archive->Read( vPosition, _T("Position") );
				vPosition.x = ( vPosition.x * fConvert );
				vPosition.y = ( vPosition.y * fConvert );
				vPosition.z = ( vPosition.z * fConvert );
				
				Archive->Read( vRotation, _T("Rotation") );

				Archive->Read( vScaling, _T("Scaling") );
				vScaling.x = ( vScaling.x * fConvert );
				vScaling.y = ( vScaling.y * fConvert );
				vScaling.z = ( vScaling.z * fConvert );

				IArchive *MemArchive;
				CHashString memType(_T("Memory"));

				CREATEARCHIVE caOut;
				caOut.mode = STREAM_MODE_WRITE;
				caOut.streamData = NULL;
				caOut.streamSize = 0;
				caOut.streamType = &memType;
				static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caOut) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive = caOut.archive;

				MemArchive->Write( szFileName, _T("FileName") );
				MemArchive->Write( vPosition, _T("Position") );
				MemArchive->Write( vRotation, _T("Rotation") );
				MemArchive->Write( vScaling, _T("Scaling") );
		
				CREATESTREAM cs;
				cs.streamData = caOut.streamData;
				cs.streamSize = caOut.streamSize;
				cs.mode = STREAM_MODE_READ;
				static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &cs) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive->Init(cs.openStream);

				sop.name = &hszName;
				sop.archive = MemArchive;
				static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
				m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);
				
				MemArchive->Close();
			}

			else if( hszTypeName.GetUniqueID() == CHashString(_T("CPhysicsObject")).GetUniqueID() )
			{
				//StdString szDynamics;
				StdString szType;
				StdString szShapeFileName;
				//float fMass;
				//Vec3 vPosition;
				//Vec3 vRotation;
				//Vec3 vScaling;

				//Archive->Read( vPosition, _T("pos") );
				//vPosition.SetX( vPosition.GetX() * fConvert );
				//vPosition.SetY( vPosition.GetY() * fConvert );
				//vPosition.SetZ( vPosition.GetZ() * fConvert );

				//Archive->Read( vRotation, _T("rot") );
				
				//Archive->Read( vScaling, _T("scale") );
				//vScaling.SetX( vScaling.GetX() * fConvert );
				//vScaling.SetY( vScaling.GetY() * fConvert );
				//vScaling.SetZ( vScaling.GetZ() * fConvert );

				//Archive->Read( fMass, _T("mass") );
				Archive->Read( szType, _T("Type") );
				Archive->Read( szShapeFileName, _T("filename") );

				IArchive *MemArchive;
				CHashString memType(_T("Memory"));
				//int size =	sizeof(char) * 256 * 2 + sizeof(float) + sizeof(Vec3) * 3 + 256;
				
				CREATEARCHIVE caOut;
				caOut.mode = STREAM_MODE_WRITE;
				caOut.streamData = NULL;
				caOut.streamSize = 0;
				caOut.streamType = &memType;
				static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caOut) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive = caOut.archive;

				//MemArchive->Write( vPosition, _T("pos") );
				//MemArchive->Write( vRotation, _T("rot") );
				//MemArchive->Write( vScaling, _T("scale") );
				//MemArchive->Write( fMass, _T("mass") );
				//MemArchive->Write( szDynamics, _T("dynamics") );
				//MemArchive->Write( szShapeFileName, _T("shapeFile") );
				MemArchive->Write( szType, _T("Type") );
				MemArchive->Write( szShapeFileName, _T("filename") );

				CREATESTREAM cs;
				cs.streamData = caOut.streamData;
				cs.streamSize = caOut.streamSize;
				cs.mode = STREAM_MODE_READ;
				static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &cs) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive->Init(cs.openStream);

				sop.name = &hszName;
				sop.archive = MemArchive;
				static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
				m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);

				MemArchive->Close();
			}
			else if( hszTypeName.GetUniqueID() == CHashString(_T("CTerrainConfig")).GetUniqueID() )
			{
				StdString szTerShaderLib;
				StdString szTerShaderEff;
				int iSectorRes;
				float fSectorSize;
				float fZScale;
				float fLODDistance;

				Archive->Read( szTerShaderLib, _T("TerrainShaderLibrary") );
				Archive->Read( szTerShaderEff, _T("TerrainShaderEffect") );
				Archive->Read( iSectorRes, _T("SectorResolution") );
				Archive->Read( fSectorSize, _T("SectorSize") );
				fSectorSize = fSectorSize * fConvert;
				Archive->Read( fZScale, _T("ZScale") );
				fZScale = fZScale * fConvert;
				Archive->Read( fLODDistance, _T("LODDistance") );
				
				IArchive *MemArchive;
				CHashString memType(_T("Memory"));
				
				CREATEARCHIVE caOut;
				caOut.mode = STREAM_MODE_WRITE;
				caOut.streamData = NULL;
				caOut.streamSize = 0;
				caOut.streamType = &memType;
				static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caOut) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive = caOut.archive;

				MemArchive->Write( szTerShaderLib, _T("TerrainShaderLibrary") );
				MemArchive->Write( szTerShaderEff, _T("TerrainShaderEffect") );
				MemArchive->Write( iSectorRes, _T("SectorResolution") );
				MemArchive->Write( fSectorSize, _T("SectorSize") );
				MemArchive->Write( fZScale, _T("ZScale") );
				MemArchive->Write( fLODDistance, _T("LODDistance") );

				CREATESTREAM cs;
				cs.streamData = caOut.streamData;
				cs.streamSize = caOut.streamSize;
				cs.mode = STREAM_MODE_READ;
				static DWORD msgHash_CreateStream_Memory = CHashString(_T("CreateStream_Memory")).GetUniqueID();
				if (m_ToolBox->SendMessage(msgHash_CreateStream_Memory, sizeof(CREATESTREAM), &cs) != MSG_HANDLED)
				{
					static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
					m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);
					return true;
				}
				MemArchive->Init(cs.openStream);

				sop.name = &hszName;
				sop.archive = MemArchive;
				static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
				m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);

				MemArchive->Close();
			}
			else
			{
				sop.name = &hszName;
				sop.archive = Archive;
				static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
				m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);
			}
		}
		else
		{
			sop.name = &hszName;
			sop.archive = Archive;
			static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
			m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);
		}

		iop.name = &hszName;
		static DWORD msgHash_InitObject = CHashString(_T("InitObject")).GetUniqueID();
		m_ToolBox->SendMessage(msgHash_InitObject, sizeof(INITOBJECTPARAMS), &iop, NULL, NULL);

		elapsedTime += timer->GetRealTime() - lastLoadTime;
		lastLoadTime = timer->GetRealTime();				
		if (elapsedTime > secondsPerFrame)
		{
			elapsedTime = 0.0f;
			pbp.currentPosition = Archive->GetCurrentNodePosition();
			pbp.totalSize = numNodes;
			m_ToolBox->SendMessage(msgHash_LoadingUpdate, sizeof(LOADINGUPDATEPARAMS), &pbp);
		}
	}

	pbp.currentPosition = 0;
	pbp.totalSize = 0;
	m_ToolBox->SendMessage(msgHash_LoadingUpdate, sizeof(LOADINGUPDATEPARAMS), &pbp);

	Archive->Close();

	static DWORD msgHash_SetFileVersion = CHashString(_T("SetFileVersion")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_SetFileVersion, sizeof(IHashString), &oldVersion);

	return MSG_HANDLED_STOP;
}
예제 #10
0
void NounShip::destroyShip( Noun * pKiller, bool bZeroVelocity )
{
	// make sure the damage is enough
	m_Damage = maxDamage();
	// clear the current order & command, so if they respawn the ship doesn't try to keep doing it's last command
	setCommand( NOCOMMAND, NULL );
	setOrder( NOORDER, NULL, NULL );

	// inform the context user first
	if ( pKiller != this )
	{
		gameContext()->gameUser()->onDestroyed( this, pKiller );
		if ( pKiller != NULL )
			gameContext()->gameUser()->onKill( pKiller, this );
	}
	else 
		gameContext()->gameUser()->onSelfDestruct( this );

	if ( WidgetCast<NounPlanet>( pKiller ) )
		gameContext()->gameUser()->onCollidePlanet( this );

	// create the primary explosion
	if ( context()->isClient() )
	{
		Scene * pScene = destroyEffect();
		if ( pScene != NULL )
		{
			// TODO: no need to add this explosion of this player is nowhere near the explosion
			// ship destroyed, create the explosion effect
			SceneryDebris * pEffect = new SceneryDebris;
			pEffect->setNounContext( new NounContext( pScene ) );
			pEffect->setContext( context() );
			pEffect->setPosition( worldPosition() );
			pEffect->setDelay( 0.0f );
			pEffect->setFrame( frame() );

			if (! bZeroVelocity )
				pEffect->setVelocity( Vector3( sin( m_fHeading ) * m_fVelocity, 0.0f, cos( m_fHeading) * m_fVelocity ) );
			if (! pEffect->setSegment( "Effect" ) )
				pEffect->setLife( 15.0f );

			context()->attachNoun( pEffect );
		}

		NounTrail::CopyTrailsIntoZone( this );
	}

	// list of destroyed items to remove from ship..
	std::list< Noun * > destroyed;

	// damage enhancements, once they reach their maxDamage() they are destroyed..
	for(int i=0;i<childCount();++i)
	{
		NounEnhancement * pEnh = WidgetCast<NounEnhancement>( child(i) );
		if ( pEnh != NULL )
		{
			if ( pEnh->incrementDamage() )
			{
				LOG_STATUS( "NounShip", "[ENHANCEMENT]:Destroyed:%s:%s:%u", pEnh->getName(), name(), userId() );
				message( CharString().format( "<color;ffffff>Comms: Enhancement '%s' destroyed!", pEnh->getName() ) );
				destroyed.push_back( pEnh );
			}
			continue;
		}

		// remove any beacons on death..
		NounBeacon * pBeacon = WidgetCast<NounBeacon>( child(i) );
		if ( pBeacon != NULL )
		{
			destroyed.push_back( pBeacon );
			continue;
		}
	}

	// server-side only logic
	if ( isServer() )
	{
		// check for area damage
		Array< GameContext::NounCollision > collide;
		if ( context()->proximityCheck( worldPosition(), explodeArea(), collide ) )
		{
			for(int i=0;i<collide.size();i++)
			{
				NounGame * pCollide = WidgetCast<NounGame>( collide[i].pNoun );
				if ( !pCollide || pCollide == this )
					continue;

				if ( pCollide->canDamage( DAMAGE_ENERGY | DAMAGE_KINETIC ) &&
					collide[i].fDistance < explodeArea() )
				{
					float damageRatio = 1.0f - (collide[i].fDistance / explodeArea());
					int damage = damageRatio * explodeDamage();
					
					if ( damage > 0 )
					{
						pCollide->inflictDamage( tick(), this, damage, DAMAGE_ENERGY | DAMAGE_KINETIC, 
							pCollide->worldFrame() * (worldPosition() - pCollide->worldPosition()) );
					}
				}
			}
		}

		// drop enhancements after we do area damage, otherwise we'll destroy the dropped loot..
		dropLoot();

		// space-monsters do not leave behind devices
		if ( ! isMonster() )
		{
			// eject some of the resources used to build the ship into space
			int nAmount = DESTROYED_SHIP_RESOURCE * buildCost( this );
			while( nAmount > 0 )
			{
				CargoResource::Ref pCargo = new CargoResource( nAmount );
				nAmount -= pCargo->quantity();

				Vector3 vPosition( worldPosition() + RandomVector( -radius(), radius() ) );
				vPosition.y = 0.0f;

				pCargo->setPosition( vPosition );
				context()->attachNoun( pCargo );
			}

			//// check for any cargo items...  if found put them into space
			//for(int i=0;i<childCount();i++)
			//{
			//	BaseNode * pChild = child(i);
		
			//	NounCargo::Ref pCargo;
			//	if ( WidgetCast<NounCargo>( pChild ) )
			//	{
			//		int roll = rand() % 100;
			//		if ( roll < ((NounCargo *)pChild)->durability() )
			//			pCargo = (NounCargo *)pChild->copy();
			//	}

			//	if ( pCargo.valid() )
			//	{
			//		Vector3 vPosition( worldPosition() + RandomVector( -5.0f, 5.0f ) );
			//		vPosition.y = 0.0f;

			//		pCargo->setPosition( vPosition );
			//		context()->attachNoun( pCargo );
			//	}
			//}
		}

		// last before detach so that players dont dupe thier enhancements
		// that were dropped
		// save off storage with this "active" ship
		if(userId() != 0)
			context()->user()->saveStorage(this);

	}

	// remove desrtroyed items from ship..
	while( destroyed.size() > 0 )
	{
		Noun * pDestroyed = destroyed.front();
		destroyed.pop_front();

		if ( pDestroyed )
			pDestroyed->detachSelf();
	}

	// lastly, detach the ship from the universe
	setDetach();
}
예제 #11
0
int KCircleMissileProcessor::Update(double fTime, double fTimeLast, KRLMissile* pRLMissile)
{
	HRESULT hr = E_FAIL;
	int nRetCode = false;
	int nSFXModelCount = 0;
	double fTimeDelta = 0.0f;
	double fTimeTotal = 0.0f;
    KMissilePhaseCircleModel* pCircleModel = NULL;

	ASSERT(m_pRLMissile);
	ASSERT(m_pMissilePhaseModel);

    pCircleModel = (KMissilePhaseCircleModel*)m_pMissilePhaseModel;
	nSFXModelCount = GetSFXModelCount();

	fTimeTotal = GetTimeTotal();

	fTimeDelta = fTime - GetTimeStart();
	if (fTimeDelta <= fTimeTotal)
	{
		nRetCode = abs(fTimeTotal) > FLT_EPSILON;
		KGLOG_PROCESS_ERROR(nRetCode);

		for (int nSFXModel = 0; nSFXModel < nSFXModelCount; ++nSFXModel)
		{
            float fDistance = 0.0f;
            float fDistanceReciprocal = 1.0f;
            float fMovementDelta = 0.0f;
            float fModelScale = 0.0f;
            float fAccelerationPercent = 0.0f;

			D3DXVECTOR3 vPosition(0.0f, 0.0f, 0.0f);
            D3DXVECTOR3 vLocalPosition(0.0f, 0.0f, 0.0f);
			D3DXQUATERNION qRotationLH;
            
            KCircleMissile& Missile = m_aCircleMissile[nSFXModel];
			KCircleMissileParam& BeginParam = Missile.BeginParam;
			KCircleMissileParam& EndParam = Missile.EndParam;
			KCircleMissileParam	CurrentParam;
			KCircleMissileParam	TotalParam;

            hr = OnAccelerationPercent(pCircleModel->nAcceleration, static_cast<float>(fTimeDelta), static_cast<float>(fTimeTotal), fAccelerationPercent);
            KGLOG_COM_PROCESS_ERROR(hr);

            hr = OnMovementTypeCorrect(pCircleModel->nMovementType, static_cast<float>(fAccelerationPercent), m_fTotalDistance, m_fParabolaAngle, fMovementDelta);;
            KGLOG_COM_PROCESS_ERROR(hr);

            hr = OnMovementOneSelf(m_fMeteorSpeed, m_fMeteorRadius, static_cast<float>(fTimeDelta), vLocalPosition);
            KGLOG_COM_PROCESS_ERROR(hr);

            fModelScale = static_cast<float>(m_fTotalModelScale * (fAccelerationPercent) + pCircleModel->fModelScaleBegin);

            TotalParam.fCircleRadius = EndParam.fCircleRadius - BeginParam.fCircleRadius;
            TotalParam.fFOV = EndParam.fFOV - BeginParam.fFOV;
            TotalParam.fFOVAngleVelocity = EndParam.fFOVAngleVelocity - BeginParam.fFOVAngleVelocity;
            TotalParam.fTerrainOffset = EndParam.fTerrainOffset - BeginParam.fTerrainOffset;
            TotalParam.fLineHeight = EndParam.fLineHeight - BeginParam.fLineHeight;

            CurrentParam.fCircleRadius = static_cast<float>(BeginParam.fCircleRadius + TotalParam.fCircleRadius * fAccelerationPercent);
            CurrentParam.fLineHeight = static_cast<float>(BeginParam.fLineHeight + TotalParam.fLineHeight * fAccelerationPercent);
            CurrentParam.fTerrainOffset = static_cast<float>(BeginParam.fTerrainOffset + TotalParam.fTerrainOffset * fAccelerationPercent);
            CurrentParam.fFOVAngleVelocity = static_cast<float>(BeginParam.fFOVAngleVelocity + TotalParam.fFOVAngleVelocity * fAccelerationPercent);

			if (abs(CurrentParam.fFOVAngleVelocity) <= FLT_EPSILON)
			{
				CurrentParam.fFOV = static_cast<float>(BeginParam.fFOV + TotalParam.fFOV * fAccelerationPercent);
			}
			else
			{
				BeginParam.fFOV += CurrentParam.fFOVAngleVelocity;
				CurrentParam.fFOV = BeginParam.fFOV;
			}

            if (pCircleModel->nMissileDirection == MISSILE_DIRECTION_HORIZONTAL)
            {
                vPosition.x = CurrentParam.fCircleRadius * cosf(CurrentParam.fFOV);
                vPosition.z = CurrentParam.fCircleRadius * sinf(CurrentParam.fFOV) + CurrentParam.fLineHeight + vLocalPosition.z;
                vPosition.y = CurrentParam.fTerrainOffset + vLocalPosition.y;

                fDistance = sqrtf(vPosition.x * vPosition.x + vPosition.z * vPosition.z);

                if (abs(fDistance) > FLT_EPSILON)
                    fDistanceReciprocal = 1.0f / fDistance;

                vPosition.x *= (fMovementDelta + fDistance) * fDistanceReciprocal;
                vPosition.z *= (fMovementDelta + fDistance) * fDistanceReciprocal;
            }
            else
            {
                vPosition.x = CurrentParam.fCircleRadius * cosf(CurrentParam.fFOV) + vLocalPosition.y;
                vPosition.z = CurrentParam.fLineHeight + vLocalPosition.z;
                vPosition.y = CurrentParam.fCircleRadius * sinf(CurrentParam.fFOV) + CurrentParam.fTerrainOffset;

                fDistance = sqrtf(vPosition.x * vPosition.x + vPosition.y * vPosition.y);

                if (abs(fDistance) > FLT_EPSILON)
                    fDistanceReciprocal = 1.0f / fDistance;

                vPosition.x *= (fMovementDelta + fDistance) * fDistanceReciprocal;
                vPosition.y *= (fMovementDelta + fDistance) * fDistanceReciprocal;
            }			

			YawToQuatLH(qRotationLH, CurrentParam.fFOV);

            for (int nModelType = 0; nModelType != MISSILE_PHASE_SFX_TYPE_COUNT; ++nModelType)
            {
                hr = SetSFXModelOrientation(nModelType, nSFXModel, fModelScale, vLocalPosition, vPosition, qRotationLH);
                KGLOG_COM_PROCESS_ERROR(hr);
            }
            Missile.vPosition = vLocalPosition;
		}
	}

	return true;
Exit0:
	return false;
}
예제 #12
0
파일: appbase.cpp 프로젝트: newobj/taz
void CAppBase::Render()
{
//	SDL_SysWMinfo wmi = { 0 };
//	SDL_GetWMInfo(&wmi);
//	SetWindowPos(wmi.window, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOREPOSITION |SWP_NOSIZE);

	CCamera Camera;
	Camera.SetViewportDims(CVec2i(GetVideo()->GetWidth(), GetVideo()->GetHeight()));
	GetRender()->SetCamera(&Camera);
	
	CVec3f vDirection;
	vDirection.Point(g_fAzimuth, g_fElevation);
	Camera.SetDirection(-vDirection);
	
	CVec3f vPosition(0,0,0);
	vDirection *= g_fZoom;
	Camera.SetPosition(vPosition+vDirection+CVec3f(160,0,160));
//	Camera.SetFOV(60.0f);
//	Camera.SetAspectRatio(4.0f/3.0f);
	static ITube* s_pTube = NULL;
	if ( !s_pTube )
	{
		s_pTube = ITube::Create();
		s_pTube->SetShader("shaders/tube.shader");
		CVec3f vPoint(0,0,0);
		for ( int i = 0 ; i < 100 ; ++i )
		{
			s_pTube->AddControlPoint(CVec3f(160+20.0f*sin(float(i)/10.0f), i, (160+20.0f*cos(float(i)/10.0f))));
		}
	}

	GetRender()->BeginProjection(eProjectionPerspective);
	{
		GetRender()->BeginRenderPass(eRenderPassAccum);
		{
			GetScene()->Render3d();
			GetRender()->RenderTube(s_pTube);
		}
		GetRender()->EndRenderPass(eRenderPassAccum);

		GetRender()->BeginRenderPass(eRenderPassNormal);
		{
			GetScene()->Render3d();
			GetRender()->RenderTube(s_pTube);

			static bool once = true;
			static CVec3f vSrc;
			static CVec3f vDest;
//				if ( once )
			{
				vSrc = GetRender()->Unproject(NULL, g_vMousePos, 10.0f);
				vDest = GetRender()->Unproject(NULL, g_vMousePos, 10000.0f);
				once=false;
			}

			CVec3f vDir = vDest-vSrc; vDir.Normalize();
			IObject* pObject = NULL;
			if ( pObject = GetScene()->PickObject(vSrc, vDir) )
			{
				Debug("Picked %s", pObject->GetClass()->GetClassDef()->GetName().c_str());
			}

			CPlane3f plane(CVec3f(0,1,0), 0.0f);
			if ( plane.IntersectRay(CRay3f(vSrc, vDir), &g_vCursor3d) )
			{
//				Debug("x,y,z = %f,%f,%f", g_vCursor3d.x, g_vCursor3d.y, g_vCursor3d.z);
			}
			else
			{
//				Debug("...");
			}

//				GetRender()->RenderLine(CVec3f(160,0,160), vDest, CRGBA(255,255,0,255));
//				GetRender()->RenderLine(CVec3f(0,0,0), vDest, CRGBA(0,255,0,255));
//				GetRender()->RenderModelSkinned(&s_ModelSkinned);
		}
		GetRender()->EndRenderPass(eRenderPassNormal);
	}
	GetRender()->EndProjection(eProjectionPerspective);
	GetRender()->BeginProjection(eProjectionOrtho);
	{
		GetUi()->Render();
	}
	GetRender()->EndProjection(eProjectionOrtho);

	GetRender()->SetCamera(NULL);

	GetRender()->Swap();
}