当前位置: 首页>>代码示例>>C++>>正文


C++ D3DXVec3Normalize函数代码示例

本文整理汇总了C++中D3DXVec3Normalize函数的典型用法代码示例。如果您正苦于以下问题:C++ D3DXVec3Normalize函数的具体用法?C++ D3DXVec3Normalize怎么用?C++ D3DXVec3Normalize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了D3DXVec3Normalize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnD3D10CreateDevice

//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice(ID3D10Device* pDev10, const DXGI_SURFACE_DESC *pBackBufferSurfaceDesc, void* pUserContext)
{
	HRESULT hr;

	g_pSkyBox    = new S3UTSkybox();
	//g_pEnvMap    = new HDRCubeTexture;

    V_RETURN(DXUTSetMediaSearchPath(L"..\\Source\\SoftShadows"));
    V_RETURN(g_DialogResourceManager.OnD3D10CreateDevice(pDev10));
    V_RETURN(g_D3DSettingsDlg.OnD3D10CreateDevice(pDev10));
    V_RETURN(D3DX10CreateFont(pDev10, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &g_pFont10));

    g_SampleUI.GetSlider(IDC_LIGHT_SIZE)->SetValue((int)(g_fFilterSize * 200.0));
	g_SampleUI.GetComboBox(IDC_SHADOW_ALGORITHM)->SetSelectedByIndex(ssmap.bAccurateShadow == true ? 0 : 1);

    switch( ShadowAlgorithm )
    {
    case    STANDARD_BP:
        	g_ABP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    BP_MSSM_KERNEL:
	        g_BPMSSMKernel.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    STD_VSM:
	        g_StdVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    MIP_VSM:
	        g_MipVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    HIR_BP:
        	g_HBP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    BP_GI:
        	g_BPGI.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    case    STD_PCSS:
        	g_PCSS.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
            break;
    default:
            break;
    }

	g_NoShadow.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
	g_Final.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
	g_GBuffer.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);
	g_ScrQuadRender.OnD3D10CreateDevice(g_ABP.m_pEffect,pDev10,pBackBufferSurfaceDesc,pUserContext);
	ssmap.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext);

	g_Widget.OnD3D10CreateDevice( pDev10,pBackBufferSurfaceDesc,pUserContext );
	g_Blender.OnD3D10CreateDevice( pDev10,pBackBufferSurfaceDesc,pUserContext );

    V_RETURN(D3DX10CreateSprite(pDev10, 512, &g_pSprite10));
	{//must be after g_ABP create a device,because they uses the members of g_ABP
		static const D3D10_INPUT_ELEMENT_DESC scenemeshlayout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
		};
		if (g_MeshLight.Create(pDev10, L"arrow.x", (D3D10_INPUT_ELEMENT_DESC*)scenemeshlayout, 3) != S_OK)
		{
			MessageBox(DXUTGetHWND(), L"Could not load geometry from arrow.x", L"Error", MB_OK);
			exit(0);
		}
		D3D10_PASS_DESC PassDesc;
		V_RETURN(g_NoShadow.m_pEffect->GetTechniqueByName("RenderAcc")->GetPassByIndex(0)->GetDesc(&PassDesc));
		V_RETURN(pDev10->CreateInputLayout(scenemeshlayout, 3, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pMaxLayout));
	}

    LoadNewModel();

	//V_RETURN( DXUTFindDXSDKMediaFileCch( g_EnvMapFilePath, MAX_PATH_STR, g_DefaultEnvMapName[0] ) );
    //g_pEnvMap->OnCreateDevice(pDev10, g_EnvMapFilePath, DXGI_FORMAT_R8G8B8A8_UNORM);
	g_pSkyBox->OnCreateDevice( pDev10 );
   // g_pSkyBox->SetTexture( g_pEnvMap->m_TextureRV );

	g_pFloatBufferSurfaceDesc.SampleDesc.Count   = pBackBufferSurfaceDesc->SampleDesc.Count;
    g_pFloatBufferSurfaceDesc.SampleDesc.Quality = pBackBufferSurfaceDesc->SampleDesc.Quality;



    D3DXVECTOR3 vTmp = D3DXVECTOR3(1, 2, 3);
    D3DXVec3Normalize(&g_vLightDir, &vTmp);

    SAFE_RELEASE(g_pRenderState);
    D3D10_RASTERIZER_DESC RasterizerState;
    RasterizerState.FillMode = D3D10_FILL_SOLID;
    RasterizerState.CullMode = D3D10_CULL_FRONT;
    RasterizerState.FrontCounterClockwise = true;
    RasterizerState.DepthBias = false;
    RasterizerState.DepthBiasClamp = 0.1;
    RasterizerState.SlopeScaledDepthBias = 0;
    RasterizerState.DepthClipEnable = true;
    RasterizerState.ScissorEnable = false;
    RasterizerState.MultisampleEnable = false;
    RasterizerState.AntialiasedLineEnable = false;
    V(pDev10->CreateRasterizerState(&RasterizerState, &g_pRenderState));
//.........这里部分代码省略.........
开发者ID:SenichiFSeiei,项目名称:oursavsm,代码行数:101,代码来源:SoftShadows.cpp

示例2: TrVertexFunc_TransformByModelviewAndNormalize

static void TrVertexFunc_TransformByModelviewAndNormalize( const GLfloat *vertex, float *output )
{
	D3DXVec3TransformCoord((D3DXVECTOR3*)output, (D3DXVECTOR3*)vertex, D3DGlobal.modelviewMatrixStack->top());
	D3DXVec3Normalize((D3DXVECTOR3*)output, (D3DXVECTOR3*)output);
}
开发者ID:drons,项目名称:qindie-gl,代码行数:5,代码来源:d3d_texgen.cpp

示例3: D3DXMatrixRotationAxis

