Changeset 3390 in orxonox.OLD for orxonox/branches/nico
- Timestamp:
- Feb 2, 2005, 1:04:00 PM (20 years ago)
- Location:
- orxonox/branches/nico/src/importer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/nico/src/importer/Makefile.am
r3384 r3390 12 12 material.cc \ 13 13 vector.cc 14 14 15 heightmap_SOURCES= main.cc \ 15 16 heightMapTerrain.cc \ 16 heightMapViewer.cc 17 heightMapViewer.cc \ 18 vector.cc \ 19 windowHandler.cc 17 20 18 21 noinst_HEADERS= framework.h \ -
orxonox/branches/nico/src/importer/Makefile.in
r3384 r3390 54 54 PROGRAMS = $(bin_PROGRAMS) 55 55 am_heightmap_OBJECTS = main.$(OBJEXT) heightMapTerrain.$(OBJEXT) \ 56 heightMapViewer.$(OBJEXT) 56 heightMapViewer.$(OBJEXT) vector.$(OBJEXT) \ 57 windowHandler.$(OBJEXT) 57 58 heightmap_OBJECTS = $(am_heightmap_OBJECTS) 58 59 heightmap_LDADD = $(LDADD) … … 134 135 SHELL = @SHELL@ 135 136 STRIP = @STRIP@ 137 SUB_PROJECTS_FALSE = @SUB_PROJECTS_FALSE@ 138 SUB_PROJECTS_TRUE = @SUB_PROJECTS_TRUE@ 136 139 VERSION = @VERSION@ 137 140 ac_ct_CC = @ac_ct_CC@ … … 189 192 heightmap_SOURCES = main.cc \ 190 193 heightMapTerrain.cc \ 191 heightMapViewer.cc 194 heightMapViewer.cc \ 195 vector.cc \ 196 windowHandler.cc 192 197 193 198 noinst_HEADERS = framework.h \ … … 210 215 esac; \ 211 216 done; \ 212 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/importer/Makefile'; \217 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/importer/Makefile'; \ 213 218 cd $(top_srcdir) && \ 214 $(AUTOMAKE) -- foreignsrc/importer/Makefile219 $(AUTOMAKE) --gnu src/importer/Makefile 215 220 .PRECIOUS: Makefile 216 221 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status -
orxonox/branches/nico/src/importer/heightMapTerrain.cc
r3384 r3390 27 27 if (bitmap == NULL) return false; 28 28 29 cout << "bitmap-dimensions: " << bitmap->w << "x" << bitmap->h << endl; 30 29 cout << "bitmap-dimensions: " << bitmap->w << " x " << bitmap->h << endl; 30 cout << "bitmap-pitch: " << bitmap->pitch << endl; 31 cout << "bitmap->format->BytesPerPixel: " << (int)bitmap->format->BytesPerPixel << endl; 32 cout << "bitmap->format->BitsPerPixel: " << (int)bitmap->format->BitsPerPixel << endl; 33 31 34 if (bitmap->w % width != 0) return false; 32 35 if (bitmap->h % height != 0) return false; … … 48 51 return false; 49 52 } 53 54 cout << displayListCount << " display lists generated. starting at: " << displayListStart << endl; 55 50 56 51 57 int i,j; … … 69 75 bool HeightMapTerrain::readIntoList(int left, int top, int width, int height, int levelOfDetail, GLuint displayListNr) 70 76 { 71 // y is the height value in OpenGL convention72 GLuint x,y,z;73 GLfloat col;74 75 77 cout << "creating list Nr " << displayListNr << endl; 76 78 cout << "left, top, width, height: " << left << ", " << top << ", " << width << ", " << height << endl; 77 79 78 glNewList(displayListNr,GL_COMPILE); 79 { 80 for (z=top; z<top+height; z++) 80 // y is the height value in OpenGL convention 81 int x,y,z; 82 GLfloat col; 83 84 // used for normal calculations 85 Vector O; // origin: the vertex where i'm standing 86 Vector N,E,S,W,NE,SE,SW,NW; // vectors pointing to north, east, ... 87 88 bool eightTriangles = false; 89 90 91 // contains a normal vector for every vertex 92 normals = new Vector[width*height]; 93 94 // precalculate all vertex normals for later use in display list generation 95 // many superflous calculations i know... 96 for (z=top; z<top+height; z++) 97 { 98 for (x=left; x<left+width; x++) 81 99 { 82 glBegin(GL_QUAD_STRIP); 100 O = Vector(x,getHeightValue(x,z),z); 101 102 N = Vector(x,getHeightValue(x,z-1),z-1) - O; 103 E = Vector(x+1,getHeightValue(x+1,z),z) - O; 104 S = Vector(x,getHeightValue(x,z+1),z+1) - O; 105 W = Vector(x-1,getHeightValue(x-1,z),z) - O; 106 107 if (eightTriangles == false) 108 // calculate the average normal vector by adding up all 4 adjacent triangle normal vectors 109 normals[(z-top) * height + (x-left)] = N.cross(W) + W.cross(S) + S.cross(E); 110 111 else 83 112 { 84 for (x=left; x<left+width; x++) 113 NE = Vector(x+1,getHeightValue(x+1,z-1),z-1) - O; 114 SE = Vector(x+1,getHeightValue(x+1,z+1),z+1) - O; 115 SW = Vector(x-1,getHeightValue(x-1,z+1),z+1) - O; 116 NW = Vector(x-1,getHeightValue(x-1,z-1),z-1) - O; 117 // calculate the average normal vector by adding up all 8 adjacent triangle normal vectors 118 normals[(z-top) * height + (x-left)] = N.cross(NW) + NW.cross(W) + W.cross(SW) + SW.cross(S) + S.cross(SE) + SE.cross(E) + E.cross(NE) + NE.cross(N); 119 } 120 121 // every second vertex is the edge of eightTriangles (the others have only four triangles) 122 eightTriangles = !eightTriangles; 123 } 124 } 125 126 cout << "normals precalculated for list " << displayListNr << endl; 127 128 glNewList(displayListStart + displayListNr,GL_COMPILE); 129 { 130 glBegin(GL_TRIANGLES); 131 { 132 // don't go through last col and row, because they are already done by second last col&row 133 for (z = top; z < (top + height) - 1; z++) 134 { 135 for (x = left; x < (left + width) - 1; x++) 85 136 { 86 y = heightValue(x,z+1); 87 col = y / 256.0; 88 glColor3f(1.0,0.0,0.0); 89 glVertex3i(x,y,z+1); 90 91 y = heightValue(x,z); 92 col = y / 256.0; 93 glColor3f(1.0,0.0,0.0); 94 glVertex3i(x,y,z); 137 // draw 2 triangles per (x,z) pair 138 139 if (eightTriangles) 140 { 141 call_glNormal_and_glVertex(x,z,top,left,height); 142 call_glNormal_and_glVertex(x,z+1,top,left,height); 143 call_glNormal_and_glVertex(x+1,z,top,left,height); 144 145 call_glNormal_and_glVertex(x+1,z,top,left,height); 146 call_glNormal_and_glVertex(x,z+1,top,left,height); 147 call_glNormal_and_glVertex(x+1,z+1,top,left,height); 148 } 149 150 else 151 { 152 call_glNormal_and_glVertex(x,z,top,left,height); 153 call_glNormal_and_glVertex(x,z+1,top,left,height); 154 call_glNormal_and_glVertex(x+1,z+1,top,left,height); 155 156 call_glNormal_and_glVertex(x+1,z,top,left,height); 157 call_glNormal_and_glVertex(x,z,top,left,height); 158 call_glNormal_and_glVertex(x+1,z+1,top,left,height); 159 } 160 161 162 // use the same trick to change the triangles everytime. once |/| and once |\| 163 eightTriangles = !eightTriangles; 164 95 165 } 96 166 } 97 glEnd();98 167 } 99 168 glEnd(); 169 100 170 } 101 171 glEndList(); 172 173 174 delete[] normals; 102 175 103 176 return true; 104 177 } 105 178 106 GLint HeightMapTerrain::heightValue(Uint8 x, Uint8 z) 107 { 108 return 100; 179 180 void HeightMapTerrain::call_glNormal_and_glVertex(int x,int z,int top,int left,int height) 181 { 182 /* 183 GLfloat color[4]; // color parameter for glMaterial 184 185 int heightVal = getHeightValue(x,z); 186 187 color[0] = 1.0 / 256.0 * heightVal; 188 color[1] = 1.0 / 256.0 * heightVal; 189 color[2] = 1.0 / 256.0 * heightVal; 190 color[3] = 1; // alpha channel (1 = solid) 191 192 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); 193 */ 194 glNormal3f(normals[(z-top) * height + (x-left)].x,normals[(z-top) * height + (x-left)].y,normals[(z-top) * height + (x-left)].z); 195 glVertex3i(x,getHeightValue(x,z),z); 196 } 197 198 199 GLint HeightMapTerrain::getHeightValue(int x, int z) 200 { 201 if (bitmap == NULL) return 0; 202 203 // catch out of image access 204 int X = x % bitmap->w; 205 int Z = z % bitmap->h; 109 206 110 207 /* 111 if (bitmap == NULL) return 0; 208 if (X != x) cout << "x lies outside of image (" << x << "," << z << ")" << endl; 209 if (Z != z) cout << "z lies outside of image (" << x << "," << z << ")" << endl; 210 */ 211 212 // if x or z exeed the image size, return 0 as height value 213 if (X != x || Z != z) return 0; 214 112 215 113 216 Uint8 index; 114 SDL_Color* color = NULL; 115 217 SDL_Color color; 116 218 117 219 SDL_LockSurface(bitmap); 118 119 index = *((Uint8*)bitmap->pixels [z * bitmap->h + x]);120 color = &bitmap->format->palette->colors[index];121 220 221 index = *((Uint8*)bitmap->pixels + Z * bitmap->pitch + X * bitmap->format->BytesPerPixel); 222 color = bitmap->format->palette->colors[index]; 223 122 224 SDL_UnlockSurface(bitmap); 123 124 return color->r;125 */126 } 225 226 // return the red component, because in a grayscale pic, r,g and b are all the same value 227 return (GLint)color.r; 228 } -
orxonox/branches/nico/src/importer/heightMapTerrain.h
r3384 r3390 11 11 using namespace std; 12 12 13 #include "vector.h" 13 14 #include "../stdincl.h" 14 15 #include "vector.h"16 17 15 18 16 class HeightMapTerrain … … 35 33 36 34 // array of display lists 37 GLuint* displayLists;35 //GLuint* displayLists; 38 36 39 37 private: 40 38 // returns the height value between 0 and 256 for a point (x,z) in the picture 41 GLint heightValue(Uint8 x, Uint8 z); 42 39 GLint getHeightValue(int x, int z); 40 41 // makes a call to glNormal and glVertex for supplied x and z 42 void call_glNormal_and_glVertex(int x,int z,int top,int left,int height); 43 43 44 // holds the loaded pixels 44 45 SDL_Surface* bitmap; 45 46 47 // holds normal vector for every vertex 48 Vector* normals; 49 }; 46 50 47 48 }; 51 -
orxonox/branches/nico/src/importer/heightMapViewer.cc
r3384 r3390 21 21 22 22 upVector = Vector(0,1,0); 23 23 24 24 wireframe = false; 25 25 mousedown = false; 26 smoothShading = false; 26 27 27 28 } … … 38 39 cout << "HeightMapViewer init()" << endl; 39 40 40 if (windowhandler.createOpenGLWindow(WIDTH,HEIGHT,FULLSCREEN) == false) 41 #ifdef FULLSCREEN 42 if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, true)) 43 #else 44 if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, false)) 45 #endif 41 46 { 42 47 cout << "could not create OpenGL-Window." << endl; … … 46 51 if (terrain.loadBitmap(fileName) == false) 47 52 { 48 cout << "could not create OpenGL-Window." << endl;53 cout << "could not load bitmap." << endl; 49 54 return false; 50 55 } 51 56 52 terrain.createDisplayLists( 64, 64, 1);57 terrain.createDisplayLists(128, 128, 1); 53 58 54 59 return true; … … 73 78 { 74 79 case SDL_MOUSEMOTION: 75 if (mousedown)80 if (mousedown==true) 76 81 { 77 angleX = PI / 180 * event.motion.xrel * 0. 1;78 angleY = PI / 180 * event.motion.yrel * 0. 1;82 angleX = PI / 180 * event.motion.xrel * 0.2; 83 angleY = PI / 180 * event.motion.yrel * 0.2; 79 84 80 85 // Quaternion(angle,axis) 81 rotator = Quaternion( angleX,Vector(0,1,0));86 rotator = Quaternion(-angleX,Vector(0,1,0)); 82 87 sightDirection = rotator.apply(sightDirection); 88 89 #ifdef FULLSCREEN 90 rotator = Quaternion(angleY,perpendicular(sightDirection)); 91 #else 92 rotator = Quaternion(-angleY,perpendicular(sightDirection)); 93 #endif 83 94 84 rotator = Quaternion(-angleY,sightDirection.perpendicular());85 95 sightDirection = rotator.apply(sightDirection); 86 96 … … 99 109 switch(event.key.keysym.sym) 100 110 { 111 case SDLK_UP: 112 // move in direction of sight 113 cameraPos = cameraPos + sightDirection * 0.7; 114 updateView(); 115 break; 116 117 case SDLK_DOWN: 118 // move in direction of sight 119 cameraPos = cameraPos - sightDirection * 0.7; 120 updateView(); 121 break; 122 123 case SDLK_LEFT: 124 cameraPos = cameraPos + perpendicular(sightDirection) * 0.7; 125 updateView(); 126 break; 127 128 case SDLK_RIGHT: 129 cameraPos = cameraPos - perpendicular(sightDirection) * 0.7; 130 updateView(); 131 break; 132 133 case SDLK_s: 134 smoothShading = !smoothShading; 135 if (smoothShading) glShadeModel(GL_SMOOTH); 136 else glShadeModel(GL_FLAT); 137 break; 138 101 139 case SDLK_w: 102 140 wireframe = !wireframe; … … 105 143 break; 106 144 107 case SDLK_UP:108 // move in direction of sight109 cameraPos = cameraPos + sightDirection;110 updateView();111 break;112 113 case SDLK_DOWN:114 // move in direction of sight115 cameraPos = cameraPos - sightDirection;116 updateView();117 break;118 119 case SDLK_LEFT:120 cameraPos = cameraPos - sightDirection.perpendicular();121 updateView();122 break;123 124 case SDLK_RIGHT:125 cameraPos = cameraPos + sightDirection.perpendicular();126 updateView();127 break;128 129 145 case SDLK_r: 130 // restore original view vectors 131 cameraPos = Vector(0,0,40); 132 sightDirection = Vector(0,0,-1); 146 // reset view vectors 147 //cameraPos = Vector(0,0,40); 148 //sightDirection = Vector(0,0,-1); 149 cameraPos = Vector(73.9871,172.496,286.137); 150 sightDirection = Vector(0.23429,-0.736527,-0.625574); 151 133 152 updateView(); 134 153 break; … … 138 157 << "display list count: " << terrain.displayListCount << endl 139 158 << "first display list at: " << terrain.displayListStart << endl 159 << "camera position: " << "(" << cameraPos.x << "," << cameraPos.y << "," << cameraPos.z << ")" << endl 160 << "sightDirection: " << "(" << sightDirection.x << "," << sightDirection.y << "," << sightDirection.z << ")" << endl 140 161 << endl; 141 162 … … 165 186 SDL_GL_SwapBuffers(); 166 187 167 //SDL_Delay(100);188 SDL_Delay(1); 168 189 } 169 190 … … 175 196 // be sure to use up to date lookAt-vector 176 197 lookAt = cameraPos + sightDirection; 177 upVector = sightDirection.cross( sightDirection.perpendicular()) * -1;198 upVector = sightDirection.cross(perpendicular(sightDirection)); 178 199 179 200 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix … … 181 202 182 203 // Calculate The Aspect Ratio Of The Window 183 gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0. 1f,100.0f);204 gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.5f,300.0f); 184 205 gluLookAt (cameraPos.x,cameraPos.y,cameraPos.z, 185 206 lookAt.x,lookAt.y,lookAt.z, … … 191 212 192 213 void HeightMapViewer::drawScene() 193 { 214 { 194 215 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 195 216 196 glutWireCube(1.0); 197 198 int i; 199 200 for (i=0; i<terrain.displayListCount; i++) 201 { 202 glCallList(terrain.displayListStart + i); 203 } 204 } 217 glPushMatrix(); 218 { 219 //glTranslatef(0.0,1.0,0.0); 220 glScalef(1,0.2,1); 221 222 for (int i=0; i<terrain.displayListCount; i++) 223 { 224 glCallList(terrain.displayListStart + i); 225 } 226 } 227 glPopMatrix(); 228 229 glColor3f(0.0,1.0,0.0); 230 // glutWireCube(1.0); 231 232 glColor3f(0.0,0.0,1.0); 233 glBegin(GL_POINTS); 234 for (float z=0;z<10;z++) 235 for (float x=0;x<10;x++) 236 glVertex3f(x,0,z); 237 glEnd(); 238 239 } 240 241 242 243 /** 244 \brief returns a vector that is perpendicular and lies in the xz-plane 245 */ 246 Vector perpendicular (Vector perpendic) 247 { 248 Vector r; 249 250 r.x = perpendic.z; 251 r.z = -perpendic.x; 252 253 r.normalize(); 254 255 return r; 256 } -
orxonox/branches/nico/src/importer/heightMapViewer.h
r3384 r3390 18 18 #include "../stdincl.h" 19 19 20 20 21 #define WIDTH 640 21 22 #define HEIGHT 480 22 #define FULLSCREEN false23 23 24 /* 25 #define WIDTH 1280 26 #define HEIGHT 854 27 #define FULLSCREEN true 28 */ 24 //#define WIDTH 1280 25 //#define HEIGHT 854 26 //#define FULLSCREEN 27 29 28 30 29 class HeightMapViewer … … 46 45 bool wireframe; 47 46 bool mousedown; 47 bool smoothShading; 48 48 49 49 Vector cameraPos; … … 56 56 Quaternion rotator; 57 57 }; 58 59 Vector perpendicular (Vector perpendic);
Note: See TracChangeset
for help on using the changeset viewer.