Пример #1
0
    Font::~Font() {
#ifdef DEBUG
        printf("Font destructor...\n");
#endif
        FREEANDNULL(m_color);
        FREEANDNULL(m_texture);
    }
Пример #2
0
    BoundingBox::~BoundingBox() {
    #ifdef DEBUG
        printf("BoundingBox destructor...\n");
    #endif

        FREEANDNULL(m_minEdge);
        FREEANDNULL(m_maxEdge);
        FREEANDNULL(m_center);
    }
Пример #3
0
    ModelMD2::~ModelMD2() {
#ifdef DEBUG
        printf("ModelMD2 destructor...\n");
#endif
        FREEANDNULL(m_skins);
        FREEANDNULL(m_texCoords);
        FREEANDNULL(m_triangles);
        FREEANDNULL(m_frames);
        FREEANDNULL(m_actions);
    }
Пример #4
0
    void ModelMD2::prepareFrame() {
#ifdef DEBUG
        static bool isFirst = true;
        if (isFirst) {
            printf("Call ModelMD2::prepareFrame()...\n");
            isFirst = false;
        }
#endif
        if (m_actionIdx == -1)
            return;

        float *uvs = (float *) malloc(m_header.numTriangles * 6 * sizeof(float));
        float *vertices = (float *) malloc(m_header.numTriangles * 9 * sizeof(float));
        float *normals = (float *) malloc(m_header.numTriangles * 9 * sizeof(float));
        int i, j, uvIdx = 0, vertexIdx = 0, normalIdx = 0;

        md2_frame_t *f = &m_frames[m_frameIdx];

        for (i = 0; i < m_header.numTriangles; i++) {
            md2_triangle_t *t = &m_triangles[i];
            for (j = 0; j < 3; j++) {
                //set uvs
                uvs[uvIdx++] = (float) m_texCoords[t->textureIndices[j]].s / (float) m_header.skinWidth;
                uvs[uvIdx++] = 1.0f - (float) m_texCoords[t->textureIndices[j]].t / (float) m_header.skinHeight;
                //set vertices & normals
                vertices[vertexIdx++] = f->vertices[t->vertexIndices[j]].vertex[0];
                vertices[vertexIdx++] = f->vertices[t->vertexIndices[j]].vertex[1];
                vertices[vertexIdx++] = f->vertices[t->vertexIndices[j]].vertex[2];

                normals[normalIdx++] = f->vertices[t->vertexIndices[j]].normal[0];
                normals[normalIdx++] = f->vertices[t->vertexIndices[j]].normal[2];
                normals[normalIdx++] = f->vertices[t->vertexIndices[j]].normal[1];
            }
        }
        setVertices(vertices, m_header.numTriangles * 9 * sizeof(float));
        setNormals(normals, m_header.numTriangles * 9 * sizeof(float));
        setUvs(uvs, m_header.numTriangles * 6 * sizeof(float));

        FREEANDNULL(vertices);
        FREEANDNULL(normals);
        FREEANDNULL(uvs);

        m_frameIdx++;
        if (m_frameIdx > m_actions[m_actionIdx].max_idx)
            m_frameIdx = m_isLooped ? m_actions[m_actionIdx].min_idx : m_actions[m_actionIdx].max_idx;
    }
Пример #5
0
    ModelMS3D::~ModelMS3D() {
#ifdef DEBUG
        printf("ModelMS3D destructor...\n");
#endif
        int i;
        FREEANDNULL(m_vertices);
        FREEANDNULL(m_triangles);
        //free group's triangle indices & group
        for (i = 0; i < m_groupsCount; i++)
            FREEANDNULL(m_groups[i].triangleIndices);
        FREEANDNULL(m_groups);
        //free materials
        FREEANDNULL(m_materials);
        //free joints and its key frames & martices data
        for (i = 0; i < m_jointsCount; i++) {
            FREEANDNULL(m_joints[i].keyFramesRot);
            FREEANDNULL(m_joints[i].keyFramesTrans);
                        //delete matrix pointers
            delete m_joints[i].absMatrix;
                        delete m_joints[i].relMatrix;
                        delete m_joints[i].finMatrix;
        }
        FREEANDNULL(m_joints);
    }
