Example #1
0
GameObject * GameObject::createFromFile(const std::string & path)
{
    GameObject *ret = new GameObject("Primitive");
    ret->AddComponent<MeshRenderer>();
    ret->AddComponent<MeshFilter>();

    Mesh * mesh = Resources::LoadMesh(path);

    if (!mesh)
    {
        return NULL;
    }

    Graphics::uploadMesh(mesh);

    MeshFilter *mf = ret->GetComponent<MeshFilter>();
    if (mf) {
     mf->setMesh(mesh);
    }

    MeshRenderer *renderer = ret->GetComponent<MeshRenderer>();
    if (renderer)
    {

    }

    return ret;
}
Example #2
0
GameObject* GameObject::createPrimitive(int primitiveType)
{
  GameObject* gameObject = new GameObject();

  MeshFilter* meshFilter = gameObject->addComponent<MeshFilter>();
  meshFilter->setMesh(Resources::load<Mesh>("primitives/cube"));

  MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
  //meshRenderer->setMaterial(material);

  return gameObject;
}
Example #3
0
void SkyBox::onAwake()
{
  Debug::log("SkyBox awoken");

  std::vector<Vector3> vertices;
  vertices.push_back(Vector3(-100, -100, 50));
  vertices.push_back(Vector3(-100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, -100, 50));
  vertices.push_back(Vector3(-100, -100, 50));

  std::vector<Vector2> uv;
  uv.push_back(Vector2(0, 1));
  uv.push_back(Vector2(0, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 1));
  uv.push_back(Vector2(0, 1));

  std::vector<int> triangles;
  triangles.push_back(0);
  triangles.push_back(1);
  triangles.push_back(2);
  triangles.push_back(3);
  triangles.push_back(4);
  triangles.push_back(5);

  Mesh* mesh = new Mesh();
  mesh->setVertices(vertices);
  mesh->setUv(uv);
  mesh->setTriangles(triangles, 0);

  MeshFilter* meshFilter = getGameObject()->addComponent<MeshFilter>();
  meshFilter->setMesh(mesh);

  Texture2d* texture = Resources::load<Texture2d>("textures/clouds");

  //Texture2d* texture = new Texture2d(1, 1);
  //texture->setPixel(0, 0, Color(1, 0, 0));
  //texture->apply();

  Material* material = new Material(Resources::load<Material>("shaders/Internal-SkyboxTexture"));
  material->setMainTexture(texture);

  MeshRenderer* meshRenderer = getGameObject()->addComponent<MeshRenderer>();
  meshRenderer->setMaterial(material);

  //getGameObject()->getTransform()->translate(Vector3(0, 0, 10));
  //getGameObject()->getTransform()->rotate(Vector3(0, 180, 0));
}
Example #4
0
void BloomScreen::onAwake()
{
  BloomCamera::create();
  playerGo = new GameObject("Player");
  playerGo->getTransform()->setPosition(Vector3(-10, 0, -10));

  MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
  playerMr->setMaterial(Resources::load<Material>("shaders/Internal-MeshRendererTexture"));
  playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse").cast<Texture>());

  arc<Mesh> mesh = Resources::load<Mesh>("models/curuthers/curuthers");
  MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  playerMf->setMesh(mesh);
}
Example #5
0
void MeshCollider::awake()
{
  Debug::log("MeshCollider awaken");

  MeshFilter* meshFilter = getGameObject()->getComponent<MeshFilter>();

  if(meshFilter != NULL)
  {
    mesh = meshFilter->getMesh();
    Debug::log("Added mesh");
  }

  Collider::awake();
}
Example #6
0
void WaterScreen::onAwake()
{
  accel = 0.0f;
  WaterCamera::create();
  effectUp = true;
  effectOffset = 0.0f;
  texOffset = 0.0f;

  waterGo = new GameObject("Water");
  waterGo->getTransform()->rotate(Vector3(0, 180, 0));
  waterGo->getTransform()->translate(Vector3(0, -1, 0));
  waterMr = waterGo->addComponent<MeshRenderer>();
  MeshFilter* waterMf = waterGo->addComponent<MeshFilter>();
  waterMf->setMesh(Resources::load<Mesh>("models/water/water"));
  waterMaterial = Resources::load<Material>("shaders/water");
  waterMr->setMaterial(waterMaterial);
  arc<Texture2d> waterTexture = Resources::load<Texture2d>("models/water/water");
  waterMaterial->setMainTexture(waterTexture.cast<Texture>());

  playerGo = new GameObject("Player");
  playerGo->getTransform()->setPosition(Vector3(0, 0, 0));

  playerMr = playerGo->addComponent<AnimatedMeshRenderer>();

  arc<AnimatedMesh> mesh = Resources::load<AnimatedMesh>("models/captain/captain");
  playerMr->setAnimatedMesh(mesh);

  for(int i = 0; i < playerMr->getRoot()->getTransform()->getChildCount(); i++)
  {
    if(playerMr->getRoot()->getTransform()->getChild(i)->getGameObject()->getName() == "Lightsaber")
    {
      arc<Material> fullRed = Resources::load<Material>("shaders/accum/full_red");
      fullRed->setMainTexture(Resources::load<Texture2d>("models/captain/captain").cast<Texture>());
      playerMr->getRoot()->getTransform()->getChild(i)->getGameObject()->getComponent<MeshRenderer>()
        ->setMaterial(fullRed);
    }
  }

  runAnimation = Resources::load<Animation>("models/captain/run.anm");
  idleAnimation = Resources::load<Animation>("models/captain/idle.anm");
  jumpAnimation = Resources::load<Animation>("models/captain/jump.anm");
  playerMr->setAnimation(idleAnimation);
  playerMr->setFps(1);
  playerMr->play();

  //Mesh* mesh = Resources::load<Mesh>("models/captain/captain");
  //MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  //playerMf->setMesh(mesh);
}
Example #7
0
	inline void Renderer::Render(Camera* camera, Scene* scene) {
		
		if (p_surface == NULL || camera == NULL) return;

		if (m_width != p_surface->w || m_height != p_surface->h) {
			m_width = p_surface->w;
			m_height = p_surface->h;
			SetViewport(0.0f, 0.0f, m_width, m_height);

			if (camera->autoUpdate) {
				camera->Set(m_width, m_height);
				camera->Update();
			}
		}

		SetClearColor(camera->background, 1.0f);
		ClearCanvas(m_clearColor, m_clearDepth, m_clearStencil);
		
		if (scene == NULL) return;
		uint32 i, il;
		
		Array<Sprite*>* sprites = scene->GetComponents<Sprite>();
		if (sprites != NULL) {
			for (i = 0, il = sprites->Length(); i < il; i++) {
				Sprite* sprite = (*sprites)[i];
				GameObject* gameObject = sprite->GetGameObject();
				if (gameObject == NULL) continue;
				Transform* transform = gameObject->GetComponent<Transform>();
				if (transform == NULL) continue;
				
				transform->UpdateMatrices(camera->view);
				m_RenderSprite(camera, sprite, transform);
			}
		}
		
		Array<MeshFilter*>* meshFilters = scene->GetComponents<MeshFilter>();
		if (meshFilters != NULL) {
			for (i = 0, il = meshFilters->Length(); i < il; i++) {
				MeshFilter* meshFilter = (*meshFilters)[i];
				GameObject* gameObject = meshFilter->GetGameObject();
				if (gameObject == NULL) continue;
				Transform* transform = gameObject->GetComponent<Transform>();
				if (transform == NULL) continue;
				
				transform->UpdateMatrices(camera->view);
				m_RenderMeshFilter(camera, meshFilter, transform);
			}
		}
	}
