Exemple #1
0
int				main(void)
{
	std::list<IGameObject*>		lst;
	Trololo			*obj = new Trololo(1, 1, FOOD);
	Trololo			*obj2 = new Trololo(2, 1, FOOD);
	void			*dl_handle;
	IGraphicLib		*(*lnc)(int, int, std::string);
	void			(*del)(IGraphicLib *);
	IGraphicLib		*lib;
	std::list<int>	scores;

	dl_handle = dlopen("lib_glfw.so", RTLD_LAZY | RTLD_LOCAL);
	if (!dl_handle)
	{
		std::cerr << dlerror() << std::endl;
		return 1;
	}
	lnc = (IGraphicLib *(*)(int, int, std::string)) (dlsym(dl_handle, "getDynLibPointer"));
	if (!lnc)
	{
		std::cerr << dlerror() << std::endl;
		return 1;
	}
	del = (void (*)(IGraphicLib *)) (dlsym(dl_handle, "delLibPointer"));
	if (!del)
	{
		std::cerr << dlerror() << std::endl;
		return 1;
	}
	lst.push_back(obj);
	lst.push_back(obj2);
	scores.push_back(0);
	scores.push_back(2000);
	lib = lnc(1000, 1000, "Nibbler");
	//lib->display(lst);
	lib->display_score(scores);
	while(lib->keyhandler() != 27);
	del(lib);
	dlclose(dl_handle);

	return (0);
}
Exemple #2
0
//collision move sphere with triangle
bool kgmCollision::collision(vec3& start, vec3& end, float radius, vec3& tra, vec3& trb,
                             vec3& trc, vec3& pt_insect)
{
  triangle3 triangle(tra, trb, trc);
  plane3    plane(tra, trb, trc);
  line3     line(start, end);

  float s_dist = plane.distance(start),
        e_dist = plane.distance(end);

  bool b_plinsect = false;
  bool b_plnear = false;

  if(s_dist < 0.0) return false;

  if(plane.intersect(line, pt_insect))
  {
    b_plinsect = true;
  }

  if((e_dist >= 0.0f) && (e_dist < radius))
  {
    pt_insect = plane.projection(end);
    b_plnear = true;
  }

  if(!b_plinsect && !b_plnear)
  {
    return false;
  }

  if(b_plinsect || b_plnear)
  {
    //  return true;
  }

  if(triangle.isin(pt_insect))
  {
    m_point = pt_insect;
    m_normal = plane.normal();

    return true;
  }

  sphere3 sphere(pt_insect, radius);
  /* if(sphere.isin(tra) || sphere.isin(trb) || sphere.isin(trc)){
   m_point = pt_insect;
   m_normal = plane.normal();
   return true;
 }
//*/

  line3 lna(tra, trb), lnb(trb, trc), lnc(trc, tra);

  if(crossLineSphere(lna, sphere) ||
     crossLineSphere(lnb, sphere) ||
     crossLineSphere(lnc, sphere))
  {
    m_point = pt_insect;
    m_normal = plane.normal();

    return true;
  }

  return false;
}