Changeset 7216 in orxonox.OLD for branches/std/src/world_entities
- Timestamp:
- Mar 12, 2006, 8:54:30 AM (19 years ago)
- Location:
- branches/std/src/world_entities
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/world_entities/elements/text_element.cc
r7193 r7216 70 70 } 71 71 72 void TextElement::setText(const char*text)72 void TextElement::setText(const std::string& text) 73 73 { 74 74 Text::setText(text); 75 75 } 76 76 77 void TextElement::setFont(const char*font)77 void TextElement::setFont(const std::string& font) 78 78 { 79 79 Text::setFont(font, (unsigned int)this->getSizeY2D()); -
branches/std/src/world_entities/elements/text_element.h
r7019 r7216 29 29 virtual void loadParams(const TiXmlElement* root); 30 30 31 void setText(const char*text);32 void setFont(const char*font);31 void setText(const std::string& text); 32 void setFont(const std::string& font); 33 33 34 34 private: -
branches/std/src/world_entities/planet.cc
r7193 r7216 45 45 this->toList(OM_GROUP_01); 46 46 47 this->material = new Material();48 47 //this->material->setIllum(20); 49 48 //this->material->setAmbient(0.1, 0.1, 0.1); … … 71 70 { 72 71 PRINTF(5)("Deleting Planet\n"); 73 if( this->material)74 delete this->material;75 72 } 76 73 … … 92 89 * @param textureName the top texture. 93 90 */ 94 void Planet::setTexture(const char*textureName)91 void Planet::setTexture(const std::string& textureName) 95 92 { 96 this->material ->setDiffuseMap(textureName);93 this->material.setDiffuseMap(textureName); 97 94 } 98 95 … … 124 121 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 125 122 126 this->material ->select();123 this->material.select(); 127 124 128 125 // /WorldEntity::draw(); -
branches/std/src/world_entities/planet.h
r6959 r7216 9 9 /* INCLUDES */ 10 10 #include "world_entity.h" 11 11 #include "material.h" 12 12 /* FORWARD DECLARATION */ 13 class Material;14 13 class Texture; 15 14 … … 26 25 void setSize(float size); 27 26 /** assumes jpg as input-format */ 28 void setTexture(const char*textureName);27 void setTexture(const std::string& textureName); 29 28 30 29 … … 34 33 35 34 private: 36 Material *material; //!< Materials for the Planet. sorted by number (0-5) top, bottom, left, right, front, back35 Material material; //!< Materials for the Planet. sorted by number (0-5) top, bottom, left, right, front, back 37 36 Texture* texture; //!< Textures for the CubeMap. 38 37 -
branches/std/src/world_entities/power_ups/param_power_up.cc
r7193 r7216 81 81 } 82 82 83 void ParamPowerUp::setType(const char*type)83 void ParamPowerUp::setType(const std::string& type) 84 84 { 85 85 for(int i = 0; i < POWERUP_PARAM_size; ++i) { 86 if( strcmp(type, paramTypes[i]) == 0) {86 if(type == paramTypes[i]) { 87 87 this->type = (EnumParamPowerUpType)i; 88 88 break; -
branches/std/src/world_entities/power_ups/param_power_up.h
r7065 r7216 28 28 void setMaxValue(float value); 29 29 void setMinValue(float value); 30 void setType(const char*type);30 void setType(const std::string& type); 31 31 EnumParamPowerUpType getType(); 32 32 float getValue(); … … 43 43 44 44 private: 45 static const char* paramTypes[]; 46 EnumParamPowerUpType type; 47 float value; 48 float max_value; 49 float min_value; 45 EnumParamPowerUpType type; 46 float value; 47 float max_value; 48 float min_value; 49 50 static const char* paramTypes[]; 51 50 52 }; 51 53 -
branches/std/src/world_entities/power_ups/power_up.cc
r7207 r7216 182 182 }; 183 183 184 void PowerUp::setRespawnType(const char* type) 184 185 void PowerUp::setRespawnType(const std::string& type) 185 186 { 186 187 for(int i = 0; i < RESPAWN_size; ++i) 187 188 { 188 if( !strcmp(type, respawnTypes[i]))189 if(type == respawnTypes[i]) 189 190 { 190 191 this->respawnType = (PowerUpRespawn)i; -
branches/std/src/world_entities/power_ups/power_up.h
r7207 r7216 31 31 virtual void draw () const; 32 32 virtual void tick(float dt); 33 void setRespawnType(const char*type);33 void setRespawnType(const std::string& type); 34 34 void setRespawnTime(const float respawn); 35 35 … … 45 45 46 46 private: 47 SoundSource soundSource;48 SoundBuffer* pickupBuffer;49 SoundBuffer* respawnBuffer;50 Material* sphereMaterial;51 PowerUpRespawn respawnType;52 float respawnTime;53 float respawnStart;54 static const char* respawnTypes[];47 SoundSource soundSource; 48 SoundBuffer* pickupBuffer; 49 SoundBuffer* respawnBuffer; 50 Material* sphereMaterial; 51 PowerUpRespawn respawnType; 52 float respawnTime; 53 float respawnStart; 54 static const char* respawnTypes[]; 55 55 56 WorldEntity* collider;56 WorldEntity* collider; 57 57 }; 58 58 -
branches/std/src/world_entities/recorder.cc
r7193 r7216 54 54 55 55 LoadParam(root, "duration", this, Recorder, setStreamDuration); 56 56 57 LoadParam(root, "fps", this, Recorder, setFPS); 58 57 59 LoadParam(root, "name", this, Recorder, initVideo); 58 60 } … … 71 73 72 74 73 void Recorder::initVideo(const char*filename)75 void Recorder::initVideo(const std::string& filename) 74 76 { 75 77 frame_count = 0; … … 78 80 79 81 // auto detect the output format from the name, default is mpeg 80 output_format = guess_format(NULL, filename , NULL);82 output_format = guess_format(NULL, filename.c_str(), NULL); 81 83 if (!output_format) 82 84 { … … 93 95 94 96 format_context->oformat = output_format; 95 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename );97 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename.c_str()); 96 98 97 99 // add video stream using the default format codec and initialize the codec … … 104 106 105 107 // print some information 106 dump_format(format_context, 0, filename , 1);108 dump_format(format_context, 0, filename.c_str(), 1); 107 109 108 110 // now that all the parameters are set, we can open the … … 110 112 if(video_stream) 111 113 this->openVideo(); 112 114 113 115 // open the output file, if needed 114 116 if(!(output_format->flags & AVFMT_NOFILE)) 115 117 { 116 if(url_fopen(&format_context->pb, filename , URL_WRONLY) < 0)117 PRINTF(1)("Could not open %s\n", filename );118 if(url_fopen(&format_context->pb, filename.c_str(), URL_WRONLY) < 0) 119 PRINTF(1)("Could not open %s\n", filename.c_str()); 118 120 } 119 121 120 122 // write the stream header, if any 121 av_write_header(format_context); 123 av_write_header(format_context); 122 124 } 123 125 … … 129 131 av_free(buffer); 130 132 131 // write the trailer, if any 133 // write the trailer, if any 132 134 av_write_trailer(format_context); 133 135 134 136 // free the streams 135 137 for(int i = 0; i < format_context->nb_streams; i++) … … 175 177 176 178 void Recorder::allocPicture() 177 { 179 { 178 180 picture = avcodec_alloc_frame(); 179 181 if(!picture) … … 189 191 return; 190 192 } 191 avpicture_fill((AVPicture *)picture, picture_buf, 193 avpicture_fill((AVPicture *)picture, picture_buf, 192 194 codec_context->pix_fmt, width, height); 193 195 … … 211 213 if (!video_stream) 212 214 PRINTF(1)("Could not alloc stream\n"); 213 215 214 216 codec_context = video_stream->codec; 215 217 codec_context->codec_id = output_format->video_codec; … … 219 221 codec_context->bit_rate = 400000; 220 222 // resolution must be a multiple of two 221 codec_context->width = State::getResX(); 223 codec_context->width = State::getResX(); 222 224 codec_context->height = State::getResY(); 223 225 … … 229 231 // timebase should be 1/framerate and timestamp increments should be 230 232 // identically 1 231 codec_context->time_base.den = (int)stream_frame_rate; 233 codec_context->time_base.den = (int)stream_frame_rate; 232 234 codec_context->time_base.num = 1; 233 235 codec_context->gop_size = 12; // emit one intra frame every twelve frames at most … … 235 237 236 238 if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO) 237 // needed to avoid using macroblocks in which some coeffs overflow 238 // this doesnt happen with normal video, it just happens here as the 239 // needed to avoid using macroblocks in which some coeffs overflow 240 // this doesnt happen with normal video, it just happens here as the 239 241 // motion of the chroma plane doesnt match the luma plane 240 242 codec_context->mb_decision=2; … … 275 277 { 276 278 int out_size, err; 277 279 278 280 codec_context = video_stream->codec; 279 281 280 282 if(frame_count >= stream_nb_frames) 281 283 { … … 287 289 this->fillYuvImage(); 288 290 289 291 290 292 if(format_context->oformat->flags & AVFMT_RAWPICTURE) 291 293 { … … 293 295 // futur for that 294 296 av_init_packet(&packet); 295 297 296 298 packet.flags |= PKT_FLAG_KEY; 297 299 packet.stream_index= video_stream->index; 298 300 packet.data= (uint8_t *)picture; 299 301 packet.size= sizeof(AVPicture); 300 302 301 303 err = av_write_frame(format_context, &packet); 302 304 } … … 309 311 { 310 312 av_init_packet(&packet); 311 313 312 314 packet.pts= av_rescale_q(codec_context->coded_frame->pts, codec_context->time_base, video_stream->time_base); 313 315 if(codec_context->coded_frame->key_frame) … … 316 318 packet.data= buffer; 317 319 packet.size= out_size; 318 320 319 321 // write the compressed frame in the media file 320 322 err = av_write_frame(format_context, &packet); -
branches/std/src/world_entities/recorder.h
r6981 r7216 20 20 class Recorder : public WorldEntity 21 21 { 22 private:23 AVFrame* picture;24 uint8_t* buffer;25 int frame_count;26 int buffer_size;27 28 AVOutputFormat* output_format;29 AVFormatContext* format_context;30 AVCodecContext* codec_context;31 AVCodec *codec;32 AVStream* video_stream;33 AVPacket packet;34 double video_pts;35 36 uint8_t *picture_buf;37 int size;38 39 int height;40 int width;41 float time;42 43 float stream_duration;44 float stream_frame_rate;45 int stream_nb_frames;46 47 AVFrame* RGB_frame;48 22 public: 49 23 Recorder (const TiXmlElement* root = NULL); … … 56 30 57 31 private: 58 void initVideo(const char*filename);32 void initVideo(const std::string& filename); 59 33 void addVideoStream(); 60 34 void openVideo(); … … 66 40 void setStreamDuration(float duration); 67 41 void setFPS(float fps); 42 43 44 private: 45 AVFrame* picture; 46 uint8_t* buffer; 47 int frame_count; 48 int buffer_size; 49 50 AVOutputFormat* output_format; 51 AVFormatContext* format_context; 52 AVCodecContext* codec_context; 53 AVCodec* codec; 54 AVStream* video_stream; 55 AVPacket packet; 56 double video_pts; 57 58 uint8_t* picture_buf; 59 int size; 60 61 int height; 62 int width; 63 float time; 64 65 float stream_duration; 66 float stream_frame_rate; 67 int stream_nb_frames; 68 69 AVFrame* RGB_frame; 68 70 }; 69 71 -
branches/std/src/world_entities/terrain.cc
r7207 r7216 48 48 this->loadParams(root); 49 49 50 // if (this->model != NULL)51 50 // if (this->model != NULL) 51 //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); 52 52 } 53 53 … … 64 64 65 65 if (!strstr(fileName, ".obj") || !strstr(fileName, ".OBJ") ) 66 67 68 66 { 67 this->loadModel(fileName); 68 } 69 69 else 70 71 72 70 { 71 // load the hightMap here. 72 } 73 73 } 74 74 … … 98 98 99 99 if(this->heightMap) 100 100 delete heightMap; 101 101 } 102 102 … … 122 122 123 123 LoadParam(root, "scale", this, Terrain, setScale) 124 124 .describe("The scale in x,y,z direction"); 125 125 126 126 LoadParam(root, "texture", this, Terrain, loadTexture) 127 127 .describe("The name of the Texture for this heightMap"); 128 128 129 129 LoadParam(root, "vegetation", this, Terrain, loadVegetation) 130 130 .describe("the fileName of the vegetation, that should be loaded onto this terrain. (must be relative to the data-dir)") ; 131 131 132 132 LoadParam(root, "height-map", this, Terrain, loadHeightMap) 133 133 .describe("The HeightMap, splitted into two strings seperated by ','. 1: HeighMap, 2: ColorMap"); 134 134 135 135 } … … 140 140 } 141 141 142 void Terrain::loadHeightMap(const char* heightMapFile, const char*colorMap)142 void Terrain::loadHeightMap(const std::string& heightMapFile, const std::string& colorMap) 143 143 { 144 144 if (this->heightMap != NULL) … … 151 151 152 152 this->heightMap = new HeightMap(hmName, hmColorName); 153 // heightMap->scale(Vector(43.0f,4.7f,43.0f));153 // heightMap->scale(Vector(43.0f,4.7f,43.0f)); 154 154 heightMap->scale(this->terrainScale); 155 155 heightMap->setAbsCoor(this->getAbsCoor()); … … 158 158 159 159 160 void Terrain::loadTexture(const char*textureName)161 { 162 PRINTF(0)("Load texture: %s\n", textureName);163 164 165 166 167 168 169 170 171 heightMapMaterial->setAmbientMap(textureName);172 heightMapMaterial->setSpecularMap(textureName);160 void Terrain::loadTexture(const std::string& textureName) 161 { 162 PRINTF(4)("Load texture: %s\n", textureName.c_str()); 163 164 heightMapMaterial->setDiffuse(1.0,1.0,1.0); 165 heightMapMaterial->setAmbient(1.0,1.0,1.0 ); 166 heightMapMaterial->setSpecular(1.0,1.0,1.0); 167 heightMapMaterial->setShininess(.5); 168 heightMapMaterial->setTransparency(1.0); 169 170 heightMapMaterial->setDiffuseMap(textureName); 171 // heightMapMaterial->setAmbientMap(textureName); 172 // heightMapMaterial->setSpecularMap(textureName); 173 173 } 174 174 … … 202 202 this->getAbsCoor ().z); 203 203 /* rotate */ 204 // Vector tmpRot = this->getAbsDir().getSpacialAxis();204 // Vector tmpRot = this->getAbsDir().getSpacialAxis(); 205 205 //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 206 206 … … 224 224 225 225 226 /*227 glMatrixMode(GL_MODELVIEW);228 glPushMatrix();229 glLoadIdentity();230 Vector camera = State::getCameraNode()->getAbsCoor(); // Go on here ..........!!!231 232 float height = heightMap->getHeight(camera.x, camera.z);233 234 glEnable (GL_COLOR_MATERIAL) ;235 glBegin(GL_QUADS); // Draw The Cube Using quads236 glColor3f(0.0f,1.0f,0.0f); // Color Blue237 glVertex3f(camera.x + 63.0f,Terrain->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top)238 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top)239 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top)240 glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Right Of The Quad (Top)241 glEnd(); // End Drawing The Plan242 243 glPopMatrix();*/244 245 246 /* THIS IS ONLY FOR DEBUGGING INFORMATION */226 /* 227 glMatrixMode(GL_MODELVIEW); 228 glPushMatrix(); 229 glLoadIdentity(); 230 Vector camera = State::getCameraNode()->getAbsCoor(); // Go on here ..........!!! 231 232 float height = heightMap->getHeight(camera.x, camera.z); 233 234 glEnable (GL_COLOR_MATERIAL) ; 235 glBegin(GL_QUADS); // Draw The Cube Using quads 236 glColor3f(0.0f,1.0f,0.0f); // Color Blue 237 glVertex3f(camera.x + 63.0f,Terrain->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top) 238 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top) 239 glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top) 240 glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Right Of The Quad (Top) 241 glEnd(); // End Drawing The Plan 242 243 glPopMatrix();*/ 244 245 246 /* THIS IS ONLY FOR DEBUGGING INFORMATION */ 247 247 if (this->ssp != NULL) 248 248 this->ssp->drawQuadtree(); … … 254 254 // if the terrain is the Terrain of Dave 255 255 if (debugTerrain == TERRAIN_DAVE) 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 256 { 257 objectList = glGenLists(1); 258 glNewList (objectList, GL_COMPILE); 259 260 glColor3f(1.0,0,0); 261 262 int sizeX = 100; 263 int sizeZ = 80; 264 float length = 1000; 265 float width = 200; 266 float widthX = float (length /sizeX); 267 float widthZ = float (width /sizeZ); 268 269 float height [sizeX][sizeZ]; 270 Vector normal_vectors[sizeX][sizeZ]; 271 272 273 for ( int i = 0; i<sizeX-1; i+=1) 274 for (int j = 0; j<sizeZ-1;j+=1) 275 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 276 276 #ifdef __WIN32__ 277 277 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; 278 278 #else 279 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;279 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; 280 280 #endif 281 281 282 //Die Huegel ein wenig glaetten 283 for (int h=1; h<2;h++) 284 for (int i=1;i<sizeX-2 ;i+=1 ) 285 for(int j=1;j<sizeZ-2;j+=1) 286 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 287 288 //Berechnung von normalen Vektoren 289 for(int i=1;i<sizeX-2;i+=1) 290 for(int j=1;j<sizeZ-2 ;j+=1) 291 { 292 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 293 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 294 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 295 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 296 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 297 298 Vector c1 = v2 - v1; 299 Vector c2 = v3 - v1; 300 Vector c3= v4 - v1; 301 Vector c4 = v5 - v1; 302 Vector zero = Vector (0,0,0); 303 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 304 normal_vectors[i][j].normalize(); 305 } 306 307 glBegin(GL_QUADS); 308 int snowheight=3; 309 for ( int i = 0; i<sizeX; i+=1) 310 for (int j = 0; j<sizeZ;j+=1) 311 { 312 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 313 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 314 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 315 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 316 float a[3]; 317 if(height[i][j]<snowheight){ 318 a[0]=0; 319 a[1]=1.0-height[i][j]/10-.3; 320 a[2]=0; 321 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 322 } 323 else{ 324 a[0]=1.0; 325 a[1]=1.0; 326 a[2]=1.0; 327 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 328 329 } 330 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 331 glVertex3f(v1.x, v1.y, v1.z); 332 if(height[i+1][j]<snowheight){ 333 a[0]=0; 334 a[1] =1.0-height[i+1][j]/10-.3; 335 a[2]=0; 336 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 337 } 338 else{ 339 a[0]=1.0; 340 a[1]=1.0; 341 a[2]=1.0; 342 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 343 344 } 345 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 346 glVertex3f(v2.x, v2.y, v2.z); 347 if(height[i+1][j+1]<snowheight){ 348 a[0]=0; 349 a[1] =1.0-height[i+1][j+1]/10-.3; 350 a[2]=0; 351 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 352 } 353 else{ 354 a[0]=1.0; 355 a[1]=1.0; 356 a[2]=1.0; 357 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 358 359 360 } 361 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 362 glVertex3f(v3.x, v3.y, v3.z); 363 if(height[i][j+1]<snowheight){ 364 a[0]=0; 365 a[1] =1.0-height[i+1][j+1]/10-.3; 366 a[2]=0; 367 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 368 } 369 else{ 370 a[0]=1.0; 371 a[1]=1.0; 372 a[2]=1.0; 373 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 374 } 375 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 376 glVertex3f(v4.x, v4.y, v4.z); 377 378 } 379 glEnd(); 380 glEndList(); 381 } 282 //Die Huegel ein wenig glaetten 283 for (int h=1; h<2;h++) 284 for (int i=1;i<sizeX-2 ;i+=1 ) 285 for(int j=1;j<sizeZ-2;j+=1) 286 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 287 288 //Berechnung von normalen Vektoren 289 for(int i=1;i<sizeX-2;i+=1) 290 for(int j=1;j<sizeZ-2 ;j+=1) 291 { 292 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 293 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 294 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 295 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 296 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 297 298 Vector c1 = v2 - v1; 299 Vector c2 = v3 - v1; 300 Vector c3= v4 - v1; 301 Vector c4 = v5 - v1; 302 Vector zero = Vector (0,0,0); 303 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 304 normal_vectors[i][j].normalize(); 305 } 306 307 glBegin(GL_QUADS); 308 int snowheight=3; 309 for ( int i = 0; i<sizeX; i+=1) 310 for (int j = 0; j<sizeZ;j+=1) 311 { 312 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 313 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 314 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 315 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 316 float a[3]; 317 if(height[i][j]<snowheight) 318 { 319 a[0]=0; 320 a[1]=1.0-height[i][j]/10-.3; 321 a[2]=0; 322 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 323 } 324 else 325 { 326 a[0]=1.0; 327 a[1]=1.0; 328 a[2]=1.0; 329 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 330 331 } 332 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 333 glVertex3f(v1.x, v1.y, v1.z); 334 if(height[i+1][j]<snowheight) 335 { 336 a[0]=0; 337 a[1] =1.0-height[i+1][j]/10-.3; 338 a[2]=0; 339 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 340 } 341 else 342 { 343 a[0]=1.0; 344 a[1]=1.0; 345 a[2]=1.0; 346 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 347 348 } 349 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 350 glVertex3f(v2.x, v2.y, v2.z); 351 if(height[i+1][j+1]<snowheight) 352 { 353 a[0]=0; 354 a[1] =1.0-height[i+1][j+1]/10-.3; 355 a[2]=0; 356 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 357 } 358 else 359 { 360 a[0]=1.0; 361 a[1]=1.0; 362 a[2]=1.0; 363 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 364 365 366 } 367 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 368 glVertex3f(v3.x, v3.y, v3.z); 369 if(height[i][j+1]<snowheight) 370 { 371 a[0]=0; 372 a[1] =1.0-height[i+1][j+1]/10-.3; 373 a[2]=0; 374 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 375 } 376 else 377 { 378 a[0]=1.0; 379 a[1]=1.0; 380 a[2]=1.0; 381 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 382 } 383 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 384 glVertex3f(v4.x, v4.y, v4.z); 385 386 } 387 glEnd(); 388 glEndList(); 389 } 382 390 383 391 if (debugTerrain == TERRAIN_BENSCH) 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 392 { 393 /* 394 this->model = (OBJModel*) new Model(); 395 this->model->setName("CUBE"); 396 this->model->addVertex (-0.5, -0.5, 0.5); 397 this->model->addVertex (0.5, -0.5, 0.5); 398 this->model->addVertex (-0.5, 0.5, 0.5); 399 this->model->addVertex (0.5, 0.5, 0.5); 400 this->model->addVertex (-0.5, 0.5, -0.5); 401 this->model->addVertex (0.5, 0.5, -0.5); 402 this->model->addVertex (-0.5, -0.5, -0.5); 403 this->model->addVertex (0.5, -0.5, -0.5); 404 405 this->model->addVertexTexture (0.0, 0.0); 406 this->model->addVertexTexture (1.0, 0.0); 407 this->model->addVertexTexture (0.0, 1.0); 408 this->model->addVertexTexture (1.0, 1.0); 409 this->model->addVertexTexture (0.0, 2.0); 410 this->model->addVertexTexture (1.0, 2.0); 411 this->model->addVertexTexture (0.0, 3.0); 412 this->model->addVertexTexture (1.0, 3.0); 413 this->model->addVertexTexture (0.0, 4.0); 414 this->model->addVertexTexture (1.0, 4.0); 415 this->model->addVertexTexture (2.0, 0.0); 416 this->model->addVertexTexture (2.0, 1.0); 417 this->model->addVertexTexture (-1.0, 0.0); 418 this->model->addVertexTexture (-1.0, 1.0); 419 420 this->model->finalize(); 421 */ 422 } 415 423 } 416 424 … … 450 458 451 459 void Terrain::writeDebug( ) const 452 { 453 } 460 {} 454 461 455 462 void Terrain::readDebug( ) const 456 { 457 } 463 {} 458 464 459 465 float Terrain::getHeight(float x, float y) 460 466 { 461 462 463 464 } 467 if(this->heightMap != NULL) 468 return (this->heightMap->getHeight(x, y)); 469 return 0; 470 } -
branches/std/src/world_entities/terrain.h
r7207 r7216 43 43 void loadVegetation(const std::string& vegetationFile); 44 44 45 void loadHeightMap(const char* heightMapFile, const char* colorMap = NULL);46 void loadTexture(const char*textureName);45 void loadHeightMap(const std::string& heightMapFile, const std::string& colorMap); 46 void loadTexture(const std::string& textureName); 47 47 void setScale(float x, float y, float z); 48 48 -
branches/std/src/world_entities/weapons/aim.cc
r7193 r7216 147 147 * @param textureFile The texture-file to load onto the crosshair 148 148 */ 149 void Aim::setTexture(const char*textureFile)149 void Aim::setTexture(const std::string& textureFile) 150 150 { 151 151 this->material->setDiffuseMap(textureFile); -
branches/std/src/world_entities/weapons/aim.h
r6724 r7216 46 46 47 47 void setSize(float size); 48 void setTexture(const char*textureFile);48 void setTexture(const std::string& textureFile); 49 49 /** @param rotationSpeed the speed at what the crosshair should rotate */ 50 50 inline void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; -
branches/std/src/world_entities/weapons/crosshair.cc
r7193 r7216 79 79 EventListener::loadParams(root); 80 80 81 LoadParam(root, "texture", this , Crosshair, setTexture)81 LoadParam(root, "texture", this->material, Material, setDiffuseMap) 82 82 .describe("the texture-file to load onto the Crosshair"); 83 83 … … 103 103 * @param textureFile The texture-file to load onto the crosshair 104 104 */ 105 void Crosshair::setTexture(const char*textureFile)105 void Crosshair::setTexture(const std::string& textureFile) 106 106 { 107 107 this->material->setDiffuseMap(textureFile); -
branches/std/src/world_entities/weapons/crosshair.h
r6512 r7216 31 31 32 32 void setSize(float size); 33 void setTexture(const char*textureFile);33 void setTexture(const std::string& textureFile); 34 34 /** @param rotationSpeed the speed at what the crosshair should rotate */ 35 35 void setRotationSpeed(float rotationSpeed) { this->rotationSpeed = rotationSpeed; }; -
branches/std/src/world_entities/weapons/weapon.cc
r7207 r7216 165 165 * @param projectile the Name of the Projectile. 166 166 */ 167 void Weapon::setProjectileTypeC(const char* projectile) 168 { 169 if (projectile == NULL) 170 return; 167 void Weapon::setProjectileTypeC(const std::string& projectile) 168 { 171 169 FastFactory* tmpFac = FastFactory::searchFastFactory(projectile); 172 170 if (tmpFac != NULL) … … 176 174 else 177 175 { 178 PRINTF(1)("Projectile %s does not exist for weapon %s\n", projectile , this->getName());176 PRINTF(1)("Projectile %s does not exist for weapon %s\n", projectile.c_str(), this->getName()); 179 177 } 180 178 } … … 613 611 * @return The Action if known, WA_NONE otherwise. 614 612 */ 615 WeaponAction Weapon::charToAction(const char*action)616 { 617 if ( !strcmp(action, "none"))613 WeaponAction Weapon::charToAction(const std::string& action) 614 { 615 if (action == "none") 618 616 return WA_NONE; 619 else if ( !strcmp(action, "shoot"))617 else if (action == "shoot") 620 618 return WA_SHOOT; 621 else if ( !strcmp(action, "charge"))619 else if (action == "charge") 622 620 return WA_CHARGE; 623 else if ( !strcmp(action, "reload"))621 else if (action == "reload") 624 622 return WA_RELOAD; 625 else if ( !strcmp(action, "acitvate"))623 else if (action == "acitvate") 626 624 return WA_ACTIVATE; 627 else if ( !strcmp(action, "deactivate"))625 else if (action == "deactivate") 628 626 return WA_DEACTIVATE; 629 else if ( !strcmp(action, "special1"))627 else if (action == "special1") 630 628 return WA_SPECIAL1; 631 629 else 632 630 { 633 PRINTF(2)("action %s could not be identified.\n", action );631 PRINTF(2)("action %s could not be identified.\n", action.c_str()); 634 632 return WA_NONE; 635 633 } … … 674 672 * @return The State if known, WS_NONE otherwise. 675 673 */ 676 WeaponState Weapon::charToState(const char*state)677 { 678 if ( !strcmp(state, "none"))674 WeaponState Weapon::charToState(const std::string& state) 675 { 676 if (state == "none") 679 677 return WS_NONE; 680 else if ( !strcmp(state, "shooting"))678 else if (state == "shooting") 681 679 return WS_SHOOTING; 682 else if ( !strcmp(state, "charging"))680 else if (state == "charging") 683 681 return WS_CHARGING; 684 else if ( !strcmp(state, "reloading"))682 else if (state == "reloading") 685 683 return WS_RELOADING; 686 else if ( !strcmp(state, "activating"))684 else if (state == "activating") 687 685 return WS_ACTIVATING; 688 else if ( !strcmp(state, "deactivating"))686 else if (state == "deactivating") 689 687 return WS_DEACTIVATING; 690 else if ( !strcmp(state, "inactive"))688 else if (state == "inactive") 691 689 return WS_INACTIVE; 692 else if ( !strcmp(state, "idle"))690 else if (state == "idle") 693 691 return WS_IDLE; 694 692 else 695 693 { 696 PRINTF(2)("state %s could not be identified.\n", state );694 PRINTF(2)("state %s could not be identified.\n", state.c_str()); 697 695 return WS_NONE; 698 696 } -
branches/std/src/world_entities/weapons/weapon.h
r7207 r7216 111 111 inline long getCapability() const { return this->capability; }; 112 112 void setProjectileType(ClassID projectile); 113 void setProjectileTypeC(const char*projectile);113 void setProjectileTypeC(const std::string& projectile); 114 114 /** @returns The projectile's classID */ 115 115 inline ClassID getProjectileType() { return this->projectile; }; … … 132 132 // STATE CHANGES // 133 133 /** @param state the State to time @param duration the duration of the State */ 134 inline void setStateDuration(const char*state, float duration) { setStateDuration(charToState(state), duration); };134 inline void setStateDuration(const std::string& state, float duration) { setStateDuration(charToState(state), duration); }; 135 135 /** @param state the State to time @param duration the duration of the State */ 136 136 inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; }; … … 149 149 150 150 void setActionSound(WeaponAction action, const std::string& soundFile); 151 /** @see void setActionSound(WeaponAction action, const char*soundFile); */152 void setActionSound(const char* action, const char*soundFile) { this->setActionSound(charToAction(action), soundFile); };151 /** @see void setActionSound(WeaponAction action, const std::string& soundFile); */ 152 void setActionSound(const std::string& action, const std::string& soundFile) { this->setActionSound(charToAction(action), soundFile); }; 153 153 154 154 Animation3D* getAnimation(WeaponState state, PNode* node = NULL); … … 176 176 177 177 // utility: 178 static WeaponAction charToAction(const char*action);178 static WeaponAction charToAction(const std::string& action); 179 179 static const char* actionToChar(WeaponAction action); 180 static WeaponState charToState(const char*state);180 static WeaponState charToState(const std::string& state); 181 181 static const char* stateToChar(WeaponState state); 182 182 -
branches/std/src/world_entities/world_entity.cc
r7203 r7216 61 61 this->bCollide = true; 62 62 63 this->md2TextureFileName = NULL;64 65 63 this->objectListNumber = OM_INIT; 66 64 this->objectListIterator = NULL; … … 123 121 * @todo fix this, so it only has one loadModel-Function. 124 122 */ 125 void WorldEntity::loadModel(const char*fileName, float scaling, unsigned int modelNumber)123 void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber) 126 124 { 127 125 this->modelLODName = fileName; 128 126 this->scaling = scaling; 129 if ( fileName != NULL && strcmp(fileName, ""))127 if (!fileName.empty()) 130 128 { 131 129 // search for the special character # in the LoadParam 132 if (strchr(fileName, '#') != NULL) 133 { 134 PRINTF(4)("Found # in %s... searching for LOD's\n", fileName); 135 char* lodFile = new char[strlen(fileName)+1]; 136 strcpy(lodFile, fileName); 137 char* depth = strchr(lodFile, '#'); 130 if (fileName.find('#') != std::string::npos) 131 { 132 PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str()); 133 std::string lodFile = fileName; 134 unsigned int offset = lodFile.find('#'); 138 135 for (unsigned int i = 0; i < 3; i++) 139 136 { 140 *depth= 48+(int)i;137 lodFile[offset] = 48+(int)i; 141 138 if (ResourceManager::isInDataDir(lodFile)) 142 139 this->loadModel(lodFile, scaling, i); … … 149 146 this->scaling = 1.0; 150 147 } 151 if( strstr(fileName, ".obj"))152 { 153 PRINTF(4)("fetching OBJ file: %s\n", fileName );148 if(fileName.find(".obj") != std::string::npos) 149 { 150 PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str()); 154 151 BaseObject* loadedModel = ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, this->scaling); 155 152 if (loadedModel != NULL) … … 159 156 this->buildObbTree(4); 160 157 } 161 else if( strstr(fileName, ".md2"))162 { 163 PRINTF(4)("fetching MD2 file: %s\n", fileName );158 else if(fileName.find(".md2") != std::string::npos) 159 { 160 PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str()); 164 161 Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling); 165 162 //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); -
branches/std/src/world_entities/world_entity.h
r7095 r7216 36 36 virtual void loadParams(const TiXmlElement* root); 37 37 38 void loadModel(const char*fileName, float scaling = 1.0f, unsigned int modelNumber = 0);38 void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0); 39 39 void setModel(Model* model, unsigned int modelNumber = 0); 40 40 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; 41 41 42 inline void loadMD2Texture(const char*fileName) { this->md2TextureFileName = fileName; }42 inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } 43 43 44 44 bool buildObbTree(unsigned int depth); … … 113 113 114 114 std::vector<Model*> models; //!< The model that should be loaded for this entity. 115 const char*md2TextureFileName; //!< the file name of the md2 model texture, only if this116 const char*modelLODName; //!< the name of the model lod file115 std::string md2TextureFileName; //!< the file name of the md2 model texture, only if this 116 std::string modelLODName; //!< the name of the model lod file 117 117 BVTree* obbTree; //!< this is the obb tree reference needed for collision detection 118 118
Note: See TracChangeset
for help on using the changeset viewer.