Exemple #1
0
/*!
 * \brief Adds triangles for the outer hull
 * \param radius Radius of the robot
 * \param height Height of the robot
 * \param num Number of segments
 * \param angle Angle of the hull start
 * \param angleStep Step size in rad
 */
void Mesh::addRobotCover(float radius, float height, uint num, float angle, float angleStep)
{
    QVector<uint>& group = m_groups["cover"];
    for (uint i = 0; i <= num; i++) {
        // upper vertex row
        addNormal(cos(angle), sin(angle), 0.0f);
        addTexCoord((angle - M_PI_2) / M_PI / 2.0f, 1.0f);
        addVertex(radius * cos(angle), radius * sin(angle),  height / 2.0f);
        m_hull.append(QVector3D(radius * cos(angle), radius * sin(angle),  height / 2.0f));

        // bottom vertex row
        addNormal(cos(angle), sin(angle), 0.0f);
        addTexCoord((angle - M_PI_2) / M_PI / 2.0f, 0.0f);
        addVertex(radius * cos(angle), radius * sin(angle), -height / 2.0f);
        m_hull.append(QVector3D(radius * cos(angle), radius * sin(angle), -height / 2.0f));

        group.append(i * 2 + 0);
        group.append(i * 2 + 1);

        angle += angleStep;
    }

    for (uint i = 0; i < num; i++) {
        addTriangle(i * 2 + 0, i * 2 + 1, i * 2 + 2);
        addTriangle(i * 2 + 2, i * 2 + 1, i * 2 + 3);
    }
}
Exemple #2
0
/*!
 * \brief Adds triangles for top/bottom plates
 * \param radius Radius of the robot
 * \param height Height of the robot
 * \param num Number of segments
 * \param angle Angle of the front side
 * \param angleStep Step size in rad
 * \param top If \c true this method creates the top plate. Otherwise the bottom plate is created
 */
void Mesh::addRobotPlate(float radius, float height, uint num, float angle, float angleStep, bool top)
{
    QVector<uint>& group = m_groups[top ? "top" : "bottom"];

    const float normal = top ? 1.0f : -1.0f;
    const uint firstIndex = m_vertices.count() / 3;

    addNormal(0.0f, 0.0f, normal);
    addTexCoord(0.5f, 0.5f);
    addVertex(0.0f, 0.0f, normal * height / 2.0f);
    group.append(firstIndex);

    for (uint i = 0; i <= num; i++) {
        addNormal(0.0f, 0.0f, normal);
        addTexCoord(cos(angle - M_PI_2) / 2.0f + 0.5f, sin(angle - M_PI_2) / 2.0f + 0.5f);
        addVertex(radius * cos(angle), radius * sin(angle), normal * height / 2.0f);

        group.append(firstIndex + i + 1);
        angle += normal * angleStep;
    }
    group.append(firstIndex + 1);

    for (uint i = 0; i < num; i++)
        addTriangle(firstIndex, firstIndex + i + 1, firstIndex + i + 2);
    addTriangle(firstIndex, firstIndex + num + 1, firstIndex + 1);
}
Exemple #3
0
/*!
 * \brief Adds front plane
 * \param radius Radius of the robot
 * \param height Height of the robot
 * \param angleStart Start angle in rad
 * \param angleStop Stop angle in rad
 */
