void MaterialManager::destroyAllMaterials() { Material *temp; Uint length = mPtrArray->getLength(); while(length--) { temp = (Material *)mPtrArray->getElement(length); DELETEANDNULL(temp); //mPtrArray->setElement(NULL, length); } mPtrArray->clearAll(); return; }
Material* MaterialManager::createMaterial() { Bool rv; Material *pMaterial = new Material(); if( !pMaterial ) return NULL; rv = mPtrArray->append((TPointer)pMaterial); if(FALSE==rv) { DELETEANDNULL(pMaterial); TOY3D_TIPS("Error: Failed to store the pointer.\n"); return NULL; } return pMaterial; }
/* * Class: com_forget3d_demo_F3DStarsRenderer * Method: f3dStarsInit * Signature: ()V */ void JNICALL Java_com_forget3d_demo_F3DStarsRenderer_f3dStarsInit(JNIEnv* env, jclass cls) { __android_log_print(ANDROID_LOG_INFO, "Forget3D", "world->init()..."); World::release(); world = World::getInstance(); world->init(); texture = Image::loadTexture("/sdcard/star.bmp"); __android_log_print(ANDROID_LOG_INFO, "Forget3D", "load texture: %s ...", "/sdcard/star.bmp"); camera = world->getActiveCamera(); camera->setEye(0.0f, 0.0f, 15.0f); /* Create A Loop That Goes Through All The Stars */ for (int loop=0; loop < NUM; loop++) { /* Start All The Stars At Angle Zero */ stars[loop].angle=0.0f; /* Calculate Distance From The Center */ stars[loop].dist=((float)loop/NUM)*5.0f; /* Give star[loop] A Random Red Intensity */ stars[loop].r=rand() % 256; /* Give star[loop] A Random Green Intensity */ stars[loop].g=rand() % 256; /* Give star[loop] A Random Blue Intensity */ stars[loop].b=rand() % 256; } DELETEANDNULL(font, false); font = new Font(16, 16, 24, 36, "/sdcard/font.bmp"); // /sdcard/game/forget3d/font.bmp, /dev/sample/font.bmp __android_log_print(ANDROID_LOG_INFO, "Forget3D", "create Font: %s ...", "/sdcard/font.bmp"); is_initialized = true; is_done = 1; __android_log_print(ANDROID_LOG_INFO, "Forget3D", "start loop..."); is_done = 1; gettimeofday(&timeNow, NULL); i_time = CLOCK(timeNow); sprintf(strFps, "Fps:%.2f", 0.0f); printf("strFps: %s\n", strFps); }
/* * Class: com_forget3d_demo_F3DStarsRenderer * Method: f3dStarsDone * Signature: ()V */ void JNICALL Java_com_forget3d_demo_F3DStarsRenderer_f3dStarsDone(JNIEnv* env, jclass cls) { __android_log_print(ANDROID_LOG_INFO, "Forget3D", "call f3dStarsDone..."); DELETEANDNULL(font, false); World::release(); }
void ModelMS3D::prepareFrame() { #ifdef DEBUG static bool isFirst = true; if (isFirst) { printf("Call ModelMS3D::prepareFrame()...\n"); isFirst = false; } #endif if ((m_frameCount < 0 || m_frameIdx < 0 || (m_joints == NULL)) && m_isPrepared) { #ifdef DEBUG printf("No joint or frame, don't need prepare again...\n"); #endif return; } int i, j, n; for (i = 0; i < m_jointsCount; i++) { Matrix *transform = new Matrix(); if (m_frameIdx < m_joints[i].header.numKeyFramesRot) transform->setRotationRadians( m_joints[i].keyFramesRot[m_frameIdx].rotation[0], m_joints[i].keyFramesRot[m_frameIdx].rotation[1], m_joints[i].keyFramesRot[m_frameIdx].rotation[2] ); if (m_frameIdx < m_joints[i].header.numKeyFramesTrans) transform->setTranslation( m_joints[i].keyFramesTrans[m_frameIdx].position[0], m_joints[i].keyFramesTrans[m_frameIdx].position[1], m_joints[i].keyFramesTrans[m_frameIdx].position[2] ); Matrix *relativeFinal = new Matrix(); relativeFinal->set(m_joints[i].relMatrix->getMatrix()); relativeFinal->postMultiply(transform->getMatrix()); if ( m_joints[i].parentJointIndex == -1 ) m_joints[i].finMatrix->set(relativeFinal->getMatrix()); else { m_joints[i].finMatrix->set(m_joints[m_joints[i].parentJointIndex].finMatrix->getMatrix()); m_joints[i].finMatrix->postMultiply(relativeFinal->getMatrix()); } DELETEANDNULL(transform, false); DELETEANDNULL(relativeFinal, false); } for (i = 0; i < m_groupsCount; i++) { int v_idx = 0, n_idx = 0, u_idx = 0; float *vertices = new float[m_groups[i].numTriangles * 9]; float *normals = new float[m_groups[i].numTriangles * 9]; float *uvs = NULL; if (m_materials != NULL && !m_isPrepared) uvs = new float[m_groups[i].numTriangles * 6]; //read all group triangles for (j = 0; j < m_groups[i].numTriangles; j++) { //get the triangle & vertex indices ms3d_triangle_t triangle = m_triangles[m_groups[i].triangleIndices[j]]; for (int m = 0; m < 3; m++) { //get the vertex, and apply joint data to it ms3d_vertex_t vertex = m_vertices[triangle.vertexIndices[m]]; int b_idx = vertex.boneId; if (b_idx != -1) { Vector *vector_n = new Vector( triangle.vertexNormals[m][0], triangle.vertexNormals[m][1], triangle.vertexNormals[m][2] ); vector_n->transform3(m_joints[b_idx].finMatrix); vector_n->normalize(); Vector *vector_v = new Vector( vertex.vertex[0], vertex.vertex[1], vertex.vertex[2] ); vector_v->transform(m_joints[b_idx].finMatrix); for (n = 0; n < 3; n++) { vertices[v_idx++] = vector_v->getVector()[n]; // copy vertices normals[n_idx++] = vector_n->getVector()[n]; // copy normals } DELETEANDNULL(vector_n, false); DELETEANDNULL(vector_v, false); } else { //copy vertex data to mesh for (int n = 0; n < 3; n++) { vertices[v_idx++] = m_vertices[triangle.vertexIndices[m]].vertex[n]; // copy vertices normals[n_idx++] = triangle.vertexNormals[m][n]; // copy normals } } if (m_materials != NULL && !m_isPrepared) { uvs[u_idx++] = triangle.s[m]; uvs[u_idx++] = 1.0f - triangle.t[m]; } } } //set data to mesh setVertices(vertices, m_groups[i].numTriangles * 9 * sizeof(float), i); setNormals(normals, m_groups[i].numTriangles * 9 * sizeof(float), i); if (m_materials != NULL && !m_isPrepared) { setUvs(uvs, m_groups[i].numTriangles * 6 * sizeof(float), i); } DELETEANDNULL(vertices, true); DELETEANDNULL(normals, true); DELETEANDNULL(uvs, true); } m_frameIdx++; if (m_frameIdx >= m_frameCount) m_frameIdx = m_isLooped ? 0 : m_frameCount - 1; //after prepare frame, set m_isPrepared to true if (!m_isPrepared) m_isPrepared = GL_TRUE; }
void MaterialManager::destroyMaterial(Material *pMat) { mPtrArray->remove((TPointer)pMat); DELETEANDNULL(pMat); return; }
MaterialManager::~MaterialManager() { mPtrArray->destroy(); DELETEANDNULL(mPtrArray); }