liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

cartesianpolar.c (1013B)


      1 // cartesian to polar test
      2 
      3 #include "../lash_game_standard.h"
      4 #include <string.h>
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 
      8 int main(int argc, char *argv[]) {
      9 	if (argc < 5 || (argc != 5 && argc < 7)) {
     10 		printf("Usage: %s src_x src_y target_x target_y [inv_x inv_y]\n", argv[0]);
     11 		return 1;
     12 	}
     13 	
     14 	int16_t target_x = atoi(argv[1]);
     15 	int16_t target_y = atoi(argv[2]);
     16 	int16_t src_x = atoi(argv[3]);
     17 	int16_t src_y = atoi(argv[4]);
     18 	float radians_result;
     19 	float radius_result;
     20 	int inv_x = 0;
     21 	int inv_y = 0;
     22 	
     23 	if (argc > 5) {
     24 		if (strcmp(argv[5], "0")) 
     25 			inv_x = 1;
     26 		if (strcmp(argv[6], "0")) 
     27 			inv_y = 1;
     28 	}	
     29 	
     30 	lash_cartesianToPolar(src_x, src_y, target_x, target_y, &radians_result, &radius_result, inv_x, inv_y);
     31 	
     32 	char *inv_x_str = inv_x ? "Yes" : "No";
     33 	char *inv_y_str = inv_y ? "Yes" : "No";
     34 	
     35 	printf("Src: x%d,y%d\nTarget: x%d,y%d\nInverse X: %s\nInverse Y: %s\nRadians: %f\nRadius: %f\n", src_x, src_y, target_x, target_y, inv_x_str, inv_y_str, radians_result, radius_result);
     36 	
     37 	
     38 	return 0;
     39 }