void Mesh::addRobotFront(float radius, float height, float angleStart, float angleStop)
{
    uint firstIndex = m_vertices.count() / 3;

    addNormal(cos(angleStop), sin(angleStop), 0.0f);
    addTexCoord(0.0f, 1.0f);
    addVertex(radius * cos(angleStop), radius * sin(angleStop),  height / 2.0f);

    addNormal(cos(angleStop), sin(angleStop), 0.0f);
    addTexCoord(0.0f, 0.0f);
    addVertex(radius * cos(angleStop), radius * sin(angleStop), -height / 2.0f);

    addNormal(cos(angleStart), sin(angleStart), 0.0f);
    addTexCoord(1.0f, 1.0f);
    addVertex(radius * cos(angleStart), radius * sin(angleStart),  height / 2.0f);

    addNormal(cos(angleStart), sin(angleStart), 0.0f);
    addTexCoord(1.0f, 0.0f);
    addVertex(radius * cos(angleStart), radius * sin(angleStart), -height / 2.0f);

    addTriangle(firstIndex + 0, firstIndex + 1, firstIndex + 2);
    addTriangle(firstIndex + 2, firstIndex + 1, firstIndex + 3);

    QVector<uint>& group = m_groups["front"];
    group.append(firstIndex + 0);
    group.append(firstIndex + 1);
    group.append(firstIndex + 2);
    group.append(firstIndex + 3);
}
Exemple #4
0
void GCheckbox::setup() {
	box_width = 21;
	box_height = 18;
	mouse_x = x+gui->metrics.label_width;
	mouse_y = y;
	mouse_width = gui->metrics.row_width - (mouse_x);
	mouse_height = gui->metrics.row_height;
		
	// Vertices
	x += gui->metrics.label_width;
	y += 3;
	
	addVertex(x,y);
	addVertex(x+box_width,y);
	addVertex(x+box_width,y+box_height);
	addVertex(x,y+box_height);
	
	x -= gui->metrics.label_width;	
	y -= 3;
	
	// Texcoords 
	tex_a = addTexCoord(GTCX(0),GTCY(64));
	tex_b = addTexCoord(GTCX(box_width),GTCY(64));
	tex_c = addTexCoord(GTCX(box_width),GTCY(64+box_height));
	tex_d = addTexCoord(GTCX(0),GTCY(64+box_height));

	flagChanged();
}
Exemple #5
0
void updateFile(ObjFile* file, const char* line)
{
    // counts the number of groups, objectes, faces, positions, normals, 
    // texcoords 

    // TODO: trim [line]

    if (line[0] == 'v' && line[1] == ' ')
    {
        addPosition(file, line);
        return;
    }

    if (line[0] == 'v' && line[1] == 'n' && line[2] == ' ')
    {
        addNormal(file, line);
        return;
    }

    if (line[0] == 'v' && line[1] == 't' && line[2] == ' ')
    {
        addTexCoord(file, line);
        return;
    }

    if (line[0] == 'o' && line[1] == ' ')
    {
        addObject(file, line);
        return;
    }

    if (line[0] == 'g' && line[1] == ' ')
    {
        addGroup(file, line);
        return;
    }

    if (line[0] == 'f' && line[1] == ' ')
    {
        addFace(file, line);
        return;
    }

    if (strstr(line, "usemtl") == line) 
    {
        setCurrentMaterial(file, line);
        return;
    }
}
Exemple #6
0
void GButton::setup() {
	float string_width = gui->label_font.stringWidth(label);
	bar_width = 6;
	button_height = 29;
	button_width = string_width + 20;

	x += gui->metrics.label_width;
	y += 3;
	mouse_x = x;
	mouse_y = y;
	mouse_width = button_width;
	mouse_height = button_height;
	

	// vertices: left bar
	addVertex(x,y);
	addVertex(x+bar_width,y);
	addVertex(x+bar_width,y+button_height);
	addVertex(x, y+button_height);

	// vertices: button fill
	addVertex(x+bar_width,y);
	addVertex(x+bar_width+button_width-bar_width,y);
	addVertex(x+bar_width+button_width-bar_width,y+button_height);
	addVertex(x+bar_width, y+button_height);

	// vertices: rigth bar
	float start_x = x+bar_width+button_width-bar_width;
	addVertex(start_x,y);
	addVertex(start_x+bar_width,y);
	addVertex(start_x+bar_width,y+button_height);
	addVertex(start_x, y+button_height);

	x -= gui->metrics.label_width;
	
	// texcoord: left part of buton.
	texcoords.push_back(addTexCoord(GTCX(64),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(64+bar_width),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(64+bar_width),GTCY(button_height)));
	texcoords.push_back(addTexCoord(GTCX(64),GTCY(button_height)));
	
	// texcoord: button fill
	texcoords.push_back(addTexCoord(GTCX(71),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(71),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(71),GTCY(button_height)));
	texcoords.push_back(addTexCoord(GTCX(71),GTCY(button_height)));

	// texcoord: right bar
	texcoords.push_back(addTexCoord(GTCX(73),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(81),GTCY(0)));
	texcoords.push_back(addTexCoord(GTCX(81),GTCY(button_height)));
	texcoords.push_back(addTexCoord(GTCX(71),GTCY(button_height)));
	
	num_texcoords = texcoords.size();
	flagChanged();
	y -= 3;
}
Exemple #7
0
		Mesh::Mesh(istream &is, bool calculateEdges) : calculateEdges(calculateEdges) {
			FileId id;												// Read File header
			get(is, id);

			if (!is) {
				console::print(1.0f, 0.0f, 0.0f, "Failed to load mesh!");
				return;
			}

			if (id != string2id("mESH")) {
				console::print(1.0f, 0.0f, 0.0f, "Not a mesh file!");
				return;
			}

			FileVersion ver;
			get(is, ver);

			if (ver.major != 1 || ver.minor != 0) {
				console::print(1.0f, 0.0f, 0.0f, "Unknown mesh version!");
				return;
			}

			MeshHeader header;										// Read mesh file header
			get(is, header);									

			for (dword i = 0; i < header.textures; ++i) {			// Read textures
				char name[256];
				byte length;
				get(is, length);
				is.read(name, (int)length + 1);
				addTexture(name);
			}

			for (dword i = 0; i < header.materials; i++) {			// Read materials
				addMaterial(Material(is));
			}

			for (dword i = 0; i < header.vertices; i++) {			// Read vertices
				Vector3 v;
				get(is, v[0]);
				get(is, v[1]);
				get(is, v[2]);
				addVertex(v);
			}
			
			for (dword i = 0; i < header.vertices; i++) {			// Read normals
				Vector3 n;
				get(is, n[0]);
				get(is, n[1]);
				get(is, n[2]);
				setNormal(i, n);
			}
			
			for (dword i = 0; i < header.vertices; i++) {			// Read texture coordinates
				Vector2 uv;
				get(is, uv[0]);
				get(is, uv[1]);
				addTexCoord(uv);
			}
			
			for (dword i = 0; i < header.triangles; i++) {			// Read triangles
				Triangle tri;
				get(is, tri.v[0]);
				get(is, tri.v[1]);
				get(is, tri.v[2]);
				get(is, tri.texture);
				get(is, tri.material);
				tri.uv[0] = tri.v[0];
				tri.uv[1] = tri.v[1];
				tri.uv[2] = tri.v[2];
				addTriangle(tri);
			}
			
			for (dword i = 0; i < header.edges; i++) {				// Read edges
				Edge e;
				get(is, e.v[0]);
				get(is, e.v[1]);
				get(is, e.plane[0]);
				get(is, e.plane[1]);
				if (!calculateEdges) addEdge(e);
			}
		}