示例#1
0
void RenderToCubeTex::BeginCubeSurf(Engine& engine)
{
	LSL_ASSERT(IsBeginRT());

	CameraDesc camDesc = engine.GetContext().GetCamera().GetDesc();
	//camDesc.pos = D3DXVECTOR3(0, 0, 15.0f);
	camDesc.pos = _viewPos;
	camDesc.style = csPerspective;
	camDesc.aspect = 1;
	camDesc.nearDist = 1.0f;
	camDesc.farDist = 100.0f;
	camDesc.fov = D3DX_PI/2;

	switch(_flags.faceType)
	{
	case D3DCUBEMAP_FACE_POSITIVE_X:
		camDesc.dir = D3DXVECTOR3(-1.0f, 0.0f, 0.0f );
		camDesc.up = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
		break;

	case D3DCUBEMAP_FACE_NEGATIVE_X:			
		camDesc.dir = D3DXVECTOR3(1.0f, 0.0f, 0.0f );			
		camDesc.up = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
		break; 

	case D3DCUBEMAP_FACE_POSITIVE_Y:			
		camDesc.dir = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
		camDesc.up = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
		break;
			
	case D3DCUBEMAP_FACE_NEGATIVE_Y:			
		camDesc.dir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
		camDesc.up = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
		break;				
			
	case D3DCUBEMAP_FACE_POSITIVE_Z:
		camDesc.dir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
		camDesc.up = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
		break;				
	
	case D3DCUBEMAP_FACE_NEGATIVE_Z:
		camDesc.dir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
		camDesc.up = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
		break;
	}

	_myCamera.SetDesc(camDesc);	
	engine.GetContext().ApplyCamera(&_myCamera);

	ApplyRT(engine, _flags);
}
示例#2
0
void LightClass::SetPosition(float x, float y, float z)
{
	m_position = D3DXVECTOR3(x, y, z);
	return;
}
void GraphicsEngine::Render()
{
  this->camera.Update();
  

  //////////////CAMERA CODE//////////////////////
  // Define camera information.
  /*D3DXVECTOR3 cameraPos(camera.m_pos.x, camera.m_pos.y,
    camera.m_pos.z);
  D3DXVECTOR3 lookAtPos(camera.m_view.x, camera.m_view.y,
    camera.m_view.z);
  D3DXVECTOR3 upDir(camera.m_up.x, camera.m_up.y,
    camera.m_up.z);*/

  //A Matrix to hold the world transforms of the objects
  D3DXMATRIX worldTransform;
  D3DXMatrixIdentity(&worldTransform);

  // Build view matrix.
  /*D3DXMatrixLookAtLH(&g_ViewMatrix, &cameraPos,
    &lookAtPos, &upDir);*/
  g_ViewMatrix = *camera.GetViewMatrix();

  // Apply the view (camera).
  g_D3DDevice->SetTransform(D3DTS_VIEW, &g_ViewMatrix);

  // Set the projection matrix.
  D3DXMatrixPerspectiveFovLH(&g_projection, 45.0f,
    WINDOW_WIDTH/WINDOW_HEIGHT, 0.1f, 1000.0f);

  g_D3DDevice->SetTransform(D3DTS_PROJECTION, &g_projection);
  //////////////////////END CAMERA CODE///////////



  // Clear the backbuffer.
  g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
    D3DCOLOR_ARGB(40,40,40,100), 1.0f, 0);


  //Sort the Objects By their z value in view space
  SortBackToFront();


  //////////////////////////////////////////////////////////////////////////////
  ///////////////////////////BEGIN SCENE////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////
  
  // Begin the scene.  Start rendering.
  g_D3DDevice->BeginScene();

  //Render Skybox

    static int time = 0; 
    time += 16;
    g_D3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
    g_D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
    
    
    D3DXMatrixIdentity(&worldTransform);
    unsigned int passes;
    effectMap["HackMapping"]->GetEffect()->Begin(&passes, 0);
    effectMap["HackMapping"]->GetEffect()->BeginPass(0);
    GetWorldMtx(&worldTransform, D3DXVECTOR3(gmMgr->graphics_->camera.GetPos().x,gmMgr->graphics_->camera.GetPos().y, gmMgr->graphics_->camera.GetPos().z), D3DXVECTOR3(1,1,1),D3DXVECTOR3(0,time/10000.0f,0));
    effectMap["HackMapping"]->GetEffect()->SetMatrix("g_world", &worldTransform);
    effectMap["HackMapping"]->GetEffect()->SetMatrix("g_wvp", &(worldTransform * g_ViewMatrix * g_projection));


    effectMap["HackMapping"]->GetEffect()->SetTexture("g_texture", this->GetTexture("glow"));
    effectMap["HackMapping"]->GetEffect()->SetTexture("g_normals", textureMap["default"]);

    effectMap["HackMapping"]->GetEffect()->SetBool("Lighting", false);
    effectMap["HackMapping"]->GetEffect()->CommitChanges();

    skybox->mesh->DrawSubset(0);

    effectMap["HackMapping"]->GetEffect()->SetBool("Lighting", true);
    effectMap["HackMapping"]->GetEffect()->CommitChanges();

    effectMap["HackMapping"]->GetEffect()->EndPass();
    effectMap["HackMapping"]->GetEffect()->End();


    g_D3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
    g_D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
  //}

    // Clear the backbuffer.
  g_D3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER,
    D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0);


  // Texture filter.
  g_D3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
  g_D3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

  g_D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
  RenderScene();

  g_D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
  RenderScene();

  RenderText();

  
  if(m_pBGTexture)
  {
    //GraphicsEngine::CreateComponent(FOSSA);
    g_pSprite->Begin(D3DXSPRITE_ALPHABLEND);

    D3DXMATRIX mat4Transform;
    D3DXMATRIX mat4OldTransform;

    D3DXVECTOR2 vec2Scale;
    vec2Scale.x = static_cast<float>(WINDOW_WIDTH)/1024.f;
    vec2Scale.y = static_cast<float>(WINDOW_HEIGHT)/1024.f;

    D3DXVECTOR3 vec3Position(0.0f, 0.0f, 0.0f);



    g_pSprite->GetTransform(&mat4OldTransform);

    D3DXMatrixTransformation2D(&mat4Transform, NULL, 0.0f, &vec2Scale, NULL, 0.0f, NULL);

    g_pSprite->SetTransform(&mat4Transform);

    g_pSprite->Draw(m_pBGTexture, NULL, NULL, &vec3Position, m_BGColor);

    g_pSprite->SetTransform(&mat4OldTransform);

    g_pSprite->End();
  }


  // End the scene.  Stop rendering.
  g_D3DDevice->EndScene();

  //////////////////////////////////////////////////////////////////////////////
  ///////////////////////////END SCENE//////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////

  // Display the scene.
  g_D3DDevice->Present(NULL, NULL, NULL, NULL);

}
bool SkeletonClass::UpdateBuffers(ID3D10Device* device)
{

	VertexType* vertices;
	void* verticesPtr;
	HRESULT result;

	if((m_SkeletonModel[0].x == 0) && (m_SkeletonModel[0].y == 0) && (m_SkeletonModel[0].z == 0))
	{
		return true; 
	}
	
	// Create the vertex array.
	vertices = new VertexType[m_vertexCount];
	if(!vertices)
	{
		return false;
	}

	for(DWORD i = 0; i < m_vertexCount; ++i) 
	{
		vertices[i].position = D3DXVECTOR3(m_SkeletonModel[i].x, m_SkeletonModel[i].y, m_SkeletonModel[i].z);
		vertices[i].color =  D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f); 

		if( i >= 8 && i <= 11)
		{
			vertices[i].color =  D3DXVECTOR4(1.0f, 1.0f, 0.0f, 1.0f); 
		}

		if(m_Skeleton.eSkeletonPositionTrackingState[i] == NUI_SKELETON_POSITION_INFERRED)
		{
			vertices[i].color =  D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f);
		}

		if(m_Skeleton.eSkeletonPositionTrackingState[i] == NUI_SKELETON_POSITION_NOT_TRACKED)
		{
			vertices[i].color =  D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
		}
	}

	// Initialize the vertex buffer pointer to null first.
	verticesPtr = 0;

	// Lock the vertex buffer.
	result = m_vertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&verticesPtr);
	if(FAILED(result))
	{
		return false;
	}

	// Copy the data into the vertex buffer.
	memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType) * m_vertexCount));

	// Unlock the vertex buffer.
	m_vertexBuffer->Unmap();

	// Release the vertex array as it is no longer needed.
	delete [] vertices;
	vertices = 0;

	return true;
}
示例#5
0
bool ModelClass::InitializeBuffers(ID3D11Device* device)
{
	VertexType* vertices;
	unsigned long* indices;
	D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
	D3D11_SUBRESOURCE_DATA vertexData, indexData;
	HRESULT result;
	int i;


	// Create the vertex array.
	vertices = new VertexType[m_vertexCount];
	if(!vertices)
	{
		return false;
	}

	// Create the index array.
	indices = new unsigned long[m_indexCount];
	if(!indices)
	{
		return false;
	}

	// Load the vertex array and index array with data.
	for(i=0; i<m_vertexCount; i++)
	{
		vertices[i].position = D3DXVECTOR3(m_model[i].x, m_model[i].y, m_model[i].z);
		vertices[i].texture = D3DXVECTOR2(m_model[i].tu, m_model[i].tv);
		vertices[i].normal = D3DXVECTOR3(m_model[i].nx, m_model[i].ny, m_model[i].nz);
		vertices[i].tangent = D3DXVECTOR3(m_model[i].tx, m_model[i].ty, m_model[i].tz);
		vertices[i].binormal = D3DXVECTOR3(m_model[i].bx, m_model[i].by, m_model[i].bz);

		indices[i] = i;
	}

	// Set up the description of the static vertex buffer.
	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the vertex data.
	vertexData.pSysMem = vertices;
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	// Now create the vertex buffer.
	result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
	if(FAILED(result))
	{
		return false;
	}

	// Set up the description of the static index buffer.
	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;
	indexBufferDesc.StructureByteStride = 0;

	// Give the subresource structure a pointer to the index data.
	indexData.pSysMem = indices;
	indexData.SysMemPitch = 0;
	indexData.SysMemSlicePitch = 0;

	// Create the index buffer.
	result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
	if(FAILED(result))
	{
		return false;
	}

	// Release the arrays now that the vertex and index buffers have been created and loaded.
	delete [] vertices;
	vertices = 0;

	delete [] indices;
	indices = 0;

	return true;
}
	D3DXVECTOR3 QuatToVec3(D3DXQUATERNION a_Quat)
	{
		return D3DXVECTOR3(a_Quat.x,a_Quat.y,a_Quat.z);
	}
