예제 #1
0
void ConstructRegionBrushes(scene::INodePtr brushes[6], const Vector3& region_mins, const Vector3& region_maxs)
{
	const float THICKNESS = 10;
  {
    // set mins
    Vector3 mins(region_mins[0]-THICKNESS, region_mins[1]-THICKNESS, region_mins[2]-THICKNESS);

    // vary maxs
    for(std::size_t i=0; i<3; i++)
    {
      Vector3 maxs(region_maxs[0]+THICKNESS, region_maxs[1]+THICKNESS, region_maxs[2]+THICKNESS);
      maxs[i] = region_mins[i];
      Brush_ConstructCuboid(*Node_getBrush(brushes[i]), 
      						AABB::createFromMinMax(mins, maxs),
      						texdef_name_default(), 
      						TextureProjection());
    }
  }

  {
    // set maxs
    Vector3 maxs(region_maxs[0]+THICKNESS, region_maxs[1]+THICKNESS, region_maxs[2]+THICKNESS);

    // vary mins
    for(std::size_t i=0; i<3; i++)
    {
      Vector3 mins(region_mins[0]-THICKNESS, region_mins[1]-THICKNESS, region_mins[2]-THICKNESS);
      mins[i] = region_maxs[i];
      Brush_ConstructCuboid(*Node_getBrush(brushes[i+3]), 
      						AABB::createFromMinMax(mins, maxs),
      						texdef_name_default(),
      						TextureProjection());
    }
  }
}
예제 #2
0
char* mthr(float time1, float time2, char* inject)
{
    static char fmttime[] = "00:00A> 00:00A";
    int h1 = hours(time1);
    int m1 = mins(time1);
    int h2 = hours(time2);
    int m2 = mins(time2);
    if (clock_is_24h_style()) {
        mini_snprintf(fmttime, sizeof(fmttime), "%d:%02d%s %d:%02d",h1,m1,inject,h2,m2);
	} else {
        if (h1 > 11 && h2 > 11) {
            if (h1 > 12) h1 -= 12;
            if (h2 > 12) h2 -= 12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dP%s %d:%02dP",h1,m1,inject,h2,m2);
        } else if (h1 > 11) {
			if (h1 > 12) h1 -= 12;
			if (h2 == 0) h2=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dP%s %d:%02dA",h1,m1,inject,h2,m2);
        } else if (h2 > 11) {
			if (h2 > 12) h2 -= 12;
			if (h1 == 0) h1=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dA%s %d:%02dP",h1,m1,inject,h2,m2);
        } else {
			if (h1 == 0) h1=12;
			if (h2 == 0) h2=12;
            mini_snprintf(fmttime, sizeof(fmttime), "%d:%02dA%s %d:%02dA",h1,m1,inject,h2,m2);
        }
    }
    return fmttime;
}
예제 #3
0
void ConstructRegionBrushes(scene::Node* brushes[6], const Vector3& region_mins, const Vector3& region_maxs)
{
  {
    // set mins
    Vector3 mins(region_mins[0]-32, region_mins[1]-32, region_mins[2]-32);

    // vary maxs
    for(std::size_t i=0; i<3; i++)
    {
      Vector3 maxs(region_maxs[0]+32, region_maxs[1]+32, region_maxs[2]+32);
      maxs[i] = region_mins[i];
      Brush_ConstructCuboid(*Node_getBrush(*brushes[i]), aabb_for_minmax(mins, maxs), texdef_name_default(), TextureProjection());
    }
  }

  {
    // set maxs
    Vector3 maxs(region_maxs[0]+32, region_maxs[1]+32, region_maxs[2]+32);

    // vary mins
    for(std::size_t i=0; i<3; i++)
    {
      Vector3 mins(region_mins[0]-32, region_mins[1]-32, region_mins[2]-32);
      mins[i] = region_maxs[i];
      Brush_ConstructCuboid(*Node_getBrush(*brushes[i+3]), aabb_for_minmax(mins, maxs), texdef_name_default(), TextureProjection());
    }
  }
}
예제 #4
0
파일: Geometry.cpp 프로젝트: Clever-Boy/XLE
    std::pair<Float3, Float3> TransformBoundingBox(const Float3x4& transformation, std::pair<Float3, Float3> boundingBox)
    {
        Float3 corners[] = 
        {
            Float3(  boundingBox.first[0], boundingBox.first[1],  boundingBox.first[2] ),
            Float3( boundingBox.second[0], boundingBox.first[1],  boundingBox.first[2] ),
            Float3(  boundingBox.first[0], boundingBox.second[1], boundingBox.first[2] ),
            Float3( boundingBox.second[0], boundingBox.second[1], boundingBox.first[2] ),

            Float3(  boundingBox.first[0], boundingBox.first[1],  boundingBox.second[2] ),
            Float3( boundingBox.second[0], boundingBox.first[1],  boundingBox.second[2] ),
            Float3(  boundingBox.first[0], boundingBox.second[1], boundingBox.second[2] ),
            Float3( boundingBox.second[0], boundingBox.second[1], boundingBox.second[2] )
        };

        for (unsigned c=0; c<dimof(corners); ++c) {
            corners[c] = TransformPoint(transformation, corners[c]);
        }

        Float3 mins(FLT_MAX, FLT_MAX, FLT_MAX), maxs(-FLT_MAX, -FLT_MAX, -FLT_MAX);
        for (unsigned c=0; c<dimof(corners); ++c) {
            mins[0] = std::min(mins[0], corners[c][0]);
            mins[1] = std::min(mins[1], corners[c][1]);
            mins[2] = std::min(mins[2], corners[c][2]);

            maxs[0] = std::max(maxs[0], corners[c][0]);
            maxs[1] = std::max(maxs[1], corners[c][1]);
            maxs[2] = std::max(maxs[2], corners[c][2]);
        }

        return std::make_pair(mins, maxs);
    }
