Exemplo n.º 1
0
/*****************************************************************
*函数名称:addrtot                                                                                  
*功能           :2  进制地址转换成字符型
*				addrtot - convert binary address to text
*				(dotted decimal or IPv6 string)
*
*******************************************************************
*
*
*
******************************************************************/
size_t	addrtot(const ip_address *src, int format, char *dst, size_t dstlen)
{
	const unsigned char *b;
	size_t n;
	char buf[1+ADDRTOT_BUF+1];	/* :address: */
	char *p;
	int t = addrtypeof(src);
   #define	TF(t, f)	(((t)<<8) | (f))

	n = addrbytesptr(src, &b);
	if (n == 0) {
	bad:
	  dst[0]='\0';
	  strncat(dst, "invalid", dstlen);
	  return sizeof("invalid");
	}

	switch (TF(t, format)) {
	case TF(AF_INET, 0):
		n = normal4(b, n, buf, &p);
		break;
	case TF(AF_INET6, 0):
		n = normal6(b, n, buf, &p, 1);
		break;
	case TF(AF_INET, 'Q'):
		n = normal4(b, n, buf, &p);
		break;
	case TF(AF_INET6, 'Q'):
		n = normal6(b, n, buf, &p, 0);
		break;
	case TF(AF_INET, 'r'):
		n = reverse4(b, n, buf, &p);
		break;
	case TF(AF_INET6, 'r'):
		n = reverse6(b, n, buf, &p);
		break;
	default:		/* including (AF_INET, 'R') */
	        goto bad;
		break;
	}

	if (dstlen > 0) 
	{
		if (dstlen < n)
			p[dstlen - 1] = '\0';
		strcpy(dst, p);
	}
	return n;
}
Exemplo n.º 2
0
BaseIF* makeVane(const Real&     thick,
                 const RealVect& normal,
                 const Real&     innerRadius,
                 const Real&     outerRadius,
                 const Real&     offset,
                 const Real&     height)
{
  RealVect zero(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));
  bool inside = true;

  Vector<BaseIF*> vaneParts;

  // Each side of the vane (infinite)
  RealVect normal1(normal);
  RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0));
  PlaneIF plane1(normal1,point1,inside);

  vaneParts.push_back(&plane1);

  RealVect normal2(-normal);
  RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0));
  PlaneIF plane2(normal2,point2,inside);

  vaneParts.push_back(&plane2);

  // Make sure we only get something to the right of the origin
  RealVect normal3(D_DECL(0.0,0.0,1.0));
  RealVect point3(D_DECL(0.0,0.0,0.0));
  PlaneIF plane3(normal3,point3,inside);

  vaneParts.push_back(&plane3);

  // Cut off the top and bottom
  RealVect normal4(D_DECL(1.0,0.0,0.0));
  RealVect point4(D_DECL(offset,0.0,0.0));
  PlaneIF plane4(normal4,point4,inside);

  vaneParts.push_back(&plane4);

  RealVect normal5(D_DECL(-1.0,0.0,0.0));
  RealVect point5(D_DECL(offset+height,0.0,0.0));
  PlaneIF plane5(normal5,point5,inside);

  vaneParts.push_back(&plane5);

  // The outside of the inner cylinder
  TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside);

  vaneParts.push_back(&inner);

  // The inside of the outer cylinder
  TiltedCylinderIF outer(outerRadius,xAxis,zero,inside);

  vaneParts.push_back(&outer);

  IntersectionIF* vane = new IntersectionIF(vaneParts);

  return vane;
}
Exemplo n.º 3
0
BaseIF* makeVane(const Real&     thick,
                 const RealVect& normal,
                 const Real&     innerRadius,
                 const Real&     outerRadius,
                 const Real&     offset,
                 const Real&     height,
                 const Real&     angle)
{
  RealVect zeroVect(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));
  bool inside = true;

  Vector<BaseIF*> vaneParts;

  Real sinTheta = sin(angle);