//플레이어를 로컬 x-축, y-축, z-축을 중심으로 회전한다.
void CObject_Player::Rotate(float x, float y, float z)
{
	D3DXMATRIX mtxRotate;
	DWORD nCurrentCameraMode = m_pCamera->GetMode();

//1인칭 카메라 또는 3인칭 카메라의 경우 플레이어의 회전은 약간의 제약이 따른다.
	if ((nCurrentCameraMode == FIRST_PERSON_CAMERA) || (nCurrentCameraMode == THIRD_PERSON_CAMERA))
	{
/*로컬 x-축을 중심으로 회전하는 것은 고개를 앞뒤로 숙이는 동작에 해당한다. 그러므로 x-축을 중심으로 회전하는 각도는 -89.0~+89.0도 사이로 제한한다. x는 현재의 m_fPitch에서 실제 회전하는 각도이므로 x만큼 회전한 다음 Pitch가 +89도 보다 크거나 -89도 보다 작으면 m_fPitch가 +89도 또는 -89도가 되도록 회전각도(x)를 수정한다.*/
		if (x != 0.0f)
		{
			m_fPitch += x;
			if (m_fPitch > +89.0f) { x -= (m_fPitch - 89.0f); m_fPitch = +89.0f; }
			if (m_fPitch < -89.0f) { x -= (m_fPitch + 89.0f); m_fPitch = -89.0f; }
		} 
//로컬 y-축을 중심으로 회전하는 것은 몸통을 돌리는 것이므로 회전 각도의 제한이 없다.
		if (y != 0.0f)
		{
			m_fYaw += y;
			if (m_fYaw > 360.0f) m_fYaw -= 360.0f;
			if (m_fYaw < 0.0f) m_fYaw += 360.0f;
		} 
/*로컬 z-축을 중심으로 회전하는 것은 몸통을 좌우로 기울이는 것이므로 회전 각도는 -20.0~+20.0도 사이로 제한된다. z는 현재의 m_fRoll에서 실제 회전하는 각도이므로 z만큼 회전한 다음 m_fRoll이 +20도 보다 크거나 -20도보다 작으면 m_fRoll이 +20도 또는 -20도가 되도록 회전각도(z)를 수정한다.*/
		if (z != 0.0f) 
		{
			m_fRoll += z;
			if (m_fRoll > +20.0f) { z -= (m_fRoll - 20.0f); m_fRoll = +20.0f; }
			if (m_fRoll < -20.0f) { z -= (m_fRoll + 20.0f); m_fRoll = -20.0f; }
		} 
//카메라를 x, y, z 만큼 회전한다. 플레이어를 회전하면 카메라가 회전하게 된다.
		m_pCamera->Rotate(x, y, z);

/*플레이어를 회전한다. 1인칭 카메라 또는 3인칭 카메라에서 플레이어의 회전은 로컬 y-축에서만 일어난다. 플레이어의 로컬 y-축(Up 벡터)을 기준으로 로컬 z-축(Look 벡터)와 로컬 x-축(Right 벡터)을 회전시킨다. 기본적으로 Up 벡터를 기준으로 회전하는 것은 플레이어가 똑바로 서있는 것을 가정한다는 의미이다.*/
		if (y != 0.0f)
		{
			D3DXMatrixRotationAxis(&mtxRotate, &m_d3dxvUp, (float)D3DXToRadian(y));
			D3DXVec3TransformNormal(&m_d3dxvLook, &m_d3dxvLook, &mtxRotate);
			D3DXVec3TransformNormal(&m_d3dxvRight, &m_d3dxvRight, &mtxRotate);
		} 
	} 
	else if (nCurrentCameraMode == SPACESHIP_CAMERA)
	{
/*스페이스-쉽 카메라에서 플레이어의 회전은 회전 각도의 제한이 없다. 그리고 모든 축을 중심으로 회전을 할 수 있다.*/
		m_pCamera->Rotate(x, y, z);
		if (x != 0.0f) 
		{
			D3DXMatrixRotationAxis(&mtxRotate, &m_d3dxvRight, (float)D3DXToRadian(x));
			D3DXVec3TransformNormal(&m_d3dxvLook, &m_d3dxvLook, &mtxRotate);
			D3DXVec3TransformNormal(&m_d3dxvUp, &m_d3dxvUp, &mtxRotate);
		} 
		if (y != 0.0f) 
		{
			D3DXMatrixRotationAxis(&mtxRotate, &m_d3dxvUp, (float)D3DXToRadian(y));
			D3DXVec3TransformNormal(&m_d3dxvLook, &m_d3dxvLook, &mtxRotate);
			D3DXVec3TransformNormal(&m_d3dxvRight, &m_d3dxvRight, &mtxRotate);
		} 
		if (z != 0.0f) 
		{
			D3DXMatrixRotationAxis(&mtxRotate, &m_d3dxvLook, (float)D3DXToRadian(z));
			D3DXVec3TransformNormal(&m_d3dxvUp, &m_d3dxvUp, &mtxRotate);
			D3DXVec3TransformNormal(&m_d3dxvRight, &m_d3dxvRight, &mtxRotate);        
		}    
	} 

/*회전으로 인해 플레이어의 로컬 x-축, y-축, z-축이 서로 직교하지 않을 수 있으므로 z-축(LookAt 벡터)을 기준으로 하여 서로 직교하고 단위벡터가 되도록 한다.*/
	D3DXVec3Normalize(&m_d3dxvLook, &m_d3dxvLook);
	D3DXVec3Cross(&m_d3dxvRight, &m_d3dxvUp, &m_d3dxvLook);
	D3DXVec3Normalize(&m_d3dxvRight, &m_d3dxvRight);
	D3DXVec3Cross(&m_d3dxvUp, &m_d3dxvLook, &m_d3dxvRight);
	D3DXVec3Normalize(&m_d3dxvUp, &m_d3dxvUp);
}
开发者ID:anaddict100,项目名称:kpu-MonsterMonster,代码行数:72,代码来源:Object_Player.cpp

示例4: D3DXVECTOR3