示例#7
0
void Enemy::SetPos(D3DXVECTOR3 pos)
{
	obj->position = D3DXVECTOR3(pos.x,pos.y,pos.z);
	actor->setGlobalPose(PxTransform(PxVec3(pos.x,pos.y,pos.z)));
}
示例#8
0
void EditorLinePrimitive::RecalcTransforms()
{
	//Matrices we need
	D3DXMATRIX matWorld,matScale,MatRot,MatTemp;

	//Temporary translation
	D3DXVECTOR3 Trans;


	//Copy from the original location, 
	//so we can modify it without hurting anything
	Trans=Location;

	//Devide Trans through Scale
	/*Trans.x/=Scale.x;
	Trans.y/=Scale.y;
	Trans.z/=Scale.z;*/


	//Apply translation to the WorldMatrix
	D3DXMatrixTranslation(&matWorld,Trans.x,Trans.y,Trans.z);

	//Now scale another matrix
	D3DXMatrixScaling( &matScale, Scale.x, Scale.y, Scale.z );

	


	//Apply rotation
	D3DXMatrixIdentity(&MatRot);

	D3DXVECTOR3 DeltaRot = Rotation - RotationMatrixAngles;

	if(Rotation != D3DXVECTOR3(0,0,0))
	{
		// Calculate matrix with the new angles
		if(bLocalRotation)
		{
			D3DXVECTOR3 Up(0,1,0);
			D3DXVECTOR3 Front(1,0,0);
			D3DXVECTOR3 Right;
			

			D3DXVec3TransformNormal(&Up, &Up, &RotationMatrix);
			D3DXVec3TransformNormal(&Front, &Front, &RotationMatrix);
			D3DXVec3Cross(&Right, &Up, &Front);

			D3DXMATRIX X;
			D3DXMatrixRotationAxis(&X, &Front, DeltaRot.x);

			D3DXMATRIX Y;
			D3DXMatrixRotationAxis(&Y, &Up, DeltaRot.y);

			D3DXMATRIX Z;
			D3DXMatrixRotationAxis(&Z, &Right, DeltaRot.z);

			RotationMatrix *= X * Y * Z;
		}else
		{
			D3DXMatrixIdentity(&MatRot);

			D3DXMatrixRotationAxis(&MatTemp, &D3DXVECTOR3(1,0,0), Rotation.x);        // Pitch
			D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
			D3DXMatrixRotationAxis(&MatTemp, &D3DXVECTOR3(0,1,0), Rotation.y);         // Yaw
			D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
			D3DXMatrixRotationAxis(&MatTemp, &D3DXVECTOR3(0,0,1), Rotation.z);       // Roll
			D3DXMatrixMultiply(&RotationMatrix, &MatRot, &MatTemp);

			//RotationMatrix = X * Y * Z;
		}

		RotationMatrixAngles = Rotation;
	}else if(!bJustUseRotationMatrix)
	{
		// Reset matrix to identity (Todo: ROTATION! Ò.ó Y U NO WORK!? (As I want))
		D3DXMatrixIdentity(&RotationMatrix);
		RotationMatrixAngles = D3DXVECTOR3(0,0,0);
	}


	WorldMatrix = matScale * RotationMatrix * matWorld;
	
}
示例#9
0
/** Creates a box of lines */
HRESULT EditorLinePrimitive::CreateLineBoxPrimitive(D3DXVECTOR4* Color)
{
	LineVertex vx[24];

	// Bottom
	vx[0].Position = D3DXVECTOR3(-1,-1,-1);
	EncodeColor(&vx[0], Color);
	vx[1].Position = D3DXVECTOR3(1,-1,-1);
	EncodeColor(&vx[1], Color);

	vx[2].Position = D3DXVECTOR3(1,-1,-1);
	EncodeColor(&vx[2], Color);
	vx[3].Position = D3DXVECTOR3(1,-1,1);
	EncodeColor(&vx[3], Color);

	vx[4].Position = D3DXVECTOR3(1,-1,1);
	EncodeColor(&vx[4], Color);
	vx[5].Position = D3DXVECTOR3(-1,-1,1);
	EncodeColor(&vx[5], Color);

	vx[6].Position = D3DXVECTOR3(-1,-1,1);
	EncodeColor(&vx[6], Color);
	vx[7].Position = D3DXVECTOR3(-1,-1,-1);
	EncodeColor(&vx[7], Color);

	// Sides | | | |

	vx[8].Position = D3DXVECTOR3(-1,-1,-1);
	EncodeColor(&vx[8], Color);
	vx[9].Position = D3DXVECTOR3(-1,1,-1);
	EncodeColor(&vx[9], Color);

	vx[10].Position = D3DXVECTOR3(1,-1,-1);
	EncodeColor(&vx[10], Color);
	vx[11].Position = D3DXVECTOR3(1,1,-1);
	EncodeColor(&vx[11], Color);

	vx[12].Position = D3DXVECTOR3(1,-1,1);
	EncodeColor(&vx[12], Color);
	vx[13].Position = D3DXVECTOR3(1,1,1);
	EncodeColor(&vx[13], Color);

	vx[14].Position = D3DXVECTOR3(-1,-1,1);
	EncodeColor(&vx[14], Color);
	vx[15].Position = D3DXVECTOR3(-1,1,1);
	EncodeColor(&vx[15], Color);

	// Top
	vx[16].Position = D3DXVECTOR3(-1,1,-1);
	EncodeColor(&vx[16], Color);
	vx[17].Position = D3DXVECTOR3(1,1,-1);
	EncodeColor(&vx[17], Color);

	vx[18].Position = D3DXVECTOR3(1,1,-1);
	EncodeColor(&vx[18], Color);
	vx[19].Position = D3DXVECTOR3(1,1,1);
	EncodeColor(&vx[19], Color);

	vx[20].Position = D3DXVECTOR3(1,1,1);
	EncodeColor(&vx[20], Color);
	vx[21].Position = D3DXVECTOR3(-1,1,1);
	EncodeColor(&vx[21], Color);

	vx[22].Position = D3DXVECTOR3(-1,1,1);
	EncodeColor(&vx[22], Color);
	vx[23].Position = D3DXVECTOR3(-1,1,-1);
	EncodeColor(&vx[23], Color);

	HRESULT hr;
	LE(CreatePrimitive(vx, 24));

	return hr;
}
示例#10
0
/** Creates a solid box */
HRESULT EditorLinePrimitive::CreateSolidBoxPrimitive(D3DXVECTOR4* Color, float Extends)
{
	LineVertex vx[36];
	int i=0;

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,-1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,-1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	vx[i].Position = D3DXVECTOR3(-1,1,1);
	EditorLinePrimitive::EncodeColor(&vx[i++], Color);

	// Loop through all vertices and apply the extends
	for(i = 0; i < 36; i++)
	{
		*(D3DXVECTOR4 *)&vx[i].Position *= Extends;
	}

	HRESULT hr;
	LE(CreateSolidPrimitive(&vx[0], 36));

	return hr;
}
示例#11
0
/** Creates a plate, not of lines. Can't use intersection on this*/
HRESULT EditorLinePrimitive::CreateFilledCirclePrimitive(float Radius, UINT Detail, const D3DXVECTOR4* Color, int Axis)
{
	UINT NumVerts = Detail*3;
	LineVertex* vx = new LineVertex[NumVerts];

	float Step = (D3DX_PI*2)/((float)(Detail)-1);
	float s = 0;

	int i=0;
	while(i < NumVerts)
	{
		switch(Axis)
		{
		case 0:
			// XZ-Axis
			vx[i].Position = D3DXVECTOR3(sinf(s), 0, cosf(s));
			break;
		
		case 1:
			// YZ-Axis
			vx[i].Position = D3DXVECTOR3(0, sinf(s), cosf(s));
			break;

		case 2:
			// ZY-Axis
			vx[i].Position = D3DXVECTOR3(sinf(s), cosf(s), 0);
			break;
		}
		EncodeColor(&vx[i], Color);
		s+=Step;
		i++;


		switch(Axis)
		{
		case 0:
			// XZ-Axis
			vx[i].Position = D3DXVECTOR3(sinf(s), 0, cosf(s));
			break;
		
		case 1:
			// YZ-Axis
			vx[i].Position = D3DXVECTOR3(0, sinf(s), cosf(s));
			break;

		case 2:
			// ZY-Axis
			vx[i].Position = D3DXVECTOR3(sinf(s), cosf(s), 0);
			break;
		}
		EncodeColor(&vx[i], Color);
		//s+=Step;
		i++;

		vx[i].Position = D3DXVECTOR3(0, 0, 0);
		EncodeColor(&vx[i], Color);
		i++;

	}

	HRESULT hr = CreatePrimitive(vx, NumVerts, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	delete[] vx;
	return hr;
}
示例#12
0
/**
* CAIManager::spawnGroup
* @date Modified May 30, 2006
*/
void CAIManager::spawnGroup(EObjectType eType, D3DXVECTOR3 vPos, int nNum)
{
	CObjectManager* poObjectManager = CObjectManager::getInstancePtr();

	// these values can be different for each enemy type that is being spawned
	// based on the specific models being used
	D3DXVECTOR3 vScale, vOrientation(((float)(rand()%100))+1.0f, 0.0f, ((float)(rand()%100))+1.0f);
	D3DXVec3Normalize(NULL, &vOrientation, &vOrientation);
	float fBVHeight = 0.0f, fBVRadius = 0.0f;
	switch (eType)
	{
	case OBJ_ENEMY_ZOMBIECITIZEN:
		vScale = D3DXVECTOR3(0.5f, 0.5f, 0.5f);
		fBVHeight = 15.0f;
		fBVRadius = 3.0f;
		break;
	case OBJ_ENEMY_GASEOUSCLAY:
		vScale = D3DXVECTOR3(0.75f, 0.75f, 0.75f);
		fBVHeight = 15.0f;
		fBVRadius = 4.0f;
		break;
	case OBJ_ENEMY_ICECREAMMAN:
		vScale = D3DXVECTOR3(0.75f, 0.75f, 0.75f);
		fBVHeight = 15.0f;
		fBVRadius = 4.0f;
		break;
	case OBJ_ENEMY_QUARTERBACK:
		vScale = D3DXVECTOR3(0.75f, 0.75f, 0.75f);
		fBVHeight = 15.0f;
		fBVRadius = 4.0f;
		break;
	}

	// make the new group, local variable problem is not an issue because the newGroup gets pushed into the list
	CAIGroup newGroup;
	newGroup.setAvgPos(vPos);

	// set the center enemy attributes
	CEnemy* newEnemy = (CEnemy*)poObjectManager->createObject(eType);
	newEnemy->setPosition(vPos);
	newEnemy->setBV(D3DXVECTOR3(newEnemy->getPosition().x, fBVHeight, newEnemy->getPosition().z), fBVRadius);
	newEnemy->setActorMatrix(vOrientation, newEnemy->getPosition(), vScale);
	newGroup.getEnemies()->push_back(newEnemy);

	int nNumCreated = 1, nCurrentRing = 0;
	float fRadius = SPAWN_SPACEING, fAngle = 0.0f, fEnemyWidth = newEnemy->getBV().fRadius * 2.0f, fAngleChange = 0.0f;
	// for truncation
	int nNumInRing = (int)((fRadius*2.0f*3.14159f)/fEnemyWidth);
	++nNumInRing;
	fAngleChange = (2.0f*3.14159f)/(float)nNumInRing;

	while (nNumCreated < nNum)
	{
		// another ring
		if (nCurrentRing == nNumInRing)
		{
			fRadius += SPAWN_SPACEING;
			// update offset
			nNumInRing = (int)((fRadius*2.0f*3.14159f)/fEnemyWidth);
			++nNumInRing;
			fAngleChange = (2.0f*3.14159f)/(float)nNumInRing;
			nCurrentRing = 0;
		}

		CEnemy* newEnemy = (CEnemy*)poObjectManager->createObject(eType);
		newEnemy->setPosition(D3DXVECTOR3(vPos.x + (fRadius * cos(fAngle)), vPos.y, vPos.z + (fRadius * sin(fAngle))));
		newEnemy->setBV(D3DXVECTOR3(newEnemy->getPosition().x, fBVHeight, newEnemy->getPosition().z), fBVRadius);
		newEnemy->setActorMatrix(vOrientation, newEnemy->getPosition(), vScale);
		newGroup.getEnemies()->push_back(newEnemy);

		// keep going around the circle
		fAngle += fAngleChange;
		++nNumCreated;
		++nCurrentRing;
	}

	m_loGroups.push_back(newGroup);
	m_loGroups.back().updateLeader(true);

	// AwesomeTime code
	CObjectManager::ObjectList loPlayers;
	CObjectManager::getInstance().getObjects(OBJ_PLAYER, &loPlayers);
	((CPlayer*)(loPlayers.front()))->m_oStats.addEnemiesSpawned((unsigned int)nNum);
	if(((CPlayer*)(loPlayers.front()))->isAwesome()) ((CPlayer*)(loPlayers.front()))->m_oStats.addAwesomeEnemiesSpawned(nNum);

	// Play spawn sound
	CSoundManager::getInstance().playSound(SND_EFFECT_ZOMBIESPAWN);
}
示例#13
0
/**
* CAIManager::updateCurrentObjective
* @date Modified June 2, 2006
*/
void CAIManager::updateCurrentObjective(void)
{
	// if we don't have an objective we need to find the first one
	if (m_poCurrentObjective == NULL)
	{
		CObjectManager::ObjectList loObjectives;
		CObjectManager::getInstance().getObjects(OBJ_OBJECTIVE_TRIGGER, &loObjectives);
		CObjectManager::ObjectList::iterator oObjectiveIter = loObjectives.begin();
		while (oObjectiveIter != loObjectives.end())
		{
			if (((CObjectiveTrigger*)(*oObjectiveIter))->m_unOrderNumber == 0)
			{
				m_poCurrentObjective = ((CObjectiveTrigger*)(*oObjectiveIter));
				D3DXVECTOR3 pos = m_poCurrentObjective->getPosition();
				pos.y += 5.0f;
				m_poObjectiveEmitter->setActorMatrix(m_poCurrentObjective->getOrientation(), pos, D3DXVECTOR3(1,1,1));
				m_poObjectiveEmitter->play();

				// if this is a OJT_GOTO activate the barriers
				if (m_poCurrentObjective->m_eObjectiveType == CObjectiveTrigger::OJT_GOTO)
				{
					if (!m_poCurrentObjective->m_loBarriers.empty())
					{
						// activate the barriers
						std::list<CObjectiveBarrier*>::iterator oBarrierIter = m_poCurrentObjective->m_loBarriers.begin();
						while (oBarrierIter != m_poCurrentObjective->m_loBarriers.end())
						{
							((CObjectiveBarrier*)(*oBarrierIter))->activate();
							((CObjectiveBarrier*)(*oBarrierIter))->setMesh((CMesh*)CResourceManager::getInstance().loadResource(RES_MESH, "roadBlockSign.x"));
							((CObjectiveBarrier*)(*oBarrierIter))->m_pExplosion->setActorMatrix(((CObjectiveBarrier*)(*oBarrierIter))->getOrientation(), ((CObjectiveBarrier*)(*oBarrierIter))->getPosition(), ((CObjectiveBarrier*)(*oBarrierIter))->getScale());
							((CObjectiveBarrier*)(*oBarrierIter))->m_pExplosion->play();
							oBarrierIter++;
						}

						int nRand = rand() % 3;
						switch (nRand)
						{
						case 0:
							CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION1);
							break;
						case 1:
							CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION2);
							break;
						case 2:
							CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION3);
							break;
						default:
							break;
						}
					}
				}
				break;
			}
			oObjectiveIter++;
		}

		// if we couldn't find it just get out of here
		if (m_poCurrentObjective == NULL)
			return;
	}

	// check for people trying to cheat
	if (m_poCurrentObjective->m_eObjectiveType == CObjectiveTrigger::OJT_GOTO && m_bSkipCurrentObjective)
	{
		m_poCurrentObjective->m_bTriggered = true;
	}

	// if it isn't triggered check to see if it can be
	if (!m_poCurrentObjective->m_bTriggered)
	{
		m_poCurrentObjective->checkTriggerActivate();
	}

	// check to see if it has been triggered because it could have been updated by the function call above
	if (m_poCurrentObjective->m_bTriggered)
	{
		m_poObjectiveEmitter->pause();
		// if it is complete we can move to the next trigger
		if (m_poCurrentObjective->checkTriggerComplete(m_bSkipCurrentObjective))
		{
			// if this was the goal objective we are done
			if (m_poCurrentObjective->m_bGoal)
			{
				CGameKernel::getInstance().changeState(CWinState::getInstancePtr());
				return;
			}
			else
			{
				// find the next goal
				CObjectManager::ObjectList loObjectives;
				CObjectManager::getInstance().getObjects(OBJ_OBJECTIVE_TRIGGER, &loObjectives);
				CObjectManager::ObjectList::iterator oObjectiveIter = loObjectives.begin();
				unsigned int unNextObjective = m_poCurrentObjective->m_unOrderNumber + 1;
				m_poCurrentObjective = NULL;
				while (oObjectiveIter != loObjectives.end())
				{
					if (((CObjectiveTrigger*)(*oObjectiveIter))->m_unOrderNumber == unNextObjective)
					{
						m_poCurrentObjective = ((CObjectiveTrigger*)(*oObjectiveIter));
						D3DXVECTOR3 pos = m_poCurrentObjective->getPosition();
						pos.y += 5.0f;
						m_poObjectiveEmitter->setActorMatrix(m_poCurrentObjective->getOrientation(),pos, D3DXVECTOR3(1,1,1));
						m_poObjectiveEmitter->play();

						// if this is a OJT_GOTO activate the barriers
						if (m_poCurrentObjective->m_eObjectiveType == CObjectiveTrigger::OJT_GOTO)
						{
							if (!m_poCurrentObjective->m_loBarriers.empty())
							{
								// activate the barriers
								std::list<CObjectiveBarrier*>::iterator oBarrierIter = m_poCurrentObjective->m_loBarriers.begin();
								while (oBarrierIter != m_poCurrentObjective->m_loBarriers.end())
								{
									((CObjectiveBarrier*)(*oBarrierIter))->activate();
									((CObjectiveBarrier*)(*oBarrierIter))->setMesh((CMesh*)CResourceManager::getInstance().loadResource(RES_MESH, "roadBlockSign.x"));
									((CObjectiveBarrier*)(*oBarrierIter))->m_pExplosion->setActorMatrix(((CObjectiveBarrier*)(*oBarrierIter))->getOrientation(), ((CObjectiveBarrier*)(*oBarrierIter))->getPosition(), ((CObjectiveBarrier*)(*oBarrierIter))->getScale());
									((CObjectiveBarrier*)(*oBarrierIter))->m_pExplosion->play();
									oBarrierIter++;
								}

								int nRand = rand() % 3;
								switch (nRand)
								{
								case 0:
									CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION1);
									break;
								case 1:
									CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION2);
									break;
								case 2:
									CSoundManager::getInstance().playSound(SND_EFFECT_EXPLOSION3);
									break;
								default:
									break;
								}
							}
						}

						break;
					}
					oObjectiveIter++;
				}

				// if we couldn't find it just get out of here
				if (m_poCurrentObjective == NULL)
					return;
			}
		}
	}

}
示例#14
0
/**
* CAIManager::update
* @date Modified April 26, 2006
*/
void CAIManager::update(void)
{
	// go to the object manager and get the players and update the nodes corresponding to them
	CObjectManager* poObjectManager = CObjectManager::getInstancePtr();
	CObjectManager::ObjectList loPlayers;
	poObjectManager->getObjects(OBJ_PLAYER, &loPlayers);
	CObjectManager::ObjectList::iterator oPlayerIter = loPlayers.begin();

	// now that we have the players, check to see it there are any cluckin bombs to add as goals
	CObjectManager::ObjectList loBombs;
	poObjectManager->getObjects(OBJ_WEAPON_BIGCLUCKINGBOMB, &loBombs);
	CObjectManager::ObjectList::iterator oBombIter = loBombs.begin();
	while (oBombIter != loBombs.end())
	{
		loPlayers.push_back((*oBombIter));
		oBombIter++;
	}

	std::list<CAINode*>::iterator oNodeIter = m_loGoals.begin();

	bool bUpdateGoalLinks = false;
	if (m_bUpdateGoalLinks)
	{
		bUpdateGoalLinks = true;
		m_bUpdateGoalLinks = false;
	}

	while (oNodeIter != m_loGoals.end() && oPlayerIter != loPlayers.end())
	{
		// to cover the case of a big cluckin bomb, keep the goal node off the ground
		(*oNodeIter)->setPosition(D3DXVECTOR3(ACTOR_PTR(oPlayerIter)->getBV().centerPt.x, ((CPlayer*)loPlayers.front())->getBV().centerPt.y, ACTOR_PTR(oPlayerIter)->getBV().centerPt.z));

		if (bUpdateGoalLinks)
		{
			unlinkNode(*oNodeIter);
			linkNode(*oNodeIter);
		}			

		oNodeIter++;
		oPlayerIter++;
	}

	// cases where a player quits
	if (oNodeIter != m_loGoals.end())
	{
		while (oNodeIter != m_loGoals.end())
		{
			unlinkNode(*oNodeIter);
			delete *oNodeIter;
			oNodeIter = m_loGoals.erase(oNodeIter);
		}
	}
	
	// case where a player joins
	if (oPlayerIter != loPlayers.end())
	{
		while (oPlayerIter != loPlayers.end())
		{
			CAINode* newNode = new CAINode;
			// to cover the case of a big cluckin bomb, keep the goal node off the ground
			newNode->setPosition(D3DXVECTOR3(ACTOR_PTR(oPlayerIter)->getBV().centerPt.x, ((CPlayer*)loPlayers.front())->getBV().centerPt.y, ACTOR_PTR(oPlayerIter)->getBV().centerPt.z));
			newNode->setRadius(1.0f);
			m_loGoals.push_back(newNode);
			linkNode(newNode);
			oPlayerIter++;
		}
	}

	updateGroupLeaders();
	updateSpawnTriggers();
	updateCurrentObjective();

	// make sure this gets reset every time or the objectives will skip to gameover
	m_bSkipCurrentObjective = false;
}
示例#15
0
Vector3f Camera::screenToWorld(const Vector2f& pos) {
	
	mat4 ma1 = m_View * m_Proj;
	mat4 inv1 = matrix::mat4Inverse(ma1);

	Vector4f in;
	in.x = (pos.x - 1024.0f) / 1024.0f;
	in.y = (768.0f - pos.y) / 768.0f;
	in.z = 1.0f;
	in.w = 1.0;

	// Map to range -1 to 1
	in.x = in.x * 2.0 - 1.0;
	in.y = in.y * 2.0 - 1.0;
	in.z = in.z * 2.0 - 1.0;

	Vector4f o4 = inv1 * in;
	o4 *= 1.0f / o4.w;
	/*
	//Vector4f ndc(2 * pos.x / 1024 - 1,2 * (768 - pos.y) / 768 - 1,1, 1);

	Vector3f ndc(2 * pos.x / 1024 - 1, 2 * (768 - pos.y) / 768 - 1, 1);

	Vector3f tmp = m * ndc;
	//tmp *= 1.0f / tmp.w;

	return Vector3f(tmp.x, tmp.y, tmp.z);
	*/
	
	/*
	Vector3f v;
	v.x = (((2.0f * pos.x) / 1024) - 1) / m_Proj._11;
	v.y = (-2.0f * pos.y / 768 + 1) / m_Proj._22;
	v.z = 1.0f;

	//LOG << "v: " << DBG_V3(v);

	mat4 matInvView = matrix::mat4Inverse(m_View);

	//Vector4f ndc((2 * (pos.x - 1024)) / 1024 - 1,(2 * (768 - pos.y)) / 768 - 1, 0, 1);

	Vector3f rayDir = matInvView * v;

	Vector3f rayOrigin;

	rayOrigin.x = matInvView._41;
	rayOrigin.y = matInvView._42;
	rayOrigin.z = matInvView._43;
	//LOG << "v: " << DBG_V3(v);
	return rayDir;
	*/


	D3DXMATRIX tm;
	D3DXMatrixPerspectiveFovLH(&tm, 0.25f*PI, 1024.0f / 768.0f, 0.1f, 1000.0f);
	mat4 m = m_View;// *m_Proj;
	mat4 inv = matrix::mat4Inverse(m_Proj);
	D3DXMATRIX itm;
	D3DXMatrixInverse(&itm,NULL,&tm);

	D3DXMATRIX viewMatrix;
	D3DXMatrixLookAtLH(&viewMatrix,
		&D3DXVECTOR3(0.0f, 0.0f, -16.0f), //position
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f), //Look at
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));

	D3DXMATRIX worldMatrix;
	D3DXMatrixIdentity(&worldMatrix);

	D3DXMATRIX m1, m2, m3;
	D3DXVECTOR3 vvec,outv;
	D3DXMatrixMultiply(&m1, &worldMatrix, &viewMatrix);
	D3DXMatrixMultiply(&m2, &m1, &tm);
	D3DXMatrixInverse(&m3, NULL, &m2);
	vvec.x = 2.0f * (pos.x - 1024.0f) / 1024.0f - 1.0f;
	vvec.y = 1.0f - 2.0f * (pos.y - 768.0f) / 768.0f;
	vvec.z = 1.0f;// (pv->z - pviewport->MinZ) / (pviewport->MaxZ - pviewport->MinZ);
	D3DXVec3TransformCoord(&outv, &vvec, &m3);

	//LOG << "screen pos: " << DBG_V2(pos);
	Vector3f vec;
	vec.x = (((2.0f * pos.x) / 1024.0f) - 1.0f);// / m_Proj._11;
	vec.y = -(((2.0f * pos.y) / 768.0f) - 1.0f);// / m_Proj._22;

	//vec.x = (2.0f * pos.x - 1024.0f) / 1024.0f - 1.0f;
	//vec.y = 1.0f - (2.0f * pos.y - 768.0f) / 768.0f;
	vec.z = 1.0f;// (pos.z - 0.1) / (1000 - pviewport->MinZ);
	Vector3f pout = vec * inv;
	//D3DXVec3TransformCoord(pout, &vec, &inv);
	return vec;
	
}
示例#16
0
bool GraphicsClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
	bool result;

	//如果对象已经存在,先释放掉它们
	ShutDown();

	// 创建一个D3DClass对象
	m_D3D = new D3DClass;
	if(!m_D3D)
		return false;

	// 调用D3DClass初始化函数 
	result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, 
		SCREEN_DEPTH, SCREEN_NEAR);
	if(!result)
	{
		MessageBox(hwnd, TEXT("Could not initialize Direct3D"), TEXT("Error"), MB_OK); 
		return false; 
	}

	//创建摄像机对象
	m_Camera = new CameraClass;
	if(!m_Camera)
		return false;

	// 设置摄像机位置
	D3DXVECTOR3 campos = D3DXVECTOR3(0.0f, 0.0f, -10.0f);
	m_Camera->setPosition(&campos);

	// 创建模型对象
	m_Model = new ModelClass;
	if(!m_Model)
		return false;

	// 初始化模型对象
	result = m_Model->Initialize(m_D3D->GetDevice(), 300, 300, 1.0f);
	if(!result)
	{
		MessageBox(hwnd, TEXT("Could not initialize the model object."), TEXT("Error"), MB_OK);
		return false;
	}

	// 创轴建模型对象
	m_AxisModel = new AxisModelClass;
	if(!m_AxisModel)
		return false;

	// 初始化坐标轴模型对象
	result = m_AxisModel->Initialize(m_D3D->GetDevice());
	if(!result)
	{
		MessageBox(hwnd, TEXT("Could not initialize the axis model object."), TEXT("Error"), MB_OK);
		return false;
	}

	// 创建shader对象
	m_ColorShader = new ColorShaderClass;
	if(!m_ColorShader)
		return false;

	// 初始化shader对象
	result = m_ColorShader->Initialize(m_D3D->GetDevice(), hwnd);
	if(!result)
	{
		MessageBox(hwnd, TEXT("Could not initialize the color shader object."), TEXT("Error"), MB_OK);
		return false;
	}

	return true;
}
示例#17
0
void cPlayer::Update(float delta){
	
	if (GetKeyState(VK_SPACE) & 0x8000 && m_eCurrAnim != E_ANIM_ATTACK){
		m_fAttackAnimationTime += delta;
		m_eCurrAnim = E_ANIM_ATTACK;
		m_pRoot->SetState(cPart::eAnimationPT::E_STATE_ATTACK);
	}
	else if (m_eCurrAnim == E_ANIM_ATTACK){	// 공격중인 상태일때
		m_fAttackAnimationTime += delta;
	
		if (m_fAttackAnimationTime > 0.180f && m_bAttacked == false){
			// Attack triggered (callback) 0.125sec
			m_bAttacked = true;
			//m_pGame->CollisionCheck(this);
		}
		else if (m_fAttackAnimationTime > 0.25f){
			m_bAttacked = false;
			m_fAttackAnimationTime = 0;
			m_eCurrAnim = E_ANIM_IDLE;
			m_pRoot->SetState(cPart::eAnimationPT::E_STATE_IDLE);
			m_pRoot->SetForcedXangle(D3DXToRadian(240.0f));
		}
	}
	else { // 공격 상태중이 아닐때
		if (GetKeyState('A') & 0x8000)
		{
			m_fAngle -= 4.0f * delta;
			D3DXMATRIXA16 matR;
			D3DXMatrixRotationY(&matR, m_fAngle);
			m_vForward = D3DXVECTOR3(0, 0, 1);
			D3DXVec3TransformNormal(&m_vForward, &m_vForward, &matR);
		}
		else if (GetKeyState('D') & 0x8000)
		{
			m_fAngle += 4.0f * delta;
			D3DXMATRIXA16 matR;
			D3DXMatrixRotationY(&matR, m_fAngle);
			m_vForward = D3DXVECTOR3(0, 0, 1);
			D3DXVec3TransformNormal(&m_vForward, &m_vForward, &matR);
		}

		if (GetKeyState('W') & 0x8000)
		{
			m_eCurrAnim = E_ANIM_WALK;
			m_pRoot->SetState(cPart::eAnimationPT::E_STATE_WALK);
			m_vPosition += (m_vForward * m_fSpeed * delta);
		}
		else if (GetKeyState('S') & 0x8000)
		{
			m_eCurrAnim = E_ANIM_WALK;
			m_pRoot->SetState(cPart::eAnimationPT::E_STATE_WALK);
			m_vPosition -= (m_vForward * m_fSpeed * delta);
		}
		else
		{
			m_eCurrAnim = E_ANIM_IDLE;
			m_pRoot->SetState(cPart::eAnimationPT::E_STATE_IDLE);
		}

	}

	if (m_eCurrAnim == E_ANIM_IDLE)
	{
		m_pRoot->SetForcedAngle(0.0f);
	}

	D3DXMATRIXA16 matR, matT, matWorld;
	D3DXMatrixRotationY(&matR, m_fAngle);
	D3DXMatrixTranslation(&matT, m_vPosition.x, m_vPosition.y, m_vPosition.z);
	matWorld = matR * matT;

	m_pRoot->Update(delta, &matWorld);
}
示例#18
0
HRESULT KG3DSelector::OnRender()
{
	HRESULT hRetCode = E_FAIL;
	HRESULT hResult = E_FAIL;
	D3DLOCKED_RECT Rect;
	LPDIRECT3DSURFACE9 pResultColor = NULL;
	LPDIRECT3DSURFACE9 pStencilRT = NULL;
	D3DVIEWPORT9 vp;
	D3DVIEWPORT9 vpNew;
	KG3DRenderState RenderState;
	DWORD dwSelectIndex = 0xff;
	g_pd3dDevice->GetViewport(&vp);
		
	vpNew = vp;
	vpNew.X /= m_nScale;
	vpNew.Y /= m_nScale;
	vpNew.Width /= m_nScale;
	vpNew.Height /= m_nScale;
	
	m_dwIndex = 0;//Stencil Index清零
	KG_PROCESS_SUCCESS(!m_vecModels.size());
		
	hResult = g_pd3dDevice->GetRenderTarget(0, &m_pRTSave);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->GetDepthStencilSurface(&m_pDepthSave);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = m_pStencilRT->GetSurfaceLevel(0, &pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetRenderTarget(0, pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetDepthStencilSurface(m_pStencilDepth);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 1L);
	KG_COM_PROCESS_ERROR(hResult);
	
	g_pd3dDevice->SetViewport(&vpNew);

	RenderModelList();
	
	if (0)
	{
		D3DXSaveTextureToFile("d:\\test.tga", D3DXIFF_TGA, m_pStencilRT, NULL);
	}

	hResult = g_pd3dDevice->SetTexture(0, m_pStencilRT);
	KG_COM_PROCESS_ERROR(hResult);

	g_pd3dDevice->SetTexture(1, NULL);

	hResult = g_pd3dDevice->SetDepthStencilSurface(NULL);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetRenderTarget(0, m_pRT);
	KG_COM_PROCESS_ERROR(hResult);
	
	RenderState.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

	float fU = float(m_MousePoint.x) / m_nWidth ;
	float fV = float(m_MousePoint.y) / m_nHeight;

	ScreenRect[0].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[1].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[2].vec2UV = D3DXVECTOR2(fU, fV);
	ScreenRect[3].vec2UV = D3DXVECTOR2(fU, fV);

	hResult = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 1L);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->SetFVF(SelectorVertex::dwFVF);
	KG_COM_PROCESS_ERROR(hResult);

	RenderState.SetRenderState(D3DRS_FOGENABLE, FALSE);
	RenderState.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	RenderState.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	RenderState.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	RenderState.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

	hResult = g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, ScreenRect, sizeof(SelectorVertex));
	KG_COM_PROCESS_ERROR(hResult);

	hResult = m_pResult->GetSurfaceLevel(0, &pResultColor);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = g_pd3dDevice->GetRenderTargetData(m_pRT, pResultColor);
	KG_COM_PROCESS_ERROR(hResult);

	hResult = pResultColor->LockRect(&Rect, NULL, 0);
	KG_COM_PROCESS_ERROR(hResult);

	BYTE *pBit = (BYTE*)Rect.pBits;
	dwSelectIndex = *(pBit + 2);

	pResultColor->UnlockRect();
	KG_COM_PROCESS_ERROR(hResult);

	if (dwSelectIndex != 0xff)
	{
		_ASSERTE(dwSelectIndex < m_vecModels.size());
		m_pSelectedModel = m_vecModels[dwSelectIndex];
	}
	else
	{
		//模糊选择, 在所有的模型都没有精确选中的时候, 选中离镜头最近的那一个
		D3DXVECTOR3 vec3CamPos;
		float fNear = 9999999999.f;
		DWORD dwNear = 0xffffffff;
		g_cGraphicsTool.GetCamera()->GetPosition(&vec3CamPos);
		for (size_t i = 0; i < m_vecModels.size(); i++)
		{
			D3DXVECTOR3 vec3Length = vec3CamPos - D3DXVECTOR3(m_vecModels[i]->m_matWorld._41, 
				m_vecModels[i]->m_matWorld._42, 
				m_vecModels[i]->m_matWorld._43);
			
			float fLength = vec3Length.x * vec3Length.x + vec3Length.y * vec3Length.y + vec3Length.z * vec3Length.z;
			if (fLength < fNear)
			{
				fNear = fLength;
				dwNear = static_cast<DWORD>(i);
			}
		}
		m_pSelectedModel = m_vecModels[dwNear];
	}

	m_bSelected = TRUE;