#if CH_SPACEDIM == 3
  Real cosTheta = cos(angle);

  // Each side of the vane (infinite)
  // rotate the normal around x-axis
  RealVect normal1(D_DECL(normal[0],cosTheta*normal[1]-sinTheta*normal[2],sinTheta*normal[1]+cosTheta*normal[2]));
  // rotate point on top of vane around x-axis
  RealVect point(D_DECL(offset+height/2.0,-thick/2.0,0.0));
  RealVect point1(D_DECL(point[0],cosTheta*point[1]-sinTheta*point[2],sinTheta*point[1]+cosTheta*point[2]));
  PlaneIF plane1(normal1,point1,inside);

  vaneParts.push_back(&plane1);

  RealVect normal2(-normal1);
  // rotate point on bottom (-point[2] of vane around x-axis
  RealVect point2(D_DECL(point[0],-cosTheta*point[1]-sinTheta*point[2],-sinTheta*point[1]+cosTheta*point[2]));
  PlaneIF plane2(normal2,point2,inside);

  vaneParts.push_back(&plane2);
#endif

  // Make sure we only get something to the right of the origin
  RealVect normal3(D_DECL(0.0,-sinTheta,cosTheta));
  RealVect point3(D_DECL(0.0,0.0,0.0));
  PlaneIF plane3(normal3,point3,inside);

  vaneParts.push_back(&plane3);

  // Cut off the top and bottom
  RealVect normal4(D_DECL(1.0,0.0,0.0));
  RealVect point4(D_DECL(offset,0.0,0.0));
  PlaneIF plane4(normal4,point4,inside);

  vaneParts.push_back(&plane4);

  RealVect normal5(D_DECL(-1.0,0.0,0.0));
  RealVect point5(D_DECL(offset+height,0.0,0.0));
  PlaneIF plane5(normal5,point5,inside);

  vaneParts.push_back(&plane5);

  // The outside of the inner cylinder
  TiltedCylinderIF inner(innerRadius,xAxis,zeroVect,!inside);

  vaneParts.push_back(&inner);

  // The inside of the outer cylinder
  TiltedCylinderIF outer(outerRadius,xAxis,zeroVect,inside);

  vaneParts.push_back(&outer);

  IntersectionIF* vane = new IntersectionIF(vaneParts);

  return vane;
}
Exemplo n.º 4
0
//Begin TubeGen
void TubeGen::generate(	float holeR, int numEdgePoints,
						const color4& insideColor, const color4& outsideColor	)
{
	if (holeR > 1.0 || holeR < 0.0) throw 11;

	const float theta = 2.0 * M_PI / numEdgePoints;

	//2 sides, 2 * numEdgePoints points, 2 colors, 2 * numEdgePoints + 2 normals
	//numEdgePoints wedges, 4 sides per wedge, 1 quadrilateral per side,
	//2 triangles per quadrilateral, 3 vertices per triangle, 3 attributes per vertex
	numElements = 2 * 2 * numEdgePoints + 2 + 2 * numEdgePoints + 2;
	numVertices = 2 * numEdgePoints * 4;
	numIndices = numEdgePoints * 4 * 2 * 3;

	elements = new vec4[numElements];
	data = new vec4[numVertices * 3];
	indices = new GLubyte[numIndices];

	sizeData = numVertices * 3 * sizeof(vec4);
	sizeIndices = numIndices * sizeof(GLubyte);

	colors = numVertices * sizeof(vec4);
	normals = numVertices * 2 * sizeof(vec4);

	//set vertices
	//front
	//inside
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i] = point4(holeR * cos(i * theta), holeR * sin(i * theta), 1.0, 1.0);
	//outside
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + numEdgePoints] = point4(cos(i * theta), sin(i * theta), 1.0, 1.0);
	//back
	//outside
	int temp = 2 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + temp] = point4(cos(i * theta), sin(i * theta), -1.0, 1.0);
	//inside
	temp = 3 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + temp] = point4(holeR * cos(i * theta), holeR * sin(i * theta), -1.0, 1.0);
	//set colors
	elements[4 * numEdgePoints] = insideColor; elements[4 * numEdgePoints + 1] = outsideColor;
	//set normals
	elements[4 * numEdgePoints + 2] = MatMath::zNORM; elements[4 * numEdgePoints + 3] = -MatMath::zNORM;
	temp = 4 * (numEdgePoints + 1);
	for (int i = 0; i < numEdgePoints; ++i) {
		elements[i + temp] = normal4(cos(i * theta), sin(i * theta), 0.0, 0.0);
		elements[i + numEdgePoints + temp] = -1.0 * elements[i + temp];
	}

	//points
	//front
	for (int i = 0; i < 2 * numEdgePoints; ++i)
		data[i] = elements[i];
	//back
	for (int i = 2 * numEdgePoints; i < 4 * numEdgePoints; ++i)
		data[i] = elements[i];
	//inside
	temp = 4 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i) {
		data[i + temp] = elements[i + 3 * numEdgePoints];
		data[i + numEdgePoints + temp] = elements[i];
	}
	//outside
	temp = 6 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i) {
		data[i + temp] = elements[i + numEdgePoints];
		data[i + numEdgePoints + temp] = elements[i + 2 * numEdgePoints];
	}
	//colors
	//front
	temp = 8 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i) {
		data[i + temp] = insideColor;
		data[i + numEdgePoints + temp] = outsideColor;
	}
	//back
	temp = 10 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i) {
		data[i + temp] = outsideColor;
		data[i + numEdgePoints + temp] = insideColor;
	}
	//inside and outside
	for (int i = 12 * numEdgePoints; i < 14 * numEdgePoints; ++i) {
		//inside
		data[i] = insideColor;
		//outside
		data[i + 2 * numEdgePoints] = outsideColor;
	}
	//normals
	//front and back
	for (int i = 16 * numEdgePoints; i < 18 * numEdgePoints; ++i) {
		data[i] = MatMath::zNORM;
		data[i + 2 * numEdgePoints] = -MatMath::zNORM;
	}
	//inside
	temp = 20 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + temp] = data[i + numEdgePoints + temp] = elements[i + 5 * numEdgePoints + 4];
	//outside
	temp = 22 * numEdgePoints;
	for (int i =0; i < numEdgePoints; ++i)
		data[i + temp] = data[i + numEdgePoints + temp] = elements[i + 4 * (numEdgePoints + 1)];

	//indices
	//front
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		//first triangle
		indices[i * 6] = i + 1;
		indices[i * 6 + 1] = i;
		indices[i * 6 + 2] = i + numEdgePoints;
		//second triangle
		indices[i * 6 + 3] = i + numEdgePoints;
		indices[i * 6 + 4] = i + 1 + numEdgePoints;
		indices[i * 6 + 5] = i + 1;
	}
	//first triangle
	indices[numEdgePoints * 6 - 6] = 0;
	indices[numEdgePoints * 6 - 5] = numEdgePoints - 1;
	indices[numEdgePoints * 6 - 4] = 2 * numEdgePoints - 1;
	//second triangle
	indices[numEdgePoints * 6 - 3] = 2 * numEdgePoints - 1;
	indices[numEdgePoints * 6 - 2] = numEdgePoints;
	indices[numEdgePoints * 6 - 1] = 0;
	//back
	temp = 2 * numEdgePoints;
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		//first triangle
		indices[6 * (i + numEdgePoints)] = i + 1 + temp;
		indices[6 * (i + numEdgePoints) + 1] = i + temp;
		indices[6 * (i + numEdgePoints) + 2] = i + numEdgePoints + temp;
		//second triangle
		indices[6 * (i + numEdgePoints) + 3] = i + numEdgePoints + temp;
		indices[6 * (i + numEdgePoints) + 4] = i + 1 + numEdgePoints + temp;
		indices[6 * (i + numEdgePoints) + 5] = i + 1 + temp;
	}
	//first triangle
	indices[12 * numEdgePoints - 6] = temp;
	indices[12 * numEdgePoints - 5] = numEdgePoints - 1 + temp;
	indices[12 * numEdgePoints - 4] = 2 * numEdgePoints - 1 + temp;
	//second triangle
	indices[12 * numEdgePoints - 3] = 2 * numEdgePoints - 1 + temp;
	indices[12 * numEdgePoints - 2] = numEdgePoints + temp;
	indices[12 * numEdgePoints - 1] = temp;
	//inside
	temp = 4 * numEdgePoints;
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		//first triangle
		indices[6 * (i + 2 * numEdgePoints)] = i + 1 + temp;
		indices[6 * (i + 2 * numEdgePoints) + 1] = i + temp;
		indices[6 * (i + 2 * numEdgePoints) + 2] = i + numEdgePoints + temp;
		//second triangle
		indices[6 * (i + 2 * numEdgePoints) + 3] = i + numEdgePoints + temp;
		indices[6 * (i + 2 * numEdgePoints) + 4] = i + 1 + numEdgePoints + temp;
		indices[6 * (i + 2 * numEdgePoints) + 5] = i + 1 + temp;
	}
	//first triangle
	indices[18 * numEdgePoints - 6] = temp;
	indices[18 * numEdgePoints - 5] = numEdgePoints - 1 + temp;
	indices[18 * numEdgePoints - 4] = 2 * numEdgePoints - 1 + temp;
	//second triangle
	indices[18 * numEdgePoints - 3] = 2 * numEdgePoints - 1 + temp;
	indices[18 * numEdgePoints - 2] = numEdgePoints + temp;
	indices[18 * numEdgePoints - 1] = temp;
	//outside
	temp = 6 * numEdgePoints;
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		//first triangle
		indices[6 * (i + 3 * numEdgePoints)] = i + 1 + temp;
		indices[6 * (i + 3 * numEdgePoints) + 1] = i + temp;
		indices[6 * (i + 3 * numEdgePoints) + 2] = i + numEdgePoints + temp;
		//second triangle
		indices[6 * (i + 3 * numEdgePoints) + 3] = i + numEdgePoints + temp;
		indices[6 * (i + 3 * numEdgePoints) + 4] = i + 1 + numEdgePoints + temp;
		indices[6 * (i + 3 * numEdgePoints) + 5] = i + 1 + temp;
	}
	//first triangle
	indices[24 * numEdgePoints - 6] = temp;
	indices[24 * numEdgePoints - 5] = numEdgePoints - 1 + temp;
	indices[24 * numEdgePoints - 4] = 2 * numEdgePoints - 1 + temp;
	//second triangle
	indices[24 * numEdgePoints - 3] = 2 * numEdgePoints - 1 + temp;
	indices[24 * numEdgePoints - 2] = numEdgePoints + temp;
	indices[24 * numEdgePoints - 1] = temp;
}
Exemplo n.º 5
0
//Begin ConeGen
void ConeGen::generate(int numEdgePoints, const color4& baseColor, const color4& pointColor) {
	int numPoints = numEdgePoints + 1;
	//numEdgePoints + 2 points, 2 colors, 2 * numEdgePoints + 1 normals
	//numEdgePoints wedges, 2 triangles per wedge, 3 vertices per triangle, 3 attributes per vertex
	numElements = 3 * numEdgePoints + 5;
	numVertices = numPoints + 2 * numEdgePoints;
	numIndices = numVertices * 3;

	elements = new vec4[numElements];
	data = new vec4[3 * numVertices];
	indices = new unsigned char[numIndices];

	sizeData = numVertices * 3 * sizeof(vec4);
	sizeIndices = numIndices * sizeof(GLubyte);

	colors = numVertices * sizeof(vec4);
	normals = numVertices * 2 * sizeof(vec4);

	const float theta = 2.0 * M_PI / numEdgePoints;

	//set vertices
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i] = point4(cos(i * theta), sin(i * theta), 1.0, 1.0);
	elements[numEdgePoints] = point4(0.0, 0.0, 1.0, 1.0);
	elements[numPoints] = point4(0.0, 0.0, -1.0, 1.0);
	//set colors
	elements[numEdgePoints + 2] = baseColor; elements[numEdgePoints + 3] = pointColor;
	//set normals
	elements[numEdgePoints + 4] = MatMath::zNORM;
	int temp = numEdgePoints + 5;
	mat4 tempRotate;
	const normal4 tempNorm1 = normal4(0.4472, 0.0, -0.1056, 0.0);
	const normal4 tempNorm2 = rZ(theta/2.0) * tempNorm1;
	for (int i = 0; i < numEdgePoints; ++i) {
		tempRotate = rZ(i * theta);
		elements[i + temp] = tempRotate * tempNorm1;
		elements[i + numEdgePoints + temp] = tempRotate * tempNorm2;
	}

	//points
	//base
	for (int i = 0; i < numEdgePoints; ++i)
		data[i] = elements[i];
	data[numEdgePoints] = elements[numEdgePoints];
	//edge
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + numPoints] = elements[i];
	//tip
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + 2 * numEdgePoints + 1] = elements[numPoints];
	//colors
	//base
	for (int i = 3 * numEdgePoints + 1; i < 5 * numEdgePoints + 2; ++i)
		data[i] = baseColor;
	//tip
	for (int i = 5 * numEdgePoints + 2; i < 6 * numEdgePoints + 2; ++i)
		data[i] = pointColor;
	//normals
	//base
	for (int i = 6 * numEdgePoints + 2; i < 7 * numEdgePoints + 3; ++i)
		data[i] = MatMath::zNORM;
	//edge
	temp = 7 * numEdgePoints + 3;
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + temp] = elements[i + numEdgePoints + 5];
	//tip
	temp = 8 * numEdgePoints + 3;
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + temp] = elements[i + 2 * numEdgePoints + 5];

	//indices
	//base
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		indices[3 * i] = numEdgePoints; indices[3 * i + 1] = i; indices[3 * i + 2] = i + 1;
	}
	indices[3 * numEdgePoints - 3] = numEdgePoints;
	indices[3 * numEdgePoints - 2] = numEdgePoints - 1;
	indices[3 * numEdgePoints - 1] = 0;
	//cone
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		indices[3 * (i + numEdgePoints)] = i + 1 + numPoints;
		indices[3 * (i + numEdgePoints) + 1] = i + numPoints;
		indices[3 * (i + numEdgePoints) + 2] = i + numPoints + numEdgePoints;
	}
	indices[6 * numEdgePoints - 3] = numPoints;
	indices[6 * numEdgePoints - 2] = numPoints + numEdgePoints - 1;
	indices[6 * numEdgePoints - 1] = 3 * numEdgePoints;
}
Exemplo n.º 6
0
//Begin CylinderGen
void CylinderGen::generate(	int numEdgePoints, const color4& frontColor,
							const color4& backColor, const color4& sideColor	)
{
	int numPoints = numEdgePoints + 1;

	//2 ends, numPoints points per end, 3 colors, numEdgePoints + 2 normals
	//numEdgePoints wedges, 4 triangles per wedge, 3 vertices per triangle, 3 attributes per vertex
	numElements = 2 * numPoints + 3 + numEdgePoints + 2;
	numVertices = 2 * (numPoints + numEdgePoints);
	numIndices = numEdgePoints * 4 * 3;

	elements = new vec4[numElements];
	data = new vec4[3 * numVertices];
	indices = new GLubyte[numIndices];

	sizeData = numVertices * 3 * sizeof(vec4);
	sizeIndices = numIndices * sizeof(GLubyte);

	colors = numVertices * sizeof(vec4);
	normals = numVertices * 2 * sizeof(vec4);

	const float theta = 2.0 * M_PI / numEdgePoints;

	//set vertices
	//front circle
	elements[0] = point4(0.0, 0.0, 1.0, 1.0);
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + 1] = point4(cos(i * theta), sin(i * theta), 1.0, 1.0);
	//back circle
	elements[numPoints] = point4(0.0, 0.0, -1.0, 1.0);
	int temp = numPoints + 1;
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + temp] = point4(cos(i * theta), sin(i * theta), -1.0, 1.0);
	//set colors
	elements[2 * numPoints] = frontColor;
	elements[2 * numPoints + 1] = backColor;
	elements[2 * numPoints + 2] = sideColor;
	//set normals
	elements[2 * numPoints + 3] = MatMath::zNORM;
	elements[2 * numPoints + 4] = -MatMath::zNORM;
	temp = 2 * numPoints + 5;
	for (int i = 0; i < numEdgePoints; ++i)
		elements[i + temp] = normal4(cos(i * theta), sin(i * theta), 0.0, 0.0);

	//points
	//front circle
	data[0] = elements[0];
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + 1] = elements[i + 1];
	//back circle
	data[numPoints] = elements[numPoints];
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + numPoints + 1] = elements[2 * numPoints - 1 - i];
	//sides
	for (int i = 0; i < numEdgePoints; ++i) {
		data[i + 2 * numPoints] = elements[i + 1];
		data[i + 2 * numPoints + numEdgePoints] = elements[i + numPoints + 1];
	}
	//colors
	//front
	for (int i = 2 * (numPoints + numEdgePoints); i < 3 * numPoints + 2 * numEdgePoints; ++i)
		data[i] = frontColor;
	//back
	for (int i = 3 * numPoints + 2 * numEdgePoints; i < 4 * numPoints + 2 * numEdgePoints; ++i)
		data[i] = backColor;
	//side
	for (int i = 4 * numPoints + 2 * numEdgePoints; i < 4 * (numPoints + numEdgePoints); ++i)
		data[i] = sideColor;
	//normals
	//front
	for (int i = 4 * (numPoints + numEdgePoints); i < 5 * numPoints + 4 * numEdgePoints; ++i)
		data[i] = MatMath::zNORM;
	//back
	for (int i = 5 * numPoints + 4 * numEdgePoints; i < 6 * numPoints + 4 * numEdgePoints; ++i)
		data[i] = -MatMath::zNORM;
	//side
	temp = 6 * numPoints + 4 * numEdgePoints;
	for (int i = 0; i < numEdgePoints; ++i)
		data[i + temp] = data[i + numEdgePoints + temp] = elements[i + 2 * numPoints + 5];

	//indices
	//front circle
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		indices[i * 3] = 0; indices[i * 3 + 1] = i + 1; indices[i * 3 + 2] = i + 2;
	}
	indices[(numEdgePoints - 1) * 3] = 0;
	indices[(numEdgePoints - 1) * 3 + 1] = numPoints - 1;
	indices[(numEdgePoints - 1) * 3 + 2] = 1;
	//back circle
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		indices[3 * (i + numEdgePoints)] = numPoints;
		indices[3 * (i + numEdgePoints) + 1] = i + 1 + numPoints;
		indices[3 * (i + numEdgePoints) + 2] = i + 2 + numPoints;
	}
	indices[3 * (2 * numEdgePoints - 1)] = numPoints;
	indices[3 * (2 * numEdgePoints - 1) + 1] = 2 * numPoints - 1;
	indices[3 * (2 * numEdgePoints - 1) + 2] = numPoints + 1;
	//side squares
	temp = 2 * numPoints;
	for (int i = 0; i < numEdgePoints - 1; ++i) {
		//first triangle
		indices[6 * (i + numEdgePoints)] = i + 1 + temp;
		indices[6 * (i + numEdgePoints) + 1] = i + temp;
		indices[6 * (i + numEdgePoints) + 2] = i + numEdgePoints + temp;
		//second triangle
		indices[6 * (i + numEdgePoints) + 3] = i + numEdgePoints + temp;
		indices[6 * (i + numEdgePoints) + 4] = i + numEdgePoints + 1 + temp;
		indices[6 * (i + numEdgePoints) + 5] = i + 1 + temp;
	}
	//first triangle
	indices[12 * numEdgePoints - 6] = temp;
	indices[12 * numEdgePoints - 5] = numEdgePoints - 1 + temp;
	indices[12 * numEdgePoints - 4] = 2 * numEdgePoints - 1 + temp;
	//second triangle
	indices[12 * numEdgePoints - 3] = 2 * numEdgePoints - 1 + temp;
	indices[12 * numEdgePoints - 2] = numEdgePoints + temp;
	indices[12 * numEdgePoints - 1] = temp;
}
Exemplo n.º 7
0
void  QmaxButton::createArrowBackground(QPainter &painter)
{
   // printf("Arrow BackGround2\n");
    QRect scaledRect;
    scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));

    QImage image(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied);
    image.fill(QColor(0, 0, 0, 0).rgba());
    //QPainter painter(image);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    painter.drawImage(0, 0, image);

    if(Colors::useEightBitPalette)
    {
        painter.setPen(QColor(120,120,120));
        if(this->m_nPressed)
            painter.setBrush(QColor(60,60,60));
        else if(this->m_nHighlight)
            painter.setBrush(QColor(100,100,100));
        else
            painter.setBrush(QColor(80,80,80));
    }
    else
    {
        QLinearGradient outlinebrush(0,0,0,scaledRect.height());
        QLinearGradient brush(0,0,0,scaledRect.height());

        brush.setSpread(QLinearGradient::PadSpread);
        QColor highlight(255,255,255,128);
        QColor shadow(0,0,0,70);
        QColor sunken(220,220,220,30);
        QColor normal1(88,88,89,255);
        QColor normal2(88,88,89,255);
        QColor normal3(0,0,200,10);
        QColor normal4(255,255,250,255);

         if(m_nType==3 || m_nType == 4)
         {
            normal1 = QColor(100,180,189,55);
            normal2 = QColor(100,180,189,255);
         }
        if(m_nPressed)
        {
            outlinebrush.setColorAt(0.0f,shadow);
            outlinebrush.setColorAt(1.0f,highlight);
            brush.setColorAt(1.0f,sunken);
            painter.setPen(Qt::NoPen);

        }
        else
        {
            outlinebrush.setColorAt(0.75f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal2);
            if(m_nHighlight)
                brush.setColorAt(1.0f,normal1);
            painter.setPen(QPen(outlinebrush,1));
        }
        if(this->isEnabled()==false )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal3);
            painter.setPen(QPen(outlinebrush,2));

        }
        if(m_nStatus )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal2);
            painter.setPen(QPen(outlinebrush,1));
        }
        painter.setBrush(brush);

    }

    
   // painter.drawRect(0, 0, scaledRect.width(), scaledRect.height());

    float xOff = scaledRect.width() / 2;
    float yOff = scaledRect.height() / 2;
    float sizex = 5.0f * matrix.m11();
    float sizey = 3.5f * matrix.m22();
    if (m_nType == 3)
        sizey *= -1;
    QPainterPath path;
    path.moveTo(xOff, yOff + (5 * sizey));
    path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey));
    path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey));
    path.lineTo(xOff, yOff + (5 * sizey));
    painter.drawPath(path);

}
Exemplo n.º 8
0
void  QmaxButton::createButton(QPainter &painter)
{
    QRect scaledRect;
    scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height()));
    QImage bg(this->m_strImage);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    QLinearGradient brush1(0,0,0,scaledRect.height());
    painter.drawImage(-2, -2, bg);


    if(Colors::useEightBitPalette)
    {
        painter.setPen(QColor(120,120,120));
        if(this->m_nPressed)
            painter.setBrush(QColor(60,60,60));
        else if(this->m_nHighlight)
            painter.setBrush(QColor(100,100,100));
        else
            painter.setBrush(QColor(80,80,80));
    }
    else
    {
        QLinearGradient outlinebrush(0,0,0,scaledRect.height());
        QLinearGradient brush(0,0,0,scaledRect.height());

        brush.setSpread(QLinearGradient::PadSpread);
        QColor highlight(255,255,255,128);
        QColor shadow(0,0,0,70);
        QColor sunken(220,220,220,30);
        QColor normal1(255,255,245,60);
        QColor normal2(255,255,235,10);
        QColor normal3(200,200,200,10);
        QColor normal4(255,255,250,255);

         if(m_nType && m_nType != 5  )
         {
            normal1 = QColor(200,170,160,50);
            normal2 = QColor(50,10,0,50);
         }
        if(m_nPressed)
        {
            outlinebrush.setColorAt(0.0f,shadow);
            outlinebrush.setColorAt(1.0f,highlight);
            brush.setColorAt(1.0f,sunken);
            painter.setPen(Qt::NoPen);

        }
        else
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal1);
            if(m_nHighlight)
                brush.setColorAt(1.0f,normal2);
            painter.setPen(QPen(outlinebrush,1));
        }
        if(this->isEnabled()==false )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal3);
            painter.setPen(QPen(outlinebrush,1));

        }
        if(m_nStatus )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal4);
            painter.setPen(QPen(outlinebrush,1));
        }
        painter.setBrush(brush);

    }


    if(m_nType == 1)
        painter.drawRect(0,0,scaledRect.width(),scaledRect.height());
    else if(m_nType == 0)
        painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize);
    else if(m_nType == 5)
        painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height());
    QFont font( "DejaVu Sans" );
    font.setPointSize( 12 );
    painter.setFont( font );
    brush1.setColorAt(1.0f,QColor(255,255,255,255));
    if(this->isEnabled()==false)
    {
        brush1.setColorAt(1.0f,QColor(200,200,200,100));
    }
    painter.setPen(QPen(brush1,1));
    painter.setBrush(brush1);
    QFontMetrics fMetrics = painter.fontMetrics();
    QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText );
    QRectF txtRect( scaledRect.center(), sz );
    int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10);
    int yPoint = scaledRect.height()/2;
    painter.drawText(xPoint,yPoint,m_strText);
}