00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * $Log: terrainground.cpp,v $ 00023 * Revision 1.2.4.1 2006/01/12 15:12:34 martius 00024 * disabled for now 00025 * 00026 * Revision 1.2 2005/10/28 12:06:10 martius 00027 * *** empty log message *** 00028 * 00029 * Revision 1.1 2005/10/25 22:22:46 martius 00030 * moved implementation to cpp 00031 * data constructor 00032 * store method 00033 * different heighmap codings 00034 * 00035 * * 00036 ***************************************************************************/ 00037 00038 // #include <stdio.h> 00039 // #include <math.h> 00040 // #include <assert.h> 00041 00042 // #include "terrainground.h" 00043 // #include <drawstuff/drawstuff.h> 00044 // #include "imageppm.h" 00045 00046 // double Terrainground::coding(CodingMode mode, const unsigned char* data){ 00047 // switch(mode){ 00048 // case Red: 00049 // return (data[0])/256.0; 00050 // break; 00051 // case Sum: 00052 // return (data[0] + data[1] + data[2])/(3*256.0); 00053 // break; 00054 // case LowMidHigh: 00055 // return ((long(data[0]) << 16) + (long(data[1]) << 8) + data[2])/65536.0; 00056 // break; 00057 // default: 00058 // return 0; 00059 // } 00060 00061 // } 00062 00063 // Terrainground::Terrainground(const OdeHandle& odehandle, double size, double height, char *filename, 00064 // CodingMode codingMode) 00065 // : AbstractObstacle::AbstractObstacle(odehandle) 00066 // { 00067 // this->height = height; 00068 // this->size = size; 00069 // obstacle_exists=false; 00070 // texture = 0; 00071 // base_x=0.0; 00072 // base_y=0.0; 00073 // base_z=0.0; 00074 // displayListNumber=-1; 00075 // pTerrainHeights=0; 00076 // texture=DS_NONE; 00077 00078 // if(!heightmap.loadImage(filename)) return; 00079 // // image width and image height MUST be the same AND A POWER OF 2 ****************** 00080 // TERRAINNODES = heightmap.width(); 00081 // assert(heightmap.height() == TERRAINNODES); 00082 // int bitcounter = 0; 00083 // for(unsigned int i=0; i < sizeof(TERRAINNODES)*8; i++){ 00084 // bitcounter += (TERRAINNODES & (1<<i)) != 0; 00085 // } 00086 // assert(bitcounter==1); 00087 00088 // pTerrainHeights = new double[TERRAINNODES*TERRAINNODES]; 00089 00090 // // copy and convert the heightmap from RGB chars to double 00091 // for(int i=0; i< TERRAINNODES*TERRAINNODES; i++){ 00092 // // use the coding th get the height and scale it to height 00093 // pTerrainHeights[i] = coding(codingMode, heightmap.data() + i*3)*height; 00094 // } 00095 00096 // displayListNumber = dsCreateDisplayListTerrainZD(size, TERRAINNODES, pTerrainHeights); 00097 00098 // }; 00099 00100 00101 // Terrainground::~Terrainground() 00102 // { 00103 // destroy(); 00104 // if(pTerrainHeights) delete[] pTerrainHeights; 00105 // } 00106 00107 00108 // // draws the obstacle (terrain) 00109 // void Terrainground::draw() 00110 // { 00111 // if(pTerrainHeights && displayListNumber >= 0) { 00112 // dsSetColor (color.r, color.g, color.b); // color settings have no effect on object if textured 00113 // // dsDrawTerrainZD( (int)base_x, (int)base_z, size, size/ (double)TERRAINNODES, TERRAINNODES, pTerrainHeights, dGeomGetRotation(terrainZ), dGeomGetPosition(terrainZ)); 00114 // dsSetTexture (texture,1); 00115 // dsCallList(displayListNumber, dGeomGetRotation(terrainZ), dGeomGetPosition(terrainZ)); 00116 // } 00117 // }; 00118 00119 00120 // void Terrainground::setTextureID(int t) { 00121 // texture = t; 00122 // setColor(1,1,1); 00123 // } 00124 00125 00126 // void Terrainground::setPosition(double x, double y, double z){ 00127 // base_x = x; 00128 // base_y = y; 00129 // base_z = z; 00130 // if (obstacle_exists) destroy(); 00131 // create(); 00132 // }; 00133 00134 // void Terrainground::getPosition(double& x, double& y, double& z){ 00135 // x = base_x; 00136 // y = base_y; 00137 // z = base_z; 00138 // } 00139 00140 // void Terrainground::setGeometry(double length_, double width_, double height_){ 00141 // size = length_; 00142 // height = height_; 00143 // }; 00144 00145 // // virtual void setGeometry(double length_, double width_, double height_, double factorlength2_){ 00146 // // length=length_; 00147 // // width=width_; 00148 // // height =height_; 00149 // // factorlength2=factorlength2_; 00150 // // }; 00151 00152 // void Terrainground::setColor(double r, double g, double b){ 00153 // color.r=r; 00154 // color.g=g; 00155 // color.b=b; 00156 // }; 00157 00158 00159 // void Terrainground::create(){ 00160 // if(!pTerrainHeights) return; 00161 00162 // terrainZ = dCreateTerrainZ( space, pTerrainHeights, size, TERRAINNODES, 1, 1); 00163 // dGeomSetPosition ( terrainZ, base_x, base_y, base_z); 00164 00165 // obstacle_exists=true; 00166 // }; 00167 00168 00169 // void Terrainground::destroy(){ 00170 // if(pTerrainHeights) 00171 // dGeomDestroy( terrainZ ); 00172 // obstacle_exists=false; 00173 // }; 00174 00175