Пример #1
0
TriangleMesh::TriangleMesh(int nv, int nt, int *ind, Vertex *ver, Material *mat, LightSource *l) : Object(mat, l), numvertices(nv), numtriangles(nt) {
	for (int i = 0; i < nv; i++) {
		vertices[i].object = (TriangleMesh*) this;
	}
	cache = NULL;
	setBBox();
}
void IndexedFaceSet::ComputeBBox()
{
	float XMax = _Vertices[0];
	float YMax = _Vertices[1];
	float ZMax = _Vertices[2];

	float XMin = _Vertices[0];
	float YMin = _Vertices[1];
	float ZMin = _Vertices[2];

	// parse all the coordinates to find the Xmax, YMax, ZMax
	float *v = _Vertices;

	for (unsigned int i = 0; i < (_VSize / 3); ++i) {
		if (*v > XMax)
			XMax = *v;
		if (*v < XMin)
			XMin = *v;
		++v;

		if (*v > YMax)
			YMax = *v;
		if (*v < YMin)
			YMin = *v;
		++v;

		if (*v > ZMax)
			ZMax = *v;
		if (*v < ZMin)
			ZMin = *v;
		++v;
	}

	setBBox(BBox<Vec3f>(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax)));
}
Пример #3
0
void BaseMesh::putIntoObjectSpace()
{
	BoundingBox b = BaseMesh::calculateBBox();
	setBBox(b);
	
	const Vector3F c = b.center();
	
	const unsigned nv = getNumVertices();
	for(unsigned i = 0; i < nv; i++)
		_vertices[i] -= c;
}
Пример #4
0
Triangle::Triangle(const Vector3D & epA, const Vector3D & epB,
                   const Vector3D & epC, Color color)
                    : epA(epA), epB(epB), epC(epC), color(color) {
    normal = (epC - epA).crossProduct(epB - epA).normalize();
    distance = normal.dotProduct(epA);
    setBBox(std::min({epA.getX(), epB.getX(), epC.getX()}),
            std::min({epA.getY(), epB.getY(), epC.getY()}),
            std::min({epA.getZ(), epB.getZ(), epC.getZ()}),
            std::max({epA.getX(), epB.getX(), epC.getX()}),
            std::max({epA.getY(), epB.getY(), epC.getY()}),
            std::max({epA.getZ(), epB.getZ(), epC.getZ()}));
}
Пример #5
0
Character::Character(World *w) : Entity() {
    image->SetTexture(*ImageManager::getInstance()->getImage("them"));
    setBBox(sf::Vector2f(24, 30));
    speed = sf::Vector2f(250, 150);
    isFalling = false;
    canFall = true;
    canMove = true;
    isHanging = false;
    isClimbing = false;
    world = w;
    direction = sf::Vector2f(0, 0);
    origin = sf::Vector2f(0,0);  
}
Пример #6
0
ENTRYPOINT void
reshape_glschool(ModeInfo *mi, int width, int height)
{
	Bool					wire = MI_IS_WIREFRAME(mi);
	double					aspect = (double)width/(double)height;
	glschool_configuration	*sc = &scs[MI_SCREEN(mi)];

	glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sc->context));
	if (sc->school != (School *)0) {
		setBBox(sc->school, -aspect*160, aspect*160, -130, 130, -450, -50.0);
		glDeleteLists(sc->bboxList, 1);
		createBBoxList(&SCHOOL_BBOX(sc->school), &sc->bboxList, wire);
	}
	reshape(width, height);
}
Пример #7
0
Goal::Goal() : Entity() {
    image->SetTexture(*ImageManager::getInstance()->getImage("map/goal"));
    setBBox(sf::Vector2f(36, 30));
}
Пример #8
0
bool CCubeModel::build(const Maths::SVector3D & pos, GLfloat side)
{
  /* cube positional coordinates */
  static const Maths::SVector3D cube_pos_coords[] = {
    /* front face */
    Maths::SVector3D( 1.0f,  0.0f, 1.0f),
    Maths::SVector3D( 1.0f,  1.0f, 1.0f),
    Maths::SVector3D( 0.0f,  1.0f, 1.0f),
    Maths::SVector3D( 0.0f,  0.0f, 1.0f),

    /* back face */
    Maths::SVector3D( 0.0f,  0.0f,  0.0f),
    Maths::SVector3D( 0.0f,  1.0f,  0.0f),
    Maths::SVector3D( 1.0f,  1.0f,  0.0f),
    Maths::SVector3D( 1.0f,  0.0f,  0.0f),

    /* top face */
    Maths::SVector3D( 0.0f,  1.0f,  0.0f),
    Maths::SVector3D( 0.0f,  1.0f,  1.0f),
    Maths::SVector3D( 1.0f,  1.0f,  1.0f),
    Maths::SVector3D( 1.0f,  1.0f,  0.0f),

    /* bottom face */
    Maths::SVector3D( 0.0f,  0.0f,  1.0f),
    Maths::SVector3D( 0.0f,  0.0f,  0.0f),
    Maths::SVector3D( 1.0f,  0.0f,  0.0f),
    Maths::SVector3D( 1.0f,  0.0f,  1.0f),

    /* right face */
    Maths::SVector3D( 1.0f,  0.0f,  0.0f),
    Maths::SVector3D( 1.0f,  1.0f,  0.0f),
    Maths::SVector3D( 1.0f,  1.0f,  1.0f),
    Maths::SVector3D( 1.0f,  0.0f,  1.0f),

    /* left face */
    Maths::SVector3D( 0.0f,  0.0f,  1.0f),
    Maths::SVector3D( 0.0f,  1.0f,  1.0f),
    Maths::SVector3D( 0.0f,  1.0f,  0.0f),
    Maths::SVector3D( 0.0f,  0.0f,  0.0f)
  };
  
  /* cube's texture coordinates */
  static const Maths::SVector2D cube_tex_coords[] = {
    /* front face texture */
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f),

    /* back face texture */
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f),

    /* top face texture */
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f),
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),

    /* bottom face texture */
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f),
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),

    /* right face texture */
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f),

    /* left face texture */
    Maths::SVector2D(1.0f, 1.0f),
    Maths::SVector2D(1.0f, 0.0f),
    Maths::SVector2D(0.0f, 0.0f),
    Maths::SVector2D(0.0f, 1.0f)
  };

  /* indexes for the cube vertices */
  static const GLuint indices[] = {
     0,  1,  2,  3,
     4,  5,  6,  7,
     8,  9, 10, 11,
    12, 13, 14, 15,
    16, 17, 18, 19,
    20, 21, 22, 23
  };

  /* number of elements in cube pos/tex coords and indices arrays */
  static const unsigned int num_elems = sizeof(indices) / sizeof(*indices);

  /* allocate memory on GPU */
  bool vb_res = m_vb.bufferData(NULL, num_elems);
  bool ib_res = m_ib.bufferData(NULL, num_elems);

  if ((!vb_res) || (!ib_res))
  {
    qDebug() << "Failed to allocate memory in GPU for index or vertex buffer";
    return false;
  }

  /* lock the buffers for writing */
  Maths::SVertex *vptr = m_vb.lock(GL_WRITE_ONLY);
  GLuint *iptr  = m_ib.lock(GL_WRITE_ONLY);

  if ((vptr == NULL) || (iptr == NULL))
  {
    qDebug() << "Failed to lock index or vertex buffer";
    return false;
  }

  /* calculate the cube offset */
  Maths::SVector3D cube_pos(pos.x * side, pos.y * side, pos.z * side);

  /* load the model to GPU */
  for (unsigned int i = 0; i < num_elems; ++i)
  {
    vptr[i] = Maths::SVertex(cube_pos + cube_pos_coords[i] * side, cube_tex_coords[i]);
    iptr[i] = indices[i];
  }

  /* unlock the buffers */
  m_ib.unlock();
  m_vb.unlock();

  /* set the bounding box */
  setBBox(CBBox(cube_pos, side));

  return true;
}