Example #8
0
void Terrain::onAwake()
{
  MeshRenderer* mr = getGameObject()->addComponent<MeshRenderer>();
  MeshFilter* mf = getGameObject()->addComponent<MeshFilter>();
  arc<Mesh> mesh = Resources::load<Mesh>("models/terrain/terrain");
  arc<Texture2d> tex = Resources::load<Texture2d>("models/terrain/terrain");

  arc<Material> material(new Material(Resources::load<Material>("shaders/Internal-MeshRendererTexture")));
  material->setMainTexture(tex.cast<Texture>());

  mr->setMaterial(material);
  mf->setMesh(mesh);

  MeshCollider* meshCollider = getGameObject()->addComponent<MeshCollider>();

  getGameObject()->getTransform()->setPosition(Vector3(0, -1, 25));
}
Example #9
0
void LayerScreen::onAwake()
{
  cameraGo = LayerCamera::create();

  playerGo = new GameObject("Player");
  //playerGo->setLayer(1 << 1);
  playerGo->getTransform()->setPosition(Vector3(0, 0, 0));

  MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
  playerMr->setMaterial(Resources::load<Material>("shaders/textured"));
  playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse"));

  Mesh* mesh = Resources::load<Mesh>("models/curuthers/curuthers");
  MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  playerMf->setMesh(mesh);
  
  
}
void SelectAnimationScreen::onAwake()
{
  modelGo = new GameObject("Model");
  modelGo->addComponent<MeshRenderer>();
  MeshFilter* mf = modelGo->addComponent<MeshFilter>();
  mf->setMesh(Resources::load<Mesh>(SelectModelScreen::choice.substr(0, SelectModelScreen::choice.length() - 4)));

  std::string modelDir = Util::pathOnly(SelectModelScreen::choice);

  Debug::log(modelDir);

  Util::scanDir(modelDir, &files);

  for(int i = 0; i < files.size(); i++)
  {
    std::string curr = files.at(i);

    if(curr.length() <= 4 || curr.substr(curr.length() - 4) != ".anm")
    {
      files.erase(files.begin() + i);
      i--;
    }
  }
}
void mesh_filter::DepthSelfFiltering::addMeshes(MeshFilter<StereoCameraModel>& mesh_filter)
{
  robot_model_loader::RobotModelLoader robotModelLoader("robot_description");
  robot_model::RobotModelConstPtr robotModel = robotModelLoader.getModel();
  const vector<robot_model::LinkModel*>& links = robotModel->getLinkModelsWithCollisionGeometry();
  for (size_t i = 0; i < links.size(); ++i)
  {
    shapes::ShapeConstPtr shape = links[i]->getShape();
    if (shape->type == shapes::MESH)
    {
      const shapes::Mesh& m = static_cast<const shapes::Mesh&>(*shape);
      MeshHandle mesh_handle = mesh_filter.addMesh(m);
      transform_provider_.addHandle(mesh_handle, links[i]->getName());
    }
  }
}
Example #12
0
GameObject* GameObject::createPrimitive(PrimitiveType type)
{
   GameObject *ret = new GameObject("Primitive");
   ret->AddComponent<MeshRenderer>();
   ret->AddComponent<MeshFilter>();

   Mesh* mesh = new Mesh();

   const float shapeSize = 5.5f;

   if (type == GAMEOBJECT_QUAD) {
       mesh->vertices.push_back(glm::vec3(-shapeSize,0,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,0,shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,0,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,0,shapeSize));

       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1));
       mesh->uvs.push_back(glm::vec2(1,0));
       mesh->uvs.push_back(glm::vec2(1,1));

       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Pink());

       mesh->triangles.push_back(0);
       mesh->triangles.push_back(2);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(0);
       mesh->triangles.push_back(3);
       mesh->triangles.push_back(1);
   }

   if (type == GAMEOBJECT_CUBE) {
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize,-shapeSize, shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize,  shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize,  shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize,shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize, shapeSize,shapeSize));

       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, -shapeSize,shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, shapeSize,-shapeSize));
       mesh->vertices.push_back(glm::vec3(shapeSize, shapeSize,shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize, -shapeSize, shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, shapeSize));

       mesh->vertices.push_back(glm::vec3(-shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3(-shapeSize,  shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize, -shapeSize, -shapeSize));
       mesh->vertices.push_back(glm::vec3( shapeSize,  shapeSize, -shapeSize));

       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));
       mesh->normals.push_back(glm::vec3(0,-1,0));

       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));
       mesh->normals.push_back(glm::vec3(0,1,0));

       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));
       mesh->normals.push_back(glm::vec3(-1,0,0));

       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));
       mesh->normals.push_back(glm::vec3(1,0,0));

       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));
       mesh->normals.push_back(glm::vec3(0,0,1));

       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));
       mesh->normals.push_back(glm::vec3(0,0,-1));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,USHRT_MAX));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,0));
       mesh->uvs.push_back(glm::vec2(USHRT_MAX,USHRT_MAX));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->uvs.push_back(glm::vec2(0,0));
       mesh->uvs.push_back(glm::vec2(0,1.0f));
       mesh->uvs.push_back(glm::vec2(1.0f,0));
       mesh->uvs.push_back(glm::vec2(1.0f,1.0f));

       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());
       mesh->colors.push_back(Color::Red());


       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());
       mesh->colors.push_back(Color::Green());


       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());
       mesh->colors.push_back(Color::Blue());


       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());
       mesh->colors.push_back(Color::Pink());


       mesh->triangles.push_back(0);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(2);
       mesh->triangles.push_back(1);
       mesh->triangles.push_back(3);
       mesh->triangles.push_back(2);

       mesh->triangles.push_back(4);
       mesh->triangles.push_back(5);
       mesh->triangles.push_back(6);
       mesh->triangles.push_back(5);
       mesh->triangles.push_back(7);
       mesh->triangles.push_back(6);

       mesh->triangles.push_back(8);
       mesh->triangles.push_back(9);
       mesh->triangles.push_back(10);
       mesh->triangles.push_back(9);
       mesh->triangles.push_back(11);
       mesh->triangles.push_back(10);

       mesh->triangles.push_back(12);
       mesh->triangles.push_back(13);
       mesh->triangles.push_back(14);
       mesh->triangles.push_back(13);
       mesh->triangles.push_back(15);
       mesh->triangles.push_back(14);
   }


   Graphics::uploadMesh(mesh);

   //MeshFilter* mf = dynamic_cast<MeshFilter*>(ret->getComponent("MeshFilter"));
   MeshFilter *mf = ret->GetComponent<MeshFilter>();
   if (mf) {
    mf->setMesh(mesh);
   }

   MeshRenderer *renderer = ret->GetComponent<MeshRenderer>();
   if (renderer)
   {
       //Material * newMaterial = new Material();
       //Shader * phongShader = Shader::Find("phong");
       //newMaterial->setShader(phongShader);

       //renderer->setMaterial(newMaterial);
   }

   return ret;
}
Example #13
0
void MeshRenderer::render()
{
  MeshFilter* meshFilter = getGameObject()->getComponent<MeshFilter>();
  arc<Mesh> mesh;
  Transform* transform = getGameObject()->getTransform();

  if(transform == NULL)
  {
    Debug::log("Failed to find Transform");
    return;
  }

  if(meshFilter == NULL)
  {
    Debug::log("Failed to find MeshFilter");
    return;
  }

  mesh = meshFilter->getMesh();

  if(mesh.get() == NULL)
  {
    Debug::log("No mesh bound");
    return;
  }

  // obtain left-handed coordinate system by multiplying a negative Z scale on ModelView matrix

  Matrix4x4 viewMat = Matrix4x4::getTrs(
    Camera::getCurrent()->getGameObject()->getTransform()->getPosition(),
    Camera::getCurrent()->getGameObject()->getTransform()->getRotation(),
    Vector3(1, 1, 1) * Vector3(1, 1, -1)
  ).inverse();

  Matrix4x4 modelMat = Matrix4x4::getTrs(
    transform->getPosition(),
    transform->getRotation(),
    Vector3(1, 1, 1) * Vector3(1, 1, 1)
  );

  for(int i = 0; i < mesh->getSubmeshCount(); i++)
  {
    arc<Material> material = getMaterial();

    if(materials.size() > i)
    {
      material = materials.at(i);
    }

    if(material.get() == NULL)
    {
      if(mesh->getNormals().size() > 0 && mesh->getUv().size() > 0)
      {
        material = Material::meshNormalTextureMaterial;
        material->setMainTexture(Texture2d::defaultTexture.cast<Texture>());
      }
      else if(mesh->getNormals().size() > 0)
      {
        material = Material::meshNormalMaterial;
      }
      else
      {
        material = Material::meshNormalMaterial;
      }
    }

    material->setMatrix("in_Projection", Camera::getCurrent()->getProjectionMatrix());
    material->setMatrix("in_View", viewMat);
    material->setMatrix("in_NormalMatrix", (viewMat * modelMat.inverse()).transpose());

    for(int j = 0; j < material->getPassCount(); j++)
    {
      material->setPass(j, material);
      Graphics::drawMeshNow(mesh, modelMat, i);
    }
  }
}
void DeferredRenderingApplication::OnStart()
{
	mpMainCamera->GetGameObject()->GetTransform()->SetPosition(glm::vec3(0.0f, FLOOR_SIZE * 0.5f, (float)FLOOR_SIZE));
	mpMainCamera->GetGameObject()->GetTransform()->RotateAround(-20.0f, glm::vec3(1.0f, 0.0f, 0.0f));

	std::vector<PointLight*> pointLights;
	GameObject* pPointLightGameObject;
	PointLight* pPointLight;

	float depthIncrement = FLOOR_SIZE / (float)LIGHT_GRID_DEPTH;
	float horizontalIncrement = FLOOR_SIZE / (float)LIGHT_GRID_WIDTH;
	float intensity = 0.2f;

	for (float z = 1; z < FLOOR_SIZE; z += depthIncrement)
	{
		for (float x = 1; x < FLOOR_SIZE; x += horizontalIncrement)
		{
			pPointLightGameObject = GameObject::Instantiate();
			pPointLightGameObject->GetTransform()->SetPosition(glm::vec3(-(FLOOR_SIZE * 0.5f - (2.0f * SPHERE_RADIUS)) + x, SPHERE_RADIUS * 2.5f, -(FLOOR_SIZE * 0.5f - (2.0f * SPHERE_RADIUS)) + z));

			pPointLight = PointLight::Instantiate(pPointLightGameObject);
			glm::vec4 color = Colors::COMMON_LIGHT_COLORS[Random::Range(0, Colors::NUMBER_OF_COMMON_LIGHT_COLORS)];
			pPointLight->SetDiffuseColor(color);
			pPointLight->SetSpecularColor(color);
			pPointLight->SetIntensity(intensity);

			pointLights.push_back(pPointLight);
		}
	}

	mpCheckersColorMapTexture = TextureImporter::Import("textures/CheckersColorMap.png");

	mpFloorMaterial = new Material(ShaderRegistry::Find("Specular"));
	mpFloorMaterial->SetTexture("colorMap", mpCheckersColorMapTexture);
	mpFloorMaterial->SetVec4("diffuseColor", Colors::WHITE);
	mpFloorMaterial->SetVec4("specularColor", Colors::WHITE);
	mpFloorMaterial->SetFloat("shininess", 5.0f);

	mpFloorMesh = StandardGeometries::CreateXZPlane((float)FLOOR_SIZE, (float)FLOOR_SIZE, 1, 1, glm::vec3(0, 0, 0));

	GameObject* pFloorGameObject = GameObject::Instantiate();
	MeshRenderer* pMeshRenderer = MeshRenderer::Instantiate(pFloorGameObject);
	pMeshRenderer->AddMesh(mpFloorMesh);
	MeshFilter* pMeshFilter = MeshFilter::Instantiate(pFloorGameObject);
	pMeshFilter->SetMaterial(mpFloorMaterial);

	mpSphereMaterial = new Material(ShaderRegistry::Find("SolidColor"));
	mpSphereMaterial->SetVec4("diffuseColor", Colors::WHITE);
	mpSphereMaterial->SetVec4("specularColor", Colors::WHITE);
	mpSphereMaterial->SetFloat("shininess", 30.0f);

	mpSphereMesh = StandardGeometries::CreateSphere(SPHERE_RADIUS, NUMBER_OF_SPHERE_SLICES);

	std::vector<GameObject*> spheres;
	for (float z = 0; z < FLOOR_SIZE; z += 1.0f)
	{
		for (float x = 0; x < FLOOR_SIZE; x += 1.0f)
		{
			GameObject* pSphereGameObject = GameObject::Instantiate();
			pMeshRenderer = MeshRenderer::Instantiate(pSphereGameObject);
			pMeshRenderer->AddMesh(mpSphereMesh);
			pMeshFilter = MeshFilter::Instantiate(pSphereGameObject);
			pMeshFilter->SetMaterial(mpSphereMaterial);
			pSphereGameObject->GetTransform()->SetPosition(glm::vec3(-(FLOOR_SIZE * 0.5f - (2.0f * SPHERE_RADIUS)) + x, SPHERE_RADIUS, -(FLOOR_SIZE * 0.5f - (2.0f * SPHERE_RADIUS)) + z));
			spheres.push_back(pSphereGameObject);
		}
	}

	GameObject* pGeneralBehavioursGameObject = GameObject::Instantiate();

	LightsAnimator* pLightsAnimator = LightsAnimator::Instantiate(pGeneralBehavioursGameObject);
	pLightsAnimator->SetLights(pointLights);

	KeyBindings* pKeyBindings = KeyBindings::Instantiate(pGeneralBehavioursGameObject);

	FirstPersonCameraController* pFirstPersonCameraController = FirstPersonCameraController::Instantiate(pGeneralBehavioursGameObject);
	pFirstPersonCameraController->SetWalkSpeed(WALK_SPEED);
	pFirstPersonCameraController->SetTurnSpeed(TURN_SPEED);
	pFirstPersonCameraController->SetFlying(true);
}