Пример #6
0
void ModelAM::loadModel (const char* filename)
{
    FILE *file;
    int r, i, j;
    int version = 0;
    int mesh_num = 0;
    int vertex_num = 0;
    int uv_num = 0;
    int triangle_num = 0;
    int temp = 0;
    int material_num = 0;
    float specular_level, glossiness;


    char mesh_name[32];
    float box;
	float *vertices = NULL;
	float *uvs = NULL;
	short *indices = NULL;


    printf ("loadModel %s.\n", filename);

    file = fopen (filename, "r");
    if (file == NULL)
        return;


    r = fscanf (file, "SimpleMeshFormat %d\n", &version);
    printf ("verson = %d.\n", version);

    r = fscanf (file, "%d\n", &mesh_num);
    printf ("mesh_num = %d.\n", mesh_num);
	setMeshCount (mesh_num);


    for (i = 0; i < mesh_num; i++) {

        r = fscanf (file, "%s\n", mesh_name);
        printf ("mesh_name = %s.\n", mesh_name);

        r = fscanf (file, "%d\n", &vertex_num);
        printf ("vertex_num = %d.\n", vertex_num);

        vertices = (float*)malloc (vertex_num * 3 * sizeof (float));
        if (!vertices) {
            //Fixme: free sth if needed.
            return;
        }

        for (j = 0; j < vertex_num; j++)  {
            r = fscanf (file, "%g %g %g\n",
                            &vertices[j*3],
                            &vertices[j*3+1],
                            &vertices[j*3+2]);
        }

		
        setVertices (vertices, vertex_num * 3 * sizeof (float), i);
        FREEANDNULL (vertices);

        r = fscanf (file, "%d\n", &uv_num);
	
        uvs = (float*)malloc (uv_num * 2 * sizeof (float));
        if (!uvs) {
            //Fixme: free sth if needed.
            return;
        }


        for (j = 0; j < uv_num; j++)  {
            r = fscanf (file, "%g %g\n",
                            &uvs[j*2],
                            &uvs[j*2+1]);
        }

        setUvs(uvs, uv_num * 2 * sizeof (float), i);
        FREEANDNULL (uvs);


        r = fscanf (file, "%d\n", &triangle_num);
        printf ("triangle_num = %d.\n", triangle_num);
		
		setTriangleNums(triangle_num, i);

        indices = (short *)malloc (triangle_num * 3 * sizeof (short));
        if (!indices) {
            //Fixme: free sth if needed.
            return;
        }

	
        for (j = 0; j < triangle_num; j++)  {
            r = fscanf (file, "%d %hd %hd %hd %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n",
                           &temp, //nSmoothGroup
                           &indices[j*3],
                           &indices[j*3+1],
                           &indices[j*3+2],
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box,
                           &box);

        }


        setIndices (indices, triangle_num * 3 * sizeof (short), i);
        FREEANDNULL (indices);
 


//    	setMaterialAmbient (0.9, 0.6, 0.6, 0);
//    	setMaterialDiffuse (0.9, 0.6, 0.6, 0);


		float ambient [3];
    	float diffuse [3];
    	float specular [3];
    	float emission [3];
    	float shininess;



        r = fscanf (file, "%d\n", &material_num);
        //_M3D_PRINTF ("material_num = %d.\n", material_num);


		//FIXME: handle only one material
		//Basicly, diffuse decide mesh color in white light

        r = fscanf (file, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g\n",
                           &specular_level,
                           &glossiness,
                           &ambient[0],
                           &ambient[1],
                           &ambient[2],
                           &diffuse[0],
                           &diffuse[1],
                           &diffuse[2],
                           &specular[0],
                           &specular[1],
                           &specular[2],
                           &emission[0],
                           &emission[1],
                           &emission[2]);

        if (specular_level > 0)
            shininess = glossiness;
        else
            shininess = -1;

			
/*
            _M3D_PRINTF ("loadAmModel: %g %g %g %g %g %g %g %g %g %g\n",
                           shininess,
                           ambient[0],
                           ambient[1],
                           ambient[2],
                           diffuse[0],
                           diffuse[1],
                           diffuse[2],
                           specular[0],
                           specular[1],
                           specular[2]);
        }
*/

        setMaterialAmbient (ambient[0],
                            ambient[1],
                            ambient[2],
                            i);

        setMaterialDiffuse (diffuse[0],
                            diffuse[1],
                            diffuse[2],
                            i);

        setMaterialEmission (emission[0],
                             emission[1],
                             emission[2],
                             i);

        if (shininess > 0) {

             setMaterialShininess (shininess, i);
             setMaterialSpecular (specular[0], specular[1], specular[2], i);

        }


    }



    fclose (file);


    return;
}