void Minion::ProcessState()
{
	D3DXVECTOR3 pos = position;
	D3DXVECTOR3 direction;
	D3DXVECTOR3 right;
	D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0);
	float toPlayerRotationAngle;
	D3DXMatrixRotationY(&rotation, rotationAngle);
	D3DXVECTOR3 forward = D3DXVECTOR3(rotation._31, rotation._32, rotation._33);
	if (target)
	{
		direction = *target - position;
		D3DXVec3Normalize(&direction, &direction);
		D3DXVec3Cross(&right, &up, &direction);
		toPlayerRotationAngle = atan2f(direction.x,direction.z);
	}
	else direction = forward;
	
	switch (currentState)
	{
	case CharacterState::CHARACTER_IDLE:
	{
		float tick = GameManager::GetTick();
		idleTime += tick;
		if (hm->GetHeight(pos.y, pos.x, pos.z) != false)
		{
		}
		SelectPatrolPosition();
		if (!player->GetIsDead())
		{
			ChangeCharacterState(CharacterState::CHARACTER_PATROL);
		}
		else
		{
			if (idleTime < (float)rand() / RAND_MAX * 2) {
				ChangeCharacterState(CharacterState::CHARACTER_PATROL);
			}
		}

	}break;
	case CharacterState::CHARACTER_PATROL:
	{
		if (hm->GetHeight(pos.y, pos.x, pos.z) != false)
		{
			if (player)
			{
				if (Collision::IsSphereToSphere(sight_wide, player->GetBoundingSphereValue()))
				{
					D3DXVECTOR3 toPlayer = player->GetPosition() - position;
					D3DXVec3Normalize(&toPlayer, &toPlayer);

					//cos60°ú ºñ±³¸¦ Çؼ­ ³»Àû°ªÀÌ ¾È¿¡ ÀÖÀ¸¸é ¦i¾Æ°¨
					//Áß°£¿¡ ¾î´ÀÂÊÀ¸·Î µ¹¾Æ¾ß ÇÒÁö ¿ø·¡ ȸÀü°¢¿¡ 90À» ´õÇؼ­ ºÎÈ£°¡ ¹Ù²î´ÂÁö ÆÇÁ¤ÇÑ´Ù. DX±âº» ȸÀüÀº CWÀÌ´Ù.
					if (D3DXVec3Dot(&forward, &toPlayer) > cosf(D3DX_PI*0.33f))
					{
						if (D3DXVec3Dot(&toPlayer, &D3DXVECTOR3(cosf(rotationAngle + D3DX_PI*0.5f), 0, sinf(rotationAngle + D3DX_PI*0.5f))) > 0)
						{
							rotateCW = true;

						}
						else rotateCW = false;
						target = player->GetPositionAddress();
						ChangeCharacterState(CharacterState::CHARACTER_TRACE);
					}
					else
					{
						//½Ã¾ß°¢ ¹Û¿¡ ÀÖ´Ù.
						//Á¼Àº ¿ø ¾È¿¡ µé¾î¿À¸é ÆÇÁ¤À» ÇÔ. µÑ´Ù ¾Æ´Ï¸é °¡´ø ±æÀ» °£´Ù.
						if (Collision::IsSphereToSphere(sight_narrow, player->GetBoundingSphereValue()))
						{
							if (D3DXVec3Dot(&toPlayer, &D3DXVECTOR3(cosf(rotationAngle + D3DX_PI*0.5f), 0, sinf(rotationAngle + D3DX_PI*0.5f))) > 0)
							{
								rotateCW = true;

							}
							else rotateCW = false;
							target = player->GetPositionAddress();
							if (player->GetIsDead())
							{
								
							}
							else
							{
								ChangeCharacterState(CharacterState::CHARACTER_TRACE);
							}
						}

					}
				}
			}
			if (isHit)
			{
				hp -= inDamage;
				if (hp > 0)
				{
					ChangeCharacterState(CharacterState::CHARACTER_HIT);
				}
				else ChangeCharacterState(CharacterState::CHARACTER_DEAD);
			}
			
//.........这里部分代码省略.........
开发者ID:naknaknak,项目名称:3D_Game_Portfolio,代码行数:101,代码来源:Minion.cpp

示例5: D3DXVec3Normalize

	void SunLight::Render() {
		D3DXVec3Normalize((D3DXVECTOR3*)&mD3DLight.Direction, &Node::GetFrontVector());
		Light::Render();
	}
开发者ID:NHNNEXT,项目名称:2014-01-HUDIGAME-PoopTube,代码行数:4,代码来源:SunLight.cpp

示例6: FillGrid_WithNormals_Indexed


//.........这里部分代码省略.........
            pVertex->ny = 0.0f;
            pVertex->nz = 0.0f;
            pVertex->u = 0.0f + ( (float)j / dwWidth  );
            pVertex->v = 0.0f + ( (float)i / dwLength );
            pVertex++;
        }
    }

    // Allocate memory for buffer of indices in system memory
    WORD*    pIndexBuffer = new WORD [nNumIndex];
    WORD*    pIndex = &pIndexBuffer[0];

    // Fill index buffer
    for ( DWORD i=0; i<dwLength; ++i )
    {
        for ( DWORD j=0; j<dwWidth; ++j )
        {
            *pIndex++ = (WORD)(   i     * ( dwWidth+1 ) + j );
            *pIndex++ = (WORD)(   i     * ( dwWidth+1 ) + j + 1 );
            *pIndex++ = (WORD)( ( i+1 ) * ( dwWidth+1 ) + j );

            *pIndex++ = (WORD)( ( i+1 ) * (dwWidth+1) + j );
            *pIndex++ = (WORD)(   i     * (dwWidth+1) + j + 1 );
            *pIndex++ = (WORD)( ( i+1 ) * (dwWidth+1) + j + 1 );
        }
    }

    // Set initial data info
    D3D11_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = pIndexBuffer;

    // Fill DX11 index buffer description
    D3D11_BUFFER_DESC    bd;
    bd.Usage =           D3D11_USAGE_DEFAULT;
    bd.ByteWidth =       sizeof( WORD ) * nNumIndex;
    bd.BindFlags =       D3D11_BIND_INDEX_BUFFER;
    bd.CPUAccessFlags =  0;
    bd.MiscFlags =       0;
    
    // Create DX11 index buffer specifying initial data
    hr = pd3dDevice->CreateBuffer( &bd, &InitData, lplpIB );
    if( FAILED( hr ) )
    {
        OutputDebugString( L"FillGrid_WithNormals_Indexed: Failed to create index buffer.\n" );
        return;
    }
    DXUT_SetDebugName( *lplpIB, "FillGrid IB Nrmls" );

    // Write normals into vertex buffer
    pVertex = &pVertexBuffer[0];

    // Loop through all indices
    for ( DWORD i=0; i<nNumIndex/3; ++i )
    {
        WORD i1 = pIndexBuffer[3*i + 0];
        WORD i2 = pIndexBuffer[3*i + 1];
        WORD i3 = pIndexBuffer[3*i + 2];
        D3DXVECTOR3 Normal = CalculateTriangleNormal( (D3DXVECTOR3 *)&pVertexBuffer[i1].x, 
                                                      (D3DXVECTOR3 *)&pVertexBuffer[i2].x, 
                                                      (D3DXVECTOR3 *)&pVertexBuffer[i3].x );

        // Add normal to each vertex for this triangle
        *( (D3DXVECTOR3 *)&pVertexBuffer[i1].nx ) += Normal;
        *( (D3DXVECTOR3 *)&pVertexBuffer[i2].nx ) += Normal;
        *( (D3DXVECTOR3 *)&pVertexBuffer[i3].nx ) += Normal;
    }

    // Final normalization pass
    for ( DWORD i=0; i<nNumVertex; ++i )
    {
        D3DXVec3Normalize( (D3DXVECTOR3 *)&pVertexBuffer[i].nx, (D3DXVECTOR3 *)&pVertexBuffer[i].nx );
    }


    // Set initial data info
    InitData.pSysMem = pVertexBuffer;

    // Fill DX11 vertex buffer description
    bd.Usage =            D3D11_USAGE_DEFAULT;
    bd.ByteWidth =        sizeof( EXTENDEDVERTEX ) * nNumVertex;
    bd.BindFlags =        D3D11_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags =   0;
    bd.MiscFlags =        0;

    // Create DX11 vertex buffer specifying initial data
    hr = pd3dDevice->CreateBuffer( &bd, &InitData, lplpVB );
    if( FAILED( hr ) )
    {
        OutputDebugString( L"FillGrid_WithNormals_Indexed: Failed to create vertex buffer.\n" );
        return;
    }
    DXUT_SetDebugName( *lplpVB, "FillGrid VB Nrmls Idx" );

    // Release host memory index buffer
    delete [] pIndexBuffer;

    // Release host memory vertex buffer
    delete [] pVertexBuffer;

}
开发者ID:KNeal,项目名称:Oculus,代码行数:101,代码来源:Grid_Creation11.cpp

