L
Liam Harper
Guest
I'm working on an isometric grid and I thought I'd cracked the maths but I've hit a wall. I'm using draw_line_width() to draw a simple Cartesian grid in the centre of the screen:
This works fine, but when I try to convert these coordinates to isometric coordinates, I can't get the grid centred on the screen. Instead it's off to the left and bottom of the screen and I can't get my head around why!
How do I get the grid to start drawing in the centre?
Code:
global.GridLeft = (room_width / 2) - ((global.CellWidth * global.NoOfXCells) / 2);
global.GridTop = (room_height / 2) - ((global.CellHeight * global.NoOfYCells) / 2);
// Draw vertical lines
draw_line_width(
global.GridLeft + (i * global.CellWidth),
global.GridTop,
global.GridLeft + (i * global.CellWidth),
global.GridTop + (global.CellHeight * global.NoOfYCells),
1
);
// Draw horizontal lines
draw_line_width(
global.GridLeft,
global.GridTop + (i * global.CellHeight),
global.GridLeft + (global.CellWidth * global.NoOfXCells),
global.GridTop + (i * global.CellHeight),
1
);
Code:
// Cartesian to isometric script
/// @function iso_start_end(cart_x1, cart_y1, cart_x2, cart_y2, array)
/// @param cart_x1
/// @param cart_x2
/// @param cart_y1
/// @param cart_y2
/// @param array
cart_x1 = argument0;
cart_y1 = argument1;
cart_x2 = argument2;
cart_y2 = argument3;
array = argument4;
array[0] = cart_x1 - cart_y1;
array[1] = (cart_x1 + cart_y1) / 2;
array[2] = cart_x2 - cart_y2;
array[3] = (cart_x2 + cart_y2) / 2;
return array;
Code:
// Draw lines with isometric coordinates
isometric = iso_start_end(
global.GridLeft + (i * global.CellWidth),
global.GridTop,
global.GridLeft + (i * global.CellWidth),
global.GridTop + (global.CellHeight * global.NoOfYCells),
isometric
);
draw_line_width(isometric[0], isometric[1], isometric[2], isometric[3], 1);
isometric = iso_start_end(
global.GridLeft,
global.GridTop + (i * global.CellHeight),
global.GridLeft + (global.CellWidth * global.NoOfXCells),
global.GridTop + (i * global.CellHeight),
isometric
);
draw_line_width(isometric[0], isometric[1], isometric[2], isometric[3], 1);
Attachments
-
25.8 KB Views: 14