int main (int argc, const char * argv[]) { if (argc < 3) { printf("Usage: asciigenerator input.bmp definition.txt [grid size]\n"); exit(EXIT_SUCCESS); } const char * inputFile = argv[1]; const char * definitionsFile = argv[2]; treeRoot = createTreeFromFile(definitionsFile); int width = 0; int height = 0; int rowSize = 0; unsigned char * bmpData = createBitmapData(inputFile, &width, &height, &rowSize); int gridCols = 1; int gridRows = 1; if (argc == 5) { gridCols = atoi(argv[3]); gridRows = atoi(argv[4]); } calculateGrid(bmpData, gridCols, gridRows, width, height, treeRoot); free(bmpData); destroyTree(treeRoot); return 0; }
UniformGrid::UniformGrid(unsigned int p_numTriangles, std::vector<RTMesh>* p_mesh, std::vector<RTMaterial>* p_material, std::vector<RTLight>* p_light, Vector3 p_numVoxels, Color clearColor) :m_clearColor(clearColor) { m_min = Vector3(std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()); m_max = Vector3(0, 0, 0); calculateBB(p_mesh, p_numVoxels); calculateGrid(p_numTriangles, p_mesh, p_material, p_light, p_numVoxels); }
bool Terrain::coordinateToGrid( float x,float y,int& GX,int& GY ) { Ogre::Vector2 mRenderWindowSize(Core::getSingletonPtr()->mWindow->getWidth(),Core::getSingletonPtr()->mWindow->getHeight()); // 检查边界条件 if (x < 0 || x > mRenderWindowSize.x || y < 0 || y > mRenderWindowSize.y) return false; //执行射线运算,获取与网格的交点 Ogre::Ray ray = Core::getSingletonPtr()->mCamera->getCameraToViewportRay(x / mRenderWindowSize.x, y / mRenderWindowSize.y); Ogre::Vector3 point; Ogre::ulong target; float d; if(mCollisionTools->raycast(ray,point,target,d,QUERYMASK_TERRAIN)) { calculateGrid(point.x,point.z,GX, GY); return true; } else { return false; } }
//////////////////////////////////////////////////////////////////////////////// //! Run a simple test for CUDA //////////////////////////////////////////////////////////////////////////////// void runTest( int argc, char** argv) { ocd_options opts = ocd_get_options(); platform_id = opts.platform_id; n_device = opts.device_id; if ( argc != 8) { printf("Usage: GpuTemporalDataMining [<platform> <device> --] <file path> <temporal constraint path> <threads> <support> <(a)bsolute or (r)atio> <(s)tatic | (d)ynamic> <(m)ap and merge | (n)aive | (o)hybrid> \n"); return; } // CUT_DEVICE_INIT(); initGpu(); getDeviceVariables(device_id); printf("Dataset, Support Threshold, PTPE or MapMerge, A1 or A1+A2, Level, Episodes (N), Episodes Culled (X), A1 Counting Time, A2 Counting Time, Generation Time, Total Counting Time\n"); //CUT_SAFE_CALL( cutCreateTimer( &timer)); //CUT_SAFE_CALL( cutCreateTimer( &generating_timer)); //CUT_SAFE_CALL( cutCreateTimer( &a1_counting_timer)); //CUT_SAFE_CALL( cutCreateTimer( &a2_counting_timer)); //CUT_SAFE_CALL( cutCreateTimer( &total_timer)); //CUT_SAFE_CALL( cutStartTimer( total_timer)); //CUT_SAFE_CALL( cutStartTimer( timer)); //CUT_SAFE_CALL( cutStartTimer( generating_timer)); //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer)); //CUT_SAFE_CALL( cutStartTimer( a2_counting_timer)); unsigned int num_threads = atoi(argv[3]); // allocate host memory //initEpisodeCandidates(); if ( loadData( argv[1] ) != 0 ) return; if ( loadTemporalConstraints(argv[2]) != 0 ) return; // Check whether value supplied is absolute or ratio support supportType = *(argv[5]) == 'a' ? ABSOLUTE : RATIO; memoryModel = *(argv[6]) == 's' ? STATIC : DYNAMIC; switch (*(argv[7])) { case 'm': algorithmType = MAP_AND_MERGE; break; case 'n': algorithmType = NAIVE; break; case 'o': algorithmType = OPTIMAL; break; } support = atof(argv[4]); dumpFile = fopen( "episode.txt", "w" ); //printf("Initializing GPU Data...\n"); setupGpu(); // setup execution parameters size_t grid[3]; size_t threads[3]; //printf("Event stream size: %i\n", eventSize); // BEGIN LOOP for ( int level = 1; level <= eventSize; level++ ) { printf("Generating episode candidates for level %i...\n", level); // CUT_SAFE_CALL( cutResetTimer( total_timer)); // CUT_SAFE_CALL( cutStartTimer( total_timer)); //CUDA_SAFE_CALL( cudaUnbindTexture( candidateTex ) ); if(level != 1){ unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * (level-1) * sizeof(UBYTE) ); //CUDA_SAFE_CALL( cudaUnbindTexture( intervalTex ) ); unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-2) * 2 * sizeof(float)); } // CUT_SAFE_CALL( cutResetTimer( generating_timer)); // CUT_SAFE_CALL( cutStartTimer( generating_timer)); // int test1, test = numCandidates; // generateEpisodeCandidatesCPU( level ); // test1 = numCandidates; // numCandidates = test; printf("Generating Episodes\n"); #ifdef CPU_EPISODE_GENERATION generateEpisodeCandidatesCPU( level ); #else generateEpisodeCandidatesGPU( level, num_threads ); #endif // CUT_SAFE_CALL( cutStopTimer( generating_timer)); //printf( "\tGenerating time: %f (ms)\n", cutGetTimerValue( generating_timer)); if ( numCandidates == 0 ) break; printf("Writing to buffer\n"); // Copy candidates to GPU #ifdef CPU_EPISODE_GENERATION clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent); START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) #endif bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8); bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT ); //printf("Executing kernel on %i candidates...\n", numCandidates, level); // execute the kernel calculateGrid(grid, num_threads, numCandidates); calculateBlock(threads, num_threads, numCandidates); int sections; unsigned int shared_mem_needed; //CUT_SAFE_CALL( cutStartTimer( counting_timer)); int aType = algorithmType; if ( algorithmType == OPTIMAL ) aType = chooseAlgorithmType( level, numCandidates, num_threads ); if ( memoryModel == DYNAMIC ) { if ( aType == NAIVE ) { shared_mem_needed = MaxListSize*level*threads[0]*sizeof(float); printf("Shared memory needed %d\n", shared_mem_needed); //CUT_SAFE_CALL( cutResetTimer( a1_counting_timer)); //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer)); countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); } else { printf("DYNAMIC MAP MERGE\n"); calculateLevelParameters(level, threads, grid, sections); shared_mem_needed = 16000; printf("numCandidates=%d\n", numCandidates); //CUT_SAFE_CALL( cutResetTimer( a1_counting_timer)); //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer)); countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); //countCandidatesMapMergeStatic<<< grid, threads, shared_mem_needed >>>( d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates ); } } else { if ( aType == NAIVE ) { shared_mem_needed = level*threads[0]*sizeof(float); } else { calculateLevelParameters(level, threads, grid, sections); shared_mem_needed = 16000; } //CUT_SAFE_CALL( cutResetTimer( a2_counting_timer)); //CUT_SAFE_CALL( cutStartTimer( a2_counting_timer)); if ( aType == NAIVE ) countCandidatesStatic(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); else countCandidatesMapMergeStatic(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); clFinish(commands); //CUT_SAFE_CALL( cutStopTimer( a2_counting_timer)); int err; err = clEnqueueReadBuffer(commands,d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to read buffer from device."); unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE) ); unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float)); // Remove undersupported episodes cullCandidates( level ); if ( numCandidates == 0 ) break; unsigned int mmthreads = num_threads; if ( MaxListSize*level*num_threads*sizeof(float) > 16384 ) { if ( MaxListSize*level*96*sizeof(float) < 16384 ) mmthreads = 96; else if ( MaxListSize*level*64*sizeof(float) < 16384) mmthreads = 64; else if ( MaxListSize*level*32*sizeof(float) < 16384) mmthreads = 32; printf("More shared memory needed for %d threads. Changed to %d threads.\n", num_threads, mmthreads ); } #ifdef CPU_EPISODE_GENERATION err = clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent); START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to write buffer 1."); if(numCandidates * (level - 1) * 2 * sizeof(float) != 0) err = clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer) CHKERR(err, "Unable to write buffer 2."); END_TIMER(ocdTempTimer) #endif bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8); bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT ); if ( algorithmType == OPTIMAL ) aType = chooseAlgorithmType( level, numCandidates, mmthreads ); // Run (T1,T2] algorithm if ( aType == NAIVE ) { shared_mem_needed = MaxListSize*level* mmthreads*sizeof(float); calculateGrid(grid, mmthreads, numCandidates ); calculateBlock(threads, mmthreads, numCandidates ); } else { calculateLevelParameters(level, threads, grid, sections); shared_mem_needed = 16000; } //CUT_SAFE_CALL( cutResetTimer( a1_counting_timer)); //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer)); if ( aType == NAIVE ) countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); else countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed ); } printf("Finishing\n"); clFinish(commands); //CUT_SAFE_CALL( cutStopTimer( a1_counting_timer)); //printf( "\tCounting time: %f (ms)\n", cutGetTimerValue( counting_timer)); // check if kernel execution generated an error //CUT_CHECK_ERROR("Kernel execution failed"); //printf("Copying result back to host...\n\n"); int err = clEnqueueReadBuffer(commands, d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to read memory 1."); err = clEnqueueReadBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent); clFinish(commands); START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer) END_TIMER(ocdTempTimer) CHKERR(err, "Unable to read memory 2."); //CUDA_SAFE_CALL( cudaMemcpy( h_mapRecords, d_mapRecords, 3 * numSections * maxLevel * maxCandidates * sizeof(float), cudaMemcpyDeviceToHost )); saveResult(level); fflush(dumpFile); // END LOOP //CUT_SAFE_CALL( cutStopTimer( total_timer)); // Print Statistics for this run printf("%s, %f, %s, %s, %d, %d, %d\n", argv[1], // Dataset support, // Support Threshold algorithmType == NAIVE ? "PTPE" : algorithmType == MAP_AND_MERGE ? "MapMerge" : "Episode-Based", // PTPE or MapMerge or Episode-Based memoryModel == STATIC ? "A1+A2" : "A1", // A1 or A1+A2 level, // Level numCandidates+episodesCulled, // Episodes counted episodesCulled // Episodes removed by A2 // cutGetTimerValue( a1_counting_timer), // Time for A1 // memoryModel == STATIC ? cutGetTimerValue( a2_counting_timer) : 0.0f, // Time for A2 // cutGetTimerValue( generating_timer), // Episode generation time // cutGetTimerValue( total_timer) ); // Time for total loop ); } printf("Done!\n"); cleanup(); //CUT_SAFE_CALL( cutStopTimer( timer)); //printf( "Processing time: %f (ms)\n", cutGetTimerValue( timer)); //CUT_SAFE_CALL( cutDeleteTimer( timer)); //CUT_SAFE_CALL( cutDeleteTimer( generating_timer)); //CUT_SAFE_CALL( cutDeleteTimer( a1_counting_timer)); //CUT_SAFE_CALL( cutDeleteTimer( a2_counting_timer)); //CUT_SAFE_CALL( cutDeleteTimer( total_timer)); }
void NCGR::draw(ReadContext &ctx) { uint32 imageWidth, imageHeight; calculateGrid(ctx, imageWidth, imageHeight); if ((imageWidth >= 0x8000) || (imageHeight >= 0x8000)) throw Common::Exception("Unsupported full image dimensions"); _format = kPixelFormatB8G8R8A8; _mipMaps.push_back(new MipMap); _mipMaps.back()->width = imageWidth; _mipMaps.back()->height = imageHeight; _mipMaps.back()->size = imageWidth * imageHeight * 4; _mipMaps.back()->data = new byte[_mipMaps.back()->size]; byte *data = _mipMaps.back()->data; const bool is0Transp = (ctx.pal[0] == 0xF8) && (ctx.pal[1] == 0x00) && (ctx.pal[2] == 0xF8); // Fill with palette entry 0. Some NCGR cells might be empty, or smaller for (uint32 i = 0; i < (imageWidth * imageHeight); i++) { data[i * 4 + 0] = ctx.pal[0]; data[i * 4 + 1] = ctx.pal[1]; data[i * 4 + 2] = ctx.pal[2]; data[i * 4 + 3] = is0Transp ? 0x00 : 0xFF; } /* The actual image data is stored in a "tiled" fashion, so we need to unswizzle * this manually. Moreover, we ourselves stitch together several NCGR files into * one image. */ const uint32 tileWidth = 8; const uint32 tileHeight = 8; for (std::vector<NCGRFile>::iterator n = ctx.ncgrs.begin(); n != ctx.ncgrs.end(); ++n) { if (!n->image) continue; n->image->seek(0); // Position of this NCGR within the big image const uint32 imagePos = n->offsetX + n->offsetY * imageWidth; // Number of "tiles" in this image's rows/columns const uint32 tilesX = n->width / tileWidth; const uint32 tilesY = n->height / tileHeight; // Go over all tiles for (uint32 yT = 0; yT < tilesY; yT++) { for (uint32 xT = 0; xT < tilesX; xT++) { // Position of the tile within the NCGR const uint32 tilePos = xT * tileWidth + yT * tileHeight * imageWidth; // Go over all pixels in the tile for (uint32 y = 0; y < tileHeight; y++) { for (uint32 x = 0; x < tileWidth; x++) { // Position of the pixel within the tile const uint32 pos = imagePos + tilePos + x + y * imageWidth; const uint8 pixel = n->image->readByte(); if (pos > (imageWidth * imageHeight)) continue; data[pos * 4 + 0] = ctx.pal[pixel * 3 + 0]; data[pos * 4 + 1] = ctx.pal[pixel * 3 + 1]; data[pos * 4 + 2] = ctx.pal[pixel * 3 + 2]; data[pos * 4 + 3] = ((pixel == 0) && is0Transp) ? 0x00 : 0xFF; } } } } } }
static void drawGrid(kernelWindowComponent *containerComponent) { // This function draws grid boxes around all the grid cells containing // components (or parts thereof) kernelWindowContainer *container = containerComponent->data; kernelWindowComponent *component = NULL; int *columnStartX = NULL; int *columnWidth = NULL; int *rowStartY = NULL; int *rowHeight = NULL; int count1, count2, count3; // Check params if (!containerComponent) return; if (containerComponent->type != containerComponentType) { kernelError(kernel_error, "Component is not a container"); return; } columnWidth = kernelMalloc(container->maxComponents * sizeof(int)); columnStartX = kernelMalloc(container->maxComponents * sizeof(int)); rowHeight = kernelMalloc(container->maxComponents * sizeof(int)); rowStartY = kernelMalloc(container->maxComponents * sizeof(int)); if (!columnWidth || !columnStartX || !rowHeight || !rowStartY) goto out; for (count1 = 0; count1 < container->numComponents; count1 ++) if (container->components[count1]->type == containerComponentType) drawGrid(container->components[count1]); // Calculate the grid calculateGrid(containerComponent, columnStartX, columnWidth, rowStartY, rowHeight, (containerComponent->width - containerComponent->minWidth), (containerComponent->height - containerComponent->minHeight)); for (count1 = 0; count1 < container->numComponents; count1 ++) { component = container->components[count1]; for (count2 = 0; count2 < component->params.gridHeight; count2 ++) { for (count3 = 0; count3 < component->params.gridWidth; count3 ++) { kernelGraphicDrawRect(containerComponent->buffer, &((color) {0,0,0}), draw_normal, columnStartX[component->params.gridX + count3], rowStartY[component->params.gridY + count2], columnWidth[component->params.gridX + count3], rowHeight[component->params.gridY + count2], 1, 0); } } } out: if (columnWidth) kernelFree(columnWidth); if (columnStartX) kernelFree(columnStartX); if (rowHeight) kernelFree(rowHeight); if (rowStartY) kernelFree(rowStartY); return; }
static int layoutSize(kernelWindowComponent *containerComponent, int width, int height) { // Loop through the subcomponents, adjusting their dimensions and calling // their resize() functions int status = 0; kernelWindowContainer *container = containerComponent->data; kernelWindowComponent *component = NULL; int *columnWidth = NULL; int *columnStartX = NULL; int *rowHeight = NULL; int *rowStartY = NULL; int tmpWidth, tmpHeight; int tmpX, tmpY; int count1, count2; columnWidth = kernelMalloc(container->maxComponents * sizeof(int)); columnStartX = kernelMalloc(container->maxComponents * sizeof(int)); rowHeight = kernelMalloc(container->maxComponents * sizeof(int)); rowStartY = kernelMalloc(container->maxComponents * sizeof(int)); if (!columnWidth || !columnStartX || !rowHeight || !rowStartY) { status = ERR_MEMORY; goto out; } // Don't go beyond minimum sizes if (width < containerComponent->minWidth) width = containerComponent->minWidth; if (height < containerComponent->minHeight) height = containerComponent->minHeight; // Calculate the grid with the extra/less space factored in calculateGrid(containerComponent, columnStartX, columnWidth, rowStartY, rowHeight, (width - containerComponent->minWidth), (height - containerComponent->minHeight)); for (count1 = 0; count1 < container->numComponents; count1 ++) { // Resize the component component = container->components[count1]; tmpWidth = 0; if ((component->flags & WINFLAG_RESIZABLEX) && !(component->params.flags & WINDOW_COMPFLAG_FIXEDWIDTH)) { for (count2 = 0; count2 < component->params.gridWidth; count2 ++) tmpWidth += columnWidth[component->params.gridX + count2]; tmpWidth -= (component->params.padLeft + component->params.padRight); } else { tmpWidth = component->width; } if (tmpWidth < component->minWidth) tmpWidth = component->minWidth; tmpHeight = 0; if ((component->flags & WINFLAG_RESIZABLEY) && !(component->params.flags & WINDOW_COMPFLAG_FIXEDHEIGHT)) { for (count2 = 0; count2 < component->params.gridHeight; count2 ++) tmpHeight += rowHeight[component->params.gridY + count2]; tmpHeight -= (component->params.padTop + component->params.padBottom); } else { tmpHeight = component->height; } if (tmpHeight < component->minHeight) tmpHeight = component->minHeight; if ((tmpWidth != component->width) || (tmpHeight != component->height)) { if (component->resize) component->resize(component, tmpWidth, tmpHeight); component->width = tmpWidth; component->height = tmpHeight; } // Move it too, if applicable tmpX = columnStartX[component->params.gridX]; tmpWidth = 0; for (count2 = 0; count2 < component->params.gridWidth; count2 ++) tmpWidth += columnWidth[component->params.gridX + count2]; switch (component->params.orientationX) { case orient_left: tmpX += component->params.padLeft; break; case orient_center: tmpX += ((tmpWidth - component->width) / 2); break; case orient_right: tmpX += ((tmpWidth - component->width) - component->params.padRight); break; } tmpY = rowStartY[component->params.gridY]; tmpHeight = 0; for (count2 = 0; count2 < component->params.gridHeight; count2 ++) tmpHeight += rowHeight[component->params.gridY + count2]; switch (component->params.orientationY) { case orient_top: tmpY += component->params.padTop; break; case orient_middle: tmpY += ((tmpHeight - component->height) / 2); break; case orient_bottom: tmpY += ((tmpHeight - component->height) - component->params.padBottom); break; } if ((tmpX != component->xCoord) || (tmpY != component->yCoord)) { if (component->move) component->move(component, tmpX, tmpY); component->xCoord = tmpX; component->yCoord = tmpY; } // Determine whether this component expands the bounds of our container tmpWidth = (component->xCoord + component->width + component->params.padRight); if (tmpWidth > (containerComponent->xCoord + containerComponent->width)) { containerComponent->width = (tmpWidth - containerComponent->xCoord); } tmpHeight = (component->yCoord + component->height + component->params.padBottom); if (tmpHeight > (containerComponent->yCoord + containerComponent->height)) { containerComponent->height = (tmpHeight - containerComponent->yCoord); } } status = 0; out: if (columnWidth) kernelFree(columnWidth); if (columnStartX) kernelFree(columnStartX); if (rowHeight) kernelFree(rowHeight); if (rowStartY) kernelFree(rowStartY); return (status); }
float Terrain::getHeight(float x, float y) { float height = PLANEHEIGHT; int xx = 0,yy = 0; int s = mMapData->getMapSize(); calculateGrid(x,y,xx,yy); switch (mMapData->getTerrainType(xx,yy)) { case HighGround: height = HEIGHGROUNDHEIGHT; break; case LowGround: case Water: height = PLANEHEIGHT; break; case Cliff: case Ramp: Ogre::Entity* entity = NULL; Ogre::Vector3 result = Ogre::Vector3::ZERO; float distToColl = 20.0f; if(mCollisionTools->raycastFromPoint(Ogre::Vector3(x,20.0f,y),Ogre::Vector3::NEGATIVE_UNIT_Y,result,(Ogre::ulong&)entity,distToColl,QUERYMASK_TERRAIN)) { height = 20.0f - distToColl; } else height = PLANEHEIGHT; break; /* bool ishighground[8]; ishighground[0] = mMapData->getTerrainType(xx - 1,yy - 1) == HighGround; ishighground[1] = mMapData->getTerrainType(xx,yy - 1) == HighGround; ishighground[2] = mMapData->getTerrainType(xx + 1,yy - 1) == HighGround; ishighground[3] = mMapData->getTerrainType(xx - 1,yy) == HighGround; ishighground[4] = mMapData->getTerrainType(xx + 1,yy) == HighGround; ishighground[5] = mMapData->getTerrainType(xx - 1,yy + 1) == HighGround; ishighground[6] = mMapData->getTerrainType(xx,yy + 1) == HighGround; ishighground[7] = mMapData->getTerrainType(xx + 1,yy + 1) == HighGround; float dx,dy; getWorldCoords(xx,yy,dx,dy); dx = x - dx; if(dx == 0.0f) dx += 0.01f; dy = y - dy; float z[4]; z[0] = (ishighground[3] || ishighground[0] || ishighground[1])? HEIGHGROUNDHEIGHT:PLANEHEIGHT; z[1] = (ishighground[1] || ishighground[2] || ishighground[4])? HEIGHGROUNDHEIGHT:PLANEHEIGHT; z[2] = (ishighground[3] || ishighground[5] || ishighground[6])? HEIGHGROUNDHEIGHT:PLANEHEIGHT; z[3] = (ishighground[5] || ishighground[6] || ishighground[7])? HEIGHGROUNDHEIGHT:PLANEHEIGHT; if(z[0] != z[1]) height = z[0] + z[1] * dx /TILESIZE; else if(z[0] != z[2]) height = z[0] + z[2] / dy; else if(z[2] != z[3]) height = z[2] + z[3] / dx; else if(z[1] != z[3]) height = z[1] + z[3] / dy; else height = PLANEHEIGHT; */ } return height; }