예제 #5
0
void glBox(idVec3_t &color, idVec3_t &point, float size) {
	idVec3_t mins(point);
	idVec3_t maxs(point);
	mins[0] -= size;
	mins[1] += size;
	mins[2] -= size;
	maxs[0] += size;
	maxs[1] -= size;
	maxs[2] += size;
	qglColor3fv(color);
	qglBegin(GL_LINE_LOOP);
	qglVertex3f(mins[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],maxs[1],mins[2]);
	qglVertex3f(mins[0],maxs[1],mins[2]);
	qglEnd();
	qglBegin(GL_LINE_LOOP);
	qglVertex3f(mins[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],maxs[2]);
	qglEnd();

	qglBegin(GL_LINES);
  	qglVertex3f(mins[0],mins[1],mins[2]);
	qglVertex3f(mins[0],mins[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],mins[2]);
	qglEnd();

}
예제 #6
0
Nested<CircleArc> canonicalize_circle_arcs(Nested<const CircleArc> polys) {
  // Find the minimal point in each polygon under lexicographic order
  Array<int> mins(polys.size());
  for (int p=0;p<polys.size();p++) {
    const auto poly = polys[p];
    for (int i=1;i<poly.size();i++)
      if (lex_less(poly[i].x,poly[mins[p]].x))
        mins[p] = i;
  }

  // Sort the polygons
  struct Order {
    Nested<const CircleArc> polys;
    RawArray<const int> mins;
    Order(Nested<const CircleArc> polys, RawArray<const int> mins)
      : polys(polys), mins(mins) {}
    bool operator()(int i,int j) const {
      return lex_less(polys(i,mins[i]).x,polys(j,mins[j]).x);
    }
  };
  Array<int> order = arange(polys.size()).copy();
  sort(order,Order(polys,mins));

  // Copy into new array
  Nested<CircleArc> new_polys(polys.sizes().subset(order).copy(),uninit);
  for (int p=0;p<polys.size();p++) {
    const int base = mins[order[p]];
    const auto poly = polys[order[p]];
    const auto new_poly = new_polys[p];
    for (int i=0;i<poly.size();i++)
      new_poly[i] = poly[(i+base)%poly.size()];
  }
  return new_polys;
}
예제 #7
0
파일: rar.c 프로젝트: jra101/sumatrapdf
static bool rar_restart_solid(ar_archive *ar)
{
    ar_archive_rar *rar = (ar_archive_rar *)ar;
    off64_t current_offset = ar->entry_offset;
    log("Restarting decompression for solid entry");
    if (!ar_parse_entry_at(ar, ar->entry_offset_first)) {
        ar_parse_entry_at(ar, current_offset);
        return false;
    }
    while (ar->entry_offset < current_offset) {
        size_t size = ar->entry_size_uncompressed;
        rar->solid.restart = false;
        while (size > 0) {
            unsigned char buffer[1024];
            size_t count = mins(size, sizeof(buffer));
            if (!ar_entry_uncompress(ar, buffer, count)) {
                ar_parse_entry_at(ar, current_offset);
                return false;
            }
            size -= count;
        }
        if (!ar_parse_entry(ar)) {
            ar_parse_entry_at(ar, current_offset);
            return false;
        }
    }
    rar->solid.restart = false;
    return true;
}
예제 #8
0
Q3BSPNode *Q3BSPRep::createNode( int n ){
	q3_node *q3node=(q3_node*)header.dir[3].lump+n;
	q3_plane *q3plane=(q3_plane*)header.dir[2].lump+q3node->plane;

	Q3BSPNode *node=new Q3BSPNode;

	Vector mins( q3node->mins[0],q3node->mins[1],q3node->mins[2] );
	Vector maxs( q3node->maxs[0],q3node->maxs[1],q3node->maxs[2] );

	node->box=Box( tf(mins) );
	node->box.update( tf(maxs) );
	node->plane.n=tf(q3plane->normal);
	node->plane.d=-q3plane->distance;

	for( int k=0;k<2;++k ){
		if( q3node->children[k]>=0 ){
			node->nodes[k]=createNode( q3node->children[k] );
			node->leafs[k]=0;
		}else{
			node->leafs[k]=createLeaf( -q3node->children[k]-1 );
			node->nodes[k]=0;
		}
	}

	return node;
}
예제 #9
0
void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const std::string& shader, const TextureProjection& projection)
{
  const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } };
  Vector3 mins(bounds.origin - bounds.extents);
  Vector3 maxs(bounds.origin + bounds.extents);

  brush.clear();
  brush.reserve(6);

  {
    for(int i=0; i < 3; ++i)
    {
      Vector3 planepts1(maxs);
      Vector3 planepts2(maxs);
      planepts2[box[i][0]] = mins[box[i][0]];
      planepts1[box[i][1]] = mins[box[i][1]];

      brush.addPlane(maxs, planepts1, planepts2, shader, projection);
    }
  }
  {
    for(int i=0; i < 3; ++i)
    {
      Vector3 planepts1(mins);
      Vector3 planepts2(mins);
      planepts1[box[i][0]] = maxs[box[i][0]];
      planepts2[box[i][1]] = maxs[box[i][1]];

      brush.addPlane(mins, planepts1, planepts2, shader, projection);
    }
  }
}
예제 #10
0
void Clipper::getPlanePoints(Vector3 planepts[3], const AABB& bounds) const {
	ASSERT_MESSAGE(valid(), "clipper points not initialised");

	planepts[0] = _clipPoints[0]._coords;
	planepts[1] = _clipPoints[1]._coords;
	planepts[2] = _clipPoints[2]._coords;

	Vector3 maxs(bounds.origin + bounds.extents);
	Vector3 mins(bounds.origin - bounds.extents);

	if (!_clipPoints[2].isSet()) {
		int n = (_viewType == XY) ? 2 : (_viewType == YZ) ? 0 : 1;
		int x = (n == 0) ? 1 : 0;
		int y = (n == 2) ? 1 : 2;

		if (n == 1) // on viewtype XZ, flip clip points
		{
			planepts[0][n] = maxs[n];
			planepts[1][n] = maxs[n];
			planepts[2][x] = _clipPoints[0]._coords[x];
			planepts[2][y] = _clipPoints[0]._coords[y];
			planepts[2][n] = mins[n];
		}
		else {
			planepts[0][n] = mins[n];
			planepts[1][n] = mins[n];
			planepts[2][x] = _clipPoints[0]._coords[x];
			planepts[2][y] = _clipPoints[0]._coords[y];
			planepts[2][n] = maxs[n];
		}
	}
}
예제 #11
0
파일: Fonts.cpp 프로젝트: YoungBot/Engine
Vertex3D_PCT* Fonts::CreateCharactersVerts(Vector3 startPos, std::string words, float scale, RGBA& color, int& size)
{
	size_t wordsLength = words.length();
	Vertex3D_PCT* verts = new Vertex3D_PCT[wordsLength*6];
	float startPosX = startPos.x;
	float startPosY = startPos.y;
	for (size_t i = 0; i < wordsLength; i++)
	{
		for (unsigned int j = 0; j<m_characters.size(); j++)
		{
			if (m_characters[j].m_ID != words[i])
			{
				continue;
			}
			Vector2 mins(startPosX + scale*m_characters[j].m_OffsetXY.x, startPosY - scale*(m_characters[j].m_OffsetXY.y + m_characters[j].m_GLYPHWH.y));
			Vector2 maxs(startPosX + scale*(m_characters[j].m_OffsetXY.x + m_characters[j].m_GLYPHWH.x), startPosY - scale*(m_characters[j].m_OffsetXY.y));
			verts[i*6] = Vertex3D_PCT(Vector3(mins.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), color);
			verts[i*6+1] = Vertex3D_PCT(Vector3(mins.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), color);
			verts[i*6+2] = Vertex3D_PCT(Vector3(maxs.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), color);
															
			verts[i * 6 + 3] = Vertex3D_PCT(Vector3(mins.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), color);
			verts[i * 6 + 4] = Vertex3D_PCT(Vector3(maxs.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), color);
			verts[i * 6 + 5] = Vertex3D_PCT(Vector3(maxs.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y), color);


			startPosX += scale*m_characters[j].m_XAdvance;
			break;
		}
	}
	size = wordsLength*6;
	return verts;
}
    int minCut(string s) {
        
        int len = s.size();
        int minSplit = 1000;
        
        if(len <= 0){
        	return minSplit;
        }

        vector<int> mins(len);
        mins[0] = 0;

        for(int i = 1; i < len; i++){
        	int min = 1000;
        	for(int j = i; j > 0; j--){
        		if(mins[j - 1] < min && isPalindrome(s, j, i - j + 1)){
        			int curStep = mins[j - 1] + 1;
        			min = curStep > min ? min : curStep;
        		}
        	}
        	if(isPalindrome(s, 0, i + 1)){
        		min = 0;
        	}
        	mins[i] = min;
        }

        return mins[len - 1];
    }
