Exemplo n.º 1
0
void Iglo::Initialize(const GameContext& gameContext)
{
	UNREFERENCED_PARAMETER(gameContext);

	// ADD MODEL
	auto physX = PhysxManager::GetInstance()->GetPhysics();

	auto igloModelComponent = new ModelComponent(L"./Resources/Meshes/Iglo.ovm");

	auto igloMaterial = new DiffuseMaterial();
	igloMaterial->SetDiffuseTexture(L"./Resources/Textures/Iglo.jpg");
	gameContext.pMaterialManager->AddMaterial(igloMaterial, 1);

	igloModelComponent->SetMaterial(1);

	AddComponent(igloModelComponent);

	auto rigidbody = new RigidBodyComponent();
	rigidbody->SetKinematic(true);
	AddComponent(rigidbody);

	auto defaultMaterial = physX->createMaterial(0.5f, 0.5f, 0.1f);
	auto igloMesh = ContentManager::Load<PxTriangleMesh>(L"./Resources/Meshes/Iglo.ovpt");
	shared_ptr<PxGeometry> igloGeo(new PxTriangleMeshGeometry(igloMesh));
	auto IgloCollider = new ColliderComponent(igloGeo, *defaultMaterial);

	AddComponent(IgloCollider);

	GetTransform()->Translate(m_Position);
}
Exemplo n.º 2
0
void GLSprite::BeginFastRendering()
{
	GLVideo* video = m_video.lock().get();
	video->SetVertexShader(video->GetFontShader());
	ShaderPtr pCurrentVS = video->GetVertexShader();
	pCurrentVS->SetConstant("bitmapSize", GetBitmapSizeF());

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	SetDiffuseTexture(pCurrentPS);
}
void SkyBoxTestScene::Initialize(const GameContext& gameContext)
{
    UNREFERENCED_PARAMETER(gameContext);

    auto skinnedDiffuseMaterial = new SkinnedDiffuseMaterial();
    skinnedDiffuseMaterial->SetDiffuseTexture(L"./Resources/Textures/Knight.jpg");
    gameContext.pMaterialManager->AddMaterial(skinnedDiffuseMaterial, 115);

    m_pModel = new ModelComponent(L"./Resources/Meshes/Knight.ovm");
    m_pModel->SetMaterial(115);
    auto obj = new GameObject();
    obj->AddComponent(m_pModel);
    AddChild(obj);

    obj->GetTransform()->Scale(0.1f, 0.1f, 0.1f);

    auto myMaterial = new SkyBoxMaterial();
    myMaterial->SetDiffuseTexture(L"./Resources/Textures/SkyBox.dds");
    gameContext.pMaterialManager->AddMaterial(myMaterial, 110);
    auto skycube = new SkyBoxPrefab(110);
    AddChild(skycube);

}
Exemplo n.º 4
0
void MkShaderEffectAssignPack::Clear(void)
{
	ClearWorldViewProjection();
	SetAlpha(1.f);

	SetDiffuseTexture(NULL);
	SetShaderTexture0(NULL);
	SetShaderTexture1(NULL);
	SetShaderTexture2(NULL);

	D3DXVECTOR4 empty(0.f, 0.f, 0.f, 0.f);
	SetUDP0(empty);
	SetUDP1(empty);
	SetUDP2(empty);
	SetUDP3(empty);
}
void ModelTestScene::Initialize(const GameContext& gameContext)
{
	UNREFERENCED_PARAMETER(gameContext);

	//GROUND PLANE
	//************
	auto physX = PhysxManager::GetInstance()->GetPhysics();

	auto bouncyMaterial = physX->createMaterial(0, 0, 1);
	auto ground = new GameObject();
	ground->AddComponent(new RigidBodyComponent(true));

	std::shared_ptr<PxGeometry> geom(new PxPlaneGeometry());
	ground->AddComponent(new ColliderComponent(geom, *bouncyMaterial, PxTransform(PxQuat(XM_PIDIV2, PxVec3(0, 0, 1)))));
	AddChild(ground);

	//CHAIR OBJECT
	//************
	m_pChair = new GameObject();

	//1. Attach a modelcomponent (chair.ovm)
	auto chairModelComponent = new ModelComponent(L"./Resources/Meshes/chair.ovm");
	m_pChair->AddComponent(chairModelComponent);

	//2. Create a ColorMaterial and add it to the material manager
	auto chairColorMaterial = new ColorMaterial();
	gameContext.pMaterialManager->AddMaterial(chairColorMaterial, 102);

	//3. Assign the material to the previous created modelcomponent
	m_pChair->GetComponent<ModelComponent>()->SetMaterial(102);
	// Build and Run

	//4. Create a DiffuseMaterial (using PosNormTex3D.fx)
	//		Make sure you are able to set a texture (DiffuseMaterial::SetDiffuseTexture(const wstring& assetFile))
	//		Load the correct shadervariable and set it during the material variable update
	auto chairDiffuseMaterial = new DiffuseMaterial();
	chairDiffuseMaterial->SetDiffuseTexture(L"./Resources/Textures/Chair_Dark.dds");
	gameContext.pMaterialManager->AddMaterial(chairDiffuseMaterial, 104);

	//5. Assign the material to the modelcomponent
	m_pChair->GetComponent<ModelComponent>()->SetMaterial(104);
	// Build and Run

	//6. Attach a rigidbody component (pure-dynamic)
	auto chairRigidbody = new RigidBodyComponent();
	m_pChair->AddComponent(chairRigidbody);

	//7. Attach a collider component (Use a PxConvexMeshGeometry [chair.ovpc])

	auto defaultMaterial = physX->createMaterial(0.5f, 0.5f, 0.1f);
	auto chairMesh = ContentManager::Load<PxConvexMesh>(L"./Resources/Meshes/chair.ovpc");
	shared_ptr<PxGeometry> chairGeo(new PxConvexMeshGeometry(chairMesh));
	auto chairCollider = new ColliderComponent(chairGeo, *defaultMaterial);

	m_pChair->AddComponent(chairCollider);

	AddChild(m_pChair);

	chairRigidbody->SetDensity(300);

	m_pChair->GetTransform()->Translate(0, 10, 0);

	// Build and Run
}
Exemplo n.º 6
0
bool GLSprite::DrawShaped(
	const math::Vector2 &v2Pos,
	const math::Vector2 &v2Size,
	const Color& color0,
	const Color& color1,
	const Color& color2,
	const Color& color3,
	const float angle)
{
	if (v2Size == math::Vector2(0,0))
	{
		return true;
	}

	// compute flip parameters that will be sent to the VS
	math::Vector2 flipMul, flipAdd;
	GetFlipShaderParameters(flipAdd, flipMul);

	// centralizes the sprite according to the origin
	math::Vector2 v2Center = m_normalizedOrigin * v2Size;

	GLVideo* video = m_video.lock().get();
	ShaderPtr pCurrentVS = video->GetVertexShader();

	math::Matrix4x4 mRot;
	if (angle != 0.0f)
		mRot = math::RotateZ(math::DegreeToRadian(angle));
	pCurrentVS->SetMatrixConstant("rotationMatrix", mRot);

	// rounds up the final position to avoid alpha distortion
	math::Vector2 v2FinalPos;
	if (video->IsRoundingUpPosition())
	{
		v2FinalPos.x = floor(v2Pos.x);
		v2FinalPos.y = floor(v2Pos.y);
	}
	else
	{
		v2FinalPos = v2Pos;
	}

	pCurrentVS->SetConstant("size", v2Size);
	pCurrentVS->SetConstant("entityPos", v2FinalPos);
	pCurrentVS->SetConstant("center", v2Center);
	pCurrentVS->SetConstant("flipMul", flipMul);
	pCurrentVS->SetConstant("flipAdd", flipAdd);
	pCurrentVS->SetConstant("bitmapSize", GetBitmapSizeF());
	pCurrentVS->SetConstant("scroll", GetScroll());
	pCurrentVS->SetConstant("multiply", GetMultiply());

	const bool setCameraPos = pCurrentVS->ConstantExist("cameraPos");
	if (setCameraPos)
		pCurrentVS->SetConstant("cameraPos", video->GetCameraPos());

	if (m_rect.size.x == 0 || m_rect.size.y == 0)
	{
		pCurrentVS->SetConstant("rectSize", GetBitmapSizeF());
		pCurrentVS->SetConstant("rectPos", 0, 0);
	}
	else
	{
		pCurrentVS->SetConstant("rectSize", m_rect.size);
		pCurrentVS->SetConstant("rectPos", m_rect.pos);
	}

	pCurrentVS->SetConstant("color0", color0);
	pCurrentVS->SetConstant("color1", color1);
	pCurrentVS->SetConstant("color2", color2);
	pCurrentVS->SetConstant("color3", color3);

	if (pCurrentVS->ConstantExist("depth"))
		pCurrentVS->SetConstant("depth", video->GetSpriteDepth());

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	SetDiffuseTexture(pCurrentPS);

	pCurrentVS->SetShader();

	// draw the one-pixel-quad applying the vertex shader
	video->GetRectRenderer().Draw(m_rectMode);

	return true;
}