Example #1
0
void 
VSResSurfRevLib::createTorus(float innerRadius, float outerRadius, int rings, int sides) {

	float tubeRadius = (outerRadius - innerRadius) * 0.5f;
	float *p = circularProfile(-3.14159f, 3.14159f, tubeRadius, sides, innerRadius + tubeRadius);
	computeVAO(sides+1, p+2, p, rings, 0.0f);
}
Torus::Torus(float* position, Game *game, float innerRadius, float outerRadius, int rings, int sides) : Object(position, game) 
{
	float tubeRadius = (outerRadius - innerRadius) * 0.5f;
	float *p = circularProfile(-3.14159f, 3.14159f, tubeRadius, sides, innerRadius + tubeRadius);
	computeVAO(sides + 1, p + 2, p, rings, 0.0f);
	free(p);
}
Example #3
0
void 
VSSurfRevLib::createSphere(float radius, int divisions) {

	std::vector<float> p;
	circularProfile(p, -3.14159f/2.0f, 3.14159f/2.0f, radius, divisions);
	computeVAO(divisions+1, &(p[2]), &(p[0]), divisions*2, 0.0f);
}
Example #4
0
void 
VSSurfRevLib::createTorus(float innerRadius, float outerRadius, int rings, int sides) {

	float tubeRadius = (outerRadius - innerRadius) * 0.5f;
	std::vector<float> p;
	circularProfile(p, -3.14159f, 3.14159f, tubeRadius, sides, innerRadius + tubeRadius);
	computeVAO(sides+1, &(p[2]), &(p[0]), rings, 0.0f);
}
Example #5
0
void 
VSSurfRevLib::create (float *p, int numP, int sides, int closed, float smoothCos) {

	if (numP < 2)
		return;

	int i; 
	int totalPoints;
	// if closed the first point is replicated at the end
	// two extra points are added for normal computation
	if (closed)
		totalPoints = numP + 3;
	else
		totalPoints = numP + 2;

	std::vector<float> points;
	points.resize(totalPoints * 2);

	for (i = 2; i < (numP + 1) * 2; i++) {
		points[i] = p[i - 2];
	}
	if (closed) {
		points[(totalPoints - 2) * 2] = points[2];
		points[(totalPoints - 2) * 2 + 1] = points[3];
	}

	// distinguishes between closed curves and open curves
	// for normal computation
	int numPoints = numP + 2;

	if (closed) {

		points[0] = p[(numP - 1) * 2];
		points[1] = p[(numP - 1) * 2 + 1];

		points[(numPoints ) * 2] = p[2];
		points[(numPoints ) * 2 + 1] = p[3];
	}
	else {

		points[0] = points[2] + (points[2] - points[4]);
		points[1] = points[3] + (points[3] - points[5]);

		points[(numPoints - 1) * 2] = points[(numPoints - 2) * 2] +
			(points[(numPoints - 2) * 2] - points[(numPoints - 3) * 2]);
		points[(numPoints - 1) * 2 + 1] = points[(numPoints - 2) * 2 + 1] +
			(points[(numPoints - 2) * 2 + 1] - points[(numPoints - 3) * 2 + 1]);
	}

	computeVAO(totalPoints-2, &(points[2]), &(points[0]), sides, smoothCos);
}
Example #6
0
void 
VSResSurfRevLib::createCylinder(float height, float radius, int sides) {

	float p[] = {
			-radius,	-height*0.5f, 
			0.0f,		-height*0.5f, 
			radius,		-height*0.5f,  
			radius,		 height*0.5f,  
			0.0f,		 height*0.5f,
			-radius,	 height*0.5f
	};

	computeVAO(4, p+2, p, sides, 0.0f);
}
Example #7
0
void 
VSSurfRevLib::createCylinder(float height, float radius, int sides, int stacks) {

	std::vector<float> p;

	p.push_back(-radius); p.push_back(-height*0.5f);
	p.push_back(0.0f); p.push_back(-height*0.5f);

	float deltaH = height / stacks;
	for (int i = 0; i < stacks+1; ++i) {
		p.push_back(radius); p.push_back(-height*0.5f + i * deltaH);
	}

	p.push_back(0.0f); p.push_back(height*0.5f);
	p.push_back(-radius); p.push_back(height*0.5f);

	computeVAO(stacks+3, &(p[2]), (float *)&(p[0]), sides, 0.0f);
}
Example #8
0
void 
VSSurfRevLib::createCone(float height, float baseRadius, int sides) {

	float v[2];
	v[0] = -baseRadius;
	v[1] = height;

	std::vector<float> p;

	p.push_back(-baseRadius);	p.push_back(0.0f);
	p.push_back(0.0f);			p.push_back(0.0f);
	p.push_back(baseRadius);	p.push_back(0.0f);
	int max = (int)(1 + height/ (baseRadius*2*3.14159 / sides)) ;
	for (int i = 0; i < max; ++i) {
	
		p.push_back(baseRadius - i * baseRadius  / max); p.push_back( i * height  / max);
	}
	p.push_back(0.0f);			p.push_back(height);
	p.push_back(-baseRadius);	p.push_back(height * 2.0f);

	computeVAO((int)((p.size()-4)/2), &(p[2]), &(p[0]), sides, 0.0f);
}
Example #9
0
void 
VSResSurfRevLib::createCone(float height, float baseRadius, int sides) {

	float v[2];
	v[0] = -baseRadius;
	v[1] = height;

	std::vector<float> p;

	p.push_back(-baseRadius);	p.push_back(0.0f);
	p.push_back(0.0f);			p.push_back(0.0f);
	p.push_back(baseRadius);	p.push_back(0.0f);
	int max = (int)(1 + height/ (baseRadius*2*3.14159 / sides)) ;
	for (int i = 0; i < max; ++i) {
	
		p.push_back(baseRadius - i * baseRadius  / max); p.push_back( i * height  / max);
	}
	p.push_back(0.0f);			p.push_back(height);
	p.push_back(-baseRadius);	p.push_back(height * 2.0f);
	//float p[(sides+3)*2] = {
	//		-baseRadius,	0.0, 
	//		0.0f,			0.0, 
	//		baseRadius,		0.0f,
	//		baseRadius + v[0] * 0.1,		v[1] * 0.1,
	//		baseRadius + v[0] * 0.2,		v[1] * 0.2,
	//		baseRadius + v[0] * 0.3,		v[1] * 0.3,
	//		baseRadius + v[0] * 0.4,		v[1] * 0.4,
	//		baseRadius + v[0] * 0.5,		v[1] * 0.5,
	//		baseRadius + v[0] * 0.6,		v[1] * 0.6,
	//		baseRadius + v[0] * 0.7,		v[1] * 0.7,
	//		baseRadius + v[0] * 0.8,		v[1] * 0.8,
	//		baseRadius + v[0] * 0.9,		v[1] * 0.9,
	//		0.0f,			height,  
	//		-baseRadius,	height*2.0f,
	//	};

	computeVAO((p.size()-4)/2, &(p[2]), &(p[0]), sides, 0.0f);
}
Example #10
0
void 
VSResSurfRevLib::create (float *p, int numP, int sides, int closed, float smoothCos) {

	int i; 
	// two extra points are added for normal computation

	float *points = (float *)malloc(sizeof(float) * (numP+2) * 2);

	for(i=2;i<(numP+1)*2;i++) {
		points[i] = p[i-2];
	}

	// distinguishes between closed curves and open curves
	// for normal computation
	int numPoints = numP + 2;

	if (closed) {

		points[0] = p[(numP-2)*2];
		points[1] = p[(numP-2)*2+1];

		points[(numPoints-1)*2]     = p[2];
		points[(numPoints-1)*2 + 1] = p[3];
	}
	else {

		points[0] = points[2] + (points[2]-points[4]);
		points[1] = points[3] + (points[3]-points[5]);

		points[(numPoints-1)*2]     = points[(numPoints-2)*2]     + 
											(points[(numPoints-2)*2]     - points[(numPoints-3)*2]);
		points[(numPoints-1)*2 + 1] = points[(numPoints-2)*2 + 1] + 
											(points[(numPoints-2)*2 + 1] - points[(numPoints-3)*2 + 1]);
	}

	computeVAO(numP, p, points, sides, smoothCos);
}
Example #11
0
void 
VSResSurfRevLib::createSphere(float radius, int divisions) {

	float *p = circularProfile(-3.14159f/2.0f, 3.14159f/2.0f, radius, divisions);
	computeVAO(divisions+1, p+2, p, divisions*2, 0.0f);
}