示例7: UpdateEnemy


//.........这里部分代码省略.........
				}
				else if(g_enemy[nCntEnemy].rot.y < 0.0f - D3DX_PI)
				{
					g_enemy[nCntEnemy].rot.y = g_enemy[nCntEnemy].rot.y + D3DX_PI*2;
				}

				//次の回転位置に到着したら
				if( fabs(g_enemy[nCntEnemy].rot.y - g_enemy[nCntEnemy].rotTarget.y) < VALUE_ROTATE &&
					fabs(g_enemy[nCntEnemy].rot.x - g_enemy[nCntEnemy].rotTarget.x) < VALUE_ROTATE &&
					fabs(g_enemy[nCntEnemy].rot.z - g_enemy[nCntEnemy].rotTarget.z) < VALUE_ROTATE
					)
				{
					g_enemy[nCntEnemy].rot = g_enemy[nCntEnemy].rotTarget;
					g_enemy[nCntEnemy].rotAngle = D3DXVECTOR3( 0, 0, 0);
				}
				else //次の回転位置にまだ到着してない
				{
					g_enemy[nCntEnemy].rot += g_enemy[nCntEnemy].rotAngle * fTimeSpeed;
				}	

				//回転していない時
				if(g_enemy[nCntEnemy].rotAngle == D3DXVECTOR3( 0, 0, 0))
				{
					//慣性処理
					g_enemy[nCntEnemy].move.x -= g_enemy[nCntEnemy].move.x * 0.05f;
					g_enemy[nCntEnemy].move.z -= g_enemy[nCntEnemy].move.z * 0.05f;

					D3DXVECTOR3 tNextPos = g_enemy[nCntEnemy].pos;
					tNextPos.x += g_enemy[nCntEnemy].move.x * sinf(g_enemy[nCntEnemy].rot.y);
					tNextPos.z += g_enemy[nCntEnemy].move.z * cosf(g_enemy[nCntEnemy].rot.y);

					D3DXVECTOR3 tSphere  = D3DXVECTOR3( 0, 0, 0);
					D3DXVECTOR3 front = tNextPos - g_enemy[nCntEnemy].pos;
					D3DXVec3Normalize( &tSphere, &front);
					tSphere *= MODEL_SPHERE;

					//壁の法線ベクトルを取得変数の初期化
					D3DXVECTOR3 wall_nor = D3DXVECTOR3(0,0,0);

					//Side
					g_enemy[nCntEnemy].posLSide.x = g_enemy[nCntEnemy].pos.x + 15.0f * sinf(g_enemy[nCntEnemy].rotTarget.y + D3DXToRadian(-90.0f));
					g_enemy[nCntEnemy].posLSide.z = g_enemy[nCntEnemy].pos.z + 15.0f * cosf(g_enemy[nCntEnemy].rotTarget.y + D3DXToRadian(-90.0f));

					g_enemy[nCntEnemy].posRSide.x = g_enemy[nCntEnemy].pos.x + 15.0f * sinf(g_enemy[nCntEnemy].rotTarget.y + D3DXToRadian(90.0f));
					g_enemy[nCntEnemy].posRSide.z = g_enemy[nCntEnemy].pos.z + 15.0f * cosf(g_enemy[nCntEnemy].rotTarget.y + D3DXToRadian(90.0f));

					//壁に当たったら
					if( HitCheckMeshWall( g_enemy[nCntEnemy].posLSide, g_enemy[nCntEnemy].posLSide + tSphere, &wall_nor, NULL) ||
						HitCheckMeshWall( g_enemy[nCntEnemy].posRSide, g_enemy[nCntEnemy].posRSide + tSphere, &wall_nor, NULL) )
					{

						if( g_enemy[nCntEnemy].bSeePlayer || !g_enemy[nCntEnemy].bPatrol)
						{
							//壁ずり処理:移動ベクトルを修正
							GetWallScratchVector( &front, front, wall_nor);
				
							D3DXVec3Normalize( &tSphere, &front);
							tSphere *= MODEL_SPHERE;

							if( !HitCheckMeshWall( g_enemy[nCntEnemy].pos, g_enemy[nCntEnemy].pos + tSphere, &wall_nor, NULL) )
							{
								//移動処理
								g_enemy[nCntEnemy].pos += front;
							}
						}
						
开发者ID:minamiliu,项目名称:Time_To_Shoot,代码行数:66,代码来源:enemy.cpp

示例8: switch

void Enemy::update(float dt)
{
	//No keyboard input, just preset patterns
	gameTime += dt;
	elapsed += dt;
	
	bool moving = false;
	bool sprinting = false;


	switch(aiMode) {
	case RANDOM:
		//Check if first time through. If so, select random waypoint within bounds
		//if(aiPath.size() == 0) {
		//	/*float xRange;
		//	float zRange;
		//	float tempX1, tempX2, xOffset;
		//	float tempZ1, tempZ2, zOffset;
		//	
		//	if(xBounds.x < 0) {tempX1 = - xBounds.x;} else {tempX1 = xBounds.x;}
		//	if(xBounds.y < 0) {tempX2 = - xBounds.y;} else {tempX2 = xBounds.y;}
		//	if(zBounds.x < 0) {tempZ1 = - zBounds.x;} else {tempZ1 = zBounds.x;}
		//	if(zBounds.y < 0) {tempZ2 = - zBounds.y;} else {tempZ2 = zBounds.y;}

		//	xRange = tempX1 + tempX2;
		//	zRange = tempZ1 + tempZ2;*/

		//	float xRand, zRand;
		//	std::random_device rseed;
		//	std::mt19937 rng(rseed());
		//	std::uniform_int<int> dist1(xBounds.x,xBounds.y);
		//	xRand = dist1(rng);
		//	std::uniform_int<int> dist2(zBounds.x,zBounds.y);
		//	zRand = dist2(rng);

		//	aiPath.push_back(Vector3(xRand, position.y, zRand));
		//	direction = aiPath[0] - position;
		//	D3DXVec3Normalize(&direction, &direction);
		//}

		////Check if close to destination
		////	If so, calculate and set new destination
		//if(((position.x < (aiPath[pathIndex].x + 1.0f)) && (position.x > (aiPath[pathIndex].x - 1.0f)))
		//&&((position.z < (aiPath[pathIndex].z + 1.0f)) && (position.z > (aiPath[pathIndex].z - 1.0f))))
		//{
		//	float xRand, zRand;

		//	std::random_device rseed;
		//	std::mt19937 rng(rseed());

		//	std::uniform_int<int> dist1(xBounds.x, xBounds.y);
		//	xRand = dist1(rng);
		//	std::uniform_int<int> dist2(zBounds.x, zBounds.y);
		//	zRand = dist2(rng);

		//	aiPath[0] = Vector3(xRand, position.y, zRand);
		//	direction = aiPath[0] - position;
		//	D3DXVec3Normalize(&direction, &direction);

		//	elapsed = 0;
		//}

		////Move toward waypoint, updating both position and direction
		//if(pathIndex == 0)
		//	OutputDebugString(L"0\n");
		//else
		//	OutputDebugString(L"1\n");


		//position += direction * speed * dt;
		//moving = true;

		break;
	case PATH:


		//Check if close to waypoint
		//	If so, calculate and set new waypoint
		if(((position.x < (aiPath[pathIndex].x + 1.0f)) && (position.x > (aiPath[pathIndex].x - 1.0f)))
		&&((position.z < (aiPath[pathIndex].z + 1.0f)) && (position.z > (aiPath[pathIndex].z - 1.0f))))
		{
			if(pathIndex == aiPath.size() - 1)
			{
				pathDir = -1;
			}
			if (pathIndex == 0)
			{
				pathDir = 1;
			}
			pathIndex += pathDir;
			if (pathIndex > aiPath.size() - 1)
				pathIndex = aiPath.size() - 1;
			direction = aiPath[pathIndex] - position;
			D3DXVec3Normalize(&direction, &direction);
			

			elapsed = 0;
		}

		//Move toward waypoint, updating position
//.........这里部分代码省略.........
开发者ID:eckerdj1,项目名称:Comp446_Game2,代码行数:101,代码来源:Enemy.cpp

示例9: _XMeshMath_DistanceBetweenTwoPoint

bool XProc_DeleteCharacter::Process( void )
{	
	if(g_pTitleFlashObject) g_pTitleFlashObject->PlayTimerFire();

	g_MessageBox.Process();	
	g_IMEWindow.Process();
	m_WindowManager.Process();

	if( m_CameraMoving )
	{
		FLOAT fFrameSpeed = 0.0f;

		FLOAT distance = _XMeshMath_DistanceBetweenTwoPoint( m_CameraMovingTarget, g_LodTerrain.m_3PCamera.m_TargetPosition );
		FLOAT maxdistance = _XMeshMath_DistanceBetweenTwoPoint( D3DXVECTOR3( 0.125f, 0.495f, 0.0f ), D3DXVECTOR3( 0.125f, 0.895f, 0.0f ) );

		if( maxdistance - distance < 0.08f )
			 fFrameSpeed = g_fElapsedFrameMilisecondTime / 4.0f;
		else if( maxdistance - distance < 0.18f )
			 fFrameSpeed = g_fElapsedFrameMilisecondTime / 1.2f;
		else 
		{
			if( distance < 0.08f )
				fFrameSpeed = g_fElapsedFrameMilisecondTime / 2.0f;
			else if( distance < 0.18f )
				fFrameSpeed = g_fElapsedFrameMilisecondTime;
			else
				fFrameSpeed = g_fElapsedFrameMilisecondTime * 2.5f;
		}

		BOOL zooming = TRUE;
		if( m_CameraMovingTargetDistance > g_LodTerrain.m_3PCamera.GetDistance() )
		{
			g_LodTerrain.m_3PCamera.SetDistance( g_LodTerrain.m_3PCamera.GetDistance() + fFrameSpeed * 5.0f );

			if( m_CameraMovingTargetDistance < g_LodTerrain.m_3PCamera.GetDistance() )
			{
				g_LodTerrain.m_3PCamera.SetDistance( m_CameraMovingTargetDistance );
				zooming = FALSE;
			}
		}
		else if( m_CameraMovingTargetDistance < g_LodTerrain.m_3PCamera.GetDistance() )
		{
			g_LodTerrain.m_3PCamera.SetDistance( g_LodTerrain.m_3PCamera.GetDistance() - fFrameSpeed * 5.0f );

			if( m_CameraMovingTargetDistance > g_LodTerrain.m_3PCamera.GetDistance() )
			{
				g_LodTerrain.m_3PCamera.SetDistance( m_CameraMovingTargetDistance );
				zooming = FALSE;
			}
		}
		else
		{
			zooming = FALSE;
		}
				
		if( distance < EPSILON3 )
		{
			g_LodTerrain.m_3PCamera.m_TargetPosition = m_CameraMovingTarget;
			g_LodTerrain.m_3PCamera.UpdateViewMatrix();
			g_LodTerrain.m_3PCamera.UpdateProjMatrix();

			if( !zooming )
				m_CameraMoving = FALSE;
		}
		else
		{
			D3DXVECTOR3 direction = m_CameraMovingTarget - g_LodTerrain.m_3PCamera.m_TargetPosition;
			D3DXVec3Normalize( &direction, &direction );

			D3DXVECTOR3 prevPosition = g_LodTerrain.m_3PCamera.m_TargetPosition;

			g_LodTerrain.m_3PCamera.m_TargetPosition += direction * fFrameSpeed * 1.68f;

			FLOAT prevdistance = _XMeshMath_DistanceBetweenTwoPoint( prevPosition, m_CameraMovingTarget );
			FLOAT newdistance = _XMeshMath_DistanceBetweenTwoPoint( m_CameraMovingTarget, g_LodTerrain.m_3PCamera.m_TargetPosition );

			if( prevdistance < newdistance )
			{
				g_LodTerrain.m_3PCamera.m_TargetPosition = m_CameraMovingTarget;
				
				if( !zooming )
					m_CameraMoving = FALSE;
			}

			g_LodTerrain.m_3PCamera.UpdateViewMatrix();
			g_LodTerrain.m_3PCamera.UpdateProjMatrix();
		}
	}


	return true;
}
开发者ID:F5000,项目名称:spree,代码行数:92,代码来源:XProc_DeleteCharacter.cpp

示例10: D3DXMatrixIdentity


//.........这里部分代码省略.........
			for ( int i = 0; i < vertexSizeCount; ++i )
			{
				fileData[i] = fgetc(fp);
			}
		}
		fclose(fp);

		tileCount = mapSize - 1;

		std::vector<FVF_PositionNormalTexture> fvfVertex;
		fvfVertex.resize(vertexSizeCount);
		vertex.resize(vertexSizeCount);

		for (int z = 0; z < mapSize; ++z)
		{
			for (int x = 0; x < mapSize; ++x)
			{
				int index = z * mapSize + x;
				FVF_PositionNormalTexture v;
				v.pos = D3DXVECTOR3((float)x, fileData[index] * 0.2f, (float)-z);
				v.normal = D3DXVECTOR3(0,1,0);
				v.tex = D3DXVECTOR2(x / (float)tileCount, z / (float)tileCount);

				fvfVertex[index] = v;
				vertex[index] = v.pos;
			}
		}

		//노말값들 갱신
		//필요한건 벡터 4개
		//왼쪽, 오른쪽, 위쪽, 아래쪽

		for (int z = 1; z < tileCount; ++z)
		{
			for (int x = 1; x < tileCount; ++x)
			{
				int index = z * mapSize + x;
				D3DXVECTOR3 left = vertex[index - 1];
				D3DXVECTOR3 right = vertex[index + 1];
				D3DXVECTOR3 front = vertex[index - mapSize];
				D3DXVECTOR3 rear = vertex[index + mapSize];
				D3DXVECTOR3 leftToRight = right - left;
				D3DXVECTOR3 frontToRear = rear - front;
				D3DXVECTOR3 normal;
				D3DXVec3Cross(&normal, &leftToRight, &frontToRear);
				D3DXVec3Normalize(&normal, &normal);

				fvfVertex[index].normal = normal;
			}
		}

		//버벡스 버퍼, 인덱스 버퍼 만들기
		std::vector<DWORD> indexData;
		triangleCount = tileCount * tileCount * 2;
		indexData.resize(triangleCount * 3);
		for (int z = 0; z < tileCount; ++z)
		{
			for (int x = 0, k = 0; x < tileCount; ++x, ++k)
			{
				int _0 = (x + 0) + (z + 0) * mapSize;
				int _1 = (x + 1) + (z + 0) * mapSize;
				int _2 = (x + 0) + (z + 1) * mapSize;
				int _3 = (x + 1) + (z + 1) * mapSize;

				indexData[z * (6 * tileCount) + k] = (_0);
				indexData[z * (6 * tileCount) + ++k] = (_1);
				indexData[z * (6 * tileCount) + ++k] = (_2);

				indexData[z * (6 * tileCount) + ++k] = (_3);
				indexData[z * (6 * tileCount) + ++k] = (_2);
				indexData[z * (6 * tileCount) + ++k] = (_1);
			}
		}
		int bufferSize = fvfVertex.size() * sizeof(FVF_PositionNormalTexture);
		GameManager::GetDevice()->CreateVertexBuffer(
			bufferSize,
			0,
			FVF_PositionNormalTexture::FVF,
			D3DPOOL_MANAGED,
			&vertexBuffer,
			nullptr);
		LPVOID pV;
		vertexBuffer->Lock(0, 0, &pV, 0);
		memcpy_s(pV, bufferSize, &fvfVertex[0], bufferSize);
		vertexBuffer->Unlock();

		bufferSize = indexData.size() * sizeof(DWORD);
		GameManager::GetDevice()->CreateIndexBuffer(
			bufferSize,
			0,
			D3DFMT_INDEX32,
			D3DPOOL_MANAGED,
			&indexBuffer,
			nullptr);
		LPVOID pI;
		indexBuffer->Lock(0, 0, &pI, 0);
		memcpy_s(pI, bufferSize, &indexData[0], bufferSize);
		indexBuffer->Unlock();
	}
}
开发者ID:naknaknak,项目名称:3D_Game_Portfolio,代码行数:101,代码来源:HeightMap.cpp

示例11: D3DApp

RobotArmDemo::RobotArmDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	// Initialize Camera Settings
	mCameraRadius    = 9.0f;
	mCameraRotationY = 1.5f * D3DX_PI;
	mCameraHeight    = 0.0f;

	// Setup a directional light.
	mLight.dirW    = D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.spec    = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

	// Load the bone .X file mesh.
	LoadXFile("bone.x", &mBoneMesh, mMtrl, mTex);
	D3DXMatrixIdentity(&mWorld);

	// Create the white dummy texture.
	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

	// Initialize the bones relative to their parent frame.
	// The root is special--its parent frame is the world space.
	// As such, its position and angle are ignored--its 
	// toWorldXForm should be set explicitly (that is, the world
	// transform of the entire skeleton).
	//
	// *------*------*------*------
	//    0      1      2      3

	for(int i = 1; i < NUM_BONES; ++i) // Ignore root.
	{
		// Describe each bone frame relative to its parent frame.
		mBones[i].pos    = D3DXVECTOR3(2.0f, 0.0f, 0.0f);
		mBones[i].zAngle = 0.0f;
	}
	// Root frame at center of world.
	mBones[0].pos    = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	mBones[0].zAngle = 0.0f;


	// Start off with the last (leaf) bone:
	mBoneSelected = NUM_BONES-1;

	mGfxStats->addVertices(mBoneMesh->GetNumVertices() * NUM_BONES);
	mGfxStats->addTriangles(mBoneMesh->GetNumFaces() * NUM_BONES);

	buildFX();

	onResetDevice();
}
开发者ID:chenbk85,项目名称:3dlearn,代码行数:62,代码来源:RobotArmDemo.cpp

