mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	refactored texture mapping -- can change the texture precision when already active now
This commit is contained in:
		
							
								
								
									
										1
									
								
								hyper.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								hyper.h
									
									
									
									
									
								
							| @@ -2014,6 +2014,7 @@ typedef float GLfloat; | |||||||
| struct textureinfo { | struct textureinfo { | ||||||
|   transmatrix M; |   transmatrix M; | ||||||
|   int texture_id; |   int texture_id; | ||||||
|  |   vector<array<hyperpoint, 3>> triangles; | ||||||
|   vector<GLfloat> vertices; |   vector<GLfloat> vertices; | ||||||
|   vector<GLfloat> tvertices;  |   vector<GLfloat> tvertices;  | ||||||
|   cell *c; |   cell *c; | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								textures.cpp
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								textures.cpp
									
									
									
									
									
								
							| @@ -274,27 +274,29 @@ set<cell*> models; | |||||||
|  |  | ||||||
| void mapTexture(cell *c, textureinfo& mi, patterns::patterninfo &si, const transmatrix& T, int shift = 0) { | void mapTexture(cell *c, textureinfo& mi, patterns::patterninfo &si, const transmatrix& T, int shift = 0) { | ||||||
|   mi.c = c; |   mi.c = c; | ||||||
|   mi.vertices.clear(); |  | ||||||
|   mi.tvertices.clear(); |  | ||||||
|   mi.symmetries = si.symmetries; |   mi.symmetries = si.symmetries; | ||||||
|   mi.current_type = c->type; |   mi.current_type = c->type; | ||||||
|    |    | ||||||
|   mi.M = T * applyPatterndir(c, si); |   mi.M = T * applyPatterndir(c, si); | ||||||
|  |  | ||||||
|   if(tstate == tsAdjusting) return; |  | ||||||
|  |  | ||||||
|   ld z = ctof(c) ? rhexf : hexvdist; |   ld z = ctof(c) ? rhexf : hexvdist; | ||||||
|    |    | ||||||
|   // int sym = si.symmetries; |   mi.triangles.clear(); | ||||||
|  |  | ||||||
|   for(int i=0; i<c->type; i++) { |   for(int i=0; i<c->type; i++) { | ||||||
|     int i2 = i+shift; |     int i2 = i+shift; | ||||||
|     hyperpoint h1 =  spin(M_PI + M_PI * (2*i2 -1) / c->type) * xpush(z) * C0; |     hyperpoint h1 =  spin(M_PI + M_PI * (2*i2 -1) / c->type) * xpush(z) * C0; | ||||||
|     hyperpoint h2 =  spin(M_PI + M_PI * (2*i2 +1) / c->type) * xpush(z) * C0; |     hyperpoint h2 =  spin(M_PI + M_PI * (2*i2 +1) / c->type) * xpush(z) * C0; | ||||||
|     mapTextureTriangle(mi, make_array(C0, h1, h2)); |     mi.triangles.push_back(make_array(C0, h1, h2)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | void mapTexture2(textureinfo& mi) { | ||||||
|  |   mi.vertices.clear(); | ||||||
|  |   mi.tvertices.clear(); | ||||||
|  |   for(auto& t: mi.triangles) | ||||||
|  |     mapTextureTriangle(mi, t); | ||||||
|  |   } | ||||||
|  |    | ||||||
| int recolor(int col) { | int recolor(int col) { | ||||||
|   if(color_alpha == 0) return col; |   if(color_alpha == 0) return col; | ||||||
|   for(int i=1; i<4; i++) |   for(int i=1; i<4; i++) | ||||||
| @@ -402,6 +404,10 @@ void perform_mapping() { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |   if(tstate == tsActive) | ||||||
|  |     for(auto& mi: texture_map) | ||||||
|  |       mapTexture2(mi.second); | ||||||
|  |  | ||||||
|   models.clear(); |   models.clear(); | ||||||
|   for(auto& t: texture_map) models.insert(t.second.c); |   for(auto& t: texture_map) models.insert(t.second.c); | ||||||
|    |    | ||||||
| @@ -908,6 +914,7 @@ void showMenu() { | |||||||
|     dialog::addColorItem(XLAT("grid color"), grid_color, 'g'); |     dialog::addColorItem(XLAT("grid color"), grid_color, 'g'); | ||||||
|     dialog::addColorItem(XLAT("mesh color"), mesh_color, 'm'); |     dialog::addColorItem(XLAT("mesh color"), mesh_color, 'm'); | ||||||
|     dialog::addSelItem(XLAT("color alpha"), its(color_alpha), 'c'); |     dialog::addSelItem(XLAT("color alpha"), its(color_alpha), 'c'); | ||||||
|  |     dialog::addSelItem(XLAT("precision"), its(gsplits), 'P'); | ||||||
|     dialog::addItem(XLAT("edit the texture"), 'e'); |     dialog::addItem(XLAT("edit the texture"), 'e'); | ||||||
|     dialog::addItem(XLAT("save the full texture image"), 'S'); |     dialog::addItem(XLAT("save the full texture image"), 'S'); | ||||||
|     dialog::addItem(XLAT("save texture config"), 's'); |     dialog::addItem(XLAT("save texture config"), 's'); | ||||||
| @@ -1023,10 +1030,13 @@ void showMenu() { | |||||||
|       dialog::editNumber(color_alpha, 0, 255, 15, 0, XLAT("color alpha"), |       dialog::editNumber(color_alpha, 0, 255, 15, 0, XLAT("color alpha"), | ||||||
|         XLAT("The higher the value, the less important the color of underlying terrain is.")); |         XLAT("The higher the value, the less important the color of underlying terrain is.")); | ||||||
|       }     |       }     | ||||||
|     else if(uni == 'P' && tstate <= tsAdjusting) { |     else if(uni == 'P') { | ||||||
|       dialog::editNumber(gsplits, 0, 4, 1, 1, XLAT("precision"), |       dialog::editNumber(gsplits, 0, 4, 1, 1, XLAT("precision"), | ||||||
|         XLAT("precision")); |         XLAT("precision")); | ||||||
|       dialog::reaction = perform_mapping; |       if(tstate == tsActive) dialog::reaction = [] () { | ||||||
|  |           for(auto& mi: texture_map) | ||||||
|  |             mapTexture2(mi.second); | ||||||
|  |         }; | ||||||
|       } |       } | ||||||
|     else if(uni == 'S' && tstate == tsAdjusting)  |     else if(uni == 'S' && tstate == tsAdjusting)  | ||||||
|       dialog::openFileDialog(texturename, XLAT("save the raw texture"), ".png",  |       dialog::openFileDialog(texturename, XLAT("save the raw texture"), ".png",  | ||||||
| @@ -1250,6 +1260,7 @@ void remap(eTextureState old_tstate, eTextureState old_tstate_max) { | |||||||
|         auto& mi2 = texture_map[si.id]; |         auto& mi2 = texture_map[si.id]; | ||||||
|         mi2 = mi; |         mi2 = mi; | ||||||
|         mapTexture(c, mi2, si, Id, pshift); |         mapTexture(c, mi2, si, Id, pshift); | ||||||
|  |         mapTexture2(mi2); | ||||||
|         mi2.tvertices = move(new_tvertices); |         mi2.tvertices = move(new_tvertices); | ||||||
|         } |         } | ||||||
|       catch(out_of_range) {  |       catch(out_of_range) {  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue