Exemplo n.º 1
0
GeometryBufferPtr GizmoRotate::generateCircles()
{
	// Vertex data
	std::vector< Vector3 > pos;
	std::vector< Vector3 > colors;

	Matrix4x3 transform;

	// X axis
	std::vector< Vector3 > posX;
	generateCircle(posX, SLICES);
	generateColors(colors, X);

	transform = Matrix4x3::createScale( Vector3(0.4f) );
	TransformVertices(pos, posX, transform);

	// Y axis
	std::vector< Vector3 > posY;
	generateCircle(posY, SLICES);
	generateColors(colors, Y);
	
	transform = Matrix4x3::createScale( Vector3(0.4f) );
	transform = transform*Matrix4x3::createRotation( EulerAngles(0, 90, 0) );
	TransformVertices(pos, posY, transform);
	
	// Z axis
	std::vector< Vector3 > posZ;
	generateCircle(posZ, SLICES);
	generateColors(colors, Z);

	transform = Matrix4x3::createScale( Vector3(0.4f) );
	transform = transform*Matrix4x3::createRotation( EulerAngles(90, 0, 0) );
	TransformVertices(pos, posZ, transform);

	// Translate it a bit.
	transform = Matrix4x3::createTranslation( Vector3::UnitY * 0.5f );
	for( uint i = 0; i < pos.size(); i++ )
	{
		Vector3& v = pos[i];
		v = transform*v;
	}

	// Vertex buffer setup
	GeometryBufferPtr gb = AllocateHeap(GeometryBuffer);

	assert( pos.size() == colors.size() );

	gb->set( VertexAttribute::Position, pos );
	gb->set( VertexAttribute::Color, colors );
	
	return gb;
}
Exemplo n.º 2
0
void Cylinder::generateCylinder()
{
    generateCircle();
    generateWall( 1.0f, m_numDivisions);
    generateWall(-1.0f, m_numDivisions);
	generateSide(m_numDivisions);
}
Exemplo n.º 3
0
void CylinderSlice::generateCylinder()
{
	generateCircle(m_sliceAngle);
	generateWall( 1.0f, m_numDivisions-1);
	generateWall(-1.0f, m_numDivisions-1);
	generateSide(m_numDivisions-1);

	// build extra sides
	if(m_sliceAngle < 360.0)
	{
		vec3 p1(m_circlePoints[0].x, m_circlePoints[0].y,  1.0f);
		vec3 p2(0.0f, 0.0f,  1.0f);
		vec3 p3(m_circlePoints[0].x, m_circlePoints[0].y, -1.0f);
		vec3 p4(0.0f, 0.0f, -1.0f);

		// Side 1
		vec3 n = cross(p4-p2, p1-p2);
		m_vertices[m_numVertices] = p1; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 0.0f); m_numVertices++;
		m_vertices[m_numVertices] = p2; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 0.0f); m_numVertices++;
		m_vertices[m_numVertices] = p4; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 1.0f); m_numVertices++;
		n = cross(p3-p4, p1-p4);	// value does not change
		m_vertices[m_numVertices] = p4; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 1.0f); m_numVertices++;
		m_vertices[m_numVertices] = p3; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 1.0f); m_numVertices++;
		m_vertices[m_numVertices] = p1; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 0.0f); m_numVertices++;

		m_edges[m_numEdges++] = p1;
		m_edges[m_numEdges++] = p2; 
		m_edges[m_numEdges++] = p2;
		m_edges[m_numEdges++] = p4;
		m_edges[m_numEdges++] = p4;
		m_edges[m_numEdges++] = p3;
		m_edges[m_numEdges++] = p3;
		m_edges[m_numEdges++] = p1;

		m_cols[0].n = normalize(n);
		//m_cols[0].n.y = 0.0f; m_cols[0].n.z = -1.0f;
		m_cols[0].d = dot(m_cols[0].n, p4);

		p1 = vec3(m_circlePoints[m_numDivisions-1].x, m_circlePoints[m_numDivisions-1].y,  1.0f);
		p3 = vec3(m_circlePoints[m_numDivisions-1].x, m_circlePoints[m_numDivisions-1].y, -1.0f);

		// Side 2
		n = cross(p4-p3, p1-p3);
		m_vertices[m_numVertices] = p1; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 0.0f); m_numVertices++;
		m_vertices[m_numVertices] = p3; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 1.0f); m_numVertices++;
		m_vertices[m_numVertices] = p4; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 1.0f); m_numVertices++;
		n = cross(p1-p2, p4-p2);	// value does not change
		m_vertices[m_numVertices] = p4; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 1.0f); m_numVertices++;
		m_vertices[m_numVertices] = p2; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(0.0f, 0.0f); m_numVertices++;
		m_vertices[m_numVertices] = p1; m_normals[m_numVertices] = n; m_textureUV[m_numVertices] = vec2(1.0f, 0.0f); m_numVertices++;

		m_edges[m_numEdges++] = p1;
		m_edges[m_numEdges++] = p2;
		m_edges[m_numEdges++] = p4;
		m_edges[m_numEdges++] = p3;
		m_edges[m_numEdges++] = p3;
		m_edges[m_numEdges++] = p1;

		m_cols[1].n = normalize(n);
		m_cols[1].n.z = m_cols[1].n.y; m_cols[1].n.y = 0.0f;
		m_cols[1].d = dot(m_cols[1].n, p2);

		p2 = vec3(m_circlePoints[0].x, m_circlePoints[0].y, 1.0f);

		m_cols[2].n = p1;//normalize(cross(p2 - p1, p3 - p1));
		m_cols[2].d = dot(m_cols[2].n, p1);
	}
}