示例12: memset

HRESULT APPLICATION::Init(HINSTANCE hInstance, int width, int height, bool windowed)
{
	debug.Print("Application initiated");

	//Create Window Class
	WNDCLASS wc;
	memset(&wc, 0, sizeof(WNDCLASS));
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)::DefWindowProc; 
	wc.hInstance     = hInstance;
	wc.lpszClassName = "D3DWND";

	//Register Class and Create new Window
	RegisterClass(&wc);
	m_mainWindow = CreateWindow("D3DWND", "Example 12.7: Constructing Buildings", WS_EX_TOPMOST, 0, 0, width, height, 0, 0, hInstance, 0); 
	SetCursor(NULL);
	ShowWindow(m_mainWindow, SW_SHOW);
	UpdateWindow(m_mainWindow);

	//Create IDirect3D9 Interface
	IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

    if(d3d9 == NULL)
	{
		debug.Print("Direct3DCreate9() - FAILED");
		return E_FAIL;
	}

	//Check that the Device supports what we need from it
	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	//Hardware Vertex Processing or not?
	int vp = 0;
	if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

	//Check vertex & pixelshader versions
	if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
	{
		debug.Print("Warning - Your graphic card does not support vertex and pixelshaders version 2.0");
	}

	//Set D3DPRESENT_PARAMETERS
	D3DPRESENT_PARAMETERS d3dpp;
	d3dpp.BackBufferWidth            = width;
	d3dpp.BackBufferHeight           = height;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 1;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = m_mainWindow;
	d3dpp.Windowed                   = windowed;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	//Create the IDirect3DDevice9
	if(FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow,
								 vp, &d3dpp, &m_pDevice)))
	{
		debug.Print("Failed to create IDirect3DDevice9");
		return E_FAIL;
	}

	//Release IDirect3D9 interface
	d3d9->Release();

	// Create m_light
	::ZeroMemory(&m_light, sizeof(m_light));
	m_light.Type      = D3DLIGHT_DIRECTIONAL;
	m_light.Ambient   = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	m_light.Diffuse   = D3DXCOLOR(0.9f, 0.9f, 0.9f, 1.0f);
	m_light.Specular  = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	D3DXVECTOR3 dir = D3DXVECTOR3(-1.0f, -1.0f, 0.0f);
	D3DXVec3Normalize(&dir, &dir);
	m_light.Direction = dir;	
	m_pDevice->SetLight(0, &m_light);
	m_pDevice->LightEnable(0, true);

	//Set sampler state
	for(int i=0;i<4;i++)
	{
		m_pDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
		m_pDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		m_pDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
	}

	m_build1.Load("meshes/townhall_b.x", m_pDevice);
	m_build2.Load("meshes/townhall.x", m_pDevice);
	m_buildPrc = 0.0f;

	return S_OK;
}
开发者ID:Alriightyman,项目名称:RTS,代码行数:98,代码来源:app.cpp