Exit1:
	hRetCode = S_OK;
Exit0:
	
	if (!m_bSelected)
	{
		m_pSelectedModel = NULL;
	}
		
	m_vecModels.clear();
	SAFE_RELEASE(pStencilRT);
	SAFE_RELEASE(pResultColor);
	if (m_pRTSave)
	{
		g_pd3dDevice->SetRenderTarget(0, m_pRTSave);
	}
	if (m_pDepthSave)
	{
		g_pd3dDevice->SetDepthStencilSurface(m_pDepthSave);
		g_pd3dDevice->SetViewport(&vp);
	}
	
	SAFE_RELEASE(pResultColor);
	SAFE_RELEASE(m_pRTSave);
	SAFE_RELEASE(m_pDepthSave);
	return hRetCode;
}
示例#19
0
void Enemy::Update(float dT)
{
	UpdateBullets(dT);
	obj->Update(dT);
	if(!isDead)
	{
		currentMoveTime += dT;
		if(currentMoveTime > movementSwitchTime)
		{
			currentMoveTime = 0;
			float xspeed = rand()% (int)ceil(movementSpeed); //getal van 0 tot 10
			float xfSpeed = xspeed - (int)ceil(movementSpeed)/2; // getal van -5 tot 5
			float zspeed = rand()%(int)ceil(movementSpeed); //getal van 0 tot 10
			float zfSpeed = zspeed -(int)ceil( movementSpeed)/2; // getal van -5 tot 5
			
			moveDir = D3DXVECTOR3(xfSpeed, 0, zfSpeed);
		}
		PxVec3 pos = actor->getGlobalPose().p;
		PxVec3 pDir = (playerPos - pos);
		pDir.y = 0;
		pDir.normalize();
		PxVec3 target = PxVec3(moveDir.x,0,moveDir.z);
		float angle = 90 - (90 * pDir.dot(target.getNormalized())) - 90; //mapping range 1 to -1 into 0-180 if desirable
		playerRight.y = 0;
		float direction = playerRight.dot(target.getNormalized());
		if(direction < 0 && angle > -45 && angle < 45)
		{
			angle = -angle;		
		}
		Object2D::Animation* cAnim = obj->GetCurrentAnim();
		Object2D::Animation anim;
		if(angle < -45)
		{
			cMState = MovementState::Forward; 
			anim = obj->GetAnimation("WalkForward");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkForward");
			}	
		}
		if(angle > -45 && angle < 0 && direction < 0)
		{
			cMState = MovementState::Left;
			anim = obj->GetAnimation("WalkLeft");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkLeft");
			}
		}
		else if(angle > 0 && angle < 45 && direction > 0)
		{
			cMState = MovementState::Right; 
			anim = obj->GetAnimation("WalkRight");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkRight");
			}
		}
		if(angle > -45 && angle < 0 && direction > 0)
		{
			cMState = MovementState::Right; 
			anim = obj->GetAnimation("WalkRight");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkRight");
			}
		}
		else if(angle > 0 && angle < 45 && direction < 0)
		{
			cMState = MovementState::Left;
			anim = obj->GetAnimation("WalkLeft");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkLeft");
			}
		}
		if(angle > 45)
		{
			cMState = MovementState::Back;
			anim = obj->GetAnimation("WalkBack");
			if(anim.isFinished || cAnim->AnimationName.compare(anim.AnimationName) != 0)
			{
				obj->PlayAnimation("WalkBack");
			}		
		}
		CheckShooting(30,dT*1.2f);
		if(sawPlayer)
		{
			cState = Enemy::Moving;
			int i = 0;
			CheckFutureCollision(i);
			Move(moveDir,dT*movementSpeed);
		}
	}
}
示例#20
0
PropsDemo::PropsDemo(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();

	mTime = 0.0f;

	mGfxStats = new GfxStats();

	// Set path to art resources.
	SetCurrentDirectory("Art/");

	// World space units are meters.  
	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"castlehm257.raw", "grass.dds",	"dirt.dds",	
		"rock.dds", "blend_castle.dds", 0.5f, 0.0f);

	D3DXVECTOR3 toSun(-1.0f, 3.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Setup water.
	D3DXMATRIX waterWorld;
	D3DXMatrixTranslation(&waterWorld, 8.0f, 35.0f, -80.0f);
	mWater = new Water(33, 33, 20, 20, waterWorld);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(8.0f, 35.0f, -100.0f);
	gCamera->setSpeed(20.0f);
	mFreeCamera = false;

	buildCastle();
	buildTrees();
	buildGrass();

	HR(D3DXCreateTextureFromFile(gd3dDevice, "grassfin0.dds", &mGrassTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

	buildFX();

	mLight.dirW    = -toSun;
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.spec    = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
	HR(mGrassFX->SetValue(mhGrassDirToSunW, &(-mLight.dirW), sizeof(D3DXVECTOR3)));

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());
	mGfxStats->addVertices(mWater->getNumVertices());
	mGfxStats->addTriangles(mWater->getNumTriangles());
	mGfxStats->addVertices(mCastle.mesh->GetNumVertices());
	mGfxStats->addTriangles(mCastle.mesh->GetNumFaces());
	mGfxStats->addVertices(mTrees[0].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[0].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[1].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[1].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[2].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[2].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[3].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[3].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mGrassMesh->GetNumVertices());
	mGfxStats->addTriangles(mGrassMesh->GetNumFaces());

	onResetDevice();
}
示例#21
0
void Enemy::UpdateBullets(float deltaTimeF)
{
	for(unsigned int i = 0; i < bullets.size(); i++)
	{
		Bullet* bullet = bullets.at(i);
		bullet->bulletLife+=deltaTimeF;
		bullet->obj->position += bullet->direction*deltaTimeF*55;
		PxVec3 finalDir = PxVec3(bullet->direction.x,bullet->direction.y,bullet->direction.z);
		finalDir.normalize();
		PxRaycastBuffer hit = physics->RaycastSingle(PxVec3(bullet->obj->position.x,bullet->obj->position.y,bullet->obj->position.z),finalDir,2);
		if(hit.block.actor != NULL)
		{
			if(hit.block.actor == physics->player->getActor())
			{
				int damageToReceive = 15;
				if(*armour > 0)
				{
					*armour -= damageToReceive;
					if(*armour < 0)
					{
						damageToReceive = abs(*armour);
						*health -= damageToReceive;
						*armour = 0;
					}
				}
				else
				{
					*health -= damageToReceive;
				}
				if(*health > 0)
				{
					std::vector<std::string> names;
					names.push_back("SAMHIT1");
					names.push_back("SAMHIT2");
					names.push_back("SAMHIT3");
					resources->GetSoundHandler()->PlayRandom(&names);
					if(*health >= 75)
					{
						GUI::GUITexture* g = gui->GetGUIObj("Resources/GUI/Heart.png");
						if(g->currentlyPlayingAnimation.compare("100") != 0)
						{
							gui->PlayAnimation(gui->GetGUIObj("Resources/GUI/Heart.png"),"100");
						}
					}
					else if(*health < 75 && *health >= 50)
					{
						GUI::GUITexture* g = gui->GetGUIObj("Resources/GUI/Heart.png");
						if(g->currentlyPlayingAnimation.compare("75") != 0)
						{
							gui->PlayAnimation(gui->GetGUIObj("Resources/GUI/Heart.png"),"75");
						}
					}
					else if(*health < 50 && *health >= 25)
					{
						GUI::GUITexture* g = gui->GetGUIObj("Resources/GUI/Heart.png");
						if(g->currentlyPlayingAnimation.compare("50") != 0)
						{
							gui->PlayAnimation(gui->GetGUIObj("Resources/GUI/Heart.png"),"50");
						}
					}
					else if(*health < 25 && *health > 0)
					{
						GUI::GUITexture* g = gui->GetGUIObj("Resources/GUI/Heart.png");
						if(g->currentlyPlayingAnimation.compare("25") != 0)
						{
							gui->PlayAnimation(gui->GetGUIObj("Resources/GUI/Heart.png"),"25");
						}
					}
				}
				else
				{
					GUI::GUITexture* g = gui->GetGUIObj("Resources/GUI/Heart.png");
					if(g->currentlyPlayingAnimation.compare("0") != 0)
					{
						gui->PlayAnimation(gui->GetGUIObj("Resources/GUI/Heart.png"),"0");
					}
					resources->GetSoundHandler()->PlayWaveFile("SAMDIE1");
				}
				bullets.erase(bullets.begin()+i);
				bullet->obj->ReleaseResources();
				delete bullet->obj;
				delete bullet;
				return;
			}
			else if(hit.block.actor->isRigidStatic() != NULL)
			{
				bullets.erase(bullets.begin()+i);
				bullet->obj->ReleaseResources();
				delete bullet->obj;
				delete bullet;
				return;
			}

			
		}
		if(Vector3Distance(&D3DXVECTOR3(playerPos.x,playerPos.y,playerPos.z),&bullet->obj->position) > 300 && bullet->bulletLife > 2)
		{
			bullets.erase(bullets.begin()+i);
			bullet->obj->ReleaseResources();
			delete bullet->obj;
			delete bullet;
			return;
		}
	}
}
示例#22
0
int Transform::HitTest(const D3DXMATRIX& projection, const D3DXMATRIX& view, const D3DXMATRIX& model, const D3D10_VIEWPORT& vp, int type, Vec2f mousepos, Vec3f pos, IHitTest* hitTest)
{
	D3DXMATRIX transform = GetTransform();

	D3DXMATRIX model2 = model * transform;

//	D3DXVECTOR3 location(0,0,0);
//	D3DXVECTOR4 v;
//	D3DXVec3Transform(&v, &location, &transform);

	float scale = 10;

	D3DXVECTOR3 out;

	D3DXVECTOR3 _obj = *D3DXVec3Project(&out, &D3DXVECTOR3(0,0,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _xaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(scale,0,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _yaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(0,scale,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _zaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(0,0,scale), &vp, &projection, &view, &model2);

	Vec3f obj = VecProject(Vec3f(0,0,0), vp, projection, view, model2);
	Vec3f xaxis = VecProject(Vec3f(scale,0,0), vp, projection, view, model2);
	Vec3f yaxis = VecProject(Vec3f(0,scale,0), vp, projection, view, model2);
	Vec3f zaxis = VecProject(Vec3f(0,0,scale), vp, projection, view, model2);

	if (fabs(mousepos[0]-obj[0]) < 3 &&
		fabs(mousepos[1]-obj[1]) < 3)
	{
		hitTest->OnHit(this, type, *(Vec3f*)&obj);
		return 1;
	}
	else
	{
	//

		int axis = 0;

		double t;
		if (point_near_line_2d(obj, xaxis, mousepos, &t))
		{
			axis = 1;
		}
		else if (point_near_line_2d(obj, yaxis, mousepos, &t))
		{
			axis = 2;
		}
		else if (point_near_line_2d(obj, zaxis, mousepos, &t))
		{
			axis = 3;
		}

		if (axis)
		{
			hitTest->OnHit(this, type, obj, axis, t);

#if 0
			SelectedObject* p = object->m_selectedObject;
		//	p->m_object = object;
			p->m_wtransform = model;

			// ??
			if (m_document->m_objectMode == Mode_Model || m_document->m_objectMode == Mode_Axis)
				p->m_startTransform = object->m_transform->m_matrix;
			else
				p->m_startTransform = LDraw::matrix4f::getIdentity();

			p->m_z = obj[2];

			p->m_axis = axis;
			p->m_axis_t = t;

			selectedObjects.Add(p);
#endif
		}
	}

	return 0;
}
示例#23
0
void cPyramid::Setup(D3DCOLOR c, D3DXMATRIXA16* pmat)
{
	m_matWorld = (*pmat);

	ST_PC_VERTEX v;
	
	v.c = c;

	v.p = D3DXVECTOR3( 0,  0,  0); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1, -1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3(-1, -1, -1); m_vecVertex.push_back(v);

	v.p = D3DXVECTOR3( 0,  0,  0); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1,  1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1, -1); m_vecVertex.push_back(v);
	
	v.p = D3DXVECTOR3( 0,  0,  0); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3(-1, -1,  1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1,  1); m_vecVertex.push_back(v);

	v.p = D3DXVECTOR3( 0,  0,  0); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3(-1, -1, -1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3(-1, -1,  1); m_vecVertex.push_back(v);


	v.p = D3DXVECTOR3(-1, -1, -1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1, -1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1,  1); m_vecVertex.push_back(v);

	v.p = D3DXVECTOR3(-1, -1, -1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3( 1, -1,  1); m_vecVertex.push_back(v);
	v.p = D3DXVECTOR3(-1, -1,  1); m_vecVertex.push_back(v);
}
bool ModelClass::InitializeBuffers(ID3D11Device* device)
{
	
	
	unsigned long* indices;
	D3D11_BUFFER_DESC vertexBufferDesc,indexBufferDesc;
	D3D11_SUBRESOURCE_DATA vertexData,indexData;
	HRESULT result;
	
#ifdef __CHAPTER_FOUR__
	m_vertexCount = 8;
	m_indexCount = 36;

	VertexType* vertice;
	//배열 생성
	vertice = new VertexType[m_vertexCount];
	if(!vertice)
	{
		return false;
	}
#elif defined __CHAPTER_FIVE__
	m_vertexCount = 8;
	m_indexCount = 36;

	TexVertexType* vertice;
	//배열 생성
	vertice = new TexVertexType[m_vertexCount];
	if (!vertice)
	{
		return false;
	}
#elif defined __CHAPTER_SIX__
	m_vertexCount = 24;
	m_indexCount = 36;

	LightVertexType* vertice;
	//배열 생성
	vertice = new LightVertexType[m_vertexCount];
	if (!vertice)
	{
		return false;
	}
#endif

	indices = new unsigned long[m_indexCount];
	if(!indices)
	{
		return false;
	}

#ifdef __CHAPTER_FIVE__
	//정점 배열 값 저장
	vertice[0].pos = D3DXVECTOR3(-1.0f,1.0f,-1.0f);
	vertice[0].tex = D3DXVECTOR2(0.0f,0.0f);

	vertice[1].pos = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
	vertice[1].tex = D3DXVECTOR2(0.0f, 1.0f);

	vertice[2].pos = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	vertice[2].tex = D3DXVECTOR2(1.0f, 0.0f);

	vertice[3].pos = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
	vertice[3].tex = D3DXVECTOR2(1.0f, 1.0f);

	vertice[4].pos = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	vertice[4].tex = D3DXVECTOR2(0.0f, 0.0f);

	vertice[5].pos = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
	vertice[5].tex = D3DXVECTOR2(1.0f, 0.0f);

	vertice[6].pos = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	vertice[6].tex = D3DXVECTOR2(0.0f, 1.0f);

	vertice[7].pos = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
	vertice[7].tex = D3DXVECTOR2(1.0f, 1.0f);

	indices[0] = 3;
	indices[1] = 1;
	indices[2] = 0;
	indices[3] = 2;
	indices[4] = 1;
	indices[5] = 3;

	indices[6] = 0;
	indices[7] = 5;
	indices[8] = 4;
	indices[9] = 1;
	indices[10] = 5;
	indices[11] = 0;

	indices[12] = 3;
	indices[13] = 4;
	indices[14] = 7;
	indices[15] = 0;
	indices[16] = 4;
	indices[17] = 3;

	indices[18] = 1;
	indices[19] = 6;
	indices[20] = 5;
	indices[21] = 2;
	indices[22] = 6;
	indices[23] = 1;

	indices[24] = 2;
	indices[25] = 7;
	indices[26] = 6;
	indices[27] = 3;
	indices[28] = 7;
	indices[29] = 2;

	indices[30] = 6;
	indices[31] = 4;
	indices[32] = 5;
	indices[33] = 7;
	indices[34] = 4;
	indices[35] = 6;
#elif defined __CHAPTER_FOUR__
	//정점 배열 값 저장
	vertice[0].position = D3DXVECTOR3(-1.0f,1.0f,-1.0f);
	vertice[0].color = D3DXVECTOR4(0.0f,1.0f,0.0f,1.0f);

	vertice[1].position = D3DXVECTOR3(1.0f,1.0f,-1.0f);
	vertice[1].color = D3DXVECTOR4(0.0f,1.0f,0.0f,1.0f);

	vertice[2].position = D3DXVECTOR3(1.0f,1.0f,1.0f);
	vertice[2].color = D3DXVECTOR4(0.0f,1.0f,0.0f,1.0f);

	vertice[3].position = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
	vertice[3].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);

	vertice[4].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	vertice[4].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);

	vertice[5].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
	vertice[5].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);

	vertice[6].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	vertice[6].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);

	vertice[7].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
	vertice[7].color = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);

	indices[0] = 3;
	indices[1] = 1;
	indices[2] = 0;
	indices[3] = 2;
	indices[4] = 1;
	indices[5] = 3;

	indices[6] = 0;
	indices[7] = 5;
	indices[8] = 4;
	indices[9] = 1;
	indices[10] = 5;
	indices[11] = 0;

	indices[12] = 3;
	indices[13] = 4;
	indices[14] = 7;
	indices[15] = 0;
	indices[16] = 4;
	indices[17] = 3;

	indices[18] = 1;
	indices[19] = 6;
	indices[20] = 5;
	indices[21] = 2;
	indices[22] = 6;
	indices[23] = 1;

	indices[24] = 2;
	indices[25] = 7;
	indices[26] = 6;
	indices[27] = 3;
	indices[28] = 7;
	indices[29] = 2;

	indices[30] = 6;
	indices[31] = 4;
	indices[32] = 5;
	indices[33] = 7;
	indices[34] = 4;
	indices[35] = 6;
#elif defined __CHAPTER_SIX__
	vertice[0].pos = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
	vertice[0].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[0].nom = D3DXVECTOR3(0.0f, 1.0f, 0.0f);


	vertice[1].pos = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
	vertice[1].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[1].nom = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

	vertice[2].pos = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	vertice[2].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[2].nom = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

	vertice[3].pos = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
	vertice[3].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[3].nom = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

	//2
	vertice[4].pos = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	vertice[4].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[4].nom = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

	vertice[5].pos = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
	vertice[5].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[5].nom = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

	vertice[6].pos = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	vertice[6].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[6].nom = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

	vertice[7].pos = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
	vertice[7].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[7].nom = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

	//3
	vertice[8].pos = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
	vertice[8].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[8].nom = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);

	vertice[9].pos = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	vertice[9].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[9].nom = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);

	vertice[10].pos = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
	vertice[10].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[10].nom = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);

	vertice[11].pos = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
	vertice[11].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[11].nom = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);

	//4
	vertice[12].pos = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	vertice[12].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[12].nom = D3DXVECTOR3(1.0f, 0.0f, 0.0f);

	vertice[13].pos = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
	vertice[13].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[13].nom = D3DXVECTOR3(1.0f, 0.0f, 0.0f);

	vertice[14].pos = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
	vertice[14].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[14].nom = D3DXVECTOR3(1.0f, 0.0f, 0.0f);

	vertice[15].pos = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	vertice[15].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[15].nom = D3DXVECTOR3(1.0f, 0.0f, 0.0f);

	//5
	vertice[16].pos = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
	vertice[16].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[16].nom = D3DXVECTOR3(0.0f, 0.0f, -1.0f);

	vertice[17].pos = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
	vertice[17].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[17].nom = D3DXVECTOR3(0.0f, 0.0f, -1.0f);

	vertice[18].pos = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
	vertice[18].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[18].nom = D3DXVECTOR3(0.0f, 0.0f, -1.0f);

	vertice[19].pos = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
	vertice[19].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[19].nom = D3DXVECTOR3(0.0f, 0.0f, -1.0f);

	//
	vertice[20].pos = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
	vertice[20].tex = D3DXVECTOR2(0.0f, 0.0f);
	vertice[20].nom = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

	vertice[21].pos = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	vertice[21].tex = D3DXVECTOR2(1.0f, 0.0f);
	vertice[21].nom = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

	vertice[22].pos = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	vertice[22].tex = D3DXVECTOR2(0.0f, 1.0f);
	vertice[22].nom = D3DXVECTOR3(0.0f, 0.0f, 1.0f);

	vertice[23].pos = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
	vertice[23].tex = D3DXVECTOR2(1.0f, 1.0f);
	vertice[23].nom = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
	
	indices[0] = 3;
	indices[1] = 1;
	indices[2] = 0;
	indices[3] = 2;
	indices[4] = 1;
	indices[5] = 3;

	indices[6] = 6;
	indices[7] = 4;
	indices[8] = 5;
	indices[9] = 7;
	indices[10] = 4;
	indices[11] = 6;

	indices[12] = 11;
	indices[13] = 9;
	indices[14] = 8;
	indices[15] = 10;
	indices[16] = 9;
	indices[17] = 11;

	indices[18] = 14;
	indices[19] = 12;
	indices[20] = 13;
	indices[21] = 15;
	indices[22] = 12;
	indices[23] = 14;

	indices[24] = 19;
	indices[25] = 17;
	indices[26] = 16;
	indices[27] = 18;
	indices[28] = 17;
	indices[29] = 19;

	indices[30] = 22;
	indices[31] = 20;
	indices[32] = 21;
	indices[33] = 23;
	indices[34] = 20;
	indices[35] = 22;
#endif

	

#ifdef __CHAPTER_FOUR__
	//정점 버퍼의 DESC 작성
	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof(VertexType)* m_vertexCount;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = 0;
#elif defined __CHAPTER_FIVE__
	//정점 버퍼의 DESC 작성
	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof(TexVertexType)* m_vertexCount;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = 0;
#elif defined __CHAPTER_SIX__
	//정점 버퍼의 DESC 작성
	vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	vertexBufferDesc.ByteWidth = sizeof(LightVertexType)* m_vertexCount;
	vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vertexBufferDesc.CPUAccessFlags = 0;
	vertexBufferDesc.MiscFlags = 0;
	vertexBufferDesc.StructureByteStride = 0;
#endif
	

	vertexData.pSysMem = vertice;
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
	if (FAILED(result))
	{
		return false;
	}

	indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	indexBufferDesc.ByteWidth = sizeof(unsigned long)*m_indexCount;
	indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	indexBufferDesc.CPUAccessFlags = 0;
	indexBufferDesc.MiscFlags = 0;
	indexBufferDesc.StructureByteStride = 0;

	indexData.pSysMem = indices;
	indexData.SysMemPitch = 0;
	indexData.SysMemSlicePitch = 0;

	result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
	if (FAILED(result))
	{
		return false;
	}

	delete[] vertice;
	vertice = NULL;

	delete[] indices;
	indices = NULL;

	return true;
}
示例#25
0
bool TestPlanetObj::Initialize(ObjectManager* om)
{
	return TestPlanetObj::Initialize(om, D3DXVECTOR3(GAME_WIDTH*0.5f - objectImage.getWidth() *0.5f, 
			 GAME_HEIGHT*0.5f - objectImage.getHeight()*0.5f, 1));
}
示例#26
0
//-----------------------------------------------------------------------------
// Animation call back handler.
//-----------------------------------------------------------------------------
HRESULT CALLBACK PlayerObject::HandleCallback( THIS_ UINT Track, LPVOID pCallbackData )
{
	// Get a pointer to the callback data.
	AnimationCallbackData *data = (AnimationCallbackData*)pCallbackData;

	// If the player is not touching the ground, then it can't make foot steps.
	if( IsTouchingGround() == false )
		return S_OK;

	// Check which foot caused the callback.
	if( data->foot == 1 )
	{
		// Reset the step result.
		m_stepResult.material = NULL;

		// Preform a ray intersection for the left foot. If it is succesful,
		// then play the material's step sound.
		if( Engine::GetInstance()->GetSceneManager()->RayIntersectScene( &m_stepResult, GetTranslation() + GetMesh()->GetReferencePoint( "rp_left_foot" )->GetTranslation(), D3DXVECTOR3( 0.0f, -1.0f, 0.0f ) ) == true )
		{
			if( ( (GameMaterial*)m_stepResult.material )->GetStepSound() != NULL )
				m_leftStepAudioPath->Play( ( (GameMaterial*)m_stepResult.material )->GetStepSound()->GetSegment() );
		}
	}
	else
	{
		// Reset the step result.
		m_stepResult.material = NULL;

		// Preform a ray intersection for the right foot. If it is succesful,
		// then play the material's step sound.
		if( Engine::GetInstance()->GetSceneManager()->RayIntersectScene( &m_stepResult, GetTranslation() + GetMesh()->GetReferencePoint( "rp_right_foot" )->GetTranslation(), D3DXVECTOR3( 0.0f, -1.0f, 0.0f ) ) == true )
		{
			if( ( (GameMaterial*)m_stepResult.material )->GetStepSound() != NULL )
				m_rightStepAudioPath->Play( ( (GameMaterial*)m_stepResult.material )->GetStepSound()->GetSegment() );
		}
	}

	return S_OK;
}
示例#27
0
GraphicsComponent * GraphicsEngine::CreateComponent(GraphicObjects object)
{
  GraphicsComponent *comp = NULL;

  switch(object)
  {
  case FOSSA:
    {
      /*BlockGraphicComponent *fossa = new BlockGraphicComponent();
      comp = fossa;
      fossa->model = modelMap["fossa"];
      fossa->shader = effectMap["HackMapping"];
      fossa->scale = D3DXVECTOR3(.2,.2,.2);
      fossa->position = D3DXVECTOR3(0,20,0);
      fossa->rotation = D3DXVECTOR3(0,0,0);

      fossa->Normal = textureMap["default"];*/
      //fossa->m_vec4Color = D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f);


      SkinnedComponent *fossa = new SkinnedComponent();
      comp = fossa;
      fossa->model = skinnedMeshMap["animations"];
      fossa->shader = effectMap["SkinnedMesh"];
      fossa->scale = D3DXVECTOR3(.25,.25,.25);
      fossa->position = D3DXVECTOR3(10,10,10);
      fossa->rotation = D3DXVECTOR3(0,0,0);
      
      

      HR(fossa->model->getAnimCtrl()->CloneAnimationController(fossa->model->getAnimCtrl()->GetMaxNumAnimationOutputs(),
        fossa->model->getAnimCtrl()->GetMaxNumAnimationSets(),fossa->model->getAnimCtrl()->GetMaxNumTracks(),fossa->model->getAnimCtrl()->GetMaxNumEvents(),
        &fossa->mAnimCtrl));

			//SETUP////////////
			for( unsigned i = 0; i < fossa->mAnimCtrl->GetMaxNumTracks(); i++ )
				fossa->mAnimCtrl->SetTrackEnable(i, TRUE);

			///////////////////

			//TEST PLAYING AN ANIMATION TRACK!!!!
			fossa->mAnimCtrl->SetTrackEnable(0, TRUE);
			LPD3DXANIMATIONSET animSet = NULL;
			//fossa->mAnimCtrl->SetTrackSpeed(0, .01f);
			fossa->mAnimCtrl->GetAnimationSet(2, &animSet);
			fossa->mAnimCtrl->SetTrackAnimationSet(0, animSet);
			animSet->Release();
			/////////
    }
    break;  

  case BLOCK_STONE:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["block_stone"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->visible = true;
      block->Normal = textureMap["rocks_normals"];
    }
    break;  

  case BLOCK_ICE:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["block_ice"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->visible = true;
      block->Normal = textureMap["ice_normals"];
    }
    break;

    case BLOCK_FAN:
    {
			/*BlockGraphicComponent *block = new BlockGraphicComponent();
			comp = block;
			block->model = modelMap["block_fan"];
			block->shader = effectMap["HackMapping"];
			block->scale = D3DXVECTOR3(1,1,1);
			block->position = D3DXVECTOR3(0,0,0);
			block->rotation = D3DXVECTOR3(0,0,0);
			block->visible = true;
			block->Normal = textureMap["default"];*/

			SkinnedComponent *fan = new SkinnedComponent();
      comp = fan;
      fan->model = skinnedMeshMap["fanblock"];
      fan->shader = effectMap["SkinnedMesh"];
      fan->scale = D3DXVECTOR3(.05f,.05f,.05f);
      fan->position = D3DXVECTOR3(10,10,10);
      fan->rotation = D3DXVECTOR3(0,0,0);
      
      

      HR(fan->model->getAnimCtrl()->CloneAnimationController(fan->model->getAnimCtrl()->GetMaxNumAnimationOutputs(),
        fan->model->getAnimCtrl()->GetMaxNumAnimationSets(),fan->model->getAnimCtrl()->GetMaxNumTracks(),fan->model->getAnimCtrl()->GetMaxNumEvents(),
        &fan->mAnimCtrl));

			//SETUP////////////
			for( unsigned i = 0; i < fan->mAnimCtrl->GetMaxNumTracks(); i++ )
				fan->mAnimCtrl->SetTrackEnable(i, FALSE);

			///////////////////

			//TEST PLAYING AN ANIMATION TRACK!!!!
			fan->mAnimCtrl->SetTrackEnable(0, TRUE);
			LPD3DXANIMATIONSET animSet = NULL;
			//fan->mAnimCtrl->SetTrackSpeed(0, .01f);
			fan->mAnimCtrl->GetAnimationSet(0, &animSet);
			fan->mAnimCtrl->SetTrackAnimationSet(0, animSet);
			animSet->Release();
			////////////////////////////////////////////
    }
    break;

    case BLOCK_TRAMPOLINE:
    {
      /*BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["block_trampoline"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->visible = true;
      block->Normal = textureMap["trampoline_normals"];*/

			
			SkinnedComponent *block = new SkinnedComponent();
      comp = block;
      block->model = skinnedMeshMap["block_trampoline"];
      block->shader = effectMap["SkinnedMesh"];
      block->scale = D3DXVECTOR3(.01f,.01f,.01f);
      block->position = D3DXVECTOR3(10,10,10);
      block->rotation = D3DXVECTOR3(0,0,0);
      //block->Normal = textureMap["trampoline_normals"];
      

      HR(block->model->getAnimCtrl()->CloneAnimationController(block->model->getAnimCtrl()->GetMaxNumAnimationOutputs(),
        block->model->getAnimCtrl()->GetMaxNumAnimationSets(),block->model->getAnimCtrl()->GetMaxNumTracks(),block->model->getAnimCtrl()->GetMaxNumEvents(),
        &block->mAnimCtrl));

			//SETUP////////////
			for( unsigned i = 0; i < block->mAnimCtrl->GetMaxNumTracks(); i++ )
				block->mAnimCtrl->SetTrackEnable(i, FALSE);

			///////////////////

			//TEST PLAYING AN ANIMATION TRACK!!!!
			block->mAnimCtrl->SetTrackEnable(0, TRUE);
			LPD3DXANIMATIONSET animSet = NULL;
			block->mAnimCtrl->SetTrackSpeed(0, 1.f);
			block->mAnimCtrl->GetAnimationSet(0, &animSet);
			block->mAnimCtrl->SetTrackAnimationSet(0, animSet);
			animSet->Release();

			block->ChangeAnimSpeed(.3f);
 			block->ChangeAnim(0);
			////////////////////////////////////////////
    }
    break;

    case BLOCK_SAND:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["block_sand"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->visible = true;
      block->Normal = textureMap["sand_normals"];
    }
    break;

  case DIGIBLOCK:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["digiblock"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);


      block->Normal = textureMap["default"];
    }
    break;  
  case RIGIDBLOCK:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["rigidblock"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);


      block->Normal = textureMap["default"];
    }
    break;  
  case JEWEL:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["jewel_off"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;    
  case JEWEL_1:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
       block->model = modelMap["jewel1"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;  
  case JEWEL_2:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["jewel2"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;
  case JEWEL_3:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["jewel3"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;  
  case JEWEL_4:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["jewel4"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;
  case JEWEL_5:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["jewel5"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["jewelNorm"];
    }
    break;  
  case HUB_FLOOR:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["hub_floor"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["rocks_normals"];
    }  
    break;
  case HUB_WALL1:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["hub_wall1"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["default"];
    }
    break;
  case HUB_WALL2:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["hub_wall2"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["default"];
    }
    break;  
  case HUB_WALL3:
    {
      BlockGraphicComponent *block = new BlockGraphicComponent();
      comp = block;
      block->model = modelMap["hub_wall3"];
      block->shader = effectMap["HackMapping"];
      block->scale = D3DXVECTOR3(1,1,1);
      block->position = D3DXVECTOR3(0,0,0);
      block->rotation = D3DXVECTOR3(0,0,0);
      block->Normal = textureMap["default"];
    }
    break;
  default:
    return NULL;

  }
	comp->type = object;

  ComponentList.push_back(comp);
  return comp;
}
示例#28
0
void StaticCamera::SetFromSunlight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXVECTOR4 Power, float Width, float Height, float Depth)
{
	D3DXVECTOR3 d3dLookAt = D3DXVECTOR3(Width, Height, Depth) * 0.5f;//(*position + *Direction * m_fFarPlane);
	D3DXVECTOR3 eye = *position / D3DXVec3Length(position);
	eye *= D3DXVec3Length(&d3dLookAt) * 1.1f;
	eye += d3dLookAt;

	CBaseCamera::SetViewParams(&eye, &d3dLookAt);
	mLightColor = Power;

	*position = eye;
	d3dLookAt = d3dLookAt - eye;
	d3dLookAt /= D3DXVec3Length(&d3dLookAt);
	*direction = d3dLookAt;

	D3DXVECTOR3 cornersWorld[] = {
		D3DXVECTOR3(0,0,0), 
		D3DXVECTOR3(Width, 0, 0), 
		D3DXVECTOR3(Width, Height, 0), 
		D3DXVECTOR3(Width, Height, Depth),
		D3DXVECTOR3(0, Height, 0), 
		D3DXVECTOR3(0, Height, Depth), 
		D3DXVECTOR3(0,0,Depth), 
		D3DXVECTOR3(Width, 0, Depth)
	};

	D3DXVECTOR3 lightSpaceBoxMin = D3DXVECTOR3(FLT_MAX,FLT_MAX,FLT_MAX);
	D3DXVECTOR3 lightSpaceBoxMax = D3DXVECTOR3(FLT_MIN, FLT_MIN, FLT_MIN);

	for (int i = 0; i < 8; ++i)
	{
		D3DXVec3TransformCoord(&cornersWorld[i], &cornersWorld[i], GetViewMatrix());
		lightSpaceBoxMin.x = lightSpaceBoxMin.x < cornersWorld[i].x ? lightSpaceBoxMin.x : cornersWorld[i].x;
		lightSpaceBoxMin.y = lightSpaceBoxMin.y < cornersWorld[i].y ? lightSpaceBoxMin.y : cornersWorld[i].y;
		lightSpaceBoxMin.z = lightSpaceBoxMin.z < cornersWorld[i].z ? lightSpaceBoxMin.z : cornersWorld[i].z;


		lightSpaceBoxMax.x = lightSpaceBoxMax.x > cornersWorld[i].x ? lightSpaceBoxMax.x : cornersWorld[i].x;
		lightSpaceBoxMax.y = lightSpaceBoxMax.y > cornersWorld[i].y ? lightSpaceBoxMax.y : cornersWorld[i].y;
		lightSpaceBoxMax.z = lightSpaceBoxMax.z > cornersWorld[i].z ? lightSpaceBoxMax.z : cornersWorld[i].z;
	};

	SetOrthoParams(lightSpaceBoxMax.x - lightSpaceBoxMin.x, lightSpaceBoxMax.y - lightSpaceBoxMin.y, lightSpaceBoxMin.z, lightSpaceBoxMax.z);
	
	//set constant buffer
	D3DXMATRIX identityMatrix;
	D3DXMatrixIdentity(&identityMatrix);

	cameraCBuffer->Data.World	= identityMatrix;
	cameraCBuffer->Data.refractiveIndexETA = 1.0f;
	cameraCBuffer->Data.View	= *GetViewMatrix();
	cameraCBuffer->Data.WorldViewProjection = identityMatrix * cameraCBuffer->Data.View * (*GetProjMatrix());
	//float test = D3DXMatrixDeterminant(GetProjMatrix());
	//test = D3DXMatrixDeterminant(GetViewMatrix());
	//test = test +1;
}
示例#29
0
// 移動スピード
static const float MOVE_SPEED = 1.3f;
// 横の移動量の減衰値
static const float VELO_RESIST = 0.9f;
// 横の移動量の範囲
static const float VELO_MAX = 3;
// ビューポート変換の行列
static const D3DXMATRIX VIEW_PORT = {
	SCREEN_WIDTH*0.5f, 0, 0, 0,
	0, SCREEN_HEIGHT*0.5f, 0, 0,
	0, 0, 1, 0,
	SCREEN_WIDTH*0.5f, SCREEN_HEIGHT*0.5f, 0, 1
};
// 飛ぶ先の座標 HPと歓声ゲージ 添え字はプレイヤ番号と対応
static const D3DXVECTOR3 POS_HP_BAR[2] = {
	D3DXVECTOR3(335, 121, 0),
	D3DXVECTOR3(SCREEN_WIDTH - 335, 121, 0)
};
static const D3DXVECTOR3 POS_CROWD_BAR[2] = {
	D3DXVECTOR3(425, 75, 0),
	D3DXVECTOR3(SCREEN_WIDTH - 425, 75, 0)
};
// 飛ぶまでのフレーム数
static const int FLY_INTERVAL = 60;
// 飛ぶ時の移動スピード 補間するtime(0~1)の加算値
static const float FLY_TIME_SPEED = 0.1f;
// 縮小スピード
static const float SIZE_RESIST = 0.9f;
// 画面外に行かないように制限をつける
static const float POS2D_MIN = 100.f;
示例#30
0
void ColoredCubeApp::initApp()
{
	D3DApp::initApp();
	//0: Parallel
	//1: Point
	//2: Spot

	hurtLight = D3DXCOLOR(1,0,0,1);

	ambientLight = D3DXCOLOR(0.3f, 0.03f, 0.2f, 1.0f);
	//ambientLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	lights[1].ambient  = ambientLight;
	lights[1].diffuse  = D3DXCOLOR(0.0f, 0.02f, 0.02f, 1.0f);
	lights[1].specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	lights[1].att.x    = 1.0f;
	lights[1].att.y    = 0.0f;
	lights[1].att.z    = 0.0f;
	lights[1].spotPow  = 20;
	lights[1].range    = 100;
	lights[1].pos = D3DXVECTOR3(-10,20,-10);
	lights[1].dir = D3DXVECTOR3(0, -1, 0);	
	lights[1].lightType.x = 0;


	buildFX();
	buildVertexLayouts();

	Dimension d;
	d.x = 10;
	d.z = 10;
	mazeX = d.x;
	mazeZ = d.z;
	maze.init(d,mfxWVPVar,mfxWorldVar,md3dDevice);
	maze.build();
	maze.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");	
	maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg");
	maze.setFloorTex(mfxDiffuseMapVar,mfxSpecMapVar,L"carpet_diffuse.jpg",L"brickwork-bump-map.jpg");
	camera.init(&maze);

	mBox.init(md3dDevice, 1.0f);

	//testMesh.init(md3dDevice,1.0f,"surfrev2.dat");

	line.init(md3dDevice, 1.0f, DARKBROWN);
	line2.init(md3dDevice, 1.0f, RED);
	line3.init(md3dDevice, 1.0f, GREEN);

	origin.init(&line,&line2,&line3,mfxWVPVar,10);

	quad1.init(md3dDevice,1,D3DXCOLOR(0.5,0.25,0.1,1.0));

	//make the texture init in another function so it is not an issue switching between shaders
	/*floor.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3,0),Vector3(0,0,0),0,Vector3(20,0.1,20));
	floor.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"defaultspec.dds");

	wall1.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(-20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20));
	wall2.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20));
	wall3.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,20),Vector3(0,0,0),0,Vector3(20,20,0.1));
	wall4.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,-20),Vector3(0,0,0),0,Vector3(20,20,0.1));*/

	player.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(10,0,10),Vector3(0,0,0),0,Vector3(1,1,1));
	player.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");
	Location start = maze.getStartPosition();
	start = maze.cellToPx(start);
	player.setPosition(Vector3(start.x+10,0,start.z+10));

	flashLightObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	flashLightObject.setRotation(Vector3(ToRadian(90),0,0));

	//lightObject1.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	//lightObject1.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	for(int i = 0; i < numLightObjects; i++)
	{
		lamps[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.75,0.75,0.75));
		lamps[i].setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		lamps[i].setPosition(Vector3(spot.x,5,spot.z));
		lamps[i].setColor(D3DXCOLOR(0.2f, 0.5f, 0.3f, 1.0f));
	}

	key.init(md3dDevice,1,"item1.txt");
	for(int i = 0; i < totalKeys; i++)
	{
		keyObject[i].init(&key,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		keyObject[i].setPosition(Vector3(spot.x,-1,spot.z));
	}

	endCube.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(3.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(2,2,2));
	endCube.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	Location end = maze.getEndPosition();
	end = maze.cellToPx(end);
	endCube.setPosition(Vector3(end.x,0,end.z));

	//set up the end light
	endLight.ambient  = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	endLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 0.3f, 1.0f);
	endLight.specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	endLight.att.x    = 1.0f;
	endLight.att.y    = 0.0f;
	endLight.att.z    = 0.0f;
	endLight.spotPow  = 10;
	endLight.range    = 100;
	endLight.pos = D3DXVECTOR3(end.x,10,end.z);
	endLight.dir = D3DXVECTOR3(0, -1, 0);	
	endLight.lightType.x = 2;


	//batteryObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	for(int i = 0; i < numBatteries; i++)
	{
		batteries[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.5,0.5,0.5));
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		batteries[i].setPosition(Vector3(spot.x,-1,spot.z));
	}

	ghosts.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(5,0,0),Vector3(0,0,0),10,Vector3(0.25,0.25,0.25));
	ghosts.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	
	//Normalize(&mParallelLight.dir,&(flashLightObject.getPosition()-wall1.getPosition()));
	// init sound system
    audio = new Audio();
    if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0')  // if sound files defined
    {
        if( FAILED( hr = audio->initialize() ) )
        {
			exit(1);
            //if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) )
            //    throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found."));
            //else
            //    throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system."));
        }
    }
	//set up the camera
	camera.setHeightAndWidth(mClientWidth,mClientHeight);

	audio->playCue(MUSIC);

	//input->initialize(this->getMainWnd(), false);  
	//sound object
	/*testSound = new SoundItem(audio,Vector3(0,0,0),50);
	static string sounds[] = {"gun_sound_effect","Light Bulb Breaking-SoundBible.com-53066515"};
	testSound->setSounds(sounds,2);*/
}