virtual void render(const btDiscreteDynamicsWorld* rbWorld) { //clear the color buffer TGAColor clearColor; clearColor.bgra[0] = 255; clearColor.bgra[1] = 255; clearColor.bgra[2] = 255; clearColor.bgra[3] = 255; clearBuffers(clearColor); ATTRIBUTE_ALIGNED16(btScalar modelMat[16]); ATTRIBUTE_ALIGNED16(float viewMat[16]); ATTRIBUTE_ALIGNED16(float projMat[16]); m_camera.getCameraProjectionMatrix(projMat); m_camera.getCameraViewMatrix(viewMat); btVector3 lightDirWorld(-5,200,-40); switch (m_upAxis) { case 1: lightDirWorld = btVector3(-50.f,100,30); break; case 2: lightDirWorld = btVector3(-50.f,30,100); break; default:{} }; lightDirWorld.normalize(); for (int i=0;i<rbWorld->getNumCollisionObjects();i++) { btCollisionObject* colObj = rbWorld->getCollisionObjectArray()[i]; int colObjIndex = colObj->getUserIndex(); int shapeIndex = colObj->getCollisionShape()->getUserIndex(); if (colObjIndex>=0 && shapeIndex>=0) { TinyRenderObjectData* renderObj = 0; int* cptr = m_swInstances[colObjIndex]; if (cptr) { int c = *cptr; TinyRenderObjectData** sptr = m_swRenderObjects[c]; if (sptr) { renderObj = *sptr; //sync the object transform const btTransform& tr = colObj->getWorldTransform(); tr.getOpenGLMatrix(modelMat); for (int i=0;i<4;i++) { for (int j=0;j<4;j++) { renderObj->m_projectionMatrix[i][j] = projMat[i+4*j]; renderObj->m_modelMatrix[i][j] = modelMat[i+4*j]; renderObj->m_viewMatrix[i][j] = viewMat[i+4*j]; renderObj->m_localScaling = colObj->getCollisionShape()->getLocalScaling(); renderObj->m_lightDirWorld = lightDirWorld; } } TinyRenderer::renderObject(*renderObj); } } } } static int counter=0; counter++; if ((counter&7)==0) { char filename[1024]; sprintf(filename,"framebuf%d.tga",counter); m_rgbColorBuffer.flip_vertically(); getFrameBuffer().write_tga_file(filename,true); } float color[4] = {1,1,1,1}; }
/** @param texture : コンバート元データのUUID @param add_fname : コンバート先ファイル名の追加文字列 @param ext_fname : コンバート先ファイル名の拡張子 @param dist : コンバート先のパス @param comformat : 内部処理が失敗した場合の外部処理コマンド.NULL の場合はデフォルトを使用する. */ void OARTool::ConvertTexture(const char* texture, const char* add_name, const char* ext_name, const char* dist, const char* comformat) { if (texture==NULL) return; Buffer outpath; if (dist==NULL) outpath = make_Buffer_bystr((char*)pathTEX.buf); else outpath = make_Buffer_bystr(dist); bool converted = false; cat_s2Buffer(texture, &outpath); if (add_name!=NULL) { cat_s2Buffer("_", &outpath); cat_s2Buffer(add_name, &outpath); if (ext_name!=NULL) { if (ext_name[0]!='.') cat_s2Buffer(".", &outpath); cat_s2Buffer(ext_name, &outpath); } } rewrite_sBuffer_str(&outpath, " ", "\\ "); rewrite_sBuffer_str(&outpath, ";", "\\;"); if (!file_exist((char*)outpath.buf)) { Buffer inppath = make_Buffer_bystr(texture); rewrite_sBuffer_str(&inppath, " ", "\\ "); rewrite_sBuffer_str(&inppath, ";", "\\;"); free_Buffer(&inppath); char* path = get_resource_path((char*)texture, assetsFiles); char* extn = get_file_extension(path); // if (path!=NULL && extn!=NULL && (extn[0]=='j' || extn[0]=='J')) { // for Jpeg2000 // JPEG2KImage jpg = readJPEG2KFile(path); if (jpg.state==0) { MSGraph<uByte> vp = JPEG2KImage2MSGraph<uByte>(jpg); DEBUG_MODE print_message("OARTool::ConvertTexture: texture = %s [size = (%4d,%4d,%2d), mode = %d]\n", texture, jpg.ws, jpg.hs, jpg.col, jpg.cmode); // if (vp.zs>0) { TGAImage tga = MSGraph2TGAImage(vp); int err = writeTGAFile((char*)outpath.buf, tga); if (!err) converted = true; else print_message("OARTool::ConvertTexture: ERROR: write error (%d).\n", err); tga.free(); } else { print_message("OARTool::ConvertTexture: ERROR: color num of %s is %d\n", texture, vp.zs); } vp.free(); jpg.free(); } else { if (jpg.state==ERROR_GRAPH_IVDDATA) { DEBUG_MODE print_message("OARTool::ConvertTexture: ERROR: texture %s is invalid.\n", texture); } else { DEBUG_MODE print_message("OARTool::ConvertTexture: ERROR: texture %s convert error (%d).\n", texture, jpg.state); } } // Retry convert using external command if (!converted) { DEBUG_MODE print_message("OARTool::ConvertTexture: RETRY: convert %s to %s\n", path, (char*)outpath.buf); // char command[LDATA]; memset(command, 0, LDATA); if (comformat!=NULL) { snprintf(command, LDATA-1, comformat, path, (char*)outpath.buf); } else { snprintf(command, LDATA-1, OART_JP2_DECOMP_COM, path, (char*)outpath.buf); } int ret = system(command); int err = WEXITSTATUS(ret); if (err!=0) print_message("OARTool::ConvertTexture: ERROR: texture %s convert error (%d, %d).\n", texture, jpg.state, err); else DEBUG_MODE print_message("OARTool::ConvertTexture: SUCCESS: texture %s is converted.\n", texture); } } else { print_message("OARTool::ConvertTexture: ERROR: texture %s is lost!\n", texture); } } free_Buffer(&outpath); return; }