示例13: atan2f

void Player::update(float _dt)
{
	//do nothing if dead
	if (bIsDead)
	{
		gStateMachine->transitionState(STATE_LOSE);
		return;
	}

	Pawn::update(_dt);
	//facing controls
	if (gDInput->keyDown(DIK_Q))
	{
		gCameraMain->setAngleOffset(1.0f * _dt);
	}
	if (gDInput->keyDown(DIK_E))
	{
		gCameraMain->setAngleOffset(-1.0f * _dt);
	}


	//face towards mouse position
	float a = (float)gWindowWidth / 2.0f - gDInput->mCursorPos2D.x;
	float b = (float)gWindowHeight / 2.0f - gDInput->mCursorPos2D.y;
	float angle = atan2f(b, a) + D3DX_PI / 2.0f + gCameraMain->getAngleOffset();
	mRotation.y = angle;

	//direction controls
	bIsMoving = false;
	mVelocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	if (gDInput->keyDown(DIK_W))
	{
		mVelocity += D3DXVECTOR3(0.0f, 0.0f, mSpeed);
		bIsMoving = true;
	}
	if (gDInput->keyDown(DIK_S))
	{
		mVelocity += D3DXVECTOR3(0.0f, 0.0f, -mSpeed);
		bIsMoving = true;
	}
	if (gDInput->keyDown(DIK_A))
	{
		mVelocity += D3DXVECTOR3(-mSpeed, 0.0f, 0.0f);
		bIsMoving = true;
	}
	if (gDInput->keyDown(DIK_D))
	{
		mVelocity += D3DXVECTOR3(mSpeed, 0.0f, 0.0f);
		bIsMoving = true;
	}

	if (mVelocity != D3DXVECTOR3(0.0f, 0.0f, 0.0f))
	{
		//face direction that the buttons indicate we're going
		D3DXVec3Normalize(&mVelocity, &mVelocity);
		float a = (float)gWindowWidth * 0.5f - mVelocity.x;
		float b = (float)gWindowHeight * 0.5f - mVelocity.z;
		float angle = atan2f(b, a) + /*D3DX_PI * 1.795f + */5.6391588f + 
			gCameraMain->getAngleOffset();

		//build rotation matrix
		D3DXMATRIX rot;
		D3DXMatrixRotationY(&rot, angle);
		//transform direction by rot matrix
		D3DXVECTOR4 transform;
		D3DXVec3Transform(&transform, &mVelocity, &rot);
		mVelocity = D3DXVECTOR3(transform.x, transform.y, transform.z);

		D3DXVec3Normalize(&mVelocity, &mVelocity);
		mVelocity *= mSpeed;
	}
	
	//did we collide with any level geometry?
	bool colliding = false;
	//for each colliding mesh in level
	// SAM: TODO: Hack, this is for testing
// 	mLastPosition = mPosition;
// 	mPosition += (mVelocity * _dt);
	for (Mesh* M : gCurrentLevel->getWorldGeometry())
	{
		//for each bounding box in mesh
/*		for (AxisAlignedBoundingBox2D* AABB : M->getAABBs())
		{
			colliding = collides(*AABB, BoundingSphere2D(D3DXVECTOR2(mPosition.x, mPosition.z), mRadius));
			if (colliding)
				break;
		}
		if (colliding) break;*/

		// SAM
		for (UINT i = 0; i < M->getBoundsBoxList().size(); ++i) {
			colliding = collides(AxisAlignedBoundingBox(M->getBoundsBoxList()[i]), BoundingSphere(D3DXVECTOR3(mPosition.x, mPosition.y, mPosition.z), mRadius));
			if (colliding)
				break;
		}
		if (colliding)
			break;
	}
	//move
	if (!colliding)
//.........这里部分代码省略.........
开发者ID:brentspector,项目名称:Dart,代码行数:101,代码来源:Player.cpp

示例14: switch

void Follower::update(float _dt)
{
	//do nothing if dead
	if (bIsDead)
	{//will add a more elaborate lose screen later
		gStateMachine->transitionState(STATE_LOSE);
		return;
	}

	Pawn::update(_dt);

	mLastPathFound += _dt;
	static float aiCheck = 0.0f;
	aiCheck += _dt;
	if (aiCheck >= RUN_AI)//only run the AI every so many frames
	//inside this conditional you should use aiCheck where you'd normally use _dt
	{
		float distanceToPlayerSq;
		bIsMoving = true;
		switch (mState)
		{
		case PSTATE_PURSUE:
			distanceToPlayerSq = D3DXVec3LengthSq(&(gPlayer->getPosition() - mPosition));
			if (distanceToPlayerSq > FOLLOW_DISTANCE_SQ)
			{
				if (!followPath() || mLastPathFound > MIN_PATH_TIME)
					setPathPlayer();
			}
			else if (distanceToPlayerSq > FOLLOW_DISTANCE_STOP_SQ)
			{
				mVelocity = gPlayer->getPosition() - mPosition;
				D3DXVec3Normalize(&mVelocity, &mVelocity);//normalize to 1 unit length vector
				mVelocity *= mSpeed;//multiply by speed
			}
			else
			{
				stop();
				bIsMoving = false;
			}
			break;
		case PSTATE_AFRAID:
			//how long has it been afraid
			mAfraidTime += _dt;
			if (mAfraidTime >= mAfraidMax)
			{//don't let the follower be afraid indefinitely, else the task of getting them
				//to the goal might become impossible
				bAfraid = false;
				mAfraidTime = 0.0f;
				mState = PSTATE_PURSUE;
				break;
			}
			//if no longer afraid
			if (!bAfraid)
			{
				mState = PSTATE_PURSUE;
				break;
			}
			else//flee randomly in panic
			{
				if (mLastPathFound >= MIN_PATH_TIME || !followPath(1.0f))
				{
					setPathFlee();
				}
				//gSound->getSystem()->playSound(NULL, followerCry, false, 0);
			}
			break;
		}
		mPosition += (mVelocity * aiCheck);//set position based on speed
		detectCollision();//let the player push the follower, but not into walls
		pointForward(aiCheck);//set rotation based on direction
		mMesh->setPosRot(mPosition, mRotation);//set position and rotation of mesh
		aiCheck = 0.0f;
	}
	
}
开发者ID:brentspector,项目名称:Dart,代码行数:75,代码来源:Player.cpp

示例15: BeginState

bool ZEffectBillboardList::Draw()
{
	if(!m_pVB) return false;

	if( size()==0 ) return true;

	BeginState();

	HRESULT		hr;

	DWORD		dwRemainNum = (DWORD)size();

	iterator itr=begin();

	while(dwRemainNum)
	{
		if(m_dwBase >= EFFECTBASE_DISCARD_COUNT)
			m_dwBase = 0;

		// 갯수가 BILLBOARD_FLUSH_COUNT 를 넘어가면 BILLBOARD_FLUSH_COUNT 씩 찍는다
		DWORD dwThisNum = min( dwRemainNum , BILLBOARD_FLUSH_COUNT );

		// 버퍼의 크기를 넘어가면 개수를 줄여서 크기만큼만 찍는다
		dwThisNum = min( dwThisNum , EFFECTBASE_DISCARD_COUNT - m_dwBase );	


		BYTE		*pVertices;
		if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(ZEFFECTCUSTOMVERTEX) * 4, dwThisNum * sizeof(ZEFFECTCUSTOMVERTEX) * 4,
			(VOID**)&pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		BYTE *pInd;
		if( FAILED( hr = m_pIB->Lock( m_dwBase * sizeof(WORD) * 6, dwThisNum * sizeof(WORD) * 6,
			(VOID**)&pInd, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		for(DWORD j=0;j<dwThisNum;j++)
		{
			ZEFFECTBILLBOARDITEM *p = (ZEFFECTBILLBOARDITEM*)*itr;

			// Transform
			rmatrix matTranslation;
			rmatrix matScaling;
			rmatrix matWorld;

			rvector dir = p->normal;

			rvector up=p->up;
			rvector right;

			if(IS_EQ(dir.z,1.f)) up=rvector(1,0,0);

			D3DXVec3Cross(&right, &up, &dir);
			D3DXVec3Normalize(&right, &right);

			D3DXVec3Cross(&up, &right, &dir);
			D3DXVec3Normalize(&up, &up);

			rmatrix mat;
			D3DXMatrixIdentity(&mat);
			mat._11=right.x;mat._12=right.y;mat._13=right.z;
			mat._21=up.x;mat._22=up.y;mat._23=up.z;
			mat._31=dir.x;mat._32=dir.y;mat._33=dir.z;

			rvector pos=p->position;

//			float fScale=p->fStartSize * p->fOpacity + p->fEndSize * (1.f - p->fOpacity);

			float fInt = min(1,max(0,(p->fLifeTime - p->fElapsedTime)/p->fLifeTime));

			float fScale=p->fStartSize * fInt + p->fEndSize * (1.f - fInt);

			if( p->bUseTrainSmoke ) {

				float fRatio = GetLifeRatio(p);
				float fAddScale = (p->fEndSize - p->fStartSize) / p->fLifeTime;

				if(fRatio < 0.1f ) {
					fAddScale *= 0.001f;
				}
				else if(fRatio < 0.4) {
					fAddScale *= 0.02f;
				}
				else {
					fAddScale *= 0.05f;
				}

				p->fCurScale += fAddScale;

				if(p->fCurScale > p->fEndSize)
					p->fCurScale = p->fEndSize;

				fScale = p->fCurScale;
			}

			D3DXMatrixScaling(&matScaling,fScale*m_Scale.x,fScale*m_Scale.y,fScale*m_Scale.z);
//.........这里部分代码省略.........
开发者ID:MagistrAVSH,项目名称:node3d,代码行数:101,代码来源:ZEffectBillboardList.cpp


注:本文中的D3DXVec3Normalize函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。