./vdo_triangle_select.lua

  1.  
  2. local SIN_60 = 0.866 
  3. local CENTER_TO_CORNER = 0.58 
  4.  
  5. --Math Functions for Triangle Select 
  6. local function cap(val, min_val, max_val) 
  7. 	if val < min_val then 
  8. 		return min_val 
  9. 	elseif val > max_val then 
  10. 		return max_val 
  11. 	end 
  12. 	 
  13. 	return val 
  14. end 
  15.  
  16. -- calculate the magnitude of a line 
  17. local function magnitude(startx,starty,endx,endy) 
  18.  
  19. 	local x = endx - startx 
  20. 	local y = endy - starty 
  21.  
  22.     return sqrt( x * x + y * y ) 
  23. end 
  24.  
  25. -- Inherited from Vdo_base_object 
  26. Vdo_triangle_select = Vdo_base_object:new_base() 
  27.  
  28. local TRIANGLE_NW_X = 32 
  29. local TRIANGLE_NW_Y = 32 
  30. local TRIANGLE_SIDE = 235 
  31.  
  32. local Min_x = 0 
  33. local Min_y = 0 
  34. local Max_x = TRIANGLE_SIDE 
  35.  
  36. -- height of triangle 
  37. local Max_y = TRIANGLE_SIDE * SIN_60 
  38.  
  39. local Fat_txt 
  40. local Skinny_txt 
  41. local Strength_txt 
  42.  
  43. local Cursor 
  44.  
  45.  
  46. local function update_percent_fields(fat, skinny, strength) 
  47. 	-- update % displays	 
  48. 	local body 
  49. 	local insert_values = { [0] = fat } 
  50. 	body = vint_insert_values_in_string("STORE_FAT", insert_values) 
  51. 	Fat_txt:set_text(body) 
  52. 	 
  53. 	insert_values = { [0] = skinny } 
  54. 	body = vint_insert_values_in_string("STORE_SKINNY", insert_values) 
  55. 	Skinny_txt:set_text(body) 
  56. 	 
  57. 	insert_values = { [0] = strength } 
  58. 	body = vint_insert_values_in_string("STORE_STRENGTH", insert_values) 
  59. 	Strength_txt:set_text(body)	 
  60. end 
  61.  
  62. function Vdo_triangle_select:init() 
  63.  
  64. 	self.btn_select = Vdo_button_toggle:new("btn_select", self.handle, self.doc_handle) 
  65. 	self.btn_highlight = Vdo_button_highlight:new("btn_highlight", self.handle, self.doc_handle) 
  66. 	 
  67. 	self.btn_highlight:show_button(CTRL_MENU_BUTTON_A) 
  68. 	 
  69. 	self.btn_select:set_label("STORE_SELECT_BUILD") 
  70. 	 
  71. 	self.tri_color_grp = Vdo_base_object:new("tri_color_grp", self.handle, self.doc_handle) 
  72. 	self.tri_color_grp:set_visible(false) 
  73. 	 
  74. 	self.btn_select:set_highlight(true) 
  75. 	self.btn_highlight:set_highlight(true) 
  76.  
  77. 	self.pulse_anim = Vdo_anim_object:new("stick_pulse_anim", self.handle, self.doc_handle) 
  78. 	self.pulse_anim:unpause() 
  79. 	 
  80. 	-- Temp: bitmap doesn't line up with triangle edges 
  81. 	-- TRIANGLE_NW_X, TRIANGLE_NW_Y = triangle_h:get_anchor() 
  82. 	 
  83. 	--Get Cursor Handle 
  84. 	Cursor = Vdo_base_object:new("cursor", self.handle, self.doc_handle) 
  85. 	 
  86. 	local triangle_bmp = Vdo_base_object:new("triangle_base", self.handle, self.doc_handle) 
  87. 	triangle_bmp:set_image("ui_menu_pcr_tri") 
  88. 	 
  89. 	--Modify Stick Graphic depending on system 
  90. 	local cursor_bmp = Vdo_base_object:new("stick_bitmap",  Cursor.handle, Cursor.doc_handle) 
  91. 	local cursor_txt = Vdo_base_object:new("stick_text",  Cursor.handle, Cursor.doc_handle) 
  92. 	self.glow_bmp = Vdo_base_object:new("glow",  Cursor.handle, Cursor.doc_handle) 
  93. 	 
  94. 	if game_get_platform() == "PS3" then  
  95. 		cursor_bmp:set_image("ui_hud_combo_thumb_ps3")  
  96. 		cursor_txt:set_text("L") 
  97. 	elseif (game_get_platform() == "PC") then  
  98. 		cursor_bmp:set_image("ui_pc_body_select_circle")  
  99. 		cursor_txt:set_visible(false) 
  100. 	else 
  101. 		cursor_bmp:set_image("ui_hud_combo_thumb") 
  102. 		cursor_txt:set_text("LS") 
  103. 	end 
  104. 	 
  105. 	--Uncomment these for more accurate cursor 
  106. 	--cursor_bmp:set_visible(false) 
  107. 	--cursor_txt:set_visible(false) 
  108. 	--self.glow_bmp:set_visible(false) 
  109. 	 
  110. 	-- start in the middle of the triangle - need to update based on current settings 
  111. 	Cursor:set_anchor(TRIANGLE_NW_X + Max_x / 2, TRIANGLE_NW_Y + TRIANGLE_SIDE * CENTER_TO_CORNER) 
  112. 	 
  113. 	Fat_txt = Vdo_base_object:new("fat_txt", self.handle, self.doc_handle) 
  114. 	Skinny_txt = Vdo_base_object:new("skinny_txt", self.handle, self.doc_handle) 
  115. 	Strength_txt = Vdo_base_object:new("strength_txt", self.handle, self.doc_handle) 
  116. 	 
  117. 	update_percent_fields(0, 0, 0) 
  118. end 
  119.  
  120. function	Vdo_triangle_select:init_morphs(str, skin, fat, x, y) 
  121.  
  122. 	-- leave cursor in middle for never initialized position 
  123. 	if x >= 0 and y >= 0 then 
  124. 		Cursor:set_anchor(x,y) 
  125. 	else 
  126. 		Cursor:set_anchor(TRIANGLE_NW_X + Max_x / 2, TRIANGLE_NW_Y + TRIANGLE_SIDE * CENTER_TO_CORNER) 
  127. 	end 
  128.  
  129. 	-- update % displays	 
  130. 	update_percent_fields(floor(fat * 100 + 0.5), floor(skin * 100 + 0.5), floor(str * 100 + 0.5))	 
  131. end 
  132.  
  133. -- Move the left stick by the given magnitudes 
  134. function Vdo_triangle_select:move_left_stick(mag_x, mag_y) 
  135.  
  136. 	local cursor_x, cursor_y = Cursor:get_anchor() 
  137. 	 
  138. 	local new_x = cursor_x + mag_x 
  139. 	local new_y = cursor_y - mag_y	 
  140. 	 
  141. 	-- convert from screen position  
  142. 	local rel_x = new_x - TRIANGLE_NW_X 
  143. 	local rel_y = new_y - TRIANGLE_NW_Y 
  144. 	 
  145. 	local ax = 0 
  146. 	local ay = Max_y 
  147. 	local bx = (Max_x / 2) 
  148. 	local by = 0 
  149. 	local cx = Max_x 
  150. 	local cy = ay 
  151. 	 
  152. 	-- Check the location of the mouse cursor against each side of the triangle 
  153. 	-- If the point is "inside," it is to the right or on the line 
  154. 	local point_inside_left = false 
  155. 	local point_inside_right = false 
  156. 	local point_inside_bottom = false 
  157. 	if which_side_of_2d_line(rel_x, rel_y, ax, ay, bx, by) >= 0 then 
  158. 		point_inside_left = true 
  159. 	end 
  160. 	 
  161. 	if which_side_of_2d_line(rel_x, rel_y, bx, by, cx, cy) >= 0 then 
  162. 		point_inside_right = true 
  163. 	end 
  164. 	 
  165. 	if which_side_of_2d_line(rel_x, rel_y, cx, cy, ax, ay) >= 0 then 
  166. 		point_inside_bottom = true 
  167. 	end 
  168. 	 
  169. 	local new_x, new_y 
  170. 	--local rel_x, rel_y 
  171. 	if point_inside_left and point_inside_right and point_inside_bottom then 
  172. 		-- If the point is inside the triangle, then done 
  173. 	else 
  174. 		-- If the point is not on the inside of the triangle, find the closest point on the 
  175. 		-- line that the point is not on the inside of. 
  176. 		 
  177. 		if not point_inside_left then 
  178. 			rel_x, rel_y= closest_point_on_line_segment(rel_x, rel_y, ax, ay, bx, by) 
  179. 		end 
  180. 		 
  181. 		if not point_inside_right then 
  182. 			rel_x, rel_y = closest_point_on_line_segment(rel_x, rel_y, bx, by, cx, cy) 
  183. 		end 
  184. 		 
  185. 		if not point_inside_bottom then 
  186. 			rel_x, rel_y = closest_point_on_line_segment(rel_x, rel_y, cx, cy, ax, ay) 
  187. 		end 
  188. 	end	 
  189. 	 
  190. 	-- convert from screen coord (top is lower y value) to Cartesian for my sanity 
  191. 	rel_y = Max_y - rel_y 
  192. 	 
  193. 	-- Get percentages for display, and to update the morph. 
  194. 	 
  195. 	local center_x = 117.5 
  196. 	local center_y = 67.84 
  197. 	 
  198. 	local d_left_corner = magnitude(0, 0, rel_x, rel_y) 
  199. 	local d_right_corner = magnitude(rel_x, rel_y, Max_x, 0) 
  200. 	local d_top_corner = magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  201. 	 
  202. 	local d_bottom = d_left_corner + d_right_corner 
  203. 	local d_left = d_left_corner + d_top_corner 
  204. 	local d_right = d_right_corner + d_top_corner 
  205. 	 
  206. 	local closest 
  207. 	if d_bottom < d_left then 
  208. 		if d_bottom < d_right then 
  209. 			-- closest to bottom 
  210. 			closest = 1 
  211. 		else 
  212. 			-- closest to right 
  213. 			closest = 0 
  214. 		end 
  215. 	else 
  216. 		if d_left < d_right then 
  217. 			-- closest to left 
  218. 			closest = 2 
  219. 		else 
  220. 			-- closest to right 
  221. 			closest = 0 
  222. 		end 
  223. 	end 
  224. 	 
  225. 	local d_center = magnitude(center_x, center_y, rel_x, rel_y) 
  226. 	local d_min = magnitude(center_x, center_y, 0, 0) * 2 
  227. 	local d_max = Max_x * 2					--magnitude(0, 0, Max_x, 0); 
  228. 	 
  229. 	local fat_percent = d_min 
  230. 	local skinny_percent = d_min 
  231. 	local muscle_percent = d_min 
  232.  
  233. 	-- left side (fat) 
  234. 	if closest ~= 2 then 
  235. 		if d_right < d_bottom then 
  236. 			-- right section 
  237. 			if d_right_corner > d_top_corner then 
  238. 				fat_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  239. 			else 
  240. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  241. 			end 
  242. 		else 
  243. 			-- bottom section 
  244. 			if d_right_corner > d_left_corner then 
  245. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  246. 			else 
  247. 				fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  248. 			end 
  249. 		end 
  250. 	end 
  251. 	fat_percent = (fat_percent - d_min) / (d_max - d_min) 
  252. 	 
  253. 	-- right side (skinny) 
  254. 	if closest ~= 0 then 
  255. 		if d_left < d_bottom then 
  256. 			-- left section 
  257. 			if d_left_corner > d_top_corner then 
  258. 				skinny_percent = magnitude(Max_x, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  259. 			else 
  260. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  261. 			end 
  262. 		else 
  263. 			-- bottom section 
  264. 			if d_left_corner > d_right_corner then 
  265. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  266. 			else 
  267. 				skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  268. 			end 
  269. 		end 
  270. 	end 
  271. 	skinny_percent = (skinny_percent - d_min) / (d_max - d_min) 
  272.  
  273. 	-- bottom side (strength) 
  274. 	if closest ~= 1 then 
  275. 		if d_left < d_right then 
  276. 			-- left section 
  277. 			if d_top_corner > d_left_corner then 
  278. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x, 0) 
  279. 			else 
  280. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  281. 			end 
  282. 		else 
  283. 			-- right section 
  284. 			if d_top_corner > d_right_corner then 
  285. 				muscle_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  286. 			else 
  287. 				muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  288. 			end 
  289. 		end 
  290. 	end 
  291. 	muscle_percent = (muscle_percent - d_min) / (d_max - d_min) 
  292. 	 
  293. 	-- update % displays	 
  294. 	update_percent_fields(floor(fat_percent * 100 + 0.5), floor(skinny_percent * 100 + 0.5), floor(muscle_percent * 100 + 0.5))		 
  295. 	 
  296. 	-- convert back to screen coord 
  297. 	rel_y = Max_y - rel_y 
  298. 	 
  299. 	-- convert back to screen position 
  300. 	new_x = rel_x + TRIANGLE_NW_X 
  301. 	new_y = rel_y + TRIANGLE_NW_Y 
  302.  
  303. 	Cursor:set_anchor(new_x, new_y) 
  304. 	 
  305. 	if new_x ~= self.old_x or new_y ~= self.old_y then 
  306. 		game_UI_audio_play("UI_Cell_Nav") 
  307. 	end 
  308. 	self.old_x = new_x 
  309. 	self.old_y = new_y 
  310. 	 
  311. 	return muscle_percent, skinny_percent, fat_percent, new_x, new_y 
  312. end 
  313.  
  314. function Vdo_triangle_select:set_highlight_color(new_color) 
  315. 	self.btn_highlight:set_highlight_color(new_color) 
  316. 	Fat_txt:set_color(new_color.R, new_color.G, new_color.B) 
  317. 	Skinny_txt:set_color(new_color.R, new_color.G, new_color.B) 
  318. 	Strength_txt:set_color(new_color.R, new_color.G, new_color.B)	 
  319. 	self.glow_bmp:set_color(new_color.R, new_color.G, new_color.B)	 
  320. 	self.tri_color_grp:set_color(new_color.R, new_color.G, new_color.B)	 
  321. 	self.tri_color_grp:set_visible(true) 
  322. end 
  323.  
  324.  
  325. -- ===================================== 
  326. --       Mouse Specific Functions 
  327. -- ===================================== 
  328.  
  329. function Vdo_triangle_select:update_mouse(mouse_x, mouse_y)	 
  330. 	if (mouse_x ~= nil) and (mouse_y ~= nil) then 
  331. 		local triangle_base = Vdo_base_object:new("triangle_base", self.handle, self.doc_handle) 
  332. 		local tri_x, tri_y = vint_get_global_anchor(triangle_base.handle, self.doc_handle) 
  333. 		local tri_width, tri_height = triangle_base:get_actual_size() 
  334. 		 
  335. 		-- Calculate the points of the innermost triangle (A, B, C) in screen space 
  336. 		-- A is the bottom left point, B is the top point, C is the bottom right point 
  337. 		local ax = tri_x + TRIANGLE_NW_X 
  338. 		local ay = tri_y + TRIANGLE_NW_Y + Max_y + 4 
  339. 		local bx = tri_x + (tri_width / 2) 
  340. 		local by = tri_y + TRIANGLE_NW_Y + 4 
  341. 		local cx = tri_x + tri_width - TRIANGLE_NW_X 
  342. 		local cy = ay 
  343. 		 
  344. 		-- Adjust the mouse_x and mouse_y position based on the resolution/etc 
  345. 		local screen_w, screen_h = vint_get_screen_size() 
  346. 		local anchor_x, anchor_y 
  347. 		local relative_x, relative_y 
  348. 		if vint_is_std_res() then 
  349. 			local doc_width = screen_h * 4 / 3 
  350. 			local offset = (doc_width - screen_w) / 2 
  351. 			mouse_x = ((mouse_x + offset) * 640 / doc_width) 
  352. 			mouse_y = mouse_y * 480 / screen_h 
  353. 			 
  354. 			mouse_x = tri_x + (mouse_x - tri_x) * 1.5 
  355. 			mouse_y = tri_y + (mouse_y - tri_y) * 1.5 
  356. 		else  
  357. 			local doc_width = screen_h * 16 / 9 
  358. 			local offset = (doc_width - screen_w) / 2 
  359. 			mouse_x = ((mouse_x + offset) * 1280 / doc_width) 
  360. 			mouse_y = mouse_y * 720 / screen_h 
  361. 		end 
  362. 		 
  363. 		-- Check the location of the mouse cursor against each side of the triangle 
  364. 		-- If the point is "inside," it is to the right or on the line 
  365. 		local point_inside_left = false 
  366. 		local point_inside_right = false 
  367. 		local point_inside_bottom = false 
  368. 		if which_side_of_2d_line(mouse_x, mouse_y, ax, ay, bx, by) >= 0 then 
  369. 			point_inside_left = true 
  370. 		end 
  371. 		 
  372. 		if which_side_of_2d_line(mouse_x, mouse_y, bx, by, cx, cy) >= 0 then 
  373. 			point_inside_right = true 
  374. 		end 
  375. 		 
  376. 		if which_side_of_2d_line(mouse_x, mouse_y, cx, cy, ax, ay) >= 0 then 
  377. 			point_inside_bottom = true 
  378. 		end 
  379. 		 
  380. 		local new_x, new_y 
  381. 		local rel_x, rel_y 
  382. 		if point_inside_left and point_inside_right and point_inside_bottom then 
  383. 			-- If the point is inside the triangle, calculate the position of the mouse in the triangle space 
  384. 			new_x = mouse_x - tri_x 
  385. 			new_y = mouse_y - tri_y - 4 
  386. 			 
  387. 		else 
  388. 			-- If the point is not on the inside of the triangle, find the closest point on the 
  389. 			-- line that the point is not on the inside of. 
  390. 			 
  391. 			if not point_inside_left then 
  392. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, ax, ay, bx, by) 
  393. 			end 
  394. 			 
  395. 			if not point_inside_right then 
  396. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, bx, by, cx, cy) 
  397. 			end 
  398. 			 
  399. 			if not point_inside_bottom then 
  400. 				new_x, new_y = closest_point_on_line_segment(mouse_x, mouse_y, cx, cy, ax, ay) 
  401. 			end 
  402. 			 
  403. 			-- Calculate the position of the point in the triangle space 
  404. 			new_x = new_x - tri_x 
  405. 			new_y = new_y - tri_y - 4 
  406. 		end 
  407. 		 
  408. 		rel_x = new_x - TRIANGLE_NW_X 
  409. 		rel_y = Max_y - (new_y - TRIANGLE_NW_Y) 
  410.  
  411. 		Cursor:set_anchor(new_x, new_y) 
  412. 		 
  413. 		-- Cap just in case. 
  414. 		rel_x = cap(rel_x, 0, Max_x) 
  415. 		rel_y = cap(rel_y, 0, Max_y) 
  416. 	 
  417. 		local center_x = 117.5 
  418. 		local center_y = 67.84 
  419. 		 
  420. 		local d_left_corner = magnitude(0, 0, rel_x, rel_y) 
  421. 		local d_right_corner = magnitude(rel_x, rel_y, Max_x, 0) 
  422. 		local d_top_corner = magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  423. 		 
  424. 		local d_bottom = d_left_corner + d_right_corner 
  425. 		local d_left = d_left_corner + d_top_corner 
  426. 		local d_right = d_right_corner + d_top_corner 
  427. 		 
  428. 		local closest 
  429. 		if d_bottom < d_left then 
  430. 			if d_bottom < d_right then 
  431. 				-- closest to bottom 
  432. 				closest = 1 
  433. 			else 
  434. 				-- closest to right 
  435. 				closest = 0 
  436. 			end 
  437. 		else 
  438. 			if d_left < d_right then 
  439. 				-- closest to left 
  440. 				closest = 2 
  441. 			else 
  442. 				-- closest to right 
  443. 				closest = 0 
  444. 			end 
  445. 		end 
  446. 		 
  447. 		local d_center = magnitude(center_x, center_y, rel_x, rel_y) 
  448. 		local d_min = magnitude(center_x, center_y, 0, 0) * 2 
  449. 		local d_max = Max_x * 2					--magnitude(0, 0, Max_x, 0); 
  450. 		 
  451. 		local fat_percent = d_min 
  452. 		local skinny_percent = d_min 
  453. 		local muscle_percent = d_min 
  454.  
  455. 		-- left side (fat) 
  456. 		if closest ~= 2 then 
  457. 			if d_right < d_bottom then 
  458. 				-- right section 
  459. 				if d_right_corner > d_top_corner then 
  460. 					fat_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  461. 				else 
  462. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  463. 				end 
  464. 			else 
  465. 				-- bottom section 
  466. 				if d_right_corner > d_left_corner then 
  467. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  468. 				else 
  469. 					fat_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  470. 				end 
  471. 			end 
  472. 		end 
  473. 		fat_percent = (fat_percent - d_min) / (d_max - d_min) 
  474. 		 
  475. 		-- right side (skinny) 
  476. 		if closest ~= 0 then 
  477. 			if d_left < d_bottom then 
  478. 				-- left section 
  479. 				if d_left_corner > d_top_corner then 
  480. 					skinny_percent = magnitude(Max_x, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  481. 				else 
  482. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  483. 				end 
  484. 			else 
  485. 				-- bottom section 
  486. 				if d_left_corner > d_right_corner then 
  487. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x /2, Max_y) 
  488. 				else 
  489. 					skinny_percent = magnitude(Max_x, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x / 2, Max_y) 
  490. 				end 
  491. 			end 
  492. 		end 
  493. 		skinny_percent = (skinny_percent - d_min) / (d_max - d_min) 
  494.  
  495. 		-- bottom side (strength) 
  496. 		if closest ~= 1 then 
  497. 			if d_left < d_right then 
  498. 				-- left section 
  499. 				if d_top_corner > d_left_corner then 
  500. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, center_x, center_y) + magnitude(center_x, center_y, Max_x, 0) 
  501. 				else 
  502. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  503. 				end 
  504. 			else 
  505. 				-- right section 
  506. 				if d_top_corner > d_right_corner then 
  507. 					muscle_percent = magnitude(0, 0, center_x, center_y) + magnitude(center_x, center_y, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  508. 				else 
  509. 					muscle_percent = magnitude(0, 0, rel_x, rel_y) + magnitude(rel_x, rel_y, Max_x, 0) 
  510. 				end 
  511. 			end 
  512. 		end 
  513. 		muscle_percent = (muscle_percent - d_min) / (d_max - d_min) 
  514. 	 
  515. 		-- update % displays	 
  516. 		update_percent_fields(floor(fat_percent * 100 + 0.5), floor(skinny_percent * 100 + 0.5), floor(muscle_percent * 100 + 0.5))		 
  517. 	 
  518. 		return muscle_percent, skinny_percent, fat_percent, new_x, new_y 
  519. 	end 
  520. end