Ejemplo n.º 1
0
// Creates a player
GameObject* GameManager::CreatePlayer( uint32_t index, const XMFLOAT3& position, const XMFLOAT3& scale )
{
    Scene* scene = Scene::GetInstance();
    GameObject* player = scene->AddGameObject( "Player_" + std::to_string( index ) );
    ID3D11Device* device = player->GetDevice();
    ID3D11DeviceContext* deviceContext = player->GetDeviceContext();

    // Set the player's transform info
    Transform* transform = player->GetTransform();
    transform->SetPosition( position );
    transform->SetScale( scale );

    // Add the collider to the player
    BoxCollider* collider = player->AddComponent<BoxCollider>();
    collider->SetSize( XMFLOAT3( 1, 1, 1 ) );

    // Add the rigid body to the player
    Rigidbody* rigidbody = player->AddComponent<Rigidbody>();
    rigidbody->SetMass( 0 );

    // Add the default material to the player
    DefaultMaterial* material = player->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\Rocks2.jpg" );
    material->LoadNormalMap( "Textures\\Rocks2Normals.jpg" );
    material->SetDirectionalLight( StageLight );

    // Add the mesh renderer to the player
    MeshRenderer* meshRenderer = player->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\cube.obj", device, deviceContext ) );

    return player;
}
Ejemplo n.º 2
0
HRESULT Jaraffe::CScene::Init()
{
	// 1) Create MainCamera
	Camera* newCamera = new Camera();
	Camera::SetMainCamera(newCamera);

	GameObject* m_pMainCamera = GameObject::Create();
	m_pMainCamera->InsertComponent(new Transform);
	m_pMainCamera->InsertComponent(newCamera);

	m_pMainCamera->Init();

	// 2) Create Directional Light
	Jaraffe::Component::Light* pMainLight = new Jaraffe::Component::Light();
	auto plight = pMainLight->SetLightType(Jaraffe::Light::LightType::Directional);
	if (plight != nullptr)
	{
		auto cast = (Jaraffe::Light::DirectionalLight*)plight;
		cast->Ambient	= XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
		cast->Diffuse	= XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		cast->Specular	= XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
		cast->Direction = XMFLOAT3(-0.707f, 0.0f, 0.707f);
	}

	GameObject* m_DirectionalLight = GameObject::Create();
	m_DirectionalLight->InsertComponent(new Transform);
	m_DirectionalLight->InsertComponent(pMainLight);

	//---- T E S T ----
	Jaraffe::Material* pMat = new Jaraffe::Material();
	Jaraffe::Texture* pTex = new Jaraffe::Texture();
	pTex->SetTexture(gTEXTUREMGR->CreateTexture(L"Resources/Textures/WoodCrate01.dds"));
	pMat->m_MainTexture = pTex;

	MeshRenderer* pMeshRenderer = new MeshRenderer();
	pMeshRenderer->SetMaterial(pMat);

	GameObject* m_pTestModel = GameObject::Create();
	m_pTestModel->InsertComponent(new Transform);
	m_pTestModel->InsertComponent(pMeshRenderer);
	m_pTestModel->InsertComponent(new Mesh);

	m_ObjectList.push_back(m_pTestModel);

	//---- E N D   ----

	// All GameObject Init
	for (size_t i = 0; i < m_ObjectList.size(); i++)
	{
		m_ObjectList[i]->Init();
	}

	return S_OK;
}
Ejemplo n.º 3
0
// Creates an arrow game object
GameObject* GameManager::CreateArrow( const XMFLOAT3& position, const XMFLOAT3& force )
{
    static const XMFLOAT3 ArrowSize = { 1, 0.1f, 1.0f };

    Scene* scene = Scene::GetInstance();
    ID3D11Device* device = _gameObject->GetDevice();
    ID3D11DeviceContext* deviceContext = _gameObject->GetDeviceContext();

    // Create the arrow object
    GameObject* arrow = scene->AddGameObject( _gameObject->GetName() + "_Arrow_" + std::to_string( _arrowCount++ ) );
    
    // Set some transform info
    Transform* transform = arrow->GetTransform();
    transform->SetPosition( position );

    // Add the arrow's collider
    BoxCollider* collider = arrow->AddComponent<BoxCollider>();
    collider->SetSize( ArrowSize );

    // Add the arrow's rigidbody
    Rigidbody* rigidbody = arrow->AddComponent<Rigidbody>();
    rigidbody->SetMass( 1.0f );

    // Set the arrow's collision callback
    GameObject::CollisionCallback callback = std::bind( &GameManager::OnArrowCollide, this, _1 );
    arrow->AddEventListener( "OnArrowCollide", callback );

    // Add a default material
    DefaultMaterial* material = arrow->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\SolidWhite.png" );
    material->SetDirectionalLight( StageLight );

    // Add a mesh renderer
    MeshRenderer* meshRenderer = arrow->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\arrow.obj", device, deviceContext ) );

    return arrow;
}
Ejemplo n.º 4
0
void Scene::Render( RenderPass renderPass, Viewport* viewport )
{
	static Mesh* skyboxMesh = ResourceManager::GetGenMesh(GenMeshes::Cube);

	std::string viewportName = viewport != NULL ? viewport->GetName() : "";

	bool ignoreShadowCast = true;
	if (renderPass == RenderPass::ShadowPass)
	{
		ignoreShadowCast = false;
	}

	for (uint rank = 0; rank < m_layers.size(); rank++)
	{
		if ( !m_layers[rank]->IsEnabled() )	continue;

		RenderManager::UseNewLayer(renderPass);

		if (rank == 0)
		{
			if ( m_skyboxMaterial != NULL && renderPass != RenderPass::PickingPass )
			{
				Transform transform(NULL);
				transform.SetPositionWorld( RenderManager::GetRenderCamera()->GetComponent<Transform>()->GetPositionWorld() );
				transform.SetScaleWorld( Vector3(m_skyboxSize) );

				MeshRenderer renderer;
				renderer.SetMaterial(m_skyboxMaterial);
				renderer.SetMesh(skyboxMesh);
				renderer.SetFaceCulling( FaceCulling::CULL_FRONT );

				RenderManager::ObjectToRender objectToRender;
				objectToRender.transform = &transform;
				objectToRender.meshRenderer = &renderer;
				objectToRender.renderPass = renderPass;

				RenderManager::RenderObject( objectToRender );
			}

			GizmoManager::RenderGrid( renderPass );
		}

#if (ME3D_SHADING_MODE == ME3D_CLASSIC_SHADING)
	
		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						RenderManager::AddActiveLight( activeLight );
					}
				}
			}
		}
#endif


		for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
		{
			GameObject* obj = m_layers[rank]->GetObjectAt(j);

			if ( !obj->IsIgnoringViewport(viewportName)
				&& obj->IsFullyActive() )
			{
				GizmoManager::RenderFollower( obj, renderPass );

				MeshRenderer* renderer = obj->GetComponent<MeshRenderer>();
				GuiTexture* guiTexture = obj->GetComponent<GuiTexture>();

				glEnable(GL_DEPTH_TEST);
				glDepthMask(GL_TRUE);

				glEnable(GL_BLEND);
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

				if (renderer != NULL &&
					renderer->GetMaterial() != NULL &&
					renderer->GetMesh() != NULL &&
					(ignoreShadowCast || renderer->IsCastingShadows()) )
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.transform = obj->GetComponent<Transform>();
					objectToRender.meshRenderer = renderer;
					objectToRender.renderPass = renderPass;

					RenderManager::RenderObject( objectToRender );
				}

				if (guiTexture != NULL)
				{
					RenderManager::ObjectToRender objectToRender;
					objectToRender.uniqueIndex = obj->GetUniqueIndex();
					objectToRender.guiTexture = guiTexture;

					RenderManager::RenderObject( objectToRender );
				}
			}
		}


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)

		if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
		{
			for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
			{
				GameObject* obj = m_layers[rank]->GetObjectAt(j);

				if (obj->IsFullyActive())
				{
					Light* lightComp = obj->GetComponent<Light>();
					if (lightComp != NULL && lightComp->IsEnabled())
					{
						RenderManager::ActiveLight activeLight;
						activeLight.light = lightComp;
						activeLight.transform = obj->GetComponent<Transform>();

						switch (lightComp->GetType())
						{
						case LightType::Directional:
							RenderManager::DeferredDirectional(activeLight);
							break;
						case LightType::Point:
						case LightType::Spot:
							RenderManager::DeferredPointAndSpot(activeLight);
							break;
						}
					}
				}
			}
		}
#endif


#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
		if (renderPass != RenderPass::PickingPass)
		{
			RenderManager::DeferredUnlit();
		}
#endif

		RenderManager::CollapseLayer(renderPass);

	} // end for
	 


	// layer for gizmo
	RenderManager::UseNewLayer(renderPass);
		
	GizmoManager::RenderTools(renderPass);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);



	// layer for menu
	RenderManager::UseNewLayer(renderPass);
		
	MenuManager::Render(renderPass, viewportName);

#if (ME3D_SHADING_MODE == ME3D_DEFERRED_SHADING)
	if (renderPass != RenderPass::PickingPass)
	{
		RenderManager::DeferredUnlit();
	}
#endif

	RenderManager::CollapseLayer(renderPass);

}