Add line_from_origin function
This commit is contained in:
		
							
								
								
									
										15
									
								
								src/ui.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/ui.c
									
									
									
									
									
								
							| @@ -8,8 +8,10 @@ | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #define NOODLE_HALF_WIDTH 2 | ||||
| #define DEFAULT_NOODLE_LENGTH 60 | ||||
|  | ||||
| INTERNAL bool aabb(rect rec, i32 x, i32 y); | ||||
| INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length); | ||||
|  | ||||
| void init_ui_ctx(ui_ctx *ctx) { | ||||
|   *ctx = (ui_ctx){0}; | ||||
| @@ -239,3 +241,16 @@ INTERNAL bool aabb(rect rec, i32 x, i32 y) { | ||||
|   return x > rec.topleft.x && x <= rec.topleft.x + rec.w && y > rec.topleft.y && | ||||
|          y <= rec.topleft.y + rec.h; | ||||
| } | ||||
|  | ||||
| INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length) { | ||||
|   f64 rad = radians(angle); | ||||
|   f64 direction = angle / absolute(angle) * -1; | ||||
|  | ||||
|   i32 adjacent = line_length * cos(rad) * direction; // dx | ||||
|   i32 opposite = line_length * sin(rad) * direction; // dy | ||||
|  | ||||
|   return (line){ | ||||
|       (point){origin.x + adjacent, origin.y + opposite}, | ||||
|       origin, | ||||
|   }; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user