Ejemplo n.º 1
0
GameEntity EntityFactory::CreatePlayer(DirectX::XMFLOAT3 position)
{
    EntityManager* pEntity = EntityManager::Instance();
	ResourceManager* pResource = ResourceManager::Instance();

    GameEntity player = pEntity->Create("Player");
    pEntity->AddComponent<RenderComponent>(player, pResource->GetMaterial("ship"), pResource->GetMesh("Ship"));
    pEntity->AddComponent<InputComponent>(player, 5.0f);
    pEntity->AddComponent<CollisionComponent>(player, *pResource->GetMesh("Ship"), XMFLOAT3(0, 0, 0), 0.0007f);
    pEntity->AddComponent<AttackComponent>(player, 5.0f);
    TransformComponent* pTrans = pEntity->AddComponent<TransformComponent>(player, position);
    pTrans->transform.SetScale(.001f);
    PhysicsComponent* pPhysics = pEntity->AddComponent<PhysicsComponent>(player, XMVectorZero(), XMVectorZero());
    pPhysics->drag = 0.60f;
    pPhysics->rotationalDrag = 0.30f;

	GameEntity exhaust = pEntity->Create("Exhaust");
	pEntity->AddComponent<RenderComponent>(exhaust, pResource->GetMaterial("thruster"), pResource->GetMesh("Thruster"))->maskOnly = true;
	TransformComponent* eTrans = pEntity->AddComponent<TransformComponent>(exhaust, position);
	eTrans->transform.Translate(0.0f, 0.0f, -0.3f);
	eTrans->transform.Scale(400.0f);

	pTrans->transform.AddChild(&eTrans->transform);

	// Particles
	Particle p(XMFLOAT4(1, 0, 0, 1),
			   XMFLOAT4(1, 1, 0.1f, 0.8f),
			   XMFLOAT4(1, 0.5f, 0.1f, 0.9f),
			   XMFLOAT3(0, 0, -0.9),
			   XMFLOAT3(0, 0, -0.3),
			   XMFLOAT3(0, 0, 0),
			   0.9f,
			   0.4f,
			   0.1f,
			   0.0f,
			   0);

	ParticleGenerator* pGML = new ParticleGenerator(p, XMFLOAT3( 0.0f,  -0.16f, -1.05f), 0.08f, 0.00001, 10);
	ParticleGenerator* pGMU = new ParticleGenerator(p, XMFLOAT3( 0.0f,  +0.04f, -1.05f), 0.08f, 0.00001, 10);
	ParticleGenerator* pGRU = new ParticleGenerator(p, XMFLOAT3(+0.33f, +0.04f, -1.05f), 0.08f, 0.00001, 10);
	ParticleGenerator* pGLU = new ParticleGenerator(p, XMFLOAT3(-0.33f, +0.04f, -1.05f), 0.08f, 0.00001, 10);
	ParticleGenerator* pGRL = new ParticleGenerator(p, XMFLOAT3(+0.35f, -0.16f, -1.05f), 0.08f, 0.00001, 10);
	ParticleGenerator* pGLL = new ParticleGenerator(p, XMFLOAT3(-0.35f, -0.16f, -1.05f), 0.08f, 0.00001, 10);


	ParticleComponent* pParticles = pEntity->AddComponent<ParticleComponent>(player);
	pParticles->AddGenerator(pGML);
	pParticles->AddGenerator(pGMU);
	pParticles->AddGenerator(pGRU);
	pParticles->AddGenerator(pGLU);
	pParticles->AddGenerator(pGRL);
	pParticles->AddGenerator(pGLL);
    return player;
}
Ejemplo n.º 2
0
void DebugVectorRenderer::Render()
{
	if (primitiveCount > 0)
	{
		if (meshesInitialized == false)
		{
			this->CreateMeshes();
		}

		Engine* engine = Engine::GetInstance();
		Camera* camera = this->activeCamera;

		Mat4x4f viewProjection = camera->GetProjectionMatrix() * camera->GetViewMatrix();

		ResourceManager* rm = engine->GetResourceManager();
		Shader* shader = rm->GetShader("res/shaders/debug_vector.shader.json");

		int colorUniformLocation = -1;
		for (unsigned int i = 0; i < shader->materialUniformCount; ++i)
		{
			if (shader->materialUniforms[i].type == ShaderUniformType::Vec4)
			{
				colorUniformLocation = shader->materialUniforms[i].location;
			}
		}

		glDisable(GL_DEPTH_TEST);
		glDisable(GL_BLEND);

		// Use shader
		glUseProgram(shader->driverId);

		for (unsigned int i = 0; i < primitiveCount; ++i)
		{
			Primitive* primitive = primitives + i;
			Mat4x4f mvp = viewProjection * primitive->transform;

			unsigned int meshId = this->meshIds[static_cast<unsigned int>(primitive->type)];
			const Mesh& mesh = rm->GetMesh(meshId);

			// Set color uniform
			glUniform4fv(colorUniformLocation, 1, primitive->color.ValuePointer());

			// Bind vertex array object
			glBindVertexArray(mesh.vertexArrayObject);

			// Set transform matrix uniform
			glUniformMatrix4fv(shader->uniformMatMVP, 1, GL_FALSE, mvp.ValuePointer());

			// Draw
			glDrawElements(mesh.primitiveMode, mesh.indexCount, mesh.indexElementType, nullptr);
		}

		// Clear primitive count
		primitiveCount = 0;
	}
}
/*
 * Go through each mesh resource and material resource. If any of the resources aren't yet ready,
 * stop and return false.
 */
bool MeshAttachment::DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager )
{
  bool ready = false;
  mFinishedResourceAcquisition = false;

  if ( !mMesh.mesh )
  {
    SceneGraph::Mesh* mesh(resourceManager.GetMesh(mMesh.meshResourceId));
    mMesh.mesh = mesh;
  }

  if ( mMesh.mesh && mMesh.mesh->HasGeometry( Mesh::UPDATE_THREAD ) )
  {
    const SceneGraph::Material* material = mMesh.material;
    ready = material->AreResourcesReady();
    mFinishedResourceAcquisition = ready;
  }

  return ready;
}
Ejemplo n.º 4
0
void DebugVectorRenderer::CreateMeshes()
{
	Engine* engine = Engine::GetInstance();
	ResourceManager* rm = engine->GetResourceManager();

	{
		Vertex3f lineVertexData[] = {
			Vertex3f{ Vec3f(0.0f, 0.0f, 0.0f) },
			Vertex3f{ Vec3f(0.0f, 0.0f, -1.0f) }
		};

		unsigned short lineIndexData[] = { 0, 1 };

		unsigned int& lineMeshId = this->meshIds[static_cast<unsigned int>(PrimitiveType::Line)];
		lineMeshId = rm->CreateMesh();
		Mesh& lineMesh = rm->GetMesh(lineMeshId);

		BufferRef<Vertex3f> vertices;
		vertices.data = lineVertexData;
		vertices.count = sizeof(lineVertexData) / sizeof(Vertex3f);

		BufferRef<unsigned short> indices;
		indices.data = lineIndexData;
		indices.count = sizeof(lineIndexData) / sizeof(unsigned short);

		lineMesh.SetPrimitiveMode(Mesh::PrimitiveMode::Lines);
		lineMesh.Upload_3f(vertices, indices);
	}

	{
		Vertex3f cubeVertexData[] = {
			Vertex3f{ Vec3f(-0.5f, -0.5f, -0.5f) },
			Vertex3f{ Vec3f(0.5f, -0.5f, -0.5f) },
			Vertex3f{ Vec3f(-0.5f, -0.5f, 0.5f) },
			Vertex3f{ Vec3f(0.5f, -0.5f, 0.5f) },
			Vertex3f{ Vec3f(-0.5f, 0.5f, -0.5f) },
			Vertex3f{ Vec3f(0.5f, 0.5f, -0.5f) },
			Vertex3f{ Vec3f(-0.5f, 0.5f, 0.5f) },
			Vertex3f{ Vec3f(0.5f, 0.5f, 0.5f) }
		};

		unsigned short cubeIndexData[] = {
			0, 1, 1, 3, 3, 2, 2, 0,
			0, 4, 1, 5, 2, 6, 3, 7,
			4, 5, 5, 7, 7, 6, 6, 4
		};

		unsigned int& cubeMeshId = this->meshIds[static_cast<unsigned int>(PrimitiveType::Cube)];
		cubeMeshId = rm->CreateMesh();
		Mesh& cubeMesh = rm->GetMesh(cubeMeshId);

		BufferRef<Vertex3f> vertices;
		vertices.data = cubeVertexData;
		vertices.count = sizeof(cubeVertexData) / sizeof(Vertex3f);

		BufferRef<unsigned short> indices;
		indices.data = cubeIndexData;
		indices.count = sizeof(cubeIndexData) / sizeof(unsigned short);

		cubeMesh.SetPrimitiveMode(Mesh::PrimitiveMode::Lines);
		cubeMesh.Upload_3f(vertices, indices);
	}

	{
		static const int sphereVertices = 72;

		Vertex3f sphereVertexData[sphereVertices];

		for (int i = 0; i < 24; ++i)
		{
			float f = Math::Const::Tau / 24 * i;
			sphereVertexData[0 + i] = Vertex3f{ Vec3f(std::sin(f), std::cos(f), 0.0f) };
		}

		for (int i = 0; i < 24; ++i)
		{
			float f = Math::Const::Tau / 24 * i;
			sphereVertexData[24 + i] = Vertex3f{ Vec3f(0.0f, std::sin(f), std::cos(f)) };
		}

		for (int i = 0; i < 24; ++i)
		{
			float f = Math::Const::Tau / 24 * i;
			sphereVertexData[48 + i] = Vertex3f{ Vec3f(std::cos(f), 0.0f, std::sin(f)) };
		}

		unsigned short sphereIndexData[sphereVertices * 2] = {
			0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
			6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12,
			12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18,
			18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 0,

			24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
			30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36,
			36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42,
			42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 24,

			48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 54,
			54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60,
			60, 61, 61, 62, 62, 63, 63, 64, 64, 65, 65, 66,
			66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71, 48
		};

		unsigned int& sphereMeshId = this->meshIds[static_cast<unsigned int>(PrimitiveType::Sphere)];
		sphereMeshId = rm->CreateMesh();
		Mesh& sphereMesh = rm->GetMesh(sphereMeshId);

		BufferRef<Vertex3f> vertices;
		vertices.data = sphereVertexData;
		vertices.count = sizeof(sphereVertexData) / sizeof(Vertex3f);

		BufferRef<unsigned short> indices;
		indices.data = sphereIndexData;
		indices.count = sizeof(sphereIndexData) / sizeof(unsigned short);

		sphereMesh.SetPrimitiveMode(Mesh::PrimitiveMode::Lines);
		sphereMesh.Upload_3f(vertices, indices);
	}

	meshesInitialized = true;
}
Ejemplo n.º 5
0
GameEntity EntityFactory::CreateAsteroid(DirectX::XMFLOAT3 position, DirectX::XMFLOAT3 velocity, DirectX::XMFLOAT3 acceleration, DirectX::XMFLOAT3 rotation, float scale, int id)
{
    EntityManager* pEntity = EntityManager::Instance();
    ResourceManager* pResource = ResourceManager::Instance();

    GameEntity asteroid = pEntity->Create("Asteroid");
    pEntity->AddComponent<CollisionComponent>(asteroid, 0.95f*scale, position);
    pEntity->AddComponent<AsteroidRenderComponent>(asteroid, id);
    pEntity->AddComponent<RenderComponent>(asteroid, pResource->GetMaterial("asteroid"), pResource->GetMesh("Sphere"));
    pEntity->AddComponent<PhysicsComponent>(asteroid, velocity, acceleration);
    TransformComponent* pTransform = pEntity->AddComponent<TransformComponent>(asteroid, position);
    pTransform->transform.SetRotation(rotation);
    pTransform->transform.SetScale(scale);

    return asteroid;
}