예제 #13
0
파일: main.cpp 프로젝트: pibara/MinorFs2
int main(int argc, char *argv[])
{
    int fuseargcount=1;
    char *fuseargv[6];
    struct fuse_operations capfs_oper;
    capfs_oper.init        = capfs_init,
               capfs_oper.destroy     = capfs_destroy,
                          capfs_oper.getattr     = capfs_getattr,
                                     capfs_oper.fgetattr    = capfs_fgetattr,
                                                capfs_oper.access      = capfs_access,
                                                           capfs_oper.readlink    = capfs_readlink,
                                                                      capfs_oper.readdir     = capfs_readdir,
                                                                                 capfs_oper.mknod       = capfs_mknod,
                                                                                            capfs_oper.mkdir       = capfs_mkdir,
                                                                                                       capfs_oper.symlink     = capfs_symlink,
                                                                                                                  capfs_oper.unlink      = capfs_unlink,
                                                                                                                             capfs_oper.rmdir       = capfs_rmdir,
                                                                                                                                        capfs_oper.rename      = capfs_rename,
                                                                                                                                                   capfs_oper.link        = capfs_link,
                                                                                                                                                              capfs_oper.chmod       = capfs_chmod,
                                                                                                                                                                         capfs_oper.chown       = capfs_chown,
                                                                                                                                                                                    capfs_oper.truncate    = capfs_truncate,
                                                                                                                                                                                               capfs_oper.ftruncate   = capfs_ftruncate,
                                                                                                                                                                                                          capfs_oper.utimens     = capfs_utimens,
                                                                                                                                                                                                                     capfs_oper.create      = capfs_create,
                                                                                                                                                                                                                                capfs_oper.open        = capfs_open,
                                                                                                                                                                                                                                           capfs_oper.read        = capfs_read,
                                                                                                                                                                                                                                                      capfs_oper.write       = capfs_write,
                                                                                                                                                                                                                                                                 capfs_oper.statfs      = capfs_statfs,
                                                                                                                                                                                                                                                                            capfs_oper.release     = capfs_release,
                                                                                                                                                                                                                                                                                       capfs_oper.opendir     = capfs_opendir,
                                                                                                                                                                                                                                                                                                  capfs_oper.releasedir  = capfs_releasedir,
                                                                                                                                                                                                                                                                                                             capfs_oper.fsync       = capfs_fsync,
                                                                                                                                                                                                                                                                                                                        capfs_oper.flush       = capfs_flush,
                                                                                                                                                                                                                                                                                                                                   capfs_oper.fsyncdir    = capfs_fsyncdir,
                                                                                                                                                                                                                                                                                                                                              capfs_oper.lock        = capfs_lock,
                                                                                                                                                                                                                                                                                                                                                         capfs_oper.bmap        = capfs_bmap,
                                                                                                                                                                                                                                                                                                                                                                    capfs_oper.ioctl       = capfs_ioctl,
                                                                                                                                                                                                                                                                                                                                                                               capfs_oper.poll        = capfs_poll,
                                                                                                                                                                                                                                                                                                                                                                                          capfs_oper.setxattr    = capfs_setxattr,
                                                                                                                                                                                                                                                                                                                                                                                                     capfs_oper.getxattr    = capfs_getxattr,
                                                                                                                                                                                                                                                                                                                                                                                                                capfs_oper.listxattr   = capfs_listxattr,
                                                                                                                                                                                                                                                                                                                                                                                                                           capfs_oper.removexattr = capfs_removexattr,
                                                                                                                                                                                                                                                                                                                                                                                                                                      capfs_oper.flag_nullpath_ok = 0;
    fuseargv[0]=argv[0];
    if ((argc > 1) && (argv[1][0] == '-')) {
        fuseargv[1]=argv[1];
        fuseargcount=2;
    }
    string_literal_wrapper mino("-o");
    fuseargv[fuseargcount]=mino;     //After the argv[0] and optionaly a -d argument set some options:
    string_literal_wrapper allow_other("allow_other");
    fuseargv[fuseargcount+1]=allow_other;  //* allow all users to access the filesystem.
    string_literal_wrapper mins("-s");
    fuseargv[fuseargcount+2]=mins; //Run the filesystem as single threaded.
    string_literal_wrapper mountpoint("/minorfs/cap");
    fuseargv[fuseargcount+3]=mountpoint;
    return fuse_main(4+fuseargcount, fuseargv, &capfs_oper,NULL);
}
//=mins if dir < 0
//=maxs if dir >= 0
array minmaxs(const array f1,const array f2,const array df,const array dir )
{
  array condition = (dir>=0);
  array res = condition*maxs(f1, f2, df)
    +(1-condition)*mins(f1, f2, df);
  res.eval();
  return res;
}
예제 #15
0
static CString GetStringTime(__int64 ms)
{
	__int64 h(ms/(1000*60*60));
	__int64 mins(ms-h*1000*60*60);
	__int64 m(mins/(1000*60));
	__int64 s(mins-m*1000*60);
	s /= 1000;
	CString t;
	t.Format(_T("%02d:%02d:%02d"), (int)h,(int)m,(int)s);
	return t;
}
예제 #16
0
파일: Cone.cpp 프로젝트: AresAndy/ufoai
	void Cone::generate (Brush& brush, const AABB& bounds, std::size_t sides, const TextureProjection& projection,
			const std::string& shader)
	{
		if (sides < _minSides) {
			gtkutil::errorDialog(_("Too few sides for constructing the prism, minimum is 3"));
			return;
		}
		if (sides > _maxSides) {
			gtkutil::errorDialog(_("Too many sides for constructing the prism, maximum is 32"));
			return;
		}

		brush.clear();
		brush.reserve(sides + 1);

		Vector3 mins(bounds.origin - bounds.extents);
		Vector3 maxs(bounds.origin + bounds.extents);

		float radius = maxExtent(bounds.extents);
		const Vector3& mid = bounds.origin;
		Vector3 planepts[3];

		planepts[0][0] = mins[0];
		planepts[0][1] = mins[1];
		planepts[0][2] = mins[2];
		planepts[1][0] = maxs[0];
		planepts[1][1] = mins[1];
		planepts[1][2] = mins[2];
		planepts[2][0] = maxs[0];
		planepts[2][1] = maxs[1];
		planepts[2][2] = mins[2];

		brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);

		for (std::size_t i = 0; i < sides; ++i) {
			double sv = sin(i * 3.14159265 * 2 / sides);
			double cv = cos(i * 3.14159265 * 2 / sides);

			planepts[0][0] = static_cast<float> (floor(mid[0] + radius * cv + 0.5));
			planepts[0][1] = static_cast<float> (floor(mid[1] + radius * sv + 0.5));
			planepts[0][2] = mins[2];

			planepts[1][0] = mid[0];
			planepts[1][1] = mid[1];
			planepts[1][2] = maxs[2];

			planepts[2][0] = static_cast<float> (floor(planepts[0][0] - radius * sv + 0.5));
			planepts[2][1] = static_cast<float> (floor(planepts[0][1] + radius * cv + 0.5));
			planepts[2][2] = maxs[2];

			brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
		}
	}
