mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	embedding:: a simple general implementation of radar
This commit is contained in:
		| @@ -51,6 +51,7 @@ struct display_data { | ||||
|   vector<radarpoint> radarpoints; | ||||
|   vector<radarline> radarlines; | ||||
|   transmatrix radar_transform; | ||||
|   transmatrix radar_transform_post; | ||||
|  | ||||
|   ld eyewidth(); | ||||
|   bool stereo_active(); | ||||
|   | ||||
| @@ -83,7 +83,7 @@ EX bool mouseout2() { | ||||
| EX movedir vectodir(hyperpoint P) { | ||||
|  | ||||
|   transmatrix U = unshift(ggmatrix(cwt.at)); | ||||
|   if(embedded_plane && cgi.emb->is_same_in_same())  U = current_display->radar_transform * U; | ||||
|   if(embedded_plane && cgi.emb->is_same_in_same())  U = current_display->radar_transform_post * current_display->radar_transform * U; | ||||
|  | ||||
|   P = direct_exp(lp_iapply(P)); | ||||
|  | ||||
|   | ||||
| @@ -229,7 +229,7 @@ EX } | ||||
|     virtual transmatrix actual_to_base(const transmatrix &T) = 0; | ||||
|     virtual hyperpoint normalize_flat(hyperpoint a) { return flatten(normalize(a)); } | ||||
|     virtual hyperpoint flatten(hyperpoint a); | ||||
|     virtual transmatrix get_radar_transform(const transmatrix& V); | ||||
|     virtual void set_radar_transform(); | ||||
|     virtual transmatrix get_lsti() { return Id; } | ||||
|     virtual transmatrix get_lti() { return logical_scaled_to_intermediate; } | ||||
|     virtual hyperpoint base_to_logical(hyperpoint h) = 0; | ||||
| @@ -947,55 +947,17 @@ EX const transmatrix& lmirror() { | ||||
|   return Mirror; | ||||
|   } | ||||
|  | ||||
| transmatrix embedding_method::get_radar_transform(const transmatrix& V) { | ||||
|   if(cgi.emb->is_euc_in_sl2()) { | ||||
|     return inverse(actual_view_transform * V); | ||||
|     } | ||||
|   else if(nonisotropic) { | ||||
|     transmatrix T = actual_view_transform * V; | ||||
|     ld z = -tC0(view_inverse(T)) [2]; | ||||
|     transmatrix R = actual_view_transform; | ||||
|     R = logical_scaled_to_intermediate * R; | ||||
|     if(R[1][2] || R[2][2]) | ||||
|       R = cspin(1, 2, -atan2(R[1][2], R[2][2])) * R; | ||||
|     if(R[0][2] || R[2][2]) | ||||
|       R = cspin(0, 2, -atan2(R[0][2], R[2][2])) * R; | ||||
|     if(is_hyp_in_solnih()) R = Id; | ||||
|     R = intermediate_to_logical_scaled * R; | ||||
|     return inverse(R) * zpush(-z); | ||||
|     } | ||||
|   else if(gproduct) { | ||||
|     transmatrix T = V; | ||||
|     ld z = zlevel(tC0(inverse(T))); | ||||
|  | ||||
|     transmatrix R = NLP; | ||||
|     if(R[1][2] || R[2][2]) | ||||
|       R = cspin(1, 2, -atan2(R[1][2], R[2][2])) * R; | ||||
|     if(R[0][2] || R[2][2]) | ||||
|       R = cspin(0, 2, -atan2(R[0][2], R[2][2])) * R; | ||||
|  | ||||
|     return R * zpush(z); | ||||
|     } | ||||
|   else if(is_euc_in_sph()) { | ||||
|     return inverse(V); | ||||
|     } | ||||
|   else if(is_cylinder()) { | ||||
|     return inverse(V); | ||||
|     } | ||||
|   else { | ||||
|     transmatrix T = actual_view_transform * V; | ||||
|     transmatrix U = view_inverse(T); | ||||
|  | ||||
|     if(T[0][2] || T[1][2]) | ||||
|       T = spin(-atan2(T[0][2], T[1][2])) * T; | ||||
|     if(T[1][2] || T[2][2]) | ||||
|       T = cspin(1, 2, -atan2(T[1][2], T[2][2])) * T; | ||||
|  | ||||
|     ld z = -asin_auto(tC0(view_inverse(T)) [2]); | ||||
|     T = zpush(-z) * T; | ||||
|  | ||||
|     return T * U; | ||||
|     } | ||||
| void embedding_method::set_radar_transform() { | ||||
|   auto& rt = current_display->radar_transform; | ||||
|   auto& rtp = current_display->radar_transform_post; | ||||
|   if(!embedded_plane) { rt = rtp = Id; return; } | ||||
|   transmatrix U = actual_view_transform * View; | ||||
|   auto a = inverse(U) * C0; | ||||
|   auto l = actual_to_intermediate(a); | ||||
|   l[2] = 0; | ||||
|   rt = inverse(intermediate_to_actual_translation(l)) * inverse(U); | ||||
|   transmatrix T = intermediate_to_logical * View * intermediate_to_actual_translation(l); | ||||
|   rtp = cspin(0, 1, atan2(T[0][1], T[0][0])); | ||||
|   } | ||||
|  | ||||
| EX void swapmatrix(transmatrix& T) { | ||||
|   | ||||
| @@ -5066,9 +5066,7 @@ EX void make_actual_view() { | ||||
|     nisot::local_perspective_used = true; | ||||
|     } | ||||
|   #endif | ||||
|   #if MAXMDIM >= 4 | ||||
|   if(embedded_plane) current_display->radar_transform = cgi.emb->get_radar_transform(View); | ||||
|   #endif | ||||
|   cgi.emb->set_radar_transform(); | ||||
|   Viewbase = View; | ||||
|   } | ||||
|  | ||||
|   | ||||
							
								
								
									
										71
									
								
								radar.cpp
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								radar.cpp
									
									
									
									
									
								
							| @@ -27,75 +27,20 @@ pair<bool, hyperpoint> makeradar(shiftpoint h) { | ||||
|     if(d >= vid.radarrange) return {false, h1}; | ||||
|     if(d) h1 = h1 * (d / vid.radarrange / hypot_d(3, h1)); | ||||
|     } | ||||
|   else if(mhyperbolic) { | ||||
|     if(cgi.emb->is_hyp_in_solnih()) { | ||||
|       geom3::light_flip(true); | ||||
|       h1 = parabolic1(h1[1]) * xpush0(h1[0]); | ||||
|       geom3::light_flip(false); | ||||
|       h1[3] = h1[2]; h1[2] = 0; | ||||
|       // h1 = current_display->radar_transform * h1; | ||||
|       } | ||||
|   else { | ||||
|     h1 = cgi.emb->actual_to_base(h.h); | ||||
|     h1 = current_display->radar_transform_post * h1; | ||||
|     if(mhyperbolic) { | ||||
|       h1[LDIM] = h1[2]; h1[2] = 0; | ||||
|       for(int a=0; a<LDIM; a++) h1[a] = h1[a] / (1 + h1[LDIM]); | ||||
|       h1[3] *= 2; | ||||
|       } | ||||
|   else if(msphere) { | ||||
|     if(cgi.emb->is_same_in_same()) h1[2] = h1[LDIM]; | ||||
|     if(hyperbolic) h1 /= sinh(1); | ||||
|     } | ||||
|   else { | ||||
|     if(cgi.emb->is_euc_in_hyp()) { | ||||
|       for(int a=0; a<3; a++) h1[a] = h1[a] / (1 + h1[3]); | ||||
|       h1[2] -= 1; | ||||
|       h1 *= 2 / sqhypot_d(3, h1); | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     else if(cgi.emb->is_same_in_same()) { | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 * (d / (vid.radarrange + cgi.scalefactor/4) / hypot_d(3, h1)); | ||||
|       } | ||||
|     else if(cgi.emb->is_euc_in_sph()) { | ||||
|       h1[0] = atan2(h.h[0], h.h[2]); | ||||
|       h1[1] = atan2(h.h[1], h.h[3]); | ||||
|       h1[2] = 0; | ||||
|       h1 = cgi.emb->intermediate_to_logical * h1; | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     else if(cgi.emb->is_cylinder()) { | ||||
|       h1[0] = h.h[0]; | ||||
|       h1[1] = atan2(h.h[1], h.h[2]); | ||||
|       h1[2] = 0; | ||||
|       h1 = cgi.emb->intermediate_to_logical * h1; | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     else if(cgi.emb->is_euc_in_sl2()) { | ||||
|       h1 = cgi.emb->intermediate_to_logical * cgi.emb->actual_to_intermediate(unshift(h)); h1[1] = -h1[1]; | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     else if(cgi.emb->is_euc_in_product()) { | ||||
|       if(in_h2xe()) | ||||
|         h1[0] = atanh(h.h[0] / h.h[2]); | ||||
|       else | ||||
|         h1[0] = atan2(h.h[2], h.h[0]); | ||||
|       h1[2] = - zlevel(h.h) - h.shift; | ||||
|       h1[1] = 0; | ||||
|       h1[3] = 0; | ||||
|       h1 = cgi.emb->intermediate_to_logical * h1; | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     else { | ||||
|     if(meuclid) { | ||||
|       d = hypot_d(2, h1); | ||||
|       if(d > vid.radarrange) return {false, h1}; | ||||
|       if(d) h1 = h1 / (vid.radarrange + cgi.scalefactor/4); | ||||
|       } | ||||
|     /* no change for sphere! */ | ||||
|     } | ||||
|   if(invalid_point(h1)) return {false, h1}; | ||||
|   return {true, h1}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue