Exemple #1
0
BBOX UNIT::GetBoundingBox()
{
	if(m_type == 0)			//Farmer
		return BBOX(m_position + D3DXVECTOR3(0.3f, 1.0f, 0.3f), m_position - D3DXVECTOR3(0.3f, 0.0f, 0.3f));
	else if(m_type == 1)	//Soldier
		return BBOX(m_position + D3DXVECTOR3(0.35f, 1.2f, 0.35f), m_position - D3DXVECTOR3(0.35f, 0.0f, 0.35f));
	else if(m_type == 2)	//Magician
		return BBOX(m_position + D3DXVECTOR3(0.3f, 1.1f, 0.3f), m_position - D3DXVECTOR3(0.3f, 0.0f, 0.3f));

	return BBOX();
}
Exemple #2
0
extern void test_sagwrite_3x3_zero(void)
{
    bbox_t bbox = BBOX(0, 3, 0, 3);
    polyline_t p;
    CU_ASSERT_EQUAL(polyline_rect(bbox, &p), 0);

    domain_t *dom = domain_insert(NULL, &p);
    CU_ASSERT_PTR_NOT_NULL(dom);

    const char path[] = "tmp/sagwrite-3x3.txt";

    CU_ASSERT_EQUAL(sagwrite(path, dom, f0, NULL, 3, 3), 0);

    sagread_t sagread;

    CU_ASSERT_EQUAL(sagread_open(path, &sagread), 0);

    CU_ASSERT_EQUAL_FATAL(sagread.grid.dim, 2);
    CU_ASSERT_EQUAL_FATAL(sagread.vector.dim, 2);

    double eps = 1e-10;

    for (int i = 0 ; i < 2 ; i++)
    {
        CU_ASSERT_EQUAL_FATAL(sagread.grid.n[i], 3);
        CU_ASSERT_DOUBLE_EQUAL(sagread.grid.bnd[i].min, 0.5, eps);
        CU_ASSERT_DOUBLE_EQUAL(sagread.grid.bnd[i].max, 2.5, eps);
    }

    sagread_close(sagread);
    domain_destroy(dom);

    unlink(path);
}
Exemple #3
0
inline
BBOX
bface_bbox(Bface* face) 
{
   BBOX ret = BBOX();
   ret.update(face->v1()->loc());
   ret.update(face->v2()->loc());
   ret.update(face->v3()->loc());
   return ret;
}
Exemple #4
0
inline
BBOX
bface_bbox(QuadtreeNode* face) 
{
   BBOX ret = BBOX();
   ret.update(face->v1());
   ret.update(face->v2());
   ret.update(face->v3());
   return ret;
}
Exemple #5
0
BBOX MESHINSTANCE::GetBoundingBox()
{
	if(m_pMesh == NULL || m_pMesh->m_pMesh == NULL)return BBOX();
	
	if(m_pMesh->m_pMesh->GetFVF() != ObjectVertex::FVF)		// XYZ and NORMAL and UV
		return BBOX();

	BBOX bBox(D3DXVECTOR3(-10000.0f, -10000.0f, -10000.0f),
			  D3DXVECTOR3(10000.0f, 10000.0f, 10000.0f));
	D3DXMATRIX World = GetWorldMatrix();

	//Lock vertex buffer of the object
	ObjectVertex* vertexBuffer = NULL;
	m_pMesh->m_pMesh->LockVertexBuffer(0,(void**)&vertexBuffer);

	//For each vertex in the mesh
	for(int i=0;i<(int)m_pMesh->m_pMesh->GetNumVertices();i++)
	{
		//Transform vertex to world space using the MESHINSTANCE
		//world matrix, i.e. the position, rotation and scale
		D3DXVECTOR3 pos;
		D3DXVec3TransformCoord(&pos, &vertexBuffer[i]._pos, &World);

		// Check if the vertex is outside the bounds
		// if so, then update the bounding volume
		if(pos.x < bBox.min.x)bBox.min.x = pos.x;
		if(pos.x > bBox.max.x)bBox.max.x = pos.x;
		if(pos.y < bBox.min.y)bBox.min.y = pos.y;
		if(pos.y > bBox.max.y)bBox.max.y = pos.y;
		if(pos.z < bBox.min.z)bBox.min.z = pos.z;
		if(pos.z > bBox.max.z)bBox.max.z = pos.z;
	}

	m_pMesh->m_pMesh->UnlockVertexBuffer();

	return bBox;
}
Exemple #6
0
DLLEXPORT
int32_t DLLCALL search(SearchContext* sc, const Rect rect, const int32_t count, Point* out_points)
{
	std::vector<int32_t> res = query_BUQTree(sc->ps, count, BBOX(rect), sc->root);
	
	for (int i = 0; i < res.size(); i++)
	{
		out_points[i].x    = sc->ps.x[res[i]];
		out_points[i].y    = sc->ps.y[res[i]];
		out_points[i].rank = sc->ps.rank[res[i]];
		out_points[i].id   = sc->ps.id[res[i]];
	}

	return res.size();
}
Exemple #7
0
void
OctreeNode::set_neibors()
{
   OctreeNode* n;
   BBOX test_box = BBOX(min()-0.5*dim(), max()+0.5*dim());

   if ((!_leaf || _display) && _height != 1) {
      for (int i = 0; i < 8; i++) {
         n = _parent->get_children()[i];
         if (n != this && (!n->get_leaf() || n->get_disp())) {
            _neibors += n;
         }
      }

      _parent->neibors().num();

      for (int i = 0; i < _parent->neibors().num(); i++) {
         n = _parent->neibors()[i];
         if (!n->get_leaf()) {
            for (int j = 0; j < 8; j++) {
               if (n->get_children()[j]->overlaps(test_box) &&
                   (!n->get_children()[j]->get_leaf() || 
                    n->get_children()[j]->get_disp())) {
                  //XXX - crashing here...
                  _neibors += n->get_children()[j];
               }
            }
         }
      }
        
   }

   if (!_leaf) {
      for (int i = 0; i < 8; i++) {
         _children[i]->set_neibors();
      }
   }
}
BBOX MeshModel::getActualBBox() const
{
	return BBOX(vertices);
}
Exemple #9
0
/********************************************************
Given a velocity vector and a position, it will test all
objects found with the sps octree for collisions and
return and new velocity that doesn't run through objects
********************************************************/
CWvec
Collide::_get_move(CWpt& s, CWvec& vel)
{
   if (_land == NULL)
      return vel;

   //transform source/velocty to object space
   Wpt source = _land->inv_xform() * s;
   Wvec velocity = _land->inv_xform() * vel;

   Wpt dest = source + velocity; //destination to travel to (obj space)
   double speed = velocity.length();

   _hitFaces.clear();

   double boxsize = _size * 5;
   Wvec d = Wvec(1,1,1)*boxsize;
   _camBox = BBOX(source - d, source + d);

	_hitFaces.clear();

	//build collision list from the land
	 buildCollisionList(_RootNode);
		
	//if(_hitFaces.num() != 0)
	//	cout << "Faces Found: " << _hitFaces.num() << endl;

   //if there are no near by nodes then bring camera closer to the object
   if (_hitFaces.empty())
		{
		Wvec force = _land->bbox().center() - dest;
		return velocity+(_size * .1 * log(force.length()) * force);
		}

   ARRAY<Wvec> norms;
   ARRAY<double> weights;
   double totalWeight = 0;

	//spring forces

   //weight all near by nodes
   for (int i = 0; i < _hitFaces.num(); i++) {
      Wpt p;
      _hitFaces[i]->bc2pos(_smplPoints[i],p);
      Wvec n = _hitFaces[i]->bc2norm(_smplPoints[i]);

      //get the projected distance of the camera and the surface point
      //against the normal of the surface point
      Wvec v  = (dest - p).projected(n);
      double dist = n*v;

      //calculate the weight of given point
      weights.add(pow(e,sqr(dist)));
      totalWeight+=weights[i];

      //calculate normal
      if (dist <= _size)       //if its closer than it should be
         norms += speed * (_size - dist) * n;
      else                            //if its further than should be             
         norms += speed * (_size - dist) * -n;
   }

   //calculate combination of all weighted norms
   Wvec force = Wvec(0,0,0);
   for (int i = 0; i < _hitFaces.num(); i++)
      force += (weights[i]/totalWeight) * norms[i];

	//smooth forces so its not jerky
	double a = .1;
   _prevForce = force;
	force = ((1 - a) * (force - _prevForce)) +_pV;
   _pV = force;

/*   
   for (int i = 0; i < _hitFaces.num(); i++)
		{
		Wpt p;
		_hitFaces[i]->bc2pos(_smplPoints[i],p);
		Wvec n = _hitFaces[i]->bc2norm(_smplPoints[i]);

		Wvec v  = ((source + (velocity + force)) - p).projected(n);
		double dist = n*v;
		if(dist < _size)
			velocity = velocity + (n *(_size - dist));
		}
	*/

   return _land->xform() * (velocity + force);
}
Exemple #10
0
 BBOX Rectangle::LocalBBOX() const {
     return BBOX(Vector3f(-x_size / 2.f, EPS, -z_size / 2.f),
                 Vector3f(x_size / 2.f, -EPS, z_size / 2.f));
 }