//#################### PUBLIC METHODS ####################
void BroadPhaseCollisionDetector::add_object(const PhysicsObject_Ptr& object)
{
	// Step 1:	Determine the lowest grid for the object, based on the maximum dimension of
	// the bounding box of its movement.
	Vector3d halfDimensions = object->bounds(m_boundsManager)->half_dimensions();
	Vector3d previousPos = object->previous_position() ? *object->previous_position() : object->position();
	Vector3d pos = object->position();

	Vector3d mins(std::min(previousPos.x, pos.x), std::min(previousPos.y, pos.y), std::min(previousPos.z, pos.z));
	mins -= halfDimensions;
	Vector3d maxs(std::max(previousPos.x, pos.x), std::max(previousPos.y, pos.y), std::max(previousPos.z, pos.z));
	maxs += halfDimensions;

	Vector3d size = maxs - mins;
	double maxDimension = std::max(std::max(size.x, size.y), size.z);

	HGrid::iterator lowestGrid = m_hgrid.lower_bound(maxDimension);

	// Step 2:	Determine which cells it overlaps on the lowest grid just identified.
	std::set<CellIndex> cells = determine_overlapped_cells(mins, maxs, lowestGrid->first);

	// Step 3:	Insert the object into every grid above (and including) the lowest one,
	//			flagging collisions where applicable.
	for(HGrid::iterator it=lowestGrid, iend=m_hgrid.end(); it!=iend; ++it)
	{
		bool lowest = it == lowestGrid;

		if(!lowest)
		{
			// Propagate the cells up to the next layer.
			cells = propagate_cells(cells);
		}

		for(std::set<CellIndex>::const_iterator jt=cells.begin(), jend=cells.end(); jt!=jend; ++jt)
		{
			CellData& data = it->second[*jt];

			// Look through the objects already overlapping the cell and flag any necessary collisions.
			for(CellData::const_iterator kt=data.begin(), kend=data.end(); kt!=kend; ++kt)
			{
				if(lowest || kt->second)	// if this is the lowest layer for at least one of the objects
				{
					m_potentialCollisions.insert(std::make_pair(kt->first, object));
				}
			}

			// Add the object itself to the set of those overlapping the cell.
			data.push_back(std::make_pair(object, lowest));
		}
	}
}
예제 #18
0
void Brush_ConstructCone(Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection)
{
  if(sides < c_brushCone_minSides)
  {
    globalErrorStream() << c_brushCone_name << ": sides " << Unsigned(sides) << ": too few sides, minimum is " << Unsigned(c_brushCone_minSides) << "\n";
    return;
  }
  if(sides > c_brushCone_maxSides)
  {
    globalErrorStream() << c_brushCone_name << ": sides " << Unsigned(sides) << ": too many sides, maximum is " << Unsigned(c_brushCone_maxSides) << "\n";
    return;
  }

  brush.undoSave();
  brush.clear();
  brush.reserve(sides+1);

  Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
  Vector3 maxs(vector3_added(bounds.origin, bounds.extents));

  float radius = max_extent(bounds.extents);
  const Vector3& mid = bounds.origin;
  Vector3 planepts[3];

  planepts[0][0] = mins[0];planepts[0][1] = mins[1];planepts[0][2] = mins[2];
  planepts[1][0] = maxs[0];planepts[1][1] = mins[1];planepts[1][2] = mins[2];
  planepts[2][0] = maxs[0];planepts[2][1] = maxs[1];planepts[2][2] = mins[2];

  brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);

  for (std::size_t i=0 ; i<sides ; ++i)
  {
    double sv = sin (i*3.14159265*2/sides);
    double cv = cos (i*3.14159265*2/sides);

    planepts[0][0] = static_cast<float>(floor(mid[0]+radius*cv+0.5));
    planepts[0][1] = static_cast<float>(floor(mid[1]+radius*sv+0.5));
    planepts[0][2] = mins[2];

    planepts[1][0] = mid[0];
    planepts[1][1] = mid[1];
    planepts[1][2] = maxs[2];

    planepts[2][0] = static_cast<float>(floor(planepts[0][0] - radius * sv + 0.5));
    planepts[2][1] = static_cast<float>(floor(planepts[0][1] + radius * cv + 0.5));
    planepts[2][2] = maxs[2];

    brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
  }
}
예제 #19
0
int minCut(string s) {
    int len = (int)s.length();
    
    if (len == 0) return 0;
    
    /* Step 1 Generate Palindrome Matrix */
    vector<vector<bool>> palinMat;
    for (int i = 0; i < len; i++) {
        vector<bool> palinRow = vector<bool>(len,false);
        palinRow[i] = true;
        palinMat.push_back(palinRow);
    }
    
    // step size from 1 to N - 1
    for (int step = 1; step < len; step++) {
        for (int start = 0; start + step < len; start++) {
            int end = start + step;
            if (s[start] != s[end]) {//s[i] != s[j], mat(i,j) = false
                palinMat[start][end] = false;
            }else{
                //s[i] == s[j], check mat[i+1,j-1] when step > 1,if step == 1 no need to check
                if (step == 1) palinMat[start][end] = true;
                else palinMat[start][end] = palinMat[start + 1][end - 1];
            }
        }
    }
    
    
    /* use dp to find min-cut
     Under the condition palinMat[start][end] == true:
     1) mins[end] = mins[start - 1] + 1     if mins[end] > mins[start - 1] + 1
     2) mins[end] = 0                       if start == 0
     */
    vector<int> mins(len,len);
    mins[0] = 0;
    for (int start = 0; start < len; start++) {
        for (int end = start; end < len; end++) {
            if (palinMat[start][end] && start == 0) {
                mins[end] = 0;
                continue;
            }
            if (palinMat[start][end] && mins[start - 1] + 1 < mins[end])
                mins[end] = mins[start - 1] + 1;
        }
    }
    
    return mins[len - 1];
}
예제 #20
0
파일: Fonts.cpp 프로젝트: YoungBot/Engine
NTBVertex3D_PCT* Fonts::CreateNTBVertsFromStringVector(Vector3 startPos, std::vector<std::string>& currentStringVec, float scale, RGBA& color, int& size)
{
	size = 0;
	std::vector<NTBVertex3D_PCT> verts;
	RGBA fadeColor = RGBA(color.GetRed(), color.GetGreen(), color.GetBlue(), fadeScale);
	for (int k = (int)currentStringVec.size() - 1; k >= 0; k--)
	{
		size_t wordsLength = currentStringVec[k].length();

		float startPosX = startPos.x;
		float startPosY = startPos.y;
		float yOffsetFloat = 0.0f;
		m_curserPos.x = startPosX;
		for (size_t i = 0; i < wordsLength; i++)
		{
			for (unsigned int j = 0; j < m_characters.size(); j++)
			{
				if (m_characters[j].m_ID != currentStringVec[k][i])
				{
					continue;
				}
				Vector2 mins(startPosX + scale*m_characters[j].m_OffsetXY.x, startPosY - scale*(m_characters[j].m_OffsetXY.y + m_characters[j].m_GLYPHWH.y));
				Vector2 maxs(startPosX + scale*(m_characters[j].m_OffsetXY.x + m_characters[j].m_GLYPHWH.x), startPosY - scale*(m_characters[j].m_OffsetXY.y));
				mins += Vector2(0.0f, m_scale * (currentStringVec.size() - k - 1));
				maxs += Vector2(0.0f, m_scale * (currentStringVec.size() - k - 1));
				verts.push_back(NTBVertex3D_PCT(Vector3(mins.x, maxs.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
				verts.push_back(NTBVertex3D_PCT(Vector3(mins.x, mins.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
				verts.push_back(NTBVertex3D_PCT(Vector3(maxs.x, mins.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
								
				verts.push_back(NTBVertex3D_PCT(Vector3(mins.x, maxs.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
				verts.push_back(NTBVertex3D_PCT(Vector3(maxs.x, mins.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
				verts.push_back(NTBVertex3D_PCT(Vector3(maxs.x, maxs.y - yOffsetFloat, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), Vector3(0.0F, 0.0F, 0.0F), fadeColor));
				startPosX += scale*m_characters[j].m_XAdvance;

				break;
			}

		}
		yOffsetFloat += 0.0f;
	}
	NTBVertex3D_PCT* passOutVerts = new NTBVertex3D_PCT[verts.size()];
	memcpy(passOutVerts, verts.data(), verts.size()*sizeof(NTBVertex3D_PCT));
	size = verts.size();
	return passOutVerts;
}
예제 #21
0
//If 12 hour time, subtract 12 from hr if hr > 12
char* thr(float time, char ap)
{
    static char fmttime[] = "00:00A";
    int h = hours(time);
    int m = mins(time);
    if (clock_is_24h_style()) {
        mini_snprintf(fmttime, sizeof(fmttime), "%d:%02d",h,m);
    } else {
        if (h > 11) {
            if (h > 12) h -= 12;
            mini_snprintf(fmttime, sizeof(fmttime), (ap==1)?"%d:%02dP":"%d:%02d",h,m);
        } else {
			if (h == 0) h=12;
            mini_snprintf(fmttime, sizeof(fmttime), (ap==1)?"%d:%02dA":"%d:%02d",h,m);
        }
    }
    return fmttime;
}
예제 #22
0
파일: Fonts.cpp 프로젝트: YoungBot/Engine
Vertex3D_PCT* Fonts::CreateConsoleCharactersVerts(Vector3 startPos, float scale, RGBA& color, int& size)
{
	size = 0;
	std::vector<Vertex3D_PCT> verts;
	RGBA fadeColor = RGBA(color.GetRed(), color.GetGreen(), color.GetBlue(), fadeScale);
	for (int k = (int)m_log.size()-1; k >= 0; k--)
	{
		size_t wordsLength = m_log[k].length();
		
		float startPosX = startPos.x;
		float startPosY = startPos.y;
		m_curserPos.x = startPosX;
		for (size_t i = 0; i < wordsLength; i++)
		{
			for (unsigned int j = 0; j < m_characters.size(); j++)
			{
				if (m_characters[j].m_ID != m_log[k][i])
				{
					continue;
				}
				Vector2 mins(startPosX + scale*m_characters[j].m_OffsetXY.x, startPosY - scale*(m_characters[j].m_OffsetXY.y + m_characters[j].m_GLYPHWH.y));
				Vector2 maxs(startPosX + scale*(m_characters[j].m_OffsetXY.x + m_characters[j].m_GLYPHWH.x), startPosY - scale*(m_characters[j].m_OffsetXY.y));
				mins += Vector2(0.0f, m_scale * (m_log.size() - k - 1));
				maxs += Vector2(0.0f, m_scale * (m_log.size() - k - 1));
				verts.push_back(Vertex3D_PCT(Vector3(mins.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), fadeColor));
				verts.push_back(Vertex3D_PCT(Vector3(mins.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), fadeColor));
				verts.push_back(Vertex3D_PCT(Vector3(maxs.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), fadeColor));
					 
				verts.push_back(Vertex3D_PCT(Vector3(mins.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x, m_characters[j].m_XY.y), fadeColor));
				verts.push_back(Vertex3D_PCT(Vector3(maxs.x, mins.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y + m_characters[j].m_WH.y), fadeColor));
				verts.push_back(Vertex3D_PCT(Vector3(maxs.x, maxs.y, startPos.z), Vector2(m_characters[j].m_XY.x + m_characters[j].m_WH.x, m_characters[j].m_XY.y), fadeColor));
				startPosX += scale*m_characters[j].m_XAdvance;
				
				break;
			}
			
		}
	}
	Vertex3D_PCT* passOutVerts = new Vertex3D_PCT[verts.size()];
	memcpy(passOutVerts,verts.data(),verts.size()*sizeof(Vertex3D_PCT));
	size = verts.size();
	return passOutVerts;
}
예제 #23
0
inline HRectBound<MetricType, ElemType>& HRectBound<MetricType, ElemType>::operator|=(
    const MatType& data)
{
  Log::Assert(data.n_rows == dim);

  arma::Col<ElemType> mins(min(data, 1));
  arma::Col<ElemType> maxs(max(data, 1));

  minWidth = std::numeric_limits<ElemType>::max();
  for (size_t i = 0; i < dim; i++)
  {
    bounds[i] |= math::RangeType<ElemType>(mins[i], maxs[i]);
    const ElemType width = bounds[i].Width();
    if (width < minWidth)
      minWidth = width;
  }

  return *this;
}
void CPhysicsCollision::InitBBoxCache()
{
	Vector boxVerts[8], *ppVerts[8];
	Vector mins(-16,-16,0), maxs(16,16,72);
	// init with the player box
	InitBoxVerts( boxVerts, ppVerts, mins, maxs );
	// Generate a convex hull from the verts
	CPhysConvex *pConvex = ConvexFromVerts( ppVerts, 8 );
	IVP_Compact_Poly_Point *pPoints = reinterpret_cast<IVP_Compact_Ledge *>(pConvex)->get_point_array();
	for ( int i = 0; i < 8; i++ )
	{
		int nearest = -1;
		float minDist = 0.1;
		Vector tmp;
		ConvertPositionToHL( pPoints[i], tmp );
		for ( int j = 0; j < 8; j++ )
		{
			float dist = (boxVerts[j] - tmp).Length();
			if ( dist < minDist )
			{
				minDist = dist;
				nearest = j;
			}
		}
		
		m_bboxVertMap[i] = nearest;

#if _DEBUG
		for ( int k = 0; k < i; k++ )
		{
			Assert( m_bboxVertMap[k] != m_bboxVertMap[i] );
		}
#endif
		// NOTE: If this is wrong, you can disable FAST_BBOX above to fix
		AssertMsg( nearest != -1, "CPhysCollide: Vert map is wrong\n" );
	}
	CPhysCollide *pCollide = ConvertConvexToCollide( &pConvex, 1 );
	AddBBoxCache( pCollide, mins, maxs );
}
예제 #25
0
 int maximumGap(vector<int>& nums) {
     if (nums.size() < 2)
         return 0;
     int min = *min_element(nums.begin(), nums.end());
     int mymax = *max_element(nums.begin(), nums.end());
     int range = mymax - min;
     int nbuckets = nums.size();
     vector<int> mins(nbuckets, INT_MAX), maxs(nbuckets, INT_MIN);
     for(auto x : nums) {
         int index = ((double)(x-min)*(nbuckets-1))/range;
         if (mins[index] > x) mins[index] = x;
         if (maxs[index] < x) maxs[index] = x;
     }
     int prev = maxs[0];
     mymax = 0;
     for (int i = 1; i < nbuckets; i++) {
         if (mins[i] == INT_MAX) continue;
         mymax = max(mymax, mins[i]-prev);
         prev = maxs[i];
     }
     return mymax;
 }
예제 #26
0
/*
================
glBox
================
*/
void glBox(idVec4 &color, idVec3 &point, float size) {
	idVec3 mins(point);
	idVec3 maxs(point);
	mins[0] -= size;
	mins[1] += size;
	mins[2] -= size;
	maxs[0] += size;
	maxs[1] -= size;
	maxs[2] += size;
	idVec4	saveColor;
	qglGetFloatv(GL_CURRENT_COLOR, saveColor.ToFloatPtr());
	qglColor3fv( color.ToFloatPtr() );
	qglBegin(GL_LINE_LOOP);
	qglVertex3f(mins[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],maxs[1],mins[2]);
	qglVertex3f(mins[0],maxs[1],mins[2]);
	qglEnd();
	qglBegin(GL_LINE_LOOP);
	qglVertex3f(mins[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],maxs[2]);
	qglEnd();

	qglBegin(GL_LINES);
  	qglVertex3f(mins[0],mins[1],mins[2]);
	qglVertex3f(mins[0],mins[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],maxs[2]);
	qglVertex3f(mins[0],maxs[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],mins[2]);
	qglVertex3f(maxs[0],mins[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],maxs[2]);
	qglVertex3f(maxs[0],maxs[1],mins[2]);
	qglEnd();
	qglColor4fv(saveColor.ToFloatPtr());

}
예제 #27
0
void CDecalsDrawerGL4::UpdateBoundingBox(SDecalGroup& g)
{
	if (g.ids.front() == 0) {
		g.boundAABB.fill(float4());
		return;
	}

	// compute the AABB
	float3 mins(1e9,1e9,1e9), maxs(-1e9,-1e9,-1e9);
	for (int idx: g.ids) {
		if (idx == 0)
			break;

		Decal& d = decals[idx];
		const auto e = GetEdgePoinsOfDecal(d);
		for (const float2& p: e) {
			mins = float3::min(mins, float3(p.x, d.pos.y - d.size.x, p.y));
			maxs = float3::max(maxs, float3(p.x, d.pos.y + d.size.x, p.y));
		}
	}
	mins.y = std::max(mins.y, readMap->GetCurrMinHeight());
	maxs.y = std::min(maxs.y, readMap->GetCurrMaxHeight());
	g.boundAABB = {{ float4(mins, 0.f), float4(maxs, 0.f) }};
}
예제 #28
0
static int refine_func(int nv, REAL *vertex, int nf, neigh_faces *tadj, neigh_points *eadj, int nt, int *tetra) {
    int j, l;
    int pn;
    int a, b, c, p;
    int n_iters, s;
    REAL ds, d, *dx;
    REAL dm, d1, d2, delta;
    REAL rs, r;
    REAL x[3], z[3];

    pn = 0;
    ds = 0.0;
    for (j=nf; j<nv; j++) {
        d = 0.0,  s = 0;
        for (l=eadj->i[j]; l<eadj->i[j+1]; l++) {
            c = eadj->p[l];
            d += disti(vertex, j, c);
            s++;
        }
        if (s > 0)  d /= s;
        ds += d;
	pn++;
    }
    if (pn == 0)  return 0;

    ds /= pn;

//    printf("ds = %lf\n", ds);

    dx = (REAL*)libaft_malloc(sizeof(REAL)*3*pn);

    delta = 0.1;
    n_iters = 1000; // 4000
    d = 0.05 * ds * ds / n_iters;  // 1.0
    dm = mins(vertex, nt, tetra);
    if (dm < 0.0) {
	d1 = 0.05 * -dm;
	d2 = 0.0001 * -dm;
    } else {
	d1 = 0.5 * dm;
	d2 = 0.001 * dm;
    }
//    printf("delta in [%le, %le]\n", d1, d2);
    for (s=0; s<n_iters; s++) {
//	dm = mins(vertex, nt, tetra);
//	if (dm < 0.0)  delta = 0.001*-dm;
//	else delta = 0.001*dm;
//	delta = (d1*(n_iters-s) + d2*s)/n_iters;
//	delta = 1e-6;
	delta = 1.0 * ds * ds * ds * (1.0 - 0.999*s/n_iters);
//	printf("delta = %lf\n", delta);
	rs = 0.0;
	for (j=0; j<pn; j++) {
	    p = nf+j;
	    x[0] = 0.0,  x[1] = 0.0,  x[2] = 0.0;
	    for (l=tadj->i[p]; l<tadj->i[p+1]; l++) {
		a = tadj->f[l][0];
		b = tadj->f[l][1];
		c = tadj->f[l][2];
		func_xyz(vertex, p, a, b, c, z, delta, ds, 6);
		x[0] -= z[0],  x[1] -= z[1],  x[2] -= z[2];
	    }
	    r = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
	    if (r>1.0/ds*2) {
                r = 1.0/ds*2*(1.0 + log(r*ds/2))/r;
		x[0] *= r,  x[1] *= r,  x[2] *= r;
	    }
	    dx[3*j + 0] = x[0],  dx[3*j + 1] = x[1],  dx[3*j + 2] = x[2];
	    r = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
	    if (rs < r)  rs = r;
	}
	for (j=0; j<pn; j++) {
	    p = nf+j;
	    vertex[3*p + 0] += d*dx[3*j + 0];
	    vertex[3*p + 1] += d*dx[3*j + 1];
	}
	printf("rs = %le\t[%6.2lf%%]\r", rs*d, 100.0*(s+1.0)/n_iters);
    }
//    printf("\n");

    qmin=1.0, qmax = 0.0, maxdf = 0.0;
    libaft_free(dx);

    return 0;
}
예제 #29
0
파일: nav_node.cpp 프로젝트: paralin/hl2sdk
//--------------------------------------------------------------------------------------------------------------
void CNavNode::CheckCrouch( void )
{
	CTraceFilterWalkableEntities filter( NULL, COLLISION_GROUP_PLAYER_MOVEMENT, WALK_THRU_EVERYTHING );
	trace_t tr;

	// Trace downward from duck height to find the max floor height for the node's surroundings
	Vector mins( -HalfHumanWidth, -HalfHumanWidth, 0 );
	Vector maxs( HalfHumanWidth, HalfHumanWidth, 0 );
	Vector start( m_pos.x, m_pos.y, m_pos.z + VEC_DUCK_HULL_MAX.z - 0.1f );
	UTIL_TraceHull(
		start,
		m_pos,
		mins,
		maxs,
		MASK_PLAYERSOLID_BRUSHONLY,
		&filter,
		&tr );

	Vector groundPos = tr.endpos;

	if ( tr.startsolid && !tr.allsolid )
	{
		// Try going down out of the solid and re-check for the floor height
		start.z -= tr.endpos.z - 0.1f;

		UTIL_TraceHull(
			start,
			m_pos,
			mins,
			maxs,
			MASK_PLAYERSOLID_BRUSHONLY,
			&filter,
			&tr );

		groundPos = tr.endpos;
	}

	if ( tr.startsolid )
	{
		// we don't even have duck height clear.  try a simple check to find floor height.
		float x, y;

		// Find the highest floor z - for a player to stand in this area, we need a full
		// VEC_HULL_MAX.z of clearance above this height at all points.
		float maxFloorZ = m_pos.z;
		for( y = -HalfHumanWidth; y <= HalfHumanWidth + 0.1f; y += HalfHumanWidth )
		{
			for( x = -HalfHumanWidth; x <= HalfHumanWidth + 0.1f; x += HalfHumanWidth )
			{
				float floorZ;
				if ( TheNavMesh->GetGroundHeight( m_pos, &floorZ ) )
				{
					maxFloorZ = MAX( maxFloorZ, floorZ + 0.1f );
				}
			}
		}

		groundPos.Init( m_pos.x, m_pos.y, maxFloorZ );
	}

	// For each direction, trace upwards from our best ground height to VEC_HULL_MAX.z to see if we have standing room.
	for ( int i=0; i<NUM_CORNERS; ++i )
	{
#if DEBUG_NAV_NODES
		if ( nav_test_node_crouch_dir.GetInt() != NUM_CORNERS && i != nav_test_node_crouch_dir.GetInt() )
			continue;
#endif // DEBUG_NAV_NODES

		NavCornerType corner = (NavCornerType)i;
		Vector2D cornerVec;
		CornerToVector2D( corner, &cornerVec );

		Vector actualGroundPos = groundPos; // we might need to adjust this if the tracehull failed above and we fell back to m_pos.z

		// Build a mins/maxs pair for the HumanWidth x HalfHumanWidth box facing the appropriate direction
		mins.Init();
		maxs.Init( cornerVec.x * HalfHumanWidth, cornerVec.y * HalfHumanWidth, 0 );

		// now make sure that mins is smaller than maxs
		for ( int j=0; j<3; ++j )
		{
			if ( mins[j] > maxs[j] )
			{
				float tmp = mins[j];
				mins[j] = maxs[j];
				maxs[j] = tmp;
			}
		}

		UTIL_TraceHull(
			actualGroundPos + Vector( 0, 0, 0.1f ),
			actualGroundPos + Vector( 0, 0, VEC_HULL_MAX.z - 0.2f ),
			mins,
			maxs,
			MASK_PLAYERSOLID_BRUSHONLY,
			&filter,
			&tr );
		actualGroundPos.z += tr.fractionleftsolid * VEC_HULL_MAX.z;
		float maxHeight = actualGroundPos.z + VEC_DUCK_HULL_MAX.z;
		for ( ; tr.startsolid && actualGroundPos.z <= maxHeight; actualGroundPos.z += 1.0f )
		{
			// In case we didn't find a good ground pos above, we could start in the ground.  Move us up some.
			UTIL_TraceHull(
				actualGroundPos + Vector( 0, 0, 0.1f ),
				actualGroundPos + Vector( 0, 0, VEC_HULL_MAX.z - 0.2f ),
				mins,
				maxs,
				MASK_PLAYERSOLID_BRUSHONLY,
				&filter,
				&tr );
		}
		if (tr.startsolid || tr.fraction != 1.0f)
		{
			SetAttributes( NAV_MESH_CROUCH );
			m_crouch[corner] = true;
		}

#if DEBUG_NAV_NODES
		if ( nav_show_nodes.GetBool() )
		{
			if ( nav_test_node_crouch_dir.GetInt() == i || nav_test_node_crouch_dir.GetInt() == NUM_CORNERS  )
			{
				if ( tr.startsolid )
				{
					NDebugOverlay::Box( actualGroundPos, mins, maxs+Vector( 0, 0, VEC_HULL_MAX.z), 255, 0, 0, 10, 20.0f );
				}
				else if ( m_crouch[corner] )
				{
					NDebugOverlay::Box( actualGroundPos, mins, maxs+Vector( 0, 0, VEC_HULL_MAX.z), 0, 0, 255, 10, 20.0f );
				}
				else
				{
					NDebugOverlay::Box( actualGroundPos, mins, maxs+Vector( 0, 0, VEC_HULL_MAX.z), 0, 255, 0, 10, 10.0f );
				}
			}
		}
#endif // DEBUG_NAV_NODES
	}
}
예제 #30
0
void Brush_ConstructPrism(Brush& brush, const AABB& bounds, std::size_t sides, int axis, const std::string& shader, const TextureProjection& projection)
{
  if(sides < c_brushPrism_minSides)
  {
    globalErrorStream() << c_brushPrism_name << ": sides " << sides << ": too few sides, minimum is " << c_brushPrism_minSides << "\n";
    return;
  }
  if(sides > c_brushPrism_maxSides)
  {
    globalErrorStream() << c_brushPrism_name << ": sides " << sides << ": too many sides, maximum is " << c_brushPrism_maxSides << "\n";
    return;
  }

  brush.clear();
  brush.reserve(sides+2);

  Vector3 mins(bounds.origin - bounds.extents);
  Vector3 maxs(bounds.origin + bounds.extents);

  float radius = max_extent_2d(bounds.extents, axis);
  const Vector3& mid = bounds.origin;
  Vector3 planepts[3];

  planepts[2][(axis+1)%3] = mins[(axis+1)%3];
  planepts[2][(axis+2)%3] = mins[(axis+2)%3];
  planepts[2][axis] = maxs[axis];
  planepts[1][(axis+1)%3] = maxs[(axis+1)%3];
  planepts[1][(axis+2)%3] = mins[(axis+2)%3];
  planepts[1][axis] = maxs[axis];
  planepts[0][(axis+1)%3] = maxs[(axis+1)%3];
  planepts[0][(axis+2)%3] = maxs[(axis+2)%3];
  planepts[0][axis] = maxs[axis];

  brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);

  planepts[0][(axis+1)%3] = mins[(axis+1)%3];
  planepts[0][(axis+2)%3] = mins[(axis+2)%3];
  planepts[0][axis] = mins[axis];
  planepts[1][(axis+1)%3] = maxs[(axis+1)%3];
  planepts[1][(axis+2)%3] = mins[(axis+2)%3];
  planepts[1][axis] = mins[axis];
  planepts[2][(axis+1)%3] = maxs[(axis+1)%3];
  planepts[2][(axis+2)%3] = maxs[(axis+2)%3];
  planepts[2][axis] = mins[axis];

  brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
 
  for (std::size_t i=0 ; i<sides ; ++i)
  {
    double sv = sin (i*3.14159265*2/sides);
    double cv = cos (i*3.14159265*2/sides);

    planepts[0][(axis+1)%3] = static_cast<float>(floor(mid[(axis+1)%3]+radius*cv+0.5));
    planepts[0][(axis+2)%3] = static_cast<float>(floor(mid[(axis+2)%3]+radius*sv+0.5));
    planepts[0][axis] = mins[axis];

    planepts[1][(axis+1)%3] = planepts[0][(axis+1)%3];
    planepts[1][(axis+2)%3] = planepts[0][(axis+2)%3];
    planepts[1][axis] = maxs[axis];

    planepts[2][(axis+1)%3] = static_cast<float>(floor(planepts[0][(axis+1)%3] - radius*sv + 0.5));
    planepts[2][(axis+2)%3] = static_cast<float>(floor(planepts[0][(axis+2)%3] + radius*cv + 0.5));
    planepts[2][axis] = maxs[axis];

    brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
  }
}